]> git.draconx.ca Git - cdecl99.git/blobdiff - src/cdecl99.c
Add support for parsing English-like declarations.
[cdecl99.git] / src / cdecl99.c
index 2df7ec8c98543293a7c980178a3fd6b28a9cfd89..64b95f78cf38a2778dd5a20bad73efc43d45553b 100644 (file)
@@ -151,6 +151,32 @@ out:
        return ret;
 }
 
+static int cmd_declare(const char *cmd, const char *arg)
+{
+       struct cdecl *decl;
+       const char *str;
+       int ret = -1;
+
+       /* The name of the command is significant here. */
+       decl = cdecl_parse_english(cmd);
+       if (!decl)
+               goto out;
+
+       /*
+        * English parses have at most one full declarator, so no loop is
+        * needed here.
+        */
+       str = do_format(cdecl_declare, decl);
+       if (!str)
+               goto out;
+
+       printf("%s\n", str);
+       ret = 1;
+out:
+       cdecl_free(decl);
+       return ret;
+}
+
 static int cmd_quit(const char *cmd, const char *arg)
 {
        return 0;
@@ -165,6 +191,8 @@ static const struct command {
 } commands[] = {
        { "explain",  cmd_explain,  "Explain a C declaration." },
        { "simplify", cmd_simplify, "Simplify a C declaration." },
+       { "declare",  cmd_declare,  "Construct a C declaration." },
+       { "type",     cmd_declare,  "Construct a C type name." },
        { "help",     cmd_help,     "Print this list of commands." },
        { "quit",     cmd_quit,     "Quit the program." },
        { "exit",     cmd_quit,     NULL }