Enlightenment CVS committal Author : kwo Project : e16 Module : e
Dir : e16/e/src Modified Files: config.c sound.c windowmatch.c Log Message: Avoid dangling buffer. Eliminate some redundant code. =================================================================== RCS file: /cvs/e/e16/e/src/config.c,v retrieving revision 1.149 retrieving revision 1.150 diff -u -3 -r1.149 -r1.150 --- config.c 24 Jul 2006 23:56:39 -0000 1.149 +++ config.c 12 Aug 2006 10:33:47 -0000 1.150 @@ -52,20 +52,6 @@ } } -static int -IsWhitespace(const char *s) -{ - int i = 0; - - while (s[i]) - { - if ((s[i] != ' ') && (s[i] != '\n') && (s[i] != '\t')) - return 0; - i++; - } - return 1; -} - #define LINE_BUFFER_SIZE 1024 /* * This function will get a single line from the file @@ -75,9 +61,19 @@ char * GetLine(char *s, int size, FILE * f) { - char *si, *so, ch, quote, escape; static char *buffer = NULL; - static char *bufptr = NULL; + static const char *bufptr = NULL; + char *so, ch, quote, escape; + const char *si; + size_t nr; + + if (buffer == NULL) + { + buffer = Emalloc(LINE_BUFFER_SIZE); + if (buffer == NULL) + return NULL; + buffer[LINE_BUFFER_SIZE - 1] = '\0'; + } si = bufptr; so = s; @@ -85,83 +81,74 @@ escape = '\0'; for (;;) { - if (buffer == NULL) - { - buffer = Emalloc(LINE_BUFFER_SIZE); - if (buffer == NULL) - return NULL; - } - /* Get a line from the input file */ if (si == NULL) { - si = fgets(buffer, LINE_BUFFER_SIZE - 1, f); - buffer[LINE_BUFFER_SIZE - 1] = '\0'; - if (si == NULL) - { - /* EOF */ - Efree(buffer); - buffer = bufptr = NULL; - return NULL; - } + nr = fread(buffer, 1, LINE_BUFFER_SIZE - 1, f); + if (nr == 0) + break; + buffer[nr] = '\0'; + si = buffer; } /* Split on ';' or '\n', handle quoting */ - for (; si;) + ch = *si++; + switch (ch) { - ch = *si++; - switch (ch) - { - case '\0': - si = NULL; - if (so == s) /* Skip empty lines */ - break; - goto case_eol; - case ';': /* Line separator */ - if (escape || quote) - goto case_char; - case '\n': - if (so == s) /* Skip empty lines */ - break; - case_eol: - *so = '\0'; /* Terminate and return */ - goto done; - case '\r': /* Ignore */ - break; - case '\\': /* Escape */ - if (escape) - goto case_char; - escape = ch; - break; - case '"': /* Quoting */ + case '\0': + si = NULL; + break; + case ';': /* Line separator */ + if (escape || quote) + goto case_char; + case '\n': + if (so == s) /* Skip empty lines */ + break; + *so = '\0'; /* Terminate and return */ + goto done; + case '\r': /* Ignore */ + break; + case '\\': /* Escape */ + if (escape) + goto case_char; + escape = ch; + break; + case '"': /* Quoting */ /* case '\'': */ - if (escape) - goto case_char; - if (quote == '\0') - quote = ch; - else if (quote == ch) - quote = '\0'; - else - goto case_char; - break; - case ' ': /* Whitespace */ - case '\t': - if (so == s) /* Skip leading whitespace */ - break; - case_char: /* Normal character */ - default: - *so++ = ch; - escape = '\0'; - if (--size > 1) - break; - *so = '\0'; - goto done; - } + if (escape) + goto case_char; + if (quote == '\0') + quote = ch; + else if (quote == ch) + quote = '\0'; + else + goto case_char; + break; + case ' ': /* Whitespace */ + case '\t': + if (so == s) /* Skip leading whitespace */ + break; + case_char: /* Normal character */ + default: + *so++ = ch; + escape = '\0'; + if (--size > 1) + break; + *so = '\0'; + goto done; } } done: bufptr = si; + if (si == NULL) + { + /* EOF */ + Efree(buffer); + buffer = NULL; + if (so == s) + return NULL; + } /* Strip trailing whitespace */ si = so; @@ -174,7 +161,7 @@ if (so != si) *so = '\0'; - if (EventDebug(EDBUG_TYPE_CONFIG)) + if (EventDebug(EDBUG_TYPE_CONFIG) > 1) Eprintf("GetLine %s\n", s); return s; @@ -196,7 +183,7 @@ char *def_home, *def_user, *def_shell; if (EventDebug(EDBUG_TYPE_CONFIG)) - Eprintf("ConfigFilePreparse %s->%s\n", path, dest); + Eprintf("ConfigFilePreparse %s -> %s\n", path, dest); def_home = homedir(getuid()); def_user = username(getuid()); @@ -241,9 +228,6 @@ while (GetLine(s, sizeof(s), fs)) { - if (IsWhitespace(s)) - continue; - i1 = i2 = CONFIG_INVALID; fields = sscanf(s, "%i %i", &i1, &i2); @@ -270,6 +254,7 @@ Alert(_("CONFIG: missing required data in \"%s\"\n"), s); } } + if (i2 == CONFIG_OPEN) { if (e_cfg_ver > max_e_cfg_ver) =================================================================== RCS file: /cvs/e/e16/e/src/sound.c,v retrieving revision 1.47 retrieving revision 1.48 diff -u -3 -r1.47 -r1.48 --- sound.c 8 Aug 2006 03:58:42 -0000 1.47 +++ sound.c 12 Aug 2006 10:33:47 -0000 1.48 @@ -334,59 +334,34 @@ #include "conf.h" static int -SoundConfigLoad(void) +SoundConfigLoad(FILE * fs) { int err = 0; SoundClass *sc; char s[FILEPATH_LEN_MAX]; char s1[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; - int i1, ret; - FILE *fs; - char *file; - - file = ConfigFileFind("sound.cfg", Mode.theme.path, 1); - if (!file) - return 0; - - fs = fopen(file, "r"); - Efree(file); - if (!fs) - goto done; + int i1, fields; while (GetLine(s, sizeof(s), fs)) { i1 = -1; - ret = sscanf(s, "%d", &i1); - if (ret == 1) - { - switch (i1) - { - case CONFIG_VERSION: - case CONFIG_OPEN: - break; - case CONFIG_CLOSE: - goto done; - } - } - else + fields = sscanf(s, "%d", &i1); + if (fields == 1) /* Just skip the numeric config stuff */ + continue; + + s1[0] = s2[0] = '\0'; + fields = sscanf(s, "%4000s %4000s", s1, s2); + if (fields != 2) { - s1[0] = s2[0] = '\0'; - ret = sscanf(s, "%4000s %4000s", s1, s2); - if (ret != 2) - { - Eprintf("Ignoring line: %s\n", s); - break; - } - sc = SclassCreate(s1, s2); + Eprintf("Ignoring line: %s\n", s); + continue; } + sc = SclassCreate(s1, s2); } if (err) ConfigAlertLoad(_("Sound")); - done: - if (fs) - fclose(fs); return err; } @@ -403,7 +378,7 @@ SoundInit(); break; case ESIGNAL_CONFIGURE: - SoundConfigLoad(); + ConfigFileLoad("sound.cfg", Mode.theme.path, SoundConfigLoad, 1); break; case ESIGNAL_START: if (!Conf_sound.enable) =================================================================== RCS file: /cvs/e/e16/e/src/windowmatch.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -3 -r1.49 -r1.50 --- windowmatch.c 24 Jul 2006 21:10:59 -0000 1.49 +++ windowmatch.c 12 Aug 2006 10:33:47 -0000 1.50 @@ -494,7 +494,7 @@ return buf; } -static void +static int WindowMatchConfigLoad2(FILE * fs) { char s[FILEPATH_LEN_MAX], *ss; @@ -513,26 +513,8 @@ WindowMatchDecode(s); } -} - -static void -WindowMatchConfigLoadConfig(void) -{ - char *file; - FILE *fs; - - file = ConfigFileFind("matches.cfg", NULL, 0); - if (!file) - return; - - fs = fopen(file, "r"); - Efree(file); - if (!fs) - return; - WindowMatchConfigLoad2(fs); - - fclose(fs); + return 0; } static int @@ -865,11 +847,11 @@ switch (sig) { case ESIGNAL_CONFIGURE: -#if 0 +#if 0 /* Done as part of theme loading */ ConfigFileLoad("windowmatches.cfg", Mode.theme.path, - WindowMatchConfigLoad); + WindowMatchConfigLoad, 1); #endif - WindowMatchConfigLoadConfig(); + ConfigFileLoad("matches.cfg", NULL, WindowMatchConfigLoad2, 0); #if 0 WindowMatchConfigLoadUser(); #endif ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs