Hello everyone! First off - I am beginner at this kind of stuff so please
bare with me on this. I am a firefighter at a fire station. We currently
have a program that runs "cygwin" on Windows and runs the following script.
I am trying to move this script over to a Ubuntu Server that runs faster
and more efficiently than the computer that is running Windows 2000.
The goal of this program is to capture a printout that is sent from the
dispatchers to a printer at our station. The program then reads the
printout line by line and determines if it needs to send the call to the
signboard displays and play a message. This program is hopefully able to
run continuously with no down time.
I finally have figured out how to compile the script and make it run,
however I get a segment fragmentation error when it runs. I have also been
told by someone who is smart in this kind of stuff that the reason the
program currently crashes so much in Windows is because it is not "releasing
memory" back to the system and is getting larger and larger until the
computer runs out of memory. A copy of the script is attached. Any help
in improving the script would be greatly appreciated!
Thanks again! J.R. Sellers
prealert.c File:
---
#include
#include
#include
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const
u_char *pkt_data);
void checklinesforaction(char *, char *, int, int *, int *, int *, int *);
void checkbackups(char *, char *, int *, int *, int *, int *);
void dispatchunits(char *, char *, char *, int *, int *, int *, int *);
void checklinesforaction(char *linetocheck, char *checkforcommand, int
setto, int *a, int *e, int *eb, int *t)
{
char * search;
search = 0;
search = strstr(linetocheck, checkforcommand);
if(search)
{
search = 0;
search = strstr(linetocheck, "A834");
if(search)
*a = setto;
search = 0;
search = strstr(linetocheck, "E834");
if(search)
*e = setto;
search = 0;
search = strstr(linetocheck, "E834B");
if(search)
*eb = setto;
search = 0;
search = strstr(linetocheck, "TK834");
if(search)
*t = setto;
}
}
void checkbackups(char *linetocheck, char *back, int *a, int *e, int *eb,
int *t)
{
char * search;
char * search2;
char first[16];
char hold[16];
search = 0;
search = strstr(linetocheck, back);
if(search)
{
search2 = 0;
search2 = strstr(search, "A834");
if(search2)
*a = 1;
search2 = 0;
search2 = strstr(search, "E834");
if(search2)
*e = 1;
search2 = 0;
search2 = strstr(search, "E834B");
if(search2)
*eb = 1;
search2 = 0;
search2 = strstr(search, "TK834");
if(search2)
*t = 1;
sscanf(search, "%s %s", hold, first);
if(strcmp("A834", first) == 0)
*a = 0;
if(strcmp("E834", first) == 0)
*e = 0;
if(strcmp("E834B", first) == 0)
*eb = 0;
if(strcmp("TK834", first) == 0)
*t = 0;
}
}
void dispatchunits(char *area, char *type, char *location, int *ap, int *ep,
int *ebp, int *tp)
{
int a = *ap;
int e = *ep;
int eb = *ebp;
int t = *tp;
int beforeflag = 0;
char betastring[256];
char talstring[256];
char soundstring[256];
sprintf(talstring, ":%s:%s %s\"", type, area, location);
sprintf(soundstring, "soundtest ");
if((a==1) && (e!=1) && (eb!=1) && (t!=1))
{
sprintf(betastring, "beta g r \"AMB:%s:%s %s\"", type, area, location);
system(betastring);
system("soundtest ambulance.wav");
printf("Dispatching AMBO:\n%s\n", betastring);
} else if( !(strcmp(type, "HOUSEF")) || !(strcmp(type, "BUILDF")) ||
!(strcmp(type, "APTF"))
|| !(strcmp(type, "2ALRM")) )
{
if( ((e==1) || (eb==1) || (t==1)) && !(strcmp(area, "34")) )
{
sprintf(betastring, "beta r r \"DUMP THE HOUSE! %s\"", location);
system(betastring);
system("soundtest house.wav");
printf("Dispatching FIRST DUE FIRE:\n%s\n", betastring);
} else if( ((e==1) || (eb==1) || (t==1)) )
{
strcat(soundstring, "fire");
sprintf(betastring, "beta r r \"");
if(t==1)
{
strcat(betastring, "TRK");
strcat(soundstring, "trk");
beforeflag = 1;
}
if(e==1)
{
if(beforeflag)
strcat(betastring, ":");
strcat(betastring, "ENG");
strcat(soundstring, "eng");
beforeflag = 1;
}
if(eb==1)
{
if(beforeflag)
strcat(betastring, ":");
strcat(betastring, "ENGB");
strcat(soundstring, "eng");
}
strcat(betastring, talstring);
strcat(soundstring, ".wav");
system(betastring);
system(soundstring);
printf("Dispatching FIRE:\n%s\n", betastring);
printf("%s\n", soundstring);
}
} else if(a==1 || e==1 || eb==1 || t==1)
{
sprintf(betastring, "beta y r \"");
if(t==1)
{
strcat(betastring, "TRK");
strcat(soundstring, "trk");
beforeflag = 1;
}
if(e==1)
{
if(beforeflag)
strcat(betastring, ":");
strcat(betastring, "ENG");
strcat(soundstring, "eng");
beforeflag = 1;
}
if(eb==1)
{
if(beforeflag)
strcat(betastring, ":");
strcat(betastring, "ENGB");
strcat(soundstring, "eng");
beforeflag = 1;
}
if(a==1)
{
if(beforeflag)
strcat(betastring, ":");
strcat(betastring, "AMB");
strcat(soundstring, "amb");
beforeflag = 1;
}
strcat(betastring, talstr