X-Git-Url: https://repo.or.cz/w/wmaker-crm.git/blobdiff_plain/f8dd3dc49ec764846b45f507b6e18e1fa1e7adc5..05720d97076ffc1569e50d904b998ec99c3d3d4e:/src/misc.c diff --git a/src/misc.c b/src/misc.c index 2cf4af7b..60a62ee8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -563,93 +564,59 @@ static char *getselection(WScreen * scr) return tmp; } -static char *getuserinput(WScreen * scr, char *line, int *ptr) +static char* +parseuserinputpart(char *line, int *ptr, char *endchars) { - char *ret; - char *title; - char *prompt; - int j, state; - int begin = 0; -#define BUFSIZE 512 - char tbuffer[BUFSIZE], pbuffer[BUFSIZE]; - - title = _("Program Arguments"); - prompt = _("Enter command arguments:"); - ret = NULL; - -#define _STARTING 0 -#define _TITLE 1 -#define _PROMPT 2 -#define _DONE 3 - - state = _STARTING; - j = 0; - for (; line[*ptr] != 0 && state != _DONE; (*ptr)++) { - switch (state) { - case _STARTING: - if (line[*ptr] == '(') { - state = _TITLE; - begin = *ptr + 1; - } else { - state = _DONE; - } - break; - - case _TITLE: - if (j <= 0 && line[*ptr] == ',') { - - j = 0; - if (*ptr > begin) { - strncpy(tbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE)); - tbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0; - title = (char *)tbuffer; - } - begin = *ptr + 1; - state = _PROMPT; - - } else if (j <= 0 && line[*ptr] == ')') { - - if (*ptr > begin) { - strncpy(tbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE)); - tbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0; - title = (char *)tbuffer; - } - state = _DONE; - - } else if (line[*ptr] == '(') { - j++; - } else if (line[*ptr] == ')') { - j--; - } - - break; - - case _PROMPT: - if (line[*ptr] == ')' && j == 0) { - - if (*ptr - begin > 1) { - strncpy(pbuffer, &line[begin], WMIN(*ptr - begin, BUFSIZE)); - pbuffer[WMIN(*ptr - begin, BUFSIZE)] = 0; - prompt = (char *)pbuffer; - } - state = _DONE; - } else if (line[*ptr] == '(') - j++; - else if (line[*ptr] == ')') - j--; + int depth = 0, begin; + char *value = NULL; + begin = ++*ptr; + + while(line[*ptr] != '\0') { + if(line[*ptr] == '(') { + ++depth; + } else if(depth > 0 && line[*ptr] == ')') { + --depth; + } else if(depth == 0 && strchr(endchars, line[*ptr]) != NULL) { + value = wmalloc(*ptr - begin + 1); + strncpy(value, line + begin, *ptr - begin); + value[*ptr - begin] = '\0'; break; } + ++*ptr; } - (*ptr)--; -#undef _STARTING -#undef _TITLE -#undef _PROMPT -#undef _DONE - if (!wInputDialog(scr, title, prompt, &ret)) - return NULL; - else - return ret; + return value; +} + +static char* +getuserinput(WScreen *scr, char *line, int *ptr, Bool advanced) +{ + char *ret = NULL, *title = NULL, *prompt = NULL, *name = NULL; + int rv; + + if(line[*ptr] == '(') + title = parseuserinputpart(line, ptr, ",)"); + if(title != NULL && line[*ptr] == ',') + prompt = parseuserinputpart(line, ptr, ",)"); + if(prompt != NULL && line[*ptr] == ',') + name = parseuserinputpart(line, ptr, ")"); + + if(advanced) + rv = wAdvancedInputDialog(scr, + title ? gettext(title):_("Program Arguments"), + prompt ? gettext(prompt):_("Enter command arguments:"), + name, &ret); + else + rv = wInputDialog(scr, + title ? gettext(title):_("Program Arguments"), + prompt ? gettext(prompt):_("Enter command arguments:"), + &ret); + + if(title) wfree(title); + if(prompt) wfree(prompt); + if(name) wfree(name); + + return rv ? ret : NULL; } #define S_NORMAL 0 @@ -765,8 +732,9 @@ char *ExpandOptions(WScreen * scr, char *cmdline) break; case 'a': + case 'A': ptr++; - user_input = getuserinput(scr, cmdline, &ptr); + user_input = getuserinput(scr, cmdline, &ptr, cmdline[ptr-1] == 'A'); if (user_input) { slen = strlen(user_input); olen += slen;