Enlightenment CVS committal Author : kwo Project : e16 Module : e
Dir : e16/e/src Modified Files: file.c menus.c theme.c Log Message: Fix problem showing in theme menu if theme dir contains file beginning with '.' (as pointed out by Yasufumi Haga <[EMAIL PROTECTED]>) + associated cleanups. =================================================================== RCS file: /cvsroot/enlightenment/e16/e/src/file.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -3 -r1.61 -r1.62 --- file.c 27 Jun 2004 10:42:52 -0000 1.61 +++ file.c 12 Jul 2004 23:33:15 -0000 1.62 @@ -808,55 +808,26 @@ } char * -fileof(const char *s) +fileof(const char *path) { - char ss[1024]; - int i, p1, p2; + const char *s1, *s2; - EDBUG(9, "fileof"); - i = 0; - p1 = -1; - p2 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '.') && (p2 < 0) && (p1 < 0)) - p2 = i - 1; - if ((s[i] == '/') && (p1 < 0)) - p1 = i + 1; - } - if (p2 < 0) - p2 = strlen(s) - 1; - if (p1 < 0) - p1 = 0; - if (p2 <= 0) - EDBUG_RETURN(Estrdup("")); - for (i = 0; i <= (p2 - p1); i++) - ss[i] = s[p1 + i]; - ss[i] = 0; - EDBUG_RETURN(Estrdup(ss)); + s1 = strrchr(path, '/'); + s1 = (s1) ? s1 + 1 : path; + s2 = strrchr(s1, '.'); + if (!s2) + return Estrdup(s1); + + return Estrndup(s1, s2 - s1); } char * -fullfileof(const char *s) +fullfileof(const char *path) { - char ss[1024]; - int i, p1, p2; + const char *s; - EDBUG(9, "fullfileof"); - i = 0; - p1 = -1; - for (i = strlen(s) - 1; i >= 0; i--) - { - if ((s[i] == '/') && (p1 < 0)) - p1 = i + 1; - } - if (p1 < 0) - p1 = 0; - p2 = strlen(s); - for (i = 0; i < (p2 - p1); i++) - ss[i] = s[p1 + i]; - ss[i] = 0; - EDBUG_RETURN(Estrdup(ss)); + s = strrchr(path, '/'); + return Estrdup((s) ? s + 1 : path); } char * =================================================================== RCS file: /cvsroot/enlightenment/e16/e/src/menus.c,v retrieving revision 1.144 retrieving revision 1.145 diff -u -3 -r1.144 -r1.145 --- menus.c 4 Jul 2004 22:36:57 -0000 1.144 +++ menus.c 12 Jul 2004 23:33:15 -0000 1.145 @@ -423,7 +423,7 @@ if (iclass) iclass->ref_count++; - mi->text = (text) ? Estrdup(_(text)) : NULL; + mi->text = (text) ? Estrdup((text[0]) ? _(text) : "?!?") : NULL; mi->act_id = action_id; mi->params = Estrdup(action_params); mi->child = child; @@ -1708,20 +1708,17 @@ m = MenuCreate(name); m->style = ms; lst = ListThemes(&num); - if (lst) + for (i = 0; i < num; i++) { - for (i = 0; i < num; i++) - { - s = fullfileof(lst[i]); - Esnprintf(ss, sizeof(ss), "restart_theme %s", s); - Efree(s); - s = fileof(lst[i]); - mi = MenuItemCreate(s, NULL, ACTION_EXIT, ss, NULL); - MenuAddItem(m, mi); - Efree(s); - } - freestrlist(lst, i); + s = fullfileof(lst[i]); + Esnprintf(ss, sizeof(ss), "restart_theme %s", s); + mi = MenuItemCreate(s, NULL, ACTION_EXIT, ss, NULL); + Efree(s); + MenuAddItem(m, mi); } + if (lst) + freestrlist(lst, i); + EDBUG_RETURN(m); } =================================================================== RCS file: /cvsroot/enlightenment/e16/e/src/theme.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -3 -r1.36 -r1.37 --- theme.c 12 May 2004 00:06:19 -0000 1.36 +++ theme.c 12 Jul 2004 23:33:15 -0000 1.37 @@ -28,178 +28,130 @@ static char *badreason = NULL; static char mustdel = 0; +static const char *const theme_files[] = { #if ENABLE_THEME_SANITY_CHECKING + "borders.cfg", + "buttons.cfg", + "colormodifiers.cfg", + "control.cfg", + "cursors.cfg", + "desktops.cfg", + "imageclasses.cfg", +#endif + "init.cfg", +#if ENABLE_THEME_SANITY_CHECKING + "keybindings.cfg", + "menus.cfg", + "menustyles.cfg", + "slideouts.cfg", + "sound.cfg", + "tooltips.cfg", + "windowmatches.cfg", +#endif + NULL +}; -/* be paranoid and check for files being in theme */ -static char -SanitiseThemeDir(char *dir) +/* Check for files being in theme */ +static int +SanitiseThemeDir(const char *dir) { + const char *tf; + int i; char s[4096]; - return 1; - Esnprintf(s, sizeof(s), "%s/%s", dir, "borders.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a borders.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "buttons.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a buttons.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "colormodifiers.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a colormodifiers.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "cursors.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a cursors.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "desktops.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a desktops.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "imageclasses.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a imageclasses.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "init.cfg"); - if (!isfile(s)) + for (i = 0; (tf = theme_files[i]); i++) { - badreason = _("Theme does not contain a init.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "menustyles.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a menustyles.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "slideouts.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a slideouts.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "sound.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a sound.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "tooltips.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a tooltips.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "windowmatches.cfg"); - if (!isfile(s)) - { - badreason = _("Theme does not contain a windowmatches.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "menus.cfg"); - if (isfile(s)) - { - badreason = _("Theme contains a menus.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "control.cfg"); - if (isfile(s)) - { - badreason = _("Theme contains a control.cfg file\n"); - return 0; - } - Esnprintf(s, sizeof(s), "%s/%s", dir, "keybindings.cfg"); - if (isfile(s)) - { - badreason = _("Theme contains a keybindings.cfg file\n"); - return 0; + Esnprintf(s, sizeof(s), "%s/%s", dir, tf); + if (isfile(s)) + continue; +#if 0 + Esnprintf(s, sizeof(s), _("Theme %s does not contain a %s file\n"), dir, + tf); + badreason = Estrdup(s); +#endif + return -1; } - return 1; + return 0; } -#else +static const char * +ThemeCheckPath(const char *path) +{ + char s1[FILEPATH_LEN_MAX]; -#define SanitiseThemeDir(dir) 1 + Esnprintf(s1, sizeof(s1), "%s/epplets/epplets.cfg", path); + if (exists(s1)) + return path; /* OK */ -#endif /* ENABLE_THEME_SANITY_CHECKING */ + return NULL; /* Not OK */ +} static char * append_merge_dir(char *dir, char ***list, int *count) { char s[FILEPATH_LEN_MAX], ss[FILEPATH_LEN_MAX]; char **str = NULL, *def = NULL; - char already, *tmp, *tmp2, ok; + char already, *tmp, *tmp2; int i, j, num; str = E_ls(dir, &num); - if (str) + if (!str) + return NULL; + + for (i = 0; i < num; i++) { - for (i = 0; i < num; i++) + already = 0; + for (j = 0; (j < (*count)) && (!already); j++) { - already = 0; - for (j = 0; (j < (*count)) && (!already); j++) - { - tmp = fileof((*list)[j]); - tmp2 = fileof(str[i]); - if ((tmp != NULL) && (tmp2 != NULL) && (!strcmp(tmp, tmp2))) - already = 1; - if (tmp) - Efree(tmp); - if (tmp2) - Efree(tmp2); - } - if (!already) + tmp = fileof((*list)[j]); + tmp2 = fileof(str[i]); + if ((tmp != NULL) && (tmp2 != NULL) && (!strcmp(tmp, tmp2))) + already = 1; + if (tmp) + Efree(tmp); + if (tmp2) + Efree(tmp2); + } + + if (already) + continue; + + Esnprintf(ss, sizeof(ss), "%s/%s", dir, str[i]); + + if (!strcmp(str[i], "DEFAULT")) + { + if (readlink(ss, s, sizeof(s)) > 0) { - if (!strcmp(str[i], "DEFAULT")) - { - Esnprintf(ss, sizeof(ss), "%s/%s", dir, str[i]); - if (readlink(ss, s, sizeof(s)) > 0) - { - if (s[0] == '/') - def = Estrdup(s); - else - { - Esnprintf(s, sizeof(s), "%s/%s", dir, s); - def = Estrdup(s); - } - } - } + if (s[0] == '/') + def = Estrdup(s); else { - ok = 0; - - Esnprintf(s, sizeof(s), "%s/%s", dir, str[i]); - if ((isdir(s)) && (SanitiseThemeDir(s))) - ok = 1; - else if ((isfile(s)) && (FileExtension(s)) - && (!strcmp(FileExtension(s), "etheme"))) - ok = 1; - if (ok) - { - (*count)++; - (*list) = - Erealloc(*list, (*count) * sizeof(char *)); - - (*list)[(*count) - 1] = Estrdup(s); - } + Esnprintf(s, sizeof(s), "%s/%s", dir, s); + def = Estrdup(s); } } } - freestrlist(str, num); + else + { + if (isdir(ss)) + { + if (SanitiseThemeDir(ss)) + continue; + } + else if (isfile(ss)) + { + if (!FileExtension(ss) || strcmp(FileExtension(ss), "etheme")) + continue; + } + + (*count)++; + (*list) = Erealloc(*list, (*count) * sizeof(char *)); + + (*list)[(*count) - 1] = Estrdup(ss); + } } + freestrlist(str, num); + return def; } @@ -224,18 +176,6 @@ return list; } -static const char * -ThemeCheckPath(const char *path) -{ - char s1[FILEPATH_LEN_MAX]; - - Esnprintf(s1, sizeof(s1), "%s/epplets/epplets.cfg", path); - if (exists(s1)) - return path; /* OK */ - - return NULL; /* Not OK */ -} - static char * ThemeGetPath(const char *path) { @@ -385,7 +325,7 @@ } done: - if (oktheme && SanitiseThemeDir(oktheme)) + if (oktheme && !SanitiseThemeDir(oktheme)) EDBUG_RETURN(Estrdup(oktheme)); /* failed */ ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs