home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
TICKFBS
/
TICKFB.C
next >
Wrap
C/C++ Source or Header
|
1991-12-21
|
4KB
|
205 lines
#include <stdio.h>
#include <dir.h>
#include <dos.h>
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#define MAX_AREAS 1296
#define MAX_TICKS 200
int x, y, z, num_areas, c = 0;
typedef struct {
char marea[9];
char tarea[9];
} AREAS;
typedef struct {
char area[9];
} TICKS;
TICKS *info[MAX_TICKS];
AREAS *ctl[MAX_AREAS];
FILE *in, *out, *ctnl;
int main(int argc, char *argv[])
{
char filename[80];
struct ffblk fileinfo;
if(argc < 3)
{
printf("\nUsage:\n\t");
printf("TICKFB out_file area_dat [ctl_file]\n\nExample:\n\t");
printf("TICKFB D:\\MAX\\FBRUN.BAT AREA.DAT [D:\\MAX\\TICKFB.CTL]\n");
exit(255);
}
printf("\nTICKFB By Erik VanRiper (1:107/230@fidonet.org)\n\n" \
"This program is free for non-commercial use.\n");
if(argv[3] != NULL) c = 3;
if(c == 3)
{
if((ctnl = fopen(argv[3],"r")) == NULL)
{
printf("Unable to open! %s\n",argv[3]);
exit(255);
}
}
for(x = 0; x < MAX_TICKS; x++)
{
if((info[x] = malloc(sizeof(TICKS))) == NULL)
{
printf("\nOut of memory!\n");
exit(255);
}
}
for(x = 0; x < MAX_AREAS; x++)
{
if((ctl[x] = malloc(sizeof(AREAS))) == NULL)
{
printf("\nOut of memory!\n");
exit(255);
}
}
if(c == 3) parsectl();
fclose(ctnl);
x = y = z = 0;
if(findfirst("*.TIC", &fileinfo, 0) == 0)
tickfb(fileinfo.ff_name);
else
{
printf("\nNo files found.");
fclose(out);
for(x = 0; x < MAX_AREAS; x++) free(ctl[x]);
for(x = 0; x < MAX_TICKS; x++) free(info[x]);
exit(0);
}
while(findnext(&fileinfo) == 0)
tickfb(fileinfo.ff_name);
if(z)
{
if((out = fopen(argv[1],"wt")) == NULL)
{
printf("\a\aError, unable to open %s\n",argv[1]);
exit(255);
}
fprintf(out,"@echo off\nFB %s ",argv[2]);
for(y = 0; y < z; y++)
{
fprintf(out,"%s ",info[y]->area);
}
fprintf(out,"\n");
fclose(out);
}
for(x = 0; x < MAX_AREAS; x++) free(ctl[x]);
for(x = 0; x < MAX_TICKS; x++) free(info[x]);
if(z) return(1);
return(0);
}
parsectl()
{
char line[20], *token;
num_areas = 0;
while(fgets(line,19,ctnl) != NULL)
{
token = strtok(line," ");
if(token == NULL)
{
if(num_areas) return(1);
printf("\nError no. 1 in CTL file. line = %s \n",line);
exit(255);
}
strcpy(ctl[num_areas]->tarea,token);
token = strtok(NULL," \r\n");
if(token == NULL)
{
if(num_areas) return(1);
printf("\nError no. 2 in CTL file. line = %s\n",line);
exit(255);
}
strcpy(ctl[num_areas]->marea,token);
num_areas++;
}
return(1);
}
int tickfb(char *file)
{
char line[20], *token;
if((in = fopen(file,"rb")) == NULL)
{
printf("\rError, unable to open %s",file);
return(0);
}
memset(line,'\0',20);
fgets(line,19,in);
fclose(in);
token = strtok(line," ");
token = strtok(NULL,"\r\n ");
if(token != NULL)
{
y = 0;
if(c == 3)
{
for(x = 0; x < num_areas; x++)
{
if(strcmp(ctl[x]->tarea,token) == 0)
{
for(y = 0; y < z; y++)
{
if(strcmp(info[y]->area,ctl[x]->marea) == 0)
{
return(1);
}
}
strcpy(info[z]->area,ctl[x]->marea);
y = 1;
break;
}
}
}
if(y == 0)
{
for(y = 0; y < z; y++)
{
if(strcmp(info[y]->area,token) == 0)
{
return(1);
}
}
strcpy(info[z]->area,token);
}
printf("\n%-8s -=> %s",token,info[z]->area);
z++;
}
else printf("Err.");
return(1);
}