Debian Codegraph @

musicPlayer/src/applet-dcop.c

raw
1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "applet-dcop.h"
21
22 /***************************************************************************/
23 /// Fonctions de lecture de pipe dcop
24
25 #include <stdio.h>
26
27 FILE *popen(const char *command, const char *type);
28
29 int pclose(FILE *stream);
30
31 gchar *cd_dcop_get_string (const char *cCommand) {
32 FILE *pPipe = popen (cCommand,"r");
33 if (!pPipe)
34 return NULL;
35 gchar *cRead = (gchar *) malloc (512*sizeof(gchar));
36 if (!fgets(cRead,512,pPipe)) {
37 g_free(cRead);
38 pclose(pPipe);
39 return NULL;
40 }
41 pclose(pPipe);
42 strtok (cRead,"\n");
43 return cRead;
44 }
45
46 gint cd_dcop_get_int (const char *cCommand) {
47 FILE *pPipe = popen (cCommand,"r");
48 if (!pPipe)
49 return -1;
50 gchar *cRead = (gchar *) malloc (128*sizeof(gchar));
51 if (!fgets(cRead,128,pPipe)) {
52 g_free(cRead);
53 pclose(pPipe);
54 return -1;
55 }
56 pclose(pPipe);
57 gint iRet = (gint)atoi(cRead);
58 g_free(cRead);
59 return iRet;
60 }
61
62 gboolean cd_dcop_get_boolean (const char *cCommand) {
63 FILE *pPipe = popen (cCommand,"r");
64 if (!pPipe)
65 return FALSE;
66 gchar *cRead = (gchar *) malloc (56*sizeof(gchar));
67 if (!fgets(cRead,56,pPipe)) {
68 g_free(cRead);
69 pclose(pPipe);
70 return FALSE;
71 }
72 pclose(pPipe);
73 strtok (cRead,"\n");
74 gboolean bRet = g_strcasecmp(cRead,"true")==0;
75 g_free(cRead);
76 return bRet;
77 }
78 /***************************************************************************/