| 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 |
#include <gl_defs.h> |
| 30 |
#include <xm_defs.h> |
| 31 |
#include <ctype.h> |
| 32 |
#include <sys/stat.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include <string.h> |
| 35 |
#include <dirent.h> |
| 36 |
#include <osparms.h> |
| 37 |
|
| 38 |
#define MAXLEN_FILENAME 32 /* max lenght of a filename */ |
| 39 |
|
| 40 |
static char Suffix[MAXLINE]; /* suffix of files to select */ |
| 41 |
static String filelist; /* list of file names */ |
| 42 |
static int nfiles = 0; /* number of files in filelist */ |
| 43 |
|
| 44 |
static void ScanDir(); |
| 45 |
|
| 46 |
extern int oshcmd(); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
void SetFileList( wlist,strip,dirspecs ) |
| 51 |
Widget wlist; |
| 52 |
char *dirspecs; |
| 53 |
int strip; |
| 54 |
|
| 55 |
{ |
| 56 |
int i,j,k; |
| 57 |
char liste[500]; |
| 58 |
XmStringTable str_list; |
| 59 |
|
| 60 |
strcpy(Suffix,dirspecs); |
| 61 |
|
| 62 |
ScanDir(strip,dirspecs); |
| 63 |
|
| 64 |
str_list = (XmStringTable)XtMalloc(nfiles * sizeof(XmString *)); |
| 65 |
|
| 66 |
k = 0 ; |
| 67 |
for ( i = 0; i < nfiles; i++ ) { |
| 68 |
j = 0; |
| 69 |
while (filelist[k] != '\n') { liste[j++] = filelist[k++]; } |
| 70 |
liste[j] = '\0'; |
| 71 |
k++; |
| 72 |
str_list[i] = XmStringCreateSimple(liste); |
| 73 |
} |
| 74 |
|
| 75 |
XmListSetPos(wlist, 1); |
| 76 |
XmListDeleteAllItems(wlist); |
| 77 |
XmListAddItems(wlist, str_list, nfiles, 1); |
| 78 |
|
| 79 |
for ( i = 0; i < nfiles; i++ ) |
| 80 |
XmStringFree(str_list[i]); |
| 81 |
XtFree((char *)str_list); |
| 82 |
} |
| 83 |
|
| 84 |
/* Scans the working directory for files selected by InList()???, sorted |
| 85 |
* alphabetically, and stored in an array of pointers to directory |
| 86 |
* entries called namelist. |
| 87 |
* The names of the selected files are stored in filelist. |
| 88 |
*/ |
| 89 |
|
| 90 |
static void ScanDir(strip,dir) |
| 91 |
|
| 92 |
int strip; |
| 93 |
char *dir; |
| 94 |
|
| 95 |
{ |
| 96 |
char Command[256]; |
| 97 |
char filemark; |
| 98 |
|
| 99 |
FILE *list, *number; |
| 100 |
|
| 101 |
int jj, nword, nchar, row, k=0, k0=0; |
| 102 |
register int nr; |
| 103 |
|
| 104 |
#if vms |
| 105 |
filemark = ']'; |
| 106 |
|
| 107 |
#else |
| 108 |
filemark = '/'; |
| 109 |
strcpy (Command, "ls -aF "); |
| 110 |
strcat (Command, dir); |
| 111 |
strcat (Command, " > tmpscan.dir; cat tmpscan.dir | wc > tmpscan.nb"); |
| 112 |
#endif |
| 113 |
|
| 114 |
|
| 115 |
oshcmd(Command,NULL,NULL,NULL); |
| 116 |
|
| 117 |
number = fopen("tmpscan.nb", "r"); |
| 118 |
list = fopen("tmpscan.dir","r"); |
| 119 |
|
| 120 |
fscanf(number, "%d %d %d",&nfiles, &nword, &nchar); |
| 121 |
filelist = (char *) malloc((size_t)((nchar+1)*sizeof(char))); |
| 122 |
|
| 123 |
if (strip == 1) /* Yes. Strip off directory specs */ |
| 124 |
{ |
| 125 |
for (row = 0; row < nfiles; row++) |
| 126 |
{ |
| 127 |
fscanf (list,"%s",&filelist[k]); |
| 128 |
while (filelist[k] != '\0') |
| 129 |
{ |
| 130 |
if (filelist[k] == '*') filelist[k] = ' '; |
| 131 |
k++; |
| 132 |
} |
| 133 |
|
| 134 |
for (nr=k-1; nr>k0; nr--) /* check for directory specs */ |
| 135 |
{ |
| 136 |
if (filelist[nr] == filemark) |
| 137 |
{ |
| 138 |
jj = nr + 1; |
| 139 |
strcpy(&filelist[k0],&filelist[jj]); |
| 140 |
k -= (jj-k0); |
| 141 |
break; |
| 142 |
} |
| 143 |
} |
| 144 |
filelist[k++] = '\n'; |
| 145 |
k0 = k; /* follow with start index */ |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
else /* leave as it is */ |
| 150 |
{ |
| 151 |
for (row = 0; row < nfiles; row++) |
| 152 |
{ |
| 153 |
fscanf (list,"%s",&filelist[k]); |
| 154 |
while (filelist[k] != '\0') |
| 155 |
{ |
| 156 |
if (filelist[k] == '*') filelist[k] = ' '; |
| 157 |
k++; |
| 158 |
} |
| 159 |
filelist[k++] = '\n'; |
| 160 |
} |
| 161 |
} |
| 162 |
filelist[k] = '\0'; |
| 163 |
|
| 164 |
fclose(number); |
| 165 |
fclose(list); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|