int main(int argc, char **argv) { struct configuration *config = NULL; struct question_db *qdb = NULL; struct template_db *tdb = NULL; int flags = 0; char *owner; int i; setlocale(LC_ALL, ""); config = config_new(); parsecmdline(config, argc, argv); /* always load all translations if running standalone */ unsetenv("DEBCONF_DROP_TRANSLATIONS"); /* If debconf is already running, use debconfclient to load * the templates; * This is a hack until we introduce a standard debconf * primitive for doing this. */ if (getenv("DEBIAN_HAS_FRONTEND") != NULL) { add_questions_debconf(argc, argv); exit(0); } /* parse the configuration info */ if (config->read(config, DEBCONFCONFIG) == 0) DIE("Error reading configuration information"); /* initialize database modules */ if ((tdb = template_db_new(config, NULL)) == 0) DIE("Cannot initialize DebConf template database"); if ((qdb = question_db_new(config, tdb, NULL)) == 0) DIE("Cannot initialize DebConf config database"); tdb->methods.load(tdb); qdb->methods.load(qdb); owner = argv[optind]; i = optind + 1; if (merge) flags |= DC_LOADTEMPLATE_MERGE; while (i < argc) { template_db_loadfile(tdb, qdb, argv[i++], owner, flags); } if (tdb->methods.save(tdb) != DC_OK) exit(1); if (qdb->methods.save(qdb) != DC_OK) exit(1); template_db_delete(tdb); question_db_delete(qdb); config_delete(config); return EXIT_SUCCESS; }
static int stack_template_db_initialize(struct template_db *db, struct configuration *cfg) { struct template_stack *tstack = NULL; char *configpath; struct configitem *tmp, *child; if (asprintf(&configpath, "%s::stack", db->configpath) == -1) return DC_NOTOK; tmp = cfg->tree(cfg, configpath); free(configpath); for (child = tmp->child; child != NULL; child = child->next) { if (tstack != NULL) { tstack->next = malloc(sizeof(struct template_stack)); tstack = tstack->next; } else { tstack = malloc(sizeof(struct template_stack)); db->data = tstack; } tstack->db = template_db_new(cfg, child->value); tstack->next = NULL; } return DC_OK; }
int main(int argc, char **argv) { struct configuration *config; struct template_db *tdb; struct question_db *qdb; struct question *q; char *configpath; const char *tdbname; char *dbname = 0; char *pattern = 0; regex_t pattern_regex; void *iter; int c; setlocale(LC_ALL, ""); while ((c = getopt_long(argc, argv, "hp:", g_dpc_args, NULL)) > 0) { switch (c) { case 'h': usage(argv[0]); break; case 'p': pattern = optarg; break; } } if (optind + 1 > argc) usage(argv[0]); dbname = argv[optind]; if (dbname == NULL) usage(argv[0]); /* suppress warnings about unknown localized fields */ setenv("DEBCONF_NO_I18N", "1", 1); /* parse the configuration info */ config = config_new(); if (config->read(config, DEBCONFCONFIG) == 0) DIE("Error reading configuration information"); /* find out which template databases to load; fall back to global * default if not configured otherwise */ if (asprintf(&configpath, "config::instance::%s::template", dbname) == -1) DIE("Out of memory"); tdbname = config->get(config, configpath, NULL); /* initialize database modules */ if ((tdb = template_db_new(config, tdbname)) == 0) DIE("Cannot initialize debconf template database"); if ((qdb = question_db_new(config, tdb, dbname)) == 0) DIE("Cannot initialize debconf database"); /* load database */ tdb->methods.load(tdb); qdb->methods.load(qdb); /* * Iterate through all the questions and print them out */ /* maybe compile pattern regex */ if (pattern) { int err = regcomp(&pattern_regex, pattern, REG_EXTENDED | REG_NOSUB); if (err != 0) { int errmsgsize = regerror(err, &pattern_regex, NULL, 0); char *errmsg = malloc(errmsgsize); if (errmsg == NULL) DIE("Out of memory"); regerror(err, &pattern_regex, errmsg, errmsgsize); DIE("regcomp: %s", errmsg); } } /* TODO: error checking */ iter = 0; while ((q = qdb->methods.iterate(qdb, &iter)) != NULL) { if (pattern) { if (regexec(&pattern_regex, q->tag, 0, 0, 0) != 0) goto nextq; } printf("%s %s %s\n", q->tag, q->template->type, q->value);
int main(int argc, char **argv) { struct configuration *config = config_new(); struct template_db *tdb; struct question_db *qdb; struct question *q; void *iter = 0; const char *tdbname = NULL; int c; const char *dbname = NULL; struct questionowner *owners = NULL; setlocale(LC_ALL, ""); while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) { switch (c) { case 'd': dbname = optarg; break; default: break; } } config = config_new(); if (config->read(config, DEBCONFCONFIG) == 0) DIE("Error reading configuration information"); if (listdbs) { struct configitem *instance, *item; instance = config->tree(config,"config::instance"); if (instance) { for (item=instance->child; item != NULL; item = item->next) { printf("%s %s\n", item->tag, item->value); } } config_delete(config); return 0; } if (dbname) { /* find out which template databases to load; fall back to global * default if not configured otherwise */ char *configpath; if (asprintf(&configpath, "config::instance::%s::template", dbname) == -1) DIE("Out of memory"); tdbname = config->get(config, configpath, NULL); free(configpath); } /* initialize database modules */ if ((tdb = template_db_new(config, tdbname)) == 0) DIE("Cannot initialize debconf template database"); if ((qdb = question_db_new(config, tdb, dbname)) == 0) DIE("Cannot initialize debconf database"); tdb->methods.load(tdb); qdb->methods.load(qdb); if (listowners) { while((q = qdb->methods.iterate(qdb, &iter)) != NULL) { struct questionowner *owner = q->owners; while (owner) { struct questionowner *o = owners; while (o != NULL) { if (0 == strcmp(o->owner, owner->owner)) break; o = o->next; } if (o == NULL) { o = malloc(sizeof(struct questionowner)); o->next = owners; o->owner = owner->owner; owners = o; fprintf(stdout, "%s\n", owner->owner); } owner = owner->next; } } } else { for (c = optind; c < argc; c++) { struct questionowner *o = malloc(sizeof(struct questionowner)); o->next = owners; o->owner = argv[c]; owners = o; } if (!owners) { usage(argv[0]); } while((q = qdb->methods.iterate(qdb, &iter)) != NULL) { const char seen = (q->flags & DC_QFLAG_SEEN)?'*':' '; const char *type = q->template->type?q->template->type:"";