From 171eca8b64a024e6f08c1026dd49599a6742ccac Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Tue, 17 Jan 2012 15:34:15 +0000 Subject: [PATCH] Get rid of cropline(), use wtrimspace() instead There is code duplication with the cropline() function, so get rid of it and use WINGs wtrimspace() instead. Signed-off-by: Carlos R. Mafra --- src/rootmenu.c | 27 ++++----------------------- src/workspace.c | 19 +------------------ 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/src/rootmenu.c b/src/rootmenu.c index 0ecd3b4c..cccbab8f 100644 --- a/src/rootmenu.c +++ b/src/rootmenu.c @@ -473,25 +473,6 @@ static Bool addShortcut(char *file, char *shortcutDefinition, WMenu * menu, WMen return True; } -/*******************************/ - -static char *cropline(char *line) -{ - char *end; - - if (strlen(line) == 0) - return line; - - end = &(line[strlen(line)]) - 1; - while (isspace(*line) && *line != 0) - line++; - while (end > line && isspace(*end)) { - *end = 0; - end--; - } - return line; -} - static char *next_token(char *line, char **next) { char *tmp, c; @@ -1020,14 +1001,14 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, FILE * file, char *file_ ok = 0; fgets(linebuf, MAXLINE, file); - line = cropline(linebuf); + line = wtrimspace(linebuf); lsize = strlen(line); do { if (line[lsize - 1] == '\\') { char *line2; int lsize2; fgets(elinebuf, MAXLINE, file); - line2 = cropline(elinebuf); + line2 = wtrimspace(elinebuf); lsize2 = strlen(line2); if (lsize2 + lsize > MAXLINE) { wwarning(_("%s:maximal line size exceeded in menu config: %s"), @@ -1129,7 +1110,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name) while (!feof(file)) { if (!fgets(linebuf, MAXLINE, file)) break; - line = cropline(linebuf); + line = wtrimspace(linebuf); if (line[0] == 0 || line[0] == '#' || (line[0] == '/' && line[1] == '/')) continue; @@ -1223,7 +1204,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name) while (!feof(file)) { if (!fgets(linebuf, MAXLINE, file)) break; - line = cropline(linebuf); + line = wtrimspace(linebuf); if (line[0] == 0 || line[0] == '#' || (line[0] == '/' && line[1] == '/')) continue; diff --git a/src/workspace.c b/src/workspace.c index c0493f32..dc53d03b 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -645,23 +645,6 @@ static void newWSCommand(WMenu * menu, WMenuEntry * foo) } */ } -static char *cropline(char *line) -{ - char *end; - - if (strlen(line) == 0) - return line; - - end = &(line[strlen(line)]) - 1; - while (isspace(*line) && *line != 0) - line++; - while (isspace(*end) && end != line) { - *end = 0; - end--; - } - return line; -} - void wWorkspaceRename(WScreen * scr, int workspace, char *name) { char buf[MAX_WORKSPACENAME_WIDTH + 1]; @@ -671,7 +654,7 @@ void wWorkspaceRename(WScreen * scr, int workspace, char *name) return; /* trim white spaces */ - tmp = cropline(name); + tmp = wtrimspace(name); if (strlen(tmp) == 0) { snprintf(buf, sizeof(buf), _("Workspace %i"), workspace + 1);