home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1994 September
/
Simtel-MSDOS-Sep1994-CD1.iso
/
disc1
/
filedocs
/
simsrch2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-20
|
9KB
|
319 lines
/******************************************************************************
SIMSERCH: This program facilitates searching through the SIMIBM.IDX file
available from the SIMTEL archives. It supports keyword searches
within selectable fields, starting and ending date boundaries,
and user specified index files. It can also create (or append to)
a SIMTEL request file which is suitable for e-mailing to the
SIMTEL list servers.
This program will compile and run under Turbo-C 2.0,
UNIX ANSI C, and VAX/VMS C.
This program is FREEWARE, and comes with NO WARRANTEES,
expressed or implied.
Author: Richard W. Hull <hull@skvax1.csc.ti.com>
Acknowledgements:
Ed. Mueller and Larry Johnson for providing valuable inputs and
for insisting that I submit the results to SIMTEL.
Usage: simserch [?]
[-]
[-s[fdnx] search-string]
[-d[se] start/end date]
[-i index-file]
[-r[a] simtel-request-file]
Note: Use "-" on VAX/VMS to list all files (including quotes),
other systems accept (-) flag w/o quotes.
Modification History:
V1.0 Original by Richard W. Hull <hull@skvax1.csc.ti.com>
V1.1 20-Apr-94, J. Mathews <mathews@nssdca.gsfc.nasa.gov>
Substituted strchr for strstr in most places,
added '-' flag to list all files (default
action w/no args shows usage),
and other minor modifications.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __TURBOC__
#include <ctype.h>
char *strlwr(arg)
char *arg;
{
char *arg_save = arg;
while( *arg )
{
*arg = tolower( *arg );
arg++;
}
return( arg_save );
}
#endif
#ifndef bool
#define bool char
#endif
void usage( errcode )
short errcode;
{
if (errcode)
{
printf( "simserch: ERROR: Invalid %s\n\n",
(errcode == 1) ? "number of parameters" : "parameter");
}
printf( "Usage: simserch [?] [-]\n" );
printf( " [-s[fdnx] search-string]\n" );
printf( " [-i index-file-name]\n" );
printf( " [-d[se] start/end date]\n" );
printf( " [-r[a] simtel-request-file]\n" );
printf( "\n" );
printf( " -s [f search FILE-SYSTEM\n" );
printf( " d DIRECTORY\n" );
printf( " n NAME\n" );
printf( " x DESCRIPTION]\n" );
printf( " Default is to search ALL fields.\n" );
printf( "\n" );
printf( " -d [s starting date\n" );
printf( " e ending date]\n" );
printf( " Default is Starting-Date\n" );
printf( " Date format is YYMMDD.\n" );
printf( "\n" );
printf( " -r [a append to Request File]\n" );
printf( " Default is to Overwrite Request File.\n" );
exit(0);
}
int main(argc, argv)
int argc; char *argv[];
{
FILE *index_file, *simreq_file; /* input file */
char fs[10],dir[60],name[15],descr[60]; /* input variables */
char inputline[257]; /* for initial read */
int rev,bits; /* input variables */
long length,date,sdate,edate; /* input variables */
char lfs[10],ldir[60]; /* stores last filesystem/directory */
char type; /* output variable for 'A' or 'B' */
char searchstr[40]; /* string to qualify entries */
bool search_fs, search_dir,
search_name, search_desc; /* indicates which fields to search */
char teststr[257]; /* combo of fs,dir,name,descr */
char ndxfilnam[100]; /* name of input index file */
char reqfilnam[100]; /* SIMTEL request file */
bool append_to_req; /* Flag for opening SIMTEL req file */
long tot_files, sel_files; /* total, selected files */
long tot_ldate, sel_ldate; /* total, selected last date */
int i;
sdate = 0;
edate = 999999;
searchstr[0] = '\0';
#ifdef VAX11C
strcpy( ndxfilnam, "USER2:[HULL]SIMIBM.IDX" );
#else
strcpy( ndxfilnam, "simibm.idx" );
#endif
reqfilnam[0] = '\0';
tot_files = sel_files = tot_ldate = sel_ldate = 0;
if (argc==1) usage(0); /* no arguments */
if (strchr(argv[1], '?' )) usage(0);
for (i=1; i < argc; i++)
{
if (*argv[i] != '-') usage(2); /* invalid param */
/*
* All parameters require an option argument, except for the '-' flag.
*/
if (argv[i][1] != 0)
{
if (i+1 == argc)
usage(1); /* Error if no option argument is available */
switch (argv[i][1]) {
case 's':
search_fs = search_dir = search_name = search_desc = 0;
strcpy( searchstr, argv[i+1] );
strlwr( searchstr );
/* Look for mention of specific fields to search */
if (strchr( argv[i], 'f' )) search_fs = 1;
if (strchr( argv[i], 'd' )) search_dir = 1;
if (strchr( argv[i], 'n' )) search_name = 1;
if (strchr( argv[i], 'x' )) search_desc = 1;
/* If no specific fields were mentioned, search everything */
if (!(search_fs || search_dir || search_name || search_desc))
search_fs = search_dir = search_name = search_desc = 1;
break;
case 'd':
if (strchr( argv[i], 'e' ))
{
sscanf( argv[i+1], "%ld", &edate );
if (strchr( argv[i], 's' ))
sdate = edate;
}
else
sscanf( argv[i+1], "%ld", &sdate ); /* default date */
break;
case 'i':
strcpy( ndxfilnam, argv[i+1] );
strlwr( ndxfilnam );
break;
case 'r':
strcpy( reqfilnam, argv[i+1] );
strlwr( reqfilnam );
append_to_req = (argv[i][2] == 'a');
break;
default:
usage(2); /* invalid param */
} /* switch */
i++; /* increment to next argument - skip option argument */
} /* if */
} /* for */
printf("SimTel MS-DOS Files Listing\n\n");
if (searchstr[0])
{
printf( "Will search " );
if (search_fs) printf( "FILE-SYSTEM " );
if (search_dir) printf( "DIRECTORY " );
if (search_name) printf( "NAME " );
if (search_desc) printf( "DESCRIPTION " );
printf( "for: %s\n", searchstr );
}
if (sdate > 0)
printf( "Starting Date: %ld\n", sdate );
if (edate < 999999)
{
printf( "Ending Date: %ld\n", edate );
}
printf( "Index File to be searched is: %s\n", ndxfilnam );
if (!(index_file = fopen( ndxfilnam, "r" )))
{
printf( "\nCould not open Index File: %s\n", ndxfilnam );
exit(0);
}
if (reqfilnam[0])
{
char *open_mode;
if (append_to_req)
{
open_mode = "a";
printf( "Selected Files will be appended to: %s\n", reqfilnam );
}
else
{
open_mode = "w";
printf( "Selected Files will be written to: %s\n", reqfilnam );
}
if (!(simreq_file = fopen( reqfilnam, open_mode )))
{
printf( "\nCould not open Request File: %s\n", reqfilnam );
exit(0);
}
}
printf("\nNOTE: Type B is Binary; Type A is ASCII\n");
inputline[256] = 0;
while (fgets(inputline, 256, index_file) != NULL) {
sscanf(inputline,
"\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",%d,%ld,%d,%ld,\"%[^\"]\"",
fs, dir, name, &rev, &length, &bits, &date, descr);
tot_files++;
if (date > tot_ldate) tot_ldate = date;
if (date < sdate || date > edate) continue;
teststr[0] = '\0';
if (search_fs)
{
strcat( teststr, fs );
strcat( teststr, " " );
}
if (search_dir)
{
strcat( teststr, dir );
strcat( teststr, " " );
}
if (search_name)
{
strcat( teststr, name );
strcat( teststr, " " );
}
if (search_desc)
{
strcat( teststr, descr );
strcat( teststr, " " );
}
/*
sprintf( teststr, "%s %s %s %s", fs, dir, name, descr );
*/
strlwr( teststr );
if ( (searchstr[0]) && !( strstr( teststr, searchstr ) ) )
continue;
sel_files++;
if (date > sel_ldate) sel_ldate = date;
type = (bits == 7) ? 'A' : 'B'; /* ASCII 7-bit or Binary 8-bit */
if (strcmp(ldir,dir) || strcmp(lfs,fs)) { /* New Directory */
printf("\nDirectory %s%s\n",fs,dir);
printf(" Filename Type Length Date Description\n");
printf("==============================================\n");
strcpy(ldir, dir); /* Remember last directory with ldir */
strcpy(lfs,fs); /* Remember last file system with lfs */
} /* End of the New Directory routine */
printf("%-12.12s %c %7ld %6ld %s\n",name,type,length,date,descr);
if (reqfilnam[0]) fprintf( simreq_file, "/PDGET %s%s%s UUENCODE\n",
fs, dir, name );
} /* while */
if (reqfilnam[0]) fclose( simreq_file );
printf( "\n\nNumber of Files (Total/Processed): %ld / %ld\n",
tot_files, sel_files );
printf( "Last Date for Files (Total/Processed): %ld / %ld\n",
tot_ldate, sel_ldate );
return (1) ;
} /* end of main() */