~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to monit/newcom.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
/*===========================================================================
 
2
  Copyright (C) 1995-2011 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: midas@eso.org
 
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
/*++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.LANGUAGE    C
 
30
.IDENTIFICATION     main module NEWCOM
 
31
.AUTHOR   Klaus Banse
 
32
.KEYWORDS MIDAS command initialization
 
33
.ENVIRONMENT  UNIX / VMS
 
34
.PURPOSE
 
35
  read file MID_MONIT:NEWCOM. or NEWTOM. and store its contents into binary file
 
36
  MID_MONIT:NEWCOM.DAT or NEWTOM.DAT
 
37
.ALGORITHM
 
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
 
41
 
 
42
  e.g. CLEAR/ZOOM @ CLEAZOOM
 
43
       FFT/FREQ   @/BACK FFT F
 
44
 
 
45
.RETURNS  nothing
 
46
 
 
47
.VERSION  [1.20] 870714: use osa-routines for ASCII file treatment
 
48
 
 
49
 110427         last modif
 
50
-------------------------------------------------------------------*/
 
51
 
 
52
#include <stdlib.h>
 
53
#include <stdio.h>
 
54
#include <string.h>
 
55
 
 
56
#include <fileexts.h>
 
57
#include <proto_monit.h>
 
58
#include <stlibvars.h>
 
59
#include <commdef.h>
 
60
#include <osparms.h>
 
61
 
 
62
void DEFCOM();
 
63
 
 
64
 
 
65
 
 
66
 
 
67
int main()
 
68
 
 
69
{
 
70
char    record[132], cline[82], atom[82], comnd[6], qualif[4], defqual [4];
 
71
char    file[80], *cpntr, *tmpntr;
 
72
        
 
73
int   n, nn, mm, status, first_time, allover;
 
74
int   latom, atom_len, reclen, start;
 
75
int   totsize, comsize, qualsize, linesize;
 
76
int   fp, gp;
 
77
 
 
78
 
 
79
/*  initialize   */
 
80
 
 
81
COMN.CMAX = MAXSTA_COM;
 
82
COMN.QMAX = 4 * MAXSTA_COM;
 
83
COMN.ENDLIN = 24 * MAXSTA_COM;
 
84
COMN.FIRST = 0;
 
85
COMN.INUSEC = -1;
 
86
COMN.INUSEQ = -1;
 
87
 
 
88
 
 
89
/*  allocate memory for command, qualifier structures + command lines */
 
90
 
 
91
totsize = sizeof(struct COMND_ALL);
 
92
 
 
93
comsize = (sizeof(struct COMND_STRUCT)) * (COMN.CMAX+1);   /* for security */
 
94
tmpntr = (char *) malloc((size_t)comsize);
 
95
if (tmpntr == NULL)
 
96
   {
 
97
   (void) printf("could not allocate %d bytes for COMND_STRUCT\n",comsize);
 
98
   ospexit(0);
 
99
   }
 
100
 
 
101
memset((void *)tmpntr,32,(size_t)comsize);              /* initialize it */
 
102
COMN.CP = (struct COMND_STRUCT *) tmpntr;
 
103
 
 
104
qualsize = (sizeof(struct QUALIF_STRUCT)) * (COMN.QMAX+1);   /* for security */
 
105
tmpntr = (char *) malloc((size_t)qualsize);
 
106
if (tmpntr == NULL)
 
107
   {
 
108
   (void) printf("could not allocate %d bytes for QUALIF_STRUCT\n",qualsize);
 
109
   ospexit(0);
 
110
   }
 
111
 
 
112
memset((void *)tmpntr,32,(size_t)qualsize);             /* initialize it */
 
113
COMN.QP = (struct QUALIF_STRUCT *) tmpntr;
 
114
 
 
115
linesize = COMN.ENDLIN+4;
 
116
COMN.LINE = (char *) malloc((size_t)linesize);
 
117
if (COMN.LINE == NULL)
 
118
   {
 
119
   (void) printf("could not allocate %d bytes for COMLINE\n",linesize);
 
120
   ospexit(0);
 
121
   }
 
122
else
 
123
   memset((void *)COMN.LINE,32,(size_t)linesize);       /* initialize it */
 
124
 
 
125
allover = 0;
 
126
first_time = 0;
 
127
memset((void *)defqual,32,(size_t)4);   /* use blank as default qualifier  */
 
128
 
 
129
 
 
130
/*  get file name of ASCII command list  */
 
131
 
 
132
#if vms
 
133
strcpy(record,"newcomVMS.in");          /* here we only have @ instead of @% */
 
134
#else
 
135
strcpy(record,"newcom.in");
 
136
#endif
 
137
CGN_LOGNAM(record,file,72);
 
138
 
 
139
fp = osaopen(file,READ);
 
140
if (fp == -1)
 
141
   {
 
142
   (void) printf("problems opening the initial commandfile %s ...\n",file);
 
143
   ospexit(0);
 
144
   }
 
145
        
 
146
 
 
147
/*  create new binary output file newcom.bin + open it  */
 
148
 
 
149
nn = strlen(file);
 
150
#if vms
 
151
(void) strcpy(&file[nn-6],".bin");              /* newcomVMS.in => newcom.bin */
 
152
#else
 
153
(void) strcpy(&file[nn-3],".bin");              /* newcom.in => newcom.bin */
 
154
#endif
 
155
 
 
156
gp = osdopen(file,WRITE);
 
157
if (gp == -1)
 
158
   {
 
159
   (void) printf("problems in creating binary command file...\n");
 
160
   ospexit(0);
 
161
   }
 
162
        
 
163
atom_len = 30;
 
164
 
 
165
 
 
166
/*  loop + read input records in rather free format  */
 
167
 
 
168
read_loop:
 
169
reclen = osaread(fp,record,130);
 
170
if (reclen == 0)
 
171
   goto read_loop;
 
172
else if (reclen < 0) 
 
173
   goto close_it;
 
174
 
 
175
 
 
176
/*  cut out comments  */
 
177
 
 
178
mm = CGN_INDEXC(record,'!');
 
179
if (mm == 0)                            /* skip comment lines */
 
180
   goto read_loop;
 
181
else if ((mm > 0) && (mm < reclen))
 
182
   {
 
183
   record[mm] = '\0';
 
184
   reclen = mm;
 
185
   }
 
186
 
 
187
 
 
188
/* convert tabs to blanks +  skip blank records  */
 
189
 
 
190
CGN_REPLA(record,mm,'\t',' ');
 
191
if ( (n = CGN_SKIP(record,' ','f',&mm) ) == 0 ) goto read_loop;
 
192
        
 
193
start = 0;
 
194
latom = CGN_EXTRSS(record,reclen,' ',&start,atom,atom_len);
 
195
atom[latom] = '\0';                             /* force end of string  */
 
196
 
 
197
 
 
198
/* separate command and (optional) qualifier  */
 
199
 
 
200
EXTRACOM(atom,comnd,qualif);
 
201
        
 
202
 
 
203
/* extract actual command line  (without leading blanks)  */
 
204
 
 
205
cline[0] = '\0';
 
206
for (n=latom+1;n<reclen; n++)
 
207
   {
 
208
   if (record[n] != ' ')
 
209
      {
 
210
      (void) strcpy(cline,&record[n]);
 
211
      break;
 
212
      }
 
213
   } 
 
214
        
 
215
 
 
216
/* test, if primitive command or not  */
 
217
 
 
218
if (cline[0] == '\0')
 
219
   status = ADDCOM(comnd,qualif,-2,1,cline);        /* add primitive command  */
 
220
 
 
221
else
 
222
   {
 
223
   if (first_time == 0)
 
224
      {
 
225
      first_time = 1;
 
226
      COMN.LPRIMC = COMN.INUSEC;
 
227
      COMN.LPRIMQ = COMN.INUSEQ;
 
228
      }
 
229
   status = ADDCOM(comnd,qualif,-1,1,cline);            /* add fixed command  */
 
230
   }
 
231
 
 
232
 
 
233
if (status != 0)                                /* everything o.k. ?  */
 
234
   {
 
235
   allover = 1;
 
236
   (void) printf("command %6.6s/%4.4s gave the following problem:\n",
 
237
                 comnd,qualif);
 
238
   if (status == 5)
 
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");
 
246
   else
 
247
      (void) printf("unknown error code ...\n");
 
248
   goto close_it;
 
249
   }
 
250
        
 
251
goto read_loop;
 
252
 
 
253
        
 
254
close_it:
 
255
(void) osaclose(fp);                            /*  close newcom.in */
 
256
COMN.FDEL = COMN.FIRST;
 
257
 
 
258
 
 
259
/*  now copy tables to binary file newcom.bin  */
 
260
 
 
261
if (allover != 0)
 
262
   {
 
263
   (void) printf("Something wrong - check again the command input file ! \n");
 
264
   ospexit(1);
 
265
   }
 
266
 
 
267
/* put default qualifier IMAG to all commands which have 
 
268
   a qualifier IMAG or ...                                    */
 
269
 
 
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 */
 
274
 
 
275
 
 
276
/*  open ASCII file newcom.out for listing of commands/qualifiers  */
 
277
 
 
278
nn = strlen(file);
 
279
(void) strcpy(&file[nn-3],"out");               /* newcom.bin => newcom.out */
 
280
fp = osaopen(file,1);
 
281
if (fp == -1)
 
282
   {
 
283
   (void) printf("problems in opening the ASCII output file...\n");
 
284
   ospexit(0);
 
285
   }
 
286
 
 
287
(void) SHOWCOM(fp,"-D","  ");                   /*  diagnostic display  */
 
288
(void) osaclose(fp);
 
289
 
 
290
 
 
291
/*  write the structures into binary output file  */
 
292
 
 
293
cpntr = (char *) &COMN;
 
294
status = osdwrite(gp,cpntr,(unsigned int)totsize);
 
295
if (status < totsize) goto osd_error;
 
296
 
 
297
cpntr = (char *) COMN.CP;
 
298
status = osdwrite(gp,cpntr,(unsigned int)comsize);
 
299
if (status < comsize) goto osd_error;
 
300
 
 
301
cpntr = (char *) COMN.QP;
 
302
status = osdwrite(gp,cpntr,(unsigned int)qualsize);
 
303
if (status < qualsize) goto osd_error;
 
304
 
 
305
status = osdwrite(gp,COMN.LINE,(unsigned int)linesize);
 
306
if (status < linesize) goto osd_error;
 
307
 
 
308
(void) osdclose(gp);
 
309
(void) printf("Commands successfully stored in newcom.bin. \n");
 
310
ospexit(0);
 
311
 
 
312
osd_error:
 
313
(void) printf("problems in writing into binary command file ...\n");
 
314
ospexit(1);
 
315
 
 
316
return 0;                       /* for gcc -Wall ... */
 
317
}
 
318