[pacman-dev] [PATCH] Use non-ascii identifiers for overloaded optflags

Andrew Gregory andrew.gregory.8 at gmail.com
Thu Feb 21 21:06:00 EST 2013


On Thu, 21 Feb 2013 13:42:20 -0500
Dave Reisner <dreisner at archlinux.org> wrote:

> This prevents "non-sensical" combinations of flags from being
> misinterpreted, such as:
> 
>   $ pacman -Si --changelog $package
>     --changelog is -c, meaning --clean for -S
> 
>   $ pacman -Q --sysupgrade
>     --sysupgrade is -u, meaning --upgrades for -Q
> 
> Signed-off-by: Dave Reisner <dreisner at archlinux.org>
> ---
>  src/pacman/conf.h   | 16 ++++++++++++++-
>  src/pacman/pacman.c | 56 ++++++++++++++++++++++++++---------------------------
>  2 files changed, 43 insertions(+), 29 deletions(-)
> 
> diff --git a/src/pacman/conf.h b/src/pacman/conf.h
> index d85d11f..c1fd499 100644
> --- a/src/pacman/conf.h
> +++ b/src/pacman/conf.h
> @@ -129,7 +129,21 @@ enum {
>  	OP_PRINTFORMAT,
>  	OP_GPGDIR,
>  	OP_DBONLY,
> -	OP_FORCE
> +	OP_FORCE,
> +	OP_CASCADE,
> +	OP_CHANGELOG,
> +	OP_CLEAN,
> +	OP_NODEPS,
> +	OP_DEPS,
> +	OP_NATIVE,
> +	OP_NOSAVE,
> +	OP_FILE,
> +	OP_PRINT,
> +	OP_RECURSIVE,
> +	OP_SEARCH,
> +	OP_UPGRADES,
> +	OP_SYSUPGRADE,
> +	OP_UNNEEDED
>  };
>  
>  /* clean method */
> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> index 38b28e1..513243a 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -456,21 +456,21 @@ static int parsearg_database(int opt)
>  static int parsearg_query(int opt)
>  {
>  	switch(opt) {
> -		case 'c': config->op_q_changelog = 1; break;
> -		case 'd': config->op_q_deps = 1; break;
> +		case OP_CHANGELOG: config->op_q_changelog = 1; break;
> +		case OP_DEPS: config->op_q_deps = 1; break;
>  		case 'e': config->op_q_explicit = 1; break;
>  		case 'g': (config->group)++; break;
>  		case 'i': (config->op_q_info)++; break;
>  		case 'k': (config->op_q_check)++; break;
>  		case 'l': config->op_q_list = 1; break;
>  		case 'm': config->op_q_locality |= PKG_LOCALITY_LOCAL; break;
> -		case 'n': config->op_q_locality |= PKG_LOCALITY_FOREIGN; break;
> +		case OP_NATIVE: config->op_q_locality |= PKG_LOCALITY_FOREIGN; break;
>  		case 'o': config->op_q_owns = 1; break;
> -		case 'p': config->op_q_isfile = 1; break;
> +		case OP_FILE: config->op_q_isfile = 1; break;
>  		case 'q': config->quiet = 1; break;
> -		case 's': config->op_q_search = 1; break;
> +		case OP_SEARCH: config->op_q_search = 1; break;
>  		case 't': config->op_q_unrequired = 1; break;
> -		case 'u': config->op_q_upgrade = 1; break;
> +		case OP_UPGRADES: config->op_q_upgrade = 1; break;
>  		default: return 1;
>  	}
>  	return 0;
> @@ -480,7 +480,7 @@ static int parsearg_query(int opt)
>  static int parsearg_trans(int opt)
>  {
>  	switch(opt) {
> -		case 'd':
> +		case OP_NODEPS:
>  			if(config->flags & ALPM_TRANS_FLAG_NODEPVERSION) {
>  				config->flags |= ALPM_TRANS_FLAG_NODEPS;
>  			} else {
> @@ -490,7 +490,7 @@ static int parsearg_trans(int opt)
>  		case OP_DBONLY: config->flags |= ALPM_TRANS_FLAG_DBONLY; break;
>  		case OP_NOPROGRESSBAR: config->noprogressbar = 1; break;
>  		case OP_NOSCRIPTLET: config->flags |= ALPM_TRANS_FLAG_NOSCRIPTLET; break;
> -		case 'p': config->print = 1; break;
> +		case OP_PRINT: config->print = 1; break;
>  		case OP_PRINTFORMAT:
>  			check_optarg();
>  			config->print_format = strdup(optarg);
> @@ -505,16 +505,16 @@ static int parsearg_remove(int opt)
>  	if(parsearg_trans(opt) == 0)
>  		return 0;
>  	switch(opt) {
> -		case 'c': config->flags |= ALPM_TRANS_FLAG_CASCADE; break;
> -		case 'n': config->flags |= ALPM_TRANS_FLAG_NOSAVE; break;
> -		case 's':
> +		case OP_CASCADE: config->flags |= ALPM_TRANS_FLAG_CASCADE; break;
> +		case OP_NOSAVE: config->flags |= ALPM_TRANS_FLAG_NOSAVE; break;
> +		case OP_RECURSIVE:
>  			if(config->flags & ALPM_TRANS_FLAG_RECURSE) {
>  				config->flags |= ALPM_TRANS_FLAG_RECURSEALL;
>  			} else {
>  				config->flags |= ALPM_TRANS_FLAG_RECURSE;
>  			}
>  			break;
> -		case 'u': config->flags |= ALPM_TRANS_FLAG_UNNEEDED; break;
> +		case OP_UNNEEDED: config->flags |= ALPM_TRANS_FLAG_UNNEEDED; break;
>  		default: return 1;
>  	}
>  	return 0;
> @@ -546,13 +546,13 @@ static int parsearg_sync(int opt)
>  	if(parsearg_upgrade(opt) == 0)
>  		return 0;
>  	switch(opt) {
> -		case 'c': (config->op_s_clean)++; break;
> +		case OP_CLEAN: (config->op_s_clean)++; break;
>  		case 'g': (config->group)++; break;
>  		case 'i': (config->op_s_info)++; break;
>  		case 'l': config->op_q_list = 1; break;
>  		case 'q': config->quiet = 1; break;
>  		case 's': config->op_s_search = 1; break;
> -		case 'u': (config->op_s_upgrade)++; break;
> +		case OP_SYSUPGRADE: (config->op_s_upgrade)++; break;
>  		case 'w':
>  			config->op_s_downloadonly = 1;
>  			config->flags |= ALPM_TRANS_FLAG_DOWNLOADONLY;
> @@ -585,11 +585,11 @@ static int parseargs(int argc, char *argv[])
>  		{"upgrade",    no_argument,       0, 'U'},
>  		{"version",    no_argument,       0, 'V'},
>  		{"dbpath",     required_argument, 0, 'b'},
> -		{"cascade",    no_argument,       0, 'c'},
> -		{"changelog",  no_argument,       0, 'c'},
> -		{"clean",      no_argument,       0, 'c'},
> -		{"nodeps",     no_argument,       0, 'd'},
> -		{"deps",       no_argument,       0, 'd'},
> +		{"cascade",    no_argument,       0, OP_CASCADE},
> +		{"changelog",  no_argument,       0, OP_CHANGELOG},
> +		{"clean",      no_argument,       0, OP_CLEAN},
> +		{"nodeps",     no_argument,       0, OP_NODEPS},
> +		{"deps",       no_argument,       0, OP_DEPS},
>  		{"explicit",   no_argument,       0, 'e'},
>  		{"groups",     no_argument,       0, 'g'},
>  		{"help",       no_argument,       0, 'h'},
> @@ -597,19 +597,19 @@ static int parseargs(int argc, char *argv[])
>  		{"check",      no_argument,       0, 'k'},
>  		{"list",       no_argument,       0, 'l'},
>  		{"foreign",    no_argument,       0, 'm'},
> -		{"native",     no_argument,       0, 'n'},
> -		{"nosave",     no_argument,       0, 'n'},
> +		{"native",     no_argument,       0, OP_NATIVE},
> +		{"nosave",     no_argument,       0, OP_NOSAVE},
>  		{"owns",       no_argument,       0, 'o'},
> -		{"file",       no_argument,       0, 'p'},
> -		{"print",      no_argument,       0, 'p'},
> +		{"file",       no_argument,       0, OP_FILE},
> +		{"print",      no_argument,       0, OP_PRINT},
>  		{"quiet",      no_argument,       0, 'q'},
>  		{"root",       required_argument, 0, 'r'},
> -		{"recursive",  no_argument,       0, 's'},
> -		{"search",     no_argument,       0, 's'},
> +		{"recursive",  no_argument,       0, OP_RECURSIVE},
> +		{"search",     no_argument,       0, OP_SEARCH},
>  		{"unrequired", no_argument,       0, 't'},
> -		{"upgrades",   no_argument,       0, 'u'},
> -		{"sysupgrade", no_argument,       0, 'u'},
> -		{"unneeded",   no_argument,       0, 'u'},
> +		{"upgrades",   no_argument,       0, OP_UPGRADES},
> +		{"sysupgrade", no_argument,       0, OP_SYSUPGRADE},
> +		{"unneeded",   no_argument,       0, OP_UNNEEDED},
>  		{"verbose",    no_argument,       0, 'v'},
>  		{"downloadonly", no_argument,     0, 'w'},
>  		{"refresh",    no_argument,       0, 'y'},

This breaks the single letter options.

$ ./pacman -Sc
error: invalid option


More information about the pacman-dev mailing list