|
|
1.1 ! root 1: # include "stdio.h" ! 2: # include "assert.h" ! 3: # include "ctype.h" ! 4: # include "time.h" ! 5: # include "sys/types.h" ! 6: # include "sys/stat.h" ! 7: FILE *fo, *ft; ! 8: char code[10]; ! 9: int pass=0; ! 10: char passes[200][8]; ! 11: int np=0; ! 12: ! 13: main(argc,argv) ! 14: char *argv[]; ! 15: /* distributes weather. codes to pass through are on file in argv[1] */ ! 16: { ! 17: char lbuff[200], *line, *trim(); ! 18: if (argc>1) passlist(argv[1]); ! 19: while (gets(lbuff)) ! 20: { ! 21: line = trim(lbuff); ! 22: if (strlen(line)==8 && alldigs(line) && strncmp(line+3, "00",2)==0) ! 23: newcode(line+3); ! 24: if (pass) ! 25: puts(line); ! 26: if (fo) ! 27: fprintf(fo, "%s\n", line); ! 28: } ! 29: } ! 30: char * ! 31: trim(s) ! 32: char *s; ! 33: { ! 34: char *p; ! 35: while (*s &&iscntrl(*s)) s++; ! 36: for(p=s; *p; p++) ! 37: if (iscntrl(*p)) *p = ' '; ! 38: while (*--p == ' ') *p=0; ! 39: return(s); ! 40: } ! 41: newcode(s) ! 42: char *s; ! 43: { ! 44: long t, time(); ! 45: char fn[10], otherf[10]; ! 46: int i, k1, k2; ! 47: struct tm *localtime(), *tp; ! 48: struct stat thisbuf, otherbuf; ! 49: if (strcmp(s, code)==0) return; ! 50: if (fo!=NULL) fclose(fo); ! 51: strcpy(code, s); ! 52: t = time(0); ! 53: tp = localtime(&t); ! 54: sprintf(fn, "W%s%c", code, tp->tm_hour>=12 ? 'P' : 'A'); ! 55: sprintf(otherf, "W%s%c", code, tp->tm_hour<12 ? 'P' : 'A'); ! 56: k1=stat (fn, &thisbuf); ! 57: k2=stat (otherf, &otherbuf); ! 58: if (k1==0 && k2==0 && otherbuf.st_mtime > thisbuf.st_mtime) ! 59: unlink(fn); ! 60: fo = fopen(fn, "a"); ! 61: pass=0; ! 62: for(i=0; i<np; i++) ! 63: if (strcmp(passes[i], code)==0) ! 64: pass=1; ! 65: } ! 66: passlist(s) ! 67: char *s; ! 68: { ! 69: ft = fopen(s, "r"); ! 70: if (ft==NULL) return; ! 71: while (fgets(passes[np], 8, ft)) ! 72: passes[np++][5]=0; ! 73: } ! 74: alldigs(s) ! 75: char *s; ! 76: { ! 77: while (*s) ! 78: if (!isdigit(*s++)) ! 79: return(0); ! 80: return(1); ! 81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.