Count the number of pages in a PCL file.
-
The code below, would must to show the count the number of pages in a PCL file. But, don´t show. Why?? What is wrong?? //---------------------------------- #include "stdio.h" #include "stdlib.h" #include "string.h" int main (int argc, char **argv) { FILE *InputFile; char ch, EndTag, tag[2], *InputFileName; int n, BlockSize, Pages, Copies, Quiet; unsigned long FileSize, FilePos; BlockSize =0; Pages =0; FileSize =0; FilePos =0; Copies =0; Quiet =1; InputFileName = NULL; // Parse command line parameters for(n = 1; n <= argc - 1; n++) { if(! memcmp(argv[n], "-h", 2)) { printf("Error"); exit(0); } else if(! memcmp(argv[n], "-v", 2)) Quiet = 0; else if(argv[n][0] == '-') { fprintf(stderr, "-- Parameter incorrect: '%s'.\n", argv[n]); exit(1); } else InputFileName = argv[n]; } if(InputFileName == NULL) { fprintf(stderr, "-- Must enter a file name.\n \" Use 'pclcount -h' to get help.\n"); exit(1); } // Try to open the input file if(! (InputFile = fopen(InputFileName, "r"))) { fprintf(stderr, "--Error opening file: %s\n", argv[1]); exit(-1); }; // Get the file size, to show statistics if '-v' is passed if(! Quiet) { fseek(InputFile, 0, SEEK_END); FileSize = ftell(InputFile); fseek(InputFile, 0, SEEK_SET); } while(fread(&ch, 1, 1, InputFile)) { switch(ch) { case 12: // Found FormFeed: increments page counter Pages ++; break; case 27: // Found fread(tag, 2, 1, InputFile); if(! (memcmp(tag, "*b", 2) && memcmp(tag, "(s", 2) && memcmp(tag, ")s", 2) && memcmp(tag, "&p", 2))) { /* Detect the operators: *b###W -> Start of Binary Block (s###W -> Start of Characters Description Block )s###W -> Start of Fonts Description Block &p###X -> Start of non-printable Characters Block In these operators, '###' is the size of respective block. */ // Define the block end-character EndTag = memcm
-
The code below, would must to show the count the number of pages in a PCL file. But, don´t show. Why?? What is wrong?? //---------------------------------- #include "stdio.h" #include "stdlib.h" #include "string.h" int main (int argc, char **argv) { FILE *InputFile; char ch, EndTag, tag[2], *InputFileName; int n, BlockSize, Pages, Copies, Quiet; unsigned long FileSize, FilePos; BlockSize =0; Pages =0; FileSize =0; FilePos =0; Copies =0; Quiet =1; InputFileName = NULL; // Parse command line parameters for(n = 1; n <= argc - 1; n++) { if(! memcmp(argv[n], "-h", 2)) { printf("Error"); exit(0); } else if(! memcmp(argv[n], "-v", 2)) Quiet = 0; else if(argv[n][0] == '-') { fprintf(stderr, "-- Parameter incorrect: '%s'.\n", argv[n]); exit(1); } else InputFileName = argv[n]; } if(InputFileName == NULL) { fprintf(stderr, "-- Must enter a file name.\n \" Use 'pclcount -h' to get help.\n"); exit(1); } // Try to open the input file if(! (InputFile = fopen(InputFileName, "r"))) { fprintf(stderr, "--Error opening file: %s\n", argv[1]); exit(-1); }; // Get the file size, to show statistics if '-v' is passed if(! Quiet) { fseek(InputFile, 0, SEEK_END); FileSize = ftell(InputFile); fseek(InputFile, 0, SEEK_SET); } while(fread(&ch, 1, 1, InputFile)) { switch(ch) { case 12: // Found FormFeed: increments page counter Pages ++; break; case 27: // Found fread(tag, 2, 1, InputFile); if(! (memcmp(tag, "*b", 2) && memcmp(tag, "(s", 2) && memcmp(tag, ")s", 2) && memcmp(tag, "&p", 2))) { /* Detect the operators: *b###W -> Start of Binary Block (s###W -> Start of Characters Description Block )s###W -> Start of Fonts Description Block &p###X -> Start of non-printable Characters Block In these operators, '###' is the size of respective block. */ // Define the block end-character EndTag = memcm
raf-sp wrote: But, don´t show. Why?? What is wrong?? So what does it show? Is it off by one? Does the
while
loop not find any ASCII 12 characters? Remember that "page eject" in PCL can be any of the following commands: RESET (EcE) PAGE SIZE (Ec&l#A) PAGE LENGTH (Ec&l#P) ORIENTATION CHANGE (Ec&l#0) PAPER SOURCE CONTROL SEQUENCE (Ec&l0H) with a value of zero PAPER SOURCE (Ec&l#H)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
raf-sp wrote: But, don´t show. Why?? What is wrong?? So what does it show? Is it off by one? Does the
while
loop not find any ASCII 12 characters? Remember that "page eject" in PCL can be any of the following commands: RESET (EcE) PAGE SIZE (Ec&l#A) PAGE LENGTH (Ec&l#P) ORIENTATION CHANGE (Ec&l#0) PAPER SOURCE CONTROL SEQUENCE (Ec&l0H) with a value of zero PAPER SOURCE (Ec&l#H)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
This program should to show the number of pages a file it be printed in format HP-PCL. Does the while loop not find any ASCII 12 characters? No, no finds. raf-sp
How about using
fopen(InputFileName, "r**b**")
instead?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
How about using
fopen(InputFileName, "r**b**")
instead?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
If you could provide me with a link to a .pcl file, I can provide you with a code snippet to do what you require. - DC
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
If you could provide me with a link to a .pcl file, I can provide you with a code snippet to do what you require. - DC
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow