home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
_bbs
/
get_area.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-07
|
2KB
|
105 lines
/*
* get_area.c
* get area description as line after path
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *logfile = NULL;
#define SIMTEL 1
#define OTHER 2
void
myexit(int i) {
fclose(logfile);
exit(i);
}
void
print_err(const char *fmt, ...) {
va_list args;
char str[0x100];
va_start(args, fmt);
vsprintf(str, fmt, args);
va_end(args);
if (logfile)
fprintf(logfile, "%s", str);
fprintf(stderr, "%s", str);
}
#ifdef __MSDOS__
void _Cdecl
#else
void
#endif
main(int argc, char *argv[]) {
char buf[200];
int i;
int input_t = 0;
char *p;
char search[30];
if (argc != 4) {
fprintf(stderr, "usage: get_area [type] [# spaces] [path] < input_file > output_file\n");
fprintf(stderr, "type == simtel xxx\n");
myexit(1);
}
i = atoi(argv[2]);
if (NULL == (logfile = fopen("logfile", "at"))) {
print_err("erroring opening logfile\n");
myexit(1);
}
if (0 == stricmp(argv[1], "simtel")) {
input_t = SIMTEL;
strcpy(search, strrchr(argv[3], '\\') + 1);
} else
input_t = OTHER;
while (NULL != gets(buf)) {
switch(input_t) {
case SIMTEL:
p = strtok(buf, " \t");
if (0 == stricmp(search, p)) {
p = strtok(NULL, " \t");
p += 2;
if (p) {
if (i)
printf("%*s%s\n", i, " ", p);
else
printf("%s\n", p);
}
myexit(0);
}
break;
case OTHER:
if (0 == stricmp(argv[3], buf)) {
if (NULL != gets(buf)) {
if (i)
printf("%*s%s\n", i, " ", buf);
else
printf("%s\n", buf);
}
myexit(0);
}
break;
default:
print_err("bad input type \n");
myexit(1);
}
}
print_err("no area found:\n%s\n", argv[3]);
myexit(1);
}