libdockapp: Make DAParseArguments() optional.

Some dockapps may want to handle command line options themselves, so we
make this function optional.

Previously, if this function was skipped, then a segfault would result when
trying to access the _daContext global while first creating the dockapp
window.

Now we check if _daContext has been initialized first, and if not, we
initialize it.
This commit is contained in:
Doug Torrance 2017-08-30 00:15:46 -04:00 committed by Carlos R. Mafra
parent 0167a6b2a8
commit ebae7f641b
3 changed files with 10 additions and 7 deletions

View file

@ -58,11 +58,7 @@ DAParseArguments(
int i, j, size; int i, j, size;
int found = 0; int found = 0;
_daContext = DAContextInit(); _daContext = DAContextInit(argc, argv);
_daContext->argc = argc;
_daContext->argv = argv;
_daContext->programName = argv[0];
size = (count + DEFAULT_OPTION_COUNT) * sizeof(DAProgramOption *); size = (count + DEFAULT_OPTION_COUNT) * sizeof(DAProgramOption *);
_daContext->options = malloc(size); _daContext->options = malloc(size);
@ -207,12 +203,16 @@ DAGetProgramName()
*/ */
struct DAContext * struct DAContext *
DAContextInit(void) DAContextInit(int argc, char **argv)
{ {
struct DAContext *context = malloc(sizeof(struct DAContext)); struct DAContext *context = malloc(sizeof(struct DAContext));
memset(context, 0, sizeof(struct DAContext)); memset(context, 0, sizeof(struct DAContext));
context->argc = argc;
context->argv = argv;
context->programName = argv[0];
return context; return context;
} }

View file

@ -42,6 +42,6 @@ struct DAContext {
}; };
struct DAContext *DAContextInit(void); struct DAContext *DAContextInit(int argc, char **argv);
void DAFreeContext(void); void DAFreeContext(void);

View file

@ -134,6 +134,9 @@ DACreateIcon(char *name, unsigned width, unsigned height, int argc, char **argv)
unsigned long valueMask; unsigned long valueMask;
char *resourceValue; char *resourceValue;
if (!_daContext)
_daContext = DAContextInit(argc, argv);
_daContext->width = width; _daContext->width = width;
_daContext->height = height; _daContext->height = height;