Debian Codegraph @

libsrc/st/scdc.c

raw
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 /*++++++++++++++++++++++++++ SC interface module SCDC +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCDC.C
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, descriptors
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds SCDDEL, SCDCOP, SCDGETC, SCDFND, SCDINF, YSCDINF
36
37 .VERSION [1.00] 920211: pulled out from scd.c
38 080521 last modif
39
40 ----------------------------------------------------------------------------*/
41
42 #include <fileexts.h>
43
44 #include <stdlib.h>
45 #include <string.h>
46
47
48 /*
49
50 */
51
52 int SCDDEL(imno,descr)
53
54 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55 .PURPOSE
56 delete a descriptor
57 .ALGORITHM
58 the descriptor directory is scanned for the specified name and if found,
59 that name is marked as deleted
60 If descriptor = ' ', reinitialize descriptor area.
61 .RETURNS
62 return status ( 0 = o.k. )
63 -----------------------------------------------------------------------*/
64
65 int imno; /* IN : no. of data frame */
66 char *descr; /* IN : descriptor name */
67
68 {
69 int status, bytelem, noelem, dblock, dindx, dunit, dsclen;
70
71 char dtype[4];
72 char realdescr[52], help[72];
73
74 struct FCB_STRUCT *fcbp;
75
76 struct FCT_STRUCT *fctpntr;
77
78
79
80
81 if ( (imno < 0) || (imno >= FCT.MAXENT) )
82 {
83 status = ERR_INPINV;
84 goto end_of_it;
85 }
86
87 fctpntr = FCT.ENTRIES + imno;
88 fcbp = fctpntr->FZP;
89
90
91 /* if descriptor name is '*', reinitialize descriptor area */
92
93 if (*descr == '*')
94 status = MID_INITDS(fcbp,fctpntr->IOCHAN); /* do the rest via MID_INITDS */
95
96 else
97 { /* otherwise delete single descriptor */
98 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
99 dtype[0] = ' ';
100 status = MID_YDSCDIR(imno,'F',realdescr,dtype,
101 &bytelem,&noelem,&dunit,&dblock,&dindx,help);
102 if (status == ERR_NORMAL)
103 status = MID_YDSCDIR(imno,'D',realdescr,dtype,
104 &bytelem,&noelem,&dunit,&dblock,&dindx,help);
105 }
106
107 fctpntr->KAUX[2] = 1; /* set descriptor-modified flag */
108
109
110 end_of_it: /* test for info/warnings again */
111 if (status != ERR_NORMAL)
112 MID_E2(4,imno,descr,status,1);
113
114 return (status);
115 }
116
117 /*
118
119 */
120
121 int SCDCOP(from,to,mask,dsc)
122
123 /*++++++++++++++++++++++++++++++++++++++++++++++++++
124 .PURPOSE
125 Copy descriptors from one frame to another
126 .ALGORITHM
127 Depending on 'mask' the relevant descriptors are read from
128 the source frame + written to the destination frame.
129 .REMARKS
130 mask for copying: = 1 , copy all descriptors
131 = 2 , copy only standard desc.
132 = 3 , copy all but standard descriptors
133 = 4 , copy descriptor specified by DSClist
134 = 5 , copy all but extended list of standard descriptors
135 .RETURNS
136 return status ( 0 = o.k. )
137 --------------------------------------------------*/
138
139 int from; /* IN: no. of source frame */
140 int to; /* IN: no. of destination frame */
141 int mask; /* IN: copy_mask */
142 char *dsc; /* IN: name of descr. to copy (if mask = 4) */
143
144 {
145 struct FCT_STRUCT *fctpntri, *fctpntro;
146
147
148
149 fctpntri = FCT.ENTRIES + from;
150 if (fctpntri->LINK[0] >= 2) /* use father frame */
151 {
152 from = fctpntri->LINK[1];
153 fctpntri = FCT.ENTRIES + from;
154 }
155
156 fctpntro = FCT.ENTRIES + to;
157 if (fctpntro->LINK[0] >= 2) /* use father frame */
158 {
159 to = fctpntro->LINK[1];
160 fctpntro = FCT.ENTRIES + to;
161 }
162
163 if (from != to)
164 {
165 if (fctpntro->PROT == 2)
166 return ERR_FILPRO; /* destination is write protected */
167
168 return YSCDCOP(from,to,mask,dsc);
169 }
170 return ERR_NORMAL; /* nothing to be done ... */
171 }
172
173 /*
174
175 */
176
177 int SCDGETC(imno,descr,felem,maxvals,actvals,values)
178
179 /*++++++++++++++++++++++++++++++++++++++++++++++++++
180 .PURPOSE
181 get data from character descriptor and terminate with Null (no trailing blanks)
182 .ALGORITHM
183 use SCDRDC
184 .RETURNS
185 return status ( 0 = o.k. )
186 --------------------------------------------------*/
187
188 int imno /* IN : no. of data frame */;
189 char *descr /* IN : descriptor name */;
190 int felem /* IN : position of 1st element to be accessed */;
191 int maxvals /* IN : max. no. of characters to be returned */;
192 int *actvals /* OUT: actual no. of characters returned */;
193 char *values /* OUT: array for descriptor data */;
194
195 {
196 int status, mynull, myuni;
197 register int nr;
198
199 register char mychar;
200
201
202
203 mynull = -1;
204 status = SCDRDC(imno,descr,1,felem,maxvals,actvals,values,&myuni,&mynull);
205
206
207
208 if (status == ERR_NORMAL)
209 { /* get rid of trailing blanks/nulls */
210 maxvals = (*actvals) - 1;
211 for (nr=maxvals; nr>=0; nr--)
212 {
213 mychar = values[nr];
214 if ((mychar != ' ') && (mychar != '\0'))
215 {
216 *actvals = ++nr;
217 values[nr] = '\0'; /* add null terminator */
218 return (status);
219 }
220 }
221 }
222
223 values[0] = '\0';
224 *actvals = 0;
225 return (status);
226 }
227
228 /*
229
230 */
231
232 int SCDFND(imno,descr,type,noelem,bytelem)
233
234 /*++++++++++++++++++++++++++++++++++++++++++++++++++
235 .PURPOSE
236 provide info about descriptor 'descr'
237 .ALGORITHM
238 use MID_xDSCDIR to find descr. + related info
239 .RETURNS
240 return status ( 0 = o.k. )
241 --------------------------------------------------*/
242
243 int imno /* IN: no. of data frame */;
244 char *descr /* IN: descriptor name */;
245 char *type /* OUT: type of descr - I, R, C, D or ' ' on output */;
246 int *noelem /* OUT: no. of elements */;
247 int *bytelem /* OUT: no. of bytes per element */;
248
249 {
250 int dblock, dindx, snoel, sbytel;
251 int dsclen, dunit, status, e_c, e_l;
252
253 char realdescr[52];
254 char help[72];
255
256 struct FCB_STRUCT *fcbp;
257
258 struct FCT_STRUCT *fctpntr;
259
260
261
262
263 /* disable error abort */
264
265 e_c = ERRO_CONT; e_l = ERRO_LOG; ERRO_CONT = 1; ERRO_LOG = 0;
266
267
268 /* check imno + type */
269
270 if ( (imno < 0) || (imno >= FCT.MAXENT) )
271 {
272 status = ERR_INPINV;
273 goto end_of_it;
274 }
275
276 fctpntr = FCT.ENTRIES + imno;
277 if (fctpntr->LINK[0] >= 2) /* use father frame */
278 {
279 imno = fctpntr->LINK[1];
280 fctpntr = FCT.ENTRIES + imno;
281 }
282
283 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
284
285 *type = ' ';
286 fcbp = fctpntr->FZP;
287
288 status = MID_YDSCDIR(imno,'F',realdescr,type,&sbytel,&snoel,&dunit,
289 &dblock,&dindx,help);
290
291 if (status != ERR_DSCNPR)
292 {
293 *noelem = snoel;
294 *bytelem = sbytel;
295 }
296
297 ERRO_CONT = e_c; ERRO_LOG = e_l; /* reset error flags */
298 return ERR_NORMAL;
299
300 end_of_it:
301 ERRO_CONT = e_c; ERRO_LOG = e_l; /* reset error flags */
302 MID_E2(7,imno,"SCDFND: ",status,1);
303 return status;
304 }
305
306 /*
307
308 */
309
310 int SCDINF(imno,npos,fno,buf,lbuf,numbuf)
311
312 /*++++++++++++++++++++++++++++++++++++++++++++++++++
313 .PURPOSE
314 provide info about descriptor at position 'npos'
315 .ALGORITHM
316 go through the descriptor directory and provide the desired info
317 .RETURNS
318 return status ( 0 = o.k. )
319 --------------------------------------------------*/
320
321 int imno /* IN : no. of data frame */;
322 int npos /* IN : position of descriptor, beginning with 1
323 use 0 for the descr. directory itself */;
324 int fno /* IN : specify desired info,
325 1 = NAME, 2 = TYPE, 3 = SIZE
326 4 = NAME,TYPE separated by a comma in `buf'
327 and SIZE in `numbuf'
328 5 = NAME,TYPE separated by a comma in `buf'
329 and SIZE,BYTELEM in `numbuf'
330 98 = return total no. of descriptors (except Help-d.)
331 99 = return total no. of descriptors */;
332 char *buf /* IN : buffer for character descriptor info */;
333 int lbuf /* IN : max. length of buffer above */;
334 int *numbuf /* IN : return buffer for numerical data */;
335
336 {
337 int status, chanl;
338 int snpos;
339
340 struct FCT_STRUCT *fctpntr;
341
342 struct FCB_STRUCT *fcbp;
343
344
345
346
347 if ( (imno < 0) || (imno >= FCT.MAXENT) )
348 {
349 status= ERR_INPINV; /* wrong argument `npos' */
350 goto end_of_it;
351 }
352
353 snpos = npos + 1; /* real index is at NPOS+1 because of directory */
354 if ( (snpos < 1) || (fno < 0) )
355 {
356 status= ERR_INPINV; /* wrong argument `npos' */
357 goto end_of_it;
358 }
359
360 status = ERR_NORMAL;
361
362 fctpntr = FCT.ENTRIES + imno;
363 if (fctpntr->LINK[0] >= 2) /* use father frame */
364 {
365 imno = fctpntr->LINK[1];
366 fctpntr = FCT.ENTRIES + imno;
367 }
368
369 chanl = fctpntr->IOCHAN;
370 fcbp = fctpntr->FZP;
371
372 return YSCDINF(chanl,imno,snpos,fno,buf,lbuf,numbuf);
373
374 end_of_it:
375 MID_E2(7,imno,"SCDINF: ",status,1);
376 return status;
377 }
378
379 /*
380
381 */
382
383 int XSCDINF(chanl,imno,snpos,fno,buf,lbuf,numbuf)
384
385 int chanl;
386 int imno;
387 int snpos;
388 int fno;
389 char *buf;
390 int lbuf;
391 int *numbuf;
392
393 {
394 struct FCT_STRUCT *fctpntr;
395
396 struct FCB_STRUCT *fcbp;
397
398
399 fctpntr = FCT.ENTRIES + imno;
400 if (fctpntr->LINK[0] >= 2) /* use father frame */
401 {
402 imno = fctpntr->LINK[1];
403 fctpntr = FCT.ENTRIES + imno;
404 }
405
406 chanl = fctpntr->IOCHAN;
407 fcbp = fctpntr->FZP;
408
409 return YSCDINF(chanl,imno,snpos,fno,buf,lbuf,numbuf);
410
411 }
412
413 /*
414
415 */
416
417 int YSCDINF(chanl,imno,snpos,fno,buf,lbuf,numbuf)
418 /*++++++++++++++++++++++++++++++++++++++++++++++++++
419 .PURPOSE
420 provide info about descriptor at position 'npos'
421 .ALGORITHM
422 go through the descriptor directory and provide the desired info
423 .RETURNS
424 return always 0 (checks already done in SCDINF)
425 --------------------------------------------------*/
426
427 int chanl; /* IN: I/O chanl of frame */
428 int imno /* IN: no. of data frame */;
429 int snpos /* IN: incremented position of descriptor */;
430 int fno /* IN: specify desired info,
431 1 = NAME, 2 = TYPE, 3 = SIZE
432 4 = NAME,TYPE separated by a comma in `buf'
433 5 = NAME,TYPE separated by a comma in `buf'
434 and SIZE,BYTELEM in `numbuf'
435 99 = return total no. of descriptors */;
436 char *buf /* IN: buffer for character descriptor info */;
437 int lbuf /* IN: max. length of buffer above */;
438 int *numbuf /* IN: return buffer for numerical data */;
439
440 {
441 int ext, dirfirst, dirused, dirsize, dirlen, diroff, totext;
442 int nullo;
443 int mm, npos;
444 register int nr, direntry;
445
446
447 char *dscpntr;
448 register char *cpt;
449
450 struct FCT_STRUCT *fctpntr;
451
452 struct FCB_STRUCT *fcbp;
453
454 static int mapdscdir = -1;
455 static char *dscdir;
456
457
458
459
460 fctpntr = FCT.ENTRIES + imno;
461 fcbp = fctpntr->FZP;
462
463 dirused = fcbp->DFILLED;
464 dirsize = fcbp->DSIZE;
465 totext = dirsize/fcbp->DIREXT; /* total no. of extensions for directory */
466 dscpntr = (char *) &YDSCDIR_ENTRY;
467 direntry = fcbp->DIRENTRY;
468
469 ext = 1;
470 npos = 0;
471 diroff = 0;
472
473
474 pos_loop:
475 dirfirst = diroff + 1;
476 dirlen = dirused - diroff;
477 if (fcbp->DIREXT < dirlen)
478 dirlen = fcbp->DIREXT; /* read max. 2500/6000 chars. */
479
480
481 if (mapdscdir < 0) /* allocate working buffer */
482 { /* for descr. directory */
483 dscdir = (char *)malloc((size_t)fcbp->DIREXT); /* 2500/6000 bytes */
484 mapdscdir = 1;
485 }
486
487
488 if (fno > 90)
489 {
490 nullo = -1;
491 (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,dirfirst,dirlen,dscdir,&nullo);
492 cpt = dscdir;
493
494 nr = 0;
495 while (nr < dirlen)
496 {
497 if (*cpt != '\0') npos ++; /* test if entry is used */
498 cpt += direntry; nr += direntry;
499 }
500
501
502 /* maybe we need another segment (next extension) of descr. directory */
503
504 if (ext < totext)
505 {
506 ext ++ ; /* prepare reading of next directory segment */
507 diroff += fcbp->DIREXT;
508 if (diroff < dirused) goto pos_loop; /* and loop more... */
509 }
510
511 *numbuf = --npos; /* remove descriptor directory itself */
512 return (ERR_NORMAL);
513 }
514
515
516 /* here for all the other functions */
517
518 nullo = -1;
519 (void) MID_RDSCRC(chanl,fcbp->PTRLDB,0,dirfirst,dirlen,dscdir,&nullo);
520 cpt = dscdir;
521
522 nr = 0;
523 while (nr < dirlen)
524 {
525 if (*cpt != '\0') /* test if entry is used */
526 {
527 if (++npos == snpos) /* always increment `npos' */
528 {
529 (void) memcpy(dscpntr,cpt,(size_t)fcbp->DIRENTRY);
530 goto descr_found;
531 }
532 }
533 cpt += direntry; nr += direntry;
534 }
535
536
537 /* we need another segment (next extension) of descr. directory */
538
539 if (ext < totext)
540 {
541 ext ++ ; /* prepare reading of next directory segment */
542 diroff += fcbp->DIREXT;
543 if (diroff < dirused) goto pos_loop; /* and loop more... */
544 }
545
546 memset((void *)buf,32,(size_t)lbuf); /* npos too large */
547 *numbuf = 0;
548 return (ERR_NORMAL);
549
550
551 descr_found:
552 switch(fno)
553 {
554 case 1:
555 mm = YDSC_PNTR->NAMELEN;
556 if (mm > lbuf) mm = lbuf;
557 (void) memcpy(buf,YDSC_PNTR->NAMESTR,(size_t)mm);
558 break;
559
560 case 2:
561 (void) MID_TYPINFO(YDSC_PNTR->TYPE,YDSC_PNTR->BYTELEM,buf,lbuf);
562 break;
563
564 case 3:
565 if (snpos == 1)
566 *numbuf = dirused;
567 else
568 *numbuf = YDSC_PNTR->NOELEM;
569 break;
570
571 case 4:
572 mm = YDSC_PNTR->NAMELEN;
573 if (mm >= lbuf)
574 (void) memcpy(buf,YDSC_PNTR->NAMESTR,(size_t)lbuf);
575 else
576 {
577 (void) memcpy(buf,YDSC_PNTR->NAMESTR,(size_t)(mm+1));
578 lbuf -= mm;
579 if (lbuf > 1)
580 {
581 buf[mm] = ',';
582 lbuf --;
583 (void) MID_TYPINFO(YDSC_PNTR->TYPE,YDSC_PNTR->BYTELEM,
584 buf+mm+1,lbuf);
585 }
586 }
587 break;
588
589 default: /* case 5 */
590 mm = YDSC_PNTR->NAMELEN;
591 if (mm >= lbuf)
592 (void) memcpy(buf,YDSC_PNTR->NAMESTR,(size_t)lbuf);
593 else
594 {
595 (void) memcpy(buf,YDSC_PNTR->NAMESTR,(size_t)(mm+1));
596 lbuf -= mm;
597 if (lbuf > 1)
598 {
599 buf[mm] = ',';
600 lbuf --;
601 (void) MID_TYPINFO(YDSC_PNTR->TYPE,YDSC_PNTR->BYTELEM,
602 buf+mm+1,lbuf);
603 }
604
605 if (snpos == 1)
606 *numbuf++ = dirused;
607 else
608 *numbuf++ = YDSC_PNTR->NOELEM;
609 *numbuf = YDSC_PNTR->BYTELEM;
610 }
611 }
612
613 return (ERR_NORMAL);
614 }