/* * :set tabstop=4 * (c) SPDsoft 1997 spd@daphne.cps.unizar.es * Mon Dec 29 21:04:25 MET 1997 * Check file for HP PCL data */ #include #include #include #include #define PATH_SEP '/' #define IDENT "@(#) check_pcl 0.0 (c) SPDsoft, Dec 29, 1997" #define Output_v if (G_prefs.verbose) fprintf #define Output if (!G_prefs.quiet) fprintf typedef struct { int quiet; int verbose; unsigned long zeros; } pref; pref G_prefs; static char __ident[] = IDENT; #define VERS_STR ((char*)&__ident[4]) #define ZEROS 1024 int check( FILE *f ); void get_options(int argc,char **argv); void usage(char *name); int main(int argc, char **argv); void get_options(int argc,char **argv) { int option; G_prefs.verbose= 0; G_prefs.quiet= 0; G_prefs.zeros= ZEROS; while ( (option=getopt(argc,argv,"z:qvVh")) != EOF ) { switch(option) { case 'z': G_prefs.zeros = strtoul(optarg,(char **)NULL, 0); break; case 'q': G_prefs.quiet = 1; break; case 'v': G_prefs.verbose = 1; break; case 'V': printf("%s\n",VERS_STR); break; default: usage(argv[0]); } } } void usage(char *name) { fprintf(stderr, "usage: %s [-z max][-q|-v][-V][-h] files...\n%s%d%s\n%s\n%s\n%s\n%s\n", name, "-z max: max trailing zeros (default: ", ZEROS, ")", "-q: quiet", "-v: verbose", "-V: version", "-h: This text" ); exit(-1); } int main(int argc, char **argv) { char *app; int res=0; FILE *f; if ((app = strrchr(argv[0], PATH_SEP)) != NULL) app = app+1; else app = argv[0]; get_options(argc,argv); Output_v(stdout,"zeros:\t%d\n", G_prefs.zeros); if (!argv[optind]) { Output(stdout,"(stdin):\t"); if ( 1 == check(stdin)) { res++; Output(stdout,"PCL\n"); } else { Output(stdout,"unknown\n"); } } else while(argv[optind]) { Output(stdout,"%s:\t", argv[optind]); if (( f = fopen(argv[optind], "rb")) == NULL) { Output(stdout,"%s\n", sys_errlist[errno]); } else { if ( 1 == check(f)) { res++; Output(stdout,"PCL\n"); } else { Output(stdout,"unknown\n"); } } fclose(f); optind ++; } return(!res); } int check( FILE *f ) { int c=0; int i; for( i=0; (c==0) && ( i < G_prefs.zeros ); c=fgetc(f)) i++; if (( c == EOF ) && ( 0 != ferror(f))) return 0; if ( (char) (c & 0x00ff) == 0x1b ) { c=fgetc(f); if ( ( (char) (c & 0x00ff) == 0x45 )|| ( (char) (c & 0x00ff) == 0x2a ) ) { return 1; } } return 0; }