X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/02cf98875fd0b8462ce39778db16cfd347b5c2d0..128651aeb8a83a6a240298b0391c2d183763ec93:/src/main.c diff --git a/src/main.c b/src/main.c index 8e6c04e..16f59dd 100644 --- a/src/main.c +++ b/src/main.c @@ -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 * @@ -28,9 +28,7 @@ #include #include #include -#include #include -#include #include #include @@ -39,6 +37,7 @@ #include "out.h" #include "util.h" #include "checks.h" +#include "help.h" #include "main.h" @@ -132,11 +131,7 @@ gboolean no_lines = FALSE; 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" @@ -152,9 +147,9 @@ make_bases (void) 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); } @@ -1268,7 +1263,7 @@ static void add_type_info(void) "\t\t(GInstanceInitFunc) %s_init,\n" "\t\tNULL\n" "\t};\n\n", - typebase, funcbase, typebase, prealloc, funcbase); + typebase, funcbase, typebase, npreallocs, funcbase); } static void @@ -3164,6 +3159,7 @@ static char * get_arg_names_for_macro (Method *m) { const char *sep; + char *ret; GList *li; GString *gs = g_string_new(NULL); sep = ""; @@ -3172,7 +3168,10 @@ get_arg_names_for_macro (Method *m) 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) @@ -4535,13 +4534,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 ."); + 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) @@ -4553,46 +4550,6 @@ static void print_usage(FILE *f) } } -/* - * Given a long option, return the corresponding short option character, - * or 0 if there is no such character. - */ -static char lopt_to_sopt(const char *sopts, const struct option *opt) -{ - int val = opt->val; - const char *c; - - if (val <= 0 || val > CHAR_MAX) - return 0; - - if (val == ':' || val == '+' || val == '-') - return 0; - - c = strchr(sopts, opt->val); - if (c) - return *c; - return 0; -} - -/* - * Print a string, with each line indented by i spaces. The first line - * will be indented by w fewer spaces (to account for the cursor being in - * some other column). - */ -static void print_block(const char *s, int i, int w) -{ - for (; *s; w = 0) { - const char *nl = strchr(s, '\n'); - int n = (nl ? nl-s : -1); - - printf("%*s%.*s\n", i-w, "", n, s); - if (!nl) - break; - - s = nl+1; - } -} - static void print_help(void) { const struct option *opt; @@ -4605,8 +4562,6 @@ static void print_help(void) puts("\nOptions:"); for (opt = lopts; opt->name; opt++) { struct lopt_help help; - char sopt; - int w; /* Don't display obsolete options that don't do anything */ if (!opt->flag && !opt->val) @@ -4615,24 +4570,7 @@ static void print_help(void) if (!lopt_get_help(opt, &help)) continue; - if ((sopt = lopt_to_sopt(sopts, opt))) { - w = printf(opt->has_arg == 0 ? " -%c, --%s" - : opt->has_arg == 1 ? " -%c, --%s=%s" - : " -%c, --%s[=%s]", - sopt, opt->name, help.arg); - } else { - w = printf(opt->has_arg == 0 ? " --%s" - : opt->has_arg == 1 ? " --%s=%s" - : " --%s[=%s]", - opt->name, help.arg); - } - - if (w < 0 || w > 18) { - putchar('\n'); - w = 0; - } - - print_block(help.desc, 20, w); + help_print_option(opt, help.arg, help.desc, 20); } putchar('\n'); @@ -4834,25 +4772,27 @@ compare_and_move (const char *old_filename) if (error) goto end; - if (! equal && unlink (old_filename) != 0) { - error_printf (GOB_ERROR, 0, "Can't remove %s: %s", - old_filename, g_strerror (errno)); + if (!equal && remove(old_filename) != 0) { + error_printf(GOB_ERROR, 0, "Can't remove %s: %s", + old_filename, g_strerror (errno)); goto end; } } if (equal) { - if (unlink (new_filename) != 0) - error_printf (GOB_ERROR, 0, "Can't remove %s: %s", - new_filename, g_strerror (errno)); + if (remove(new_filename) != 0) { + error_printf(GOB_ERROR, 0, "Can't remove %s: %s", + new_filename, g_strerror(errno)); + } } else { - if (rename (new_filename, old_filename) != 0) - error_printf (GOB_ERROR, 0, "Can't rename %s to %s: %s", - new_filename, old_filename, - g_strerror (errno)); + if (rename(new_filename, old_filename) != 0) { + error_printf(GOB_ERROR, 0, "Can't rename %s to %s: %s", + new_filename, old_filename, + g_strerror(errno)); + } } - end: +end: g_free (new_filename); }