/* This program repeatly calls the alevt-cap program. It reads in the data file adding time information. */ #include #include #include #include #include int checkEndTime(int endHour, int endMin); int get_hour(); int get_minute(); int get_second(); int get_day(); int get_month(); int main(int argc, char *argv[]) { FILE *output_text; FILE *input_text; FILE *ftp_text; int counter,tocontinue,end_hour,end_minute,lastminute=0; int new_hour,new_minute,new_second; int end_month,end_day=0; int actualread; int end=0; int current_hour; int problem_file=0; char thecommand[20]; char filenames[24][14] = {"p5_hour0.txt","p5_hour1.txt","p5_hour2.txt","p5_hour3.txt","p5_hour4.txt","p5_hour5.txt","p5_hour6.txt","p5_hour7.txt","p5_hour8.txt","p5_hour9.txt","p5_hour10.txt","p5_hour11.txt","p5_hour12.txt","p5_hour13.txt","p5_hour14.txt","p5_hour15.txt","p5_hour16.txt","p5_hour17.txt","p5_hour18.txt","p5_hour19.txt","p5_hour20.txt","p5_hour21.txt","p5_hour22.txt","p5_hour23.txt"}; char thefilename[100]; char theline[41]; counter=0; end_minute=59; while(end == 0) { end_hour=get_hour(); current_hour=get_hour(); end_month=get_month(); end_day=get_day(); sprintf(thefilename,"/shasta/test/%d_%d_%s",end_month,end_day,filenames[current_hour]); sprintf(thecommand,"rm /shasta/test/%d_%d_%s",end_month,end_day,filenames[current_hour]); system(thecommand); problem_file=0; if ((output_text = fopen(thefilename,"w")) == NULL) { printf("Cannot open the output textfile [%s] \n",thefilename); problem_file=1; } else { fclose(output_text); } if ((output_text = fopen(thefilename,"a")) == NULL) { printf("Cannot open the output textfile [%s] \n",thefilename); problem_file=1; } tocontinue=0; if(problem_file == 0) { printf("TELEXT CAPTURING Hour %d [%d][%d]\n",current_hour,end_hour,end_minute); system("rm ttext-888.txt"); while(tocontinue !=1) { system("/home/teletext/paul_working/alevt-cap -vbi /dev/vbi0 -format ansi,reveal -timeout 90 888"); if ((input_text = fopen("ttext-888.txt","r")) == NULL) { printf("Cannot open the ttext-888.txt \n\n"); fprintf(output_text,"Problem reading teletext page"); } else { while(!feof(input_text)) { fread(theline, sizeof theline, 1,input_text); if(actualread > 18) { fwrite(theline, sizeof theline, 1,output_text); } actualread++; } new_hour=get_hour(); new_minute=get_minute(); new_second=get_second(); if(actualread > 20) { fprintf(output_text,"\n%d %d %d ",new_hour,new_minute,new_second); } actualread=0; fprintf(output_text,"\n"); fclose(input_text); tocontinue = checkEndTime(end_hour,end_minute); } } fclose(output_text); } // end if problem_file if(get_minute() == 59 ) { while(get_minute() != 0) { // wait until the minute changes } } } // end while infinity return 0; } // end main int get_day() { long tt; struct tm *Tm; time(&tt); Tm = localtime(&tt); return Tm->tm_mday; } int get_month() { long tt; struct tm *Tm; time(&tt); Tm = localtime(&tt); return Tm->tm_mon; } int get_hour() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_hour; } int get_minute() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_min; } int get_second() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_sec; } int checkEndTime(int endHour, int endMin) { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); if(Tm->tm_hour == endHour) { if(Tm->tm_min == endMin) { continueText = 1; } } else if(Tm->tm_hour > endHour) { continueText = 1; } return continueText; }