Debian Codegraph @

libsrc/st/sct.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2010 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++++++++++ SC interface module SCT +++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCT
31 .AUTHOR K. Banse ESO - Garching 870721
32 .KEYWORDS standard interfaces.
33 .ENVIRONMENT theoretically environment independant.
34 .COMMENTS all SC_interfaces related to text display:
35 SCTPUT, SCTSYS, SCTDIS, SCTMES
36
37 .VERSION [1.00] 920212: pulled out from scst.c
38 .VERSION [1.10] 931025: support ASCII file output via " >file "
39
40 101021 last modif
41 -----------------------------------------------------------------------------*/
42
43 #include <fileexts.h>
44 #include <osyparms.h>
45
46 #include <string.h>
47
48 /*
49
50 */
51
52 int SCTPUT(text)
53 /*++++++++++++++++++++++++++++++++++++++++++++++++++
54 .PURPOSE
55 display a given character string and store it in the logfile
56 .ALGORITHM
57 .RETURNS
58 return status ( 0 = o.k )
59 --------------------------------------------------*/
60
61 char *text /* IN : text string to be displayed */;
62
63 {
64 char *txtpntr, record[8];
65
66 int ltext, outflg, kk, fp;
67
68
69
70
71
72 if (KIWORDS[OFF_LOG+3] == 2) return 0; /* no output wanted ... */
73
74 outflg = 0;
75 if (KIWORDS[OFF_LOG+8] == 0) /* check print flag */
76 {
77 if (KIWORDS[OFF_LOG+3] != 1) outflg = 1;
78 }
79
80
81 ltext = (int) strlen(text);
82 if (ltext == 0)
83 {
84 ltext = CGN_COPY(record," ");
85 txtpntr = record;
86 }
87 else
88 txtpntr = text; /* point to original buffer */
89
90
91 if (outflg == 1)
92 {
93 if (KIWORDS[OFF_OUTFLG] > KIWORDS[OFF_MODE+6])
94 (void)printf("%s\n",txtpntr); /* display text */
95 else
96 { /* output => ASCII file */
97 if (KIWORDS[OFF_OUTFLG+2] < 0)
98 {
99 if ((strncmp(&KCWORDS[OFF_OUTNAM],"Null",4) == 0) ||
100 /*
101 (strncmp(&KCWORDS[OFF_OUTNAM],"NULL",4) == 0) ||
102 (strncmp(&KCWORDS[OFF_OUTNAM],"null",4) == 0) ||
103 */
104 (strncmp(&KCWORDS[OFF_OUTNAM],"/dev/null",9) == 0))
105 {
106 if (KIWORDS[OFF_LOG+11] == -1)
107 fp = 1000;
108 else
109 fp = 999;
110 }
111 else
112 {
113 if (KIWORDS[OFF_OUTFLG+3] == -2)
114 kk = APPEND;
115 else
116 kk = WRITE;
117 fp = CGN_OPEN(&KCWORDS[OFF_OUTNAM],kk);
118 if (fp < 0)
119 {
120 (void)printf(
121 "Problems opening ASCII output file ... output -> terminal!\n");
122 KIWORDS[OFF_OUTFLG] = 99; /* undo ASCII file output */
123 (void)printf("%s\n",txtpntr); /* display text as usual */
124 (void) MID_LOG('G',txtpntr,ltext);
125 return 0;
126 }
127 }
128 KIWORDS[OFF_OUTFLG+2] = fp;
129 }
130 else
131 fp = KIWORDS[OFF_OUTFLG+2];
132
133 if (fp < 999)
134 osawrite(fp,txtpntr,ltext);
135 else if (fp > 999)
136 return 0;
137
138 if (KIWORDS[OFF_OUTFLG+1] > 0)
139 (void)printf("%s\n",txtpntr); /* also display text */
140 }
141 }
142
143 (void) MID_LOG('G',txtpntr,ltext); /* always log it */
144
145 return 0;
146 }
147 /*
148
149 */
150
151 int SCTSYS(color,text)
152 /*++++++++++++++++++++++++++++++++++++++++++++++++++
153 .PURPOSE
154 same as SCTPUT but ignore I/O redirection
155 .ALGORITHM
156 .RETURNS
157 nothing
158 --------------------------------------------------*/
159 int color; /* IN: color no. for string, like for SET/GRAPH:
160 0 = default, i.e. no colour setting,
161 1 = black, 2 = red, 3 = green,
162 4 = blue, 5 = yellow, 6 = magenta,
163 7 = cyan, 8 = white */
164 char *text /* IN : text string to be displayed */;
165
166 {
167 char *txtpntr, record[8];
168 char colnum, colcode[10] = "081240650";
169
170 int ltext, outflg;
171
172
173
174
175 if (KIWORDS[OFF_LOG+3] == 2) return 0; /* no output wanted ... */
176
177 outflg = 0;
178 if (KIWORDS[OFF_LOG+8] == 0) /* check print flag */
179 {
180 if (KIWORDS[OFF_LOG+3] != 1) outflg = 1;
181 }
182
183 /* check colour*/
184
185 if ((color < 1) || (color > 8))
186 colnum = 0; /* indicate no coloring */
187 else
188 colnum = colcode[color];
189
190
191
192 ltext = (int) strlen(text);
193 if (ltext == 0)
194 {
195 ltext = CGN_COPY(record," ");
196 txtpntr = record;
197 }
198 else
199 txtpntr = text; /* point to original buffer */
200
201
202 if (outflg == 1)
203 { /* display text */
204 if (colnum == 0)
205 (void)printf("%s\n",txtpntr);
206 else
207 (void)printf("\033[3%cm%s\033[0m\n",colnum,txtpntr);
208 }
209
210 (void) MID_LOG('G',txtpntr,ltext); /* inside Midas log it */
211
212 return 0;
213 }
214 /*
215
216 */
217
218 int SCTDIS(text,bc)
219 /*++++++++++++++++++++++++++++++++++++++++++++++++++
220 .PURPOSE
221 display a given character string as it is
222 do not (!) store it in the logfile
223 .ALGORITHM
224 .RETURNS
225 return status ( 0 = o.k )
226 --------------------------------------------------*/
227
228 char *text /* IN: text string to be displayed */;
229 int bc /* IN: backspace count \
230 = -9, erase line \
231 = -1, write string + stop at end of it \
232 = 0, write line normally \
233 = [1,80], do that many backspaces */;
234
235 {
236 char *txtpntr, record[8];
237
238 int ltext, kk, mcols, fp;
239
240
241
242
243 if (KIWORDS[OFF_LOG+3] == 2) return 0; /* no output wanted ... */
244
245 mcols = 80;
246 if (bc == -9) /* erase current line */
247 {
248 char space[80];
249
250 memset((void *)space,32,(size_t)79); /* int 32 = ' ' */
251 space[79] = '\0';
252 MID_TDISP(space,mcols,mcols); /* display text */
253 return 0;
254 }
255
256
257
258 ltext = (int) strlen(text);
259 if (ltext == 0)
260 {
261 ltext = CGN_COPY(record," ");
262 txtpntr = record;
263 }
264 else
265 txtpntr = text;
266
267
268 if (bc == -1)
269 {
270 (void)printf("%s",txtpntr);
271 return 0;
272 }
273 else if (bc == 0)
274 {
275 (void)printf("%s\n",txtpntr);
276 return 0;
277 }
278
279
280 /* now bc is > 0 */
281
282 if (mcols < ltext) ltext = mcols; /* no text longer than mcols */
283 if (bc > ltext) bc = ltext; /* and not more '\b's than text size */
284
285 if (KIWORDS[OFF_OUTFLG] > KIWORDS[OFF_MODE+6])
286 MID_TDISP(txtpntr,bc,ltext); /* display text */
287 else
288 { /* output => ASCII file */
289 if (KIWORDS[OFF_OUTFLG+2] < 0)
290 {
291 if ((strncmp(&KCWORDS[OFF_OUTNAM],"Null",4) == 0) ||
292 (strncmp(&KCWORDS[OFF_OUTNAM],"/dev/null",9) == 0))
293 {
294 if (KIWORDS[OFF_LOG+11] == -1)
295 fp = 1000;
296 else
297 fp = 999;
298 }
299 else
300 {
301 if (KIWORDS[OFF_OUTFLG+2] == -2)
302 kk = APPEND;
303 else
304 kk = WRITE;
305 fp = CGN_OPEN(&KCWORDS[OFF_OUTNAM],kk);
306 if (fp < 0)
307 {
308 (void)printf(
309 "Problems opening ASCII output file ... output -> terminal!\n");
310 KIWORDS[OFF_OUTFLG] = 99; /* undo ASCII file output */
311 MID_TDISP(txtpntr,bc,ltext); /* display text as usual */
312 return 0;
313 }
314 }
315 KIWORDS[OFF_OUTFLG+2] = fp;
316 }
317 else
318 fp = KIWORDS[OFF_OUTFLG+2];
319
320 if (fp < 999)
321 osawrite(fp,txtpntr,ltext);
322 else if (fp > 999)
323 return 0;
324
325 if (KIWORDS[OFF_OUTFLG+1] > 0)
326 MID_TDISP(txtpntr,bc,ltext); /* also display text */
327 }
328
329 return 0;
330 }
331 /*
332
333 */
334
335 int SCTMES(color,text)
336 /*++++++++++++++++++++++++++++++++++++++++++++++++++
337 .PURPOSE
338 like SCTPUT with color for text
339 .ALGORITHM
340 .RETURNS
341 return status ( 0 = o.k )
342 --------------------------------------------------*/
343
344 int color; /* IN: color no. for string, like for SET/GRAPH:
345 0 = default, i.e. no colour setting,
346 1 = black, 2 = red, 3 = green,
347 4 = blue, 5 = yellow, 6 = magenta,
348 7 = cyan, 8 = white */
349 char *text /* IN : text string to be displayed */;
350
351 {
352 char *txtpntr, record[8];
353 char colnum, colcode[10] = "081243650";
354
355 int ltext, outflg, kk, fp;
356
357
358
359
360
361 if (KIWORDS[OFF_LOG+3] == 2) return 0; /* no output wanted ... */
362
363 outflg = 0;
364 if (KIWORDS[OFF_LOG+8] == 0) /* check print flag */
365 {
366 if (KIWORDS[OFF_LOG+3] != 1) outflg = 1;
367 }
368
369
370 /* check colour*/
371
372 if ((color < 1) || (color > 8))
373 colnum = 0; /* indicate no coloring */
374 else
375 colnum = colcode[color];
376
377
378
379 ltext = (int) strlen(text);
380 if (ltext == 0)
381 {
382 ltext = CGN_COPY(record," ");
383 txtpntr = record;
384 }
385 else
386 txtpntr = text; /* point to original buffer */
387
388
389 if (outflg == 1)
390 {
391 if (KIWORDS[OFF_OUTFLG] > KIWORDS[OFF_MODE+6])
392 { /* display text */
393 if (colnum == 0)
394 (void)printf("%s\n",txtpntr);
395 else
396 (void)printf("\033[3%cm%s\033[0m\n",colnum,txtpntr);
397 }
398 else
399 { /* output => ASCII file */
400 if (KIWORDS[OFF_OUTFLG+2] < 0)
401 {
402 if ((strncmp(&KCWORDS[OFF_OUTNAM],"Null",4) == 0) ||
403 (strncmp(&KCWORDS[OFF_OUTNAM],"/dev/null",9) == 0))
404 {
405 if (KIWORDS[OFF_LOG+11] == -1)
406 fp = 1000;
407 else
408 fp = 999;
409 }
410 else
411 {
412 if (KIWORDS[OFF_OUTFLG+3] == -2)
413 kk = APPEND;
414 else
415 kk = WRITE;
416 fp = CGN_OPEN(&KCWORDS[OFF_OUTNAM],kk);
417 if (fp < 0)
418 {
419 (void)printf(
420 "Problems opening ASCII output file ... output -> terminal!\n");
421 KIWORDS[OFF_OUTFLG] = 99; /* undo ASCII file output */
422 (void)printf("%s\n",txtpntr); /* display text as usual */
423 (void) MID_LOG('G',txtpntr,ltext);
424 return 0;
425 }
426 }
427 KIWORDS[OFF_OUTFLG+2] = fp;
428 }
429 else
430 fp = KIWORDS[OFF_OUTFLG+2];
431
432 if (fp < 999)
433 osawrite(fp,txtpntr,ltext);
434 else if (fp > 999)
435 return 0;
436
437 if (KIWORDS[OFF_OUTFLG+1] > 0)
438 (void)printf("%s\n",txtpntr); /* also display text */
439 }
440 }
441
442 (void) MID_LOG('G',txtpntr,ltext); /* always log it */
443
444 return 0;
445 }
446