File: dialog.c

package info (click to toggle)
eso-midas 13.09pl1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 147,516 kB
  • ctags: 57,237
  • sloc: ansic: 364,554; sh: 6,936; makefile: 6,194; pascal: 535; perl: 40; awk: 36; sed: 14
file content (266 lines) | stat: -rw-r--r-- 5,214 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*===========================================================================
  Copyright (C) 1991-2009 European Southern Observatory (ESO)
 
  This program is free software; you can redistribute it and/or 
  modify it under the terms of the GNU General Public License as 
  published by the Free Software Foundation; either version 2 of 
  the License, or (at your option) any later version.
 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public 
  License along with this program; if not, write to the Free 
  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, 
  MA 02139, USA.
 
  Correspondence concerning ESO-MIDAS should be addressed as follows:
	Internet e-mail: midas@eso.org
	Postal address: European Southern Observatory
			Data Management Division 
			Karl-Schwarzschild-Strasse 2
			D 85748 Garching bei Muenchen 
			GERMANY
===========================================================================*/

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.IDENT        dialog.c
.MODULE       subroutines -- graphical user interface
.LANGUAGE     C
.AUTHOR       Cristian Levin - ESO La Silla
.PURPOSE      The function of this module perform the communication
              between an external process and Midas.
.KEYWORDS     signals, communication.
.COMMENTS     - Communication through a file in MID_WORK, using
                SIGUSR1 for interrupting Midas and waiting for
                SIGUSR2 from Midas.
.ENVIRONMENT  UNIX
                
.VERSION 1.0   1-Mar-1991   Implementation
.VERSION 2.0  20-May-1992   Addition of SIGUSR2 stuff

 090812		last modif
------------------------------------------------------------*/

#include <midas_def.h>
#include <osfile.h>
#include <ok.h>

#include <signal.h>

#include <stdio.h>



#define MYSESSION	"QQ"
#define FOREVER		0
#define MAXLINE         160
 
#define OKSTAT           0
#define NOEXSTAT        -999
#define SENDSTAT        -1000
#define BUSYSTAT        -1001
#define RETSTAT         -1002

#define UNDEFINED       -1009


static int CommStat, MidasStat, MidasStata, keylength;
static int startup = -1;

static char keyfile[1000][MAXLINE];

extern int strred(), strindex();



/*

*/

int AppendDialogText(s)
char   *s;

{

int  stat, secs, retstat[2];

static int  mid;

char  unit[4];



MidasStat = UNDEFINED;

if (startup == -1)
   {
   startup = 0;
   osfphname("DAZUNIT", unit);
   unit[3] = '\0';
   stat = XCZOPN(unit,MYSESSION,"",&mid);
   if (stat != 0)
      {
      CommStat = NOEXSTAT;
      return (CommStat);
      }
   }

secs = -1;			/* wait forever */
stat = XCCSND(mid,s,secs,retstat);
if (stat == 1)
   CommStat = BUSYSTAT;
else if (stat == 4)
   CommStat = SENDSTAT;
else
   {
   CommStat = OKSTAT;
   MidasStat = retstat[0];
   MidasStata = retstat[1];
   }


return (CommStat);
}

/*

*/

int AppendDialogTextNoWait(s)
char   *s;

{

int  stat, secs, retstat[2];

static int  mid;

char  unit[4];



MidasStat = UNDEFINED;

if (startup == -1)
   {
   startup = 0;
   osfphname("DAZUNIT", unit);
   unit[3] = '\0';
   stat = XCZOPN(unit,MYSESSION,"",&mid);
   if (stat != 0)
      {
      CommStat = NOEXSTAT;
      return (CommStat);
      }
   }

secs = 0;                      /* don't wait */
stat = XCCSND(mid,s,secs,retstat);
if (stat == 1)
   CommStat = BUSYSTAT;
else if (stat == 4)
   CommStat = SENDSTAT;
else
   {
   CommStat = OKSTAT;
   MidasStat = retstat[0];
   MidasStata = retstat[1];
   }


return (CommStat);
}

/*

*/

void StatMidas(actio,mstat,mstring)
char  *actio, *mstring;
int   *mstat;

{

/*  currently, MidasStata is not used */


if ((*actio == 'g') || (*actio == 'G'))
   {						/* get errors out */
   mstat[0] = MidasStat;
   if (MidasStat != UNDEFINED)
      sprintf(mstring,"Midas Error: %d",MidasStat);
   else
      mstring[0] = '\0';
   }
else
   {
   MidasStat = mstat[0];
   }

}

/*

*/

int KeyValue(key,value)

char *key, *value;

{

    int n, i, found;
    char msg[MAXLINE], line[MAXLINE];

    strcpy ( line,  "keyword: ");
    strcat ( line,  key);
    strcat ( line,  " ");

    found = 0;
    for (n=0; n<keylength; n++) {

          strcpy(msg, keyfile[n]);

          if (strindex(msg, line) == 0) {
           found = 1;
           strcpy(msg, keyfile[++n]);
           for (i=0; i<strred(msg); i++)     /* Removes redundant spaces */
               if (msg[i] == ' ')  msg[i] = ','; /* Replace by comas */
           strcpy(value, msg);
           break;
	   }        /* Matches if (strindex .. */
    }  /* Matches for n=0... */

    return(found);

}
/*

*/

int LoadFile(fsend)

char *fsend;

{

    int  fn, len=MAXLINE, n=0;
    char msg[MAXLINE];

    if ( (fn = osaopen(fsend, READ)) != -1 ) {
           while (osaread(fn,msg,len) != -1)
                    strcpy(keyfile[n++], msg);
           keylength = n;
           osaclose(fn);
	 }
    else
       printf("Error while opening %s\n",fsend);

    if (n == 0) return(0); /* File empty */
    else        return(1);
  }