📄 find.c
字号:
return DosFindNext (fbuf->dir_handle,
(PFILEFINDBUF)&fbuf->create_date,
sizeof(*fbuf) - sizeof(fbuf->dir_handle),
(PUSHORT)&SearchCount);
#elif defined(NT)
while ( TRUE ) {
if ( !FindNextFile( fbuf->dir_handle, &( fbuf->fbuf ) ) )
return GetLastError();
else if ( AttributesMatch( fbuf ) )
return NO_ERROR;
}
// return( FindNextFile( fbuf->dir_handle, &( fbuf->fbuf ) ) );
#endif
}
#if !defined(NT) || defined(_LM_)
static int
usServFindNext (struct findType *fbuf)
{
BYTE szPattern[CCHPAT];
PSB psb;
SI si;
USHORT isiNext;
#if defined(OS2)
SELECTOROF (psb) = fbuf->dir_handle;
OFFSETOF (psb) = 0;
#elif defined(NT)
// Retrive the psb stored in fbuf->dir_handle
psb = (PSB)fbuf->dir_handle;
#endif
Move (psb->szPattern, szPattern, CCHPAT);
for (isiNext = (USHORT)(psb->isiLast + 1); isiNext < psb->csi; isiNext++) {
si = psb->asi[isiNext];
if (TESTFLAG (psb->attr, A_D) && fMatch (szPattern, si.SV_NAME)) {
psb->isiLast = isiNext;
#if defined(OS2)
fbuf->create_date = fbuf->create_time = 0;
fbuf->access_date = fbuf->access_time = 0;
fbuf->date = fbuf->time = 0;
fbuf->length = fbuf->alloc = 0;
fbuf->attr = A_D;
strcpy (fbuf->name, si.SV_NAME);
fbuf->nam_len = (unsigned char) strlen (fbuf->name);
#elif defined(NT)
fbuf->fbuf.ftCreationTime.dwLowDateTime = 0;
fbuf->fbuf.ftCreationTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastAccessTime.dwLowDateTime = 0;
fbuf->fbuf.ftLastAccessTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastWriteTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastWriteTime.dwLowDateTime = 0;
fbuf->fbuf.nFileSizeLow = 0;
fbuf->fbuf.nFileSizeHigh = 0;
fbuf->attr = A_D;
fbuf->fbuf.dwFileAttributes = A_D;
strcpy (fbuf->fbuf.cFileName, si.SV_NAME);
#endif
return NO_ERROR;
}
}
return ERROR_NO_MORE_FILES;
}
/*** usServFindFirst - set up findbuf to do enumeration on server
*/
static int
usServFindFirst (char *npsz, int attr, struct findType *fbuf)
{
PSB psb;
int erc;
USHORT read, total;
char *npszServ = NULL;
/* If there is no meta matching, just see if server exists
*/
if (*strbscan (npsz, "?*") == 0) {
npszServ = npsz;
#if defined(OS2)
erc = DosAllocSeg (sizeof(SB),
(PSEL) & fbuf->dir_handle,
0x0000);
if (erc != 0)
return erc;
SELECTOROF (psb) = fbuf->dir_handle;
OFFSETOF (psb) = 0;
#elif defined(NT)
if( ( psb = (PSB)malloc( sizeof(SB) ) ) == NULL )
return ERROR_NOT_ENOUGH_MEMORY;
#endif
/* Get array of server info
*/
erc = InNetServerGetInfo (npszServ,
0,
(PBYTE) psb->asi,
sizeof(SI),
&total);
psb->csi = 1;
psb->isiLast = -1;
}
/* Get list of known servers
*/
else {
/* Adjust pattern
*/
if (!strcmp (npsz + 2, "*.*") || !strcmp (npsz + 2, "*."))
strcpy (npsz + 2, "*");
/* Find number of servers
*/
erc = InNetServerEnum (npszServ,
0,
NULL,
0,
&read,
&total);
if (erc != ERROR_MORE_DATA || total == 0)
if (erc != 0)
return erc;
else
return ERROR_NO_MORE_FILES;
/* The LANMAN API's are useless in that it is difficult to get an accurate
* count of bytes necessary to store a particular enumeration. As a
* result, we allocate a max-sized segment and waste space
*/
#if defined(OS2)
erc = DosAllocSeg (0xFFFF,
(PSEL) & fbuf->dir_handle,
0x0000);
if (erc != 0)
return erc;
SELECTOROF (psb) = fbuf->dir_handle;
OFFSETOF (psb) = 0;
#elif defined(NT)
if( ( psb = (PSB)malloc( 0xFFFF ) ) == NULL )
return ERROR_NOT_ENOUGH_MEMORY;
#endif
/* Get array of server info
*/
erc = InNetServerEnum (npszServ,
0,
(PBYTE) psb->asi,
0xFFFF - sizeof (SB),
&read,
&total);
psb->csi = read;
psb->isiLast = -1;
}
/* Fill in search attributes
*/
psb->attr = attr;
Fill (psb->szPattern, 0, CCHPAT);
Move (npsz + 2, psb->szPattern, min (CCHPAT-1, strlen (npsz + 2)));
fbuf->type = FT_SERV;
/* Find/return first matching
*/
if (fnext (fbuf)) {
Fill ((char far *) fbuf, 0, sizeof (*fbuf));
#if defined(OS2)
DosFreeSeg (SELECTOROF (psb));
#elif defined(NT)
free (psb);
#endif
return ERROR_NO_MORE_FILES;
}
return NO_ERROR;
}
/*** usSharFindFirst - begin enumeration of share set
*
* npsz pointer to pattern of the form \\machine\pattern
* attr attribute allowing search
* fbuf buffer for find poop
*/
static int
usSharFindFirst (char *npsz, int attr, struct findType *fbuf)
{
char *npszPat = strbscan (npsz + 2, "\\/");
char *npsz1 = npszPat;
BYTE c = *npszPat;
PSHB pshb;
int erc;
USHORT read, total;
*npszPat++ = 0;
/* npszPat now points to pattern portion
* Adjust pattern
*/
if (!strcmp (npszPat, "*.*") || !strcmp (npszPat, "*."))
npszPat = "*";
/* Find number of shares
*/
erc = InNetShareEnum (npsz,
0,
NULL,
0,
&read,
&total);
if (erc != ERROR_MORE_DATA || total == 0) {
*npsz1 = c;
if (erc != 0)
return erc;
else
return ERROR_NO_MORE_FILES;
}
/* Allocate segment for share data
*/
#if defined (OS2)
erc = DosAllocSeg (0xFFFF,
(PSEL) & fbuf->dir_handle,
0x0000);
if (erc != 0) {
*npsz1 = c;
return erc;
}
SELECTOROF (pshb) = fbuf->dir_handle;
OFFSETOF (pshb) = 0;
#elif defined(NT)
if( ( pshb = malloc( 0xFFFF ) ) == NULL ) {
*npsz1 = c;
return ERROR_NOT_ENOUGH_MEMORY;
}
// Store the pointer to the memory block so it may be used again for the
// next file - cast it to a unsigned and store it in fbuf->dir_handle.
// When retrieved, cast it back to a pointer.
fbuf->dir_handle = ( void * )pshb;
#endif
/* Get array of server info
*/
erc = InNetShareEnum (npsz,
1,
(PBYTE) pshb->ashi,
0xFFFF - sizeof (SHB),
&read,
&total);
pshb->cshi = read;
pshb->ishiLast = -1;
pshb->attr = attr;
Fill (pshb->szPattern, 0, CCHPAT);
Fill (pshb->szServer, 0, CCHPAT);
Move (npszPat, pshb->szPattern, min (CCHPAT-1, strlen (npszPat)));
Move (npsz, pshb->szServer, min (CCHPAT-1, strlen (npsz)));
*npsz1 = c;
fbuf->type = FT_SHAR;
/* Find/return first matching
*/
if (fnext (fbuf)) {
Fill ((char far *) fbuf, 0, sizeof (*fbuf));
#if defined(OS2)
DosFreeSeg (SELECTOROF (pshb));
#elif defined(NT)
free( pshb );
#endif
return ERROR_NO_MORE_FILES;
}
return NO_ERROR;
}
static int
usSharFindNext (struct findType *fbuf)
{
BYTE szPattern[CCHPAT];
PSHB pshb;
SHI shi;
USHORT ishiNext;
// Retrive the psb stored in fbuf->dir_handle
#if defined (OS2)
SELECTOROF (pshb) = fbuf->dir_handle;
OFFSETOF (pshb) = 0;
#elif defined (NT)
pshb = (PSHB)fbuf->dir_handle;
#endif
Move (pshb->szPattern, szPattern, CCHPAT);
for (ishiNext = (USHORT)(pshb->ishiLast + 1); ishiNext < pshb->cshi; ishiNext++) {
shi = pshb->ashi[ishiNext];
if (shi.shi1_netname[strlen (shi.shi1_netname) - 1] != '$' &&
fMatch (szPattern, shi.shi1_netname)) {
if (shi.shi1_type != STYPE_DISKTREE || TESTFLAG (pshb->attr, A_D)) {
pshb->ishiLast = ishiNext;
#if defined(OS2)
fbuf->create_date = fbuf->create_time = 0;
fbuf->access_date = fbuf->access_time = 0;
fbuf->date = fbuf->time = 0;
fbuf->length = fbuf->alloc = 0;
fbuf->attr = shi.shi1_type == STYPE_DISKTREE ? A_D : 0;
strcpy (fbuf->name, shi.shi1_netname);
fbuf->nam_len = (UCHAR) strlen (fbuf->name);
#elif defined(NT)
fbuf->fbuf.ftCreationTime.dwLowDateTime = 0;
fbuf->fbuf.ftCreationTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastAccessTime.dwLowDateTime = 0;
fbuf->fbuf.ftLastAccessTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastWriteTime.dwHighDateTime = 0;
fbuf->fbuf.ftLastWriteTime.dwLowDateTime = 0;
fbuf->fbuf.nFileSizeLow = 0;
fbuf->fbuf.nFileSizeHigh = 0;
fbuf->fbuf.dwFileAttributes =
fbuf->attr = shi.shi1_type == STYPE_DISKTREE ? A_D : 0;
strcpy (fbuf->fbuf.cFileName, shi.shi1_netname);
#endif
return NO_ERROR;
}
}
}
return ERROR_NO_MORE_FILES;
}
static int
usLoadNet ()
{
#if defined(OS2)
int erc;
#endif
if (hmodAPI != 0)
return NO_ERROR;
#if defined(OS2)
if ((erc = DosLoadModule (NULL, 0, "netoem", &hmodOEM)) != 0)
return erc;
if ((erc = DosGetProcAddr (hmodOEM, "NETSERVERENUM", (PFN far *)&pNetServerEnum)) != 0)
return erc;
if ((erc = DosLoadModule (NULL, 0, "netapi", &hmodAPI)) != 0)
return erc;
if ((erc = DosGetProcAddr (hmodAPI, "NETSERVERGETINFO", (PFN far *)&pNetServerGetInfo)) != 0)
return erc;
return DosGetProcAddr (hmodAPI, "NETSHAREENUM", (PFN far *)&pNetShareEnum);
#elif defined(NT)
if( !( hmodAPI = LoadLibrary( "netapi32" ) ) ||
#pragma message ("Known different function parameter lists")
!( pNetServerEnum = GetProcAddress( hmodAPI, "NETSERVERENUM" ) ) ||
#pragma message ("Known different function parameter lists")
!( pNetShareEnum = GetProcAddress( hmodAPI, "NETSHAREENUM" ) ) ||
#pragma message ("Known different function parameter lists")
!( pNetServerGetInfo = GetProcAddress( hmodAPI, "NETSERVERGETINFO" ) ) )
return( GetLastError() );
else
return( 0 );
#endif
}
#endif // !NT || _LM_
#if defined(NT)
static InNetServerGetInfo (const char *pszServer,
short sLevel,
char *pbBuffer,
unsigned short cbBuffer,
unsigned short *pcbTotalAvail)
{
int status;
LPBYTE bufGiven;
status = (*pNetServerGetInfo) (
IN (LPTSTR) pszServer,
IN (DWORD) sLevel,
OUT (LPBYTE *) &bufGiven
);
memmove(pbBuffer, bufGiven, cbBuffer);
free(bufGiven);
*pcbTotalAvail = 0; //Return isn't used here
return status;
}
static InNetServerEnum (const char *pszServer,
short sLevel,
char * pbBuffer,
unsigned short cbBuffer,
unsigned short *pcEntriesRead,
unsigned short *pcTotalAvail)
{
DWORD entriesread, totalentries;
LPBYTE bufGiven;
int status;
status = (*pNetServerEnum) (
IN (LPTSTR) pszServer,
IN (DWORD) sLevel,
OUT (LPBYTE *) &bufGiven,
IN (DWORD) cbBuffer,
OUT (LPDWORD) &entriesread,
OUT (LPDWORD) &totalentries,
IN (DWORD) SV_TYPE_ALL,
IN (LPTSTR) NULL,
IN OUT (LPDWORD) NULL
);
memmove(pbBuffer, bufGiven, cbBuffer);
free(bufGiven);
*pcEntriesRead = (USHORT) entriesread;
*pcTotalAvail = (USHORT) totalentries;
return status;
}
static InNetShareEnum (const char *pszServer,
short sLevel,
char * pbBuffer,
unsigned short cbBuffer,
unsigned short *pcEntriesRead,
unsigned short *pcTotalAvail)
{
DWORD entriesread, totalentries;
static DWORD resume_handle = 0;
LPBYTE bufGiven;
int status;
status = (*pNetShareEnum) (
IN (LPTSTR) pszServer,
IN (DWORD) sLevel,
OUT (LPBYTE *) &bufGiven,
IN (DWORD) cbBuffer,
OUT (LPDWORD) &entriesread,
OUT (LPDWORD) &totalentries,
IN OUT (LPDWORD) resume_handle
);
memmove(pbBuffer, bufGiven, cbBuffer);
free(bufGiven);
*pcEntriesRead = (USHORT) entriesread;
*pcTotalAvail = (USHORT) totalentries;
return status;
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -