diff options
Diffstat (limited to 'xc')
-rw-r--r-- | xc/lib/Xt/Shell.c | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/xc/lib/Xt/Shell.c b/xc/lib/Xt/Shell.c index b88dbbab2..100e8791b 100644 --- a/xc/lib/Xt/Shell.c +++ b/xc/lib/Xt/Shell.c @@ -1,4 +1,4 @@ -/* $XConsortium: Shell.c,v 1.167 94/09/02 16:16:48 kaleb Exp converse $ */ +/* $XConsortium: Shell.c,v 1.168 95/01/06 21:14:23 converse Exp converse $ */ /*********************************************************** Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts @@ -1045,6 +1045,7 @@ static void TopLevelInitialize(req, new, args, num_args) w->wm.wm_hints.initial_state = IconicState; } +static String *NewArgv(); static String *NewStringArray(); static void FreeStringArray(); @@ -1056,8 +1057,9 @@ static void ApplicationInitialize(req, new, args, num_args) { ApplicationShellWidget w = (ApplicationShellWidget)new; - if (w->application.argv) w->application.argv = - NewStringArray(w->application.argv); + if (w->application.argc > 0) + w->application.argv = NewArgv(w->application.argc, + w->application.argv); } #define XtSaveInactive 0 @@ -1664,7 +1666,8 @@ static void ApplicationDestroy(wid) Widget wid; { ApplicationShellWidget w = (ApplicationShellWidget) wid; - FreeStringArray(w->application.argv); + if (w->application.argc > 0) + FreeStringArray(w->application.argv); } static void SessionDestroy(wid) @@ -2364,6 +2367,37 @@ static Boolean TopLevelSetValues(oldW, refW, newW, args, num_args) return False; } +static String * NewArgv(count, str) + int count; + String *str; /* do not assume it's terminated by a NULL element */ +{ + Cardinal nbytes = 0; + Cardinal num = 0; + String *newarray, *new; + String *strarray = str; + String sptr; + + if (count <= 0 || !str) return NULL; + + for (num = count; num--; str++) { + nbytes += strlen(*str); + nbytes++; + } + num = (count+1) * sizeof(String); + new = newarray = (String *) XtMalloc(num + nbytes); + sptr = ((char *) new) + num; + + for (str = strarray; count--; str++) { + *new = sptr; + strcpy(*new, *str); + new++; + sptr = strchr(sptr, '\0'); + sptr++; + } + *new = NULL; + return newarray; +} + /*ARGSUSED*/ static Boolean ApplicationSetValues(current, request, new, args, num_args) @@ -2374,13 +2408,15 @@ static Boolean ApplicationSetValues(current, request, new, args, num_args) ApplicationShellWidget nw = (ApplicationShellWidget) new; ApplicationShellWidget cw = (ApplicationShellWidget) current; - if (cw->application.argv != nw->application.argv) { - nw->application.argv = NewStringArray(nw->application.argv); - FreeStringArray(cw->application.argv); - } + if (cw->application.argc != nw->application.argc || + cw->application.argv != nw->application.argv) { + + if (nw->application.argc > 0) + nw->application.argv = NewArgv(nw->application.argc, + nw->application.argv); + if (cw->application.argc > 0) + FreeStringArray(cw->application.argv); - if (cw->application.argv != nw->application.argv || - cw->application.argc != nw->application.argc) { if (XtIsRealized(new) && !nw->shell.override_redirect) { if (nw->application.argc >= 0 && nw->application.argv) XSetCommand(XtDisplay(new), XtWindow(new), |