home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
sqmurd01.zip
/
sqmurder.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-18
|
8KB
|
245 lines
/*
* This program was hacked by Harald Kipp
*
* Bug reports and wishlists should be sent to
*
* Fido : 2:2448/434
* Internet: harald@os2point.ping.de
*
* You may freely use, copy and/or redistribute this software.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <errno.h>
#include <time.h>
#include "getopt.h"
static char *version = "0.1";
static char line[1024];
static char cmd[1024];
static char squishcfg[_MAX_PATH];
static char area[_MAX_PATH];
static char batch[_MAX_PATH];
static char fixprog[_MAX_PATH];
static char chkprog[_MAX_PATH];
static char logfile[_MAX_PATH];
static void usage(void);
static char *logtime(char c);
/************************************************************************/
/* SQMURDER */
/* */
/* Simply removes all broken squish areas. */
/* */
/* */
/* Returns 0 if all areas are OK */
/* 1 if all bad areas had been fixed */
/* 2 if bad areas had been added to murder.cmd */
/* 3 if bad areas were not listed in murder.cmd */
/* 255 on nonrecoverable errors */
/* */
/************************************************************************/
int main(int argc, char *argv[])
{
int result = 0;
char *key;
char *tag;
char *path;
FILE *fpcfg;
FILE *fpbat = NULL;
FILE *fplog = NULL;
int option;
int max_errors = 20;
int bad_areas = 0;
int fixed_areas = 0;
strcpy(squishcfg, "squish.cfg");
strcpy(batch, "murder.cmd");
strcpy(chkprog, "sqinfop.exe");
printf("\n SqMurder version %s\n", version);
printf(" written %s by Harald Kipp\n\n", __DATE__);
while((option = getopt(argc,argv,"b:c:e:f:i:l:")) != EOF) {
switch(option) {
case 'b':
strcpy(batch, optarg);
break;
case 'c':
strcpy(squishcfg, optarg);
break;
case 'e':
max_errors = atoi(optarg);
break;
case 'f':
strcpy(fixprog, optarg);
break;
case 'i':
strcpy(chkprog, optarg);
break;
case 'l':
strcpy(logfile, optarg);
break;
default:
usage();
return(255);
}
}
if(logfile[0] && (fplog = fopen(logfile, "a")) == NULL)
perror(batch);
if(fplog) {
fprintf(fplog, "\n%sBegin, SqMurder Version %s\n", logtime('+'), version);
fflush(fplog);
}
if((fpcfg = fopen(squishcfg, "r")) == NULL) {
perror(squishcfg);
if(fplog) {
fprintf(fplog, "%s Can't read %s\n", logtime('!'), squishcfg);
fclose(fplog);
}
return(255);
}
if(batch[0] == '+')
fpbat = fopen(batch + 1, "a");
else
fpbat = fopen(batch, "w");
if(fpbat == NULL) {
perror(batch);
if(fplog) {
fprintf(fplog, "%s Can't open %s\n", logtime('!'), batch);
fclose(fplog);
}
}
while(fgets(line, sizeof(line), fpcfg)) {
if((key = strtok(line, " \t\n")) == NULL)
continue;
if(stricmp(key, "EchoArea"))
continue;
if((tag = strtok(NULL, " \t\n")) == NULL)
continue;
if((path = strtok(NULL, " \t\n")) == NULL)
continue;
sprintf(area, "%s.SQD", path);
if(access(area, 0))
continue;
sprintf(cmd, "%s %s -e", chkprog, path);
if(system(cmd)) {
if(++bad_areas > max_errors)
break;
if(fixprog[0]) {
sprintf(cmd, "%s %s", fixprog, path);
if(system(cmd) == 0) {
fixed_areas++;
if(result < 1)
result = 1;
if(fplog) {
fprintf(fplog, "%s Fixed %s\n", logtime('*'), tag);
fflush(fplog);
}
if(fpbat) {
fprintf(fpbat, "del %s.XXD\n", path);
fprintf(fpbat, "del %s.XXI\n", path);
fprintf(fpbat, "del %s.XXL\n", path);
if(fflush(fpbat)) {
perror(batch);
if(fplog) {
fprintf(fplog, "%s Error writing %s\n", logtime('!'), batch);
fflush(fplog);
}
break;
}
}
continue;
}
}
if(fplog) {
fprintf(fplog, "%s Bad area %s\n", logtime('#'), tag);
fflush(fplog);
}
if(fpbat) {
fprintf(fpbat, "del %s.SQB\n", path);
fprintf(fpbat, "del %s.SQD\n", path);
fprintf(fpbat, "del %s.SQI\n", path);
fprintf(fpbat, "del %s.SQL\n", path);
if(fflush(fpbat)) {
perror(batch);
if(fplog) {
fprintf(fplog, "%s Error writing %s\n", logtime('!'), batch);
fflush(fplog);
}
result = 3;
break;
}
else if(result < 2)
result = 2;
}
else
result = 3;
}
}
fclose(fpcfg);
if(fpbat) {
if(fclose(fpbat)) {
if(fplog) {
fprintf(fplog, "%s Error writing %s\n", logtime('!'), batch);
fflush(fplog);
}
result = 3;
}
}
if(fplog) {
fprintf(fplog, "%sEnd. Bad=%d, fixed=%d, result=%d\n", logtime('+'), bad_areas, fixed_areas, result);
fclose(fplog);
}
else
fprintf(stderr, "Result = %d\n", result);
return(result);
}
/************************************************************************/
/* */
/************************************************************************/
static void usage(void)
{
fprintf(stderr, "\nusage: sqmurder [options]\n\n"
"options:\n"
" -b<batchname> name of batch output (murder.cmd)\n"
" -c<configfile> name of squish config file (squish.cfg)\n"
" -e<number> maximum number of bad areas (20)\n"
" -f<fixprog> name of program to fix area\n"
" -i<infoprog> name of program to check area (sqinfop.exe)\n"
" -l<logfile> name of the logfile\n");
}
/************************************************************************/
/* */
/************************************************************************/
static char *logtime(char c)
{
static char buf[32];
time_t t;
time(&t);
buf[0] = c;
strftime(buf + 1, sizeof(buf) - 1, " %d %b %H:%M:%S MRDR ", localtime(&t));
return(buf);
}