2019-04-19 11:32:13 -05:00
|
|
|
// 19 april 2019
|
|
|
|
#include <string.h>
|
|
|
|
#include "ui.h"
|
|
|
|
#include "uipriv.h"
|
|
|
|
|
|
|
|
static int initialized = 0;
|
|
|
|
|
2019-04-20 20:38:26 -05:00
|
|
|
#define errAlreadyInitialized "libui already initialized"
|
|
|
|
#define errOptionsMustBeNULL "options parameter to uiInit() must be NULL"
|
|
|
|
|
|
|
|
static const char *commonInitErrors[] = {
|
|
|
|
errAlreadyInitialized,
|
|
|
|
errOptionsMustBeNULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int checkInitErrorLengths(uiInitError *err, const char *initErrors[])
|
|
|
|
{
|
|
|
|
const char **p;
|
|
|
|
|
|
|
|
for (p = initErrors; *p != NULL; p++)
|
|
|
|
if (strlen(*p) > 255) {
|
|
|
|
strcpy(err->Message, "[INTERNAL] uiInit() error too long: ");
|
|
|
|
strncat(err->Message, *p, 32);
|
|
|
|
strcat(err->Message, "...");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uiprivInitCheckParams(void *options, uiInitError *err, const char *initErrors[])
|
2019-04-19 11:32:13 -05:00
|
|
|
{
|
|
|
|
if (err == NULL)
|
|
|
|
return 0;
|
|
|
|
if (err->Size != sizeof (uiInitError))
|
|
|
|
return 0;
|
|
|
|
|
2019-04-20 20:38:26 -05:00
|
|
|
if (!checkInitErrorLengths(err, commonInitErrors))
|
|
|
|
return 0;
|
|
|
|
if (!checkInitErrorLengths(err, initErrors))
|
|
|
|
return 0;
|
|
|
|
|
2019-04-19 11:32:13 -05:00
|
|
|
if (initialized)
|
2019-04-20 20:38:26 -05:00
|
|
|
return uiprivInitReturnError(err, errAlreadyInitialized);
|
2019-04-19 11:32:13 -05:00
|
|
|
|
|
|
|
if (options != NULL)
|
2019-04-20 20:38:26 -05:00
|
|
|
return uiprivInitReturnError(err, errOptionsMustBeNULL);
|
2019-04-19 11:32:13 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uiprivInitReturnError(uiInitError *err, const char *msg)
|
|
|
|
{
|
2019-04-20 20:38:26 -05:00
|
|
|
// checkInitErrorLengths() above ensures that err->Message[255] will always be '\0'
|
2019-04-19 11:32:13 -05:00
|
|
|
strncpy(err->Message, msg, 256);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiprivMarkInitialized(void)
|
|
|
|
{
|
|
|
|
initialized = 1;
|
|
|
|
}
|