1 | |
---|
2 | /* File SHTRANSL.C |
---|
3 | * ========== |
---|
4 | * |
---|
5 | * version 14, 13-Nov-2006 |
---|
6 | * |
---|
7 | * SeismicHandler translation routines for parameters |
---|
8 | * K. Stammler, 29-MAR-1990 |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | /* |
---|
13 | * |
---|
14 | * SeismicHandler, seismic analysis software |
---|
15 | * Copyright (C) 1992, Klaus Stammler, Federal Institute for Geosciences |
---|
16 | * and Natural Resources (BGR), Germany |
---|
17 | * |
---|
18 | * This program is free software; you can redistribute it and/or modify |
---|
19 | * it under the terms of the GNU General Public License as published by |
---|
20 | * the Free Software Foundation; either version 2 of the License, or |
---|
21 | * (at your option) any later version. |
---|
22 | * |
---|
23 | * This program is distributed in the hope that it will be useful, |
---|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
26 | * GNU General Public License for more details. |
---|
27 | * |
---|
28 | * You should have received a copy of the GNU General Public License |
---|
29 | * along with this program; if not, write to the Free Software |
---|
30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | #include <stdio.h> |
---|
36 | #include <string.h> |
---|
37 | #include <ctype.h> |
---|
38 | #include "basecnst.h" |
---|
39 | #include BC_SYSBASE |
---|
40 | #include "shconst.h" |
---|
41 | #include "shvars.h" |
---|
42 | #include "cpusrdef.h" |
---|
43 | #include "erusrdef.h" |
---|
44 | #include "trusrdef.h" |
---|
45 | #include "ssusrdef.h" |
---|
46 | #include "tcusrdef.h" |
---|
47 | #include "infoidx.h" |
---|
48 | #include "fctxsl.h" /* include loop */ |
---|
49 | #include "fctxml.h" |
---|
50 | #include "fctxdm.h" /* include loop */ |
---|
51 | #include "trerrors.h" |
---|
52 | #include "utusrdef.h" |
---|
53 | #include "sserrors.h" |
---|
54 | #include "sherrors.h" |
---|
55 | #include "globalparams.h" |
---|
56 | |
---|
57 | #define PCFREAD '%' |
---|
58 | #define PCSYMBOL '\"' |
---|
59 | #define PCCMDPAR '#' |
---|
60 | #define PCINFENT '^' |
---|
61 | #define PCINTERN '$' |
---|
62 | #define PCCONCAT '|' |
---|
63 | #define MAXCONCAT 10 |
---|
64 | |
---|
65 | #define tr_isvar(c) (((c) >= '\"') && ((c) <= '%') || ((c) == '^') || ((c) == '|')) |
---|
66 | |
---|
67 | |
---|
68 | static void *runtrc_trv; /* running trace pointer (for PCINFENT) */ |
---|
69 | static int runidx_trv; /* running index number */ |
---|
70 | |
---|
71 | |
---|
72 | /* prototypes of local routines */ |
---|
73 | static void tr_concat( char str[], int maxlth, int *status ); |
---|
74 | static void tr_fillstr( char ch, char *idxstr, int maxlth, char *str, int *status ); |
---|
75 | |
---|
76 | |
---|
77 | /*------------------------------------------------------------------------*/ |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | void tr_partrans( PARAM *par, STATUS *status ) |
---|
82 | |
---|
83 | /* translates all parameters in "par" |
---|
84 | * |
---|
85 | * parameters of routine |
---|
86 | * PARAM *par; modify; parameters to be translated |
---|
87 | * int *status; output; return status |
---|
88 | */ |
---|
89 | { |
---|
90 | /* local variables */ |
---|
91 | int i; /* counter */ |
---|
92 | BOOLEAN noinfo; /* info not found */ |
---|
93 | |
---|
94 | /* executable code */ |
---|
95 | |
---|
96 | noinfo = FALSE; |
---|
97 | for (i=0;i<=par->pno;i++) { |
---|
98 | if (tr_isvar(par->p[i][0])) { |
---|
99 | tr_translate( par->p[i], CPC_LINELTH, status ); |
---|
100 | if (*status == SHE_NOINFO) { |
---|
101 | noinfo = TRUE; |
---|
102 | *status = TRE_NOERROR; |
---|
103 | } /*endif*/ |
---|
104 | if (*status != TRE_NOERROR) return; |
---|
105 | } /*endif*/ |
---|
106 | } /*endfor*/ |
---|
107 | if (noinfo) *status = SHE_NOINFO; |
---|
108 | |
---|
109 | } /* end of tr_partrans */ |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | /*------------------------------------------------------------------------*/ |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | void tr_translate( char str[], int maxlth, STATUS *status ) |
---|
118 | |
---|
119 | /* translates string |
---|
120 | * |
---|
121 | * parameters of routine |
---|
122 | * char *str; modify; string to be translated |
---|
123 | * int maxlth; maximum string length |
---|
124 | * int *status; output; return status |
---|
125 | */ |
---|
126 | { |
---|
127 | /* local variables */ |
---|
128 | char chid; /* char ID */ |
---|
129 | char name[CPC_LINELTH+1]; /* name of variable */ |
---|
130 | char idxstr[CPC_LINELTH+1]; /* index string */ |
---|
131 | |
---|
132 | /* executable code */ |
---|
133 | |
---|
134 | if (!tr_isvar(*str)) return; |
---|
135 | |
---|
136 | if (*str == PCCONCAT) { |
---|
137 | tr_concat( str, maxlth, status ); |
---|
138 | } else { |
---|
139 | tr_parse( str, &chid, name, idxstr, status ); |
---|
140 | if (*status != TRE_NOERROR) return; |
---|
141 | if (tr_isvar(*name)) { |
---|
142 | tr_translate( name, CPC_LINELTH, status ); |
---|
143 | if (*status != TRE_NOERROR) return; |
---|
144 | } /*endif*/ |
---|
145 | if (tr_isvar(*idxstr)) { |
---|
146 | tr_translate( idxstr, CPC_LINELTH, status ); |
---|
147 | if (*status != TRE_NOERROR) return; |
---|
148 | } /*endif*/ |
---|
149 | switch (chid) { |
---|
150 | case PCFREAD: |
---|
151 | tr_rdline( name, idxstr, maxlth, str, status ); |
---|
152 | break; |
---|
153 | case PCSYMBOL: |
---|
154 | ss_getval( SHC_SYMLOC, name, maxlth, str, status ); |
---|
155 | if (*status == SSE_UDSYM) { |
---|
156 | *status = SSE_NOERROR; |
---|
157 | ss_getval( SHC_SYMGLB, name, maxlth, str, status ); |
---|
158 | } /*endif*/ |
---|
159 | break; |
---|
160 | case PCCMDPAR: |
---|
161 | ss_getpar( name, maxlth, str, status ); |
---|
162 | if (Severe(status)) return; |
---|
163 | while (tr_isvar(*str)) { |
---|
164 | tr_translate( str, maxlth, status ); |
---|
165 | if (Severe(status)) return; |
---|
166 | } /*endif*/ |
---|
167 | break; |
---|
168 | case PCINFENT: |
---|
169 | tr_infent( name, idxstr, maxlth, str, status ); |
---|
170 | if (*status == SHE_NOINFO) strncpy( str, "-?-", maxlth); |
---|
171 | break; |
---|
172 | case PCINTERN: |
---|
173 | tr_intern( name, idxstr, maxlth, str, status ); |
---|
174 | break; |
---|
175 | default: |
---|
176 | break; |
---|
177 | } /*endswitch*/ |
---|
178 | } /*endif*/ |
---|
179 | |
---|
180 | } /* end of tr_translate */ |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | /*------------------------------------------------------------------------*/ |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | void tr_parse( char str[], char *chid, char name[], char idxstr[], |
---|
189 | STATUS *status ) |
---|
190 | |
---|
191 | /* extracts from string char ID, variable name & index string |
---|
192 | * |
---|
193 | * parameters of routine |
---|
194 | * char str[]; input; string to be parsed |
---|
195 | * char *chid; output; char ID |
---|
196 | * char name[]; output; name of variable |
---|
197 | * char idxstr[]; output; index string |
---|
198 | * int *status; output; return status |
---|
199 | */ |
---|
200 | { |
---|
201 | /* local variables */ |
---|
202 | |
---|
203 | /* executable code */ |
---|
204 | |
---|
205 | *chid = *str++; |
---|
206 | *name = '\0'; |
---|
207 | *idxstr = '\0'; |
---|
208 | |
---|
209 | while (*str != '\0' && *str != '(') |
---|
210 | *name++ = *str++; |
---|
211 | |
---|
212 | if (*(name-1) == *chid) name--; |
---|
213 | *name = '\0'; |
---|
214 | if (*str == *chid) str++; |
---|
215 | if (*str == '\0') return; |
---|
216 | if (*str++ != '(') { |
---|
217 | *status = TRE_ILIDX; |
---|
218 | return; |
---|
219 | } /*endif*/ |
---|
220 | |
---|
221 | while (*str != '\0' && *str != ')') |
---|
222 | *idxstr++ = *str++; |
---|
223 | |
---|
224 | *idxstr = '\0'; |
---|
225 | if (*str == ')') |
---|
226 | if (*(++str) != '\0') *status = TRE_PRADD; |
---|
227 | |
---|
228 | } /* end of tr_parse */ |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | /*------------------------------------------------------------------------*/ |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | void tr_rdline( char name[], char idxstr[], int maxlth, char str[], |
---|
237 | STATUS *status ) |
---|
238 | |
---|
239 | /* reads line number "idxstr" from file "name" |
---|
240 | * |
---|
241 | * parameters of routine |
---|
242 | * char name[]; input; name of file |
---|
243 | * char idxstr[]; input; line number |
---|
244 | * int maxlth; input; maximum string length (of str) |
---|
245 | * char str[]; output; line read |
---|
246 | * STATUS *status; output; return status |
---|
247 | */ |
---|
248 | { |
---|
249 | /* local variables */ |
---|
250 | int lineno; /* line number */ |
---|
251 | FILE *fp; /* file pointer */ |
---|
252 | char fname[BC_FILELTH+1]; /* filename */ |
---|
253 | char *globpath; /* pointer to globals path */ |
---|
254 | int pathcnt; /* path counter */ |
---|
255 | |
---|
256 | /* executable code */ |
---|
257 | |
---|
258 | if (*idxstr == '\0') { |
---|
259 | lineno = 1; |
---|
260 | } else if (sscanf(idxstr,"%d",&lineno) != 1) { |
---|
261 | *status = TRE_CNVIDX; |
---|
262 | err_setcontext( " ## number " ); err_setcontext( idxstr ); |
---|
263 | return; |
---|
264 | } /*endif*/ |
---|
265 | |
---|
266 | /* open file, try all globals paths if no absolute path */ |
---|
267 | if (*name == '/' || *name == '\\') { |
---|
268 | fp = sy_fopen( name, "r" ); |
---|
269 | } else { |
---|
270 | for (pathcnt=0;;pathcnt++) { |
---|
271 | globpath = GpGetStringElem( cGpL_defpath_globals, pathcnt ); |
---|
272 | if (globpath == NULL) break; |
---|
273 | if ((strlen(fname)+strlen(globpath)+1) > BC_FILELTH) { |
---|
274 | *status = TRE_STROVFL; |
---|
275 | err_setcontext( " ## filename too long" ); |
---|
276 | return; |
---|
277 | } /*endif*/ |
---|
278 | strcpy( fname, globpath ); |
---|
279 | strcat( fname, "/" ); |
---|
280 | strcat( fname, name ); |
---|
281 | ut_defext( fname, BC_FILELTH, SHC_DE_TEXT, status ); |
---|
282 | if (*status != TRE_NOERROR) return; |
---|
283 | fp = sy_fopen( fname, "r" ); |
---|
284 | if (fp != NULL) break; |
---|
285 | } /*endfor*/ |
---|
286 | } /*endif*/ |
---|
287 | if (fp == NULL) { |
---|
288 | *status = TRE_OPNRD; |
---|
289 | err_setcontext( " ## file " ); err_setcontext( fname ); |
---|
290 | return; |
---|
291 | } /*endif*/ |
---|
292 | |
---|
293 | /* if lineno == 0, determine length of file */ |
---|
294 | if (lineno == 0) { |
---|
295 | while (fgets(str,maxlth,fp) != NULL) |
---|
296 | lineno++; |
---|
297 | sprintf( str, "%d", lineno ); |
---|
298 | fclose( fp ); |
---|
299 | return; |
---|
300 | } /*endif*/ |
---|
301 | |
---|
302 | /* read specified line */ |
---|
303 | while (--lineno >= 0) { |
---|
304 | if (fgets(str,maxlth,fp) == NULL) { |
---|
305 | *status = TRE_RDFIL; |
---|
306 | fclose( fp ); |
---|
307 | err_setcontext( " ## file " ); err_setcontext( fname ); |
---|
308 | return; |
---|
309 | } /*endif*/ |
---|
310 | } /*endwhile*/ |
---|
311 | fclose( fp ); |
---|
312 | |
---|
313 | /* drop control chars at end */ |
---|
314 | lineno = (int)strlen( str ); |
---|
315 | while (str[--lineno] < ' ') |
---|
316 | str[lineno] = '\0'; |
---|
317 | |
---|
318 | } /* tr_rdline */ |
---|
319 | |
---|
320 | |
---|
321 | |
---|
322 | /*------------------------------------------------------------------------*/ |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | void tr_infent( char name[], char idxstr[], int maxlth, char str[], |
---|
327 | STATUS *status ) |
---|
328 | |
---|
329 | /* gets info "name" from trace number "idxstr" |
---|
330 | * |
---|
331 | * parameters of routine |
---|
332 | * char name[]; input; name of info |
---|
333 | * char idxstr[]; input; trace number |
---|
334 | * int maxlth; input; maximum string length (of str) |
---|
335 | * char str[]; output; info read |
---|
336 | * STATUS *status; output; return status |
---|
337 | */ |
---|
338 | { |
---|
339 | /* local variables */ |
---|
340 | int trcno; /* trace number */ |
---|
341 | long l_inf; /* long info */ |
---|
342 | int i_inf; /* int & byte info */ |
---|
343 | float r_inf; /* real info */ |
---|
344 | void *p_inf; /* ptr info */ |
---|
345 | TIME t_inf; /* time info */ |
---|
346 | unsigned ientry; /* info entry */ |
---|
347 | void *trc; /* trace pointer */ |
---|
348 | int dln; /* display list number */ |
---|
349 | int cnt; /* counter */ |
---|
350 | char wstr[BC_SHORTSTRLTH+1]; /* number of window (num string) */ |
---|
351 | |
---|
352 | /* executable code */ |
---|
353 | |
---|
354 | if (*idxstr == 'W') { /* not default window */ |
---|
355 | cnt = 0; |
---|
356 | idxstr++; |
---|
357 | while (isdigit(*idxstr) && (cnt <= BC_SHORTSTRLTH)) |
---|
358 | wstr[cnt++] = *idxstr++; |
---|
359 | wstr[cnt] = '\0'; |
---|
360 | if (*idxstr != ':') { |
---|
361 | *status = TRE_ILWDW; |
---|
362 | return; |
---|
363 | } /*endif*/ |
---|
364 | idxstr++; |
---|
365 | if (sscanf( wstr, "%d", &dln ) != 1) { |
---|
366 | *status = TRE_ILWDW; |
---|
367 | return; |
---|
368 | } /*endif*/ |
---|
369 | } else { |
---|
370 | dln = gc; /* (gc == 0) ? SHC_HIDDENLIST : gc; */ |
---|
371 | } /*endif*/ |
---|
372 | |
---|
373 | if (*idxstr == '\0') { |
---|
374 | trc = ml_trc( dln, 1, status ); |
---|
375 | if (*status != TRE_NOERROR) return; |
---|
376 | } else if (*idxstr == 'X' || strcmp(idxstr,"$X") == 0) { |
---|
377 | if (runtrc_trv == NULL) return; /* don't translate */ |
---|
378 | trc = runtrc_trv; |
---|
379 | } else if (*idxstr == 'A' && idxstr[1] == ':') { |
---|
380 | if (sscanf( idxstr+2, "%lp", &trc ) != 1) { |
---|
381 | *status = TRE_CNVIDX; |
---|
382 | err_setcontext( " ## numstr " ); err_setcontext( idxstr+2 ); |
---|
383 | return; |
---|
384 | } /*endif*/ |
---|
385 | } else if (sscanf(idxstr,"%d",&trcno) != 1) { |
---|
386 | *status = TRE_CNVIDX; |
---|
387 | err_setcontext( " ## numstr " ); err_setcontext( idxstr ); |
---|
388 | return; |
---|
389 | } else { |
---|
390 | trc = ml_trc( dln, trcno, status ); |
---|
391 | if (*status != TRE_NOERROR) return; |
---|
392 | } /*endif*/ |
---|
393 | |
---|
394 | db_ident( name, &ientry, status ); |
---|
395 | if (*status != TRE_NOERROR) return; |
---|
396 | |
---|
397 | switch (ientry & E_TYPMASK) { |
---|
398 | case EL_TYPE: |
---|
399 | l_inf = db_getl( trc, ientry, status ); |
---|
400 | if (*status != TRE_NOERROR) return; |
---|
401 | sprintf( str, "%ld", l_inf ); |
---|
402 | break; |
---|
403 | case EI_TYPE: |
---|
404 | i_inf = db_geti( trc, ientry, status ); |
---|
405 | if (*status != TRE_NOERROR) return; |
---|
406 | sprintf( str, "%d", i_inf ); |
---|
407 | break; |
---|
408 | case EB_TYPE: |
---|
409 | i_inf = db_geti( trc, ientry, status ); |
---|
410 | if (*status != TRE_NOERROR) return; |
---|
411 | sprintf( str, "%d", i_inf ); |
---|
412 | break; |
---|
413 | case ER_TYPE: |
---|
414 | r_inf = db_getr( trc, ientry, status ); |
---|
415 | if (*status != TRE_NOERROR) return; |
---|
416 | sprintf( str, "%e", r_inf ); |
---|
417 | break; |
---|
418 | case ES_TYPE: |
---|
419 | db_gets( trc, ientry, maxlth, str, status ); |
---|
420 | break; |
---|
421 | case EC_TYPE: |
---|
422 | *str = db_getc( trc, ientry, status ); |
---|
423 | str[1] = '\0'; |
---|
424 | if (*status != TRE_NOERROR) return; |
---|
425 | break; |
---|
426 | case ET_TYPE: |
---|
427 | db_gett( trc, ientry, &t_inf, status ); |
---|
428 | if (*status != TRE_NOERROR) return; |
---|
429 | if (maxlth < 30) { *status = TRE_STROVFL; return; } |
---|
430 | tc_a2t( &t_inf, str, status ); |
---|
431 | break; |
---|
432 | case EP_TYPE: |
---|
433 | p_inf = db_getp( trc, ientry, status ); |
---|
434 | if (*status != TRE_NOERROR) return; |
---|
435 | sprintf( str, "%ld", p_inf ); |
---|
436 | break; |
---|
437 | case EF_TYPE: |
---|
438 | i_inf = db_getf( trc, ientry, status ); |
---|
439 | if (*status != TRE_NOERROR) return; |
---|
440 | *str = (i_inf) ? 'Y' : 'N'; |
---|
441 | str[1] = '\0'; |
---|
442 | break; |
---|
443 | case EX_TYPE: |
---|
444 | db_getx( trc, ientry, maxlth, str, status ); |
---|
445 | break; |
---|
446 | default: |
---|
447 | *status = TRE_ILTYPE; |
---|
448 | return; |
---|
449 | } /*endswitch*/ |
---|
450 | |
---|
451 | } /* tr_infent */ |
---|
452 | |
---|
453 | |
---|
454 | |
---|
455 | /*------------------------------------------------------------------------*/ |
---|
456 | |
---|
457 | |
---|
458 | |
---|
459 | void tr_intern( char name[], char idxstr[], int maxlth, char str[], |
---|
460 | STATUS *status ) |
---|
461 | |
---|
462 | /* returns internal variable |
---|
463 | * |
---|
464 | * parameters of routine |
---|
465 | * char name[]; input; name of variable |
---|
466 | * char idxstr[]; input; index string |
---|
467 | * int maxlth; input; maximum length of output string |
---|
468 | * char str[]; output; translated string |
---|
469 | * STATUS *status; output; return status |
---|
470 | */ |
---|
471 | { |
---|
472 | /* local variables */ |
---|
473 | int num; /* number */ |
---|
474 | char numstr[3]; /* number string */ |
---|
475 | float r, r1; /* scratch */ |
---|
476 | |
---|
477 | /* executable code */ |
---|
478 | |
---|
479 | if (strcmp(name,"DSPTRCS") == 0) { |
---|
480 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
481 | if (maxlth < 5) {*status = TRE_STROVFL; return;} |
---|
482 | sprintf( str, "%d", db_dsplth(gc) ); |
---|
483 | } else if (strcmp(name,"TOTTRCS") == 0) { |
---|
484 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
485 | if (maxlth < 5) {*status = TRE_STROVFL; return;} |
---|
486 | sprintf( str, "%d", db_lstlth() ); |
---|
487 | } else if (strcmp(name,"STATUS") == 0) { |
---|
488 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
489 | if (maxlth < 6) {*status = TRE_STROVFL; return;} |
---|
490 | sprintf( str, "%d", shv_last_status ); |
---|
491 | } else if (strcmp(name,"SYSTIME") == 0) { |
---|
492 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
493 | if (maxlth < 25) {*status = TRE_STROVFL; return;} |
---|
494 | sy_gettime( str ); |
---|
495 | } else if (strcmp(name,"X") == 0) { |
---|
496 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
497 | if (maxlth < 6) {*status = TRE_STROVFL; return;} |
---|
498 | if (runidx_trv == 0) return; /* don't translate */ |
---|
499 | sprintf( str, "%d", runidx_trv ); |
---|
500 | } else if (strcmp(name,"VERSION") == 0) { |
---|
501 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
502 | if (maxlth < 17) {*status = TRE_STROVFL; return;} |
---|
503 | strcpy( str, SHC_VERSION ); |
---|
504 | } else if (strcmp(name,"DSP_X") == 0) { |
---|
505 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
506 | dm_dspcoo( &r, NULL, NULL, NULL ); |
---|
507 | sprintf( str, "%e", r ); |
---|
508 | } else if (strcmp(name,"DSP_Y") == 0) { |
---|
509 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
510 | dm_dspcoo( NULL, &r, NULL, NULL ); |
---|
511 | sprintf( str, "%e", r ); |
---|
512 | } else if (strcmp(name,"DSP_W") == 0) { |
---|
513 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
514 | dm_dspcoo( NULL, NULL, &r, NULL ); |
---|
515 | sprintf( str, "%e", r ); |
---|
516 | } else if (strcmp(name,"DSP_H") == 0) { |
---|
517 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
518 | dm_dspcoo( NULL, NULL, NULL, &r ); |
---|
519 | sprintf( str, "%e", r ); |
---|
520 | } else if (strcmp(name,"DSP_XMAX") == 0) { |
---|
521 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
522 | dm_dspcoo( &r, NULL, &r1, NULL ); |
---|
523 | r += r1; |
---|
524 | sprintf( str, "%e", r ); |
---|
525 | } else if (strcmp(name,"DSP_YMAX") == 0) { |
---|
526 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
527 | dm_dspcoo( NULL, &r, NULL, &r1 ); |
---|
528 | r += r1; |
---|
529 | sprintf( str, "%e", r ); |
---|
530 | } else if (strcmp(name,"BLANK") == 0) { |
---|
531 | tr_fillstr( ' ', idxstr, maxlth, str, status ); |
---|
532 | } else if (strcmp(name,"EXCLAMATION") == 0) { |
---|
533 | tr_fillstr( '!', idxstr, maxlth, str, status ); |
---|
534 | } else if (strcmp(name,"QUOTES") == 0) { |
---|
535 | tr_fillstr( '"', idxstr, maxlth, str, status ); |
---|
536 | } else if (strcmp(name,"DOLLAR") == 0) { |
---|
537 | tr_fillstr( '$', idxstr, maxlth, str, status ); |
---|
538 | } else if (strcmp(name,"PERCENT") == 0) { |
---|
539 | tr_fillstr( '%', idxstr, maxlth, str, status ); |
---|
540 | } else if (strcmp(name,"HAT") == 0) { |
---|
541 | tr_fillstr( '^', idxstr, maxlth, str, status ); |
---|
542 | } else if (strcmp(name,"BAR") == 0) { |
---|
543 | tr_fillstr( '|', idxstr, maxlth, str, status ); |
---|
544 | } else if (strcmp(name,"SLASH") == 0) { |
---|
545 | tr_fillstr( '/', idxstr, maxlth, str, status ); |
---|
546 | } else if (strcmp(name,"NUMBER") == 0) { |
---|
547 | tr_fillstr( '#', idxstr, maxlth, str, status ); |
---|
548 | } else if (strcmp(name,"TITLESTYLE") == 0) { |
---|
549 | sprintf( str, "%d", SHC_TITLESTYLE ); |
---|
550 | } else if (strcmp(name,"TRCINFOSTYLE") == 0) { |
---|
551 | sprintf( str, "%d", SHC_TRCINFOSTYLE ); |
---|
552 | } else if (strcmp(name,"ZEROTRCSTYLE") == 0) { |
---|
553 | sprintf( str, "%d", SHC_ZEROTRCSTYLE ); |
---|
554 | } else if (strcmp(name,"TIMEAXISSTYLE") == 0) { |
---|
555 | sprintf( str, "%d", SHC_TIMEAXISSTYLE ); |
---|
556 | } else if (strcmp(name,"MARKSTYLE") == 0) { |
---|
557 | sprintf( str, "%d", SHC_MARKSTYLE ); |
---|
558 | } else if (strcmp(name,"PMSTYLE") == 0) { |
---|
559 | sprintf( str, "%d", SHC_PMSTYLE ); |
---|
560 | } else if (strncmp(name,"HEXCHAR",7) == 0) { |
---|
561 | if (strlen(name) != 9) { *status = TRE_HEXCHAR; return; } |
---|
562 | *numstr = name[7]; |
---|
563 | numstr[1] = name[8]; |
---|
564 | numstr[2] = '\0'; |
---|
565 | if (sscanf(numstr,"%x",&num) != 1) { *status=TRE_HEXCHAR; return; } |
---|
566 | tr_fillstr( (char)num, idxstr, maxlth, str, status ); |
---|
567 | } else if (strcmp(name,"SH_ID") == 0) { |
---|
568 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
569 | if (maxlth < 10) {*status = TRE_STROVFL; return;} |
---|
570 | strcpy( str, id_shv ); |
---|
571 | } else if (strcmp(name,"PI") == 0) { |
---|
572 | if (*idxstr != '\0') {*status = TRE_ILIDX; return;} |
---|
573 | if (maxlth < 23) {*status = TRE_STROVFL; return;} |
---|
574 | strcpy( str, "3.14159265358979323846" ); |
---|
575 | } else { |
---|
576 | *status = TRE_UKINTERN; |
---|
577 | err_setcontext( " ## internal var " ); err_setcontext( name ); |
---|
578 | return; |
---|
579 | } /*endif*/ |
---|
580 | |
---|
581 | } /* end of tr_intern */ |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | /*------------------------------------------------------------------------*/ |
---|
586 | |
---|
587 | |
---|
588 | |
---|
589 | static void tr_concat( char str[], int maxlth, STATUS *status ) |
---|
590 | |
---|
591 | /* concatenates parameters |
---|
592 | * |
---|
593 | * parameters of routine |
---|
594 | * char str[]; modify; concatenated expression |
---|
595 | * int maxlth; input; maximum length of string |
---|
596 | * STATUS *status; output; return status |
---|
597 | */ |
---|
598 | { |
---|
599 | /* local variables */ |
---|
600 | int ccpos[MAXCONCAT]; /* positions of string elements */ |
---|
601 | int cccnt; /* number of string elements */ |
---|
602 | int i; /* counter */ |
---|
603 | char ccres[CPC_LINELTH+1]; /* result of concatenation */ |
---|
604 | int ccspace; /* remaining length of result string */ |
---|
605 | char *ccptr; /* pointer to result string */ |
---|
606 | int lth; /* string length */ |
---|
607 | |
---|
608 | /* executable code */ |
---|
609 | |
---|
610 | cccnt = 0; |
---|
611 | i = 0; |
---|
612 | while (str[i] != '\0') { |
---|
613 | if (str[i] == PCCONCAT) { |
---|
614 | str[i] = '\0'; |
---|
615 | if (str[i+1] == '\0') break; |
---|
616 | if (cccnt == (MAXCONCAT-1)) { |
---|
617 | *status = TRE_CCOVFL; |
---|
618 | return; |
---|
619 | } /*endif*/ |
---|
620 | ccpos[cccnt++] = i+1; |
---|
621 | } /*endif*/ |
---|
622 | i++; |
---|
623 | } /*endwhile*/ |
---|
624 | |
---|
625 | *ccres = '\0'; |
---|
626 | ccptr = ccres; |
---|
627 | ccspace = (maxlth < CPC_LINELTH) ? maxlth : CPC_LINELTH; |
---|
628 | for (i=0; i<cccnt; i++) { |
---|
629 | if (strlen(str+ccpos[i]) > ccspace) { |
---|
630 | *status = TRE_STROVFL; |
---|
631 | return; |
---|
632 | } /*endif*/ |
---|
633 | strcpy( ccptr, str+ccpos[i] ); |
---|
634 | tr_translate( ccptr, ccspace, status ); |
---|
635 | if (*status == SHE_NOINFO) |
---|
636 | *status = TRE_NOERROR; |
---|
637 | if (Severe(status)) return; |
---|
638 | lth = (int)strlen( ccptr ); |
---|
639 | ccptr += lth; |
---|
640 | ccspace -= lth; |
---|
641 | } /*endfor*/ |
---|
642 | |
---|
643 | strcpy( str, ccres ); |
---|
644 | |
---|
645 | } /* end of tr_concat */ |
---|
646 | |
---|
647 | |
---|
648 | |
---|
649 | /*------------------------------------------------------------------------*/ |
---|
650 | |
---|
651 | |
---|
652 | |
---|
653 | void tr_setruntrc( TRACE *trc, int idx ) |
---|
654 | |
---|
655 | /* sets running trace pointer */ |
---|
656 | |
---|
657 | { runtrc_trv = trc; runidx_trv = idx; } |
---|
658 | |
---|
659 | |
---|
660 | |
---|
661 | /*------------------------------------------------------------------------*/ |
---|
662 | |
---|
663 | |
---|
664 | |
---|
665 | static void tr_fillstr( char ch, char idxstr[], int maxlth, char str[], |
---|
666 | STATUS *status ) |
---|
667 | |
---|
668 | /* fills string with "idxstr" characters "ch" |
---|
669 | * |
---|
670 | * parameters of routine |
---|
671 | * char ch; input; fill character |
---|
672 | * char idxstr[]; input; number (string) of fill chars |
---|
673 | * int maxlth; input; maximum length of output string |
---|
674 | * char str[]; output; result string |
---|
675 | * STATUS *status; output; return status |
---|
676 | */ |
---|
677 | { |
---|
678 | /* local variables */ |
---|
679 | int chno; /* number of fill chars */ |
---|
680 | int i; /* counter */ |
---|
681 | |
---|
682 | /* executable code */ |
---|
683 | |
---|
684 | if (*idxstr == '\0') { |
---|
685 | *str = ch; |
---|
686 | str[1] = '\0'; |
---|
687 | return; |
---|
688 | } /*endif*/ |
---|
689 | |
---|
690 | if (sscanf(idxstr,"%d",&chno) != 1) { |
---|
691 | *status = TRE_CNVIDX; |
---|
692 | err_setcontext( " ## numstr " ); err_setcontext( idxstr ); |
---|
693 | return; |
---|
694 | } /*endif*/ |
---|
695 | |
---|
696 | if (chno > maxlth) { |
---|
697 | *status = TRE_STROVFL; |
---|
698 | return; |
---|
699 | } /*endif*/ |
---|
700 | |
---|
701 | for (i=0;i<chno; str[i++] = ch) {} |
---|
702 | str[chno] = '\0'; |
---|
703 | |
---|
704 | } /* end of tr_fillstr */ |
---|
705 | |
---|
706 | |
---|
707 | |
---|
708 | /*------------------------------------------------------------------------*/ |
---|