| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1991-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: [email protected] |
| 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 |
.IDENT dialog.c |
| 30 |
.MODULE subroutines -- graphical user interface |
| 31 |
.LANGUAGE C |
| 32 |
.AUTHOR Cristian Levin - ESO La Silla |
| 33 |
.PURPOSE The function of this module perform the communication |
| 34 |
between an external process and Midas. |
| 35 |
.KEYWORDS signals, communication. |
| 36 |
.COMMENTS - Communication through a file in MID_WORK, using |
| 37 |
SIGUSR1 for interrupting Midas and waiting for |
| 38 |
SIGUSR2 from Midas. |
| 39 |
.ENVIRONMENT UNIX |
| 40 |
|
| 41 |
.VERSION 1.0 1-Mar-1991 Implementation |
| 42 |
.VERSION 2.0 20-May-1992 Addition of SIGUSR2 stuff |
| 43 |
|
| 44 |
090812 last modif |
| 45 |
------------------------------------------------------------*/ |
| 46 |
|
| 47 |
#include <midas_def.h> |
| 48 |
#include <osfile.h> |
| 49 |
#include <ok.h> |
| 50 |
|
| 51 |
#include <signal.h> |
| 52 |
|
| 53 |
#include <stdio.h> |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#define MYSESSION "QQ" |
| 58 |
#define FOREVER 0 |
| 59 |
#define MAXLINE 160 |
| 60 |
|
| 61 |
#define OKSTAT 0 |
| 62 |
#define NOEXSTAT -999 |
| 63 |
#define SENDSTAT -1000 |
| 64 |
#define BUSYSTAT -1001 |
| 65 |
#define RETSTAT -1002 |
| 66 |
|
| 67 |
#define UNDEFINED -1009 |
| 68 |
|
| 69 |
|
| 70 |
static int CommStat, MidasStat, MidasStata, keylength; |
| 71 |
static int startup = -1; |
| 72 |
|
| 73 |
static char keyfile[1000][MAXLINE]; |
| 74 |
|
| 75 |
extern int strred(), strindex(); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
/* |
| 80 |
|
| 81 |
*/ |
| 82 |
|
| 83 |
int AppendDialogText(s) |
| 84 |
char *s; |
| 85 |
|
| 86 |
{ |
| 87 |
|
| 88 |
int stat, secs, retstat[2]; |
| 89 |
|
| 90 |
static int mid; |
| 91 |
|
| 92 |
char unit[4]; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
MidasStat = UNDEFINED; |
| 97 |
|
| 98 |
if (startup == -1) |
| 99 |
{ |
| 100 |
startup = 0; |
| 101 |
osfphname("DAZUNIT", unit); |
| 102 |
unit[3] = '\0'; |
| 103 |
stat = XCZOPN(unit,MYSESSION,"",&mid); |
| 104 |
if (stat != 0) |
| 105 |
{ |
| 106 |
CommStat = NOEXSTAT; |
| 107 |
return (CommStat); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
secs = -1; /* wait forever */ |
| 112 |
stat = XCCSND(mid,s,secs,retstat); |
| 113 |
if (stat == 1) |
| 114 |
CommStat = BUSYSTAT; |
| 115 |
else if (stat == 4) |
| 116 |
CommStat = SENDSTAT; |
| 117 |
else |
| 118 |
{ |
| 119 |
CommStat = OKSTAT; |
| 120 |
MidasStat = retstat[0]; |
| 121 |
MidasStata = retstat[1]; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
return (CommStat); |
| 126 |
} |
| 127 |
|
| 128 |
/* |
| 129 |
|
| 130 |
*/ |
| 131 |
|
| 132 |
int AppendDialogTextNoWait(s) |
| 133 |
char *s; |
| 134 |
|
| 135 |
{ |
| 136 |
|
| 137 |
int stat, secs, retstat[2]; |
| 138 |
|
| 139 |
static int mid; |
| 140 |
|
| 141 |
char unit[4]; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
MidasStat = UNDEFINED; |
| 146 |
|
| 147 |
if (startup == -1) |
| 148 |
{ |
| 149 |
startup = 0; |
| 150 |
osfphname("DAZUNIT", unit); |
| 151 |
unit[3] = '\0'; |
| 152 |
stat = XCZOPN(unit,MYSESSION,"",&mid); |
| 153 |
if (stat != 0) |
| 154 |
{ |
| 155 |
CommStat = NOEXSTAT; |
| 156 |
return (CommStat); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
secs = 0; /* don't wait */ |
| 161 |
stat = XCCSND(mid,s,secs,retstat); |
| 162 |
if (stat == 1) |
| 163 |
CommStat = BUSYSTAT; |
| 164 |
else if (stat == 4) |
| 165 |
CommStat = SENDSTAT; |
| 166 |
else |
| 167 |
{ |
| 168 |
CommStat = OKSTAT; |
| 169 |
MidasStat = retstat[0]; |
| 170 |
MidasStata = retstat[1]; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
return (CommStat); |
| 175 |
} |
| 176 |
|
| 177 |
/* |
| 178 |
|
| 179 |
*/ |
| 180 |
|
| 181 |
void StatMidas(actio,mstat,mstring) |
| 182 |
char *actio, *mstring; |
| 183 |
int *mstat; |
| 184 |
|
| 185 |
{ |
| 186 |
|
| 187 |
/* currently, MidasStata is not used */ |
| 188 |
|
| 189 |
|
| 190 |
if ((*actio == 'g') || (*actio == 'G')) |
| 191 |
{ /* get errors out */ |
| 192 |
mstat[0] = MidasStat; |
| 193 |
if (MidasStat != UNDEFINED) |
| 194 |
sprintf(mstring,"Midas Error: %d",MidasStat); |
| 195 |
else |
| 196 |
mstring[0] = '\0'; |
| 197 |
} |
| 198 |
else |
| 199 |
{ |
| 200 |
MidasStat = mstat[0]; |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
/* |
| 206 |
|
| 207 |
*/ |
| 208 |
|
| 209 |
int KeyValue(key,value) |
| 210 |
|
| 211 |
char *key, *value; |
| 212 |
|
| 213 |
{ |
| 214 |
|
| 215 |
int n, i, found; |
| 216 |
char msg[MAXLINE], line[MAXLINE]; |
| 217 |
|
| 218 |
strcpy ( line, "keyword: "); |
| 219 |
strcat ( line, key); |
| 220 |
strcat ( line, " "); |
| 221 |
|
| 222 |
found = 0; |
| 223 |
for (n=0; n<keylength; n++) { |
| 224 |
|
| 225 |
strcpy(msg, keyfile[n]); |
| 226 |
|
| 227 |
if (strindex(msg, line) == 0) { |
| 228 |
found = 1; |
| 229 |
strcpy(msg, keyfile[++n]); |
| 230 |
for (i=0; i<strred(msg); i++) /* Removes redundant spaces */ |
| 231 |
if (msg[i] == ' ') msg[i] = ','; /* Replace by comas */ |
| 232 |
strcpy(value, msg); |
| 233 |
break; |
| 234 |
} /* Matches if (strindex .. */ |
| 235 |
} /* Matches for n=0... */ |
| 236 |
|
| 237 |
return(found); |
| 238 |
|
| 239 |
} |
| 240 |
/* |
| 241 |
|
| 242 |
*/ |
| 243 |
|
| 244 |
int LoadFile(fsend) |
| 245 |
|
| 246 |
char *fsend; |
| 247 |
|
| 248 |
{ |
| 249 |
|
| 250 |
int fn, len=MAXLINE, n=0; |
| 251 |
char msg[MAXLINE]; |
| 252 |
|
| 253 |
if ( (fn = osaopen(fsend, READ)) != -1 ) { |
| 254 |
while (osaread(fn,msg,len) != -1) |
| 255 |
strcpy(keyfile[n++], msg); |
| 256 |
keylength = n; |
| 257 |
osaclose(fn); |
| 258 |
} |
| 259 |
else |
| 260 |
printf("Error while opening %s\n",fsend); |
| 261 |
|
| 262 |
if (n == 0) return(0); /* File empty */ |
| 263 |
else return(1); |
| 264 |
} |
| 265 |
|
| 266 |
|