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
|
/*===========================================================================
Copyright (C) 1995-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
===========================================================================*/
#include <gl_defs.h>
#include <xm_defs.h>
#include <ctype.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <osparms.h>
#define MAXLEN_FILENAME 32 /* max lenght of a filename */
static char Suffix[MAXLINE]; /* suffix of files to select */
static String filelist; /* list of file names */
static int nfiles = 0; /* number of files in filelist */
static void ScanDir();
extern int oshcmd();
void SetFileList( wlist,strip,dirspecs )
Widget wlist;
char *dirspecs;
int strip;
{
int i,j,k;
char liste[500];
XmStringTable str_list;
strcpy(Suffix,dirspecs);
ScanDir(strip,dirspecs);
str_list = (XmStringTable)XtMalloc(nfiles * sizeof(XmString *));
k = 0 ;
for ( i = 0; i < nfiles; i++ ) {
j = 0;
while (filelist[k] != '\n') { liste[j++] = filelist[k++]; }
liste[j] = '\0';
k++;
str_list[i] = XmStringCreateSimple(liste);
}
XmListSetPos(wlist, 1);
XmListDeleteAllItems(wlist);
XmListAddItems(wlist, str_list, nfiles, 1);
for ( i = 0; i < nfiles; i++ )
XmStringFree(str_list[i]);
XtFree((char *)str_list);
}
/* Scans the working directory for files selected by InList()???, sorted
* alphabetically, and stored in an array of pointers to directory
* entries called namelist.
* The names of the selected files are stored in filelist.
*/
static void ScanDir(strip,dir)
int strip;
char *dir;
{
char Command[256];
char filemark;
FILE *list, *number;
int jj, nword, nchar, row, k=0, k0=0;
register int nr;
#if vms
filemark = ']';
#else
filemark = '/';
strcpy (Command, "ls -aF ");
strcat (Command, dir);
strcat (Command, " > tmpscan.dir; cat tmpscan.dir | wc > tmpscan.nb");
#endif
oshcmd(Command,NULL,NULL,NULL);
number = fopen("tmpscan.nb", "r");
list = fopen("tmpscan.dir","r");
fscanf(number, "%d %d %d",&nfiles, &nword, &nchar);
filelist = (char *) malloc((size_t)((nchar+1)*sizeof(char)));
if (strip == 1) /* Yes. Strip off directory specs */
{
for (row = 0; row < nfiles; row++)
{
fscanf (list,"%s",&filelist[k]);
while (filelist[k] != '\0')
{
if (filelist[k] == '*') filelist[k] = ' ';
k++;
}
for (nr=k-1; nr>k0; nr--) /* check for directory specs */
{
if (filelist[nr] == filemark)
{
jj = nr + 1;
strcpy(&filelist[k0],&filelist[jj]);
k -= (jj-k0);
break;
}
}
filelist[k++] = '\n';
k0 = k; /* follow with start index */
}
}
else /* leave as it is */
{
for (row = 0; row < nfiles; row++)
{
fscanf (list,"%s",&filelist[k]);
while (filelist[k] != '\0')
{
if (filelist[k] == '*') filelist[k] = ' ';
k++;
}
filelist[k++] = '\n';
}
}
filelist[k] = '\0';
fclose(number);
fclose(list);
}
|