Fix problem showing in theme menu if theme dir contains file beginning with '.'

(as pointed out by Yasufumi Haga <yasufumi.haga@nifty.com>) + associated cleanups.


SVN revision: 10799
This commit is contained in:
Kim Woelders 2004-07-12 23:33:15 +00:00
parent dfca031c6c
commit aa37b28927
3 changed files with 119 additions and 211 deletions

View File

@ -808,55 +808,26 @@ canexec(const char *s)
}
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 *

View File

@ -423,7 +423,7 @@ MenuItemCreate(const char *text, ImageClass * iclass, int action_id,
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 @@ MenuCreateFromThemes(const char *name, MenuStyle * ms)
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);
}

View File

@ -28,178 +28,130 @@ static char *badtheme = NULL;
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))
for (i = 0; (tf = theme_files[i]); i++)
{
badreason = _("Theme does not contain a borders.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;
}
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))
{
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;
}
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)
continue;
Esnprintf(ss, sizeof(ss), "%s/%s", dir, str[i]);
if (!strcmp(str[i], "DEFAULT"))
{
if (readlink(ss, s, sizeof(s)) > 0)
{
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)
{
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 @@ ListThemes(int *number)
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 @@ ThemeExtract(const char *theme)
}
done:
if (oktheme && SanitiseThemeDir(oktheme))
if (oktheme && !SanitiseThemeDir(oktheme))
EDBUG_RETURN(Estrdup(oktheme));
/* failed */