/* File autogenerated by gengetopt version 2.19.1 generated with the following command: gengetopt --unamed-opts --no-handle-help The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: we make no copyright claims on it. */ /* If we use autoconf. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include "getopt.h" #include "cmdline.h" const char *gengetopt_args_info_purpose = "This program converts DVI files to Scalable Vector Graphics (SVG)"; const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS] dvifile"; const char *gengetopt_args_info_description = ""; const char *gengetopt_args_info_help[] = { "Input options:", " -p, --page=number choose page to convert (default: 1)", " -m, --map-file=filename set font map file name (default: dvipdfm.map)", "\nSVG output options:", " -b, --bbox-format=fmt set format of bounding box (default: min)", " -o, --output=filename set name of output file", " -s, --stdout write SVG output to stdout", " -z, --zip[=level] create compressed .svgz file (default: 9)", "\nSVG transformations:", " -r, --rotate=angle rotate page content clockwise", " -c, --scale=sx[,sy] scale page content", " -t, --translate=tx[,ty] shift page content", " -T, --transform=commands transform page content", "\nProcessing options:", " -M, --mag=factor magnification of Metafont output (default: 4)", " -n, --no-mktexmf don't try to create missing fonts (default: off)", " -S, --specials process \\specials (default: off)", "\nMessage options:", " -h, --help print this help and exit", " -v, --verbosity=level set verbosity level (0-7) (default: 7)", " -V, --version print version and exit", 0 }; static void clear_given (struct gengetopt_args_info *args_info); static void clear_args (struct gengetopt_args_info *args_info); static int cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); static char * gengetopt_strdup (const char *s); static void clear_given (struct gengetopt_args_info *args_info) { args_info->page_given = 0 ; args_info->map_file_given = 0 ; args_info->bbox_format_given = 0 ; args_info->output_given = 0 ; args_info->stdout_given = 0 ; args_info->zip_given = 0 ; args_info->rotate_given = 0 ; args_info->scale_given = 0 ; args_info->translate_given = 0 ; args_info->transform_given = 0 ; args_info->mag_given = 0 ; args_info->no_mktexmf_given = 0 ; args_info->specials_given = 0 ; args_info->help_given = 0 ; args_info->verbosity_given = 0 ; args_info->version_given = 0 ; } static void clear_args (struct gengetopt_args_info *args_info) { args_info->page_arg = 1; args_info->page_orig = NULL; args_info->map_file_arg = gengetopt_strdup ("dvipdfm.map"); args_info->map_file_orig = NULL; args_info->bbox_format_arg = gengetopt_strdup ("min"); args_info->bbox_format_orig = NULL; args_info->output_arg = NULL; args_info->output_orig = NULL; args_info->zip_arg = 9; args_info->zip_orig = NULL; args_info->rotate_orig = NULL; args_info->scale_arg = NULL; args_info->scale_orig = NULL; args_info->translate_arg = NULL; args_info->translate_orig = NULL; args_info->transform_arg = NULL; args_info->transform_orig = NULL; args_info->mag_arg = 4; args_info->mag_orig = NULL; args_info->no_mktexmf_flag = 0; args_info->specials_flag = 0; args_info->verbosity_arg = 7; args_info->verbosity_orig = NULL; } static void init_args_info(struct gengetopt_args_info *args_info) { args_info->page_help = gengetopt_args_info_help[1] ; args_info->map_file_help = gengetopt_args_info_help[2] ; args_info->bbox_format_help = gengetopt_args_info_help[4] ; args_info->output_help = gengetopt_args_info_help[5] ; args_info->stdout_help = gengetopt_args_info_help[6] ; args_info->zip_help = gengetopt_args_info_help[7] ; args_info->rotate_help = gengetopt_args_info_help[9] ; args_info->scale_help = gengetopt_args_info_help[10] ; args_info->translate_help = gengetopt_args_info_help[11] ; args_info->transform_help = gengetopt_args_info_help[12] ; args_info->mag_help = gengetopt_args_info_help[14] ; args_info->no_mktexmf_help = gengetopt_args_info_help[15] ; args_info->specials_help = gengetopt_args_info_help[16] ; args_info->help_help = gengetopt_args_info_help[18] ; args_info->verbosity_help = gengetopt_args_info_help[19] ; args_info->version_help = gengetopt_args_info_help[20] ; } void cmdline_parser_print_version (void) { printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); } void cmdline_parser_print_help (void) { int i = 0; cmdline_parser_print_version (); if (strlen(gengetopt_args_info_purpose) > 0) printf("\n%s\n", gengetopt_args_info_purpose); printf("\n%s\n\n", gengetopt_args_info_usage); if (strlen(gengetopt_args_info_description) > 0) printf("%s\n", gengetopt_args_info_description); while (gengetopt_args_info_help[i]) printf("%s\n", gengetopt_args_info_help[i++]); } void cmdline_parser_init (struct gengetopt_args_info *args_info) { clear_given (args_info); clear_args (args_info); init_args_info (args_info); args_info->inputs = NULL; args_info->inputs_num = 0; } static void cmdline_parser_release (struct gengetopt_args_info *args_info) { unsigned int i; if (args_info->page_orig) { free (args_info->page_orig); /* free previous argument */ args_info->page_orig = 0; } if (args_info->map_file_arg) { free (args_info->map_file_arg); /* free previous argument */ args_info->map_file_arg = 0; } if (args_info->map_file_orig) { free (args_info->map_file_orig); /* free previous argument */ args_info->map_file_orig = 0; } if (args_info->bbox_format_arg) { free (args_info->bbox_format_arg); /* free previous argument */ args_info->bbox_format_arg = 0; } if (args_info->bbox_format_orig) { free (args_info->bbox_format_orig); /* free previous argument */ args_info->bbox_format_orig = 0; } if (args_info->output_arg) { free (args_info->output_arg); /* free previous argument */ args_info->output_arg = 0; } if (args_info->output_orig) { free (args_info->output_orig); /* free previous argument */ args_info->output_orig = 0; } if (args_info->zip_orig) { free (args_info->zip_orig); /* free previous argument */ args_info->zip_orig = 0; } if (args_info->rotate_orig) { free (args_info->rotate_orig); /* free previous argument */ args_info->rotate_orig = 0; } if (args_info->scale_arg) { free (args_info->scale_arg); /* free previous argument */ args_info->scale_arg = 0; } if (args_info->scale_orig) { free (args_info->scale_orig); /* free previous argument */ args_info->scale_orig = 0; } if (args_info->translate_arg) { free (args_info->translate_arg); /* free previous argument */ args_info->translate_arg = 0; } if (args_info->translate_orig) { free (args_info->translate_orig); /* free previous argument */ args_info->translate_orig = 0; } if (args_info->transform_arg) { free (args_info->transform_arg); /* free previous argument */ args_info->transform_arg = 0; } if (args_info->transform_orig) { free (args_info->transform_orig); /* free previous argument */ args_info->transform_orig = 0; } if (args_info->mag_orig) { free (args_info->mag_orig); /* free previous argument */ args_info->mag_orig = 0; } if (args_info->verbosity_orig) { free (args_info->verbosity_orig); /* free previous argument */ args_info->verbosity_orig = 0; } for (i = 0; i < args_info->inputs_num; ++i) free (args_info->inputs [i]); if (args_info->inputs_num) free (args_info->inputs); clear_given (args_info); } int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) { FILE *outfile; int i = 0; outfile = fopen(filename, "w"); if (!outfile) { fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); return EXIT_FAILURE; } if (args_info->page_given) { if (args_info->page_orig) { fprintf(outfile, "%s=\"%s\"\n", "page", args_info->page_orig); } else { fprintf(outfile, "%s\n", "page"); } } if (args_info->map_file_given) { if (args_info->map_file_orig) { fprintf(outfile, "%s=\"%s\"\n", "map-file", args_info->map_file_orig); } else { fprintf(outfile, "%s\n", "map-file"); } } if (args_info->bbox_format_given) { if (args_info->bbox_format_orig) { fprintf(outfile, "%s=\"%s\"\n", "bbox-format", args_info->bbox_format_orig); } else { fprintf(outfile, "%s\n", "bbox-format"); } } if (args_info->output_given) { if (args_info->output_orig) { fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); } else { fprintf(outfile, "%s\n", "output"); } } if (args_info->stdout_given) { fprintf(outfile, "%s\n", "stdout"); } if (args_info->zip_given) { if (args_info->zip_orig) { fprintf(outfile, "%s=\"%s\"\n", "zip", args_info->zip_orig); } else { fprintf(outfile, "%s\n", "zip"); } } if (args_info->rotate_given) { if (args_info->rotate_orig) { fprintf(outfile, "%s=\"%s\"\n", "rotate", args_info->rotate_orig); } else { fprintf(outfile, "%s\n", "rotate"); } } if (args_info->scale_given) { if (args_info->scale_orig) { fprintf(outfile, "%s=\"%s\"\n", "scale", args_info->scale_orig); } else { fprintf(outfile, "%s\n", "scale"); } } if (args_info->translate_given) { if (args_info->translate_orig) { fprintf(outfile, "%s=\"%s\"\n", "translate", args_info->translate_orig); } else { fprintf(outfile, "%s\n", "translate"); } } if (args_info->transform_given) { if (args_info->transform_orig) { fprintf(outfile, "%s=\"%s\"\n", "transform", args_info->transform_orig); } else { fprintf(outfile, "%s\n", "transform"); } } if (args_info->mag_given) { if (args_info->mag_orig) { fprintf(outfile, "%s=\"%s\"\n", "mag", args_info->mag_orig); } else { fprintf(outfile, "%s\n", "mag"); } } if (args_info->no_mktexmf_given) { fprintf(outfile, "%s\n", "no-mktexmf"); } if (args_info->specials_given) { fprintf(outfile, "%s\n", "specials"); } if (args_info->help_given) { fprintf(outfile, "%s\n", "help"); } if (args_info->verbosity_given) { if (args_info->verbosity_orig) { fprintf(outfile, "%s=\"%s\"\n", "verbosity", args_info->verbosity_orig); } else { fprintf(outfile, "%s\n", "verbosity"); } } if (args_info->version_given) { fprintf(outfile, "%s\n", "version"); } fclose (outfile); i = EXIT_SUCCESS; return i; } void cmdline_parser_free (struct gengetopt_args_info *args_info) { cmdline_parser_release (args_info); } /* gengetopt_strdup() */ /* strdup.c replacement of strdup, which is not standard */ char * gengetopt_strdup (const char *s) { char *result = NULL; if (!s) return result; result = (char*)malloc(strlen(s) + 1); if (result == (char*)0) return (char*)0; strcpy(result, s); return result; } int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) { return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); } int cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) { int result; result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); if (result == EXIT_FAILURE) { cmdline_parser_free (args_info); exit (EXIT_FAILURE); } return result; } int cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) { return EXIT_SUCCESS; } int cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) { int c; /* Character of the parsed option. */ int error = 0; struct gengetopt_args_info local_args_info; if (initialize) cmdline_parser_init (args_info); cmdline_parser_init (&local_args_info); optarg = 0; optind = 0; opterr = 1; optopt = '?'; while (1) { int option_index = 0; char *stop_char; static struct option long_options[] = { { "page", 1, NULL, 'p' }, { "map-file", 1, NULL, 'm' }, { "bbox-format", 1, NULL, 'b' }, { "output", 1, NULL, 'o' }, { "stdout", 0, NULL, 's' }, { "zip", 2, NULL, 'z' }, { "rotate", 1, NULL, 'r' }, { "scale", 1, NULL, 'c' }, { "translate", 1, NULL, 't' }, { "transform", 1, NULL, 'T' }, { "mag", 1, NULL, 'M' }, { "no-mktexmf", 0, NULL, 'n' }, { "specials", 0, NULL, 'S' }, { "help", 0, NULL, 'h' }, { "verbosity", 1, NULL, 'v' }, { "version", 0, NULL, 'V' }, { NULL, 0, NULL, 0 } }; stop_char = 0; c = getopt_long (argc, argv, "p:m:b:o:sz::r:c:t:T:M:nShv:V", long_options, &option_index); if (c == -1) break; /* Exit from `while (1)' loop. */ switch (c) { case 'p': /* choose page to convert. */ if (local_args_info.page_given) { fprintf (stderr, "%s: `--page' (`-p') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->page_given && ! override) continue; local_args_info.page_given = 1; args_info->page_given = 1; args_info->page_arg = strtol (optarg, &stop_char, 0); if (!(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); goto failure; } if (args_info->page_orig) free (args_info->page_orig); /* free previous string */ args_info->page_orig = gengetopt_strdup (optarg); break; case 'm': /* set font map file name. */ if (local_args_info.map_file_given) { fprintf (stderr, "%s: `--map-file' (`-m') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->map_file_given && ! override) continue; local_args_info.map_file_given = 1; args_info->map_file_given = 1; if (args_info->map_file_arg) free (args_info->map_file_arg); /* free previous string */ args_info->map_file_arg = gengetopt_strdup (optarg); if (args_info->map_file_orig) free (args_info->map_file_orig); /* free previous string */ args_info->map_file_orig = gengetopt_strdup (optarg); break; case 'b': /* set format of bounding box. */ if (local_args_info.bbox_format_given) { fprintf (stderr, "%s: `--bbox-format' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->bbox_format_given && ! override) continue; local_args_info.bbox_format_given = 1; args_info->bbox_format_given = 1; if (args_info->bbox_format_arg) free (args_info->bbox_format_arg); /* free previous string */ args_info->bbox_format_arg = gengetopt_strdup (optarg); if (args_info->bbox_format_orig) free (args_info->bbox_format_orig); /* free previous string */ args_info->bbox_format_orig = gengetopt_strdup (optarg); break; case 'o': /* set name of output file. */ if (local_args_info.output_given) { fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->output_given && ! override) continue; local_args_info.output_given = 1; args_info->output_given = 1; if (args_info->output_arg) free (args_info->output_arg); /* free previous string */ args_info->output_arg = gengetopt_strdup (optarg); if (args_info->output_orig) free (args_info->output_orig); /* free previous string */ args_info->output_orig = gengetopt_strdup (optarg); break; case 's': /* write SVG output to stdout. */ if (local_args_info.stdout_given) { fprintf (stderr, "%s: `--stdout' (`-s') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->stdout_given && ! override) continue; local_args_info.stdout_given = 1; args_info->stdout_given = 1; break; case 'z': /* create compressed .svgz file. */ if (local_args_info.zip_given) { fprintf (stderr, "%s: `--zip' (`-z') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->zip_given && ! override) continue; local_args_info.zip_given = 1; args_info->zip_given = 1; if (optarg) { args_info->zip_arg = strtol (optarg, &stop_char, 0); if (!(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); goto failure; } if (args_info->zip_orig) free (args_info->zip_orig); /* free previous string */ args_info->zip_orig = gengetopt_strdup (optarg); } break; case 'r': /* rotate page content clockwise. */ if (local_args_info.rotate_given) { fprintf (stderr, "%s: `--rotate' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->rotate_given && ! override) continue; local_args_info.rotate_given = 1; args_info->rotate_given = 1; args_info->rotate_arg = strtod (optarg, &stop_char); if (!(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); goto failure; } if (args_info->rotate_orig) free (args_info->rotate_orig); /* free previous string */ args_info->rotate_orig = gengetopt_strdup (optarg); break; case 'c': /* scale page content. */ if (local_args_info.scale_given) { fprintf (stderr, "%s: `--scale' (`-c') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->scale_given && ! override) continue; local_args_info.scale_given = 1; args_info->scale_given = 1; if (args_info->scale_arg) free (args_info->scale_arg); /* free previous string */ args_info->scale_arg = gengetopt_strdup (optarg); if (args_info->scale_orig) free (args_info->scale_orig); /* free previous string */ args_info->scale_orig = gengetopt_strdup (optarg); break; case 't': /* shift page content. */ if (local_args_info.translate_given) { fprintf (stderr, "%s: `--translate' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->translate_given && ! override) continue; local_args_info.translate_given = 1; args_info->translate_given = 1; if (args_info->translate_arg) free (args_info->translate_arg); /* free previous string */ args_info->translate_arg = gengetopt_strdup (optarg); if (args_info->translate_orig) free (args_info->translate_orig); /* free previous string */ args_info->translate_orig = gengetopt_strdup (optarg); break; case 'T': /* transform page content. */ if (local_args_info.transform_given) { fprintf (stderr, "%s: `--transform' (`-T') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->transform_given && ! override) continue; local_args_info.transform_given = 1; args_info->transform_given = 1; if (args_info->transform_arg) free (args_info->transform_arg); /* free previous string */ args_info->transform_arg = gengetopt_strdup (optarg); if (args_info->transform_orig) free (args_info->transform_orig); /* free previous string */ args_info->transform_orig = gengetopt_strdup (optarg); break; case 'M': /* magnification of Metafont output. */ if (local_args_info.mag_given) { fprintf (stderr, "%s: `--mag' (`-M') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->mag_given && ! override) continue; local_args_info.mag_given = 1; args_info->mag_given = 1; args_info->mag_arg = strtod (optarg, &stop_char); if (!(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); goto failure; } if (args_info->mag_orig) free (args_info->mag_orig); /* free previous string */ args_info->mag_orig = gengetopt_strdup (optarg); break; case 'n': /* don't try to create missing fonts. */ if (local_args_info.no_mktexmf_given) { fprintf (stderr, "%s: `--no-mktexmf' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->no_mktexmf_given && ! override) continue; local_args_info.no_mktexmf_given = 1; args_info->no_mktexmf_given = 1; args_info->no_mktexmf_flag = !(args_info->no_mktexmf_flag); break; case 'S': /* process \\specials. */ if (local_args_info.specials_given) { fprintf (stderr, "%s: `--specials' (`-S') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->specials_given && ! override) continue; local_args_info.specials_given = 1; args_info->specials_given = 1; args_info->specials_flag = !(args_info->specials_flag); break; case 'h': /* Print help and exit. */ if (local_args_info.help_given) { fprintf (stderr, "%s: `--help' (`-h') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->help_given && ! override) continue; local_args_info.help_given = 1; args_info->help_given = 1; cmdline_parser_free (&local_args_info); return 0; case 'v': /* set verbosity level (0-7). */ if (local_args_info.verbosity_given) { fprintf (stderr, "%s: `--verbosity' (`-v') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); goto failure; } if (args_info->verbosity_given && ! override) continue; local_args_info.verbosity_given = 1; args_info->verbosity_given = 1; args_info->verbosity_arg = strtol (optarg, &stop_char, 0); if (!(stop_char && *stop_char == '\0')) { fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); goto failure; } if (args_info->verbosity_orig) free (args_info->verbosity_orig); /* free previous string */ args_info->verbosity_orig = gengetopt_strdup (optarg); break; case 'V': /* Print version and exit. */ cmdline_parser_print_version (); cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 0: /* Long option with no short option */ case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ goto failure; default: /* bug: option not considered. */ fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); abort (); } /* switch */ } /* while */ cmdline_parser_release (&local_args_info); if ( error ) return (EXIT_FAILURE); if (optind < argc) { int i = 0 ; int found_prog_name = 0; /* whether program name, i.e., argv[0], is in the remaining args (this may happen with some implementations of getopt, but surely not with the one included by gengetopt) */ i = optind; while (i < argc) if (argv[i++] == argv[0]) { found_prog_name = 1; break; } i = 0; args_info->inputs_num = argc - optind - found_prog_name; args_info->inputs = (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; while (optind < argc) if (argv[optind++] != argv[0]) args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; } return 0; failure: cmdline_parser_release (&local_args_info); return (EXIT_FAILURE); }