File: message.c

package info (click to toggle)
fkiss 0.33a.patch-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 804 kB
  • ctags: 1,074
  • sloc: ansic: 9,141; sh: 2,924; makefile: 98; sed: 14
file content (206 lines) | stat: -rw-r--r-- 3,780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* $Header: /home/yav/catty/fkiss/RCS/message.c,v 1.4 2000/09/02 07:57:33 yav Exp $
 * fkiss message
 * written by yav <yav@bigfoot.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; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <stdio.h>
#ifdef USE_STDARG
#include <stdarg.h>
#endif
#include "config.h"

#include "headers.h"
#include "fkiss.h"
#include "work.h"
#define PUBLIC_MESSAGE_C
#include "extern.h"

char id_message[] = "$Id: message.c,v 1.4 2000/09/02 07:57:33 yav Exp $";
static char *msgbuf;
static char *msgp;

#define CLEAR_MESSAGE() (*(msgp = msgbuf) = '\0')

void msg_init(p)
     char *p;
{
  msgbuf = p;
  CLEAR_MESSAGE();
}

int msg_queued()
{
  return msgp - msgbuf;
}

void prmsg()
{
  Bool f;
  char *p;
  char *prompt;
  
  f = False;
  p = NULL;
  prompt = *oargv;
  switch(*msgbuf) {
  case '\0':
    break;
  case 'V':
    if (verbose_mode & 2) {
      prompt = NULL;
      p = "";
    }
    break;
  case 'W':
    if (verbose_mode)
      p = " warning:";
    break;
  case 'E':
    f = True;
    p = " error:";
    break;
  default:
    p = "";
    break;
  }
  if (p != NULL) {
    if (prompt != NULL)
      fprintf(stderr, "%s:", prompt);
    fprintf(stderr, "%s%s", p, msgbuf+1);
  }
  CLEAR_MESSAGE();
  if (f)
    kiss_exit(1);
}

#if USE_STDARG
void msgset(const char *format, ...)
{
  va_list ap;
  
  va_start(ap, format);
  vsprintf(msgp, format, ap);
  msgp += strlen(msgp);
  va_end(ap);
}
#else /* USE_STDARG */
# if USE_VARARGS
void msgset(va_alist)
     va_dcl
{
  va_list ap;
  char *format;
  
  va_start(ap);
  format = va_arg(ap, char *);
  vsprintf(msgp, format, ap);
  msgp += strlen(msgp);
  va_end(ap);
}
# else /* USE_VARARGS */
void msgset(format)
     char *format;
{
  char *ap;
  
  ap = (char *)&format + sizeof(char *);
  vsprintf(msgp, format, ap);
}
# endif /* USE_VARARGS */
#endif /* USE_STDARG */

#if USE_STDARG
void msg(const char *format, ...)
{
  va_list ap;
  
  va_start(ap, format);
  vsprintf(msgp, format, ap);
  prmsg();
  va_end(ap);
}
#else /* USE_STDARG */
# if USE_VARARGS
void msg(va_alist)
     va_dcl
{
  va_list ap;
  char *format;
  
  va_start(ap);
  format = va_arg(ap, char *);
  vsprintf(msgp, format, ap);
  prmsg();
  va_end(ap);
}
# else /* USE_VARARGS */
void msg(format)
     char *format;
{
  char *ap;
  
  ap = (char *)&format + sizeof(char *);
  vsprintf(msgp, format, ap);
  prmsg();
}
# endif /* USE_VARARGS */
#endif /* USE_STDARG */


#if USE_STDARG
void debug_printf(const char *format, ...)
{
  va_list ap;
  
  if (debug_mode) {
    va_start(ap, format);
    vfprintf(stderr, format, ap);
    va_end(ap);
  }
}
#else /* USE_STDARG */
# if USE_VARARGS
void debug_printf(va_alist)
     va_dcl
{
  va_list ap;
  char *format;
  
  if (debug_mode) {
    va_start(ap);
    format = va_arg(ap, char *);
    vfprintf(stderr, format, ap);
    va_end(ap);
  }
}
# else /* USE_VARARGS */
void debug_printf(format)
     char *format;
{
  char *ap;
  
  if (debug_mode) {
    ap = (char *)&format + sizeof(char *);
    vfprintf(stderr, format, ap);
  }
}
# endif /* USE_VARARGS */
#endif /* USE_STDARG */

/* End of file */