1 /* $Header: /home/yav/catty/fkiss/RCS/message.c,v 1.4 2000/09/02 07:57:33 yav Exp $
2  * fkiss message
3  * written by yav <yav@bigfoot.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #include <X11/Xos.h>
21 #include <X11/Xlib.h>
22 #include <stdio.h>
23 #include "config.h"
24 
25 #include "headers.h"
26 #include "fkiss.h"
27 #include "work.h"
28 #define PUBLIC_MESSAGE_C
29 #include "extern.h"
30 
31 char id_message[] = "$Id: message.c,v 1.4 2000/09/02 07:57:33 yav Exp $";
32 static char *msgbuf;
33 static char *msgp;
34 
35 #define CLEAR_MESSAGE() (*(msgp = msgbuf) = '\0')
36 
msg_init(p)37 void msg_init(p)
38      char *p;
39 {
40   msgbuf = p;
41   CLEAR_MESSAGE();
42 }
43 
msg_queued()44 int msg_queued()
45 {
46   return msgp - msgbuf;
47 }
48 
prmsg()49 void prmsg()
50 {
51   Bool f;
52   char *p;
53   char *prompt;
54 
55   f = False;
56   p = NULL;
57   prompt = *oargv;
58   switch(*msgbuf) {
59   case '\0':
60     break;
61   case 'V':
62     if (verbose_mode & 2) {
63       prompt = NULL;
64       p = "";
65     }
66     break;
67   case 'W':
68     if (verbose_mode)
69       p = " warning:";
70     break;
71   case 'E':
72     f = True;
73     p = " error:";
74     break;
75   default:
76     p = "";
77     break;
78   }
79   if (p != NULL) {
80     if (prompt != NULL)
81       fprintf(stderr, "%s:", prompt);
82     fprintf(stderr, "%s%s", p, msgbuf+1);
83   }
84   CLEAR_MESSAGE();
85   if (f)
86     kiss_exit(1);
87 }
88 
89 #if USE_STDARG
msgset(const char * format,...)90 void msgset(const char *format, ...)
91 {
92   va_list ap;
93 
94   va_start(ap, format);
95   vsprintf(msgp, format, ap);
96   msgp += strlen(msgp);
97   va_end(ap);
98 }
99 #else /* USE_STDARG */
100 # if USE_VARARGS
msgset(va_alist)101 void msgset(va_alist)
102      va_dcl
103 {
104   va_list ap;
105   char *format;
106 
107   va_start(ap);
108   format = va_arg(ap, char *);
109   vsprintf(msgp, format, ap);
110   msgp += strlen(msgp);
111   va_end(ap);
112 }
113 # else /* USE_VARARGS */
msgset(format)114 void msgset(format)
115      char *format;
116 {
117   char *ap;
118 
119   ap = (char *)&format + sizeof(char *);
120   vsprintf(msgp, format, ap);
121 }
122 # endif /* USE_VARARGS */
123 #endif /* USE_STDARG */
124 
125 #if USE_STDARG
msg(const char * format,...)126 void msg(const char *format, ...)
127 {
128   va_list ap;
129 
130   va_start(ap, format);
131   vsprintf(msgp, format, ap);
132   prmsg();
133   va_end(ap);
134 }
135 #else /* USE_STDARG */
136 # if USE_VARARGS
msg(va_alist)137 void msg(va_alist)
138      va_dcl
139 {
140   va_list ap;
141   char *format;
142 
143   va_start(ap);
144   format = va_arg(ap, char *);
145   vsprintf(msgp, format, ap);
146   prmsg();
147   va_end(ap);
148 }
149 # else /* USE_VARARGS */
msg(format)150 void msg(format)
151      char *format;
152 {
153   char *ap;
154 
155   ap = (char *)&format + sizeof(char *);
156   vsprintf(msgp, format, ap);
157   prmsg();
158 }
159 # endif /* USE_VARARGS */
160 #endif /* USE_STDARG */
161 
162 
163 #if USE_STDARG
debug_printf(const char * format,...)164 void debug_printf(const char *format, ...)
165 {
166   va_list ap;
167 
168   if (debug_mode) {
169     va_start(ap, format);
170     vfprintf(stderr, format, ap);
171     va_end(ap);
172   }
173 }
174 #else /* USE_STDARG */
175 # if USE_VARARGS
debug_printf(va_alist)176 void debug_printf(va_alist)
177      va_dcl
178 {
179   va_list ap;
180   char *format;
181 
182   if (debug_mode) {
183     va_start(ap);
184     format = va_arg(ap, char *);
185     vfprintf(stderr, format, ap);
186     va_end(ap);
187   }
188 }
189 # else /* USE_VARARGS */
debug_printf(format)190 void debug_printf(format)
191      char *format;
192 {
193   char *ap;
194 
195   if (debug_mode) {
196     ap = (char *)&format + sizeof(char *);
197     vfprintf(stderr, format, ap);
198   }
199 }
200 # endif /* USE_VARARGS */
201 #endif /* USE_STDARG */
202 
203 /* End of file */
204