home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
NEWLL.ZIP
/
NEWLL.C
< prev
next >
Wrap
Text File
|
1990-05-18
|
5KB
|
244 lines
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BUFLEN sizeof(buff)
#define PATH_LEN 80
#define ATTR 0x0037
#define DIRECTORY 0x0010
#define NO_MORE_FILES 18
#define LINES_PER_PAGE 25
USHORT cdecl main ( INT argc, CHAR *argv[] );
UCHAR *lowercase ( UCHAR *str );
VOID pinfo ( USHORT rc );
VOID GetCommandLineOptions ( INT argc, CHAR *argv[] );
struct _FILEFINDBUF buff;
USHORT handle=0xFFFF;
CHAR *filenames[2000];
CHAR msg[80];
CHAR CommandLineOptions[80];
INT num_of_files = 0;
BOOL done = FALSE;
INT i,j;
INT width = 5;
INT option = 0;
ULONG total_bytes = 0;
UCHAR *lowercase(UCHAR *str)
{
while (*str)
{
(*str) = tolower( (*str) );
str++;
}
}
VOID get_commandline_options(INT start, INT argc, CHAR *argv[])
{
INT i,j,k;
strcpy(CommandLineOptions," ");
k = 1;
if (argc < start) return;
for (i=start; i < argc; i++)
for (j=0; j <= strlen( (CHAR *) argv[i][0] ); j++)
if ((argv[i][j] == '-') && (j+1 <= strlen((CHAR *) argv[i][0])))
{
CommandLineOptions[k++] = argv[i][j+1];
CommandLineOptions[k] = '\0';
}
}
INT FileCompare ( CHAR ** filename1, CHAR ** filename2 )
{
return ( strncmp ( *filename1, *filename2, 13 ) );
}
USHORT cdecl main ( INT argc, CHAR *argv[] )
{
CHAR path[PATH_LEN];
USHORT SearchCount = 1;
INT rc;
if (argv[1][0] == '-')
get_commandline_options(1, argc, argv );
else
get_commandline_options(2, argc, argv );
printf("Dual Mode Directory Lister (c) 1990 By Mark \n");
lowercase(CommandLineOptions);
if (strstr(CommandLineOptions,"h") != 0 )
{
printf("\n CommandLine Options \n");
printf(" -s Display File Sizes \n");
printf(" -h Show Commandline Switches \n");
return ( FALSE );
}
if (strstr(CommandLineOptions,"s") != 0 )
{
option = 1; width = 3;
}
if (strstr(CommandLineOptions,"t") != 0)
{
option = 2; width = 2;
}
if ( argc < 2 )
strcpy ( path , "*.*" );
else if (argv[1][0] == '-')
strcpy ( path, "*.*" );
else if ( strcmp (argv[1], "\\") == 0)
{
strcpy ( path, argv[1] );
strcat ( path, "*.*");
}
else if ( strcspn (argv[1],"*?.") < strlen(argv[1] ))
strcpy ( path, argv[1] );
else
{
strcpy (path, argv[1]);
/* strcat(path,"\\*.*"); */
if (argv[1][0] == ':' && (argv[1][1] == ' ' || argv[1][1] == '\0'))
strcat(path,"\\*.*");
else
strcat(path,"*.*");
}
if (_osmode)
printf("OS/2 Protected Mode ");
else
printf("DOS Real Mode ");
printf("[%s] \n",path );
rc = DosFindFirst ( path, &handle, ATTR, &buff,
BUFLEN, &SearchCount, 0L );
pinfo ( rc );
while ( !done )
{
rc = DosFindNext ( handle, &buff, BUFLEN, &SearchCount );
pinfo ( rc );
}
qsort ( filenames, num_of_files, sizeof ( char *), FileCompare );
for (i= 0; i < num_of_files; i += width)
{
strcpy(msg,filenames[i]);
j = i+1;
while (j < num_of_files && j < i+width)
{
strcat(msg," ");
strcat(msg,filenames[j++]);
}
printf("%s\n",msg);
}
if (num_of_files > 0)
printf("\n %i File(s) , %lu Bytes \n",num_of_files,total_bytes);
else
printf("\n No Files were Found! \n");
for (i=0; i < num_of_files; i++)
free ( filenames[i]);
return ( FALSE );
}
VOID pinfo ( USHORT rc )
{
if ( rc )
{
if ( rc == NO_MORE_FILES )
{
DosFindClose ( handle ) ;
done = TRUE;
return;
}
else
{
printf(" \n Invalid Specification !\n");
printf(" Task Aborted Error Code = %i\n",rc);
num_of_files = -1;
done = TRUE;
return;
}
}
else
{
if ( buff.attrFile & DIRECTORY )
{
switch ( option )
{
case 0: sprintf(msg,"/%-14s",buff.achName); break;
case 1: sprintf(msg,"%-14s%-6s ",buff.achName," <dir>" );break;
case 2: sprintf(msg,"%-14s%-6s %2i/%02i/%04i %02i:%02i",
buff.achName," <dir>",
buff.fdateLastWrite.month,
buff.fdateLastWrite.day,
buff.fdateLastWrite.year+1980,
buff.ftimeLastWrite.hours,
buff.ftimeLastWrite.minutes); break;
}
}
else
{
switch ( option )
{
case 0: sprintf(msg,"%-14s ",buff.achName); break;
case 1: sprintf(msg,"%-14s%6lu ",buff.achName,buff.cbFile); break;
case 2: sprintf(msg,"%-14s%6lu %2i/%02i/%04i %02i:%02i",
buff.achName,buff.cbFile,
buff.fdateLastWrite.month,
buff.fdateLastWrite.day,
buff.fdateLastWrite.year+1980,
buff.ftimeLastWrite.hours,
buff.ftimeLastWrite.minutes); break;
}
}
filenames[num_of_files] = (char *) malloc(sizeof(msg));
if (filenames[num_of_files] == NULL)
{
printf("*** Memory Error ***\n"); exit(1);
}
lowercase(msg);
strcpy(filenames[num_of_files],msg);
num_of_files++;
total_bytes += buff.cbFile;
}
}