]> git.draconx.ca Git - gob-dx.git/blobdiff - src/main.c
Use help formatting routines from dxcommon.
[gob-dx.git] / src / main.c
index c994d5ae3b0119326e3f32b52300a7fb997b71c8..0e6c55c84c1709aeed581a94f1a7ac679a0bd689 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999,2000 the Free Software Foundation.
  * Copyright (C) 2000 Eazel, Inc.
  * Copyright (C) 2001-2011 George (Jiri) Lebl
- * Copyright © 2019-2021 Nick Bowler
+ * Copyright © 2019-2022 Nick Bowler
  *
  * Author: George (Jiri) Lebl
  *
 #include "out.h"
 #include "util.h"
 #include "checks.h"
+#include "help.h"
 
 #include "main.h"
 
-enum {
-       SOPT_END = UCHAR_MAX,
-       LOPT_VERSION,
-       LOPT_NO_TOUCH,
-       LOPT_FILE_SEP,
-       LOPT_M4,
-       LOPT_M4_CLEAN,
-       LOPT_M4_DIR
-};
+#include "options.h"
 
-static const char sopts[] = "wnho:";
+static const char sopts[] = SOPT_STRING;
 static const struct option lopts[] = {
-       { "help", 0, NULL, 'h' },
-       { "version", 0, NULL, LOPT_VERSION },
-       { "exit-on-warn", 0, NULL, 'w' },
-       { "no-exit-on-warn", 0, &exit_on_warn, FALSE },
-       { "for-cpp", 0, &for_cpp, TRUE },
-       { "no-extern-c", 0, &no_extern_c, TRUE },
-       { "no-gnu", 0, &no_gnu, TRUE },
-       { "no-touch", 0, NULL, LOPT_NO_TOUCH },
-       { "no-touch-headers", 0, &no_touch_headers, TRUE },
-       { "always-private-header", 0, &private_header, PRIVATE_HEADER_ALWAYS },
-       { "ondemand-private-header", 0, &private_header, PRIVATE_HEADER_ONDEMAND },
-       { "no-private-header", 0, &private_header, PRIVATE_HEADER_NEVER },
-       { "always-private-struct", 0, &always_private_struct, TRUE },
-       { "m4", 0, NULL, LOPT_M4 },
-       { "m4-clean", 0, NULL, LOPT_M4_CLEAN },
-       { "m4-dir", 0, NULL, LOPT_M4_DIR },
-       { "no-write", 0, NULL, 'n' },
-       { "no-lines", 0, &no_lines, TRUE },
-       { "no-self-alias", 0, &no_self_alias, TRUE },
-       { "no-kill-underscores", 0, NULL, 0 /* no-op */ },
-       { "output-dir", 1, NULL, 'o' },
-       { "file-sep", 2, NULL, LOPT_FILE_SEP },
-       { "gtk3", 0, &gtk3_ok, TRUE },
+       LOPTS_INITIALIZER,
        { 0 }
 };
 
@@ -1537,7 +1508,7 @@ make_run_signal_flags(Method *m, gboolean last)
                                     "perhaps it was misspelled",
                                     flag);
                }
-               g_string_sprintfa(gs, " | G_SIGNAL_%s", flag);
+               g_string_append_printf(gs, " | G_SIGNAL_%s", flag);
        }
 
        {
@@ -1761,7 +1732,7 @@ make_argument (Argument *a)
                        if(strcmp(argflags[i], flag)==0)
                                break;
                }
-               g_string_sprintfa(flags, " | %s%s", argflags[i] ? "G_PARAM_" : "", flag);
+               g_string_append_printf(flags, " | %s%s", argflags[i] ? "G_PARAM_" : "", flag);
        }
 
        g_string_append (flags, ")");
@@ -1951,7 +1922,7 @@ make_property (Property *p)
                                if(strcmp(argflags[i], flag)==0)
                                        break;
                        }
-                       g_string_sprintfa(flags, " | %s%s", argflags[i] ? "G_PARAM_" : "", flag);
+                       g_string_append_printf(flags, " | %s%s", argflags[i] ? "G_PARAM_" : "", flag);
                }
 
                g_string_append (flags, ")");
@@ -3199,7 +3170,7 @@ get_arg_names_for_macro (Method *m)
        sep = "";
        for(li=m->args;li;li=g_list_next(li)) {
                FuncArg *arg = li->data;
-               g_string_sprintfa (gs, "%s___%s", sep, arg->name);
+               g_string_append_printf(gs, "%s___%s", sep, arg->name);
                sep = ",";
        }
        return g_string_free (gs, FALSE);
@@ -4565,13 +4536,11 @@ generate_outfiles(void)
 static void print_version(void)
 {
        printf("%s (%s) %s\n", PACKAGE_NAME, PACKAGE_TARNAME, PACKAGE_VERSION);
-       putchar('\n');
        puts("Copyright (C) 2013 George (Jiri) Lebl et al.");
-       puts("Copyright (C) 2020 Nick Bowler");
-       puts("License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>.");
+       puts("Copyright (C) 2022 Nick Bowler");
+       puts("License GPLv2+: GNU GPL version 2 or any later version");
        puts("This is free software: you are free to change and redistribute it.");
        puts("There is NO WARRANTY, to the extent permitted by law.");
-
 }
 
 static void print_usage(FILE *f)
@@ -4583,61 +4552,29 @@ static void print_usage(FILE *f)
        }
 }
 
-static void
-print_help(void)
+static void print_help(void)
 {
+       const struct option *opt;
+
        print_usage(stdout);
 
-       puts(
-"This is \"GObject Builder\": a simple preprocessor to help with\n"
-"implementing GObject types in C.\n"
-       );
-
-       puts("Options:");
-       puts("  --help,-h,-?            Display this help\n"
-            "  --version               Display version\n"
-            "  --exit-on-warn,-w       Exit with an error on warnings\n"
-            "  --no-exit-on-warn       Don't exit on warnings [default]\n"
-            "  --for-cpp               Create C++ files\n"
-            "  --no-extern-c           Never print extern \"C\" into the "
-                                      "header\n"
-            "  --no-gnu                Never use GNU extentions\n"
-            "  --no-touch              Don't touch output files unless they "
-                                      "really\n"
-            "                          changed (implies --no-touch-headers)\n"
-            "  --no-touch-headers      Don't touch headers unless they "
-                                      "really changed\n"
-            "  --always-private-header Always create a private header "
-                                      "file,\n"
-            "                          even if it would be empty\n"
-            "  --ondemand-private-header Create private header only when "
-                                      "needed\n"
-            "                          [default]\n"
-            "  --no-private-header     Don't create a private header, "
-                                      "put private\n"
-            "                          structure and protected "
-                                      "prototypes inside c file\n"
-            "  --always-private-struct Always create a private pointer "
-                                      "in\n"
-            "                          the object structure\n"
-            "  --m4                    Preprocess source with m4. "
-                                      "Following args will\n"
-            "                          be passed to m4\n"
-            "  --m4-dir                Print directory that will be "
-                                      "searched for m4\n"
-            "                          files\n"
-            "  --no-write,-n           Don't write output files, just "
-                                      "check syntax\n"
-            "  --no-lines              Don't print '#line' to output\n"
-            "  --no-self-alias         Don't create self type and macro "
-                                      "aliases\n"
-            "  --no-kill-underscores   Ignored for compatibility\n"
-            "  -o,--output-dir         The directory where output "
-                                 "should be placed\n"
-            "  --file-sep[=c]          replace default \'-\' file "
-                                      "name separator\n\n"
-            "  --gtk3                  Use gtk+3\n"
-            );
+       puts("This is \"GObject Builder\": a simple preprocessor to help with\n"
+             "implementing GObject types in C.");
+
+       puts("\nOptions:");
+       for (opt = lopts; opt->name; opt++) {
+               struct lopt_help help;
+
+               /* Don't display obsolete options that don't do anything */
+               if (!opt->flag && !opt->val)
+                       continue;
+
+               if (!lopt_get_help(opt, &help))
+                       continue;
+
+               help_print_option(opt, help.arg, help.desc, 20);
+       }
+       putchar('\n');
 
        puts("End world hunger, donate to the World Food Programme: https://www.wfp.org/");
 }