* 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, >k3_ok, TRUE },
+ LOPTS_INITIALIZER,
{ 0 }
};
gboolean no_self_alias = FALSE;
gboolean always_private_struct = FALSE;
gboolean gtk3_ok = FALSE;
-
-gint prealloc = 0;
-
-
-
+gint npreallocs = 0;
gboolean use_m4 = FALSE; /* preprocess sources with m4 */
char *m4_commandline = NULL;
#define M4_INCLUDE_DIR PKGDATADIR "/m4"
filebase = replace_sep (((Class *)class)->otype, file_sep);
gob_strdown (filebase);
- if (output_dir != NULL &&
- output_dir[0] != '\0') {
- fullfilebase = g_build_filename (output_dir, filebase, NULL);
+ if (output_dir != NULL && output_dir[0] != '\0') {
+ fullfilebase = g_strdup_printf("%s%c%s", output_dir,
+ G_DIR_SEPARATOR, filebase);
} else {
fullfilebase = g_strdup (filebase);
}
"\t\t(GInstanceInitFunc) %s_init,\n"
"\t\tNULL\n"
"\t};\n\n",
- typebase, funcbase, typebase, prealloc, funcbase);
+ typebase, funcbase, typebase, npreallocs, funcbase);
}
static void
"perhaps it was misspelled",
flag);
}
- g_string_sprintfa(gs, " | G_SIGNAL_%s", flag);
+ g_string_append_printf(gs, " | G_SIGNAL_%s", flag);
}
{
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, ")");
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, ")");
get_arg_names_for_macro (Method *m)
{
const char *sep;
+ char *ret;
GList *li;
GString *gs = g_string_new(NULL);
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);
+
+ ret = gs->str;
+ g_string_free(gs, FALSE);
+ return ret;
}
static gboolean method_is_void(Method *m)
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)
}
}
-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/");
}