home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
MSGDP206.SZH
/
DIR.C
< prev
next >
Wrap
Text File
|
1991-01-07
|
6KB
|
242 lines
/*
* released into the PUBLIC DOMAIN 30 jul 1990 by jim nutt
*/
#include <stdlib.h>
#include <errno.h>
#include <dos.h>
#define _pascal pascal
#ifdef __OS2__
#include <sys\types.h>
#define INCL_DOSPROCESS
#include <os2.h>
#include <sys\stat.h>
#include <ctype.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
static struct _FILEFINDBUF InfoBuf;
static struct find_t dta;
HDIR hDir;
USHORT cSearch;
USHORT usAttrib;
#define FILENAMELEN 13
int _pascal dir_findfirst(char * filename, int attribute, struct find_t * dta)
{
hDir = 0x0001;
usAttrib = attribute;
cSearch = 1;
#ifdef DEBUG
printf("\nDIR_FINDFIRST Inputs: '%s' %d.\n", filename, attribute);
#endif /* of DEBUG */
if (DosFindFirst( filename
, &hDir
, usAttrib
, &InfoBuf
, (USHORT)( sizeof(InfoBuf) * cSearch )
, &cSearch
, (ULONG)NULL ) != 0 )
{
#ifdef DEBUG
printf("DIR_FINDFIRST: DosFindFirst returned <>0.\n");
#endif /* of DEBUG */
DosFindClose( hDir );
errno = ENOENT;
return (-1);
} else {
#ifdef DEBUG
printf("DIR_FINDFIRST: DosFindFirst returned 0.\n");
printf("DIR_FINDFIRST: attrFile = %d.\n", InfoBuf.attrFile);
#endif /* of DEBUG */
dta->attrib = (char)InfoBuf.attrFile; /**OS2**/
dta->size = InfoBuf.cbFile;
strcpy( dta->name, InfoBuf.achName);
errno = 0;
return (0);
}
}
int _pascal dir_findnext(struct find_t * dta)
{
if ((DosFindNext( hDir
, &InfoBuf
, (USHORT)(FILENAMELEN + 23)
, &cSearch)
) || (cSearch != 1))
{
DosFindClose( hDir );
errno = ENOENT;
return (-1);
} else {
dta->attrib = (char)InfoBuf.attrFile; /**OS2**/
dta->size = InfoBuf.cbFile;
strcpy( dta->name, InfoBuf.achName);
errno = 0;
return (0);
}
}
static struct _FILEFINDBUF InfoBuf1;
HDIR hDir1;
USHORT cSearch1;
USHORT usAttrib1;
int _pascal dir_findfirst1(char * filename, int attribute, struct find_t * dta)
{
hDir1 = 0xffff;
usAttrib1 = attribute;
cSearch1 = 1;
#ifdef DEBUG
printf("\nDIR_FINDFIRST1 Inputs: '%s' %d.\n", filename, attribute);
#endif /* of DEBUG */
if (DosFindFirst( filename
, &hDir1
, usAttrib1
, &InfoBuf1
, (USHORT)( sizeof(InfoBuf1) * cSearch1 )
, &cSearch1
, (ULONG)NULL ) != 0 )
{
#ifdef DEBUG
printf("DIR_FINDFIRST1: DosFindFirst returned <>0.\n");
#endif /* of DEBUG */
DosFindClose( hDir1 );
errno = ENOENT;
return (-1);
} else {
#ifdef DEBUG
printf("DIR_FINDFIRST1: DosFindFirst returned 0.\n");
printf("DIR_FINDFIRST1: attrFile = %d.\n", InfoBuf1.attrFile);
#endif /* of DEBUG */
dta->attrib = (char)InfoBuf1.attrFile; /**OS2**/
dta->size = InfoBuf1.cbFile;
strcpy( dta->name, InfoBuf1.achName);
errno = 0;
return (0);
}
}
int _pascal dir_findnext1(struct find_t * dta)
{
if ((DosFindNext( hDir1
, &InfoBuf1
, (USHORT)(FILENAMELEN + 23)
, &cSearch1)
) || (cSearch1 != 1))
{
DosFindClose( hDir1 );
errno = ENOENT;
return (-1);
} else {
dta->attrib = (char)InfoBuf1.attrFile; /**OS2**/
dta->size = InfoBuf1.cbFile;
strcpy( dta->name, InfoBuf1.achName);
errno = 0;
return (0);
}
}
#else /* of __OS2__ */
struct _dta {
char reserved[21];
char attribute;
unsigned time;
unsigned date;
long size;
char name[13];
};
static int olddta = 0;
int _pascal dir_findnext(struct _dta * dta);
int _pascal dir_findfirst(char * filename, int attribute, struct _dta * dta);
int _pascal dir_findfirst(char * filename, int attribute, struct _dta * dta)
{
union REGS ir;
union REGS or;
#ifndef SPTR
struct SREGS sr;
#endif
ir.h.ah = 0x1a;
#ifdef SPTR
ir.x.dx = (unsigned int) dta;
intdos(&ir,&or);
#else
ir.x.dx = FP_OFF(dta);
sr.ds = FP_SEG(dta);
intdosx(&ir, &or, &sr);
#endif
ir.h.ah = 0x4e;
ir.x.cx = (unsigned int) attribute;
#ifdef SPTR
ir.x.dx = (unsigned int) filename;
intdos(&ir,&or);
#else
ir.x.dx = FP_OFF(filename);
sr.ds = FP_SEG(filename);
intdosx(&ir, &or, &sr);
#endif
if (or.x.cflag) {
errno = ENOENT;
return (-1);
}
errno = 0;
return (0);
}
int _pascal dir_findnext(struct _dta * dta)
{
union REGS ir, or;
#ifndef SPTR
struct SREGS sr;
#endif
ir.h.ah = 0x1a;
if (!olddta) {
#ifdef SPTR
ir.x.dx = (unsigned int) dta;
intdos(&ir,&or);
#else
ir.x.dx = FP_OFF(dta);
sr.ds = FP_SEG(dta);
intdosx(&ir, &or, &sr);
#endif
olddta = 1;
}
ir.h.ah = 0x4f;
intdos(&ir,&or);
if (or.x.cflag) {
errno = ENOENT;
return (-1);
} else {
errno = 0;
return (0);
}
}
#endif /* of __OS2__ */