2 * $Header: x:/prj/tech/libsrc/lg/RCS/dpathdir.c 1.8 1998/05/07 10:05:13 DAVET Exp $
4 * Datapath style opendir and readdir commands
12 EXTERN
int _dp_find_flags_tab
[4];
14 // stuffs current name
15 char *DatapathDirGetName(DatapathDir
*dpd
)
17 return dpd
->find
.name
;
20 // stuffs current path into buffer
21 void DatapathDirGetPath(DatapathDir
*dpd
,char *s
)
25 if (dpd
->dp
->datapath
[dpd
->curp
])
26 strcpy(s
,dpd
->dp
->datapath
[dpd
->curp
]);
32 // work back to start or delineation
34 while (p
>=s
&& *p
!='/' && *p
!='\\' && *p
!=':')
38 strcpy(p
,dpd
->find
.name
);
41 DatapathDir
*DatapathOpenDir(Datapath
*dpath
,char *name
,int flags
)
45 dpd
= (DatapathDir
*)Malloc(sizeof(DatapathDir
));
47 // set data path and name
49 strcpy(dpd
->path
,name
);
57 char *DatapathReadDir(DatapathDir
*dpd
)
62 // works on a null datapath
63 while((dpd
->dp
->datapath
[dpd
->curp
]!=NULL
) || (dpd
->curp
==0))
65 // first time for this one
67 if (dpd
->dp
->datapath
[dpd
->curp
]) {
68 strcpy(path
,dpd
->dp
->datapath
[dpd
->curp
]);
73 strcat(path
,dpd
->path
);
74 #if defined(__WATCOMC__) || defined(__SC__)
75 err
= _dos_findfirst(path
,_dp_find_flags_tab
[dpd
->dp
->find_flags
],&(dpd
->find
));
78 // err = (dpd->findfp =_findfirst(path, &(dpd->find)) != -1)?0:1;
79 // which should have been
80 // err = ( (dpd->findfp =_findfirst(path, &(dpd->find))) != -1)?0:1;
81 // but we will write it to be readable
82 dpd
->findfp
=_findfirst(path
, &(dpd
->find
));
83 err
= dpd
->findfp
!= -1 ? 0 : 1 ;
86 #if defined(__WATCOMC__) || defined(__SC__)
87 err
= _dos_findnext(&(dpd
->find
));
89 err
= _findnext(dpd
->findfp
,&(dpd
->find
));
93 // if there was not a read error
95 { // Screen out dot and double dot, because it's dumb.
97 if (dpd
->flags
& DP_SCREEN_DOT
)
98 if (strcmp(dpd
->find
.name
,".")==0 || strcmp(dpd
->find
.name
,"..")==0)
99 continue; // got dot, so we want to scan past it
100 break; // break out, since we have found a real file
103 #if defined(__WATCOMC__) || defined(__SC__)
104 _dos_findclose(&(dpd
->find
));
106 _findclose(dpd
->findfp
);
112 if (err
!=0) return NULL
;
113 return dpd
->find
.name
;
116 void DatapathCloseDir(DatapathDir
*dpd
)
119 #if defined(__WATCOMC__) || defined(__SC__)
120 _dos_findclose(&dpd
->find
);
122 _findclose(dpd
->findfp
);