diff options
| author | Bdale Garbee <bdale@gag.com> | 2009-09-06 10:39:23 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2009-09-06 10:39:23 -0600 | 
| commit | 35c54b3a278fa9bc2bc7f4b5ee04866697c93ba0 (patch) | |
| tree | 158e5e258d25e1d1f2ffa55492a3db43c16214ba /ao-tools/lib/cc-log.c | |
| parent | 4f8eff7401ee2d8092ab36fa33411f9b23dda880 (diff) | |
| parent | 6d018ab933832e2d80bb1564c339d9fb18b57be2 (diff) | |
Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
Diffstat (limited to 'ao-tools/lib/cc-log.c')
| -rw-r--r-- | ao-tools/lib/cc-log.c | 114 | 
1 files changed, 114 insertions, 0 deletions
| diff --git a/ao-tools/lib/cc-log.c b/ao-tools/lib/cc-log.c new file mode 100644 index 00000000..dd8177f4 --- /dev/null +++ b/ao-tools/lib/cc-log.c @@ -0,0 +1,114 @@ +/* + * Copyright © 2009 Keith Packard <keithp@keithp.com> + * + * 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; version 2 of the License. + * + * 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 <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <gconf/gconf-client.h> +#include "cc.h" + +static char *cc_file_dir; + +#define ALTOS_DIR_PATH	"/apps/aoview/log_dir" +#define DEFAULT_DIR	"AltOS" + +static void +cc_file_save_conf(void) +{ +	GConfClient	*gconf_client; + +	g_type_init(); +	gconf_client = gconf_client_get_default(); +	if (gconf_client) +	{ +		gconf_client_set_string(gconf_client, +					ALTOS_DIR_PATH, +					cc_file_dir, +					NULL); +		g_object_unref(G_OBJECT(gconf_client)); +	} +} + +static void +cc_file_load_conf(void) +{ +	char *file_dir; +	GConfClient	*gconf_client; + +	g_type_init(); +	gconf_client = gconf_client_get_default(); +	if (gconf_client) +	{ +		file_dir = gconf_client_get_string(gconf_client, +						   ALTOS_DIR_PATH, +						   NULL); +		g_object_unref(G_OBJECT(gconf_client)); +		if (file_dir) +			cc_file_dir = strdup(file_dir); +	} +} + +void +cc_set_log_dir(char *dir) +{ +	cc_file_dir = strdup(dir); +	cc_file_save_conf(); +} + +char * +cc_get_log_dir(void) +{ +	cc_file_load_conf(); +	if (!cc_file_dir) { +		cc_file_dir = cc_fullname(getenv("HOME"), DEFAULT_DIR); +		cc_file_save_conf(); +	} +	return cc_file_dir; +} + +char * +cc_make_filename(int serial, char *ext) +{ +	char		base[50]; +	struct tm	tm; +	time_t		now; +	char		*full; +	int		r; +	int		sequence; + +	now = time(NULL); +	(void) localtime_r(&now, &tm); +	cc_mkdir(cc_get_log_dir()); +	sequence = 0; +	for (;;) { +		snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", +			tm.tm_year + 1900, +			tm.tm_mon + 1, +			tm.tm_mday, +			serial, +			sequence, +			ext); +		full = cc_fullname(cc_get_log_dir(), base); +		r = access(full, F_OK); +		if (r < 0) +			return full; +		free(full); +		sequence++; +	} + +} | 
