home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
FILECHEC.ZIP
/
FILECHEC.C
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
5KB
|
225 lines
#define INCL_DOS
#define INCL_DOSERRORS
#include <os2.h>
#include <mt\stdio.h>
#include <mt\conio.h>
#include <mt\stdlib.h>
#include <mt\string.h>
#include "filechec.h"
void ParseParms(SHORT Count, PSZ Arguments[]);
SHORT ParmType (PSZ);
void ShowVersionInfo (void);
void ErrorAndDie (PSZ, USHORT);
void UserError (PSZ);
void CheckAllFiles (PSZ);
void CheckFile (PSZ);
void HandleReturn (USHORT RCode, USHORT Level, PSZ File);
USHORT OpenFile (PSZ Filename, USHORT Level);
BOOL swVerbose;
CHAR Filename[BIG_STRING];
void main(SHORT argv, PSZ argc[])
{
ShowVersionInfo();
ParseParms(argv, argc);
CheckAllFiles(Filename);
DosExit(EXIT_PROCESS, 0);
}
void CheckAllFiles(PSZ Filename)
{
USHORT RCode;
FILEFINDBUF File;
HDIR Directory = HDIR_CREATE;
USHORT Amount = 1;
RCode = DosFindFirst(Filename, // ThisFile.
&Directory, // Handle to start with.
FILE_NORMAL, // Attribs
&File,
sizeof(File),
&Amount,
0L);
if ( (RCode != NO_ERROR) &&
(RCode != ERROR_FILE_NOT_FOUND) &&
(RCode != ERROR_NO_MORE_FILES) )
ErrorAndDie("DosFindFirst", RCode);
while (RCode == NO_ERROR)
{
if ( (strcmp(File.achName, "..") != 0) &&
(strcmp(File.achName, ".") != 0) )
if (!(File.attrFile & FILE_DIRECTORY) )
CheckFile(File.achName);
RCode = DosFindNext(Directory, &File, sizeof(File), &Amount);
}
DosFindClose(Directory);
}
void HandleReturn(USHORT RCode, USHORT Level, PSZ File)
{
CHAR TempString[BIG_STRING];
switch (RCode)
{
case NO_ERROR:
printf("FILECHEC: File -> %12s Open succeeded -> %s.\n", File,
Levels[Level]);
break;
case ERROR_OPEN_FAILED:
case ERROR_FILE_NOT_FOUND:
UserError("File not found.\n");
break;
case ERROR_SHARING_VIOLATION:
printf("FILECHEC: File -> %12s Share violation -> %s.\n", File,
Levels[Level]);
break;
default:
sprintf(TempString, "Unexpected DosOpen return: %u\n", RCode);
UserError(TempString);
break;
}
}
USHORT OpenFile(PSZ Filename, USHORT Level)
{
USHORT RCode;
USHORT Action;
HFILE File;
RCode = DosOpen(Filename, &File, &Action, 0L, FILE_NORMAL, FILE_OPEN,
OpenFlags[Level], 0L);
DosClose(File);
return(RCode);
}
void CheckFile(PSZ Filename)
{
USHORT RCode;
USHORT CurrentLevel = 0;
if (swVerbose == FALSE)
{
RCode = OpenFile(Filename, 0);
HandleReturn(RCode, 0, Filename);
}
else
while (*Levels[CurrentLevel] != '\0')
{
RCode = OpenFile(Filename, CurrentLevel);
HandleReturn(RCode, CurrentLevel, Filename);
CurrentLevel++;
}
}
void ShowVersionInfo(void)
{
printf("\nFileChec Version %s: 1990, Mike Donnelly\n\n",
FC_VERSION);
}
void ParseParms(SHORT Count, PSZ Arguments[])
{
BOOL GotFile = FALSE;
BOOL NeedHelp = FALSE;
PSZ Argument;
CHAR LastChar;
swVerbose = FALSE;
if (Count == 1)
NeedHelp = TRUE;
while ( *(++Arguments) )
{
Argument = *(Arguments);
LastChar = *(Argument + (strlen(Argument) - 1) );
switch ( ParmType(Argument) )
{
case PARM_HELP:
case PARM_BAD:
NeedHelp = TRUE;
break;
case PARM_STRING:
GotFile = TRUE;
strcpy(Filename, Argument);
break;
case PARM_VERBOSE:
swVerbose = TRUE;
break;
default:
ErrorAndDie("Internal casing error at ParseParms", 1);
break;
}
}
if (NeedHelp == TRUE)
{
printf("Usage: FC filename.ext [-v]\n");
printf("\n");
printf(" -V Verbose mode, attempt various modes.\n");
DosExit(EXIT_PROCESS, 0);
}
if (GotFile == FALSE)
UserError("No file specified.");
}
SHORT ParmType(PSZ Parm)
{
SHORT Type = PARM_NONE;
if ( (*Parm == '-') ||
(*Parm == '/') )
{
switch ( toupper( *(Parm + 1)) )
{
case '?':
case 'H':
Type = PARM_HELP;
break;
case 'V':
Type = PARM_VERBOSE;
break;
default:
Type = PARM_BAD;
break;
}
}
else
Type = PARM_STRING;
return(Type);
}
void ErrorAndDie(PSZ Message, USHORT Error)
{
printf("FILECHEC: %s error %u\n", Message, Error);
DosExit(EXIT_PROCESS, Error);
}
void UserError(PSZ Text)
{
printf("FILECHEC: %s\n", Text);
DosExit(EXIT_PROCESS, 1);
}