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;
}
/************************************************************************
 * Function: cleanup
 * Inputs: none
 * Outputs: none
 * Description: cleans up if before we exit
 * Assumptions: none
 ************************************************************************/
static void cleanup(void)
{
	if (g_frontend != NULL)
		frontend_delete(g_frontend);
	if (g_templates != NULL)
	{
		g_templates->methods.save(g_templates);
		template_db_delete(g_templates);
	}
	if (g_questions != NULL)
	{
		g_questions->methods.save(g_questions);
		question_db_delete(g_questions);
	}
	if (g_config != NULL)
		config_delete(g_config);
}