Debian Codegraph @

gui/XEchelle/libsrc/listdir.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 .VERSION
28 090904 last modif
29
30 ===========================================================================*/
31 #include <math.h>
32 #include <midas_def.h>
33 #include <tbldef.h>
34 #include <string.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <proto_xech.h>
38 #include <Xm/List.h>
39 #include <Xm/Text.h>
40 #include <UxLib.h>
41
42 #define NFILEMAX 500
43 #define LFILEMAX 50
44
45 extern int AppendDialogText();
46
47
48
49 int dbx=0;
50 Widget Wdir, Wcard, Wldir, Wlist;
51 char WFList[NFILEMAX][LFILEMAX];
52 int WFnl, WFSelect[NFILEMAX], WFns;
53 char WFDir[200];
54
55 char command[500];
56 char fcomm[500];
57 char name[500];
58
59 /* Initialisation of widgets ID's and present directory*/
60 void WInit_widgets(wdir, wcard, wldir, wlist)
61 Widget wdir, wcard, wldir, wlist;
62 {
63 Wdir = wdir;
64 Wcard = wcard;
65 Wldir = wldir;
66 Wlist = wlist;
67 strcpy(WFDir,".");
68 }
69
70
71 /* Change Midas directory to the present directory */
72 void WChange_Midas_dir()
73 {
74 sprintf(command,"CHANGE/DIRECTORY %s",WFDir);
75 AppendDialogText(command);
76 }
77
78 /* Determines the new directory using a relative path,
79 updates the Directory: widget,
80 determine and updates the list of directories */
81 void WGet_all_dirs(node)
82
83 char *node;
84 {
85 FILE *fpin;
86 int n=0;
87 int ispos=1;
88
89 /* Get current directory name and display in tf_session1 */
90
91 sprintf(command, "cd %s ; cd %s ; pwd",WFDir,node);
92 if (dbx == 1) printf("GAD/Executing command: %s\n",command);
93 if ((fpin = (FILE*) popen(command,"r")) == NULL)
94 printf("Could not execute command: %s\n",command);
95 fgets(name,79,fpin);
96 name[strlen(name)-1] = '\0';
97 if (pclose(fpin) == -1)
98 printf("Could not close stream for command: %s\n",command);
99 strcpy(WFDir, name);
100 XmTextSetString(Wdir, name);
101
102 /* Determines list of sub-directories */
103
104 sprintf(command,"cd %s ; ls -F | grep / | sort ",
105 WFDir);
106 if (dbx == 1) printf("GAD/Executing command: %s\n",command);
107 if ((fpin = (FILE*) popen(command,"r")) == NULL)
108 printf("Could not execute command: %s\n",command);
109
110 XmTextSetString(Wldir, "");
111 XmTextInsert(Wldir, (XmTextPosition) ispos, "../\n");
112 while (fgets(name,79,fpin) != NULL) {
113 if (dbx == 1) printf("GAD/File: %s\n",name);
114 ispos = strlen(XmTextGetString(Wldir));
115 XmTextInsert(Wldir, (XmTextPosition) ispos, name);
116 n++;
117 }
118
119 if (pclose(fpin) == -1)
120 printf("Could not close stream for command: %s\n",command);
121 }
122
123 int WGet_all_files()
124 {
125 FILE *fpin;
126 int n=0, len;
127 char ident[74], full_name[300];
128 int null, unit, actvals, imno;
129 int pc, pl, pd, npc=1, npl=0, npd=0, ibuf[5];
130 XmString Item;
131
132 /* Reads current directory */
133 strcpy(WFDir, (char *)XmTextGetString(Wdir));
134 XmListDeleteAllItems(Wlist);
135
136 sprintf(fcomm,"cd %s ; ls %s",WFDir,XmTextGetString(Wcard));
137
138 strcpy(command,fcomm);
139 strcat(command," | grep -v middumm | sort");
140 if (dbx == 1) printf("GAF/Executing command: %s\n",command);
141
142 if ((fpin = (FILE*) popen(command,"r")) == NULL)
143 printf("Could not execute command: %s\n",command);
144
145 n=0;
146 while (fgets(name,79,fpin) != NULL) {
147
148 len = strlen(name);
149 name[--len] = '\0';
150
151 strcpy(full_name,WFDir);
152 strcat(full_name,"/");
153 strcat(full_name,name);
154
155 strcpy(ident,"");
156 SCECNT("GET", &pc, &pl, &pd);
157 SCECNT("PUT", &npc, &npl, &npd);
158
159 if (dbx == 1)
160 printf("GAF/Opening File: %s. \n",full_name);
161
162 if (SCFINF(full_name, 4, ibuf) == ERR_NORMAL) {
163 SCFOPN(full_name, D_R4_FORMAT, 1, F_IMA_TYPE, &imno);
164 if (ibuf[2] == 0) {
165 len = SCDRDC(imno, "IDENT", 1, 1, 72, &actvals, ident, &unit, &null);
166 if (dbx == 1) printf("Len = %d\n",len);
167 }
168 SCFCLO(imno);
169 }
170 SCECNT("PUT", &pc, &pl, &pd);
171 if (dbx == 1) printf("GAF/Opened File: %s\n",full_name);
172 strcpy(&WFList[n][0], name);
173
174 if (len < 15)
175 {
176 while (len++ < 17) strcat(name," ");
177 }
178 else
179 {
180 strcat(name," ");
181 }
182
183 strcat(name, ident);
184 Item = XmStringCreateSimple(name);
185 XmListAddItem(Wlist, Item, 0);
186 n++;
187 }
188
189 if (pclose(fpin) == -1)
190 printf("Could not close stream for command: %s\n",command);
191
192 WFnl = n;
193 return(WFnl);
194 }
195
196
197 int WGet_selection()
198
199 {
200 int *p, pcount, i;
201
202 XmListGetSelectedPos(Wlist,&p, &pcount);
203
204 if (pcount <= 0) {
205 printf("No item selected in the list.\n");
206 WFns = 0;
207 return(0);
208 }
209
210 for (i=0; i<pcount; i++) {
211 printf("Selected item nb %d. Value %s\n",p[i], &WFList[(p[i]-1)][0]);
212 WFSelect[i] = p[i]-1;
213 }
214 WFns = pcount;
215
216 free(p);
217 return(pcount);
218 }
219
220
221 void WProcess_table(ptable)
222
223 char* ptable;
224
225 {
226 char table[TEXT_LEN], outfile[TEXT_LEN], out[TEXT_LEN], outnb[TEXT_LEN];
227
228 int icol, ocol, row;
229 int tid, nbout;
230
231 strcpy(out,(char *)XmTextGetString(UxGetWidget(UxFindSwidget("tf_wrang1"))));
232 strcpy(outnb,(char *)XmTextGetString(UxGetWidget(UxFindSwidget("tf_wrang2"))));
233
234 sscanf(outnb,"%d",&nbout);
235 strcpy(table, WFDir);
236 strcat(table, "/");
237 strcat(table,ptable);
238
239 TCTINI (table, F_TRANS, F_IO_MODE, 3, WFns, &tid);
240 TCCINI (tid, D_C_FORMAT, 60, "A20", " ", "INPUT", &icol);
241 TCCINI (tid, D_C_FORMAT, 60, "A20", " ", "OUTPUT", &ocol);
242
243 for (row=1; row<=WFns; row++) {
244 TCEWRC(tid, row, icol, &WFList[WFSelect[row-1]][0]);
245 sprintf(outfile,"%s%d.bdf", out, (nbout+row-1));
246 TCEWRC(tid, row, ocol, outfile);
247 }
248
249 TCTCLO(tid);
250
251 }
252
253 char* WGet_First()
254
255 {
256 return(&WFList[WFSelect[0]][0]);
257 }
258
259
260
261