diff --git a/src/E.h b/src/E.h index ea7d9241..8b0c5b3c 100644 --- a/src/E.h +++ b/src/E.h @@ -568,6 +568,8 @@ void EspawnCmd(const char *cmd); /* config.c */ void SkipTillEnd(FILE * ConfigFile); char *GetLine(char *s, int size, FILE * f); +int ConfigParseline1(char *str, char *s2, char **p2, char **p3); +void ConfigParseError(const char *where, const char *line); void ConfigAlertLoad(const char *txt); char *FindFile(const char *file, const char *themepath, int localized); @@ -578,7 +580,6 @@ int ConfigFileLoad(const char *name, const char *themepath, int (*parse) (FILE * fs), int preparse); int ConfigFileRead(FILE * fs); int ThemeConfigLoad(void); -void RecoverUserConfig(void); /* dialog.c */ void DialogOK(const char *title, const char *fmt, ...); diff --git a/src/aclass.c b/src/aclass.c index 9096ad41..070f5954 100644 --- a/src/aclass.c +++ b/src/aclass.c @@ -237,6 +237,8 @@ ActionclassFindGlobal(const char *name) ActionClass * ActionclassFind(const char *name) { + if (!name) + return NULL; return (ActionClass *) ecore_list_find(aclass_list, _ActionclassMatchName, name); } @@ -261,8 +263,9 @@ AclassConfigLoad(FILE * fs) ActionClass *ac = NULL; Action *aa = NULL; char s[FILEPATH_LEN_MAX]; - int i1; char s2[FILEPATH_LEN_MAX]; + char *p2; + int i1, i2; char event = 0; char anymod = 0; int mod = 0; @@ -270,47 +273,24 @@ AclassConfigLoad(FILE * fs) int but = 0; int first = 1; char anykey = 0; - char *key = NULL; + char key[64]; char *aclass_tooltipstring = NULL; char *action_tooltipstring = NULL; char global = 0; - int fields, len2, len; + + key[0] = '\0'; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %n%4000s %n", &i1, &len2, s2, &len); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE || i1 == CONFIG_NEXT) - { - if (fields != 1) - { - RecoverUserConfig(); - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - RecoverUserConfig(); - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - } - + i1 = ConfigParseline1(s, s2, &p2, NULL); + i2 = atoi(s2); switch (i1) { case CONFIG_VERSION: break; case CONFIG_ACTIONCLASS: err = -1; - i1 = atoi(s2); - if (i1 != CONFIG_OPEN) + if (i2 != CONFIG_OPEN) goto done; ac = NULL; aa = NULL; @@ -319,7 +299,7 @@ AclassConfigLoad(FILE * fs) mod = 0; but = 0; first = 1; - _EFREE(key); + key[0] = '\0'; break; case CONFIG_CLOSE: ac->tooltipstring = @@ -349,7 +329,7 @@ AclassConfigLoad(FILE * fs) break; case CONFIG_TYPE: case ACLASS_TYPE: - if (atoi(s2) == ACLASS_TYPE_ACLASS) + if (i2 == ACLASS_TYPE_ACLASS) break; ecore_list_node_remove(aclass_list, ActionclassFind(s2)); ecore_list_prepend(aclass_list_global, ac); @@ -371,7 +351,7 @@ AclassConfigLoad(FILE * fs) * #define Mod4Mask (1<<6) * #define Mod5Mask (1<<7) */ - switch (atoi(s2)) + switch (i2) { case MASK_NONE: mod = 0; @@ -445,27 +425,25 @@ AclassConfigLoad(FILE * fs) break; case CONFIG_ANYMOD: case ACLASS_ANYMOD: - anymod = atoi(s2); + anymod = i2; break; case CONFIG_ANYBUT: case ACLASS_ANYBUT: - anybut = atoi(s2); + anybut = i2; break; case CONFIG_BUTTON: case ACLASS_BUT: - but = atoi(s2); + but = i2; break; case CONFIG_ANYKEY: case ACLASS_ANYKEY: - anykey = atoi(s2); + anykey = i2; break; case ACLASS_KEY: - if (key) - Efree(key); - key = Estrdup(s2); + STRCPY(key, s2); break; case ACLASS_EVENT_TRIGGER: - event = atoi(s2); + event = i2; break; case CONFIG_NEXT: mod = 0; @@ -480,28 +458,22 @@ AclassConfigLoad(FILE * fs) key, action_tooltipstring); /* the correct place to grab an action key */ _EFREE(action_tooltipstring); - _EFREE(key); + key[0] = '\0'; if (global) GrabActionKey(aa); ActionclassAddAction(ac, aa); first = 0; } - ActionAddTo(aa, s + len2); + ActionAddTo(aa, p2); break; case CONFIG_ACTION_TOOLTIP: - action_tooltipstring = - Estrdupcat2(action_tooltipstring, "\n", s + len2); + action_tooltipstring = Estrdupcat2(action_tooltipstring, "\n", p2); break; case CONFIG_TOOLTIP: - aclass_tooltipstring = - Estrdupcat2(aclass_tooltipstring, "\n", s + len2); + aclass_tooltipstring = Estrdupcat2(aclass_tooltipstring, "\n", p2); break; default: - RecoverUserConfig(); - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current " - "ActionClass definition:\n" - "%s\nWill ignore and continue...\n"), s); + ConfigParseError("ActionClass", s); break; } } @@ -512,7 +484,6 @@ AclassConfigLoad(FILE * fs) done: _EFREE(aclass_tooltipstring); _EFREE(action_tooltipstring); - _EFREE(key); return err; } @@ -915,15 +886,23 @@ ActionclassSetTooltipString(ActionClass * ac, const char *tts) _EFDUP(ac->tooltipstring, tts); } -void -ActionclassIncRefcount(ActionClass * ac) +ActionClass * +ActionclassAlloc(const char *name) { + ActionClass *ac; + + if (!name || !name[0]) + return NULL; + + ac = ActionclassFind(name); if (ac) ac->ref_count++; + + return ac; } void -ActionclassDecRefcount(ActionClass * ac) +ActionclassFree(ActionClass * ac) { if (ac) ac->ref_count--; diff --git a/src/aclass.h b/src/aclass.h index 7e6346e6..90e61c65 100644 --- a/src/aclass.h +++ b/src/aclass.h @@ -38,8 +38,8 @@ void ActionclassAddAction(ActionClass * ac, Action * aa); void ActionclassSetTooltipString(ActionClass * ac, const char *tts); ActionClass *ActionclassFind(const char *name); -void ActionclassIncRefcount(ActionClass * ac); -void ActionclassDecRefcount(ActionClass * ac); +ActionClass *ActionclassAlloc(const char *name); +void ActionclassFree(ActionClass * ac); const char *ActionclassGetName(ActionClass * ac); const char *ActionclassGetTooltipString(ActionClass * ac); int ActionclassGetActionCount(ActionClass * ac); diff --git a/src/backgrounds.c b/src/backgrounds.c index 53d4f365..8ca8fa90 100644 --- a/src/backgrounds.c +++ b/src/backgrounds.c @@ -1123,7 +1123,6 @@ BackgroundsConfigLoad(FILE * fs) char *bg2 = 0; char *name = 0; char ignore = 0; - int fields; unsigned int desk; #if ENABLE_COLOR_MODIFIERS @@ -1134,31 +1133,7 @@ BackgroundsConfigLoad(FILE * fs) while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - ii1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &ii1, s2); - - if (fields < 1) - { - ii1 = CONFIG_INVALID; - } - else if (ii1 == CONFIG_CLOSE) - { - if (fields != 1) - { - RecoverUserConfig(); - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - } - else if (ii1 != CONFIG_INVALID) - { - if (fields != 2) - { - RecoverUserConfig(); - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - ii1 = CONFIG_INVALID; - } - } + ii1 = ConfigParseline1(s, s2, NULL, NULL); switch (ii1) { case CONFIG_CLOSE: @@ -2376,8 +2351,7 @@ BackgroundSet1(const char *name, const char *params) { const char *p = params; char type[FILEPATH_LEN_MAX]; - char valu[FILEPATH_LEN_MAX]; - int len; + int len, value; Background *bg; XColor xclr; @@ -2397,10 +2371,11 @@ BackgroundSet1(const char *name, const char *params) } } - type[0] = valu[0] = '\0'; + type[0] = '\0'; len = 0; - sscanf(p, "%400s %4000s %n", type, valu, &len); + sscanf(p, "%400s %n", type, &len); p += len; + value = atoi(p); if (!strcmp(type, "bg.solid")) { @@ -2414,57 +2389,57 @@ BackgroundSet1(const char *name, const char *params) { if (bg->bg.file) Efree(bg->bg.file); - bg->bg.file = Estrdup(valu); + bg->bg.file = Estrdup(p); } else if (!strcmp(type, "bg.tile")) { - bg->bg_tile = atoi(valu); + bg->bg_tile = value; } else if (!strcmp(type, "bg.keep_aspect")) { - bg->bg.keep_aspect = atoi(valu); + bg->bg.keep_aspect = value; } else if (!strcmp(type, "bg.xjust")) { - bg->bg.xjust = atoi(valu); + bg->bg.xjust = value; } else if (!strcmp(type, "bg.yjust")) { - bg->bg.yjust = atoi(valu); + bg->bg.yjust = value; } else if (!strcmp(type, "bg.xperc")) { - bg->bg.xperc = atoi(valu); + bg->bg.xperc = value; } else if (!strcmp(type, "bg.yperc")) { - bg->bg.yperc = atoi(valu); + bg->bg.yperc = value; } else if (!strcmp(type, "top.file")) { if (bg->top.file) Efree(bg->top.file); - bg->top.file = Estrdup(valu); + bg->top.file = Estrdup(p); } else if (!strcmp(type, "top.keep_aspect")) { - bg->top.keep_aspect = atoi(valu); + bg->top.keep_aspect = value; } else if (!strcmp(type, "top.xjust")) { - bg->top.xjust = atoi(valu); + bg->top.xjust = value; } else if (!strcmp(type, "top.yjust")) { - bg->top.yjust = atoi(valu); + bg->top.yjust = value; } else if (!strcmp(type, "top.xperc")) { - bg->top.xperc = atoi(valu); + bg->top.xperc = value; } else if (!strcmp(type, "top.yperc")) { - bg->top.yperc = atoi(valu); + bg->top.yperc = value; } else { diff --git a/src/borders.c b/src/borders.c index 54a0f2c2..da08d87a 100644 --- a/src/borders.c +++ b/src/borders.c @@ -406,13 +406,13 @@ EwinBorderCalcSizes(EWin * ewin, int propagate) EwinPropagateShapes(ewin); } -void +static void BorderIncRefcount(const Border * b) { ((Border *) b)->ref_count++; } -void +static void BorderDecRefcount(const Border * b) { ((Border *) b)->ref_count--; @@ -656,14 +656,10 @@ BorderDestroy(Border * b) for (i = 0; i < b->num_winparts; i++) { - if (b->part[i].iclass) - ImageclassDecRefcount(b->part[i].iclass); - if (b->part[i].tclass) - TextclassDecRefcount(b->part[i].tclass); - if (b->part[i].aclass) - ActionclassDecRefcount(b->part[i].aclass); - if (b->part[i].ec) - ECursorDecRefcount(b->part[i].ec); + ImageclassFree(b->part[i].iclass); + ActionclassFree(b->part[i].aclass); + TextclassFree(b->part[i].tclass); + ECursorFree(b->part[i].ec); } if (b->num_winparts > 0) @@ -673,8 +669,7 @@ BorderDestroy(Border * b) Efree(b->name); if (b->group_border_name) Efree(b->group_border_name); - if (b->aclass) - ActionclassDecRefcount(b->aclass); + ActionclassFree(b->aclass); } static int @@ -689,9 +684,27 @@ BorderFind(const char *name) return (Border *) ecore_list_find(border_list, _BorderMatchName, name); } +Border * +BorderAlloc(const char *name) +{ + Border *b; + + b = BorderFind(name); + if (b) + BorderIncRefcount(b); + + return b; +} + +void +BorderFree(Border * b) +{ + BorderDecRefcount(b); +} + static void -BorderWinpartAdd(Border * b, ImageClass * iclass, ActionClass * aclass, - TextClass * tclass, ECursor * ec, char ontop, int flags, +BorderWinpartAdd(Border * b, const char *iclass, const char *aclass, + const char *tclass, const char *cclass, char ontop, int flags, char isregion __UNUSED__, int wmin, int wmax, int hmin, int hmax, int torigin, int txp, int txa, int typ, int tya, int borigin, int bxp, int bxa, int byp, int bya, @@ -704,24 +717,10 @@ BorderWinpartAdd(Border * b, ImageClass * iclass, ActionClass * aclass, b->part = EREALLOC(WinPart, b->part, n); - if (!iclass) - iclass = ImageclassFind(NULL, 0); - - b->part[n - 1].iclass = iclass; - if (iclass) - ImageclassIncRefcount(iclass); - - b->part[n - 1].aclass = aclass; - if (aclass) - ActionclassIncRefcount(aclass); - - b->part[n - 1].tclass = tclass; - if (tclass) - TextclassIncRefcount(tclass); - - b->part[n - 1].ec = ec; - if (ec) - ECursorIncRefcount(ec); + b->part[n - 1].iclass = (iclass) ? ImageclassAlloc(iclass, 1) : NULL; + b->part[n - 1].aclass = (aclass) ? ActionclassAlloc(aclass) : NULL; + b->part[n - 1].tclass = (tclass) ? TextclassAlloc(tclass, 1) : NULL; + b->part[n - 1].ec = (cclass) ? ECursorAlloc(cclass) : NULL; b->part[n - 1].ontop = ontop; b->part[n - 1].flags = flags; @@ -1072,122 +1071,106 @@ BorderPartLoad(FILE * fs, char type __UNUSED__, Border * b) int err = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; - int i1; - ImageClass *iclass = 0; - ActionClass *aclass = 0; - TextClass *tclass = 0; - ECursor *ec = NULL; + int i1, i2; + char iclass[64], aclass[64], tclass[64], cclass[64]; + char *piclass, *paclass, *ptclass, *pcclass; char ontop = 1; int flags = FLAG_BUTTON; char isregion = 0, keepshade = 1; int wmin = 0, wmax = 0, hmin = 0, hmax = 0, torigin = 0, txp = 0, txa = 0, typ = 0, tya = 0, borigin = 0; int bxp = 0, bxa = 0, byp = 0, bya = 0; - int fields; + + piclass = paclass = ptclass = pcclass = NULL; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - i1 = CONFIG_INVALID; - } - } + i1 = ConfigParseline1(s, s2, NULL, NULL); + i2 = atoi(s2); switch (i1) { case CONFIG_CLOSE: - BorderWinpartAdd(b, iclass, aclass, tclass, ec, ontop, flags, - isregion, wmin, wmax, hmin, hmax, torigin, txp, - txa, typ, tya, borigin, bxp, bxa, byp, bya, - keepshade); + BorderWinpartAdd(b, piclass, paclass, ptclass, pcclass, ontop, + flags, isregion, wmin, wmax, hmin, hmax, + torigin, txp, txa, typ, tya, + borigin, bxp, bxa, byp, bya, keepshade); goto done; case CONFIG_IMAGECLASS: case BORDERPART_ICLASS: - iclass = ImageclassFind(s2, 1); + STRCPY(iclass, s2); + piclass = iclass; break; case CONFIG_ACTIONCLASS: case BORDERPART_ACLASS: - aclass = ActionclassFind(s2); + STRCPY(aclass, s2); + paclass = aclass; break; case CONFIG_TEXT: case BORDERPART_TEXTCLASS: - tclass = TextclassFind(s2, 1); + STRCPY(tclass, s2); + ptclass = tclass; break; case CONFIG_CURSOR: - ec = ECursorFind(s2); + STRCPY(cclass, s2); + pcclass = cclass; break; case BORDERPART_ONTOP: - ontop = atoi(s2); + ontop = i2; break; case BORDERPART_FLAGS: - flags = atoi(s2); + flags = i2; break; case BORDERPART_ISREGION: - isregion = atoi(s2); + isregion = i2; break; case BORDERPART_WMIN: - wmin = atoi(s2); + wmin = i2; if (!wmax) wmax = wmin; break; case BORDERPART_WMAX: - wmax = atoi(s2); + wmax = i2; break; case BORDERPART_HMIN: - hmin = atoi(s2); + hmin = i2; if (!hmax) hmax = hmin; break; case BORDERPART_HMAX: - hmax = atoi(s2); + hmax = i2; break; case BORDERPART_TORIGIN: - torigin = atoi(s2); + torigin = i2; break; case BORDERPART_TXP: - txp = atoi(s2); + txp = i2; break; case BORDERPART_TXA: - txa = atoi(s2); + txa = i2; break; case BORDERPART_TYP: - typ = atoi(s2); + typ = i2; break; case BORDERPART_TYA: - tya = atoi(s2); + tya = i2; break; case BORDERPART_BORIGIN: - borigin = atoi(s2); + borigin = i2; break; case BORDERPART_BXP: - bxp = atoi(s2); + bxp = i2; break; case BORDERPART_BXA: - bxa = atoi(s2); + bxa = i2; break; case BORDERPART_BYP: - byp = atoi(s2); + byp = i2; break; case BORDERPART_BYA: - bya = atoi(s2); + bya = i2; break; case BORDERPART_KEEPSHADE: - keepshade = atoi(s2); + keepshade = i2; break; default: break; @@ -1205,33 +1188,14 @@ BorderConfigLoad(FILE * fs) Border *b = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; - int i1; - int fields; + int i1, i2; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); + i1 = ConfigParseline1(s, s2, NULL, NULL); + i2 = atoi(s2); - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - i1 = CONFIG_INVALID; - } - } - if (atoi(s2) == CONFIG_OPEN) + if (i2 == CONFIG_OPEN) { err = BorderPartLoad(fs, i1, b); if (err) @@ -1258,22 +1222,22 @@ BorderConfigLoad(FILE * fs) b->group_border_name = Estrdup(s2); break; case BORDER_LEFT: - b->border.left = atoi(s2); + b->border.left = i2; break; case BORDER_RIGHT: - b->border.right = atoi(s2); + b->border.right = i2; break; case BORDER_TOP: - b->border.top = atoi(s2); + b->border.top = i2; break; case BORDER_BOTTOM: - b->border.bottom = atoi(s2); + b->border.bottom = i2; break; case SHADEDIR: - b->shadedir = atoi(s2); + b->shadedir = i2; break; case BORDER_CHANGES_SHAPE: - b->changes_shape = atoi(s2); + b->changes_shape = i2; break; case CONFIG_ACTIONCLASS: b->aclass = ActionclassFind(s2); @@ -1293,9 +1257,6 @@ Border * BorderCreateFiller(int left, int right, int top, int bottom) { Border *b; - ImageClass *ic; - - ic = ImageclassFind("__BLACK", 1); b = BorderCreate("__FILLER"); b->throwaway = 1; @@ -1306,20 +1267,20 @@ BorderCreateFiller(int left, int right, int top, int bottom) b->border.bottom = bottom; if (top) - BorderWinpartAdd(b, ic, NULL, NULL, NULL, 1, FLAG_BUTTON, 0, + BorderWinpartAdd(b, "__BLACK", NULL, NULL, NULL, 1, FLAG_BUTTON, 0, 1, 99999, 1, 99999, -1, 0, 0, 0, 0, -1, 1024, -1, 0, top - 1, 1); if (bottom) - BorderWinpartAdd(b, ic, NULL, NULL, NULL, 1, FLAG_BUTTON, 0, + BorderWinpartAdd(b, "__BLACK", NULL, NULL, NULL, 1, FLAG_BUTTON, 0, 1, 99999, 1, 99999, -1, 0, 0, 1024, -bottom, -1, 1024, -1, 1024, -1, 1); if (left) - BorderWinpartAdd(b, ic, NULL, NULL, NULL, 1, FLAG_BUTTON, 0, + BorderWinpartAdd(b, "__BLACK", NULL, NULL, NULL, 1, FLAG_BUTTON, 0, 1, 99999, 1, 99999, -1, 0, 0, 0, top, -1, 0, left - 1, 1024, -(bottom + 1), 1); if (right) - BorderWinpartAdd(b, ic, NULL, NULL, NULL, 1, FLAG_BUTTON, 0, + BorderWinpartAdd(b, "__BLACK", NULL, NULL, NULL, 1, FLAG_BUTTON, 0, 1, 99999, 1, 99999, -1, 1024, -right, 0, top, -1, 1024, -1, 1024, -(bottom + 1), 1); @@ -1362,12 +1323,16 @@ BordersSetupFallback(void) b->border.right = 8; b->border.top = 8; b->border.bottom = 8; - BorderWinpartAdd(b, ic, ac, NULL, NULL, 1, FLAG_BUTTON, 0, 8, 99999, 8, - 99999, -1, 0, 0, 0, 0, -1, 1024, -1, 0, 7, 1); - BorderWinpartAdd(b, ic, ac, NULL, NULL, 1, FLAG_BUTTON, 0, 8, 99999, 8, - 99999, -1, 0, 0, 1024, -8, -1, 1024, -1, 1024, -1, 1); - BorderWinpartAdd(b, ic, ac, NULL, NULL, 1, FLAG_BUTTON, 0, 8, 99999, 8, - 99999, -1, 0, 0, 0, 8, -1, 0, 7, 1024, -9, 1); - BorderWinpartAdd(b, ic, ac, NULL, NULL, 1, FLAG_BUTTON, 0, 8, 99999, 8, - 99999, -1, 1024, -8, 0, 8, -1, 1024, -1, 1024, -9, 1); + BorderWinpartAdd(b, "__FALLBACK_ICLASS", "__FALLBACK_ACTION", NULL, NULL, + 1, FLAG_BUTTON, 0, 8, 99999, 8, 99999, -1, 0, 0, 0, 0, + -1, 1024, -1, 0, 7, 1); + BorderWinpartAdd(b, "__FALLBACK_ICLASS", "__FALLBACK_ACTION", NULL, NULL, + 1, FLAG_BUTTON, 0, 8, 99999, 8, 99999, -1, 0, 0, 1024, + -8, -1, 1024, -1, 1024, -1, 1); + BorderWinpartAdd(b, "__FALLBACK_ICLASS", "__FALLBACK_ACTION", NULL, NULL, + 1, FLAG_BUTTON, 0, 8, 99999, 8, 99999, -1, 0, 0, 0, 8, + -1, 0, 7, 1024, -9, 1); + BorderWinpartAdd(b, "__FALLBACK_ICLASS", "__FALLBACK_ACTION", NULL, NULL, + 1, FLAG_BUTTON, 0, 8, 99999, 8, 99999, -1, 1024, -8, 0, + 8, -1, 1024, -1, 1024, -9, 1); } diff --git a/src/borders.h b/src/borders.h index f4d5896b..3d58da79 100644 --- a/src/borders.h +++ b/src/borders.h @@ -89,8 +89,8 @@ struct _ewinbit /* borders.c */ Border *BorderFind(const char *name); -void BorderIncRefcount(const Border * b); -void BorderDecRefcount(const Border * b); +Border *BorderAlloc(const char *name); +void BorderFree(Border * b); const char *BorderGetName(const Border * b); int BorderConfigLoad(FILE * fs); void EwinBorderSelect(EWin * ewin); diff --git a/src/buttons.c b/src/buttons.c index 8ce3fa55..fbd9bf88 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -88,6 +88,7 @@ static struct static void ButtonHandleEvents(Win win, XEvent * ev, void *btn); +#if 0 /* Unused */ void ButtonIncRefcount(Button * b) { @@ -99,6 +100,7 @@ ButtonDecRefcount(Button * b) { b->ref_count--; } +#endif static int ButtonIsFixed(const Button * b) @@ -113,8 +115,8 @@ ButtonIsInternal(const Button * b) } Button * -ButtonCreate(const char *name, int id, ImageClass * iclass, - ActionClass * aclass, TextClass * tclass, const char *label, +ButtonCreate(const char *name, int id, const char *iclass, + const char *aclass, const char *tclass, const char *label, char ontop, int flags, int minw, int maxw, int minh, int maxh, int xo, int yo, int xa, int xr, int ya, int yr, int xsr, int xsa, int ysr, int ysa, char simg, int desk, char sticky) @@ -136,21 +138,10 @@ ButtonCreate(const char *name, int id, ImageClass * iclass, b->id = id; b->label = Estrdup(label); - b->iclass = iclass; - if (!b->iclass) - b->iclass = ImageclassFind(NULL, 0); - if (b->iclass) - ImageclassIncRefcount(b->iclass); - - b->aclass = aclass; - if (b->aclass) - ActionclassIncRefcount(b->aclass); - - b->tclass = tclass; - if (!b->tclass && b->label) - b->tclass = TextclassFind(NULL, 0); - if (b->tclass) - TextclassIncRefcount(b->tclass); + b->iclass = ImageclassAlloc(iclass, 1); + b->aclass = ActionclassAlloc(aclass); + if (b->label) + b->tclass = TextclassAlloc(tclass, 1); b->flags = flags; b->geom.width.min = minw; @@ -198,14 +189,9 @@ ButtonDestroy(Button * b) EoFini(b); - if (b->iclass) - ImageclassDecRefcount(b->iclass); - - if (b->aclass) - ActionclassDecRefcount(b->aclass); - - if (b->tclass) - TextclassDecRefcount(b->tclass); + ImageclassFree(b->iclass); + ActionclassFree(b->aclass); + TextclassFree(b->tclass); if (b->label) Efree(b->label); @@ -246,7 +232,7 @@ ButtonCalc(Button * b) else { if (!b->iclass) - b->iclass = ImageclassFind(NULL, 0); + b->iclass = ImageclassAlloc(NULL, 1); w = 32; h = 32; } @@ -670,17 +656,15 @@ ButtonHandleEvents(Win win __UNUSED__, XEvent * ev, void *prm) #include "conf.h" int -ButtonsConfigLoad(FILE * ConfigFile) +ButtonsConfigLoad(FILE * fs) { int err = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; - int i1; - char *name = NULL; - char *label = NULL; - ActionClass *ac = NULL; - ImageClass *ic = NULL; - TextClass *tc = NULL; + char *p2; + int i1, i2; + char name[64], label[64]; + char iclass[64], aclass[64], tclass[64]; Button *bt = NULL; Button *pbt = NULL; char ontop = 0; @@ -693,185 +677,136 @@ ButtonsConfigLoad(FILE * ConfigFile) char sticky = 0; char show = 1; char internal = 0; - int fields, len; - while (GetLine(s, sizeof(s), ConfigFile)) + name[0] = label[0] = '\0'; + iclass[0] = aclass[0] = tclass[0] = '\0'; + + while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - len = 0; - fields = sscanf(s, "%i %4000s %n", &i1, s2, &len); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - { - RecoverUserConfig(); - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - RecoverUserConfig(); - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - i1 = CONFIG_INVALID; - } - } + i1 = ConfigParseline1(s, s2, &p2, NULL); + i2 = atoi(s2); switch (i1) { case CONFIG_CLOSE: if (!pbt && !Mode_buttons.loading_user) { - bt = ButtonCreate(name, 0, ic, ac, tc, label, ontop, flags, - minw, maxw, minh, maxh, xo, yo, xa, xr, - ya, yr, xsr, xsa, ysr, ysa, simg, desk, - sticky); + bt = ButtonCreate(name, 0, iclass, aclass, tclass, label, + ontop, flags, minw, maxw, minh, maxh, + xo, yo, xa, xr, ya, yr, xsr, xsa, ysr, ysa, + simg, desk, sticky); bt->default_show = show; bt->internal = internal; } - goto done; - case CONFIG_TEXT: - tc = TextclassFind(s2, 1); - if (pbt) - pbt->tclass = tc; - break; - case BUTTON_LABEL: - _EFREE(label); - label = Estrdup(s + len); - if (pbt) + else if (pbt) { - _EFREE(pbt->label); - pbt->label = label; + _EFDUP(pbt->label, label); + EoSetLayer(pbt, ontop); + EoSetSticky(pbt, sticky); + ButtonMoveToDesktop(pbt, DeskGet(desk)); + pbt->iclass = ImageclassFind(iclass, 1); + pbt->aclass = ActionclassFind(aclass); + pbt->tclass = TextclassFind(tclass, 1); + pbt->flags = flags; + pbt->internal = internal; + pbt->default_show = show; + pbt->geom.width.min = minw; + pbt->geom.width.max = maxw; + pbt->geom.height.min = minh; + pbt->geom.height.max = maxh; + pbt->geom.xorigin = xo; + pbt->geom.yorigin = yo; + pbt->geom.xabs = xa; + pbt->geom.xrel = xr; + pbt->geom.yabs = ya; + pbt->geom.yrel = yr; + pbt->geom.xsizerel = xsr; + pbt->geom.xsizeabs = xsa; + pbt->geom.ysizerel = ysr; + pbt->geom.ysizeabs = ysa; + pbt->geom.size_from_image = simg; } - break; - case BORDERPART_ONTOP: - ontop = atoi(s2); - if (pbt) - EoSetLayer(pbt, ontop); - break; + goto done; case CONFIG_CLASSNAME: case BUTTON_NAME: - _EFREE(name); - name = Estrdup(s2); + STRCPY(name, s2); pbt = ButtonFind(name); break; - case CONFIG_ACTIONCLASS: - case BUTTON_ACLASS: - ac = ActionclassFind(s2); - if (pbt) - pbt->aclass = ac; + case BUTTON_LABEL: + STRCPY(label, s2); break; case CONFIG_IMAGECLASS: case BUTTON_ICLASS: - ic = ImageclassFind(s2, 1); - if (pbt) - pbt->iclass = ic; + STRCPY(iclass, s2); + break; + case CONFIG_ACTIONCLASS: + case BUTTON_ACLASS: + STRCPY(aclass, s2); + break; + case CONFIG_TEXT: + STRCPY(tclass, s2); + break; + case BORDERPART_ONTOP: + ontop = i2; break; case BORDERPART_WMIN: - minw = atoi(s2); - if (pbt) - pbt->geom.width.min = minw; + minw = i2; break; case BORDERPART_WMAX: - maxw = atoi(s2); - if (pbt) - pbt->geom.width.max = maxw; + maxw = i2; break; case BORDERPART_HMIN: - minh = atoi(s2); - if (pbt) - pbt->geom.height.min = minh; + minh = i2; break; case BORDERPART_FLAGS: - flags = atoi(s2); - if (pbt) - pbt->flags = flags; + flags = i2; break; case BORDERPART_HMAX: - maxh = atoi(s2); - if (pbt) - pbt->geom.height.max = maxh; + maxh = i2; break; case BUTTON_XO: - xo = atoi(s2); - if (pbt) - pbt->geom.xorigin = xo; + xo = i2; break; case BUTTON_YO: - yo = atoi(s2); - if (pbt) - pbt->geom.yorigin = yo; + yo = i2; break; case BUTTON_XA: - xa = atoi(s2); - if (pbt) - pbt->geom.xabs = xa; + xa = i2; break; case BUTTON_XR: - xr = atoi(s2); - if (pbt) - pbt->geom.xrel = xr; + xr = i2; break; case BUTTON_YA: - ya = atoi(s2); - if (pbt) - pbt->geom.yabs = ya; + ya = i2; break; case BUTTON_YR: - yr = atoi(s2); - if (pbt) - pbt->geom.yrel = yr; + yr = i2; break; case BUTTON_XSR: - xsr = atoi(s2); - if (pbt) - pbt->geom.xsizerel = xsr; + xsr = i2; break; case BUTTON_XSA: - xsa = atoi(s2); - if (pbt) - pbt->geom.xsizeabs = xsa; + xsa = i2; break; case BUTTON_YSR: - ysr = atoi(s2); - if (pbt) - pbt->geom.ysizerel = ysr; + ysr = i2; break; case BUTTON_YSA: - ysa = atoi(s2); - if (pbt) - pbt->geom.ysizeabs = ysa; + ysa = i2; break; case BUTTON_SIMG: - simg = atoi(s2); - if (pbt) - pbt->geom.size_from_image = simg; + simg = i2; break; case BUTTON_DESK: - desk = atoi(s2); - if (pbt) - ButtonMoveToDesktop(pbt, DeskGet(desk)); + desk = i2; break; case BUTTON_STICKY: - sticky = atoi(s2); - if (pbt) - EoSetSticky(pbt, sticky); + sticky = i2; break; case BUTTON_INTERNAL: - internal = atoi(s2); - if (pbt) - pbt->internal = internal; + internal = i2; break; case BUTTON_SHOW: - show = atoi(s2); - if (pbt) - pbt->default_show = show; + show = i2; break; default: break; @@ -880,9 +815,6 @@ ButtonsConfigLoad(FILE * ConfigFile) err = -1; done: - _EFREE(name); - _EFREE(label); - return err; } diff --git a/src/buttons.h b/src/buttons.h index 102100f2..da273885 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -30,9 +30,8 @@ typedef void (ButtonCbFunc) (EObj * eo, XEvent * ev, ActionClass * ac); /* buttons.c */ -Button *ButtonCreate(const char *name, int id, - ImageClass * ic, - ActionClass * ac, TextClass * tc, +Button *ButtonCreate(const char *name, int id, const char *iclass, + const char *aclass, const char *tclass, const char *label, char ontop, int flags, int minw, int maxw, int minh, int maxh, int xo, int yo, int xa, int xr, int ya, int yr, @@ -44,8 +43,6 @@ void ButtonShow(Button * b); void ButtonHide(Button * b); void ButtonMoveToCoord(Button * b, int x, int y); void ButtonMoveRelative(Button * b, int dx, int dy); -void ButtonIncRefcount(Button * b); -void ButtonDecRefcount(Button * b); void ButtonSwallowInto(Button * b, EObj * eo); void ButtonSetCallback(Button * b, ButtonCbFunc * func, EObj * eo); diff --git a/src/cmclass.c b/src/cmclass.c index ef17607c..4c353f7e 100644 --- a/src/cmclass.c +++ b/src/cmclass.c @@ -167,6 +167,7 @@ ColorModifierConfigLoad(FILE * fs) int err = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; + char *p2; int i1; char *name = NULL; const char *params = NULL; @@ -180,36 +181,10 @@ ColorModifierConfigLoad(FILE * fs) int i = 0, tx, ty; int rnum = 0, gnum = 0, bnum = 0; ColorModifierClass *cm; - int fields, len2; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i = 0; - i1 = CONFIG_INVALID; - len2 = 0; - fields = sscanf(s, "%i %n%4000s", &i1, &len2, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - { - RecoverUserConfig(); - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - RecoverUserConfig(); - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - } + i1 = ConfigParseline1(s, s2, &p2, NULL); switch (i1) { case CONFIG_CLOSE: @@ -231,7 +206,7 @@ ColorModifierConfigLoad(FILE * fs) name = Estrdup(s2); break; case COLORMOD_RED: - params = (s[len2]) ? s + len2 : NULL; + params = p2; current_param = params; if (!current_param) goto done; @@ -263,7 +238,7 @@ ColorModifierConfigLoad(FILE * fs) rnum = i; break; case COLORMOD_GREEN: - params = (s[len2]) ? s + len2 : NULL; + params = p2; current_param = params; if (!current_param) goto done; @@ -295,7 +270,7 @@ ColorModifierConfigLoad(FILE * fs) gnum = i; break; case COLORMOD_BLUE: - params = (s[len2]) ? s + len2 : NULL; + params = p2; current_param = params; if (!current_param) goto done; @@ -327,11 +302,7 @@ ColorModifierConfigLoad(FILE * fs) bnum = i; break; default: - RecoverUserConfig(); - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current " - " ColorModifier definition:\n" - "%s\nWill ignore and continue...\n"), s); + ConfigParseError("ColorModifier", s); break; } } diff --git a/src/config.c b/src/config.c index 8b83d5bc..7793aee9 100644 --- a/src/config.c +++ b/src/config.c @@ -38,19 +38,19 @@ #include "windowmatch.h" void -SkipTillEnd(FILE * ConfigFile) +SkipTillEnd(FILE * fs) { char s[FILEPATH_LEN_MAX]; int i1, i2, fields; - while (GetLine(s, sizeof(s), ConfigFile)) + while (GetLine(s, sizeof(s), fs)) { i1 = i2 = 0; fields = sscanf(s, "%i %i", &i1, &i2); if (i1 == CONFIG_CLOSE) return; if (i2 == CONFIG_OPEN) - SkipTillEnd(ConfigFile); + SkipTillEnd(fs); } } @@ -170,10 +170,54 @@ GetLine(char *s, int size, FILE * f) return s; } +int +ConfigParseline1(char *str, char *s2, char **p2, char **p3) +{ + int i1, len1, len2, fields; + + i1 = CONFIG_INVALID; + len1 = len2 = 0; + s2[0] = '\0'; + fields = sscanf(str, "%i %n%4000s %n", &i1, &len1, s2, &len2); + if (p2) + *p2 = (len1) ? str + len1 : NULL; + if (p3) + *p3 = (len2) ? str + len2 : NULL; + + if (fields <= 0) + { + i1 = CONFIG_INVALID; + } + else if (i1 == CONFIG_CLOSE || i1 == CONFIG_NEXT) + { + if (fields != 1) + { + Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), str); + } + } + else if (i1 != CONFIG_INVALID) + { + if (fields != 2) + { + i1 = CONFIG_INVALID; + Alert(_("CONFIG: missing required data in \"%s\"\n"), str); + } + } + + return i1; +} + +void +ConfigParseError(const char *where, const char *line) +{ + Alert(_("Warning: unable to determine what to do with\n" + "the following text in the middle of current %s definition:\n" + "%s\nWill ignore and continue...\n"), where, line); +} + void ConfigAlertLoad(const char *txt) { - RecoverUserConfig(); Alert(_("Warning: Configuration error in %s block.\n" "Outcome is likely not good.\n"), txt); } @@ -235,7 +279,9 @@ ConfigFileRead(FILE * fs) fields = sscanf(s, "%i %i", &i1, &i2); if (fields < 1) - i1 = CONFIG_INVALID; + { + i1 = CONFIG_INVALID; + } else if (i1 == CONFIG_VERSION) { if (fields == 2) @@ -245,7 +291,6 @@ ConfigFileRead(FILE * fs) { if (fields != 1) { - RecoverUserConfig(); Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); } } @@ -253,8 +298,8 @@ ConfigFileRead(FILE * fs) { if (fields != 2) { - RecoverUserConfig(); Alert(_("CONFIG: missing required data in \"%s\"\n"), s); + i1 = CONFIG_INVALID; } } @@ -585,26 +630,3 @@ ThemeConfigLoad(void) return 0; } - -void -RecoverUserConfig(void) -{ - int save; - - /* Don't save settings if we restart or quit */ - save = Conf.autosave; - Conf.autosave = 0; - - AlertX(_("Recover system config?"), _("Yes, Attempt recovery"), - _("Restart and try again"), _("Quit and give up"), - _ - ("Enlightenment has encountered parsing errors in your autosaved\n" - "configuration.\n" "\n" - "This may be due to filing system errors, Minor bugs or " - "unforeseen\n" "system shutdowns.\n" "\n" - "Do you wish Enlightenment to recover its original system\n" - "configuration and try again?\n")); - - /* Allow settings to be saved if we continue */ - Conf.autosave = save; -} diff --git a/src/container.c b/src/container.c index 36ce0fc3..2de59652 100644 --- a/src/container.c +++ b/src/container.c @@ -1752,39 +1752,27 @@ ContainersConfigLoad(void) char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; int i1, i2; - int fields; - Container *ct; + Container *ct, ct_dummy; Esnprintf(s, sizeof(s), "%s.ibox", EGetSavePrefix()); fs = fopen(s, "r"); if (!fs) return; - ct = NULL; + ct = &ct_dummy; while (fgets(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - i1 = CONFIG_INVALID; - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - + i1 = ConfigParseline1(s, s2, NULL, NULL); + i2 = atoi(s2); switch (i1) { case CONFIG_IBOX: err = -1; - i2 = atoi(s2); if (i2 != CONFIG_OPEN) goto done; break; case CONFIG_CLOSE: - ct = NULL; + ct = &ct_dummy; err = 0; break; @@ -1795,56 +1783,43 @@ ContainersConfigLoad(void) ct = ContainerCreate(s2); break; case TEXT_ORIENTATION: /* __ORIENTATION [ __HORIZONTAL | __VERTICAL ] */ - if (ct) - ct->orientation = (char)atoi(s2); + ct->orientation = i2; break; case CONFIG_TRANSPARENCY: /* __TRANSPARENCY [ __ON | __OFF ] */ - if (ct) - ct->nobg = (char)atoi(s2); + ct->nobg = i2; break; case CONFIG_SHOW_NAMES: /* __SHOW_NAMES [ __ON | __OFF ] */ - if (ct) - ct->shownames = (char)atoi(s2); + ct->shownames = i2; break; case CONFIG_ICON_SIZE: /* __ICON_SIZE %i */ - if (ct) - ct->iconsize = (int)atoi(s2); + ct->iconsize = i2; break; case CONFIG_ICON_MODE: /* __ICON_MODE [ 0 | 1 | 2 | 3 | 4 ] */ - if (ct) - ct->icon_mode = (int)atoi(s2); + ct->icon_mode = i2; break; case CONFIG_SCROLLBAR_SIDE: /* __SCROLLBAR_SIDE [ __BAR_LEFT/__BAR_TOP | __BAR_RIGHT/__BAR_BOTTOM ] */ - if (ct) - ct->scrollbar_side = (char)atoi(s2); + ct->scrollbar_side = i2; break; case CONFIG_SCROLLBAR_ARROWS: /* __SCROLLBAR_ARROWS [ __START | __BOTH | __FINISH | __NEITHER ] */ - if (ct) - ct->arrow_side = (char)atoi(s2); + ct->arrow_side = i2; break; case CONFIG_AUTOMATIC_RESIZE: /* __AUTOMATIC_RESIZE [ __ON | __OFF ] */ - if (ct) - ct->auto_resize = (char)atoi(s2); + ct->auto_resize = i2; break; case CONFIG_SHOW_ICON_BASE: /* __SHOW_ICON_BASE [ __ON | __OFF ] */ - if (ct) - ct->draw_icon_base = (char)atoi(s2); + ct->draw_icon_base = i2; break; case CONFIG_SCROLLBAR_AUTOHIDE: /* __SCROLLBAR_AUTOHIDE [ __ON | __OFF ] */ - if (ct) - ct->scrollbar_hide = (char)atoi(s2); + ct->scrollbar_hide = i2; break; case CONFIG_COVER_HIDE: /* __COVER_HIDE [ __ON | __OFF ] */ - if (ct) - ct->cover_hide = (char)atoi(s2); + ct->cover_hide = i2; break; case CONFIG_RESIZE_ANCHOR: /* __RESIZE_ANCHOR 0-1024 */ - if (ct) - ct->auto_resize_anchor = atoi(s2); + ct->auto_resize_anchor = i2; break; case CONFIG_IB_ANIMATE: /* __ICONBOX_ANIMATE [ 0 | 1 | 2 ] */ - if (ct) - ct->anim_mode = atoi(s2); + ct->anim_mode = i2; break; default: Eprintf("Warning: Iconbox configuration, ignoring: %s\n", s); diff --git a/src/cursors.c b/src/cursors.c index eabbde76..10fec215 100644 --- a/src/cursors.c +++ b/src/cursors.c @@ -35,9 +35,6 @@ struct _ecursor char *file; Cursor cursor; unsigned int ref_count; -#if 0 /* Not used */ - char inroot; -#endif }; static Ecore_List *cursor_list = NULL; @@ -105,9 +102,6 @@ ECursorCreate(const char *name, const char *image, int native_id, XColor * fg, ec->file = Estrdup(image); ec->cursor = curs; ec->ref_count = 0; -#if 0 /* Not used */ - ec->inroot = 0; -#endif if (!cursor_list) cursor_list = ecore_list_new(); @@ -146,9 +140,33 @@ _ECursorMatchName(const void *data, const void *match) ECursor * ECursorFind(const char *name) { + if (!name || !name[0]) + return NULL; return (ECursor *) ecore_list_find(cursor_list, _ECursorMatchName, name); } +ECursor * +ECursorAlloc(const char *name) +{ + ECursor *ec; + + if (!name) + return NULL; + + ec = ECursorFind(name); + if (ec) + ec->ref_count++; + + return ec; +} + +void +ECursorFree(ECursor * ec) +{ + if (ec) + ec->ref_count--; +} + static int ECursorConfigLoad(FILE * fs) { @@ -156,35 +174,17 @@ ECursorConfigLoad(FILE * fs) XColor xclr, xclr2; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; + char *p2; int i1, i2, r, g, b; - char *file = NULL, *name = NULL; + char name[FILEPATH_LEN_MAX], *pname; + char file[FILEPATH_LEN_MAX], *pfile; int native_id = -1; - int fields; + + pname = pfile = NULL; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - continue; - } - } - + i1 = ConfigParseline1(s, s2, &p2, NULL); switch (i1) { case CONFIG_CURSOR: @@ -194,12 +194,11 @@ ECursorConfigLoad(FILE * fs) goto done; ESetColor(&xclr, 0, 0, 0); ESetColor(&xclr2, 255, 255, 255); - _EFREE(file); - _EFREE(name); + pname = pfile = NULL; native_id = -1; break; case CONFIG_CLOSE: - ECursorCreate(name, file, native_id, &xclr, &xclr2); + ECursorCreate(pname, pfile, native_id, &xclr, &xclr2); err = 0; break; @@ -209,23 +208,25 @@ ECursorConfigLoad(FILE * fs) SkipTillEnd(fs); goto done; } - _EFDUP(name, s2); + strcpy(name, s2); + pname = name; break; case CURS_BG_RGB: r = g = b = 0; - sscanf(s, "%4000s %d %d %d", s2, &r, &g, &b); + sscanf(p2, "%d %d %d", &r, &g, &b); ESetColor(&xclr, r, g, b); break; case CURS_FG_RGB: r = g = b = 255; - sscanf(s, "%4000s %d %d %d", s2, &r, &g, &b); + sscanf(p2, "%d %d %d", &r, &g, &b); ESetColor(&xclr2, r, g, b); break; case XBM_FILE: - _EFDUP(file, s2); + strcpy(file, s2); + pfile = file; break; case NATIVE_ID: - sscanf(s, "%4000s %d", s2, &native_id); + native_id = atoi(s2); break; default: break; @@ -236,9 +237,6 @@ ECursorConfigLoad(FILE * fs) if (err) ConfigAlertLoad("Cursor"); - _EFREE(name); - _EFREE(file); - return err; } @@ -248,10 +246,6 @@ ECursorApply(ECursor * ec, Win win) if (!ec) return; XDefineCursor(disp, WinGetXwin(win), ec->cursor); -#if 0 /* Not used */ - if (win == VRoot.xwin) - ec->inroot = 1; -#endif } static Cursor @@ -259,40 +253,15 @@ ECursorGetByName(const char *name, const char *name2, unsigned int fallback) { ECursor *ec; - ec = ECursorFind(name); + ec = ECursorAlloc(name); if (!ec && name2) - ec = ECursorFind(name2); + ec = ECursorAlloc(name2); if (ec) - { - ECursorIncRefcount(ec); - return ec->cursor; - } + return ec->cursor; return XCreateFontCursor(disp, fallback); } -void -ECursorIncRefcount(ECursor * ec) -{ - if (ec) - ec->ref_count++; -} - -void -ECursorDecRefcount(ECursor * ec) -{ - if (ec) - ec->ref_count--; -} - -#if 0 /* Not used */ -static int -ECursorGetRefcount(ECursor * ec) -{ - return (ec) ? ec->ref_count : 0; -} -#endif - static Cursor ECsrs[ECSR_COUNT]; Cursor diff --git a/src/cursors.h b/src/cursors.h index 7335dcc0..781b5b34 100644 --- a/src/cursors.h +++ b/src/cursors.h @@ -42,9 +42,9 @@ #define ECSR_COUNT 12 ECursor *ECursorFind(const char *name); +ECursor *ECursorAlloc(const char *name); +void ECursorFree(ECursor * ec); void ECursorApply(ECursor * ec, Win win); -void ECursorIncRefcount(ECursor * ec); -void ECursorDecRefcount(ECursor * ec); Cursor ECsrGet(int which); void ECsrApply(int which, Window win); diff --git a/src/desktops.c b/src/desktops.c index 150e949d..1db1fd93 100644 --- a/src/desktops.c +++ b/src/desktops.c @@ -77,9 +77,10 @@ static void DeskControlsCreate(Desk * dsk) { char s[512]; - ActionClass *ac, *ac2, *ac3; - ImageClass *ic, *ic2, *ic3; + const char *ic1, *ic2, *ic3; + char ac1[64], ac2[64], ac3[64]; Button *b; + ActionClass *ac; Action *a; int x[3], y[3], w[3], h[3], m, n, o; const char *t; @@ -97,11 +98,10 @@ DeskControlsCreate(Desk * dsk) else if (Conf.desks.dragbar_length > VRoot.w) Conf.desks.dragbar_length = VRoot.w; - Esnprintf(s, sizeof(s), "DRAGBAR_DESKTOP_%i", dsk->num); - ac = ActionclassFind(s); - if (!ac) + Esnprintf(ac1, sizeof(ac1), "DRAGBAR_DESKTOP_%i", dsk->num); + if (!ActionclassFind(ac1)) { - ac = ActionclassCreate(s, 0); + ac = ActionclassCreate(ac1, 0); a = ActionCreate(EVENT_MOUSE_DOWN, 0, 0, 0, 1, 0, NULL, NULL); ActionclassAddAction(ac, a); @@ -139,50 +139,48 @@ DeskControlsCreate(Desk * dsk) } } - Esnprintf(s, sizeof(s), "RAISEBUTTON_DESKTOP_%i", dsk->num); - ac2 = ActionclassFind(s); - if (!ac2) + Esnprintf(ac2, sizeof(ac2), "RAISEBUTTON_DESKTOP_%i", dsk->num); + if (!ActionclassFind(ac2)) { - ac2 = ActionclassCreate(s, 0); + ac = ActionclassCreate(ac2, 0); a = ActionCreate(EVENT_MOUSE_UP, 1, 0, 1, 0, 0, NULL, NULL); - ActionclassAddAction(ac2, a); + ActionclassAddAction(ac, a); Esnprintf(s, sizeof(s), "desk raise %i", dsk->num); ActionAddTo(a, s); t = _("Click here to raise this desktop\nto the top.\n"); - ActionclassSetTooltipString(ac2, t); + ActionclassSetTooltipString(ac, t); } - Esnprintf(s, sizeof(s), "LOWERBUTTON_DESKTOP_%i", dsk->num); - ac3 = ActionclassFind(s); - if (!ac3) + Esnprintf(ac3, sizeof(ac3), "LOWERBUTTON_DESKTOP_%i", dsk->num); + if (!ActionclassFind(ac3)) { - ac3 = ActionclassCreate(s, 0); + ac = ActionclassCreate(ac3, 0); a = ActionCreate(EVENT_MOUSE_UP, 1, 0, 1, 0, 0, NULL, NULL); - ActionclassAddAction(ac3, a); + ActionclassAddAction(ac, a); Esnprintf(s, sizeof(s), "desk lower %i", dsk->num); ActionAddTo(a, s); t = _("Click here to lower this desktop\nto the bottom.\n"); - ActionclassSetTooltipString(ac3, t); + ActionclassSetTooltipString(ac, t); } if (Conf.desks.dragdir < 2) { - ic = ImageclassFind("DESKTOP_DRAGBUTTON_VERT", 0); - ic2 = ImageclassFind("DESKTOP_RAISEBUTTON_VERT", 0); - ic3 = ImageclassFind("DESKTOP_LOWERBUTTON_VERT", 0); + ic1 = "DESKTOP_DRAGBUTTON_VERT"; + ic2 = "DESKTOP_RAISEBUTTON_VERT"; + ic3 = "DESKTOP_LOWERBUTTON_VERT"; #if 0 - ic4 = ImageclassFind("DESKTOP_DESKRAY_VERT", 0); + ic4 = "DESKTOP_DESKRAY_VERT"; #endif } else { - ic = ImageclassFind("DESKTOP_DRAGBUTTON_HORIZ", 0); - ic2 = ImageclassFind("DESKTOP_RAISEBUTTON_HORIZ", 0); - ic3 = ImageclassFind("DESKTOP_LOWERBUTTON_HORIZ", 0); + ic1 = "DESKTOP_DRAGBUTTON_HORIZ"; + ic2 = "DESKTOP_RAISEBUTTON_HORIZ"; + ic3 = "DESKTOP_LOWERBUTTON_HORIZ"; #if 0 - ic4 = ImageclassFind("DESKTOP_DESKRAY_HORIZ", 0); + ic4 = "DESKTOP_DESKRAY_HORIZ"; #endif } @@ -284,7 +282,7 @@ DeskControlsCreate(Desk * dsk) b = ButtonCreate("_DESKTOP_DRAG_CONTROL", 1, ic3, ac3, NULL, NULL, -1, FLAG_FIXED, 1, 99999, 1, 99999, 0, 0, x[1], 0, y[1], 0, 0, w[1], 0, h[1], 0, dsk->num, 0); - b = ButtonCreate("_DESKTOP_DRAG_CONTROL", 1, ic, ac, NULL, NULL, + b = ButtonCreate("_DESKTOP_DRAG_CONTROL", 1, ic1, ac1, NULL, NULL, -1, FLAG_FIXED, 1, 99999, 1, 99999, 0, 0, x[2], 0, y[2], 0, 0, w[2], 0, h[2], 0, dsk->num, 0); ButtonSetCallback(b, DeskButtonCallback, EoObj(dsk)); @@ -295,14 +293,14 @@ DeskControlsCreate(Desk * dsk) { if (Conf.desks.dragdir == 0) { - b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac, + b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac1, NULL, NULL, 1, FLAG_FIXED_VERT, 1, 99999, 1, 99999, 0, 0, EoGetX(dsk), 0, EoGetY(dsk), 0, 0, 0, 0, 0, 1, 0, 1); } else if (Conf.desks.dragdir == 1) { - b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac, + b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac1, NULL, NULL, 1, FLAG_FIXED_VERT, 1, 99999, 1, 99999, 0, 0, EoGetX(dsk) + VRoot.w - @@ -311,14 +309,14 @@ DeskControlsCreate(Desk * dsk) } else if (Conf.desks.dragdir == 2) { - b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac, + b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac1, NULL, NULL, 1, FLAG_FIXED_HORIZ, 1, 99999, 1, 99999, 0, 0, EoGetX(dsk), 0, EoGetY(dsk), 0, 0, 0, 0, 0, 1, 0, 1); } else { - b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac, + b = ButtonCreate("_DESKTOP_DESKRAY_DRAG_CONTROL", 2, ic4, ac1, NULL, NULL, 1, FLAG_FIXED_HORIZ, 1, 99999, 1, 99999, 0, 0, EoGetX(dsk), 0, EoGetY(dsk) + VRoot.h - Conf.desks.dragbar_width, diff --git a/src/dialog.c b/src/dialog.c index 72b8c397..b000ad49 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -253,13 +253,8 @@ DialogCreate(const char *name) d->win = ECreateClientWindow(VRoot.win, -20, -20, 2, 2); EventCallbackRegister(d->win, 0, DialogHandleEvents, d); - d->tclass = TextclassFind("DIALOG", 1); - if (d->tclass) - TextclassIncRefcount(d->tclass); - - d->iclass = ImageclassFind("DIALOG", 1); - if (d->iclass) - ImageclassIncRefcount(d->iclass); + d->iclass = ImageclassAlloc("DIALOG", 1); + d->tclass = TextclassAlloc("DIALOG", 1); d->xu1 = d->yu1 = 99999; d->xu2 = d->yu2 = 0; @@ -279,10 +274,8 @@ DialogDestroy(Dialog * d) DialogKeybindingsDestroy(d); if (d->item) DialogItemDestroy(d->item, 0); - if (d->iclass) - ImageclassDecRefcount(d->iclass); - if (d->tclass) - TextclassDecRefcount(d->tclass); + ImageclassFree(d->iclass); + TextclassFree(d->tclass); FreePmapMask(&(d->pmm_bg)); EDestroyWindow(d->win); @@ -367,13 +360,8 @@ DialogAddButton(Dialog * d, const char *text, DialogCallbackFunc * func, db->clicked = 0; db->close = doclose; - db->tclass = TextclassFind("DIALOG_BUTTON", 1); - if (db->tclass) - TextclassIncRefcount(db->tclass); - - db->iclass = ImageclassFind("DIALOG_BUTTON", 1); - if (db->iclass) - ImageclassIncRefcount(db->iclass); + db->tclass = TextclassAlloc("DIALOG_BUTTON", 1); + db->iclass = ImageclassAlloc("DIALOG_BUTTON", 1); TextSize(db->tclass, 0, 0, STATE_NORMAL, text, &w, &h, 17); pad = ImageclassGetPadding(db->iclass); @@ -921,24 +909,6 @@ DialogItemSetCallback(DItem * di, DialogCallbackFunc * func, int val, di->data = data; } -#if 0 /* Unused */ -void -DialogItemSetClass(DItem * di, ImageClass * iclass, TextClass * tclass) -{ - if (di->iclass) - ImageclassDecRefcount(di->iclass); - di->iclass = iclass; - if (di->iclass) - ImageclassIncRefcount(di->iclass); - - if (di->tclass) - TextclassDecRefcount(di->tclass); - di->tclass = tclass; - if (di->tclass) - TextclassIncRefcount(di->tclass); -} -#endif - void DialogItemSetPadding(DItem * di, int left, int right, int top, int bottom) { @@ -1027,15 +997,10 @@ DialogRealizeItem(Dialog * d, DItem * di) def = "DIALOG_WIDGET_BUTTON"; } - if (!di->tclass) - di->tclass = TextclassFind(def, 1); if (!di->iclass) - di->iclass = ImageclassFind(def, 1); - - if (di->tclass) - TextclassIncRefcount(di->tclass); - if (di->iclass) - ImageclassIncRefcount(di->iclass); + di->iclass = ImageclassAlloc(def, 1); + if (!di->tclass) + di->tclass = TextclassAlloc(def, 1); if (di->type == DITEM_TABLE) { @@ -1071,20 +1036,16 @@ DialogRealizeItem(Dialog * d, DItem * di) ButtonPressMask | ButtonReleaseMask | PointerMotionMask); EventCallbackRegister(di->item.slider.knob_win, 0, DItemHandleEvents, di); + if (!di->item.slider.ic_base) { if (di->item.slider.horizontal) - { - di->item.slider.ic_base = - ImageclassFind("DIALOG_WIDGET_SLIDER_BASE_HORIZONTAL", 1); - } + di->item.slider.ic_base = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_BASE_HORIZONTAL", 1); else - { - di->item.slider.ic_base = - ImageclassFind("DIALOG_WIDGET_SLIDER_BASE_VERTICAL", 1); - } + di->item.slider.ic_base = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_BASE_VERTICAL", 1); } - im = ImageclassGetImage(di->item.slider.ic_base, 0, 0, 0); if (im) { @@ -1092,25 +1053,16 @@ DialogRealizeItem(Dialog * d, DItem * di) &di->item.slider.base_orig_h); EImageFree(im); } - if (di->item.slider.ic_base) - ImageclassIncRefcount(di->item.slider.ic_base); if (!di->item.slider.ic_knob) { if (di->item.slider.horizontal) - { - di->item.slider.ic_knob = - ImageclassFind("DIALOG_WIDGET_SLIDER_KNOB_HORIZONTAL", 1); - } + di->item.slider.ic_knob = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_KNOB_HORIZONTAL", 1); else - { - di->item.slider.ic_knob = - ImageclassFind("DIALOG_WIDGET_SLIDER_KNOB_VERTICAL", 1); - } + di->item.slider.ic_knob = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_KNOB_VERTICAL", 1); } - if (di->item.slider.ic_knob) - ImageclassIncRefcount(di->item.slider.ic_knob); - im = ImageclassGetImage(di->item.slider.ic_knob, 0, 0, 0); if (im) { @@ -1118,34 +1070,27 @@ DialogRealizeItem(Dialog * d, DItem * di) &di->item.slider.knob_orig_h); EImageFree(im); } + if (!di->item.slider.ic_border) { if (di->item.slider.horizontal) - { - di->item.slider.ic_border = - ImageclassFind("DIALOG_WIDGET_SLIDER_BORDER_HORIZONTAL", - 0); - } + di->item.slider.ic_border = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_BORDER_HORIZONTAL", 1); else - { - di->item.slider.ic_border = - ImageclassFind("DIALOG_WIDGET_SLIDER_BORDER_VERTICAL", 0); - } + di->item.slider.ic_border = + ImageclassAlloc("DIALOG_WIDGET_SLIDER_BORDER_VERTICAL", 1); } - if (di->item.slider.ic_border) + im = ImageclassGetImage(di->item.slider.ic_border, 0, 0, 0); + if (im) { - im = ImageclassGetImage(di->item.slider.ic_border, 0, 0, 0); - if (im) - { - EImageGetSize(im, &di->item.slider.border_orig_w, - &di->item.slider.border_orig_h); - EImageFree(im); - di->item.slider.border_win = - ECreateWindow(d->win, -20, -20, 2, 2, 0); - EMapWindow(di->item.slider.border_win); - } - ImageclassIncRefcount(di->item.slider.ic_border); + EImageGetSize(im, &di->item.slider.border_orig_w, + &di->item.slider.border_orig_h); + EImageFree(im); + di->item.slider.border_win = + ECreateWindow(d->win, -20, -20, 2, 2, 0); + EMapWindow(di->item.slider.border_win); } + pad = ImageclassGetPadding(di->item.slider.ic_base); if (di->item.slider.horizontal) { @@ -2109,12 +2054,9 @@ DialogItemDestroy(DItem * di, int clean) EDestroyWindow(di->item.radio_button.radio_win); break; case DITEM_SLIDER: - if (di->item.slider.ic_base) - ImageclassDecRefcount(di->item.slider.ic_base); - if (di->item.slider.ic_knob) - ImageclassDecRefcount(di->item.slider.ic_knob); - if (di->item.slider.ic_border) - ImageclassDecRefcount(di->item.slider.ic_border); + ImageclassFree(di->item.slider.ic_base); + ImageclassFree(di->item.slider.ic_knob); + ImageclassFree(di->item.slider.ic_border); if (!clean) break; EDestroyWindow(di->item.slider.base_win); @@ -2130,10 +2072,8 @@ DialogItemDestroy(DItem * di, int clean) if (clean && di->win) EDestroyWindow(di->win); - if (di->iclass) - ImageclassDecRefcount(di->iclass); - if (di->tclass) - TextclassDecRefcount(di->tclass); + ImageclassFree(di->iclass); + TextclassFree(di->tclass); Efree(di); } diff --git a/src/dialog.h b/src/dialog.h index 31d41571..1725031d 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -104,8 +104,6 @@ DItem *DialogAddItem(DItem * dii, int type); Dialog *DialogItemGetDialog(DItem * di); void DialogItemSetCallback(DItem * di, DialogCallbackFunc * func, int val, void *data); -void DialogItemSetClass(DItem * di, ImageClass * ic, - TextClass * tclass); void DialogItemSetPadding(DItem * di, int left, int right, int top, int bottom); void DialogItemSetFill(DItem * di, char fill_h, char fill_v); diff --git a/src/iclass.c b/src/iclass.c index 6f582062..b08d814d 100644 --- a/src/iclass.c +++ b/src/iclass.c @@ -375,16 +375,26 @@ ImageclassDestroy(ImageClass * ic) #endif } -void -ImageclassIncRefcount(ImageClass * ic) +ImageClass * +ImageclassAlloc(const char *name, int fallback) { - ic->ref_count++; + ImageClass *ic; + + if (!name || !name[0]) + return NULL; + + ic = ImageclassFind(name, fallback); + if (ic) + ic->ref_count++; + + return ic; } void -ImageclassDecRefcount(ImageClass * ic) +ImageclassFree(ImageClass * ic) { - ic->ref_count--; + if (ic) + ic->ref_count--; } const char * @@ -408,20 +418,16 @@ _ImageclassMatchName(const void *data, const void *match) ImageClass * ImageclassFind(const char *name, int fallback) { - ImageClass *ic; + ImageClass *ic = NULL; if (name) - { - ic = - (ImageClass *) ecore_list_find(iclass_list, _ImageclassMatchName, + ic = (ImageClass *) ecore_list_find(iclass_list, _ImageclassMatchName, name); - if (ic || !fallback) - return ic; - } + if (ic || !fallback) + return ic; - ic = - (ImageClass *) ecore_list_find(iclass_list, _ImageclassMatchName, - "__FALLBACK_ICLASS"); + ic = (ImageClass *) ecore_list_find(iclass_list, _ImageclassMatchName, + "__FALLBACK_ICLASS"); return ic; } @@ -526,7 +532,6 @@ ImageclassConfigLoad(FILE * fs) int i1; ImageClass *ic = NULL; ImageState *ICToRead = NULL; - int fields; int l, r, t, b; #if ENABLE_COLOR_MODIFIERS @@ -535,42 +540,24 @@ ImageclassConfigLoad(FILE * fs) while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - i1 = CONFIG_INVALID; - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_CLOSE: ImageclassPopulate(ic); goto done; case ICLASS_LRTB: - { - ICToRead->border = EMALLOC(EImageBorder, 1); + ICToRead->border = EMALLOC(EImageBorder, 1); - l = r = t = b = 0; - sscanf(s, "%*s %i %i %i %i", &l, &r, &t, &b); - ICToRead->border->left = l; - ICToRead->border->right = r; - ICToRead->border->top = t; - ICToRead->border->bottom = b; - /* Hmmm... imlib2 works better with this */ - ICToRead->border->right++; - ICToRead->border->bottom++; - } + l = r = t = b = 0; + sscanf(s, "%*s %i %i %i %i", &l, &r, &t, &b); + ICToRead->border->left = l; + ICToRead->border->right = r; + ICToRead->border->top = t; + ICToRead->border->bottom = b; + /* Hmmm... imlib2 works better with this */ + ICToRead->border->right++; + ICToRead->border->bottom++; break; case ICLASS_FILLRULE: ICToRead->pixmapfillstyle = atoi(s2); @@ -612,14 +599,12 @@ ImageclassConfigLoad(FILE * fs) #endif break; case ICLASS_PADDING: - { - l = r = t = b = 0; - sscanf(s, "%*s %i %i %i %i", &l, &r, &t, &b); - ic->padding.left = l; - ic->padding.right = r; - ic->padding.top = t; - ic->padding.bottom = b; - } + l = r = t = b = 0; + sscanf(s, "%*s %i %i %i %i", &l, &r, &t, &b); + ic->padding.left = l; + ic->padding.right = r; + ic->padding.top = t; + ic->padding.bottom = b; break; case CONFIG_CLASSNAME: case ICLASS_NAME: @@ -713,10 +698,7 @@ ImageclassConfigLoad(FILE * fs) ICToRead = ic->sticky_active.disabled; break; default: - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current " - "ImageClass definition:\n" - "%s\nWill ignore and continue...\n"), s); + ConfigParseError("ImageClass", s); break; } } diff --git a/src/iclass.h b/src/iclass.h index e6839071..af664b8f 100644 --- a/src/iclass.h +++ b/src/iclass.h @@ -96,8 +96,8 @@ int ImageclassIsTransparent(ImageClass * ic); #endif ImageClass *ImageclassFind(const char *name, int fallback); -void ImageclassIncRefcount(ImageClass * ic); -void ImageclassDecRefcount(ImageClass * ic); +ImageClass *ImageclassAlloc(const char *name, int fallback); +void ImageclassFree(ImageClass * ic); const char *ImageclassGetName(ImageClass * ic); EImageBorder *ImageclassGetPadding(ImageClass * ic); ImageState *ImageclassGetImageState(ImageClass * ic, int state, diff --git a/src/menus.c b/src/menus.c index ef6d0120..5fb2f5de 100644 --- a/src/menus.c +++ b/src/menus.c @@ -418,8 +418,10 @@ MenuItemCreate(const char *text, ImageClass * iclass, mi = ECALLOC(MenuItem, 1); mi->icon_iclass = iclass; +#if 0 if (iclass) ImageclassIncRefcount(iclass); +#endif mi->text = (text) ? Estrdup((text[0]) ? text : "?!?") : NULL; mi->params = Estrdup(action_params); @@ -620,8 +622,7 @@ MenuEmpty(Menu * m, int destroying) FreePmapMask(&(mi->pmm[j])); if (!destroying && mi->win) EDestroyWindow(mi->win); - if (mi->icon_iclass) - ImageclassDecRefcount(mi->icon_iclass); + ImageclassFree(mi->icon_iclass); if (mi) Efree(mi); } @@ -1777,36 +1778,17 @@ MenuMaskerHandleEvents(Win win __UNUSED__, XEvent * ev, void *prm __UNUSED__) #include "conf.h" int -MenuStyleConfigLoad(FILE * ConfigFile) +MenuStyleConfigLoad(FILE * fs) { int err = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; int i1; MenuStyle *ms = NULL; - int fields; - while (GetLine(s, sizeof(s), ConfigFile)) + while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_CLOSE: @@ -1815,24 +1797,16 @@ MenuStyleConfigLoad(FILE * ConfigFile) ms = MenuStyleCreate(s2); break; case CONFIG_TEXT: - ms->tclass = TextclassFind(s2, 1); - if (ms->tclass) - TextclassIncRefcount(ms->tclass); + ms->tclass = TextclassAlloc(s2, 1); break; case MENU_BG_ICLASS: - ms->bg_iclass = ImageclassFind(s2, 0); - if (ms->bg_iclass) - ImageclassIncRefcount(ms->bg_iclass); + ms->bg_iclass = ImageclassAlloc(s2, 1); break; case MENU_ITEM_ICLASS: - ms->item_iclass = ImageclassFind(s2, 0); - if (ms->item_iclass) - ImageclassIncRefcount(ms->item_iclass); + ms->item_iclass = ImageclassAlloc(s2, 1); break; case MENU_SUBMENU_ICLASS: - ms->sub_iclass = ImageclassFind(s2, 0); - if (ms->sub_iclass) - ImageclassIncRefcount(ms->sub_iclass); + ms->sub_iclass = ImageclassAlloc(s2, 1); break; case MENU_USE_ITEM_BACKGROUND: ms->use_item_bg = atoi(s2); @@ -1840,7 +1814,7 @@ MenuStyleConfigLoad(FILE * ConfigFile) { if (ms->bg_iclass) { - ImageclassDecRefcount(ms->bg_iclass); + ImageclassFree(ms->bg_iclass); ms->bg_iclass = NULL; } } @@ -1852,21 +1826,7 @@ MenuStyleConfigLoad(FILE * ConfigFile) ms->maxy = atoi(s2); break; case CONFIG_BORDER: - { - /* FIXME!!! I don't think this file is loaded in the - * right order! - */ - Border *b; - - if (ms->border_name) - Efree(ms->border_name); - - ms->border_name = Estrdup(s2); - - b = BorderFind(ms->border_name); - if (b) - BorderIncRefcount(b); - } + _EFDUP(ms->border_name, s2); break; default: break; @@ -1887,39 +1847,17 @@ MenuConfigLoad(FILE * fs) char s3[FILEPATH_LEN_MAX]; char s4[FILEPATH_LEN_MAX]; char s5[FILEPATH_LEN_MAX]; + char *p2, *p3; char *txt = NULL; const char *params; - int i1, i2; + int i1, i2, len; Menu *m = NULL, *mm; MenuItem *mi; ImageClass *ic = NULL; - int fields, len2, len; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - len = 0; - fields = sscanf(s, "%i %n%4000s %n", &i1, &len2, s2, &len); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - continue; - } - } - + i1 = ConfigParseline1(s, s2, &p2, &p3); switch (i1) { case CONFIG_MENU: @@ -1936,7 +1874,7 @@ MenuConfigLoad(FILE * fs) break; case MENU_PREBUILT: - sscanf(s, "%i %4000s %4000s %4000s %4000s", &i1, s2, s3, s4, s5); + sscanf(p3, "%4000s %4000s %4000s", s3, s4, s5); m = MenusCreateInternal(s4, s2, s3, s5); break; case CONFIG_CLASSNAME: @@ -1952,21 +1890,15 @@ MenuConfigLoad(FILE * fs) MenuSetStyle(m, MenuStyleFind(s2)); break; case MENU_TITLE: - MenuSetTitle(m, s + len2); + MenuSetTitle(m, p2); break; case MENU_ITEM: -#if 0 /* FIXME - Why ? */ - if ((txt) || (ic)) - { - mi = MenuItemCreate(txt, ic, NULL, NULL); - MenuAddItem(m, mi); - } -#endif ic = NULL; if (strcmp("NULL", s2)) ic = ImageclassFind(s2, 0); - params = s + len; - _EFDUP(txt, params); + if (i2 <= 0) + break; + _EFDUP(txt, p3); break; case MENU_ACTION: if ((txt) || (ic)) @@ -1977,13 +1909,12 @@ MenuConfigLoad(FILE * fs) * on your system before adding the menu entry */ if (!strcmp(s2, "exec")) { - sscanf(s + len, "%1000s", s3); + sscanf(p3, "%1000s", s3); ok = path_canexec(s3); } if (ok) { - params = s + len2; - mi = MenuItemCreate(txt, ic, params, NULL); + mi = MenuItemCreate(txt, ic, p2, NULL); MenuAddItem(m, mi); } ic = NULL; @@ -1991,18 +1922,13 @@ MenuConfigLoad(FILE * fs) } break; case MENU_SUBMENU: - len2 = 0; - sscanf(s + len, "%4000s %n", s3, &len2); + len = 0; + sscanf(p3, "%s %n", s3, &len); ic = NULL; if (strcmp("NULL", s3)) ic = ImageclassFind(s3, 0); mm = MenuFind(s2, NULL); -#if 0 /* FIXME - Remove? */ - /* if submenu empty - dont put it in - only if menu found */ - if (MenuIsEmpty(mm)) - break; -#endif - mi = MenuItemCreate(s + len + len2, ic, NULL, mm); + mi = MenuItemCreate(p3 + len, ic, NULL, mm); MenuAddItem(m, mi); break; default: diff --git a/src/progress.c b/src/progress.c index c1cf7455..cb152697 100644 --- a/src/progress.c +++ b/src/progress.c @@ -53,17 +53,9 @@ ProgressbarCreate(const char *name, int w, int h) plist = EREALLOC(Progressbar *, plist, pnum); plist[pnum - 1] = p; - p->ic = ImageclassFind("PROGRESS_BAR", 1); - if (p->ic) - ImageclassIncRefcount(p->ic); - - p->tc = TextclassFind("PROGRESS_TEXT", 1); - if (p->tc) - TextclassIncRefcount(p->tc); - - p->tnc = TextclassFind("PROGRESS_TEXT_NUMBER", 1); - if (p->tnc) - TextclassIncRefcount(p->tnc); + p->ic = ImageclassAlloc("PROGRESS_BAR", 1); + p->tc = TextclassAlloc("PROGRESS_TEXT", 1); + p->tnc = TextclassAlloc("PROGRESS_TEXT_NUMBER", 1); pad = ImageclassGetPadding(p->ic); TextSize(p->tc, 0, 0, 0, name, &tw, &th, 0); @@ -123,16 +115,11 @@ ProgressbarDestroy(Progressbar * p) break; } - if (p->ic) - ImageclassDecRefcount(p->ic); + ImageclassFree(p->ic); + TextclassFree(p->tc); + TextclassFree(p->tnc); - if (p->tc) - TextclassDecRefcount(p->tc); - if (p->tnc) - TextclassDecRefcount(p->tnc); - - if (p) - Efree(p); + Efree(p); pnum--; if (pnum <= 0) diff --git a/src/slideout.c b/src/slideout.c index ee6c11de..bd816e5a 100644 --- a/src/slideout.c +++ b/src/slideout.c @@ -405,35 +405,14 @@ SlideoutsConfigLoad(FILE * fs) int i1; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; - char *name = 0; - int fields; + char name[FILEPATH_LEN_MAX]; if (!slideout_list) slideout_list = ecore_list_new(); while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - i1 = CONFIG_INVALID; - } - } + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_CLOSE: @@ -441,24 +420,18 @@ SlideoutsConfigLoad(FILE * fs) ecore_list_prepend(slideout_list, slideout); goto done; case CONFIG_CLASSNAME: - if (name) - Efree(name); - name = Estrdup(s2); + strcpy(name, s2); break; case SLIDEOUT_DIRECTION: slideout = SlideoutCreate(name, (char)atoi(s2)); - if (name) - Efree(name); break; case CONFIG_BUTTON: SlideoutAddButton(slideout, ButtonFind(s2)); break; default: - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current Text " - "definition:\n" "%s\nWill ignore and continue...\n"), s); + ConfigParseError("Slideout", s); + break; } - } err = -1; diff --git a/src/tclass.c b/src/tclass.c index 4ad88744..ff1e3dbe 100644 --- a/src/tclass.c +++ b/src/tclass.c @@ -135,16 +135,26 @@ TextclassDestroy(TextClass * tc) Efree(tc); } -void -TextclassIncRefcount(TextClass * tc) +TextClass * +TextclassAlloc(const char *name, int fallback) { - tc->ref_count++; + TextClass *tc; + + if (!name || !name[0]) + return NULL; + + tc = TextclassFind(name, fallback); + if (tc) + tc->ref_count++; + + return tc; } void -TextclassDecRefcount(TextClass * tc) +TextclassFree(TextClass * tc) { - tc->ref_count--; + if (tc) + tc->ref_count--; } int @@ -213,20 +223,16 @@ _TextclassMatchName(const void *data, const void *match) TextClass * TextclassFind(const char *name, int fallback) { - TextClass *tc; + TextClass *tc = NULL; if (name) - { - tc = - (TextClass *) ecore_list_find(tclass_list, _TextclassMatchName, + tc = (TextClass *) ecore_list_find(tclass_list, _TextclassMatchName, name); - if (tc || !fallback) - return tc; - } + if (tc || !fallback) + return tc; - tc = - (TextClass *) ecore_list_find(tclass_list, _TextclassMatchName, - "__FALLBACK_TCLASS"); + tc = (TextClass *) ecore_list_find(tclass_list, _TextclassMatchName, + "__FALLBACK_TCLASS"); return tc; } @@ -240,31 +246,10 @@ TextclassConfigLoad(FILE * fs) int i1, r, g, b; TextClass *tc = NULL; TextState *ts = NULL; - int fields; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000[^=]", &i1, s2); - - if (fields < 1) - { - i1 = CONFIG_INVALID; - } - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - i1 = CONFIG_INVALID; - } - } + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_CLOSE: @@ -456,11 +441,9 @@ TextclassConfigLoad(FILE * fs) } break; default: - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current Text" - " definition:\n" "%s\nWill ignore and continue...\n"), s); + ConfigParseError("TextClass", s); + break; } - } err = -1; diff --git a/src/tclass.h b/src/tclass.h index e79386d4..152ae7fb 100644 --- a/src/tclass.h +++ b/src/tclass.h @@ -92,11 +92,11 @@ struct _textclass /* tclass.c */ int TextclassConfigLoad(FILE * fs); -void TextclassIncRefcount(TextClass * tc); -void TextclassDecRefcount(TextClass * tc); +TextClass *TextclassFind(const char *name, int fallback); +TextClass *TextclassAlloc(const char *name, int fallback); +void TextclassFree(TextClass * tc); int TextclassGetJustification(TextClass * tc); void TextclassSetJustification(TextClass * tc, int just); -TextClass *TextclassFind(const char *name, int fallback); /* text.c */ TextState *TextclassGetTextState(TextClass * tclass, int state, diff --git a/src/tooltips.c b/src/tooltips.c index ee58143a..27c38518 100644 --- a/src/tooltips.c +++ b/src/tooltips.c @@ -91,11 +91,10 @@ TooltipRealize(ToolTip * tt) } static ToolTip * -TooltipCreate(const char *name, ImageClass * ic0, ImageClass * ic1, - ImageClass * ic2, ImageClass * ic3, ImageClass * ic4, - TextClass * tclass, int dist, ImageClass * tooltippic) +TooltipCreate(const char *name, const char *ic0, const char *ic1, + const char *ic2, const char *ic3, const char *ic4, + const char *tclass, int dist, const char *tooltippic) { - int i; ToolTip *tt; if (ic0 == NULL || tclass == NULL) @@ -106,24 +105,18 @@ TooltipCreate(const char *name, ImageClass * ic0, ImageClass * ic1, return NULL; tt->name = Estrdup(name); - tt->iclass[0] = ic1; - tt->iclass[1] = ic2; - tt->iclass[2] = ic3; - tt->iclass[3] = ic4; - tt->iclass[4] = ic0; - ImageclassIncRefcount(ic0); - tt->tclass = tclass; - TextclassIncRefcount(tclass); - tt->tooltippic = tooltippic; - if (tooltippic) - ImageclassIncRefcount(tooltippic); + tt->iclass[0] = ImageclassAlloc(ic1, 0); + tt->iclass[1] = ImageclassAlloc(ic2, 0); + tt->iclass[2] = ImageclassAlloc(ic3, 0); + tt->iclass[3] = ImageclassAlloc(ic4, 0); + tt->iclass[4] = ImageclassAlloc(ic0, 0); + tt->tclass = TextclassAlloc(tclass, 1); + tt->tooltippic = ImageclassAlloc(tooltippic, 0); tt->dist = dist; - for (i = 0; i < 5; i++) - if (tt->iclass[i]) - ImageclassIncRefcount(tt->iclass[i]); - + if (!tt_list) + tt_list = ecore_list_new(); ecore_list_prepend(tt_list, tt); return tt; @@ -144,93 +137,70 @@ TooltipDestroy(ToolTip * tt) #endif int -TooltipConfigLoad(FILE * ConfigFile) +TooltipConfigLoad(FILE * fs) { int err = 0; - ToolTip *tt; - char *name = 0; - ImageClass *drawiclass = 0; - ImageClass *bubble1 = 0, *bubble2 = 0, *bubble3 = 0, *bubble4 = 0; - TextClass *tclass = 0; - ImageClass *tooltiphelppic = 0; char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; + char name[64]; + char iclass[64]; + char bubble1[64], bubble2[64], bubble3[64], bubble4[64]; + char tclass[64]; + char tooltiphelppic[64]; int i1; int distance = 0; - int fields; - if (!tt_list) - tt_list = ecore_list_new(); + name[0] = iclass[0] = tclass[0] = '\0'; + bubble1[0] = bubble2[0] = bubble3[0] = bubble4[0] = '\0'; + tooltiphelppic[0] = '\0'; - tt = NULL; - while (GetLine(s, sizeof(s), ConfigFile)) + while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - fields = sscanf(s, "%i %4000s", &i1, s2); - - if (fields < 1) - i1 = CONFIG_INVALID; - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - { - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - } + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_CLOSE: - if ((drawiclass) && (tclass) && (name)) - tt = TooltipCreate(name, drawiclass, bubble1, bubble2, - bubble3, bubble4, tclass, distance, - tooltiphelppic); - _EFREE(name); + if (iclass[0] && tclass[0] && name[0]) + TooltipCreate(name, iclass, bubble1, bubble2, + bubble3, bubble4, tclass, distance, + tooltiphelppic); goto done; case CONFIG_CLASSNAME: if (TooltipFind(s2)) { - SkipTillEnd(ConfigFile); + SkipTillEnd(fs); goto done; } - _EFDUP(name, s2); + STRCPY(name, s2); break; case TOOLTIP_DRAWICLASS: case CONFIG_IMAGECLASS: - drawiclass = ImageclassFind(s2, 0); + STRCPY(iclass, s2); break; case TOOLTIP_BUBBLE1: - bubble1 = ImageclassFind(s2, 0); + STRCPY(bubble1, s2); break; case TOOLTIP_BUBBLE2: - bubble2 = ImageclassFind(s2, 0); + STRCPY(bubble2, s2); break; case TOOLTIP_BUBBLE3: - bubble3 = ImageclassFind(s2, 0); + STRCPY(bubble3, s2); break; case TOOLTIP_BUBBLE4: - bubble4 = ImageclassFind(s2, 0); + STRCPY(bubble4, s2); break; case CONFIG_TEXT: - tclass = TextclassFind(s2, 1); + STRCPY(tclass, s2); break; case TOOLTIP_DISTANCE: distance = atoi(s2); break; case TOOLTIP_HELP_PIC: - tooltiphelppic = ImageclassFind(s2, 0); + STRCPY(tooltiphelppic, s2); break; default: - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current " - "ToolTip definition:\n" - "%s\nWill ignore and continue...\n"), s); + ConfigParseError("ToolTip", s); break; } } diff --git a/src/util.h b/src/util.h index 4a5cf661..7ea274cb 100644 --- a/src/util.h +++ b/src/util.h @@ -54,6 +54,8 @@ #define _EFREE(p) do { if (p) { Efree(p); p = NULL; } } while (0) #define _EFDUP(p, s) do { if (p) Efree(p); p = Estrdup(s); } while (0) +#define STRCPY(dst, src) do { src[sizeof(dst)-1] = '\0'; strcpy(dst, src); } while(0) + char *Estrtrim(char *s); char *Estrdup(const char *s); diff --git a/src/windowmatch.c b/src/windowmatch.c index e0e6c4ef..b395e367 100644 --- a/src/windowmatch.c +++ b/src/windowmatch.c @@ -127,8 +127,6 @@ WindowMatchDestroy(WindowMatch * wm) Efree(wm->name); if (wm->value) Efree(wm->value); - if (wm->border) - BorderDecRefcount(wm->border); if (wm->args) Efree(wm->args); @@ -143,28 +141,10 @@ WindowMatchConfigLoad(FILE * fs) char s[FILEPATH_LEN_MAX]; char s2[FILEPATH_LEN_MAX]; int i1; - int fields, len; while (GetLine(s, sizeof(s), fs)) { - s2[0] = 0; - i1 = CONFIG_INVALID; - len = 0; - fields = sscanf(s, "%i %4000s %n", &i1, s2, &len); - - if (fields < 1) - i1 = CONFIG_INVALID; - else if (i1 == CONFIG_CLOSE) - { - if (fields != 1) - Alert(_("CONFIG: ignoring extra data in \"%s\"\n"), s); - } - else if (i1 != CONFIG_INVALID) - { - if (fields != 2) - Alert(_("CONFIG: missing required data in \"%s\"\n"), s); - } - + i1 = ConfigParseline1(s, s2, NULL, NULL); switch (i1) { case CONFIG_VERSION: @@ -267,7 +247,6 @@ WindowMatchConfigLoad(FILE * fs) if (!wm->border) break; wm->op = MATCH_OP_BORDER; - BorderIncRefcount(wm->border); break; case WINDOWMATCH_ICON: @@ -297,10 +276,7 @@ WindowMatchConfigLoad(FILE * fs) break; default: - Alert(_("Warning: unable to determine what to do with\n" - "the following text in the middle of current " - "WindowMatch definition:\n" - "%s\nWill ignore and continue...\n"), s); + ConfigParseError("WindowMatch", s); break; } } @@ -408,7 +384,6 @@ WindowMatchDecode(const char *line) err = 1; goto done; } - BorderIncRefcount(wm->border); break; case MATCH_OP_ICON: