home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
16
/
FREEDOS.ZIP
/
FD_A4PRE.ZIP
/
SOURCE
/
MICROC.ZIP
/
FFF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-01
|
6KB
|
256 lines
/*
FFF.C "Fast File Find" (C) 1991 John Hall
Original code by: John Hall
Ported to MICRO-C by: M. "Hannibal" Toal
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Changes:
JH 1991 Original Program as received from James Hall.
MT April 1995 Ported to MICRO-C.
Eliminated external function getinfo().
Some constant values changed from Decimal to Hex.
Attempt made at duplicating fnsplit () function.
Added usage, getopt, and pagel freedos functions.
Aesthetic changes to make like other Free-DOS progs.
*/
#include <stdio.h>
#include "freedos.h" /* Free-DOS header file and functions */
#include "getopt.c" /* for parsing options */
#include "fsplit.c" /* to split file names into components */
#include "pagel.c" /* page by single output line */
/* extern int _AX_, _CX_, _DX_, Cflags; */
/* Symbolic constants */
#define FIRST 0x4e00
#define NEXT 0x4f00
#define FILE 6
#define DIR 16
#define FALSE 0
#define TRUE ! FALSE
#define MAXLINES 24
#define MAXARRAY 256
/* Function prototypes */
char *get_dir ( char *drive, char *dir ); /* Builds full search dir */
char *get_name ( char *fname, char *ext ); /* Builds full search spec */
void depth_search( char *dir, char *name ); /* Recursively searches */
int search( char *fname, int flag, int type ); /* Search for filespec */
void set_dta( char *ptr ); /* Sets DTA */
void display( char *dir, char *dta, int flag ); /* Prints file info */
void print( char *string ); /* Prints a line */
void quit( int error ); /* Handles errors */
int fcount, PAGE; /* line page count */
main( int argc, char *argv[] )
{
char drive[MAXARRAY]; /* Drive to search */
char dir[MAXARRAY]; /* Directory to start from */
char fname[MAXARRAY]; /* File name to search for */
char ext[6]; /* File extension to search for */
int i; /* Loop control variable */
LINECOUNT = 1;
PAGE = FALSE;
/* Parse to see if there are any switches */
while ((i = getopt (argc, argv, "P?", NULL)) != EOF)
{
switch (i)
{
case 'P':
PAGE = TRUE;
break;
default:
usage ();
}
};
/* Check for no arguments on the command line */
if( argc == 1 )
quit( 1 );
printf ("Fast File Find: ");
for (i = optind; i < argc; i++)
printf ("%s ", argv[i]);
/* Search for files */
for( i = optind; i < argc; i++)
{
/* Split apart pathspec */
strupr (argv[i]);
fnsplit (argv[i], drive, dir, fname, ext);
/* Search for file */
depth_search (get_dir (drive, dir), get_name (fname, ext));
}
/* Return to DOS */
quit( 0 );
}
char *get_dir( char *drive, char *dir )
{
/* Test for empty drive spec */
if(!drive[0])
sprintf (drive, "%c%c\0", get_drive() + 'A', ':' );
/* Test for empty directory */
if(!dir[0])
strcpy (dir, "\\");
/* Remove trailing backslash from directory */
if (dir[strlen(dir)-1] == '\\')
dir [strlen(dir)-1] = '\0';
/* Return full directory name */
strcat (drive, dir);
return drive;
}
char *get_name( char *fname, char *ext )
{
/* Test for empty extension */
if (!ext[0])
strcpy( ext, ".*" );
/* Add wildcards to filespec and return result */
if (!fname[0])
strcpy (fname, "*");
strcat (fname, ext);
return fname;
}
void depth_search( char *dir, char *name )
{
char filename[256]; /* File name to search for */
char dirname[256]; /* Directory name to search */
char dta[43]; /* Disk transfer area */
int flag; /* Search type flag */
/* Create a filespec */
sprintf( filename, "%s\\%s", dir, name );
/* Set the DTA to the local DTA buffer */
set_dta( dta );
/* Search for the file */
flag = FIRST;
while( search( filename, flag, FILE ) ) {
display( dir, dta, flag );
flag = NEXT;
}
/* Create a pathspec */
sprintf( filename, "%s\\*.", dir );
/* Search for a subdirectory */
flag = FIRST;
while( search( filename, flag, DIR ) ) {
flag = NEXT;
/* Specifically exclude "." and ".." fron search */
if( strcmp( ".", dta+30 ) && strcmp( "..", dta+30 ) ) {
sprintf( dirname, "%s\\%s", dir, dta+30 );
depth_search( dirname, name );
}
/* Return to local DTA buffer for next directory */
set_dta( dta );
}
}
int search( char *fname, int flag, int type )
{
/* Set up calling registers */
_AX_ = flag;
_CX_ = type;
_DX_ = fname;
if (int86(0x21) & 0x01)
return FALSE;
else
return TRUE;
}
void set_dta( char *ptr )
{
/* Set up calling registers */
_AX_ = 0x1A00;
_DX_ = ptr;
int86 (0x21);
}
void display( char *dir, char *dta, int flag )
{
/* Test for new directory */
if( flag == FIRST ) {
/* Print directory name */
print( "" );
print( dir );
}
/* Print file name and info */
print (dta+0x1E);
/* Increment number of files found */
fcount++;
}
void print( char *string )
{
/* Paginate display */
if (PAGE == TRUE)
pagel (string);
else
printf ("%s\n", string);
}
void quit( int error )
{
switch( error )
{
case 1:
usage ();
break;
default:
/* Print total number of files found */
printf( "\n%d files found.\n", fcount );
}
/* Exit to DOS with return code */
exit( error );
}
void usage (void)
{
printp ("FFF", "Fast File Find");
printc ("1991", "John Hall and RVS Utilities");
printu ("FFF", "[/P] [filespec..]");
printo ("P", "Paginate output");
exit (0);
}