1
/*===========================================================================
2
Copyright (C) 1995-2011 European Southern Observatory (ESO)
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.
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.
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,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++
30
.IDENTIFICATION main module NEWCOM
32
.KEYWORDS MIDAS command initialization
33
.ENVIRONMENT UNIX / VMS
35
read file MID_MONIT:NEWCOM. or NEWTOM. and store its contents into binary file
36
MID_MONIT:NEWCOM.DAT or NEWTOM.DAT
38
read command, qualifier and corresponding command line from NEWCOM.
39
and store them into the relevant data structures, which are then
40
written into binaray file NEWCOM.DAT for fast access
42
e.g. CLEAR/ZOOM @ CLEAZOOM
47
.VERSION [1.20] 870714: use osa-routines for ASCII file treatment
50
-------------------------------------------------------------------*/
57
#include <proto_monit.h>
58
#include <stlibvars.h>
70
char record[132], cline[82], atom[82], comnd[6], qualif[4], defqual [4];
71
char file[80], *cpntr, *tmpntr;
73
int n, nn, mm, status, first_time, allover;
74
int latom, atom_len, reclen, start;
75
int totsize, comsize, qualsize, linesize;
81
COMN.CMAX = MAXSTA_COM;
82
COMN.QMAX = 4 * MAXSTA_COM;
83
COMN.ENDLIN = 24 * MAXSTA_COM;
89
/* allocate memory for command, qualifier structures + command lines */
91
totsize = sizeof(struct COMND_ALL);
93
comsize = (sizeof(struct COMND_STRUCT)) * (COMN.CMAX+1); /* for security */
94
tmpntr = (char *) malloc((size_t)comsize);
97
(void) printf("could not allocate %d bytes for COMND_STRUCT\n",comsize);
101
memset((void *)tmpntr,32,(size_t)comsize); /* initialize it */
102
COMN.CP = (struct COMND_STRUCT *) tmpntr;
104
qualsize = (sizeof(struct QUALIF_STRUCT)) * (COMN.QMAX+1); /* for security */
105
tmpntr = (char *) malloc((size_t)qualsize);
108
(void) printf("could not allocate %d bytes for QUALIF_STRUCT\n",qualsize);
112
memset((void *)tmpntr,32,(size_t)qualsize); /* initialize it */
113
COMN.QP = (struct QUALIF_STRUCT *) tmpntr;
115
linesize = COMN.ENDLIN+4;
116
COMN.LINE = (char *) malloc((size_t)linesize);
117
if (COMN.LINE == NULL)
119
(void) printf("could not allocate %d bytes for COMLINE\n",linesize);
123
memset((void *)COMN.LINE,32,(size_t)linesize); /* initialize it */
127
memset((void *)defqual,32,(size_t)4); /* use blank as default qualifier */
130
/* get file name of ASCII command list */
133
strcpy(record,"newcomVMS.in"); /* here we only have @ instead of @% */
135
strcpy(record,"newcom.in");
137
CGN_LOGNAM(record,file,72);
139
fp = osaopen(file,READ);
142
(void) printf("problems opening the initial commandfile %s ...\n",file);
147
/* create new binary output file newcom.bin + open it */
151
(void) strcpy(&file[nn-6],".bin"); /* newcomVMS.in => newcom.bin */
153
(void) strcpy(&file[nn-3],".bin"); /* newcom.in => newcom.bin */
156
gp = osdopen(file,WRITE);
159
(void) printf("problems in creating binary command file...\n");
166
/* loop + read input records in rather free format */
169
reclen = osaread(fp,record,130);
176
/* cut out comments */
178
mm = CGN_INDEXC(record,'!');
179
if (mm == 0) /* skip comment lines */
181
else if ((mm > 0) && (mm < reclen))
188
/* convert tabs to blanks + skip blank records */
190
CGN_REPLA(record,mm,'\t',' ');
191
if ( (n = CGN_SKIP(record,' ','f',&mm) ) == 0 ) goto read_loop;
194
latom = CGN_EXTRSS(record,reclen,' ',&start,atom,atom_len);
195
atom[latom] = '\0'; /* force end of string */
198
/* separate command and (optional) qualifier */
200
EXTRACOM(atom,comnd,qualif);
203
/* extract actual command line (without leading blanks) */
206
for (n=latom+1;n<reclen; n++)
208
if (record[n] != ' ')
210
(void) strcpy(cline,&record[n]);
216
/* test, if primitive command or not */
218
if (cline[0] == '\0')
219
status = ADDCOM(comnd,qualif,-2,1,cline); /* add primitive command */
226
COMN.LPRIMC = COMN.INUSEC;
227
COMN.LPRIMQ = COMN.INUSEQ;
229
status = ADDCOM(comnd,qualif,-1,1,cline); /* add fixed command */
233
if (status != 0) /* everything o.k. ? */
236
(void) printf("command %6.6s/%4.4s gave the following problem:\n",
239
(void) printf("no command line ...\n");
240
else if (status == 6)
241
(void) printf("ambiguous command or qualifier ...\n");
242
else if (status == 10)
243
(void) printf("overflow in data structure ...\n");
244
else if (status == 42)
245
(void) printf("overflow in command_line buffer ...\n");
247
(void) printf("unknown error code ...\n");
255
(void) osaclose(fp); /* close newcom.in */
256
COMN.FDEL = COMN.FIRST;
259
/* now copy tables to binary file newcom.bin */
263
(void) printf("Something wrong - check again the command input file ! \n");
267
/* put default qualifier IMAG to all commands which have
268
a qualifier IMAG or ... */
270
DEFCOM("*","IMAG"); /* force default to IMAG */
271
DEFCOM("PLOT","ROW "); /* for PLOT, OVERPLOT set it to ROW */
272
DEFCOM("OVERPLOT","ROW ");
273
DEFCOM("SET","CONT"); /* for SET use CONTEXT as default */
276
/* open ASCII file newcom.out for listing of commands/qualifiers */
279
(void) strcpy(&file[nn-3],"out"); /* newcom.bin => newcom.out */
280
fp = osaopen(file,1);
283
(void) printf("problems in opening the ASCII output file...\n");
287
(void) SHOWCOM(fp,"-D"," "); /* diagnostic display */
291
/* write the structures into binary output file */
293
cpntr = (char *) &COMN;
294
status = osdwrite(gp,cpntr,(unsigned int)totsize);
295
if (status < totsize) goto osd_error;
297
cpntr = (char *) COMN.CP;
298
status = osdwrite(gp,cpntr,(unsigned int)comsize);
299
if (status < comsize) goto osd_error;
301
cpntr = (char *) COMN.QP;
302
status = osdwrite(gp,cpntr,(unsigned int)qualsize);
303
if (status < qualsize) goto osd_error;
305
status = osdwrite(gp,COMN.LINE,(unsigned int)linesize);
306
if (status < linesize) goto osd_error;
309
(void) printf("Commands successfully stored in newcom.bin. \n");
313
(void) printf("problems in writing into binary command file ...\n");
316
return 0; /* for gcc -Wall ... */