1
/* @(#)aglvms.c 19.1 (ES0-DMD) 02/25/03 13:53:06 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/* @(#)aglvms.c 19.1 (OAA-ASTRONET) 02/25/03 13:53:06 */
31
* HEADER : aglvms.c - Vers 3.6.000 - Dec 1991 - L. Fini, OAA
35
#define MIN(x,y) ((x)<(y))?(x):(y)
37
/*****************************************************************************/
38
/* Environment dependent features are resolved in this file */
44
/*****************************************************************************/
45
/* AGL_trns (Internal AGL use) */
48
/* This VMS version uses VMS logical names translation */
50
/* Translates logical names until no further translation is possible */
51
/* NOTE: Equivalence name is also forced to lower case and colon is stripped */
54
void AGL_trns(inpname,maxlng,trnslnam)
55
char *inpname; /* Input name */
56
int maxlng; /* Max output string length */
57
char *trnslnam; /* Output equivalence name */
59
struct dsc$descriptor trnam,wrk; /* Define CHARACTER descriptors */
61
extern long LIB$SYS_TRNLOG();
68
trnam.dsc$w_length=maxlng-1;
69
trnam.dsc$a_pointer=trnslnam;
71
wrk.dsc$a_pointer=auxbuf;
73
retlng=MIN(strlen(inpname),AUXLNG);
74
for(cnt=0; cnt<=retlng; cnt++) auxbuf[cnt] = TOUPPER(inpname[cnt]);
75
wrk.dsc$w_length=retlng;
77
do /* Translation loop */
79
retstat=LIB$SYS_TRNLOG(&wrk,&retlng,&trnam,NULL,NULL,NULL);
80
cnt=0; src=trnslnam; dst=auxbuf;
83
if(isgraph(*src)) { *dst++ = TOLOWER(*src); cnt++; }
88
while(retstat==SS$_NORMAL);
91
while( *src == '_' ) { cnt--; src++; } /* strip off leading underscores */
92
strncpy(trnslnam,src,cnt);
94
*(src)='\0'; src--; /* null terminate */
96
if(*src == ':') *src = '\0'; /* Drop the terminating colon */
103
struct dsc$descriptor wrk; /* Define CHARACTER descriptors */
104
extern long LIB$SPAWN();
108
wrk.dsc$a_pointer=cmd;
109
wrk.dsc$w_length = strlen(cmd);
110
retstat = LIB$SPAWN(&wrk,NULL,NULL,NULL,NULL,
111
NULL,NULL,NULL,NULL,NULL,NULL,NULL);
112
if(retstat != SS$_NORMAL)
118
/* Terminal I/O emulator for VAX/VMS */
120
/* This module is required due to the fact that VAX-C runtime library */
121
/* doesn't support ioctl. It provides fopen,fclose,fread,fwrite emulated by */
122
/* VMS System Service calls, in PASSTRHOUGH mode so that it works as usual */
123
/* Unix calls in RAWMODE. Ioctl is substituted by a dummy entry */
126
#define IO$M_NOECHO 0x0040
127
#define IO$M_NOFILTR 0x0200
128
#define IO$_READVBLK 0x31
129
#define IO$_TTYREADALL 0x3A
130
#define IO$_WRITEVBLK 0x30
131
#define IO$M_PURGE 0x0800
132
#define IO$M_NOFORMAT 0x0100
136
#define RFUNCT (IO$_READVBLK | IO$M_NOECHO | IO$_TTYREADALL)
137
#define RFLUSH (IO$_READVBLK | IO$M_NOECHO | IO$_TTYREADALL | IO$M_PURGE)
138
#define WFUNCT (IO$_WRITEVBLK | IO$M_NOFORMAT )
140
static short chan[10]= /* This is an internal buffer for I/O. */
141
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
143
static int rfunct=RFLUSH; /* Read function. with flush the first time */
145
/***************************************************************************/
148
/* This routine is used to open an i/o channel to a terminal. It must take */
149
/* into account system specific details. E.g. VMS systems will always open */
150
/* an I/O channel to be used for subsequent SYS$QIO calls, whereas Unix */
151
/* systems will probably simply issue a standard fopen call. */
153
FILE *AGL_fopen (name)
155
char * name; /* Device name (if it is tt, unix and MS-DOS */
156
/* systems will simply return stdout). VMS */
157
/* systems will open SYS$OUTPUT */
160
static char *sysout = "SYS$OUTPUT";
163
struct dsc$descriptor_s descr;
168
{ /* Search a free slot */
169
if(chan[i]==(-1)) break;
171
if(i==10) return(NULL);
173
if(strcmp(name,"tt")==0)
175
descr.dsc$w_length = strlen (sysout);
176
descr.dsc$a_pointer = sysout;
180
descr.dsc$w_length = strlen (name);
181
descr.dsc$a_pointer = name;
183
descr.dsc$b_class = DSC$K_CLASS_S; /* string class */
184
descr.dsc$b_dtype = DSC$K_DTYPE_T; /* ascii type */
186
status = SYS$ASSIGN (&descr,&chan+i,0,0); /* Assign the channel */
188
if(status != SS$NORMAL)
194
return ((FILE *)(chan+i));
198
/*****************************************************************************/
200
/*****************************************************************************/
202
int AGL_fread (buffer,size,nbytes,dev)
204
char *buffer; /* Output buffer */
205
int size; /* Dummy argument. Must be equal to 1 */
206
int nbytes; /* Number of characters to read */
207
FILE *dev; /* pointer to VMS I/O channel */
213
intchan = (short*)dev;
215
status = SYS$QIOW(1,*intchan,rfunct,&iosb, 0,0,buffer,nbytes,0,0,0,0);
217
rfunct = RFUNCT; /* Avoid flushing next time you read */
219
if (status != SS$NORMAL) return (ERROR);
221
return (nbytes); /* WARNING!! IT IS NOT POSSIBLE TO RETURN THE
222
NUMBER OF BYTES ACTUALLY READ */
225
/*****************************************************************************/
227
/*****************************************************************************/
229
int AGL_fwrite (buffer,size,nbytes,dev)
230
char *buffer; /* Input buffer */
231
int size; /* Dummy argument. Must be equal to 1 */
232
int nbytes; /* Number of characters to write */
233
FILE *dev; /* pointer to VMS I/O channel */
239
intchan = (short*)dev;
241
status = SYS$QIOW(1,*intchan,funct,&iosb,0,0,buffer,nbytes,0,0,0,0);
243
if (status != SS$NORMAL) return (ERROR);
250
/*****************************************************************************/
252
/*****************************************************************************/
255
FILE *dev; /* FILE pointer (obtained via AGL_fopen) */
261
intchan = (short*)dev;
266
status = SYS$DASSGN (*intchan);
268
if (status != SS$NORMAL) return (-1);
276
/***************************************************************************/
277
/* AGL_setraw AGL_reset */
279
/* These are dummy routines. The terminal I/O is performed in RAW mode */
280
/* anyway on VMS systems */
282
int AGL_setraw (filept)
287
void AGL_reset(filept)
292
int AGL_fflush (filept)
295
rfunct=RFLUSH; /* Preset flushing on next read */