~ubuntu-branches/ubuntu/wily/eso-midas/wily-proposed

« back to all changes in this revision

Viewing changes to libsrc/agl/aglvms.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)aglvms.c 19.1 (ES0-DMD) 02/25/03 13:53:06 */
 
2
/*===========================================================================
 
3
  Copyright (C) 1995 European Southern Observatory (ESO)
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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, 
 
18
  MA 02139, USA.
 
19
 
 
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 
 
26
                        GERMANY
 
27
===========================================================================*/
 
28
 
 
29
/* @(#)aglvms.c 19.1  (OAA-ASTRONET) 02/25/03 13:53:06   */
 
30
/*
 
31
 * HEADER : aglvms.c       - Vers 3.6.000  - Dec 1991 -  L. Fini, OAA
 
32
 */
 
33
 
 
34
 
 
35
#define MIN(x,y) ((x)<(y))?(x):(y)
 
36
 
 
37
/*****************************************************************************/
 
38
/* Environment dependent features are resolved in this file                  */
 
39
 
 
40
 
 
41
#define AUXLNG 257
 
42
#define SS$_NORMAL 1
 
43
 
 
44
/*****************************************************************************/
 
45
/*                       AGL_trns (Internal AGL use)                         */
 
46
/*                             VAX/VMS version                               */
 
47
 
 
48
/* This VMS version uses VMS logical names translation                       */
 
49
 
 
50
/* Translates logical names until no further translation is possible         */
 
51
/* NOTE: Equivalence name is also forced to lower case and colon is stripped */
 
52
/*       off                                                                 */
 
53
 
 
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         */
 
58
 {
 
59
  struct dsc$descriptor trnam,wrk;        /* Define CHARACTER descriptors    */
 
60
  char auxbuf[AUXLNG];
 
61
  extern long LIB$SYS_TRNLOG();
 
62
  long retstat;
 
63
  int cnt;
 
64
  short retlng;
 
65
  char *src, *dst;
 
66
 
 
67
  trnam.dsc$b_class=1;
 
68
  trnam.dsc$w_length=maxlng-1;
 
69
  trnam.dsc$a_pointer=trnslnam;
 
70
  wrk.dsc$b_class=1;
 
71
  wrk.dsc$a_pointer=auxbuf;
 
72
 
 
73
  retlng=MIN(strlen(inpname),AUXLNG);
 
74
  for(cnt=0; cnt<=retlng; cnt++) auxbuf[cnt] = TOUPPER(inpname[cnt]);
 
75
  wrk.dsc$w_length=retlng;
 
76
 
 
77
  do                                          /* Translation loop            */
 
78
   {
 
79
    retstat=LIB$SYS_TRNLOG(&wrk,&retlng,&trnam,NULL,NULL,NULL);
 
80
    cnt=0; src=trnslnam; dst=auxbuf;
 
81
    while(retlng--)
 
82
     {
 
83
      if(isgraph(*src)) { *dst++ = TOLOWER(*src); cnt++; }
 
84
      src++;
 
85
     }
 
86
    wrk.dsc$w_length=cnt;
 
87
   }
 
88
  while(retstat==SS$_NORMAL);
 
89
 
 
90
  src=auxbuf;
 
91
  while( *src == '_' ) { cnt--; src++; }    /* strip off leading underscores */
 
92
  strncpy(trnslnam,src,cnt);
 
93
  src = trnslnam+cnt;
 
94
  *(src)='\0'; src--;                       /* null terminate                */
 
95
 
 
96
  if(*src == ':') *src = '\0';              /* Drop the terminating colon */
 
97
 }
 
98
 
 
99
 
 
100
int AGL_spawn(cmd)
 
101
char *cmd;
 
102
{
 
103
struct dsc$descriptor wrk;            /* Define CHARACTER descriptors    */
 
104
extern long LIB$SPAWN();
 
105
long retstat;
 
106
 
 
107
wrk.dsc$b_class=1;
 
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) 
 
113
        return (-1);
 
114
return 0;
 
115
}
 
116
 
 
117
 
 
118
/*  Terminal I/O emulator for VAX/VMS                                        */
 
119
 
 
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             */
 
124
 
 
125
 
 
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
 
133
#define SS$NORMAL       1
 
134
#define ERROR           (-1)
 
135
 
 
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 )
 
139
 
 
140
static short chan[10]=     /* This is an internal buffer for I/O.          */
 
141
                      { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
 
142
 
 
143
static int rfunct=RFLUSH;      /* Read function. with flush the first time */
 
144
 
 
145
/***************************************************************************/
 
146
/*                               AGL_fopen                                  */
 
147
 
 
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.               */
 
152
 
 
153
FILE *AGL_fopen (name)
 
154
 
 
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               */
 
158
{
 
159
 int status; 
 
160
 static char *sysout = "SYS$OUTPUT";
 
161
  long  SYS$ASSIGN();
 
162
 
 
163
 struct dsc$descriptor_s descr;
 
164
 char *device;
 
165
 int i;
 
166
 
 
167
 for(i=0;i<10;i++)
 
168
  {                           /* Search a free slot    */
 
169
   if(chan[i]==(-1)) break;
 
170
  }
 
171
 if(i==10) return(NULL);
 
172
 
 
173
 if(strcmp(name,"tt")==0)
 
174
  {
 
175
   descr.dsc$w_length = strlen (sysout);
 
176
   descr.dsc$a_pointer = sysout;
 
177
  }
 
178
 else
 
179
  {
 
180
   descr.dsc$w_length = strlen (name);
 
181
   descr.dsc$a_pointer = name;
 
182
  }
 
183
 descr.dsc$b_class = DSC$K_CLASS_S;           /* string class                */
 
184
 descr.dsc$b_dtype = DSC$K_DTYPE_T;           /* ascii type                  */
 
185
 
 
186
 status = SYS$ASSIGN (&descr,&chan+i,0,0);    /* Assign the channel          */
 
187
 
 
188
 if(status != SS$NORMAL)
 
189
  {
 
190
   chan[i]=(-1);
 
191
   return (NULL);
 
192
  }
 
193
 
 
194
 return ((FILE *)(chan+i));
 
195
}
 
196
 
 
197
 
 
198
/*****************************************************************************/
 
199
/*                               AGL_fread                                    */
 
200
/*****************************************************************************/
 
201
 
 
202
int AGL_fread (buffer,size,nbytes,dev) 
 
203
 
 
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                 */
 
208
{
 
209
 double iosb;
 
210
 int status;
 
211
 short *intchan;
 
212
 
 
213
 intchan = (short*)dev;
 
214
 
 
215
 status = SYS$QIOW(1,*intchan,rfunct,&iosb, 0,0,buffer,nbytes,0,0,0,0);
 
216
 
 
217
 rfunct = RFUNCT;                  /* Avoid flushing next time you read      */
 
218
 
 
219
 if (status != SS$NORMAL) return (ERROR);
 
220
 
 
221
 return (nbytes);           /* WARNING!! IT IS NOT POSSIBLE  TO RETURN THE 
 
222
                                           NUMBER OF BYTES ACTUALLY READ     */
 
223
}
 
224
 
 
225
/*****************************************************************************/
 
226
/*                               AGL_fwrite                                   */
 
227
/*****************************************************************************/
 
228
 
 
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                 */
 
234
{
 
235
 double iosb;
 
236
 int status,funct;
 
237
 short *intchan;
 
238
 
 
239
 intchan = (short*)dev;
 
240
 funct = WFUNCT;
 
241
 status = SYS$QIOW(1,*intchan,funct,&iosb,0,0,buffer,nbytes,0,0,0,0);
 
242
 
 
243
 if (status != SS$NORMAL) return (ERROR);
 
244
 
 
245
 return (nbytes); 
 
246
}
 
247
 
 
248
 
 
249
 
 
250
/*****************************************************************************/
 
251
/*                               AGL_fclose                                   */
 
252
/*****************************************************************************/
 
253
 
 
254
int AGL_fclose (dev)
 
255
FILE *dev;                      /*  FILE pointer (obtained via AGL_fopen)    */
 
256
{
 
257
int status;
 
258
short *intchan;
 
259
long  SYS$DASSGN();
 
260
 
 
261
intchan = (short*)dev;
 
262
 
 
263
if(*intchan==(-1)) 
 
264
        return(-1);
 
265
 
 
266
status = SYS$DASSGN (*intchan);
 
267
 
 
268
if (status != SS$NORMAL) return (-1);
 
269
 
 
270
*intchan=(-1);
 
271
return (0);
 
272
}
 
273
 
 
274
 
 
275
 
 
276
/***************************************************************************/
 
277
/*                      AGL_setraw  AGL_reset                                */
 
278
 
 
279
/* These are dummy routines. The terminal I/O is performed in RAW mode     */
 
280
/* anyway on VMS systems                                                   */
 
281
 
 
282
int AGL_setraw (filept)
 
283
 FILE * filept;
 
284
 {
 
285
 }
 
286
 
 
287
void AGL_reset(filept)
 
288
 FILE * filept;
 
289
  {
 
290
  }
 
291
 
 
292
int AGL_fflush (filept)
 
293
 FILE * filept;
 
294
 {
 
295
  rfunct=RFLUSH;               /* Preset flushing on next read             */
 
296
 }
 
297