#include #include #include #include int main(int argc, char **argv) { static char progress[4]="|/-\\"; char buf[188]; char *sb; int sync=1; int cnt=0; FILE *f; char *fn; if (argc==2) { fn=strdup(argv[1]); f=fopen(fn,"r"); if (!f) { sprintf("Can't open \"%s\" - %s !\n",fn,strerror(errno)); exit(1); } } else { f=stdin; } while(fread(buf,1,188,f)==188) { if (!sync) { if (sb=strchr(buf,0x47)) { int res=188-(sb-buf); memcpy(buf,sb,res); fread(sb,1,res,stdin); puts("Re-Sync"); sync=1; } else { puts("Got buffer without sync"); } } else { if (*buf!=0x47) { puts("Sync lost"); sync=0; } else { cnt++; if ((cnt & 0xff) == 0) { fputc(progress[(cnt>>8)&0x3],stdout); fputc('\r',stdout); fflush(stdout); } } } } puts("*** EOF ***"); if (f!=stdin) fclose(f); exit(0); }