1
/* This file is error.c - library for message and error reporting */
3
/* ifile - intelligent mail filter for EXMH/MH
4
Copyright (C) 1997 Jason Rennie <jrennie@ai.mit.edu>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <stdarg.h> /* va_start(), va_end(), va_list */
22
#include <stdio.h> /* fopen(), fclose() */
25
#include <errno.h> /* required by SunOS 5.5.1/gcc-2.7.2 for errno var */
26
#include <time.h> /* for srand(time(NULL)) call */
27
#include <sys/stat.h> /* for chmod() call */
31
extern arguments args;
35
/* Returns a newly allocated character array which contains the
36
portion of FULL_PATH postceeding the last '/' in FULL_PATH,
37
or the entire string if FULL_PATH contains no '/' characters */
38
/* written by Jason Rennie <jrennie@ai.mit.edu> for ifile */
40
ifile_strip_path (char * full_path)
42
char buf[MAX_STR_LEN];
43
int buf_index = 0; /* index of last character in BUF */
44
int full_path_index = 0; /* index of current character in FULL_PATH */
45
char * executable_name; /* pointer to string to be returned */
47
while (full_path[full_path_index])
49
buf[buf_index++] = full_path[full_path_index++];
50
if (full_path[full_path_index] == '/')
56
buf[buf_index] = '\0';
57
executable_name = malloc(strlen(buf)+1);
58
strcpy(executable_name, buf);
60
return executable_name;
63
/* Opens info log file to report information/errors (if requested) */
64
/* Written by Jason Rennie <jrennie@ai.mit.edu> for ifile */
66
ifile_open_log (int argc, char ** argv)
70
/* if no temp file is to be created, immediately return */
71
if (!args.tmp_file) return NULL;
75
/* Create string with full path for ~/.ifile_log */
76
info_file = ifile_sprintf("%s/.ifile.log", getenv("HOME"));
78
if ((INFO = fopen(info_file, "w")))
80
chmod(info_file, 0600);
81
ifile_verbosify(ifile_progress, "%s called\n", IFILE_VERSION);
83
ifile_verbosify(ifile_verbose, "Successfully opened log file: %s\n",
89
ifile_verbosify(ifile_quiet, "Not able to open log file: %s Error: %d\n", info_file, errno);
95
/* Closes info log file if necessary */
96
/* Written by Jason Rennie <jrennie@ai.mit.edu> for ifile */
100
if (!args.tmp_file) return;
103
ifile_verbosify(ifile_verbose, "Closed log file.\n");
107
/* Print the printf-style FORMAT string and arguments on STDERR, only if
108
ARGS->VERBOSITY is equal or greater than the argument VERBOSITY_LEVEL. */
109
/* Written by Jason Rennie <jrennie@ai.mit.edu> for ifile
110
adapted from bow_verbosify() - written by Andrew Kachites McCallum */
112
ifile_verbosify (int verbosity_level, const char *format, ...)
117
/* The following few lines makes it possible to see the priority
118
levels of the various lines of output */
120
if (verbosity_level <= args.verbosity)
122
va_start (ap, format);
123
ret = vfprintf (stderr, format, ap);
128
if ((verbosity_level <= args.verbosity) ||
129
(verbosity_level <= ifile_progress))
131
va_start (ap, format);
132
if (INFO != NULL) vfprintf (INFO, format, ap);
135
if (INFO != NULL) fflush (INFO);
141
/* Reports an error in printf style format and halts the program */
142
/* strerror() is currently not used to report errors because Sun machines
143
will not compile the function for some reason */
144
/* Written by Jason Rennie <jrennie@ai.mit.edu> for ifile
145
adapted from bow_error() - written by Andrew Kachites McCallum */
147
ifile_error (const char *format, ...)
151
va_start (ap, format);
152
if (INFO) vfprintf (INFO, format, ap);
154
/* fprintf("Error: %s\n", strerror(errno)); */
156
va_start (ap, format);
157
vfprintf (stderr, format, ap);
159
/* fprintf(stderr, "Error: %s\n\n", strerror(errno)); */
161
ifile_close_log(INFO);