2 Copyright (c) 1998-1999 Matra Datavision
3 Copyright (c) 1999-2012 OPEN CASCADE SAS
5 The content of this file is subject to the Open CASCADE Technology Public
6 License Version 6.5 (the "License"). You may not use the content of this file
7 except in compliance with the License. Please obtain a copy of the License
8 at http://www.opencascade.org and read it completely before using this file.
10 The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 The Original Code and all software distributed under the License is
14 distributed on an "AS IS" basis, without warranty of any kind, and the
15 Initial Developer hereby disclaims all such warranties, including without
16 limitation, any warranties of merchantability, fitness for a particular
17 purpose or non-infringement. Please see the License for the specific terms
18 and conditions governing the rights and limitations under the License.
22 /**********************************************************
30 /** Fichier : OSD_FFI.C (SUN/UNIX)
32 /** Titre : osd_ffi_(dir, name, tab_res, max, l_dir, l_name, l_tab)
34 /** char *dir, *nmae, *tab-res;
38 /** int l_dir, l_name, l_tab;
42 /** Nombre de fichier trouve (1 ou plus)
48 /** Role : Trouver tous les fichier qui ont le meme nom que 'name' sachant
50 /** que 'name' peut etre un nom de fichier comportant le caractere
60 /** integer nb_fichier, osd_ffi
62 /** character*80 dir, name
64 /** character*80 tab_res(100)
74 /** nb_fichier = osd_ffi(dir, name, tab_res, 100)
78 /** Modifs : - sga 28/04/92 correction bug closedir
80 /** - asi 11/04/90 correction de strcmp_joker
82 /** - fsa 26/04/90 ajout du tri du tableau tab_res
84 /** par ordre aphabethique
86 /** - asi 06/09/90 ajout de la directorie aux noms de fichier
90 /** - J.P. TIRAULT le 3-Avril-1992 : Faire le close du directory
92 /** apres l'avoir ouvert.
96 /*************************************************************/
97 #if defined(_MSC_VER) && !defined(WNT)
98 #error "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!"
107 /* This hack is required to get HP's c89 to include a definition for DIR */
109 # ifndef _INCLUDE_POSIX_SOURCE
110 # define _INCLUDE_POSIX_SOURCE
115 #include <sys/types.h>
116 #include <sys/stat.h>
122 # define NAMLEN(dirent) strlen((dirent)->d_name)
124 extern char *vmsify PARAMS ((char *name, int type));
127 # define dirent direct
128 # define NAMLEN(dirent) (dirent)->d_namlen
129 # ifdef HAVE_SYS_NDIR_H
130 # include <sys/ndir.h>
132 # ifdef HAVE_SYS_DIR_H
133 # include <sys/dir.h>
138 # ifdef HAVE_VMSDIR_H
140 # endif /* HAVE_VMSDIR_H */
143 /* In GNU systems, <dirent.h> defines this macro for us. */
146 # define NAMLEN(d) _D_NAMLEN(d)
149 #if (defined (POSIX) || defined (VMS) || defined (WINDOWS32)) && !defined (__GNU_LIBRARY__)
150 /* Posix does not require that the d_ino field be present, and some
151 systems do not provide it. */
152 # define REAL_DIR_ENTRY(dp) 1
153 # define FAKE_DIR_ENTRY(dp)
155 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
156 # define FAKE_DIR_ENTRY(dp) (dp->d_ino = 1)
162 void tri(int taille, char *list,int l_tab);
163 int strcmp_joker(char *s1, char *s2);
166 osd_ffi(char *dir, char *name, char *tab_res, int *max, int l_dir, int l_name, int l_tab)
168 char file[255], directory[255];
169 int ii, jj, kk, nb_file;
171 /***** Le Nom de la directory ******/
177 for (ii=0; ii<l_dir && ii<255 && *dir != ' '; ii++)
178 directory[ii] = *(dir++);
182 /***** Le Nom de fichier recherche *******/
183 for (ii=0; ii<l_name && ii<255 && *name != ' '; ii++)
184 file[ii] = *(name++);
187 /****** On ouvre le directory pour trouver les fichiers ********/
189 if ((dirp = opendir(directory)) != NULL){
190 while ((nb_file < *max) && (dp=readdir(dirp))) {
191 /*====== Si on trouve un fichier qui lui ressemble ==========*/
192 if(strcmp_joker(file,dp->d_name) == 0) {
193 /*======= On copie sa valeur ========*/
194 /* avec la directorie */
195 /* jj tab_res, kk la ligne ,ii le nom */
196 jj = nb_file * l_tab;
198 if (directory[0] != '.') {
199 for (; kk<l_tab && directory[kk] != 0; kk++,jj++)
200 *(tab_res + jj) = directory[kk];
201 if (directory[kk-1] != '/') *(tab_res + (jj++)) = '/';
203 for (ii=0; (kk)<l_tab && *(dp->d_name+ii); ii++,jj++,kk++)
204 *(tab_res + jj) = *(dp->d_name + ii);
205 /*======= En completant avec blanc ======*/
206 for (; kk<l_tab ; jj++,kk++)
207 *(tab_res + jj) = ' ';
212 /***** tri du tableau tab_res par ordre alpha *****/
215 tri( nb_file , tab_res ,l_tab );
220 /***********************************************
224 * Title: STRCMP_JOKER(ch1,ch2)
225 * Role : Compare ch1 with ch2
226 * ch1 can have the joker caracter '*'
227 * res = 0 they are identical
229 * Modif: asi 11/04/90 correction
230 ***********************************************/
238 strcmp_joker(char *s1, char *s2)
240 char *c1=NULL,*c2=NULL; /* sauvegardes */
242 int deb = 1; /* 0 si 1er car est le joker, 1 sinon */
247 while(*s1 == JOKER) s1++;
249 while(*s2 && *s2 != *s1) s2++;
252 else return(0); /* s1 fini par un jocker */
254 else { /* comparaison de 2 car */
257 /* 1ere chaine pas de joker au debut */
258 if (deb) return (res);
259 else { /* on recherche la meme chaine plus loin */
261 while(*s2 && *s2 != *s1) s2++;
267 while(*s1 == JOKER) s1++;
271 /**************************************************
275 * Titre : COMPAR (ch1,ch2)
276 * Role : Comparer ch1 avec ch2
277 * retourne : 0 si chaines identiques
278 * >0 si ch2 avant ch1
279 * <0 si ch1 avant ch2
281 **************************************************/
284 compar(char *ch1, char *ch2)
286 /* int strcmp(char *cha, const char *chb); */
288 return(strcmp(ch1,ch2));
291 /**************************************************
295 * Titre : TRI (taille,list,l_tab)
296 * Role : Tri un tableau de chaines par ordre
299 **************************************************/
302 tri(int taille, char *list,int l_tab)
304 qsort( list , taille , l_tab ,(int (*)(const void *,const void *)) compar );
316 #include <windows.h> // added for VAC++ version -ChG 07081997
321 static struct _find_t zeptr ;
326 static LPWIN32_FIND_DATA zeptr ;
328 static struct _finddata_t zeptr ;
342 osd_ffi_(char *dir, char *name, char *tab_res, int *max, int l_dir, int l_name, int l_tab)
344 char file[255], directory[255];
345 int ii, jj, kk, nb_file;
352 /***** Le Nom de la directory ******/
359 for (ii=0; ii<l_dir && ii<255 && *dir != ' '; ii++) {
360 directory[ii] = *(dir++);
361 if ( directory [ii] == '\\' ) directory [ii] = '/' ;
366 /***** Le Nom de fichier recherche *******/
367 for (ii=0; ii<l_name && ii<255 && *name != ' '; ii++)
368 file[ii] = *(name++);
371 /****** On ouvre le directory pour trouver les fichiers ********/
374 strcpy(filespec, directory );
375 strcat(filespec, file );
378 if ((dirp = FindFirstFile(filespec, zeptr)) != INVALID_HANDLE_VALUE ) {
380 if ((dirp = _findfirst(filespec, &zeptr)) != -1 ) {
383 while (nb_file < *max && (! fini ) ) {
385 /*====== Si on trouve un fichier qui lui ressemble ==========*/
388 /*======= On copie sa valeur ========*/
389 /* avec la directorie */
390 /* jj tab_res, kk la ligne ,ii le nom */
391 jj = nb_file * l_tab;
393 if (directory[0] != '.') {
394 for (; kk<l_tab && directory[kk] != 0; kk++,jj++)
395 *(tab_res + jj) = directory[kk];
397 if (directory[kk-1] != '/') *(tab_res + (jj++)) = '/';
401 for (ii=0; (kk)<l_tab && *((*zeptr).cFileName+ii); ii++,jj++,kk++)
402 *(tab_res + jj) = *((*zeptr).cFileName + ii);
404 for (ii=0; (kk)<l_tab && *(zeptr.name+ii); ii++,jj++,kk++)
405 *(tab_res + jj) = *(zeptr.name + ii);
408 /*======= En completant avec blanc ======*/
410 for (; kk<l_tab ; jj++,kk++)
411 *(tab_res + jj) = ' ';
415 fini = FindNextFile(dirp, zeptr );
417 fini = _findnext(dirp, &zeptr );
421 /***** pas de tri du tableau tab_res par ordre alpha *****/
424 if (dirp != INVALID_HANDLE_VALUE) FindClose(dirp);
426 if (dirp) _findclose(dirp);