| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2008 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 |
/*+++++++++++++++++++ Module cgne.c +++++++++++++++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
.IDENTIFICATION Module cgne.c |
| 31 |
.AUTHOR K. Banse ESO - Garching |
| 32 |
.KEYWORDS |
| 33 |
catalogs, MIDAS frames |
| 34 |
.COMMENTS |
| 35 |
holds CGN_singleframe, CGN_FRAME, CGN_DSCUPD, CGN_LOGNAM, issub |
| 36 |
|
| 37 |
.VERSION [1.00] 920325: copied from /midas/`version'/monit/prepl.c |
| 38 |
080131 last modif |
| 39 |
|
| 40 |
-------------------------------------------------------------------------*/ |
| 41 |
|
| 42 |
#include <string.h> |
| 43 |
#include <stdlib.h> |
| 44 |
#include <fileexts.h> |
| 45 |
#include <fsydef.h> |
| 46 |
|
| 47 |
/* |
| 48 |
|
| 49 |
*/ |
| 50 |
|
| 51 |
int issub(name) |
| 52 |
char *name; |
| 53 |
|
| 54 |
{ |
| 55 |
register int nr, mr; |
| 56 |
|
| 57 |
register char cr; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
nr = 0; |
| 62 |
while (nr > -1) |
| 63 |
{ |
| 64 |
cr = name[nr]; |
| 65 |
if (cr == '@') |
| 66 |
return (nr); /* name@123 */ |
| 67 |
else if ((cr == ' ') || (cr == '\0')) |
| 68 |
{ |
| 69 |
nr--; |
| 70 |
break; |
| 71 |
} |
| 72 |
nr++; |
| 73 |
} |
| 74 |
|
| 75 |
if (name[nr] == ']') /* name[12:34] */ |
| 76 |
{ |
| 77 |
for (mr=nr; mr>0; mr--) |
| 78 |
{ |
| 79 |
if (name[mr] == '[') return(mr); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return(0); |
| 84 |
} |
| 85 |
/* |
| 86 |
|
| 87 |
*/ |
| 88 |
|
| 89 |
int CGN_singleframe(inname,type,outname) |
| 90 |
|
| 91 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 92 |
|
| 93 |
.RETURN |
| 94 |
1 = filename has changed and is stored in outname |
| 95 |
0 = no change, use inname (outname not filled) |
| 96 |
|
| 97 |
-----------------------------------------------------*/ |
| 98 |
|
| 99 |
char *inname /* IN: input name */; |
| 100 |
int type /* IN: type of frame |
| 101 |
1=image, 3=table, 4 = fit file */; |
| 102 |
char *outname /* OUT: new name */; |
| 103 |
|
| 104 |
|
| 105 |
{ |
| 106 |
char catfile[120], cbuf[120]; |
| 107 |
char *typeptr; |
| 108 |
register char cc, csav; |
| 109 |
|
| 110 |
int frmno, status, idx, k, n, mm; |
| 111 |
register int nr, isu, ioff, koff; |
| 112 |
|
| 113 |
float roff; |
| 114 |
|
| 115 |
double doff; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
typeptr = FSY_DEFPNTR[0]; |
| 121 |
csav = 'a' - 'A'; |
| 122 |
|
| 123 |
|
| 124 |
/* check for &a, &A names */ |
| 125 |
|
| 126 |
if (*inname == '&') |
| 127 |
{ |
| 128 |
cc = inname[1]; |
| 129 |
if ( (cc >= 'A') && (cc <= 'Z') ) |
| 130 |
csav += cc; |
| 131 |
else if ( (cc >= 'a') && (cc <= 'z') ) |
| 132 |
csav = cc; |
| 133 |
else /* must be &123&* or so ... */ |
| 134 |
return(0); |
| 135 |
|
| 136 |
(void) memcpy(outname,"middumm ",(size_t)9); |
| 137 |
idx = 7; |
| 138 |
if (KIWORDS[OFF_AUX+11] == 123) |
| 139 |
{ /* check AUX_MODE(12) */ |
| 140 |
mm = OFF_SESS + 10; /* point to MIDAS unit */ |
| 141 |
outname[7] = KCWORDS[mm++]; |
| 142 |
outname[8] = KCWORDS[mm]; |
| 143 |
idx = 9; |
| 144 |
} |
| 145 |
outname[idx++] = csav; |
| 146 |
|
| 147 |
ioff = koff = -1; /* look for subframes abc[...] */ |
| 148 |
for (nr=2; ; nr++) |
| 149 |
{ |
| 150 |
cc = inname[nr]; |
| 151 |
if (cc == '\0') |
| 152 |
break; |
| 153 |
else if (cc == '[') |
| 154 |
{ |
| 155 |
if (ioff == (-1)) ioff = nr-2; |
| 156 |
if (koff > (-1)) break; |
| 157 |
} |
| 158 |
else if (cc == FSY_TYPMARK) |
| 159 |
{ /* if we are after the '[' already */ |
| 160 |
if (ioff > (-1)) break; /* we leave koff as -1 */ |
| 161 |
if (koff == (-1)) koff = nr-2; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
if (koff == (-1)) |
| 166 |
{ |
| 167 |
if (KIWORDS[OFF_AUX+12] == 1) |
| 168 |
{ |
| 169 |
cbuf[0] = '.'; /* so look for default */ |
| 170 |
if (type == 1) /* image type */ |
| 171 |
(void) SCKGETC("MID$TYPES",1,8,&k,cbuf+1); |
| 172 |
else if (type == 3) /* table type */ |
| 173 |
(void) SCKGETC("MID$TYPES",9,8,&k,cbuf+1); |
| 174 |
else /* should be fit file */ |
| 175 |
(void) strcpy(cbuf+1,"fit"); |
| 176 |
typeptr = cbuf; |
| 177 |
|
| 178 |
} |
| 179 |
else |
| 180 |
typeptr = FSY_DEFPNTR[type-1]; |
| 181 |
} |
| 182 |
|
| 183 |
if (ioff < 0) |
| 184 |
{ |
| 185 |
(void) strcpy(&outname[idx],&inname[2]); |
| 186 |
if (koff == (-1)) (void) strcat(outname,typeptr); |
| 187 |
} |
| 188 |
else |
| 189 |
{ |
| 190 |
if (ioff > 0) (void) memcpy(&outname[idx],&inname[2],(size_t)ioff); |
| 191 |
if (koff == (-1)) /* e.g. &a[2.3:30.3] */ |
| 192 |
{ |
| 193 |
(void) strcpy(&outname[idx+ioff],typeptr); |
| 194 |
(void) strcat(outname,&inname[2+ioff]); |
| 195 |
} |
| 196 |
else |
| 197 |
(void) strcpy(&outname[idx+ioff],&inname[2+ioff]); |
| 198 |
} |
| 199 |
|
| 200 |
return (1); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
/* check for #xyz or #xyz_catalog */ |
| 205 |
|
| 206 |
if (*inname == '#') |
| 207 |
|
| 208 |
{ |
| 209 |
n = CGN_INDEXC(inname,'_'); |
| 210 |
if (n > 0) |
| 211 |
{ |
| 212 |
k = n - 1; |
| 213 |
(void) memcpy(cbuf,&inname[1],(size_t)k); |
| 214 |
cbuf[k] = '\0'; |
| 215 |
(void) strcpy(catfile,&inname[n+1]); |
| 216 |
} |
| 217 |
else |
| 218 |
{ /* catalog enabled? If so, copy name from keyw. CATALOG */ |
| 219 |
mm = OFF_CATINF + type; |
| 220 |
if (KIWORDS[mm+4] == 0) /* CATALINF(type+5) = catal_enabled_flag */ |
| 221 |
return (0); /* Not enabled, do nothing */ |
| 222 |
|
| 223 |
n = KIWORDS[mm-1]; /* get offset of this catalog from CATALINF */ |
| 224 |
mm = OFF_CATAL + (n - 1); |
| 225 |
k = KIWORDS[OFF_CATINF+10]; /* length of catalog file */ |
| 226 |
(void) memcpy(catfile,&KCWORDS[mm],(size_t)k); |
| 227 |
catfile[k] = '\0'; |
| 228 |
(void) strcpy(cbuf,&inname[1]); |
| 229 |
} |
| 230 |
|
| 231 |
isu = issub(cbuf); |
| 232 |
if (isu > 0) |
| 233 |
{ |
| 234 |
csav = cbuf[isu]; /* save that char. */ |
| 235 |
cbuf[isu] = '\0'; |
| 236 |
} |
| 237 |
if (CGN_CNVT(cbuf,1,1,&frmno,&roff,&doff) <= 0) return (0); |
| 238 |
|
| 239 |
status = SCCFND(catfile,frmno,outname); |
| 240 |
if (status != ERR_NORMAL) return (0);; |
| 241 |
|
| 242 |
if (isu > 0) |
| 243 |
{ |
| 244 |
cbuf[isu] = csav; |
| 245 |
(void) strcat(outname,&cbuf[isu]); /* append subframe sepcs */ |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
/* check for '*' */ |
| 251 |
|
| 252 |
else if (*inname == '*') |
| 253 |
{ |
| 254 |
cc = *(inname+1); |
| 255 |
if ((cc == ' ') || (cc == '\0')) |
| 256 |
(void) SCKGETC("IDIMEMC",1,60,&n,outname); /* should move to 100 ... */ |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
/* in all other cases use input name */ |
| 261 |
|
| 262 |
else /* nothing to do */ |
| 263 |
return (0); |
| 264 |
|
| 265 |
return (1); /* Yes, we did replace the file name */ |
| 266 |
} |
| 267 |
/* |
| 268 |
|
| 269 |
*/ |
| 270 |
|
| 271 |
int CGN_FRAME(inname,type,outname,optio) |
| 272 |
|
| 273 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 274 |
|
| 275 |
.ALGORITHM |
| 276 |
use CGN_singleframe |
| 277 |
if not replaced, copy input name over to output name |
| 278 |
.RETURNS |
| 279 |
1 if replacement, 0 if same frame returned |
| 280 |
|
| 281 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
| 282 |
|
| 283 |
char *inname /* IN: input name */; |
| 284 |
int type /* IN: type of frame, |
| 285 |
1 = image, 3 = table, 4 = FIT file */; |
| 286 |
char *outname /* OUT: new name */; |
| 287 |
int optio /* IN: = 0, single frame; = 1, whole string */; |
| 288 |
|
| 289 |
{ |
| 290 |
int klen, kk, mm, iav, status; |
| 291 |
register int nj, nr; |
| 292 |
|
| 293 |
char twork[256], tframe[80], xframe[80]; |
| 294 |
register char cr; |
| 295 |
static char limc[] = {'+','-','/','*','(',')','.',',','\0'}; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
if (optio != 1) |
| 301 |
{ |
| 302 |
cr = *inname; |
| 303 |
if ((cr == 'm') || (cr == 'M')) |
| 304 |
{ /* check for "middumm..." */ |
| 305 |
(void) CGN_UPCOPY(twork,inname+1,8); |
| 306 |
if (strncmp(twork,"IDDUMM",6) == 0) |
| 307 |
{ |
| 308 |
cr = twork[6]; |
| 309 |
if ((cr != '\0') && (cr != '.') && (cr != ' ')) |
| 310 |
{ |
| 311 |
twork[0] = '&'; /* we're sure of replacement */ |
| 312 |
(void) strcpy(twork+1,inname+7); |
| 313 |
status = CGN_singleframe(twork,type,outname); |
| 314 |
if (status == 0) (void) strcpy(outname,inname); |
| 315 |
return(status); |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
status = CGN_singleframe(inname,type,outname); |
| 321 |
if (status == 0) (void) strcpy(outname,inname); |
| 322 |
return(status); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
/* we have to handle a whole string */ |
| 327 |
|
| 328 |
mm = CGN_INDEXC(inname,'#'); |
| 329 |
if (mm >= 0) |
| 330 |
{ |
| 331 |
klen = CGN_COPY(twork,inname); |
| 332 |
kk = mm; |
| 333 |
|
| 334 |
while (klen > 0) /* always true ... */ |
| 335 |
{ |
| 336 |
tframe[0] = '#'; |
| 337 |
iav = 1; |
| 338 |
for (nr=mm+1; nr<klen; nr++) |
| 339 |
{ |
| 340 |
for (nj=0; nj<9; nj++) |
| 341 |
{ |
| 342 |
if (inname[nr] == limc[nj]) |
| 343 |
{ |
| 344 |
tframe[iav] = '\0'; |
| 345 |
goto clean_it; |
| 346 |
} |
| 347 |
} |
| 348 |
tframe[iav++] = inname[nr]; |
| 349 |
} |
| 350 |
|
| 351 |
clean_it: /* due to `#abc' => xframe is set */ |
| 352 |
(void) CGN_singleframe(tframe,type,xframe); |
| 353 |
(void) strcpy(&twork[kk],xframe); |
| 354 |
iav = (int) strlen(twork); |
| 355 |
(void) strcpy(&twork[iav],&inname[nr]); |
| 356 |
|
| 357 |
mm = CGN_INDEXC(&inname[nr],'#'); |
| 358 |
if (mm < 0) |
| 359 |
{ |
| 360 |
(void) strcpy(outname,twork); |
| 361 |
return(1); /* all done */ |
| 362 |
} |
| 363 |
|
| 364 |
mm += nr; |
| 365 |
kk = CGN_INDEXC(twork,'#'); /* '#' must also be in `twork' */ |
| 366 |
} |
| 367 |
return (1); |
| 368 |
} |
| 369 |
|
| 370 |
else |
| 371 |
{ |
| 372 |
(void) strcpy(outname,inname); |
| 373 |
return (0); |
| 374 |
} |
| 375 |
} |
| 376 |
/* |
| 377 |
|
| 378 |
*/ |
| 379 |
|
| 380 |
/* ++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 381 |
|
| 382 |
.LANGUAGE: C |
| 383 |
|
| 384 |
.AUTHOR: K.Banse |
| 385 |
|
| 386 |
.IDENTIFICATION |
| 387 |
function CGN_DSCUPD version 1.00 880127 |
| 388 |
K. Banse ESO - Garching |
| 389 |
1.10 901107 1.20 910617 2.00 920225 |
| 390 |
|
| 391 |
.KEYWORDS |
| 392 |
descriptors, copy |
| 393 |
|
| 394 |
.PURPOSE |
| 395 |
a) copy all non-standard descriptors from one frame to another |
| 396 |
b) append line(2) to descr. HISTORY |
| 397 |
if parameter HISTRY != ' ' we use HISTRY |
| 398 |
else we read key HISTORY + append all Pi (MIDAS parameters) |
| 399 |
|
| 400 |
.ALGORITHM |
| 401 |
a) use STDCOP with option 4 or 5 to do the job |
| 402 |
b) if HISTORY_UPDATE == 1, we do not write HISTORY line(s) |
| 403 |
|
| 404 |
.INPUT |
| 405 |
use as stat = CGN_DSCUPD(inno,outno,history) |
| 406 |
|
| 407 |
inno: I*4 input frame no. |
| 408 |
outno: I*4 result frame no. |
| 409 |
history: char. exp. current addition for descr. HISTORY |
| 410 |
if blank, get HISTORY from keyword HISTORY |
| 411 |
and keys P1, P2, ... |
| 412 |
outpt par: |
| 413 |
.RETURNS |
| 414 |
always status = 0 for backward compatibility reasons |
| 415 |
|
| 416 |
.VERSIONS |
| 417 |
1.00 adapted from DSCUPDX (version 1.30) |
| 418 |
1.10 get contents of Pi explicitely |
| 419 |
2.00 converted to C |
| 420 |
-------------------------------------------------------------------- */ |
| 421 |
|
| 422 |
int CGN_DSCUPD(inno,outno,history) |
| 423 |
|
| 424 |
int inno,outno; |
| 425 |
|
| 426 |
char *history; |
| 427 |
|
| 428 |
{ |
| 429 |
int flag, iav, ec, el, ed, lzero, lone, nl; |
| 430 |
int unit, stat, n, klen, mm; |
| 431 |
int bytelm, noelm; |
| 432 |
register int nr; |
| 433 |
|
| 434 |
char cbuf[100], work[164]; |
| 435 |
static char *par[] = {"P1","P2","P3","P4","P5","P6","P7","P8"}; |
| 436 |
|
| 437 |
|
| 438 |
n = 0; |
| 439 |
|
| 440 |
|
| 441 |
/* if frames not equal, we copy first all or just HISTORY descr. */ |
| 442 |
|
| 443 |
if (inno != outno) |
| 444 |
{ |
| 445 |
stat = SCKRDI("AUX_MODE",4,1,&iav,&flag,&unit,&nl); |
| 446 |
MID_DRESET(); |
| 447 |
if (flag == 1) |
| 448 |
stat = SCDCOP(inno,outno,5," "); |
| 449 |
else |
| 450 |
stat = SCDCOP(inno,outno,4,"HISTORY"); |
| 451 |
MID_DRESET(); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
/* if descriptor "HISTORY_UPDA" exists and is = 0, |
| 456 |
leave descr. HISTORY untouched */ |
| 457 |
|
| 458 |
SCECNT("GET",&ec,&el,&ed); |
| 459 |
lone = 1; lzero = 0; |
| 460 |
SCECNT("PUT",&lone,&lzero,&lzero); |
| 461 |
stat = SCDRDI(outno,"HISTORY_UPDA",1,1,&iav,&flag,&unit,&nl); |
| 462 |
SCECNT("PUT",&ec,&el,&ed); |
| 463 |
|
| 464 |
if ((stat == ERR_NORMAL) && (flag == 0)) return (0); |
| 465 |
|
| 466 |
/* o.k. we want to update the HISTORY descr: |
| 467 |
look for existing descr. HISTORY, and check if multiple of 80 chars. */ |
| 468 |
|
| 469 |
(void) SCDFND(outno,"HISTORY",work,&noelm,&bytelm); |
| 470 |
if (work[0] == 'C') |
| 471 |
{ |
| 472 |
n = noelm*bytelm; /* curent size */ |
| 473 |
mm = n / 80; |
| 474 |
iav = mm * 80; |
| 475 |
if (iav < n) /* force multiple of 80 chars. */ |
| 476 |
{ |
| 477 |
klen = ((mm+1) * 80) - n; |
| 478 |
memset((void *)work,32,(size_t)klen); |
| 479 |
(void) SCDWRC(outno,"HISTORY",1,work,-1,klen,&unit); |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
/* history str. is either given as parameter (history != ' ') |
| 485 |
or taken from keyword HISTORY and Pi */ |
| 486 |
|
| 487 |
if (*history != ' ') |
| 488 |
{ |
| 489 |
klen = (int) strlen(history); |
| 490 |
if (klen > 160) klen = 160; /* max. 160 chars. */ |
| 491 |
(void) strncpy(work,history,klen); |
| 492 |
} |
| 493 |
else |
| 494 |
{ |
| 495 |
(void) SCKGETC("HISTORY",1,80,&klen,work); |
| 496 |
(void) SCKRDI("PCOUNT",1,1,&iav,&mm,&unit,&nl); |
| 497 |
for (nr=0; nr<mm; nr++) /* append all parameters */ |
| 498 |
{ |
| 499 |
(void) SCKGETC(par[nr],1,80,&iav,cbuf); |
| 500 |
work[klen++] = ' '; |
| 501 |
n = klen; /* `n' follows `klen' */ |
| 502 |
klen += iav; |
| 503 |
if (klen < 160) |
| 504 |
(void) strcpy(&work[n],cbuf); |
| 505 |
else |
| 506 |
{ |
| 507 |
klen -= iav; |
| 508 |
break; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
if (klen < 1) |
| 514 |
return klen; /* tell that there is a problem... */ |
| 515 |
else if (klen <= 80) |
| 516 |
n = 80 - klen; |
| 517 |
else if (klen <= 160) |
| 518 |
n = 160 - klen; |
| 519 |
if (n > 0) |
| 520 |
{ |
| 521 |
memset(&work[klen],32,(size_t)n); |
| 522 |
klen += n; /* -> 80 or 160 */ |
| 523 |
} |
| 524 |
|
| 525 |
work[klen] = '\0'; |
| 526 |
(void) SCDWRC(outno,"HISTORY",1,work,-1,klen,&unit); |
| 527 |
|
| 528 |
return (0); |
| 529 |
} |
| 530 |
/* |
| 531 |
|
| 532 |
*/ |
| 533 |
|
| 534 |
void CGN_LOGNAM(infile,outfile,maxout) |
| 535 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 536 |
.PURPOSE |
| 537 |
this function translates a filename of the form LOGNAM:file |
| 538 |
to the physical name |
| 539 |
.RETURN nothing |
| 540 |
------------------------------------------------------------ */ |
| 541 |
|
| 542 |
char *infile; /* IN: input file name */ |
| 543 |
char *outfile; /* OUT: result file name */ |
| 544 |
int maxout; /* IN: max length of outfile */ |
| 545 |
|
| 546 |
|
| 547 |
{ |
| 548 |
int m, k, jcolo; |
| 549 |
register int nr; |
| 550 |
|
| 551 |
char tempa[128]; |
| 552 |
register char cc; |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
/* we're looking for something like: "SYMBOL:name" */ |
| 558 |
|
| 559 |
jcolo = -1; |
| 560 |
for (nr=0; ; nr++) |
| 561 |
{ |
| 562 |
cc = infile[nr]; |
| 563 |
if ((cc == ' ') || (cc == '\0')) /* also cut off trailing blanks */ |
| 564 |
break; |
| 565 |
else if (cc == ':') /* the ":" is fixed char. for all systems...*/ |
| 566 |
{ |
| 567 |
jcolo = nr + 1; |
| 568 |
if (nr > 127) /* we screwed up buf `tempa'!!! */ |
| 569 |
{ |
| 570 |
outfile[0] = '\0'; /* caller will find out soon ... */ |
| 571 |
return; |
| 572 |
} |
| 573 |
tempa[nr] = '\0'; |
| 574 |
goto symbol_found; /* SYMBOL: -> max 60 chars */ |
| 575 |
} |
| 576 |
|
| 577 |
tempa[nr] = cc; /* already copy to work buffer */ |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
/* no "SYMBOL:" found */ |
| 582 |
|
| 583 |
if (nr >= maxout) nr= maxout - 1; /* avoid buffer overflow */ |
| 584 |
(void) memcpy(outfile,infile,(size_t)nr); |
| 585 |
outfile[nr] = '\0'; |
| 586 |
return; |
| 587 |
|
| 588 |
|
| 589 |
symbol_found: |
| 590 |
m = OSY_TRANSLA(tempa,outfile,maxout); |
| 591 |
if (m >= maxout) /* new name too long */ |
| 592 |
{ |
| 593 |
m = maxout - 1; /* so keep orig name */ |
| 594 |
(void) memcpy(outfile,infile,(size_t)m); |
| 595 |
outfile[m] = '\0'; |
| 596 |
return; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
if (m < 1) /* No translation. */ |
| 601 |
{ |
| 602 |
maxout --; |
| 603 |
for (nr=0; nr <maxout ; nr++) |
| 604 |
{ /* Copy input file including `:' */ |
| 605 |
cc = infile[nr]; |
| 606 |
if ((cc == ' ') || (cc == '\0')) |
| 607 |
{ /* cut off trailing blanks */ |
| 608 |
outfile[nr] = '\0'; |
| 609 |
return; |
| 610 |
} |
| 611 |
outfile[nr] = cc; |
| 612 |
} |
| 613 |
outfile[maxout] = '\0'; |
| 614 |
return; /* we're already done... */ |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
/* OK, we have a translated symbol and m < maxout, so paste all together */ |
| 619 |
|
| 620 |
#if vms |
| 621 |
if (outfile[m-1] != FSY_DISKEND) |
| 622 |
{ |
| 623 |
if (outfile[m-1] != FSY_DIREND) outfile[m++] = FSY_DIREND; |
| 624 |
} |
| 625 |
#else |
| 626 |
|
| 627 |
if (outfile[m-1] != FSY_DIREND) outfile[m++] = FSY_DIREND; |
| 628 |
#endif |
| 629 |
|
| 630 |
|
| 631 |
for (nr=jcolo; ; nr++) |
| 632 |
{ |
| 633 |
cc = infile[nr]; |
| 634 |
if ((cc == ' ') || (cc == '\0')) break; |
| 635 |
} |
| 636 |
|
| 637 |
k = nr - jcolo + 1; |
| 638 |
nr = maxout - m; |
| 639 |
if (k > nr) /* final result doesn't fit! */ |
| 640 |
{ |
| 641 |
nr --; |
| 642 |
(void) memcpy(&outfile[m],&infile[jcolo],(size_t)nr); |
| 643 |
outfile[maxout-1] = '\0'; |
| 644 |
} |
| 645 |
else /* no blanks before end of string */ |
| 646 |
(void) memcpy(&outfile[m],&infile[jcolo],(size_t)k); |
| 647 |
|
| 648 |
} |
| 649 |
|