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