Category : File Managers
Archive   : FILIR11.ZIP
Filename : FILIR.C

 
Output of file : FILIR.C contained in archive : FILIR11.ZIP

/*
TITLE: FILIR (File List Reconciliation);
VERSION: 1.1;
DATE: 11/15/1988;
KEYWORDS: BBS, sysop, file, directory, utility;
SYSTEM: MS-DOS v2.1 or higher;
FILENAME: FILIR.C;
SEE-ALSO: FILIR.DOC, FILIR.MAK, README.1ST;
COMPILER: Microsoft QuickC v1.01 (large memory model);

AUTHOR: "Eric T. Burleyson
9409 52nd Avenue
College Park, Md. 20740";

DESCRIPTION: "FILIR is a program I wrote to help me reconcile my BBS file
lists. FILIR compares the list of files that I keep for my
BBS versus the files that actually exist on the disk. FILIR
was written for the PHOENIX v1.06 BBS system, but it should
work with PCBOARD or other BBS systems that use standard
ASCII file lists. See the DOC file for file layouts and
further information.";

WARNINGS: "No attempt has been made in this version to write portable C
code -- Microsoft non-ANSI extensions can probably be found
throughout. (If you convert this to Turbo C, please let me
know. Thanks in advance.)
Minimum memory and disk space requirements have not yet been
determined; actual memory and disk space requirements are
dependent on the number of files FILIR has to process.
This program also served as an exercise in C programming
(it's my first C program of substance). Expert C
programmers please forgive any abuses that you find. (Even
better, tell me about them!)
I have made this version of the source code available for
non-profit use. If you incorporate it within any of you own
non-profit programs, please give me credit. If you wish to
use it within for-profit, commercial, or shareware software,
or in a business environment, please contact me first (I'll
be very reasonable -- I just want to keep track of my own
ideas)."

*/
#include
#include
#include
#include
#include
#include
#include

#define p_name "FILIR"
#define p_vers "v1.1"
#define p_desc "File List Reconciliation"
#define p_copy "Copyright (c) 1988 Eric T. Burleyson"

#define maxfiles 1000 /* maximum number of files in list or on disk */
#define maxcomments 25 /* maximum number of preserved comments */

/* return status values */
#define st_normal 0 /* no errors */
#define st_nolist 1 /* no directory list file given */
#define st_realmax 2 /* more than maxfiles found */
#define st_listmax 3 /* more than maxfiles in list */
#define st_nomem 4 /* out of memory */
#define st_filerr 5 /* output file error */

/* configuration flags -- flags have discrete values */
#define numflags 5
#define cf_size 0
#define cf_date 1
#define cf_desc 2
#define cf_date2 3
#define cf_color 4
char *cf_names[numflags] = { "Size", "Date", "Desc", "Date2", "Color" };

#define numflagvals 3
#define cf_val_real 0
#define cf_val_list 1
#define cf_val_none 2
#define cf_default 3
char *cf_values[numflagvals] = {"File","List","None"};

/* configuration parameters -- parms are arbitrary strings */
#define numparms 4
#define cp_dirfile 0
#define cp_inmask 1
#define cp_outpath 2
#define cp_mindate 3
char *cp_names[numparms] = { "DirFile", "InMask", "OutPath", "MinDate"};

/* output file info */
#define f_name "FILIROUT"
#define numfiles 5
#define f_yes 0
#define f_nof 1
#define f_nol 2
#define f_dup 3
#define f_ans 4
char *dot_ext[] = {".YES",".NOF",".NOL",".DUP",".ANS"};

/* -function prototypes */
int configure(
int argc, /* number of command line tokens */
char *argv[], /* command line tokens */
int number_parms, /* number of legal parameter options */
char *parm_names[], /* legal parameter option names */
int number_flags, /* number of legal flag options */
char *flag_names[], /* legal flag option names */
int number_vals, /* number of different flag values */
char *flags_vals[], /* legal flag values */
char *parms[], /* returned parameter values */
int flags[] /* returned flag values */
);
int get_real_files(
char *mask,
char *files[]
);
int get_list_files(
char *fname,
char *files[],
char *comments[],
int *cnt_comments
);
int write_file(
int file_num,
FILE *fd_array[],
int flags[],
char *parms[],
char *list_file,
char *real_file,
char *delim,
char *comments[],
int cnt_comments
);
int color_file(
FILE *fd_array[],
int flags[],
char *parms[]
);
void say_goodbye(
int status
);

int comp_fname(
char **arg1,
char **arg2
);

int comp_date(
char **arg1,
char **arg2
);

/* ============================= MAIN program ============================= */
main (int argc, char *argv[])
{
/* configuration parameters */
int flags[numflags];
char *parms[numparms];

int exit_code; /* other variables */
int cnt_real;
int cnt_list;
int cnt_nolist;
int cnt_nofile;
int cnt_comments;
char *real_files[maxfiles];
char *list_files[maxfiles];
char *comments[maxcomments];
FILE *out_files[numfiles];
int i;
int i_real;
int i_list;
char filename[66];
char *delimeter;

/* code */
printf("%s %s %s %s\n",p_name,p_vers,p_desc,p_copy);
exit_code = configure(argc, argv, numparms, cp_names, numflags, cf_names,
numflagvals, cf_values, parms, flags );
if (exit_code == st_normal) {
printf("\n%s Config:",p_name);
if ( strcmp(parms[cp_outpath],"") != 0 )
printf(" %s=%s",cp_names[cp_outpath],parms[cp_outpath]);
if ( strcmp(parms[cp_mindate],"") != 0 )
printf(" %s=%s",cp_names[cp_mindate],parms[cp_mindate]);
for (i=0; i if ( flags[i] != cf_default )
printf(" %s=%s",cf_names[i],cf_values[flags[i]]);
printf("\n");
printf("%s Searching %s .. ",p_name,parms[cp_inmask]);
cnt_real = get_real_files(parms[cp_inmask], real_files);
printf("%d files found\n",abs(cnt_real));
if (cnt_real>maxfiles)
exit_code = st_realmax;
else if (cnt_real<0)
exit_code = st_nomem;
else {
printf("%s Reading %s .. ",p_name,parms[cp_dirfile]);
cnt_list = get_list_files(parms[cp_dirfile], list_files,
comments, &cnt_comments);
printf("%d files found",abs(cnt_list) );
if ( cnt_comments > 0 )
printf(", %d comment lines retained", cnt_comments );
printf("\n");
if (cnt_list>maxfiles)
exit_code = st_listmax;
else if (cnt_list<0)
exit_code = st_nomem;
else {
printf("%s Sorting .. ",p_name);
qsort ( (void *) real_files, (size_t) cnt_real, sizeof(char *),
comp_fname ); /* compiler warnings ok on this line */
qsort ( (void *) list_files, (size_t) cnt_list, sizeof(char *),
comp_fname ); /* compiler warnings ok on this line */
printf("done\n");
printf("%s Writing .. ",p_name);
for ( i = 0; i < numfiles; i++ ) {
filename[0] = '\0';
strcpy( filename, parms[cp_outpath] );
strcat( strcat( filename, f_name ), dot_ext[i] );
remove(filename); /* delete all previous output files */
out_files[i] = NULL; /* note all output files as closed */
}
i_real = 0;
i_list = 0;
delimeter = "\b\b\b";
while( (i_real < cnt_real) && (i_list < cnt_list) ) {
if ( (i_list > 0) && (comp_fname( &list_files[i_list],
&list_files[i_list-1]) == 0) ) {
exit_code=write_file(f_dup, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal)
i_list++;
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
else if ( comp_fname( &real_files[i_real], &list_files[i_list] ) == 0 ) {
exit_code=write_file(f_yes, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal) {
i_list++;
i_real++;
}
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
else if ( comp_fname( &real_files[i_real], &list_files[i_list] ) < 0 ) {
exit_code=write_file(f_nol, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal)
i_real++;
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
else if ( comp_fname( &real_files[i_real], &list_files[i_list] ) > 0 ) {
exit_code=write_file(f_nof, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal)
i_list++;
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
delimeter = "\b\b\b\b, ";
}
while ( i_real < cnt_real) {
exit_code=write_file(f_nol, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal)
i_real++;
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
while ( i_list < cnt_list ) {
if ( comp_fname( &list_files[i_list],&list_files[i_list-1]) != 0 )
exit_code=write_file(f_nof, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
else
exit_code=write_file(f_dup, out_files, flags, parms,
list_files[i_list], real_files[i_real], delimeter,
comments, cnt_comments);
if (exit_code == st_normal)
i_list++;
else {
i_list=cnt_list;
i_real=cnt_real;
}
}
fcloseall();
printf("done\n");
if ( exit_code == st_normal )
exit_code = color_file(out_files, flags, parms);
}
}
}
say_goodbye(exit_code);
exit(exit_code);
} /* ============================ End of MAIN ============================ */


/* ----------------------------------------------------------------------- */
int configure(
int argc, /* number of command line tokens */
char *argv[], /* command line tokens */
int number_parms, /* number of legal parameter options */
char *parm_names[], /* legal parameter option names */
int number_flags, /* number of legal flag options */
char *flag_names[], /* legal flag option names */
int number_vals, /* number of different flag values */
char *flag_vals[], /* legal flag values */
char *parms[], /* returned parameter values */
int flags[] /* returned flag values */
)
/*
Take command line input and returns the properly set configuration
parameters and flags. All flags and parameters except the first
parameter are optional and are expected to be in the form
'option=value'; the first parameter is required and is simply
'value'. Note that the user sees no difference between 'flags' and
'parameters' -- the distinction made by the program is that flags are
set to distinct integer values, and parameters are strings provided
by the user. Each parameter and/or flag may be interpreted differently.
*/

{
int status;
char *value;
char *option;
int i;
int j;
int not_recognized;

if ( (argc < 2) || (strchr(argv[1],'=') != NULL) ) /* error if no dirfile */
status=st_nolist;
else {
status = st_normal; /* ignore unrecognized options from here on out */
parms[cp_dirfile]=strdup( strupr(argv[1]) ); /* pick up dirfile name */
parms[cp_inmask]=strdup("*.*"); /* init parms to defaults */
parms[cp_outpath]=strdup("");
parms[cp_mindate]=strdup("");
flags[cf_size]=cf_val_real; /* init flags to defaults */
flags[cf_date]=cf_val_list;
flags[cf_desc]=cf_default;
flags[cf_date2]=cf_val_real;
flags[cf_color]=cf_default;

if (argc > 2) {
i=2;
while (i value=strchr(argv[i],'=');
if (value == NULL)
not_recognized = 1;
else {
not_recognized = 0;
value++;
option=argv[i];
option[strcspn(argv[i],"=")]='\0';
if (strcmpi(option,parm_names[cp_inmask]) == 0) {
parms[cp_inmask] = (char *) malloc( (strlen(value)+4) *
sizeof(char) );
*parms[cp_inmask] = '\0';
strcpy( parms[cp_inmask], strupr(value) );
if ( strchr(value,'.') == NULL )
if ( value[strlen(value)-1] == '\\' )
strcat(parms[cp_inmask],"*.*");
else
strcat(parms[cp_inmask],"\\*.*");
}
else if (strcmpi(option,parm_names[cp_outpath]) == 0) {
parms[cp_outpath] = (char *) malloc( (strlen(value)+1) * sizeof(char) );
*parms[cp_outpath] = '\0';
strcpy( parms[cp_outpath], strupr(value) );
if ( value[strlen(value)-1] != '\\' )
strcat(parms[cp_outpath],"\\");
}
else if (strcmpi(option,parm_names[cp_mindate]) == 0) {
if ( (strlen(value) == 8) && (isdigit(value[0]) != 0) &&
(isdigit(value[1]) != 0) && (isdigit(value[3]) != 0) &&
(isdigit(value[4]) != 0) && (isdigit(value[6]) != 0) &&
(isdigit(value[7]) != 0) ) {
value[2] = '-';
value[5] = '-';
parms[cp_mindate] = (char *) malloc( 9 * sizeof(char) );
strcpy( parms[cp_mindate], value );
}
else
printf("\n%s WARNING: Invalid option value ignored: %s\n",p_name,argv[i]);
}
else {
for ( j = 0; j < number_flags; j++ ) {
not_recognized = 1;
if (strcmpi(option,flag_names[j]) == 0) {
not_recognized = 0;
if (strcmpi(value,flag_vals[cf_val_real]) == 0)
flags[j] = cf_val_real;
else if (strcmpi(value,flag_vals[cf_val_list]) == 0)
flags[j] = cf_val_list;
else if (strcmpi(value,flag_vals[cf_val_none]) == 0)
flags[j] = cf_val_none;
else
printf("\n%s WARNING: Invalid option value ignored: %s\n",p_name,argv[i]);
break;
}
}
}
if (not_recognized)
printf("\n%s WARNING: Unknown option ignored: %s\n",p_name,argv[i]);
}
i++;
}
}
}
return(status);
}


/* ----------------------------------------------------------------------- */
int get_real_files(char *mask, char *files[])
/* Creates an array of file descriptors for the files matching mask. */
{
struct find_t file_buf;
int status;
int i;
int cnt;
char *ptr;
char *str;
char str_buf[20];
struct { /* file date bitfield representation */
unsigned int day : 5;
unsigned int month : 4;
unsigned int year : 7;
} *filedate;

cnt = 0;
status = _dos_findfirst(mask,_A_NORMAL,&file_buf);
while (status == 0) {
if (cnt < maxfiles) {
files[cnt] = strdup(" ");
if (files[cnt] == NULL)
cnt = -cnt; /* out of memory */
else {
strncpy( files[cnt], file_buf.name, strlen(file_buf.name) );

str = ltoa( file_buf.size, str_buf, 10); /* file size as chars */
ptr = files[cnt] + 12; /* point to size field */
for ( i=0; i < (9 - strlen(str)); i++ ) { /* RJSF size */
*ptr = ' ';
ptr ++;
}
strncpy(ptr,str,strlen(str)); /* copy file size */
ptr = files[cnt] + 23; /* point to date field */
filedate = &(file_buf.wr_date); /* compiler warning ok on this line */
str = itoa( filedate->month, str_buf, 10); /* month number as chars */
if (strlen(str) == 1) { /* RJZF month */
strncpy( ptr, "0", 1);
ptr ++;
}
strncpy( ptr, str, strlen(str) );
ptr = ptr + strlen(str);
strncpy( ptr, "-", 1);
ptr ++;
str = itoa( filedate->day, str_buf, 10); /* day number as chars */
if (strlen(str) == 1) { /* RJZF day */
strncpy( ptr, "0", 1);
ptr ++;
}
strncpy( ptr, str, strlen(str) );
ptr = ptr + strlen(str);
strncpy( ptr, "-", 1);
ptr ++;
str = itoa( (filedate->year + 80), str_buf, 10); /* year (< 2000) */
strncpy( ptr, str, strlen(str) );
}
}
if (cnt < 0)
status = -1;
else {
cnt++;
status = _dos_findnext(&file_buf);
}
}
return(cnt);
}


/* ----------------------------------------------------------------------- */
int get_list_files( char *fname,
char *files[],
char *comments[],
int *cnt_comments
)
/* Creates arrays of file lines and comments as read from the file list
fname. */
{
int cnt;
int i;
FILE *stream;
char line[255];
char *str;
char *ptr;

cnt = 0;
*cnt_comments = 0;
stream = fopen(fname,"r");
if ( stream != NULL ) {
str = fgets( line, 255, stream );
while ( str != NULL ) {
i = strlen(line)-1;
line[i]='\0'; /* get rid of trailing newline char */
if ( cnt < maxfiles ) {
if ( ( (line[0] == ' ') || ( i == 0 ) ) &&
( ( *cnt_comments < maxcomments ) && ( cnt == 0 ) ) ) {
comments[*cnt_comments] = strdup(line);
++*cnt_comments;
}
else {
if ( i > 74)
files[cnt] = strdup(line);
else {
i = 74;
files[cnt] = (char *) malloc( i * sizeof(char *) );
if ( files[cnt] != NULL )
*files[cnt] = '\0';
strcpy( files[cnt], line );
}
if (files[cnt] == NULL)
cnt = -cnt; /* out of memory */
else {
ptr = strchr(files[cnt],'\n');
if ( ptr == NULL )
ptr = strchr(files[cnt],'\0');
for ( ptr = ptr; ptr < files[cnt] + i; ptr ++ )
*ptr = ' ';
*ptr = '\0';
}
}
}
if (cnt < 0)
str = NULL;
else {
if ( (line[0] != ' ') && ( strlen(line) > 0 ) )
cnt++;
str = fgets( line, 255, stream );
}
}
fclose(stream);
}
return(cnt);
}


/* ----------------------------------------------------------------------- */
int write_file( int file_num, FILE *fd[], int flags[], char *parms[],
char *list_file, char *real_file, char* delim,
char *comments[], int cnt_comments)
/* Writes a line to the file indicated by file_num; the line is comprised
of components of list_file and real_file, depending on the flags. If
delim is NULL, no console output is produced, otherwise the file
names are listed as they are opened with delim as the leading delimeter
and " .. " as the trailing delimeter. When the f_yes file is opened,
the comments are written to it. */
{
char line[255];
char *ptr;
char *list_ptr;
char *real_ptr;
char filename[66];
int status;
int i;

status = st_normal;
line[0] = '\0';
filename[0] = '\0';
strcpy( filename, parms[cp_outpath] );
strcat( strcat( filename, f_name ), dot_ext[file_num] );
if ( fd[file_num] == NULL ) { /* file not open yet */
fd[file_num] = fopen(filename,"w");
if ( fd[file_num] == NULL ) {
status = st_filerr;
if (delim != NULL)
printf("unable to open %s .. ", filename);
}
else {
if (delim != NULL )
printf("%s%s%s .. ", delim, f_name, dot_ext[file_num] );
if ( file_num == f_yes ) {
i = 0;
while ( i < cnt_comments ) {
status = fprintf(fd[file_num],"%s\n",comments[i]);
if ( status == strlen(comments[i]) + 1 )
status = st_normal;
else {
status = st_filerr;
printf("%s write error .. ", filename);
break;
}
i++;
}
}
}
}
if (status == st_normal) {
if ( file_num == f_yes ) {
strncpy( line, list_file, 12); /* file name */
ptr = line + 12;
list_ptr = list_file + 12;
real_ptr = real_file + 12;
if ( flags[cf_size] == cf_val_none )
strncpy( ptr, " ", 9 );
else if ( flags[cf_size] == cf_val_real )
strncpy( ptr, real_ptr, 9 );
else if ( flags[cf_size] == cf_val_list )
strncpy( ptr, list_ptr, 9 );
ptr = ptr + 9;
list_ptr = list_ptr + 9;
real_ptr = real_ptr + 9;
if ( flags[cf_date] == cf_val_none )
strncpy( ptr, " ", 10 );
else if ( flags[cf_date] == cf_val_real )
strncpy( ptr, real_ptr, 10 );
else if ( flags[cf_date] == cf_val_list )
strncpy( ptr, list_ptr, 10 );
ptr = ptr + 2;
if ( strcmp(parms[cp_mindate],"") != 0 )
if ( comp_date( &ptr, &parms[cp_mindate] ) < 0 )
strncpy( ptr, parms[cp_mindate], 8 );
ptr = ptr + 8;
list_ptr = list_ptr + 10;
real_ptr = real_file + 23;
if ( flags[cf_desc] == cf_val_none ) {
strncpy( ptr, " ", 43);
ptr = ptr + 43;
}
else {
if ( flags[cf_date2] == cf_val_none ) {
strcpy( ptr, list_ptr);
ptr = ptr + strlen(list_ptr);
}
else {
strncpy( ptr, list_ptr, 42 );
ptr = ptr + 42;
*ptr = ' ';
ptr ++;
}
}
list_ptr = list_file + 23;
if ( flags[cf_date2] == cf_val_real ) {
strncpy( ptr, real_ptr, 2 );
ptr = ptr + 2;
*ptr = '/';
ptr ++;
real_ptr = real_ptr + 6;
strncpy( ptr, real_ptr, 2 );
ptr = ptr + 2;
}
else if ( flags[cf_date2] == cf_val_list ) {
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
*ptr = '/';
ptr ++;
list_ptr = list_ptr + 6;
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
}
*ptr = '\0';
}
else if ( file_num == f_nof ) {
strncpy( line, list_file, 12); /* file name */
ptr = line + 12;
list_ptr = list_file + 12;
if ( flags[cf_size] == cf_val_none )
strncpy( ptr, " ", 9 );
else
strncpy( ptr, list_ptr, 9 );
ptr = ptr + 9;
list_ptr = list_ptr + 9;
if ( flags[cf_date] == cf_val_none )
strncpy( ptr, " ", 10 );
else
strncpy( ptr, list_ptr, 10 );
ptr = ptr + 2;
if ( strcmp(parms[cp_mindate],"") != 0 )
if ( comp_date( &ptr, &parms[cp_mindate] ) < 0 )
strncpy( ptr, parms[cp_mindate], 8 );
ptr = ptr + 8;
list_ptr = list_ptr + 10;
if ( flags[cf_desc] == cf_val_none ) {
strncpy( ptr, " ", 43);
ptr = ptr + 43;
}
else {
if ( flags[cf_date2] != cf_val_list ) {
strcpy( ptr, list_ptr);
ptr = ptr + strlen(list_ptr);
}
else {
strncpy( ptr, list_ptr, 42 );
ptr = ptr + 42;
*ptr = ' ';
ptr ++;
}
}
list_ptr = list_file + 23;
if ( flags[cf_date2] == cf_val_list ) {
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
*ptr = '/';
ptr ++;
list_ptr = list_ptr + 6;
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
}
*ptr = '\0';
}
else if ( file_num == f_nol ) {
strncpy( line, real_file, 12); /* file name */
ptr = line + 12;
real_ptr = real_file + 12;
if ( flags[cf_size] == cf_val_none )
strncpy( ptr, " ", 9 );
else
strncpy( ptr, real_ptr, 9 );
ptr = ptr + 9;
real_ptr = real_ptr + 9;
if ( flags[cf_date] == cf_val_none )
strncpy( ptr, " ", 10 );
else
strncpy( ptr, real_ptr, 10 );
ptr = ptr + 10;
real_ptr = real_ptr + 10;
if ( flags[cf_desc] == cf_val_none )
strncpy( ptr, " ", 43 );
else
strncpy( ptr," * Description Unavailable * ", 43 );
ptr = ptr + 43;
real_ptr = real_file + 23;
if ( flags[cf_date2] == cf_val_real ) {
strncpy( ptr, real_ptr, 2 );
ptr = ptr + 2;
*ptr = '/';
ptr ++;
real_ptr = real_ptr + 6;
strncpy( ptr, real_ptr, 2 );
ptr = ptr + 2;
}
*ptr = '\0';
}
else if ( file_num == f_dup ) {
strncpy( line, list_file, 12); /* file name */
ptr = line + 12;
list_ptr = list_file + 12;
if ( flags[cf_size] == cf_val_none )
strncpy( ptr, " ", 9 );
else
strncpy( ptr, list_ptr, 9 );
ptr = ptr + 9;
list_ptr = list_ptr + 9;
if ( flags[cf_date] == cf_val_none )
strncpy( ptr, " ", 10 );
else
strncpy( ptr, list_ptr, 10 );
ptr = ptr + 10;
list_ptr = list_ptr + 10;
if ( flags[cf_desc] == cf_val_none ) {
strncpy( ptr, " ", 43);
ptr = ptr + 43;
}
else {
if ( flags[cf_date2] != cf_val_list ) {
strcpy( ptr, list_ptr);
ptr = ptr + strlen(list_ptr);
}
else {
strncpy( ptr, list_ptr, 42 );
ptr = ptr + 42;
*ptr = ' ';
ptr ++;
}
}
list_ptr = list_file + 23;
if ( flags[cf_date2] == cf_val_list ) {
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
*ptr = '/';
ptr ++;
list_ptr = list_ptr + 6;
strncpy( ptr, list_ptr, 2 );
ptr = ptr + 2;
}
*ptr = '\0';
}
ptr = line + strlen(line) - 1; /* at last char of line */
while ( *ptr == ' ' ) {
*ptr = '\0'; /* remove trailing spaces */
ptr --;
}
status = fprintf(fd[file_num],"%s\n",line);
if ( status == strlen(line) + 1 )
status = st_normal;
else {
status = st_filerr;
printf("%s write error .. ", filename);
}
}
return(status);
}


/* ----------------------------------------------------------------------- */
int color_file( FILE *fd[], int flags[], char *parms[] )
/* Creates the color file listing fron the matched file listing,
depending on the flags. */
{

char line[255];
char outline[281];
char filename[66];
int status;
char *str;

status = st_normal;
if ( ( flags[cf_color] != cf_val_none ) && ( fd[f_yes] != NULL ) ) {
printf("%s Colorizing .. ",p_name);
strcpy( filename, parms[cp_outpath] );
strcat( strcat( filename, f_name ), dot_ext[f_yes] );
fd[f_yes] = fopen(filename,"r");
if ( fd[f_yes] == NULL ) {
status = st_filerr;
printf("unable to open %s .. ", filename);
}
else {
printf("\b\b\b%s%s .. ", f_name, dot_ext[f_yes] );
strcpy( filename, parms[cp_outpath] );
strcat( strcat( filename, f_name ), dot_ext[f_ans] );
fd[f_ans] = fopen(filename,"w");
if ( fd[f_ans] == NULL ) {
status = st_filerr;
printf("unable to open %s .. ", filename);
}
else {
printf("\b\b\binto %s%s .. ", f_name, dot_ext[f_ans] );
str = fgets( line, 255, fd[f_yes] );
while ( str != NULL ) {
line[strlen(line)-1]='\0'; /* kill trailing newline char */
if ( (line[0] == ' ') || ( strlen(line) == 0 ) ) { /* comment */
strncpy( outline, "\x1b[1;36m", 7);
strncpy( outline+7, line, strlen(line) );
strcpy( outline+7+strlen(line), "\x1b[0m");
}
else { /* not a comment */
strncpy( outline, "\x1b[1;37m", 7);
strncpy( outline+7, line, 12);
strncpy( outline+19, "\x1b[32m", 5);
strncpy( outline+24, line+12, 9);
strncpy( outline+33, "\x1b[35m", 5);
strncpy( outline+38, line+21, 10);
strncpy( outline+48, "\x1b[33m", 5);
if ( flags[cf_date2] == cf_val_none ) {
strncpy( outline+53, line+31, strlen(line+31) );
strcpy( outline+53+strlen(line+31), "\x1b[0m");
}
else {
strncpy( outline+53, line+31, 43);
strncpy( outline+96, "\x1b[31m", 5);
strncpy( outline+101, line+74, 5);
strcpy( outline+106, "\x1b[0m");
}
}
status = fprintf(fd[f_ans],"%s\n",outline);
if ( status == strlen(outline) + 1 ) {
status = st_normal;
str = fgets( line, 255, fd[f_yes] );
}
else {
status = st_filerr;
printf("%s write error .. ", filename);
str = NULL;
}
}
printf("done\n");
}
}
}
return(status);
}


/* ----------------------------------------------------------------------- */
int comp_fname(char **arg1, char **arg2)
{
return( strncmp( *arg1, *arg2, 12 ) );
}


/* ----------------------------------------------------------------------- */
int comp_date(char **arg1, char **arg2)
{
char temp_arg1[6];
char temp_arg2[6];

strncpy( temp_arg1, *arg1 + 6, 2); /* yy */
strncpy( temp_arg1+2, *arg1, 2); /* mm */
strncpy( temp_arg1+4, *arg1+3 , 2); /* dd */
strncpy( temp_arg2, *arg2 + 6, 2); /* yy */
strncpy( temp_arg2+2, *arg2, 2); /* mm */
strncpy( temp_arg2+4, *arg2+3 , 2); /* dd */
return( strncmp( temp_arg1, temp_arg2, 6 ) );
}


/* ----------------------------------------------------------------------- */
void say_goodbye(int status)
{
if (status == st_normal)
printf("\n%s normal termination.\n",p_name);
else if (status == st_realmax)
printf("\n%s ABORTED: More than %d files found!\n",p_name,maxfiles);
else if (status == st_listmax)
printf("\n%s ABORTED: More than %d files in list!\n",p_name,maxfiles);
else if (status == st_nomem)
printf("\n%s ABORTED: Ran out of memory!\n",p_name,maxfiles);
else if (status == st_filerr)
printf("\n%s ABORTED: Output file error!\n",p_name);
else {
printf("\n");
printf("Usage: %s dirfile [options]\n",p_name);
printf("Options: (defaults are shown in CAPS)\n");
printf(" inmask= full path\\mask to search (defaults to *.*)\n");
printf(" outpath= path for output files (defaults to current dir)\n");
printf(" mindate= mm-dd-yy of oldest date field value on output\n");
printf(" size= none/FILE/list\n");
printf(" date= none/file/LIST\n");
printf(" desc= none\n");
printf(" date2= none/FILE/list\n");
printf(" color= none\n");
printf("Output files: (all sorted by file name)\n");
printf(" %s.YES listed files that exist\n",f_name);
printf(" %s.NOF listed files that were not found\n",f_name);
printf(" %s.NOL found files that were not listed\n",f_name);
printf(" %s.DUP files listed more than once\n",f_name);
printf(" %s.ANS same as %s.YES but with ANSI color\n",f_name,f_name);
printf("Example: %s FILES.BBS INMASK=C:\\UPLOAD\\*.ARC DATE2=NONE DATE=FILE\n",p_name);
printf(" This will compare the FILES.BBS file list with all .ARC files in the UPLOAD\n");
printf(" directory, the output files will show the actual (not listed) file size and\n");
printf(" date, and the second date field will not be added to the file descriptions.\n");
}
}