#ifdef ournix #include "ournix.h" #endif char sccsID[] = "@(#) 8f.c V1.1 Copyright Julian H. Stacey, Munich, 1 March 1996\n" ; #include /* searches for strings like XÿÿÿÿÿÿÿÿX that were produced by a faulty cache chip in a bad scsi disc drive */ typedef char FLAG ; FLAG flag_print = 1 ; /* 0 = dont print each line, just summary */ int exit_code = 0 ; int eight = 8 ; /* looking for 8 0xff s in a row */ unsigned value = 0xFF ; /* looking for 8 0xff s in a row */ FLAG print_name = 0 ; char **ARGV ; main(argc, argv) int argc ; char **argv ; { FILE *fp ; char *p ; char *name ; ARGV = argv ; #ifdef VSL /* { */ #include "../../include/vsl.h" #endif /* } */ for (argc--, argv++ ; argc ; argv++, argc--) { if (**argv != '-') break ; p = *argv + 1 ; while(*p) switch(*p++) { case 'p': /* turn off print of lines during analysis */ flag_print = 0 ; break ; case 'n': /* number of adjacent identical bytes (if not 8 ) */ eight = atoi(*++argv) ; argc-- ; break ; case 'b': /* number of adjacent identical bytes (if not 8 ) */ eight = **++argv ; argc-- ; break ; default: fprintf(stderr, "Unknown flag %c\n", *(p-1)) ; syntax() ; break ; } } if (argc >= 2 ) /* like grep, print name of >= 2 files */ print_name = 1 ; if (argc == 0) exit(do_file(stdin,(char *)0)) ; else do { name = *argv++ ; fp = fopen(name, "r") ; if (fp == (FILE *)0) { fprintf(stderr, "Cannot open '%s'\n",name) ; exit_code += 1 ; continue ; } exit_code += do_file(fp, ( print_name ) ? name : (char *) 0) ; (void) fclose(fp) ; } while (--argc) ; exit(exit_code) ; } syntax() { fprintf(stderr,"Syntax Error: %s [-p] [-n number_of_bytes] [-b byte_value] [files]\n",*ARGV,*ARGV); exit(-1) ; } /* scan for blocks of eight 0xFFs within each line of a file, remember there might be more than one block within a line */ do_file(fp,name) register FILE *fp ; char *name ; { register int this_ch ; long line_count = 1 ; unsigned char_count = 0 ; /* number of character within the line, where the string of 0xFFs starts */ long byte_count = 0 ; int i ; FLAG sick = 0 ; while((this_ch = getc(fp)) != EOF) { char_count++ ; byte_count++ ; if ( this_ch == value ) { for ( i = eight - 1 ; byte_count++ && ((this_ch = getc(fp)) == value) && i-- ; ) ; if ( i <= 0 ) { if (flag_print) { byte_count -= eight ; if (name != (char *)0) printf( "%s:\t", name ) ; printf( "byte (dec) %ld\t(hex) %lx,\tline %ld\tcharacter %u\n", byte_count, byte_count, line_count, char_count) ; byte_count += eight ; } char_count += eight ; sick = 1 ; } } else if ( this_ch == '\n' ) { line_count++ ; char_count = 0 ; } } (void) fflush(stdout) ; return( sick ) ; }