2 * EPSON ESC/P-R Printer Driver for Linux
3 * Copyright (C) 2002-2005 AVASYS CORPORATION.
4 * Copyright (C) Seiko Epson Corporation 2002-2005.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.
20 * As a special exception, AVASYS CORPORATION gives permission to
21 * link the code of this program with libraries which are covered by
22 * the AVASYS Public License and distribute their linked
23 * combinations. You must obey the GNU General Public License in all
24 * respects for all of the code used other than the libraries which
25 * are covered by AVASYS Public License.
42 static char err_pname[256] = "";
43 static FILE *debug_f = NULL;
44 static FILE *debug_f2 = NULL;
46 /* static functions */
47 static void err_doit (enum msgtype, int, const char *, va_list);
49 void debug_msg(const char *fmt, ...){
54 debug_f = fopen(DEBUG_PATH, "wb");
58 fchmod (fileno (debug_f), 0777);
62 vfprintf (debug_f, fmt, ap);
69 void debugt_msg(char * fmt, ...)
72 if(fmt == NULL || strlen(fmt) == 0){
78 debug_f2 = fopen(EPS_DEBUG_PATH2, "wb");
82 fchmod (fileno (debug_f2), 0644);
85 time_t ltime; /* calendar time */
87 struct timespec start;
92 ltime=time(NULL); /* get current cal time */
93 Tm = localtime(<ime);
94 err = clock_gettime(CLOCK_REALTIME, &start);
96 sprintf(szBuf, "[%02d-%02d-%02d %02d:%02d:%02d::%02d] %s", Tm->tm_year % 10, Tm->tm_mon + 1, Tm->tm_mday, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, (int)start.tv_nsec/1000000, fmt);
98 sprintf(szBuf, "[%02d-%02d-%02d %02d:%02d:%02d] %s", Tm->tm_year % 10, Tm->tm_mon + 1, Tm->tm_mday, Tm->tm_hour, Tm->tm_min, Tm->tm_sec, fmt);
101 va_start (ap, szBuf);
102 vfprintf (debug_f2, szBuf, ap);
110 err_init (const char *name)
112 if (name && strlen (name) < 256)
113 strcpy (err_pname, name);
118 err_msg (enum msgtype type, const char *fmt, ...)
123 err_doit (type, 0, fmt, ap);
130 err_fatal (const char *fmt, ...)
135 err_doit (MSGTYPE_ERROR, 0, fmt, ap);
142 err_system (const char *fmt,...)
149 err_doit (MSGTYPE_ERROR, e, fmt, ap);
156 err_doit (enum msgtype type, int e, const char *fmt, va_list ap)
158 if (err_pname[0] != '\0')
159 fprintf (stderr, "%s : ", err_pname);
161 if (type == MSGTYPE_ERROR)
162 fprintf (stderr, "**** ERROR **** : ");
163 else if (type == MSGTYPE_WARNING)
164 fprintf (stderr, "**** WARNING **** : ");
165 else if (type == MSGTYPE_INFO)
166 fprintf (stderr, "**** INFO **** : ");
168 vfprintf (stderr, fmt, ap);
171 fprintf (stderr, " : %s", strerror (e));
173 fprintf (stderr, "\n");