home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume10
/
contool
/
part02
/
logging.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-30
|
4KB
|
138 lines
/************************************************************************/
/* Copyright 1988-1990 by Chuck Musciano and Harris Corporation */
/* */
/* Permission to use, copy, modify, and distribute this software */
/* and its documentation for any purpose and without fee is */
/* hereby granted, provided that the above copyright notice */
/* appear in all copies and that both that copyright notice and */
/* this permission notice appear in supporting documentation, and */
/* that the name of Chuck Musciano and Harris Corporation not be */
/* used in advertising or publicity pertaining to distribution */
/* of the software without specific, written prior permission. */
/* Chuck Musciano and Harris Corporation make no representations */
/* about the suitability of this software for any purpose. It is */
/* provided "as is" without express or implied warranty. This */
/* software may not be sold without the prior explicit permission */
/* of Harris Corporation. */
/************************************************************************/
/************************************************************************/
/* */
/* logging.c message log management */
/* */
/************************************************************************/
#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/xv_xrect.h>
#include "manifest.h"
#include "contool.h"
#include "contool_ui.h"
PUBLIC Menu_item start_logging();
PUBLIC Menu_item stop_logging();
PUBLIC contool_base_objects *contool_base;
PRIVATE int logging = FALSE;
PRIVATE FILE *logfile = NULL;
PRIVATE char *log_path = NULL;
/************************************************************************/
EXPORT void disable_logging()
{
if (logging) {
fclose(logfile);
cond_free(log_path);
log_path = NULL;
logging = FALSE;
}
xv_set(contool_base->base, FRAME_RIGHT_FOOTER, "", NULL);
}
/************************************************************************/
EXPORT void enable_logging()
{ char buf[1024];
if (logging) {
if (log_path && strcmp(log_path, defaults.log_file) == 0)
return;
disable_logging();
}
if (is_empty(defaults.log_file))
error("You must specify a log file in the Properties dialog");
else if ((logfile = fopen(defaults.log_file, "a")) == NULL)
error("Cannot open log file %s : %s", defaults.log_file, sys_errlist[errno]);
else {
logging = TRUE;
log_path = strsave(defaults.log_file);
sprintf(buf, "Logging to %s...", defaults.log_file);
xv_set(contool_base->base, FRAME_RIGHT_FOOTER, buf, NULL);
}
}
/************************************************************************/
EXPORT Menu_item start_logging(item, op)
Menu_item item;
Menu_generate op;
{ contool_base_objects *ip = (contool_base_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
if (op == MENU_DISPLAY)
xv_set(item, MENU_INACTIVE, logging, NULL);
else if (op == MENU_NOTIFY)
enable_logging();
return item;
}
/************************************************************************/
EXPORT Menu_item stop_logging(item, op)
Menu_item item;
Menu_generate op;
{ contool_base_objects *ip = (contool_base_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
if (op == MENU_DISPLAY)
xv_set(item, MENU_INACTIVE, !logging, NULL);
else if (op == MENU_NOTIFY)
disable_logging();
return item;
}
/************************************************************************/
EXPORT update_logging()
{
if (logging) {
disable_logging();
enable_logging();
}
}
/************************************************************************/
EXPORT write_log(s)
char *s;
{ int t;
static char hostname[100] = "";
if (logging) {
if (*hostname == NULL)
if (gethostname(hostname, 99) != 0)
strcpy(hostname, "(unknown)");
t = time(0);
fseek(logfile, 0L, 2);
fprintf(logfile, "%s\t%.16s\t%s", hostname, ctime(&t) + 4, s);
fflush(logfile);
}
}