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

« back to all changes in this revision

Viewing changes to monit/helper.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-2009 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 HELPER
 
31
.AUTHOR           K. Banse                        ESO - Garching
 
32
.ENVIRONMENT      VMS + UNIX
 
33
.KEYWORDS         help facility
 
34
.PURPOSE
 
35
  display help information
 
36
.ALGORITHM
 
37
  real work is done in function `helpme'  (in file helpme.c)
 
38
.INPUT/OUTPUT
 
39
  the following keywords are used:
 
40
 
 
41
  IN_A/C/1/60           help command/qualif help_string (=command/qualif)
 
42
                        or ^context_name if called from context.prg
 
43
                        in that case, save context dir in FORGRxy.CTX
 
44
  INPUTC/C/1/80         currently enabled contexts
 
45
  OUTPUTC/C/1/80        currently enabled contexts
 
46
       
 
47
.VERSION   [9.00]  920423: split up into more subroutines + prepare for UIMX
 
48
 
 
49
 090429         last modif
 
50
 -------------------------------------------------- */
 
51
 
 
52
 
 
53
#include <string.h>
 
54
#include <stdlib.h>
 
55
#include <stdio.h>
 
56
 
 
57
#include <fileexts.h>
 
58
 
 
59
#include <monitdef.h>
 
60
#include <midback.h>
 
61
#include <osparms.h>
 
62
/* #include <ok.h> */
 
63
 
 
64
 
 
65
 
 
66
 
 
67
static int   nolns, exemod, ulevl, lcount;
 
68
 
 
69
 
 
70
 
 
71
 
 
72
int main()
 
73
 
 
74
{
 
75
int  ec, ed, el, ln0, ln1;
 
76
int  iav, logfl[11], nullo, nlog, mmod[2];
 
77
int  kk, prlog;
 
78
int  unit;
 
79
int  helpme();
 
80
 
 
81
char   versio[16], conxt[10], cbufa[82], cbuf[82], lina[80], *pbuf;
 
82
 
 
83
 
 
84
 
 
85
/*  get into MIDAS, save current error values + do not stop on errors */
 
86
 
 
87
(void)SCSPRO("HELPER");
 
88
(void)SCECNT("GET",&ec,&el,&ed);
 
89
ln0 = 0;  ln1 = 1;
 
90
(void)SCECNT("PUT",&ln1,&ln0,&ln0);
 
91
 
 
92
 
 
93
/*  get log flags + user level  */
 
94
 
 
95
(void)SCKRDI("MID$MODE",3,2,&iav,mmod,&unit,&nullo);
 
96
exemod = mmod[0];
 
97
(void)SCKRDI("AUX_MODE",1,8,&iav,logfl,&unit,&nullo);
 
98
 
 
99
(void)SCKRDI("LOG",1,11,&iav,logfl,&unit,&nullo);
 
100
nlog = logfl[0];
 
101
prlog = logfl[8];
 
102
nolns = logfl[10] - 2;
 
103
if ((prlog == 0) && (logfl[2] == 0)) SCKWRI("LOG",&logfl[2],1,1,&unit);
 
104
 
 
105
(void)SCKRDI("ERROR",2,1,&iav,&ln0,&unit,&nullo);
 
106
ulevl = ln0;
 
107
if ((mmod[1] > 0) || (prlog != 0))
 
108
   ulevl = 2;                /* force to expert in batch + printmode  */
 
109
 
 
110
lcount = 0;                     /* init line count */
 
111
(void)SCKGETC("MID$SESS",11,2,&iav,versio);     /* get Midas unit */
 
112
pbuf = getenv("MIDVERS");
 
113
(void) strcpy(&versio[2],pbuf); /* append Midas version */
 
114
 
 
115
 
 
116
/*  get enabled contexts  */
 
117
 
 
118
memset((void *)cbufa,32,(size_t)80);
 
119
cbufa[80] = '\0';
 
120
(void)SCKRDC("INPUTC",1,1,80,&iav,cbufa,&unit,&nullo);
 
121
cbuf[80] = '\0';
 
122
(void)SCKRDC("OUTPUTC",1,1,80,&iav,cbuf,&unit,&nullo);
 
123
 
 
124
 
 
125
/*  get command line  */
 
126
 
 
127
(void)SCKGETC("IN_A",1,60,&iav,lina);
 
128
 
 
129
 
 
130
/* is it ^blabla from context.prg   or  normal help command ?  */
 
131
 
 
132
if (lina[0] == '^')                     /* special context dir command */
 
133
   {
 
134
   int  fp, mm;
 
135
   char  ctxdir[104], frame[120], record[120], mwdir[100];
 
136
 
 
137
   (void) strncpy(conxt,&lina[1],8);    /* get 8 char context name */
 
138
   conxt[8] = '\0';
 
139
   mm = CGN_INDEXC(conxt,'.');          /* abc.ctx */
 
140
   if (mm > 0)
 
141
      {
 
142
      for (kk=mm; kk<8; kk++) conxt[kk] = ' ';
 
143
      }
 
144
   else
 
145
      mm = 8;
 
146
 
 
147
   /* get full context specs + isolate directory */
 
148
 
 
149
   (void) SCKGETC("FULLFILE",1,100,&iav,ctxdir);
 
150
   ctxdir[iav-mm-4] = '\0';
 
151
 
 
152
   (void) OSY_TRNLOG("MID_WORK",mwdir,99,&iav);
 
153
   (void) strcpy(frame,mwdir);
 
154
   (void) strcpy(lina,"FORGR  .CTX");
 
155
   lina[5] = versio[0];
 
156
   lina[6] = versio[1];
 
157
   (void) strcat(frame,lina);
 
158
 
 
159
   fp = CGN_OPEN(frame,READ);           /* just to see, if file exists */
 
160
   if (fp == -1) 
 
161
      {
 
162
      fp =  CGN_OPEN(frame,WRITE);      /* create new file */
 
163
      if (fp == -1) 
 
164
         {
 
165
         sprintf(frame,"Could not open FORGR%c%c.CTX in MID_WORK...",
 
166
                        versio[0],versio[1]);
 
167
         SCTPUT(frame);
 
168
         }
 
169
      else
 
170
         {
 
171
         (void) strncpy(record,conxt,8);
 
172
         (void) strcpy(&record[8],ctxdir);
 
173
         (void) osawrite(fp,record,(int)strlen(record));
 
174
         (void) osaclose(fp);
 
175
         }
 
176
      }
 
177
   else
 
178
      {
 
179
      int  gp;
 
180
      char  grame[124];
 
181
 
 
182
      (void) strcpy(grame,frame);
 
183
      (void) strcat(grame,"new");
 
184
      gp = CGN_OPEN(grame,WRITE);               /* open new file for copying */
 
185
      mm = 0;
 
186
 
 
187
    read_loop:
 
188
      memset((void *)record,32,(size_t)100);
 
189
      iav = osaread(fp,record,100);             /* look for context in file */
 
190
 
 
191
      if (iav < 1)
 
192
         {                              /* not found, so add to the end */
 
193
         (void) osaclose(fp);
 
194
         if (mm == 0)
 
195
            {                                   /* append new record */
 
196
            (void) strncpy(record,conxt,8);
 
197
            (void) strcpy(&record[8],ctxdir);
 
198
            (void) osawrite(gp,record,(int)strlen(record));     
 
199
            }
 
200
         (void) osaclose(gp);
 
201
         (void) osfrename(grame,frame);
 
202
         }
 
203
      else
 
204
         {
 
205
         if (strncmp(conxt,record,8) == 0)
 
206
            {
 
207
            (void) strcpy(&record[8],ctxdir);   /* direc could have changed */
 
208
            mm = 99;
 
209
            }                                   /* copy to new frame */
 
210
         (void) osawrite(gp,record,(int)strlen(record));
 
211
         goto read_loop;
 
212
         }
 
213
      }
 
214
   }
 
215
 
 
216
else                                    /* we do everything in helpme  */
 
217
   helpme(1,versio,lina,cbufa,cbuf);
 
218
 
 
219
 
 
220
logfl[0] = nlog;                        /* reset key LOG(1) */
 
221
(void)SCKWRI("LOG",logfl,1,1,&unit);
 
222
(void)SCSEPI();
 
223
return 0;                       
 
224
}
 
225
 
 
226
/*
 
227
 
 
228
*/
 
229
 
 
230
/*      this function must be synchronized with the one in dspout.c !!!  */
 
231
 
 
232
int dspout(record)
 
233
char  *record;          /* IN: string to be displayed */
 
234
 
 
235
{
 
236
char    reco[100];
 
237
 
 
238
int  n;
 
239
register int  nr;
 
240
 
 
241
 
 
242
 
 
243
/*  throw away the '\' and '|' characters */
 
244
 
 
245
if (record[0] != '\0')
 
246
   {
 
247
   n = 0;
 
248
   for (nr=0; nr<99; nr++)
 
249
      {
 
250
      if (record[nr] == '\0')
 
251
         break;
 
252
      else if ( (record[nr] == '\\') && 
 
253
                ((record[nr+1] != 'a') || (record[nr+2] != 'g')) )
 
254
         {
 
255
         if (nr == 0) return (0);               /* new line */
 
256
         }
 
257
      else if (record[nr] == '|')
 
258
         {
 
259
         if (nr == 0) 
 
260
            return (0);                         /* new line */
 
261
         else if (record[nr-1] == '\\')
 
262
            reco[n++] = record[nr];             /* "\|" -> "|"  */
 
263
         else if ( (record[nr-1] != ' ') && (record[nr+1] != ' ') )
 
264
            reco[n++] = record[nr];             /* x|y is o.k. */
 
265
         }
 
266
      else
 
267
         reco[n++] = record[nr];                /* copy character */
 
268
      }
 
269
   reco[n] = '\0';
 
270
   }
 
271
else
 
272
   {
 
273
   reco[0] = ' ';
 
274
   reco[1] = '\0';
 
275
   }
 
276
 
 
277
SCTPUT(reco);                                /*  display on terminal + log */
 
278
 
 
279
 
 
280
/*  if exemod != 1, check no. of lines on terminal screen ... */
 
281
 
 
282
if (exemod != 1) 
 
283
   {
 
284
   lcount++ ;
 
285
 
 
286
   if (lcount > nolns) 
 
287
      {
 
288
      if (ulevl >= 2) 
 
289
         {
 
290
         lcount = 0;
 
291
         return (0);
 
292
         }
 
293
  
 
294
 
 
295
/*  for novice + user level we ask */
 
296
 
 
297
      (void)printf("\n\rhit return to continue, 'q' + return to quit ");
 
298
      reco[0] = ' ';
 
299
      reco[0] = getchar();
 
300
      if ((reco[0] == 'Q') || (reco[0] == 'q')) 
 
301
         return (1);                    /* indicate, that we quit */
 
302
      
 
303
      lcount = 0;
 
304
      }
 
305
   }
 
306
 
 
307
return (0); 
 
308
}
 
309
 
 
310
/* ARGSUSED */
 
311
 
 
312
/*      this function must be synchronized with the one in dspout.c !!!  */
 
313
 
 
314
void prepmem(yourpntr)
 
315
 
 
316
char **yourpntr;
 
317
 
 
318
{
 
319
 
 
320
return;
 
321
 
 
322
}