Make a description of ${cpu} variable not so confusing.
[monky] / src / seti.c
1 /*
2  * seti.c: information about SETI for Conky
3  *
4  *  $Id$
5  */
6
7 #include "conky.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11
12 char *seti_dir = NULL;
13
14 /*
15  * Need to code for BOINC, because the old SETI@Home does not use xml to store data.
16  * Perhaps in the .conkyrc file there could be an option for BOINC or old SETI.
17  */
18
19 /*static float seti_get_float (FILE *fp, const char *name)
20 {
21   char buffer[80];
22   char *token;
23
24   while (!feof(fp) && !ferror (fp))
25   {
26     fgets(buffer, 80, fp);
27     token = strtok(buffer, ">");
28
29     if (strcmp(token, name) == 0)
30     {
31       token = strtok(NULL, "<");
32       if ( token != NULL )
33         return atof (token);
34       break;
35     }
36   }
37   return 0.0f;
38 }*/
39
40 float seti_get_data(FILE * fp, const char *name)
41 {
42         char token[1000];
43         char buffer[1000];
44         float data;
45
46         while (fgets(token, 1000, fp) != NULL)  //read the file
47                 if (strncmp(token, name, strlen(name)) == 0) {  //and search for the data in name
48                         strcpy(buffer, strchr(token, '=') + 1); //copy just the number
49                         break;
50                 }
51         data = atof(buffer);
52         return data;
53 }
54
55 void update_seti()
56 {
57         if (seti_dir == NULL)
58                 return;
59
60         char filename[80];
61
62         struct information *current_info = &info;
63
64         current_info->seti_prog = current_info->seti_credit = 0.0f;
65
66         /* read total user credit */
67
68         /*FILE *fp = fopen(filename, "r");
69            if (!fp)
70            return;
71
72            seti_credit = seti_get_float(fp, "<user_total_credit");
73
74            fclose (fp); */
75
76         snprintf(filename, 80, "%s/user_info.sah", seti_dir);
77
78         FILE *fp = fopen(filename, "r");
79
80         if (!fp) {
81                 return;
82         }
83
84         current_info->seti_credit = seti_get_data(fp, "nresults");
85
86         fclose(fp);
87
88         /* read current progress */
89
90         /*snprintf(filename, 80, "%s/slots/0/state.sah", seti_dir);
91            fp = fopen(filename, "r");
92            if (!fp)
93            return;
94
95            seti_prog = seti_get_float(fp, "<prog");
96
97            fclose (fp);
98
99            snprintf(filename, 80, "%s/slots/0/init_data.xml", seti_dir); */
100
101         snprintf(filename, 80, "%s/state.sah", seti_dir);
102
103         fp = fopen(filename, "r");
104         if (!fp)
105                 return;
106
107         current_info->seti_prog = seti_get_data(fp, "prog");
108
109         fclose(fp);
110
111 }