added a --debug option to externally set the library log level

This commit is contained in:
Aurelien Foret 2005-05-02 07:37:55 +00:00
parent 1942c74489
commit 9e7dfed18b

View file

@ -70,6 +70,7 @@ unsigned short pmo_s_search = 0;
unsigned short pmo_s_upgrade = 0; unsigned short pmo_s_upgrade = 0;
unsigned short pmo_group = 0; unsigned short pmo_group = 0;
unsigned char pmo_flags = 0; unsigned char pmo_flags = 0;
unsigned short pmo_debug = PM_LOG_WARNING;
/* configuration file option */ /* configuration file option */
char *pmo_proxyhost = NULL; char *pmo_proxyhost = NULL;
unsigned short pmo_proxyport = 0; unsigned short pmo_proxyport = 0;
@ -145,8 +146,7 @@ int main(int argc, char *argv[])
} }
/* set library parameters */ /* set library parameters */
if(pmo_verbose == 1) { if(alpm_set_option(PM_OPT_LOGMASK, (long)pmo_debug) == -1) {
if(alpm_set_option(PM_OPT_LOGMASK, (long)0xFF) == -1) {
ERR(NL, "failed to set option LOGMASK (%s)\n", alpm_strerror(pm_errno)); ERR(NL, "failed to set option LOGMASK (%s)\n", alpm_strerror(pm_errno));
cleanup(1); cleanup(1);
} }
@ -154,7 +154,6 @@ int main(int argc, char *argv[])
ERR(NL, "failed to set option LOGCB (%s)\n", alpm_strerror(pm_errno)); ERR(NL, "failed to set option LOGCB (%s)\n", alpm_strerror(pm_errno));
cleanup(1); cleanup(1);
} }
}
if(alpm_set_option(PM_OPT_DBPATH, (long)pmo_dbpath) == -1) { if(alpm_set_option(PM_OPT_DBPATH, (long)pmo_dbpath) == -1) {
ERR(NL, "failed to set option DBPATH (%s)\n", alpm_strerror(pm_errno)); ERR(NL, "failed to set option DBPATH (%s)\n", alpm_strerror(pm_errno));
cleanup(1); cleanup(1);
@ -348,7 +347,7 @@ int pacman_deptest(list_t *targets)
* *
* Returns: 0 on success, 1 on error * Returns: 0 on success, 1 on error
*/ */
int parseargs(int argc, char **argv) int parseargs(int argc, char *argv[])
{ {
int opt; int opt;
int option_index = 0; int option_index = 0;
@ -389,9 +388,10 @@ int parseargs(int argc, char **argv)
{"noconfirm", no_argument, 0, 1000}, {"noconfirm", no_argument, 0, 1000},
{"config", required_argument, 0, 1001}, {"config", required_argument, 0, 1001},
{"ignore", required_argument, 0, 1002}, {"ignore", required_argument, 0, 1002},
{"debug", required_argument, 0, 1003},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
char root[256]; char root[PATH_MAX];
while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfnoldepiuwyg", opts, &option_index))) { while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfnoldepiuwyg", opts, &option_index))) {
if(opt < 0) { if(opt < 0) {
@ -404,8 +404,12 @@ int parseargs(int argc, char **argv)
if(pmo_configfile) { if(pmo_configfile) {
free(pmo_configfile); free(pmo_configfile);
} }
pmo_configfile = strndup(optarg, PATH_MAX); break; pmo_configfile = strndup(optarg, PATH_MAX);
break;
case 1002: pmo_s_ignore = list_add(pmo_s_ignore, strdup(optarg)); break; case 1002: pmo_s_ignore = list_add(pmo_s_ignore, strdup(optarg)); break;
case 1003:
pmo_debug = atoi(optarg);
break;
case 'A': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_ADD); break; case 'A': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_ADD); break;
case 'D': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); pmo_d_resolve = 1; break; case 'D': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); pmo_d_resolve = 1; break;
case 'F': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); pmo_flags |= PM_TRANS_FLAG_FRESHEN; break; case 'F': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); pmo_flags |= PM_TRANS_FLAG_FRESHEN; break;
@ -470,8 +474,7 @@ int parseargs(int argc, char **argv)
while(optind < argc) { while(optind < argc) {
/* add the target to our target array */ /* add the target to our target array */
char *s = strdup(argv[optind]); pm_targets = list_add(pm_targets, strdup(argv[optind]));
pm_targets = list_add(pm_targets, s);
optind++; optind++;
} }