1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-11 20:05:07 -05:00

Replace hardcoded option numbers with enumeration

Pacman's long option parsing used hardcoded numbers to identify them.
This is not good practice, so replace them with enumeration constants.

Signed-off-by: Laszlo Papp <djszapi@archlinux.us>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Laszlo Papp 2009-10-13 05:14:56 +02:00 committed by Dan McGee
parent 2cabe336eb
commit f9582c7df2
2 changed files with 46 additions and 28 deletions

View File

@ -88,6 +88,24 @@ enum {
PM_OP_DEPTEST PM_OP_DEPTEST
}; };
/* Long Operations */
enum {
OP_NOCONFIRM = 1000,
OP_CONFIG,
OP_IGNORE,
OP_DEBUG,
OP_NOPROGRESSBAR,
OP_NOSCRIPTLET,
OP_ASK,
OP_CACHEDIR,
OP_ASDEPS,
OP_LOGFILE,
OP_IGNOREGROUP,
OP_NEEDED,
OP_ASEXPLICIT,
OP_ARCH
};
/* clean method */ /* clean method */
enum { enum {
PM_CLEAN_KEEPINST = 0, /* default */ PM_CLEAN_KEEPINST = 0, /* default */

View File

@ -378,20 +378,20 @@ static int parseargs(int argc, char *argv[])
{"verbose", no_argument, 0, 'v'}, {"verbose", no_argument, 0, 'v'},
{"downloadonly", no_argument, 0, 'w'}, {"downloadonly", no_argument, 0, 'w'},
{"refresh", no_argument, 0, 'y'}, {"refresh", no_argument, 0, 'y'},
{"noconfirm", no_argument, 0, 1000}, {"noconfirm", no_argument, 0, OP_NOCONFIRM},
{"config", required_argument, 0, 1001}, {"config", required_argument, 0, OP_CONFIG},
{"ignore", required_argument, 0, 1002}, {"ignore", required_argument, 0, OP_IGNORE},
{"debug", optional_argument, 0, 1003}, {"debug", optional_argument, 0, OP_DEBUG},
{"noprogressbar", no_argument, 0, 1004}, {"noprogressbar", no_argument, 0, OP_NOPROGRESSBAR},
{"noscriptlet", no_argument, 0, 1005}, {"noscriptlet", no_argument, 0, OP_NOSCRIPTLET},
{"ask", required_argument, 0, 1006}, {"ask", required_argument, 0, OP_ASK},
{"cachedir", required_argument, 0, 1007}, {"cachedir", required_argument, 0, OP_CACHEDIR},
{"asdeps", no_argument, 0, 1008}, {"asdeps", no_argument, 0, OP_ASDEPS},
{"logfile", required_argument, 0, 1009}, {"logfile", required_argument, 0, OP_LOGFILE},
{"ignoregroup", required_argument, 0, 1010}, {"ignoregroup", required_argument, 0, OP_IGNOREGROUP},
{"needed", no_argument, 0, 1011}, {"needed", no_argument, 0, OP_NEEDED},
{"asexplicit", no_argument, 0, 1012}, {"asexplicit", no_argument, 0, OP_ASEXPLICIT},
{"arch", required_argument, 0, 1013}, {"arch", required_argument, 0, OP_ARCH},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -403,21 +403,21 @@ static int parseargs(int argc, char *argv[])
} }
switch(opt) { switch(opt) {
case 0: break; case 0: break;
case 1000: config->noconfirm = 1; break; case OP_NOCONFIRM: config->noconfirm = 1; break;
case 1001: case OP_CONFIG:
if(config->configfile) { if(config->configfile) {
free(config->configfile); free(config->configfile);
} }
config->configfile = strndup(optarg, PATH_MAX); config->configfile = strndup(optarg, PATH_MAX);
break; break;
case 1002: case OP_IGNORE:
list = strsplit(optarg, ','); list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) { for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignorepkg((char *)alpm_list_getdata(item)); alpm_option_add_ignorepkg((char *)alpm_list_getdata(item));
} }
FREELIST(list); FREELIST(list);
break; break;
case 1003: case OP_DEBUG:
/* debug levels are made more 'human readable' than using a raw logmask /* debug levels are made more 'human readable' than using a raw logmask
* here, error and warning are set in config_new, though perhaps a * here, error and warning are set in config_new, though perhaps a
* --quiet option will remove these later */ * --quiet option will remove these later */
@ -440,34 +440,34 @@ static int parseargs(int argc, char *argv[])
/* progress bars get wonky with debug on, shut them off */ /* progress bars get wonky with debug on, shut them off */
config->noprogressbar = 1; config->noprogressbar = 1;
break; break;
case 1004: config->noprogressbar = 1; break; case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break; case OP_NOSCRIPTLET: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
case 1006: config->noask = 1; config->ask = atoi(optarg); break; case OP_ASK: config->noask = 1; config->ask = atoi(optarg); break;
case 1007: case OP_CACHEDIR:
if(alpm_option_add_cachedir(optarg) != 0) { if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
optarg, alpm_strerrorlast()); optarg, alpm_strerrorlast());
return(1); return(1);
} }
break; break;
case 1008: case OP_ASDEPS:
config->flags |= PM_TRANS_FLAG_ALLDEPS; config->flags |= PM_TRANS_FLAG_ALLDEPS;
break; break;
case 1009: case OP_LOGFILE:
config->logfile = strndup(optarg, PATH_MAX); config->logfile = strndup(optarg, PATH_MAX);
break; break;
case 1010: case OP_IGNOREGROUP:
list = strsplit(optarg, ','); list = strsplit(optarg, ',');
for(item = list; item; item = alpm_list_next(item)) { for(item = list; item; item = alpm_list_next(item)) {
alpm_option_add_ignoregrp((char *)alpm_list_getdata(item)); alpm_option_add_ignoregrp((char *)alpm_list_getdata(item));
} }
FREELIST(list); FREELIST(list);
break; break;
case 1011: config->flags |= PM_TRANS_FLAG_NEEDED; break; case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break;
case 1012: case OP_ASEXPLICIT:
config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; config->flags |= PM_TRANS_FLAG_ALLEXPLICIT;
break; break;
case 1013: case OP_ARCH:
setarch(optarg); setarch(optarg);
break; break;
case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break; case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;