/* This file is part of Idest. -*- c -*- Copyright (C) 2009-2011 Sergey Poznyakoff Idest is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. Idest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Idest. If not, see . */ static int mode_set = 0; #define SET_MODE(m) do { \ if (mode_set++ && mode != m) \ error(1, 0, "only one of -q, -s, -d may be used"); \ mode = m; \ } while(0) static unsigned get_version_list(const char *arg) { unsigned vers = 0; while (1) { switch (*arg) { case '1': vers |= IDEST_ID3V_1; break; case '2': vers |= IDEST_ID3V_2; break; default: error(1, 0, "invalid or unsupported version near %s", arg); } if (*++arg == ',') ++arg; else if (*arg == 0) break; else error(1, 0, "malformed version list near %s", arg); } return vers; } OPTIONS_BEGIN(gnu, "idest", [], []) GROUP([]) OPTION(query,q,[FLIST], []) BEGIN SET_MODE(MODE_QUERY); if (optarg) parse_filter_items(optarg); END OPTION(all,a,, []) BEGIN SET_MODE(MODE_QUERY); all_frames = 1; END OPTION(set,s,FIELD=VALUE, []) BEGIN char *p; SET_MODE(MODE_MOD); p = strchr(optarg, '='); if (!p) error(1, 0, "missing `=' sign in assignment"); *p++ = 0; input_list_add_assignment(optarg, p); END OPTION(delete,d,[FLIST], []) BEGIN SET_MODE(MODE_DELETE); if (optarg) parse_filter_items(optarg); END OPTION(info,i,, []) BEGIN SET_MODE(MODE_INFO); END OPTION(copy,c,FILE, []) BEGIN source_file = optarg; END OPTION(list-frames,L,, []) BEGIN SET_MODE(MODE_LIST); END GROUP([]) OPTION(filter,F,FRAME-LIST, []) BEGIN parse_filter_items(optarg); END OPTION(id-version,V,VERSION, []) BEGIN version_option = get_version_list(optarg); END OPTION(default-id-version,U,VERSION, []) BEGIN default_version_option = get_version_list(optarg); END OPTION(convert,C,VERSION, []) BEGIN convert_version = get_version_list(optarg); END OPTION(latin1,,, []) BEGIN latin1_option = 1; END OPTION(verbose,v,, []) BEGIN verbose_option = 1; END OPTION(describe,D,, []) BEGIN describe_option = 1; END GROUP([]) OPTION(backup,,[CONTROL], []) BEGIN if (optarg) backup_type = xget_version ("--backup", optarg); else backup_type = xget_version ("VERSION_CONTROL", getenv("VERSION_CONTROL")); END OPTION(backup-suffix,,SUF, []) BEGIN simple_backup_suffix = optarg; END OPTION(backup-directory,,DIR, []) BEGIN backup_dir = optarg; END IFDEF(GUILE_VERSION,[< GROUP([]) OPTION(script,S,FILE, []) BEGIN set_guile_argv(argc - optind, argv + optind); /* Save rest of arguments */ *--guile_argv = optarg; optind = argc; /* Stop argument processing */ END OPTION(format,H,NAME, []) BEGIN format_name = optarg; stop = 1; /* Stop argument processing */ END OPTION(batch,B,NAME, []) BEGIN batch_name = optarg; stop = 1; /* Stop argument processing */ END OPTION(dry-run,n,, []) BEGIN dry_run_option = 1; END OPTION(trace,,[LEVEL], []) BEGIN if (optarg) guile_debug = atoi(optarg); else guile_debug = 1; END OPTION(load-path,P,PATH, []) BEGIN guile_add_load_path(optarg, 1); END OPTION(prepend-load-path,p,PATH, []) BEGIN guile_add_load_path(optarg, 0); END OPTION(no-init-files,N,, []) BEGIN no_init_files_option = 1; END >]) OPTIONS_END void get_options(int argc, char *argv[]) { GETOPT(argc, argv) if (optind < argc && mode == MODE_MOD) { char *p; /* See if we've been given any assignment arguments */ while (argv[optind] && (p = strchr(argv[optind], '='))) { *p++ = 0; input_list_add_assignment(argv[optind++], p); } } }