summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-10 16:54:06 -0400
committerPietro Gagliardi <[email protected]>2015-04-10 16:54:06 -0400
commitd326407f05cadec6422fe3ccbcfcaf41a869dfde (patch)
tree0b1de9537d95626a8fe6bc7fe59ca7bc3294b962
parente49f6f7da880e984400966d1985b1e7103535ee6 (diff)
Decided to kill uiInitError and return the message as a const char * instead. Will need to implement on Windows.
-rw-r--r--new/init_darwin.m9
-rw-r--r--new/init_unix.c28
-rw-r--r--new/test.c6
-rw-r--r--new/ui.h6
4 files changed, 17 insertions, 32 deletions
diff --git a/new/init_darwin.m b/new/init_darwin.m
index 8d1a117..c7be20d 100644
--- a/new/init_darwin.m
+++ b/new/init_darwin.m
@@ -42,7 +42,7 @@
uiInitOptions options;
-uiInitError *uiInit(uiInitOptions *o)
+const char *uiInit(uiInitOptions *o)
{
options = *o;
[uiApplication sharedApplication];
@@ -53,11 +53,6 @@ uiInitError *uiInit(uiInitOptions *o)
return NULL;
}
-const char *uiInitErrorMessage(uiInitError *err)
-{
- return "";
-}
-
-void uiInitErrorFree(uiInitError *err)
+void uiFreeInitError(const char *err)
{
}
diff --git a/new/init_unix.c b/new/init_unix.c
index 60abc91..b10c05b 100644
--- a/new/init_unix.c
+++ b/new/init_unix.c
@@ -1,31 +1,23 @@
// 6 april 2015
#include "uipriv_unix.h"
-struct uiInitError {
- GError *err;
-};
-
uiInitOptions options;
-uiInitError *uiInit(uiInitOptions *o)
+const char *uiInit(uiInitOptions *o)
{
- uiInitError *err;
+ GError *err = NULL;
+ const char *msg;
options = *o;
- err = uiNew(uiInitError);
- if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &(err->err)) == FALSE)
- return err;
- uiFree(err);
+ if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) {
+ msg = g_strdup(err->message);
+ g_error_free(err);
+ return msg;
+ }
return NULL;
}
-const char *uiInitErrorMessage(uiInitError *err)
-{
- return err->err->message;
-}
-
-void uiInitErrorFree(uiInitError *err)
+void uiFreeInitError(const char *err)
{
- g_error_free(err->err);
- uiFree(err);
+ g_free((gpointer) err);
}
diff --git a/new/test.c b/new/test.c
index 991b62b..f61038e 100644
--- a/new/test.c
+++ b/new/test.c
@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
{
uiInitOptions o;
int i;
- uiInitError *err;
+ const char *err;
uiControl *getButton, *setButton;
memset(&o, 0, sizeof (uiInitOptions));
@@ -128,8 +128,8 @@ int main(int argc, char *argv[])
err = uiInit(&o);
if (err != NULL) {
- fprintf(stderr, "error initializing ui: %s\n", uiInitErrorMessage(err));
- uiInitErrorFree(err);
+ fprintf(stderr, "error initializing ui: %s\n", err);
+ uiFreeInitError(err);
return 1;
}
diff --git a/new/ui.h b/new/ui.h
index a692585..0625bd0 100644
--- a/new/ui.h
+++ b/new/ui.h
@@ -5,7 +5,6 @@
#include <stdint.h>
-typedef struct uiInitError uiInitError;
typedef struct uiInitOptions uiInitOptions;
// TODO note that should be initialized to zero
@@ -17,9 +16,8 @@ struct uiInitOptions {
int debugLogAllocations;
};
-uiInitError *uiInit(uiInitOptions *);
-const char *uiInitErrorMessage(uiInitError *);
-void uiInitErrorFree(uiInitError *);
+const char *uiInit(uiInitOptions *);
+void uiFreeInitError(const char *);
void uiMain(void);
void uiQuit(void);