]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl99.c
Start implementing proper error handling.
[cdecl99.git] / src / cdecl99.c
index 04de1a6640e92225676f3e56872a63e26945a70d..c5f913bd12d1fd0a442bdc0f2aa82def63d3a5cf 100644 (file)
@@ -97,13 +97,17 @@ retry:
 
 static int cmd_explain(const char *cmd, const char *arg)
 {
+       const struct cdecl_error *err;
        struct cdecl *decl;
        const char *str;
        int ret = -1;
 
        decl = cdecl_parse_decl(arg);
-       if (!decl)
+       if (!decl) {
+               err = cdecl_get_error();
+               fprintf(stderr, "%s\n", err->str);
                goto out;
+       }
 
        for (struct cdecl *i = decl; i; i = i->next) {
                str = do_format(cdecl_explain, i);
@@ -121,13 +125,17 @@ out:
 
 static int cmd_simplify(const char *cmd, const char *arg)
 {
+       const struct cdecl_error *err;
        struct cdecl *decl;
        const char *str;
        int ret = -1;
 
        decl = cdecl_parse_decl(arg);
-       if (!decl)
+       if (!decl) {
+               err = cdecl_get_error();
+               fprintf(stderr, "%s\n", err->str);
                goto out;
+       }
 
        for (struct cdecl *i = decl; i; i = i->next) {
                struct cdecl_declspec *s = i->specifiers;
@@ -156,14 +164,18 @@ out:
 
 static int cmd_declare(const char *cmd, const char *arg)
 {
+       const struct cdecl_error *err;
        struct cdecl *decl;
        const char *str;
        int ret = -1;
 
        /* The name of the command is significant here. */
        decl = cdecl_parse_english(cmd);
-       if (!decl)
+       if (!decl) {
+               err = cdecl_get_error();
+               fprintf(stderr, "%s\n", err->str);
                goto out;
+       }
 
        /*
         * English parses have at most one full declarator, so no loop is