void titleformat_compiler::remove_forbidden_chars_string_append(pfc::string_receiver & p_out,const char * p_source,t_size p_source_len,const char * p_reserved_chars) { titleformat_text_out_impl_string p_text_out(p_out); remove_forbidden_chars(&p_text_out,pfc::guid_null,p_source,p_source_len,p_reserved_chars); }
int parse_args(int *argc, char **argv, clamz_config *cfg) { int i; int nfilenames = 0; read_user_config(cfg); for (i = 1; i < *argc; i++) { if (argv[i][0] != '-' || !argv[i][1]) { argv[nfilenames + 1] = argv[i]; nfilenames++; } else if (argv[i][1] == '-' && argv[i][2] == 0) { i++; while (i < *argc) { argv[nfilenames + 1] = argv[i]; nfilenames++; i++; } break; } else if (argv[i][1] != '-') { switch (argv[i][1]) { case 'd': if (cfg->output_dir) free(cfg->output_dir); cfg->output_dir = NULL; if (argv[i][2]) cfg->output_dir = strdup(&argv[i][2]); else if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } else { i++; cfg->output_dir = strdup(argv[i]); } if (!cfg->output_dir) { print_error("Out of memory"); return 1; } break; case 'o': if (cfg->name_format) free(cfg->name_format); cfg->name_format = NULL; if (argv[i][2]) cfg->name_format = strdup(&argv[i][2]); else if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } else { i++; cfg->name_format = strdup(argv[i]); } if (!cfg->name_format) { print_error("Out of memory"); return 1; } break; case 'r': cfg->resume = 1; break; case 'i': cfg->printonly = 1; break; case 'x': cfg->printonly = cfg->printasxml = 1; break; case 'v': cfg->verbose = 1; break; case 'q': cfg->quiet = 1; break; default: fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } } else if (!strcasecmp(argv[i], "--output-dir")) { if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } i++; if (cfg->output_dir) free(cfg->output_dir); cfg->output_dir = strdup(argv[i]); if (!cfg->output_dir) { print_error("Out of memory"); return 1; } } else if (!strncasecmp(argv[i], "--output-dir=", 13)) { if (cfg->output_dir) free(cfg->output_dir); cfg->output_dir = strdup(argv[i] + 13); if (!cfg->output_dir) { print_error("Out of memory"); return 1; } } else if (!strcasecmp(argv[i], "--default-output-dir")) { if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } i++; if (!cfg->output_dir) cfg->output_dir = strdup(argv[i]); if (!cfg->output_dir) { print_error("Out of memory"); return 1; } } else if (!strncasecmp(argv[i], "--default-output-dir=", 21)) { if (!cfg->output_dir) cfg->output_dir = strdup(argv[i] + 21); if (!cfg->output_dir) { print_error("Out of memory"); return 1; } } else if (!strcasecmp(argv[i], "--output")) { if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } i++; if (cfg->name_format) free(cfg->name_format); cfg->name_format = strdup(argv[i]); if (!cfg->name_format) { print_error("Out of memory"); return 1; } } else if (!strncasecmp(argv[i], "--output=", 9)) { if (cfg->name_format) free(cfg->name_format); cfg->name_format = strdup(argv[i] + 9); if (!cfg->name_format) { print_error("Out of memory"); return 1; } } else if (!strcasecmp(argv[i], "--allow-chars")) { if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } i++; remove_forbidden_chars(cfg, argv[i]); } else if (!strncasecmp(argv[i], "--allow-chars=", 14)) { remove_forbidden_chars(cfg, argv[i] + 14); } else if (!strcasecmp(argv[i], "--forbid-chars")) { if (i == *argc - 1) { fprintf(stderr, "%s: %s: requires argument\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } i++; if (add_forbidden_chars(cfg, argv[i])) return 1; } else if (!strncasecmp(argv[i], "--forbid-chars=", 15)) { if (add_forbidden_chars(cfg, argv[i] + 15)) return 1; } else if (!strcasecmp(argv[i], "--allow-uppercase")) cfg->allowupper = 1; else if (!strcasecmp(argv[i], "--forbid-uppercase")) cfg->allowupper = 0; else if (!strcasecmp(argv[i], "--utf8-filenames") || !strcasecmp(argv[i], "--utf-8-filenames")) cfg->allowutf8 = 1; else if (!strcasecmp(argv[i], "--ascii-filenames")) cfg->allowutf8 = 0; else if (!strcasecmp(argv[i], "--resume")) cfg->resume = 1; else if (!strcasecmp(argv[i], "--info")) cfg->printonly = 1; else if (!strcasecmp(argv[i], "--xml")) cfg->printonly = cfg->printasxml = 1; else if (!strcasecmp(argv[i], "--verbose")) cfg->verbose = 1; else if (!strcasecmp(argv[i], "--quiet")) cfg->quiet = 1; else if (!strcasecmp(argv[i], "--help")) { print_usage(argv[0]); exit(0); } else if (!strcasecmp(argv[i], "--version")) { fprintf(stderr, "%s\n" "Copyright (C) 2010 Benjamin Moody\n" "This program is free software. There is ABSOLUTELY NO WARRANTY\n" "of any kind. Please see COPYING for more details.\n" "Please report bugs to %s.\n", PACKAGE_STRING, PACKAGE_BUGREPORT); exit(0); } else { fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[i]); print_usage(argv[0]); return 1; } } *argc = nfilenames + 1; return 0; }