home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1992 November
/
CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso
/
bbs
/
sftool
/
convert.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-13
|
14KB
|
797 lines
/*
* from SIMTEL20, CICA, ulowel, cug
* to:
* rbbs .dir
* opus files.bbs
* spitfire
* pcboard
*/
#if 0
1234567890123456789012345678901 [Simtel]
4DOSANN.ZIP B 6864 910819 4DOS runs on DOS 5.0 and Norton DOS info
1234567890123456789012345678901 [CICA]
diskindx.txt 901031 Cumulative Index of the WRK Disks (below)
diskroot.zip 920610 Windows Resource Kit 4/3/92
---------->
opus:
AD-FEBBS.ZIP Great Demo for Febbs made by OUNO-Soft.
rbbs:
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST modems.
#endif
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys\stat.h>
#include <time.h>
#define SIMTEL 1
#define CICA 2
#define ULOWEL 3
#define CUG 4
#define OPUS 1
#define RBBS 2
#define PCB 3
#define SPITFIRE 4
#define WILDCAT 5
struct data {
char filename[15];
long filesize;
int year;
int month;
int day;
char description[900];
};
int pastheader = 0;
int in_type;
int out_type;
struct data line;
char path[128];
FILE *logfile = NULL;
void myexit(int i);
void print_err(const char *fmt, ...);
int
readline(void) {
static char buf[1000] = "";
char workbuf[1000];
static char datebuf[5] = "12";
char *r;
if (buf[0] == 0)
if (NULL == gets(buf))
return(1);
line.filename[0] = 0;
line.description[0] = 0;
switch (in_type) {
case ULOWEL:
if (0 != strnicmp(buf, "file:", 5)) {
buf[0] = 0;
return(0);
}
r = strtok(buf, "\r\n\t ");
if (! r) {
print_err("unknown line:\n%s\n", buf);
myexit(1);
buf[0] = 0;
return(0);
}
r += strlen(r) + 1; /* skip 'file:' */
while (isspace(*r)) /* skip white */
++r;
r = strtok(r, "\r\n\t ");
if (! r) {
print_err("unknown line:\n%s\n", buf);
myexit(1);
buf[0] = 0;
return(0);
}
strcpy(line.filename, r);
while (1) {
if (NULL == gets(buf))
return(1);
if (buf[0] == '\r')
continue;
if (! buf[0])
continue;
if (isspace(buf[0])) {
strcat(line.description, " ");
strcat(line.description, &buf[1]);
} else
return(0);
}
case SIMTEL:
case CICA:
/* wait for header */
if (! pastheader) {
if (in_type == CICA) {
if (0 == strlen(buf))
++pastheader;
} else {
if (strstr(buf, "================"))
++pastheader;
}
buf[0] = 0;
return(0);
}
if (strlen(buf) == 0) {
print_err("zero length line\n");
buf[0] = 0;
return(0);
}
if (strlen(buf) < 20) {
print_err("warning: line too short:\n%s\n", buf);
}
strcpy(workbuf, buf);
r = strtok(buf, "\r\n\t ");
if (! r) {
print_err("unknown line:\n%s\n", buf);
myexit(1);
buf[0] = 0;
return(0);
}
strcpy(line.filename, r);
r += strlen(r) + 1; /* skip name */
while (isspace(*r)) /* skip white */
++r;
if (in_type == SIMTEL) {
++r; /* skip file type */
while (isspace(*r)) /* skip white */
++r;
r = strtok(r, "\r\n\t ");
if (! r) {
print_err("unknown line:\n%s\n", buf);
myexit(1);
line.filename[0] = 0;
buf[0] = 0;
return(0);
}
line.filesize = atol(r);
r += strlen(r) + 1;
while (isspace(*r)) /* skip white */
++r;
}
datebuf[0] = *r;
++r;
datebuf[1] = *r;
++r;
line.year = atoi(datebuf);
datebuf[0] = *r;
++r;
datebuf[1] = *r;
++r;
line.month = atoi(datebuf);
datebuf[0] = *r;
++r;
datebuf[1] = *r;
++r;
line.day = atoi(datebuf);
while (isspace(*r)) /* skip white */
++r;
if (*r)
strcpy(line.description, r);
buf[0] = 0;
return(0);
case CUG:
if (strlen(buf) == 0) {
print_err("zero length line\n");
buf[0] = 0;
return(0);
}
if (strlen(buf) < 10) {
print_err("warning: line too short:\n%s\n", buf);
}
strcpy(workbuf, buf);
r = strtok(buf, "\r\n\t ");
if (! r) {
print_err("unknown line:\n%s\n", buf);
buf[0] = 0;
return(0);
}
strcpy(line.filename, r);
r += strlen(r) + 1; /* skip name */
while (isspace(*r)) /* skip white */
++r;
if (*r)
strcpy(line.description, r);
buf[0] = 0;
return(0);
default:
print_err("bad input type\n");
myexit(1);
}
return(0);
}
void
opus_writeline(void) {
FILE *foo;
char buf[128];
struct stat stat_buf;
struct tm *tm;
time_t t;
char *p, *r;
if (! line.filename[0])
return;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST modems.
#endif
if (in_type == CUG) {
strupr(line.filename);
strrev(line.filename);
if (0 == strncmp("RID", line.filename, 3)) {
line.filename[0] = 0;
return;
}
if (0 == strncmp("SBB", line.filename, 3)) {
line.filename[0] = 0;
return;
}
strrev(line.filename);
}
if (out_type == OPUS) {
printf("%s %s\n", line.filename, line.description);
return;
}
switch (in_type) {
case CICA:
case ULOWEL:
case CUG:
sprintf(buf, "%s\\%s", path, line.filename);
if (NULL == (foo = fopen(buf, "r"))) {
print_err("failed opening '%s'\n %s\n", buf, line.description);
return;
}
stat(buf, &stat_buf);
fclose(foo);
line.filesize = stat_buf.st_size;
break;
default:
break;
}
switch (in_type) {
case ULOWEL:
case CUG:
t = stat_buf.st_ctime;
tm = localtime(&t);
line.month = tm->tm_mon;
line.day = tm->tm_mday;
line.year = tm->tm_year;
break;
default:
break;
}
printf("%-13s%8ld %02d-%02d-%02d ",
line.filename,
line.filesize,
line.month,
line.day,
line.year);
/* write wrapping description */
r = line.description;
p = r + strlen(r) - 1;
while (isspace(*p)) {
*p = 0;
--p;
}
r = line.description;
if (strlen(r) <= 45) {
printf("%s\n", r);
return;
}
p = r + 45;
while (! isspace(*p))
--p;
*p = 0;
printf("%s\n ", r);
r = p + 1;
while (1) {
if (strlen(r) <= 76) {
printf("%s\n", r);
return;
}
p = r + 76;
while (! isspace(*p))
--p;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST
| modems.
#endif
*p = 0;
printf("%s\n ", r);
r = p + 1;
}
}
void
pcb_writeline(void) {
char *r;
char *p;
FILE *foo;
char buf[128];
struct stat stat_buf;
struct tm *tm;
time_t t;
if (! line.filename[0])
return;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST
| modems.
#endif
if (in_type == CUG) {
strupr(line.filename);
strrev(line.filename);
if (0 == strncmp("RID", line.filename, 3)) {
line.filename[0] = 0;
return;
}
if (0 == strncmp("SBB", line.filename, 3)) {
line.filename[0] = 0;
return;
}
strrev(line.filename);
}
switch (in_type) {
case CICA:
case ULOWEL:
case CUG:
sprintf(buf, "%s\\%s", path, line.filename);
if (NULL == (foo = fopen(buf, "r"))) {
print_err("failed opening '%s'\n %s\n", buf, line.description);
return;
}
stat(buf, &stat_buf);
fclose(foo);
line.filesize = stat_buf.st_size;
default:
break;
}
switch (in_type) {
case ULOWEL:
case CUG:
t = stat_buf.st_ctime;
tm = localtime(&t);
line.month = tm->tm_mon;
line.day = tm->tm_mday;
line.year = tm->tm_year;
default:
break;
}
printf("%-13s%8ld %02d-%02d-%02d ",
line.filename,
line.filesize,
line.month,
line.day,
line.year);
/* write wrapping description */
r = line.description;
p = r + strlen(r) - 1;
while (isspace(*p)) {
*p = 0;
--p;
}
while (1) {
if (strlen(r) <= 45) {
printf("%s\n", r);
return;
}
p = r + 45;
while (! isspace(*p))
--p;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST
| modems.
#endif
*p = 0;
printf("%s\n%31s| ", r, " ");
r = p + 1;
}
}
void
spitfire_writeline(void) {
char *r;
char *p;
FILE *foo;
char buf[128];
struct stat stat_buf;
struct tm *tm;
time_t t;
int x;
char buf2[20];
if (! line.filename[0])
return;
if (in_type == CUG) {
strupr(line.filename);
strrev(line.filename);
if (0 == strncmp("RID", line.filename, 3)) {
line.filename[0] = 0;
return;
}
if (0 == strncmp("SBB", line.filename, 3)) {
line.filename[0] = 0;
return;
}
strrev(line.filename);
}
switch (in_type) {
case CICA:
case ULOWEL:
case CUG:
sprintf(buf, "%s\\%s", path, line.filename);
if (NULL == (foo = fopen(buf, "r"))) {
print_err("failed opening '%s'\n %s\n", buf,
line.description);
myexit(1);
}
stat(buf, &stat_buf);
fclose(foo);
line.filesize = stat_buf.st_size;
break;
default:
break;
}
switch (in_type) {
case ULOWEL:
case CUG:
t = stat_buf.st_ctime;
tm = localtime(&t);
line.month = tm->tm_mon;
line.day = tm->tm_mday;
line.year = tm->tm_year;
break;
default:
break;
}
/* description -- wack off at 40 chars.*/
line.description[41] = 0;
printf("%-12s", line.filename);
sprintf(buf, "%ld", line.filesize);
strrev(buf);
p = buf;
r = buf2;
x = 0;
while (*p) {
if (x == 3) {
*r++ = ',';
x = 0;
}
++x;
*r++ = *p++;
}
*r = 0;
strrev(buf2);
printf("%9s ", buf2);
printf(" %02d-%02d-%02d %s\n",
line.month,
line.day,
line.year,
line.description);
}
void
rbbs_writeline(void) {
FILE *foo;
char buf[128];
struct stat stat_buf;
struct tm *tm;
time_t t;
char *p, *r;
if (! line.filename[0])
return;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST modems.
#endif
if (in_type == CUG) {
strupr(line.filename);
strrev(line.filename);
if (0 == strncmp("RID", line.filename, 3)) {
line.filename[0] = 0;
return;
}
if (0 == strncmp("SBB", line.filename, 3)) {
line.filename[0] = 0;
return;
}
strrev(line.filename);
}
if (out_type == OPUS) {
printf("%s %s\n", line.filename, line.description);
return;
}
switch (in_type) {
case CICA:
case ULOWEL:
case CUG:
sprintf(buf, "%s\\%s", path, line.filename);
if (NULL == (foo = fopen(buf, "r"))) {
print_err("failed opening '%s'\n %s\n", buf, line.description);
return;
}
stat(buf, &stat_buf);
fclose(foo);
line.filesize = stat_buf.st_size;
break;
default:
break;
}
switch (in_type) {
case ULOWEL:
case CUG:
t = stat_buf.st_ctime;
tm = localtime(&t);
line.month = tm->tm_mon;
line.day = tm->tm_mday;
line.year = tm->tm_year;
break;
default:
break;
}
printf("%-13s%8ld %02d-%02d-%02d ",
line.filename,
line.filesize,
line.month,
line.day,
line.year);
/* write wrapping description */
r = line.description;
p = r + strlen(r) - 1;
while (isspace(*p)) {
*p = 0;
--p;
}
r = line.description;
if (strlen(r) <= 45) {
printf("%s\n", r);
return;
}
p = r + 45;
while (! isspace(*p))
--p;
*p = 0;
printf("%s\n ", r);
r = p + 1;
while (1) {
if (strlen(r) <= 76) {
printf("%s\n", r);
return;
}
p = r + 76;
while (! isspace(*p))
--p;
#if 0
9600TEXT.ZIP 16576 09-26-91 A pair of US Robotics text files about HST
| modems.
#endif
*p = 0;
printf("%s\n ", r);
r = p + 1;
}
}
void
help(void) {
print_err("usage: convert <in_type> <out_type> [directory path] < in > out\n");
print_err(" <in_type> := cug; simtel; cica; ulowel\n");
print_err(" <out_type> := opus, rbbs, spitfire, pcb\n");
print_err(" if <in_type> == cug, cica, ulowel\n");
print_err(" and <out_type> == rbbs, spitfire, pcb\n");
print_err(" [directory path] is required.\n");
myexit(1);
}
void _Cdecl
main(int argc, char *argv[]) {
int rv;
if (argc < 3)
help();
if (0 == stricmp("simtel", argv[1])) {
in_type = SIMTEL;
} else if (0 == stricmp("cica", argv[1])) {
in_type = CICA;
} else if (0 == stricmp("cug", argv[1])) {
in_type = CUG;
} else if (0 == stricmp("ulowel", argv[1])) {
in_type = ULOWEL;
} else
help();
if (0 == stricmp("opus", argv[2])) {
out_type = OPUS;
} else if (0 == stricmp("pcb", argv[2])) {
out_type = PCB;
} else if (0 == stricmp("rbbs", argv[2])) {
out_type = RBBS;
} else if (0 == stricmp("spitfire", argv[2])) {
out_type = SPITFIRE;
} else
help();
switch (in_type) {
case ULOWEL:
case CICA:
case CUG:
switch (out_type) {
case OPUS:
break;
case PCB:
case RBBS:
case SPITFIRE:
if (argc != 4)
help();
strcpy(path, argv[3]);
break;
default:
fprintf(stderr, "bad switch\n");
exit(1);
}
break;
case SIMTEL:
default:
break;
}
if (NULL == (logfile = fopen("logfile", "at"))) {
print_err("erroring opening logfile\n");
myexit(1);
}
while (1) {
rv = readline();
switch (out_type) {
case OPUS:
opus_writeline();
break;
case PCB:
pcb_writeline();
break;
case RBBS:
rbbs_writeline();
break;
case SPITFIRE:
spitfire_writeline();
break;
default:
assert(0);
break;
}
if (rv)
myexit(0);
}
}
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);
}