[Mixmaster-devel] r855 - trunk/Mix/Src
Brought to you by:
weaselp
|
From: <we...@so...> - 2004-05-13 14:06:06
|
Author: weasel
Date: 2004-05-13 16:05:55 +0200 (Thu, 13 May 2004)
New Revision: 855
Modified:
trunk/Mix/Src/menustats.c
Log:
Change menustats to mixmaster's indentation scheme
Modified: trunk/Mix/Src/menustats.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/Mix/Src/menustats.c 2004-05-13 14:02:07 UTC (rev 854)
+++ trunk/Mix/Src/menustats.c 2004-05-13 14:05:55 UTC (rev 855)
@@ -32,40 +32,40 @@
=20
=20
int url_download(char *url, char *dest) {
- int err;
+ int err;
#ifdef WIN32
- err =3D URLDownloadToFile(NULL, url, dest, BINDF_GETNEWESTVERSION, NULL=
);
+ err =3D URLDownloadToFile(NULL, url, dest, BINDF_GETNEWESTVERSION, NUL=
L);
=20
- if (err !=3D S_OK)
- return -1;
- else
- return 0;
+ if (err !=3D S_OK)
+ return -1;
+ else
+ return 0;
#else
- char s[PATHMAX];
- snprintf(s, PATHMAX, "%s -q %s -O %s", WGET, url, dest);
- err =3D system(s);
+ char s[PATHMAX];
+ snprintf(s, PATHMAX, "%s -q %s -O %s", WGET, url, dest);
+ err =3D system(s);
=20
- if (err !=3D -1) {
- if (WIFEXITED(err) =3D=3D 0)
- return -1; /* abnormal child exit */
- else
- return 0;
- }
- else
- return -1;
+ if (err !=3D -1) {
+ if (WIFEXITED(err) =3D=3D 0)
+ return -1; /* abnormal child exit */
+ else
+ return 0;
+ }
+ else
+ return -1;
#endif /* WIN32 */
}
=20
/** read the allpingers file into the buffer */
void read_allpingers(BUFFER *allpingers) {
- FILE *f;
+ FILE *f;
=20
- f =3D mix_openfile(ALLPINGERSFILE, "r");
- if (f !=3D NULL) {
- buf_clear(allpingers);
- buf_read(allpingers, f);
- fclose(f);
- }
+ f =3D mix_openfile(ALLPINGERSFILE, "r");
+ if (f !=3D NULL) {
+ buf_clear(allpingers);
+ buf_read(allpingers, f);
+ fclose(f);
+ }
}
=20
/* Get all sections from inifile.
@@ -73,23 +73,23 @@
* They are put into the sections buffer, separated by newlines
*/
void get_sections(BUFFER *inifile, BUFFER *sections) {
- BUFFER *line;
- int err;
+ BUFFER *line;
+ int err;
=20
- line =3D buf_new();
+ line =3D buf_new();
=20
- buf_rewind(inifile);
- buf_reset(sections);
+ buf_rewind(inifile);
+ buf_reset(sections);
=20
- while ((err =3D buf_getline(inifile, line)) !=3D -1) {
- if (bufileft (line, "[") &&
- bufiright(line, "]")) {
- line->data[line->length-1] =3D '\0';
- buf_appends(sections, line->data+1);
- buf_nl(sections);
- };
- }
- buf_free (line);
+ while ((err =3D buf_getline(inifile, line)) !=3D -1) {
+ if (bufileft (line, "[") &&
+ bufiright(line, "]")) {
+ line->data[line->length-1] =3D '\0';
+ buf_appends(sections, line->data+1);
+ buf_nl(sections);
+ };
+ }
+ buf_free (line);
}
=20
/* Get value of an attribute
@@ -97,44 +97,44 @@
* returns -1 if it isn't found.
*/
int get_attribute(BUFFER *inifile, char *section, char *attribute, BUFFE=
R *value) {
- BUFFER *line;
- int err =3D -1;
- int insection =3D 0;
+ BUFFER *line;
+ int err =3D -1;
+ int insection =3D 0;
=20
- line =3D buf_new();
+ line =3D buf_new();
=20
- buf_rewind(inifile);
- buf_reset(value);
+ buf_rewind(inifile);
+ buf_reset(value);
=20
- while (buf_getline(inifile, line) !=3D -1) {
- if (bufileft (line, "[") &&
- bufiright(line, "]")) {
- if (insection)
- break;
+ while (buf_getline(inifile, line) !=3D -1) {
+ if (bufileft (line, "[") &&
+ bufiright(line, "]")) {
+ if (insection)
+ break;
=20
- line->data[line->length-1] =3D '\0';
- if (strcasecmp(section, line->data+1) =3D=3D 0) {
- insection =3D 1;
- }
- } else if (insection && bufileft(line, attribute)) {
- /* we are in the right section and this attribute name
- * at least starts with what we want */
- char *ptr =3D line->data + strlen(attribute);
- /* eat up whitespace */
- while ((*ptr =3D=3D ' ') || (*ptr =3D=3D '\t'))
- ptr++;
- if (*ptr !=3D '=3D')
- continue;
- ptr++;
- while ((*ptr =3D=3D ' ') || (*ptr =3D=3D '\t'))
- ptr++;
- buf_appends(value, ptr);
- err =3D 0;
- break;
- }
- }
- buf_free (line);
- return (err);
+ line->data[line->length-1] =3D '\0';
+ if (strcasecmp(section, line->data+1) =3D=3D 0) {
+ insection =3D 1;
+ }
+ } else if (insection && bufileft(line, attribute)) {
+ /* we are in the right section and this attribute name
+ * at least starts with what we want */
+ char *ptr =3D line->data + strlen(attribute);
+ /* eat up whitespace */
+ while ((*ptr =3D=3D ' ') || (*ptr =3D=3D '\t'))
+ ptr++;
+ if (*ptr !=3D '=3D')
+ continue;
+ ptr++;
+ while ((*ptr =3D=3D ' ') || (*ptr =3D=3D '\t'))
+ ptr++;
+ buf_appends(value, ptr);
+ err =3D 0;
+ break;
+ }
+ }
+ buf_free (line);
+ return (err);
}
=20
=20
@@ -147,66 +147,66 @@
/* Download all the needed files from the specified source */
/* returns -1 on error */
int stats_download(BUFFER *allpingers, char *sourcename, int curses) {
- char *localfiles[] =3D { TYPE2REL, TYPE1LIST, PUBRING, PGPREMPUBASC, TY=
PE2LIST };
- char path[PATHMAX];
- BUFFER *value;
- int ret =3D 0;
- int err;
- int i;
+ char *localfiles[] =3D { TYPE2REL, TYPE1LIST, PUBRING, PGPREMPUBASC, T=
YPE2LIST };
+ char path[PATHMAX];
+ BUFFER *value;
+ int ret =3D 0;
+ int err;
+ int i;
=20
- value =3D buf_new();
+ value =3D buf_new();
=20
- if (curses) {
- clear();
- }
+ if (curses) {
+ clear();
+ }
=20
- err =3D get_attribute(allpingers, sourcename, "base", value);
- if (err =3D=3D 0) {
- if (curses) {
- standout();
- printw("%s", value->data);
- standend();
- }
- else
- printf("%s\n\r", value->data);
- }
-=09
- for (i=3D0; i<NUMFILES; i++) {
- err =3D get_attribute(allpingers, sourcename, files[i], value);
- if (err < 0) {
- /* the attribute vanished under us */
- ret =3D -1;
- break;
- }
- mixfile(path, localfiles[i]);
- if (curses) {
- mvprintw(i+3, 0, "downloading %s from %s...", localfiles[i], value->d=
ata);
- refresh();
- }
- else
- printf("downloading %s from %s...", localfiles[i], value->data);
- err =3D url_download(value->data, path);
- if (err < 0) {
- if (curses)
- printw("failed to download.\n\rTry using another stats source.");
- else
- printf("failed to download.\n\rTry using another stats source.\n\r")=
;
- ret =3D -1;
- break;
- }
- if (curses)
- printw("done");
- else
- printf("done\n\r");
- }
+ err =3D get_attribute(allpingers, sourcename, "base", value);
+ if (err =3D=3D 0) {
+ if (curses) {
+ standout();
+ printw("%s", value->data);
+ standend();
+ }
+ else
+ printf("%s\n\r", value->data);
+ }
=20
- if (curses) {=09
- printw("\n\n\n\n\rPress any key to continue");
- getch();
- clear();
- }
- buf_free(value);
- return ret;
+ for (i=3D0; i<NUMFILES; i++) {
+ err =3D get_attribute(allpingers, sourcename, files[i], value);
+ if (err < 0) {
+ /* the attribute vanished under us */
+ ret =3D -1;
+ break;
+ }
+ mixfile(path, localfiles[i]);
+ if (curses) {
+ mvprintw(i+3, 0, "downloading %s from %s...", localfiles[i], value=
->data);
+ refresh();
+ }
+ else
+ printf("downloading %s from %s...", localfiles[i], value->data);
+ err =3D url_download(value->data, path);
+ if (err < 0) {
+ if (curses)
+ printw("failed to download.\n\rTry using another stats source.");
+ else
+ printf("failed to download.\n\rTry using another stats source.\n\r");
+ ret =3D -1;
+ break;
+ }
+ if (curses)
+ printw("done");
+ else
+ printf("done\n\r");
+ }
+
+ if (curses) { =20
+ printw("\n\n\n\n\rPress any key to continue");
+ getch();
+ clear();
+ }
+ buf_free(value);
+ return ret;
}
/* Checks whether the stats source has all the required files.
*
@@ -214,183 +214,183 @@
* 0 otherwise
*/
int good_stats_source (BUFFER *allpingers, char *sourcename) {
- BUFFER *value;
- int i;
- int res =3D 1;
- int err;
+ BUFFER *value;
+ int i;
+ int res =3D 1;
+ int err;
=20
- value =3D buf_new();
+ value =3D buf_new();
=20
- for (i =3D 0; i < NUMFILES; i++) {
- err =3D get_attribute(allpingers, sourcename, files[i], value);
- if (err < 0) {
- res =3D 0;
- break;
- }
- }
+ for (i =3D 0; i < NUMFILES; i++) {
+ err =3D get_attribute(allpingers, sourcename, files[i], value);
+ if (err < 0) {
+ res =3D 0;
+ break;
+ }
+ }
=20
- buf_free (value);
- return (res);
+ buf_free (value);
+ return (res);
}
/* Download allpingers.txt */
/* -1 on error */
static int download_list() {
- char path[PATHMAX];
+ char path[PATHMAX];
=20
- mixfile(path, ALLPINGERSFILE);
+ mixfile(path, ALLPINGERSFILE);
=20
- clear();
- standout();
- printw(ALLPINGERSURL);
- standend();
-=09
- mvprintw(3,0,"downloading %s...", ALLPINGERSURL);
- refresh();
- if (url_download(ALLPINGERSURL, path) < 0) {
- printw("failed to download.\n\rTry again later.");
- printw("\n\n\rPress any key to continue");
- getch();
- return -1;
- }
- return 0;
+ clear();
+ standout();
+ printw(ALLPINGERSURL);
+ standend();
+
+ mvprintw(3,0,"downloading %s...", ALLPINGERSURL);
+ refresh();
+ if (url_download(ALLPINGERSURL, path) < 0) {
+ printw("failed to download.\n\rTry again later.");
+ printw("\n\n\rPress any key to continue");
+ getch();
+ return -1;
+ }
+ return 0;
}
=20
/* Displays the choice of stats sources */
#define MAXPING (26 * 2)
void update_stats() {
- char c;
- BUFFER *inifile;
- BUFFER *pingernames;
- BUFFER *goodpingers;
- BUFFER *line;
- BUFFER *statssrc;
- FILE *f;
- int num;
- int err;
- int x, y;
- int i;
+ char c;
+ BUFFER *inifile;
+ BUFFER *pingernames;
+ BUFFER *goodpingers;
+ BUFFER *line;
+ BUFFER *statssrc;
+ FILE *f;
+ int num;
+ int err;
+ int x, y;
+ int i;
=20
- inifile =3D buf_new();
- pingernames =3D buf_new();
- goodpingers =3D buf_new();
- line =3D buf_new();
- statssrc =3D buf_new();
+ inifile =3D buf_new();
+ pingernames =3D buf_new();
+ goodpingers =3D buf_new();
+ line =3D buf_new();
+ statssrc =3D buf_new();
=20
- while (1) {
- clear();
- standout();
- buf_clear(statssrc);
- f =3D mix_openfile(STATSSRC, "r");
- if (f !=3D NULL) {
- buf_read(statssrc, f);
- fclose(f);
- }
- printw("Select stats source:");
- standend();
- if (statssrc->length > 0)
- printw(" Current: %s (Enter to download)", statssrc->data);
- printw("\n\n");
+ while (1) {
+ clear();
+ standout();
+ buf_clear(statssrc);
+ f =3D mix_openfile(STATSSRC, "r");
+ if (f !=3D NULL) {
+ buf_read(statssrc, f);
+ fclose(f);
+ }
+ printw("Select stats source:");
+ standend();
+ if (statssrc->length > 0)
+ printw(" Current: %s (Enter to download)", statssrc->data);
+ printw("\n\n");
=20
- read_allpingers(inifile);
- get_sections (inifile, pingernames);
+ read_allpingers(inifile);
+ get_sections (inifile, pingernames);
=20
- num =3D 0;
- buf_reset(goodpingers);
- buf_rewind(pingernames);
- while ((buf_getline(pingernames, line) !=3D -1) && num < MAXPING) {
- if (good_stats_source (inifile, line->data)) {
- buf_cat(goodpingers, line);
- buf_nl(goodpingers);
- num++;
- }
- }
+ num =3D 0;
+ buf_reset(goodpingers);
+ buf_rewind(pingernames);
+ while ((buf_getline(pingernames, line) !=3D -1) && num < MAXPING) {
+ if (good_stats_source (inifile, line->data)) {
+ buf_cat(goodpingers, line);
+ buf_nl(goodpingers);
+ num++;
+ }
+ }
=20
- x =3D 0;
- buf_rewind(goodpingers);
- for (i=3D0; i<num; i++) {
- err =3D buf_getline(goodpingers, line);
- assert (err !=3D -1);
- y =3D i;
- if (y >=3D LINES - 6)
- y -=3D LINES - 6, x =3D 40;
- mvprintw(y + 2, x, "%c", i < 26 ? i + 'a' : i - 26 + 'A');
- mvprintw(y + 2, x + 2, "%s", line->data);
- }
- y =3D i + 3;
- if (y > LINES - 4)
- y =3D LINES - 4;
- mvprintw(y, 0, "* update list of pingers from web =3D edit list =
<space> to exit");
- c =3D getch();
- if ((c >=3D 'a' && c <=3D 'z') || (c >=3D 'A' && c <=3D 'Z')) {
- if (c >=3D 'a')
- c -=3D 'a';
- else
- c =3D c - 'A' + 26;
- if (c < num) {
- buf_rewind(goodpingers);
- while (c >=3D 0) {
- err =3D buf_getline(goodpingers, line);
- assert (err !=3D -1);
- c--;
- }
- if (stats_download(inifile, line->data, 1) =3D=3D 0) {
- f =3D mix_openfile(STATSSRC, "w+");
- if (f !=3D NULL) {
- fprintf(f, "%s", line->data);
- fclose(f);
- } else
- fprintf(stderr, "Could not open stats source file for writing\n")=
;
- break;
- }
- }
- }
- else if (c =3D=3D '*') {
- download_list();
- }
- else if (c =3D=3D '=3D') {
- char path[PATHMAX];
- mixfile(path, ALLPINGERSFILE);
- menu_spawn_editor(path, 0);
- }
- else if ((c =3D=3D '\r') && statssrc->length) {
- stats_download(inifile, statssrc->data, 1);
- break;
- }
- else if (c =3D=3D ' ') {
- break;
- }
+ x =3D 0;
+ buf_rewind(goodpingers);
+ for (i=3D0; i<num; i++) {
+ err =3D buf_getline(goodpingers, line);
+ assert (err !=3D -1);
+ y =3D i;
+ if (y >=3D LINES - 6)
+ y -=3D LINES - 6, x =3D 40;
+ mvprintw(y + 2, x, "%c", i < 26 ? i + 'a' : i - 26 + 'A');
+ mvprintw(y + 2, x + 2, "%s", line->data);
+ }
+ y =3D i + 3;
+ if (y > LINES - 4)
+ y =3D LINES - 4;
+ mvprintw(y, 0, "* update list of pingers from web =3D edit lis=
t <space> to exit");
+ c =3D getch();
+ if ((c >=3D 'a' && c <=3D 'z') || (c >=3D 'A' && c <=3D 'Z')) {
+ if (c >=3D 'a')
+ c -=3D 'a';
+ else
+ c =3D c - 'A' + 26;
+ if (c < num) {
+ buf_rewind(goodpingers);
+ while (c >=3D 0) {
+ err =3D buf_getline(goodpingers, line);
+ assert (err !=3D -1);
+ c--;
}
- clear();
+ if (stats_download(inifile, line->data, 1) =3D=3D 0) {
+ f =3D mix_openfile(STATSSRC, "w+");
+ if (f !=3D NULL) {
+ fprintf(f, "%s", line->data);
+ fclose(f);
+ } else
+ fprintf(stderr, "Could not open stats source file for writing\n");
+ break;
+ }
+ }
+ }
+ else if (c =3D=3D '*') {
+ download_list();
+ }
+ else if (c =3D=3D '=3D') {
+ char path[PATHMAX];
+ mixfile(path, ALLPINGERSFILE);
+ menu_spawn_editor(path, 0);
+ }
+ else if ((c =3D=3D '\r') && statssrc->length) {
+ stats_download(inifile, statssrc->data, 1);
+ break;
+ }
+ else if (c =3D=3D ' ') {
+ break;
+ }
+ }
+ clear();
=20
- buf_free(statssrc);
- buf_free(inifile);
- buf_free(line);
- buf_free(pingernames);
- buf_free(goodpingers);
+ buf_free(statssrc);
+ buf_free(inifile);
+ buf_free(line);
+ buf_free(pingernames);
+ buf_free(goodpingers);
}
=20
#if 0
int main() {
- strcpy(MIXDIR,"./");
+ strcpy(MIXDIR,"./");
=20
- BUFFER *allpingers;
- BUFFER *pingernames;
- BUFFER *value;
+ BUFFER *allpingers;
+ BUFFER *pingernames;
+ BUFFER *value;
=20
- allpingers =3D buf_new();
- pingernames =3D buf_new();
- value =3D buf_new();
+ allpingers =3D buf_new();
+ pingernames =3D buf_new();
+ value =3D buf_new();
=20
- read_allpingers (allpingers);
- get_sections (allpingers, pingernames);
+ read_allpingers (allpingers);
+ get_sections (allpingers, pingernames);
=20
- printf("%s", pingernames->data);
+ printf("%s", pingernames->data);
=20
- get_attribute (allpingers, "noreply", "rlist", value);
- printf("%s\n", value->data);
+ get_attribute (allpingers, "noreply", "rlist", value);
+ printf("%s\n", value->data);
=20
=20
- exit(0);
+ exit(0);
}
=20
#endif
|