/* globals.c: More globals than you can shake a stick at.
 *
 * $Id: globals.c,v 1.7 2003/02/10 06:47:23 andy Exp $
 *
 * Copyright (C) 2002 Andy Goth <unununium@openverse.com>
 * For more information visit http://ioioio.net/devel/install-log/
 * 
 * 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 along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA  02111-1307, USA. */

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "install-log.h"

char* program_name;

bool force;
bool edit;
bool quiet;

list_t include;
list_t exclude;
char* package;
char* root;
char* chrootvar;
char* logdir;
char* editor;
int verbosity;

list_t new_files;
list_t old_files;
list_t del_files;
list_t prev_files;

time_t timestamp;

/* Sets global values to defaults and to environment variable settings. */
void init_globals(char** argv)
{
	/* Strip the path from the executable name */
	program_name = strrchr(argv[0], '/');
	if (program_name == NULL) program_name = argv[0];
	else program_name++;

	/* Find defaults */
	force = 0;
	edit = 0;
	quiet = 0;

	make_string_list(&include, default_include);
	make_string_list(&exclude, default_exclude);

	package = NULL;
	chrootvar = strdup(CHROOTVAR);
	root = NULL;
	logdir = strdup(LOGDIR);
	editor = getenv("EDITOR");
	if (editor == NULL) editor = getenv("VISUAL");
	if (editor == NULL) editor = EDITOR;
	editor = strdup(editor);
	verbosity = atoi(VERBOSITY);

	atexit(free_globals);
}

/* Frees up everything allocated in globals.c. */
void free_globals(void)
{
	clear_list(&include);
	clear_list(&exclude);
	if (package != NULL) free(package);
	free(chrootvar);
	free(root);
	free(logdir);
	free(editor);
	
	clear_list(&new_files);
	clear_list(&old_files);
	clear_list(&del_files);
	clear_list(&prev_files);
}

/* EOF */

