Debian Codegraph @

cextern/cfitsio/utilities/fvrf_misc.c

raw
1 /******************************************************************************
2 * Function
3 * wrtout: print messages in the streams of stdout and out.
4 * wrterr: print erro messages in the streams of stderr and out.
5 * wrtferr: print cfitsio erro messages in the streams of stderr and out.
6 * wrtwrn: print warning messages in the streams of stdout and out.
7 * wrtsep: print seperators.
8 * num_err_wrn: Return the number of errors and warnings.
9 *
10 *******************************************************************************/
11 #include "fverify.h"
12 static int nwrns = 0;
13 static int nerrs = 0;
14 static char temp[512];
15
16 void num_err_wrn(int *num_err, int *num_wrn)
17 {
18 *num_wrn = nwrns;
19 *num_err = nerrs;
20 return;
21 }
22
23 void reset_err_wrn()
24 {
25 nwrns = 0;
26 nerrs = 0;
27 return;
28 }
29
30 int wrtout(FILE *out, char *mess)
31 {
32 if(out != NULL )fprintf(out,"%s\n",mess);
33 if(out == stdout) fflush(stdout);
34 return 0;
35 }
36
37 int wrtwrn(FILE *out, char *mess, int isheasarc)
38 {
39 if(err_report) return 0; /* Don't print the warnings */
40 if(!heasarc_conv && isheasarc) return 0; /* heasarc warnings but with
41 heasarc convention turns off */
42 nwrns++;
43 strcpy(temp,"*** Warning: ");
44 strcat(temp,mess);
45 if(isheasarc) strcat(temp," (HEASARC Convention)");
46 print_fmt(out,temp,13);
47 /* if(nwrns > MAXWRNS ) {
48 fprintf(stderr,"??? Too many Warnings! I give up...\n");
49
50 } */
51 return nwrns;
52 }
53
54 int wrterr(FILE *out, char *mess, int severity )
55 {
56
57 if(severity < err_report) {
58 fits_clear_errmsg();
59 return 0;
60 }
61 nerrs++;
62
63 strcpy(temp,"*** Error: ");
64 strcat(temp,mess);
65 if(out != NULL) {
66 if ((out!=stdout) && (out!=stderr)) print_fmt(out,temp,13);
67 /*
68 if ERR2OUT is defined, then error messages will be sent to the
69 stdout stream rather than to stderr
70 */
71 #ifdef ERR2OUT
72 print_fmt(stdout,temp,13);
73 #else
74 print_fmt(stderr,temp,13);
75 #endif
76 }
77
78 if(nerrs > MAXERRORS ) {
79
80 #ifdef ERR2OUT
81 fprintf(stdout,"??? Too many Errors! I give up...\n");
82 #else
83 fprintf(stderr,"??? Too many Errors! I give up...\n");
84 #endif
85 close_report(out);
86 exit(1);
87 }
88 fits_clear_errmsg();
89 return nerrs;
90 }
91
92 int wrtferr(FILE *out, char* mess, int *status, int severity)
93 /* construct an error message: mess + cfitsio error */
94 {
95 char ttemp[255];
96
97 if(severity < err_report) {
98 fits_clear_errmsg();
99 return 0;
100 }
101 nerrs++;
102
103 strcpy(temp,"*** Error: ");
104 strcat(temp,mess);
105 fits_get_errstatus(*status, ttemp);
106 strcat(temp,ttemp);
107 if(out != NULL ) {
108 if ((out!=stdout) && (out!=stderr)) print_fmt(out,temp,13);
109 /*
110 if ERR2OUT is defined, then error messages will be sent to the
111 stdout stream rather than to stderr
112 */
113 #ifdef ERR2OUT
114 print_fmt(stdout,temp,13);
115 #else
116 print_fmt(stderr,temp,13);
117 #endif
118 }
119
120 *status = 0;
121 fits_clear_errmsg();
122 if(nerrs > MAXERRORS ) {
123 #ifdef ERR2OUT
124 fprintf(stdout,"??? Too many Errors! I give up...\n");
125 #else
126 fprintf(stderr,"??? Too many Errors! I give up...\n");
127 #endif
128 close_report(out);
129 exit(1);
130 }
131 return nerrs;
132 }
133
134 int wrtserr(FILE *out, char* mess, int *status, int severity)
135 /* dump the cfitsio stack */
136 {
137 char* errfmt = " %.67s\n";
138 int i;
139 char tmp[20][80];
140 int nstack = 0;
141
142 if(severity < err_report) {
143 fits_clear_errmsg();
144 return 0;
145 }
146 nerrs++;
147
148 strcpy(temp,"*** Error: ");
149 strcat(temp,mess);
150 strcat(temp,"(from CFITSIO error stack:)");
151 while(nstack < 20) {
152 tmp[nstack][0] = '\0';
153 i = fits_read_errmsg(tmp[nstack]);
154 if(!i && tmp[nstack][0]=='\0') break;
155 nstack++;
156 }
157
158 if(out !=NULL) {
159 if ((out!=stdout) && (out!=stderr)) {
160 print_fmt(out,temp,13);
161 for(i=0; i<=nstack; i++) fprintf(out,errfmt,tmp[i]);
162 }
163
164 #ifdef ERR2OUT
165 print_fmt(stdout,temp,13);
166 for(i=0; i<=nstack; i++) fprintf(stdout,errfmt,tmp[i]);
167 #else
168 print_fmt(stderr,temp,13);
169 for(i=0; i<=nstack; i++) fprintf(stderr,errfmt,tmp[i]);
170 #endif
171 }
172
173 *status = 0;
174 fits_clear_errmsg();
175 if(nerrs > MAXERRORS ) {
176 #ifdef ERR2OUT
177 fprintf(stdout,"??? Too many Errors! I give up...\n");
178 #else
179 fprintf(stderr,"??? Too many Errors! I give up...\n");
180 #endif
181 close_report(out);
182 exit(1);
183 }
184 return nerrs;
185 }
186
187 void print_fmt(FILE *out, char *temp, int nprompt)
188 /* Print output of messages in a 80 character record.
189 Continue lines are aligned. */
190 {
191
192 char *p;
193 int i,j;
194 int clen;
195 char tmp[81];
196 static char cont_fmt[80];
197 static int save_nprompt = 0;
198
199 if (out == NULL) return;
200
201 if(nprompt != save_nprompt) {
202 for (i = 0; i < nprompt; i++) cont_fmt[i] = ' ';
203 strcat(cont_fmt,"%.67s\n");
204 save_nprompt = nprompt;
205 }
206
207 i = strlen(temp) - 80;
208 if(i <= 0) {
209 fprintf(out,"%.80s\n",temp);
210 }
211 else{
212 p = temp;
213 clen = 80 -nprompt;
214 strncpy(tmp,p,80);
215 tmp[80] = '\0';
216 if(isprint((int)*(p+79)) && isprint((int)*(p+80)) && *(p+80) != '\0') {
217 j = 79;
218 while(*(p+j) != ' ' && j > 0) j--;
219 p += j;
220 while( *p == ' ')p++;
221 tmp[j] = '\0';
222 }
223 else if( *(p+80) == ' ') {
224 j = 80;
225 while( *(p+j) == ' ') j++;
226 p += j;
227 }
228 else {
229 p += 80;
230 }
231 fprintf(out,"%.80s\n",tmp);
232 while(*p != '\0' && i > 0) {
233 strncpy(tmp,p,clen);
234 tmp[clen] = '\0';
235 i = strlen(p)- clen;
236 if(i > 0 && isprint((int)*(p+clen-1))
237 && isprint((int)*(p+clen))
238 && *(p+clen) != '\0') {
239 j = clen;
240 while(*(p+j)!= ' ' && j > 0) j--;
241 p += j;
242 while( *p == ' ')p++;
243 tmp[j] = '\0';
244 }
245 else if(i> 0 && *(p+clen) == ' ') {
246 j = clen;
247 while( *(p+j) == ' ') j++;
248 p += j;
249 }
250 else if(i> 0) {
251 p+= clen;
252 }
253 fprintf(out,cont_fmt,tmp);
254 }
255 }
256 if(out==stdout) fflush(stdout);
257 return;
258 }
259 void wrtsep(FILE *out,char fill, char *title, int nchar)
260 /* print a line of char fill with string title in the middle */
261 {
262 int ntitle;
263 char *line;
264 char *p;
265 int first_end;
266 int i = 0;
267
268 ntitle = strlen(title);
269 if(ntitle > nchar) nchar = ntitle;
270 if(nchar <= 0) return;
271 line = (char *)malloc((nchar+1)*sizeof(char));
272 p = line;
273 if(ntitle < 1) {
274 for (i=0; i < nchar; i++) {*p = fill; p++;}
275 *p = '\0';
276 }
277 else {
278 first_end = ( nchar - ntitle)/2;
279 for (i = 0; i < first_end; i++) { *p = fill; p++;}
280 *p = '\0';
281 strcat(line, title);
282 p += ntitle;
283 for( i = first_end + ntitle; i < nchar; i++) {*p = fill; p++;}
284 *p = '\0';
285 }
286 if(out != NULL )fprintf(out,"%s\n",line);
287 if(out == stdout )fflush(out);
288 free (line);
289 return ;
290 }
291
292
293 /* comparison function for the FitsKey structure array */
294 int compkey (const void *key1, const void *key2)
295 {
296 char *name1;
297 char *name2;
298 name1 = (*(FitsKey **)key1)->kname;
299 name2 = (*(FitsKey **)key2)->kname;
300 return strncmp(name1,name2,FLEN_KEYWORD);
301 }
302
303 /* comparison function for the colname structure array */
304 int compcol (const void *col1, const void *col2)
305 {
306 char *name1;
307 char *name2;
308 name1 = (*(ColName **)col1)->name;
309 name2 = (*(ColName **)col2)->name;
310 return strcmp(name1,name2);
311 }
312 /* comparison function for the string pattern maching*/
313 int compstrp (const void *str1, const void *str2)
314 {
315 char *p;
316 char *q;
317 p = (char *)(*(char**) str1);
318 q = (char *)(*(char**) str2);
319 while( *q == *p && *q != '\0') {
320 p++;
321 q++;
322 if(*p == '\0') return 0; /* str2 is longer than str1, but
323 matched */
324 }
325 return (*p - *q);
326 }
327
328 /* comparison function for the string exact maching*/
329 int compstre (const void *str1, const void *str2)
330 {
331 char *p;
332 char *q;
333 p = (char *)(*(char**) str1);
334 q = (char *)(*(char**) str2);
335 return strcmp( p, q);
336 }
337