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

View file

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

View file

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