Debian Codegraph @

libsrc/st/osyvmsb.c

raw
1 /*===========================================================================
2 Copyright (C) 1995 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 000703 last modif
28
29 ===========================================================================*/
30
31 #include <midas_def.h>
32 #include <secdef.h>
33 #include <ssdef.h>
34 #include <descrip.h>
35 #include <iodef.h>
36
37
38 #define BIT_0 0x1
39
40
41 static int status, n, ii, mm;
42
43 static short int iosb[4];
44
45 static char msg[260];
46
47 /*
48
49 */
50
51 void OSY_MESSAGE(statsys,errmsg)
52
53 /* ++++++++++++++++++++++++++++++++++++++++++++++++++
54
55 .IDENTIFICATION
56 function OSY_MESSAGE C-version 1.00 870804
57 K. Banse ESO - Garching
58
59 .KEYWORDS
60 system messages
61
62 .PURPOSE
63 display system message for given status
64
65 .ALGORITHM
66 use system service SYS$GETMSG
67 !!! this code is operating system dependant !!!
68
69 .INPUT/OUTPUT
70 use as OSY_MESSAGE(status,errmsg)
71
72 input par:
73 statsys: int status code
74 errmsg: char * buffer for message (should be >= 80)
75
76 -------------------------------------------------- */
77
78 int statsys;
79 char *errmsg;
80
81 {
82 int msglen;
83
84 static int rms_errcnt = 9;
85 static int rms_erros[] = {0x1c0dc, 0x1c04a,
86 0x1c00a, 0x184c4,
87 0x184cc, 0x1828a,
88 0x18292, 0x18544,
89 0x1829a};
90 static char *rms_errmsg[] = {"Cannot close file.","Directory not found.",
91 "File creation error.","Bad device (type).",
92 "Error in directory name.","File is locked.",
93 "File is not found.","Device full.",
94 "Not matching file protection."};
95
96
97 char byte_array[4];
98
99 struct dsc$descriptor_s name_descr1;
100
101
102 /* set up the VAX-11 descriptor structure */
103
104 name_descr1.dsc$b_class = DSC$K_CLASS_S;
105 name_descr1.dsc$b_dtype = DSC$K_DTYPE_T;
106
107
108 /* now execute the system service */
109
110 msglen = 0;
111 ii = SYS$GETMSG(statsys,&msglen,&name_descr1,15,byte_array);
112
113
114 if (ii & BIT_0)
115 {
116 (void) strncpy(errmsg,name_descr1.dsc$a_pointer,msglen);
117 errmsg[msglen] = '\0';
118 }
119 else
120 {
121 for (n=0; n<rms_errcnt; n++)
122 {
123 if (statsys == rms_erros[n])
124 {
125 (void)strcpy(errmsg,rms_errmsg[n]);
126 return;
127 }
128 }
129
130 (void)strcpy(errmsg,"SYS$GETMSG: no message returned...");
131 }
132
133 }
134
135 /*
136
137 */
138
139 int OSY_SLEEP(millisec,flag)
140
141 unsigned int millisec;
142 int flag; /* not used, just for compatibility with Unix */
143
144 {
145 int time[2];
146
147
148
149 time[1] = -1;
150 time[0] = - (10000 * millisec);
151
152 mm = SYS$SETIMR(1,time,0,0);
153
154 if (mm & BIT_0)
155 mm = SYS$WAITFR(1);
156
157 return mm;
158 }
159
160 /*
161
162 */
163
164 int OSY_SPAWN(mailbox_name,process,outterm,pid,astmodule,astparm)
165
166 /*
167 C
168 C++++++++++++++++++++++++++++++++++++++++++++++++++
169 C
170 C.IDENTIFICATION
171 C OSY_SPAWN C-version 1.00 870723
172 C K. Banse ESO - Garching
173 C
174 C.KEYWORDS
175 C process creation
176 C
177 C.PURPOSE
178 C create a subprocess
179 C
180 C.ALGORITHM
181 C use LIB$SPAWN to do the job
182 C A mailbox is used for input to the subprocess, output goes to stdio
183 C
184 C.INPUT/OUTPUT
185 C use as OSY_SPAWN(mailbox_name,process,outterm,pid,astmodule,astparm)
186 C
187 C input par:
188 C mailbox_name: char. string physical name of mailbox
189 C process: char. string name of subprocess
190 C outterm: char. string output stream
191 C astmodule: pointer pointer to astmodule (a function)
192 C astparm: int parameter to astmodule
193 C
194 C output par:
195 C pid: int process identification no.
196 C
197 C-------------------------------------------------------
198 C
199 */
200
201 int *pid, (* astmodule)(), *astparm;
202 char *mailbox_name, *process, *outterm;
203
204 {
205
206 struct dsc$descriptor_s name_descr1, name_descr2, name_descr3, name_descr4;
207
208 int zero;
209
210 static int icomst;
211
212 char buf1[5];
213
214
215 /* set up the VAX-11 descriptor structure for mailbox and process */
216
217 name_descr1.dsc$w_length = strlen(mailbox_name);
218 name_descr1.dsc$a_pointer = mailbox_name;
219 name_descr1.dsc$b_class = DSC$K_CLASS_S;
220 name_descr1.dsc$b_dtype = DSC$K_DTYPE_T;
221
222 name_descr2.dsc$w_length = strlen(process);
223 name_descr2.dsc$a_pointer = process;
224 name_descr2.dsc$b_class = DSC$K_CLASS_S;
225 name_descr2.dsc$b_dtype = DSC$K_DTYPE_T;
226
227 strcpy(buf1,"$! ");
228 name_descr3.dsc$w_length = strlen(buf1);
229 name_descr3.dsc$a_pointer = buf1;
230 name_descr3.dsc$b_class = DSC$K_CLASS_S;
231 name_descr3.dsc$b_dtype = DSC$K_DTYPE_T;
232
233 name_descr4.dsc$w_length = strlen(outterm);
234 name_descr4.dsc$a_pointer = outterm;
235 name_descr4.dsc$b_class = DSC$K_CLASS_S;
236 name_descr4.dsc$b_dtype = DSC$K_DTYPE_T;
237
238 /* now execute the system service */
239
240 mm = 1;
241 zero = 0;
242
243 status = LIB$SPAWN(&name_descr3,&name_descr1,&name_descr4,
244 &mm,&name_descr2,pid,&icomst,&zero,
245 astmodule,astparm);
246
247 if (status & BIT_0)
248 return ERR_NORMAL;
249 else
250 return (-1);
251 }
252
253 /*
254
255 */
256
257 int OSY_TIMER(t_action,time)
258
259 /*
260 C
261 C++++++++++++++++++++++++++++++++++++++++++++++++++
262 C
263 C.IDENTIFICATION
264 C OSY_TIMER C-version 1.00 880706
265 C K. Banse ESO - Garching
266 C
267 C.KEYWORDS
268 C CPU time
269 C
270 C.PURPOSE
271 C handle CPU timing
272 C
273 C.ALGORITHM
274 C use VAX/VMS library functions LIB$INIT_TIMER + LIB$STAT_TIMER
275 C !!! this code is operating system dependant !!!
276 C
277 C.INPUT/OUTPUT
278 C use as status = OSY_TIMER(ACTION,TIME)
279 C
280 C input par:
281 C t_action: character 'I' for initializing
282 C 'G' for getting the time
283 C output par:
284 C *time: float time in hundreds of seconds
285 C
286 C return value:
287 C status: int return status
288 C
289 C--------------------------------------------------
290 C
291 */
292
293 char t_action;
294 float *time;
295
296 {
297 int itime, two;
298
299
300
301 if (t_action == 'I')
302 status = LIB$INIT_TIMER();
303 else
304 {
305 two = 2;
306 status = LIB$STAT_TIMER(&two,&itime);
307 *time = (float) itime;
308 }
309
310 if ( status & BIT_0 )
311 status = ERR_NORMAL;
312 else
313 {
314 MID_ERROR("OSY","OSY_TIMER",status,0);
315 status = ERR_OPSSYS;
316 }
317
318 return status;
319 }
320 /*
321
322 */
323
324 int OSY_TRNLOG(name,vmsname,lvmsin,lvmsout)
325 /*
326 C
327 C++++++++++++++++++++++++++++++++++++++++++++++++++
328 C
329 C.IDENTIFICATION
330 C OSY_TRNLOG version 1.20 871102
331 C K. Banse ESO - Garching
332 C 1.30 900115 1.35 900213
333 C
334 C.KEYWORDS
335 C logical names
336 C
337 C.PURPOSE
338 C Do logical name translation.
339 C
340 C.ALGORITHM
341 C Logical name translation is performed via SYS$TRNLOG.
342 C Recursive translation is done by VMS now (from version 3.0 on...).
343 C
344 C.INPUT/OUTPUT
345 C use as OSY_TRNLOG(name,vmsname,lvmsin,lvmsout)
346 C
347 C input par:
348 C name: char. string logical file name (terminated by \0)
349 C lvmsin: int "real" length of vmsname
350 C
351 C output par:
352 C vmsname: char. exp. VMS file name
353 C lvmsout: int length of vmsname after translation
354 C
355 C.VERSION
356 C 1.30 put in conversion to upper case
357 C-------------------------------------------------------
358 C
359 */
360
361 int lvmsin, *lvmsout;
362 char *name, *vmsname;
363
364 {
365
366 struct dsc$descriptor_s name_descr1, name_descr2;
367
368 int byt1, byt2, c, cdif;
369
370
371 /* make sure we only have upper case stuff ... */
372
373 cdif = 'A' - 'a';
374 for (n=0; name[n] != '\0'; n++)
375 {
376 c = name[n];
377 if (c == ' ') break; /* no trailing blanks...! */
378 if ((c >= 'a') && (c <= 'z'))
379 msg[n] = c + cdif;
380 else
381 msg[n] = c;
382 }
383 msg[n] = '\0';
384
385
386 /* set up the VAX-11 descriptor structure */
387
388 name_descr1.dsc$w_length = n;
389 name_descr1.dsc$a_pointer = msg;
390 name_descr1.dsc$b_class = DSC$K_CLASS_S;
391 name_descr1.dsc$b_dtype = DSC$K_DTYPE_T;
392
393
394 name_descr2.dsc$w_length = lvmsin;
395 name_descr2.dsc$a_pointer = vmsname;
396 name_descr2.dsc$b_class = DSC$K_CLASS_S;
397 name_descr2.dsc$b_dtype = DSC$K_DTYPE_T;
398
399
400 /* now execute the system service */
401
402 *lvmsout = 0;
403 status = SYS$TRNLOG(&name_descr1,lvmsout,&name_descr2,&byt1,&byt2,0);
404
405 if (*lvmsout > lvmsin)
406 status = ERR_INPINV;
407 else
408 {
409 vmsname[*lvmsout] = '\0';
410 status = ERR_NORMAL;
411 }
412
413 return status;
414
415 }
416
417 /*
418
419 */
420
421 int OSY_WAKE()
422
423 {
424
425 status = SYS$WAKE(0,0);
426
427 if (status & BIT_0)
428 status = ERR_NORMAL;
429 else
430 {
431 MID_ERROR("'OSY","OSY_WAKE",status,1);
432 status = ERR_INPINV;
433 }
434
435 return status;
436
437 }
438
439 /*
440
441 */
442
443 int OSY_WVB(iochan,pbuf,nobyt,vbn)
444
445 /*
446 C
447 C++++++++++++++++++++++++++++++++++++++++++++++++++
448 C
449 C.IDENTIFICATION
450 C function OSY_WVB C-version 1.00 851124
451 C OSY_RVB 1.00 851124
452 C K. Banse ESO - Garching
453 C !! Modifed 900626 for elementary i/o mode (FO)
454 C source code on file OSYWVB.C
455 C
456 C.KEYWORDS
457 C virtual blocks on disk
458 C
459 C.PURPOSE
460 C write, read virtual blocks from disk
461 C
462 C.ALGORITHM
463 C use system service QIOW
464 C !!! this code is operating system dependant !!!
465 C
466 C.INPUT/OUTPUT
467 C use as status = OSY_WVB(iochan,pbuf,nobyt,vbn)
468 C OSY_RVB(iochan,pbuf,nobyt,vbn)
469 C
470 C input par:
471 C IOCHAN: int I/O channel assigned to disk file
472 C PBUF: char pointer pointer to buffer for disk transfer
473 C NOBYT: int no. of bytes to be transferred
474 C VBN: int starting virtual block for data transfer
475 C
476 C return value:
477 C STATUS: int return status
478 C
479 C--------------------------------------------------
480 C
481 */
482
483 int iochan,nobyt,vbn;
484 char *pbuf;
485
486 {
487 int bytes;
488
489 char block[512];
490
491
492
493
494 if (iochan < 0) /* memory frame */
495 {
496 int idx;
497
498 idx = -1 - iochan; /* recalculate VMEM index */
499 status = MID_VMIO(1,idx,pbuf,nobyt,vbn);
500 if (status == ERR_NORMAL) return status;
501
502 MID_ERROR("'OSY","OSY_WVB/QIOW",-1,0);
503 return ERR_INPINV;
504 }
505
506
507
508 /* Write only multiple of 512 bytes ... */
509
510 status = SS$_NORMAL;
511 bytes = nobyt & (~511);
512 if (bytes)
513 {
514 status = SYS$QIOW(0,iochan,IO$_WRITEVBLK,iosb,0,0,pbuf,bytes,vbn,0,0,0);
515 pbuf += bytes;
516 }
517
518
519 /* Write remaining part ... */
520
521 bytes = nobyt & (511);
522 if ((status & BIT_0) && bytes)
523 {
524 int i;
525
526 vbn += nobyt>>9;
527 status = SYS$QIOW(0,iochan,IO$_READVBLK,iosb,0,0,block,512,vbn,0,0,0);
528 for (i=0; i<bytes; i++)
529 block[i] = pbuf[i];
530
531 if (status & BIT_0)
532 status = SYS$QIOW(0,iochan,IO$_WRITEVBLK,iosb,0,0,block,512,vbn,0,0,0);
533 }
534
535 if (status & BIT_0)
536 status = ERR_NORMAL;
537 else
538 {
539 MID_ERROR("'OSY","OSY_WVB/QIOW",status,0);
540 status = ERR_INPINV;
541 }
542
543 return status;
544 }
545
546 /*
547
548 */
549
550 int OSY_RVB(iochan,pbuf,nobyt,vbn)
551 int iochan, nobyt, vbn;
552 char *pbuf; /* pointer to data buffer */
553
554 {
555 int even_bytes;
556
557
558
559 if (iochan < 0) /* memory frame */
560 {
561 int idx;
562
563 idx = -1 - iochan; /* recalculate VMEM index */
564 status = MID_VMIO(0,idx,pbuf,nobyt,vbn);
565 if (status == ERR_NORMAL) return status;
566
567 MID_ERROR("'OSY","OSY_RVB/QIOW",-1,0);
568 return ERR_INPINV;
569 }
570
571
572 /* make sure, we have an even no. of bytes */
573
574 even_bytes = nobyt + (nobyt % 2);
575 status = SYS$QIOW(0,iochan,IO$_READVBLK,iosb,0,0,pbuf,even_bytes,vbn,0,0,0);
576
577 if (status & BIT_0)
578 status = ERR_NORMAL;
579 else
580 {
581 MID_ERROR("OSY","OSY_RVB/QIOW",status,0);
582 status = ERR_INPINV;
583 }
584
585 return status;
586 }
587
588 /*
589
590 */
591
592 int OSY_WRCHAN(iochan,cbuf,len)
593
594 /*
595 C
596 C++++++++++++++++++++++++++++++++++++++++++++++++++
597 C
598 C.IDENTIFICATION
599 C function OSY_WRCHAN C-version 1.00 860616
600 C K. Banse ESO - Garching
601 C
602 C.KEYWORDS
603 C virtual blocks on disk
604 C
605 C.PURPOSE
606 C write, read virtual blocks from disk
607 C
608 C.ALGORITHM
609 C use system service QIOW
610 C !!! this code is operating system dependant !!!
611 C
612 C.INPUT/OUTPUT
613 C use as STATUS = OSY_WRCHAN(IOCHAN,CBUF,LEN)
614 C
615 C input par:
616 C IOCHAN: int I/O channel assigned to disk file
617 C CBUF: char pointer pointer to be written/read
618 C LEN: int length of char buffer CBUF points to
619 C
620 C for OSY_RDCHAN only:
621 C PROMPT: char pointer pointer to prompt buffer
622 C PLEN: int length of prompt buffer PROMPT points to
623 C if = 0, no prompting required
624 C output par:
625 C COUNT: int no. of values read (OSY_RDCHAN only)
626 C
627 C return value:
628 C STATUS: int return status
629 C
630 C.VERSIONS
631 C--------------------------------------------------
632 C
633 */
634
635 int iochan, len;
636 char *cbuf;
637
638 {
639
640 status = SYS$QIOW(0,iochan,IO$_WRITEVBLK,iosb,0,0,cbuf,len,0,0,0,0);
641
642 if (status & BIT_0)
643 status = ERR_NORMAL;
644 else
645 {
646 MID_ERROR("'OSY","OSY_WRCHAN/QIOW",status,0);
647 status = ERR_INPINV;
648 }
649
650 return status;
651 }
652