home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
DOWN.ZIP
/
DOWN.C
next >
Wrap
Text File
|
1988-11-02
|
4KB
|
234 lines
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <search.h>
char subdir[99][32]
, buf[64]
, search[32]
;
USHORT wCount
;
HDIR hDirectory
;
ULONG ulMask
;
FILEFINDBUF ffbDirentry
;
list_dirs(char *);
void main(int argc
, char *argv[]
)
{
int count
, j
;
if (argc > 1)
{
strcpy( search
, argv[1]
);
if (strchr( search, '?') != NULL)
{
printf("\nuse: down [?] [-?] [subdir]");
printf("\nVersion 3.0 (C) Copyright 1988 QMI\n");
DosExit(1,0);
}
if (DosChdir( search
, 0L
) == 0
)
{
wCount = sizeof(buf);
DosQCurDir( 0
, buf
, &wCount
);
DosQCurDisk( &wCount
, &ulMask
);
printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
DosExit(1,0);
}
else
{
strcat( search, "*.*");
}
}
else
strcpy(search, "*.*");
count = list_dirs( search);
if (count == 0)
{
printf("\nNo subdirectories found...\n");
DosExit(1,0);
}
if (count == 1)
{
wCount = sizeof(buf);
DosQCurDir( 0
, buf
, &wCount
);
DosQCurDisk( &wCount
, &ulMask
);
printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
DosExit(1,0);
}
printf("\n\nDirectory Change to: ");
gets(buf);
j = atoi(buf);
if (j)
{
if ((j > 0) && (j <= count))
DosChdir( subdir[j]
, 0L
);
}
else
{
DosChdir( buf
, 0L
);
}
wCount = sizeof(buf);
DosQCurDir( 0
, buf
, &wCount
);
DosQCurDisk( &wCount
, &ulMask
);
printf("\n==>%c:\\%s\n", 'A'+ wCount - 1, buf);
DosExit(1,0);
}
list_dirs(char *search)
{
int at,i,j = 0, n1, n2;
int dcount
, count = 0;
wCount = 1;
hDirectory = 0xFFFF;
if (DosFindFirst( search
, &hDirectory
, (USHORT) 0x0010
, &ffbDirentry
, (USHORT) sizeof(ffbDirentry)
, &wCount
, 0L
) == 0
)
{
at = ffbDirentry.attrFile;
if ((at == 0x0010) && (at != 0x0008) && (ffbDirentry.achName[0] != '.'))
strcpy(subdir[++count], ffbDirentry.achName);
}
else
{
printf("\nNo directory found that matches specification...\n");
DosExit(1,0);
}
while (TRUE)
{
wCount = 1;
if (!DosFindNext( hDirectory
, &ffbDirentry
, (USHORT) sizeof(ffbDirentry)
, &wCount
)
)
{
at = ffbDirentry.attrFile;
if ((at == 0x0010) && (at != 0x0008) && (ffbDirentry.achName[0] != '.'))
strcpy(subdir[++count], ffbDirentry.achName);
}
else
break;
}
subdir[count+1][0] = '\0';
subdir[count+2][0] = '\0';
switch (count)
{
case 0:
break;
case 1:
DosChdir( subdir[1]
, 0L
);
break;
default:
qsort( subdir[1]
, count
, 32
, strcmp
);
dcount = count/3;
switch(count%3)
{
case 0:
n1 = dcount;
n2 = n1 + dcount;
break;
case 1:
n1 = dcount + 1;
n2 = n1 + dcount;
break;
case 2:
n1 = dcount + 1;
n2 = n1 + dcount + 1;
break;
}
for (i=1; i<=dcount; i++)
{
printf("\n%3d. %-16s%3d. %-16s%3d. %-12s", i, subdir[i], i+n1, subdir[i+n1], i+n2, subdir[i+n2]);
}
switch (count%3)
{
case 0:
break;
case 1:
printf("\n%3d. %-12s", dcount+1, subdir[dcount+1]);
break;
case 2:
printf("\n%3d. %-16s%3d. %-12s", dcount+1, subdir[dcount+1], dcount+n1+1, subdir[dcount+n1+1]);
break;
}
return( count);
}
return( count);
}