Debian Codegraph @

applic/general/src/keyreg.c

raw
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: [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
30 .IDENT keyreg.c
31 .AUTHOR Pascal Ballester, ESO - Garching
32 .KEYWORDS Session Manager
33 .PURPOSE Parse initialisation file and initialize
34 session table
35
36 .VERSION 1.0 Creation 18-FEB-1994 PB
37
38 090710 last modif
39 ------------------------------------------------------------- */
40
41 #include <tbldef.h>
42 #include <midas_def.h>
43 #include <filedef.h>
44 #include <str.h>
45
46 #include <stdio.h>
47
48
49 #define MAXCHAR 200
50
51 int main()
52
53 {
54 char direct[80], file[80], table[80], phfile[300],
55 line[MAXCHAR], segment[MAXCHAR];
56 char keyname[13], type[13], defval[51], descr[101];
57 char indspace, indslash, indmark, nbcar;
58
59 int actvals, fid, tid;
60 int colk, colt, cold[4], colf;
61 int bounds[2], cnt=0, row=0, discount;
62 int dbg = 0, lgth, status;
63
64
65 bounds[0] = bounds[1] = discount = 0;
66
67
68 (void) SCSPRO("keyreg");
69
70 (void) SCKGETC("IN_A", 1, 80, &actvals, direct);
71 (void) SCKGETC("IN_B", 1, 80, &actvals, file);
72 (void) SCKGETC("OUT_A",1, 80, &actvals, table);
73
74 (void) TCTINI(table, F_TRANS, F_O_MODE, 100, 10, &tid);
75
76 TCCINI(tid, D_C_FORMAT, 32, "A10", "Keyword", "KEY", &colk);
77 TCCINI(tid, D_C_FORMAT, 12, "A8", "Type", "TYPE", &colt);
78 TCCINI(tid, D_C_FORMAT, 50, "A10", "Default", "DEFAULT", &colf);
79 TCCINI(tid, D_C_FORMAT, 70, "A15", "Description", "D1", &cold[0]);
80 TCCINI(tid, D_C_FORMAT, 70, "A5", "Description", "D2", &cold[1]);
81 TCCINI(tid, D_C_FORMAT, 70, "A5", "Description", "D3", &cold[2]);
82 TCCINI(tid, D_C_FORMAT, 70, "A5", "Description", "D4", &cold[3]);
83
84 status = osfphname(direct,phfile);
85 if (status == -1) (void) strcpy(phfile,direct);
86
87 #ifndef vms
88 if (phfile[(int)strlen(phfile)-1] != '/') (void) strcat(phfile,"/");
89 #endif
90
91 (void) strcat(phfile,file);
92
93 if ((fid = osaopen(phfile,READ)) == -1) {
94 (void) sprintf(line,"Could not open file %s",phfile);
95 SCETER(11,line);
96 }
97
98 line[0] = '\0';
99 while (osaread(fid, line, MAXCHAR) >= 0)
100 {
101 cnt++;
102
103 strred(line);
104 strlower(line);
105
106 if (line[0] == '!') {
107 if (strindex(line,"begin session list") < (int)strlen(line))
108 bounds[0] = cnt + 1;
109 if (strindex(line,"end session list") < (int)strlen(line))
110 bounds[1] = cnt - 1;
111 }
112 }
113
114 if (bounds[0] == 0) bounds[0] = 1;
115 if (bounds[1] == 0) bounds[1] = cnt - 1;
116
117 if (dbg == 1) printf("Bounds from %d to %d\n",bounds[0],bounds[1]);
118
119 osaseek(fid, 0L, FILE_START); /* Returns to beggining of file */
120
121 if (bounds[0] > 1) {
122 for(cnt=1; cnt<bounds[0]; cnt++)
123 osaread(fid, line, MAXCHAR);
124 }
125
126 for(cnt=bounds[0]; cnt<=bounds[1]; cnt++) {
127
128 if ((lgth = osaread(fid, line, MAXCHAR)) > 0) {
129
130 (void) strcpy (segment,line);
131 (void) strred (segment);
132 (void) strupper(segment);
133
134 if (dbg == 1)
135 {
136 printf(" : 1 2 3 4 5\n");
137 printf(" :012345678901234567890123456789012345678901234567890\n");
138 printf("Line :%s\n",line);
139 printf("Segment:%s\n",segment);
140 printf("Position: %d\n",strindex(segment,"WRITE/KEY"));
141 }
142
143 if (strindex(segment,"WRITE/KEY") == 0) {
144
145 discount = 0;
146
147 indspace = strindex(segment," ");
148 indslash = strindex(segment+8,"/")+8;
149 nbcar = indslash - indspace;
150
151 keyname[0] = '\0';
152
153 (void) strncopy(keyname,nbcar,segment+indspace+1);
154
155 /* if keyword already exists, it should not be deleted ... (KB)
156
157 if (MID_FNDKEY(keyname,type,&actvals,&actvals,&actvals) != -1)
158 {
159 (void) sprintf(table,"keyword: %s already exists -> no table entry",
160 keyname);
161 SCTPUT(table);
162 continue;
163 } */
164
165
166 if ((keyname[0] != '\0') && (keyname[0] != ' '))
167 {
168 TCEWRC(tid, ++row, colk, keyname);
169
170 indspace = strindex(segment+indslash," ");
171 nbcar = indspace;
172
173 strncopy(type,nbcar,segment+indslash+1);
174
175 TCEWRC(tid, row, colt, type);
176
177 indslash = strindex(line,"/");
178 indslash += strindex(line+indslash+1,"/"); /* Second Slash */
179 indspace = strindex(line+indslash," ")+indslash;
180 indmark = strindex(line,"!");
181
182 if (indmark < (int)strlen(line)) {
183
184 nbcar = indmark - indspace;
185
186 strncopy (defval,nbcar,line+indspace+1);
187 strred (defval);
188 TCEWRC (tid, row, colf, defval);
189
190 strcpy (descr,line+indmark+1);
191 TCEWRC (tid, row, cold[discount], descr);
192 }
193 else {
194 (void)strcpy (defval,line+indspace+1);
195 strred (defval);
196 TCEWRC (tid, row, colf, defval);
197 }
198
199 while(discount < 3) (void) TCEWRC (tid, row, cold[++discount], "~");
200 discount = 0;
201 }
202 } /* Closes if (segment... */
203
204 if (strindex(segment,"!$") == 0) {
205 discount++;
206 strcpy (descr,line+2);
207 (void) TCEWRC (tid, row, cold[discount], descr);
208 }
209
210
211 }} /* Closes if ((lgth=... and for (cnt=bounds[0] ... */
212
213
214 (void) TCTCLO(tid);
215 (void) osaclose(fid);
216 (void) SCSEPI();
217
218 return 0;
219 }
220
221