Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
errPrint.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <strings.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <stdarg.h>
7 #include <math.h>
8 #include <errno.h>
9 #include <readline/readline.h>
10 #include <readline/history.h>
11 
12 #include "defines.h"
13 #include "colors.h"
14 
15 #include "caclib_proto.h"
16 
17 extern char *prompt;
18 extern FILE *errPrint_fp;
19 extern int stquiet;
20 
21 int getNumericResponse(const char *fmt, ...)
22 {
23  int result;
24  char *cp, prompt[256];
25  extern char *rl_prompt;
26  va_list args;
27 
28  strcpy(prompt, rl_prompt);
29 
30  fflush(stdin);
31 
32  va_start(args, fmt);
33 
34  vfprintf(stdout, fmt, args);
35  if(errPrint_fp)
36  {
37  vfprintf(errPrint_fp, fmt, args);
38  }
39 
40  va_end(args);
41 
42  fflush(stdin);
43 
44  cp = readline(NULL);
45 
46  if(cp)
47  {
48  if(errPrint_fp)
49  {
50  fprintf(errPrint_fp, cp);
51  }
52 
53  if(errPrint_fp)
54  {
55  fprintf(errPrint_fp, "\n");
56  }
57 
58  fprintf(stdout, "\n");
59 
60  result = atoi(cp);
61 
62  rl_set_prompt(prompt);
63 
64  return(result);
65  }
66  else
67  {
68  if(errPrint_fp)
69  {
70  fprintf(errPrint_fp, "\n");
71  }
72 
73  rl_set_prompt(prompt);
74 
75  return(-1);
76  }
77 
78  return(-1);
79 }
80 
81 
82 int getYesNoQuit(const char *fmt, ...)
83 {
84  char *cp, tbuf[256];
85  va_list args;
86 
87  fflush(stdin);
88 
89  va_start(args, fmt);
90 
91  vfprintf(stdout, fmt, args);
92  if(errPrint_fp)
93  {
94  vfprintf(errPrint_fp, fmt, args);
95  }
96 
97  va_end(args);
98 
99  fflush(stdin);
100 
101  cp = fgets(tbuf, 2, stdin);
102 
103  if(cp)
104  {
105  if(errPrint_fp)
106  {
107  fprintf(errPrint_fp, cp);
108  }
109 
110  if(*cp == 'y')
111  {
112  if(errPrint_fp)
113  {
114  fprintf(errPrint_fp, "\n");
115  }
116 
117  fprintf(stdout, "\n");
118 
119  return(1);
120  }
121  else
122  if(*cp == 'q')
123  {
124  if(errPrint_fp)
125  {
126  fprintf(errPrint_fp, "\n");
127  }
128 
129  fprintf(stdout, "\n");
130 
131  return(2);
132  }
133  else
134  if(*cp == 'b')
135  {
136  if(errPrint_fp)
137  {
138  fprintf(errPrint_fp, "\n");
139  }
140 
141  fprintf(stdout, "\n");
142 
143  return(3);
144  }
145  }
146 
147  if(errPrint_fp)
148  {
149  fprintf(errPrint_fp, "\n");
150  }
151 
152  fprintf(stdout, "\n");
153 
154  return(0);
155 }
156 
157 
158 /* Print with msg with no newline */
159 void st_print(const char *fmt, ...)
160 {
161  va_list args;
162 
163  va_start(args, fmt);
164 
165  if(!stquiet)
166  {
167  vfprintf(stdout, fmt, args);
168  }
169 
170  if(errPrint_fp)
171  {
172  vfprintf(errPrint_fp, fmt, args);
173  }
174 
175  va_end(args);
176 }
177 
178 
179 /* Print with prompt + msg + (1) newline */
180 void st_report(const char *fmt, ...)
181 {
182  extern int verboseLevel;
183  extern int recursiveLevel;
184 
185  va_list args;
186 
187  if(!stquiet)
188  {
189  if(verboseLevel & VERBOSE_RECURSIVE)
190  {
191  fprintf(stdout, "%s #%d ", prompt, recursiveLevel);
192  }
193  else
194  {
195  fprintf(stdout, "%s # ", prompt);
196  }
197  }
198 
199  if(errPrint_fp)
200  {
201  if(verboseLevel & VERBOSE_RECURSIVE)
202  {
203  fprintf(errPrint_fp, "%s #%d ", prompt, recursiveLevel);
204  }
205  else
206  {
207  fprintf(errPrint_fp, "%s # ", prompt);
208  }
209  }
210 
211  va_start(args, fmt);
212 
213  if(!stquiet)
214  {
215  vfprintf(stdout, fmt, args);
216  }
217 
218  if(errPrint_fp)
219  {
220  vfprintf(errPrint_fp, fmt, args);
221  }
222 
223  va_end(args);
224 
225  if(!stquiet)
226  {
227  fprintf(stdout, "\n");
228  }
229 
230  if(errPrint_fp)
231  {
232  fprintf(errPrint_fp, "\n");
233  }
234 }
235 
236 
237 /* Print with prompt + msg + (1) newline */
238 void st_report_fp(const char *fmt, ...)
239 {
240  va_list args;
241 
242  if(!stquiet)
243  {
244  fprintf(stdout, "%s ", prompt);
245  }
246 
247  fprintf(errPrint_fp, "%s ", prompt);
248 
249  va_start(args, fmt);
250 
251  if(!stquiet)
252  {
253  vfprintf(stdout, fmt, args);
254  }
255 
256  vfprintf(errPrint_fp, fmt, args);
257 
258  va_end(args);
259 
260  if(!stquiet)
261  {
262  fprintf(stdout, "\n");
263  }
264 
265  fprintf(errPrint_fp, "\n");
266 }
267 
268 
269 
270 /* Print with (1) newline + prompt + msg + (2) newline */
271 void st_warn(const char *fmt, ...)
272 {
273  va_list args;
274 
275  if(!stquiet)
276  {
277  fprintf(stdout, "\n%s: ", prompt);
278  }
279 
280  if(errPrint_fp)
281  {
282  fprintf(errPrint_fp, "\n%s: ", prompt);
283  }
284 
285  va_start(args, fmt);
286 
287  if(!stquiet)
288  {
289  vfprintf(stdout, fmt, args);
290  }
291 
292  if(errPrint_fp)
293  {
294  vfprintf(errPrint_fp, fmt, args);
295  }
296 
297  va_end(args);
298 
299  if(!stquiet)
300  {
301  fprintf(stdout, "\n\n");
302  }
303 
304  if(errPrint_fp)
305  {
306  fprintf(errPrint_fp, "\n\n");
307  }
308 }
309 
310 
311 
312 /* Print with (1) newline + msg + (2) newline */
313 void st_fail(const char *fmt, ...)
314 {
315  va_list args;
316 
317  fprintf(stdout, "\n");
318  if(errPrint_fp)
319  {
320  fprintf(errPrint_fp, "\n");
321  }
322 
323  va_start(args, fmt);
324 
325  vfprintf(stdout, fmt, args);
326  if(errPrint_fp)
327  {
328  vfprintf(errPrint_fp, fmt, args);
329  }
330 
331  va_end(args);
332 
333  fprintf(stdout, "\n\n");
334  if(errPrint_fp)
335  {
336  fprintf(errPrint_fp, "\n\n");
337  }
338 }
339 
340 
341 int st_perror(msg)
342 char *msg;
343 {
344  char err[4096];
345 
346  fprintf(stdout, "%s # ", prompt);
347 
348  if(errPrint_fp)
349  {
350  fprintf(errPrint_fp, "%s # ", prompt);
351  }
352 
353  sprintf( err, "%s, %s", msg, strerror(errno) );
354 
355  fprintf(stdout, "%s\n", err);
356 
357  if(errPrint_fp)
358  {
359  fprintf(errPrint_fp, "%s\n", err);
360  }
361 
362  return(0);
363 }
char * prompt
Definition: makemem.c:101
struct PARSE_STACK * args
Definition: parse.h:196
#define VERBOSE_RECURSIVE
Definition: defines.h:73
int stquiet
Definition: env.c:90
int recursiveLevel
Definition: makemem.c:93
int getYesNoQuit()
void st_warn()
void st_fail()
int getNumericResponse()
void st_report_fp()
void st_report()
void st_print()
int st_perror()
FILE * errPrint_fp
Definition: linuxpops.c:70
int verboseLevel
Definition: linuxpops.c:80