2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* conf.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2007-08-21 21:28:05 -04:00
|
|
|
#include <string.h> /* strdup */
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
/* pacman */
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "conf.h"
|
2008-05-10 23:30:27 -04:00
|
|
|
#include "util.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-11-04 13:05:22 -05:00
|
|
|
/* global config variable */
|
|
|
|
config_t *config = NULL;
|
|
|
|
|
2007-04-14 17:26:39 -04:00
|
|
|
config_t *config_new(void)
|
2005-10-28 08:20:40 -04:00
|
|
|
{
|
2007-09-10 20:13:38 -04:00
|
|
|
config_t *newconfig = calloc(1, sizeof(config_t));
|
|
|
|
if(!newconfig) {
|
2008-05-10 23:30:27 -04:00
|
|
|
pm_fprintf(stderr, PM_LOG_ERROR,
|
|
|
|
_("malloc failure: could not allocate %zd bytes\n"),
|
|
|
|
sizeof(config_t));
|
2007-10-30 00:32:58 -04:00
|
|
|
return(NULL);
|
2007-04-25 17:24:23 -04:00
|
|
|
}
|
2007-08-21 21:28:05 -04:00
|
|
|
/* defaults which may get overridden later */
|
2007-09-10 20:13:38 -04:00
|
|
|
newconfig->op = PM_OP_MAIN;
|
|
|
|
newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
|
2007-08-21 21:28:05 -04:00
|
|
|
/* CONFFILE is defined at compile-time */
|
2007-09-10 20:13:38 -04:00
|
|
|
newconfig->configfile = strdup(CONFFILE);
|
2005-10-28 08:20:40 -04:00
|
|
|
|
2007-09-10 20:13:38 -04:00
|
|
|
return(newconfig);
|
2005-10-28 08:20:40 -04:00
|
|
|
}
|
|
|
|
|
2007-09-10 20:13:38 -04:00
|
|
|
int config_free(config_t *oldconfig)
|
2005-10-28 08:20:40 -04:00
|
|
|
{
|
2007-09-10 20:13:38 -04:00
|
|
|
if(oldconfig == NULL) {
|
2005-10-28 08:20:40 -04:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2008-08-24 17:24:53 -04:00
|
|
|
FREELIST(oldconfig->holdpkg);
|
2008-01-28 13:49:27 -05:00
|
|
|
FREELIST(oldconfig->syncfirst);
|
2007-09-10 20:13:38 -04:00
|
|
|
free(oldconfig->configfile);
|
2007-12-02 13:20:55 -05:00
|
|
|
free(oldconfig->rootdir);
|
|
|
|
free(oldconfig->dbpath);
|
|
|
|
free(oldconfig->logfile);
|
2009-04-04 04:17:30 -04:00
|
|
|
free(oldconfig->xfercommand);
|
2009-07-19 05:15:11 -04:00
|
|
|
free(oldconfig->print_format);
|
2007-09-10 20:13:38 -04:00
|
|
|
free(oldconfig);
|
|
|
|
oldconfig = NULL;
|
2005-10-28 08:20:40 -04:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|