| 1 | /* |
| 2 | * CANON BJ command filter for the Common UNIX Printing System. |
| 3 | * |
| 4 | * |
| 5 | * Contents: |
| 6 | * |
| 7 | * main() - Main entry and command processing. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Include necessary headers... |
| 12 | */ |
| 13 | |
| 14 | #include <cups/cups.h> |
| 15 | #include <ctype.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <stdio.h> |
| 18 | #include <strings.h> |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | * Macros... |
| 23 | */ |
| 24 | |
| 25 | #define pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!(s,n) fwrite((s), 1, (n), stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * 'main()' - Main entry and processing of driver. |
| 30 | */ |
| 31 | |
| 32 | int /* O - Exit status */ |
| 33 | maincxx . . $ main(afcd3168fc1188a4).(int argc, /* I - Number of command-line arguments */ |
| 34 | char *argv[]) /* I - Command-line arguments */ |
| 35 | { |
| 36 | FILEcxx . . $ FILE# *fp; /* Command file */ |
| 37 | char line[1024], /* Line from file */ |
| 38 | *lineptr; /* Pointer into line */ |
| 39 | int feedpage; /* Feed the page */ |
| 40 | |
| 41 | |
| 42 | /* |
| 43 | * Check for valid arguments... |
| 44 | */ |
| 45 | |
| 46 | if (argc < 6 || argc > 7) |
| 47 | { |
| 48 | /* |
| 49 | * We don't have the correct number of arguments; write an error message |
| 50 | * and return. |
| 51 | */ |
| 52 | |
| 53 | fputscxx . . $ fputs(874fa6a5e59ab9bd).("ERROR: commandtocanon job-id user title copies options [file]\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 54 | return (1); |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Open the command file as needed... |
| 59 | */ |
| 60 | |
| 61 | if (argc == 7) |
| 62 | { |
| 63 | if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[6], "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 64 | { |
| 65 | perrorcxx . . $ perror(85c52e162fed56f9).("ERROR: Unable to open command file - "); |
| 66 | return (1); |
| 67 | } |
| 68 | } |
| 69 | else |
| 70 | fp = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!; |
| 71 | |
| 72 | /* |
| 73 | * Reset the printer and initiate BJL mode |
| 74 | */ |
| 75 | |
| 76 | pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("\x1b\x5b\x4b\x02\x00\x00\x1f" "BJLSTART\x0a", 16); |
| 77 | feedpage = 0; |
| 78 | |
| 79 | /* |
| 80 | * Read the commands from the file and send the appropriate commands... |
| 81 | */ |
| 82 | |
| 83 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(line, sizeof(line), fp) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 84 | { |
| 85 | /* |
| 86 | * Drop trailing newline... |
| 87 | */ |
| 88 | |
| 89 | lineptr = line + strlencxx . . $ strlen(751346f8406fd082).(line) - 1; |
| 90 | if (*lineptr == '\n') |
| 91 | *lineptr = '\0'; |
| 92 | |
| 93 | /* |
| 94 | * Skip leading whitespace... |
| 95 | */ |
| 96 | |
| 97 | for (lineptr = line; isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*lineptr); lineptr ++); |
| 98 | |
| 99 | /* |
| 100 | * Skip comments and blank lines... |
| 101 | */ |
| 102 | |
| 103 | if (*lineptr == '#' || !*lineptr) |
| 104 | continue; |
| 105 | |
| 106 | /* |
| 107 | * Parse the command... |
| 108 | */ |
| 109 | |
| 110 | if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "Clean", 5) == 0) |
| 111 | { |
| 112 | /* |
| 113 | * Clean heads... |
| 114 | */ |
| 115 | |
| 116 | char *what; |
| 117 | |
| 118 | for (what = lineptr + 6; isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*what); what ++); |
| 119 | |
| 120 | if (*what == 0) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@Cleaning=1ALL\x0a", 15); |
| 121 | if (!strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(what,"all",3)) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@Cleaning=1ALL\x0a", 15); |
| 122 | if (!strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(what,"black",5)) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@Cleaning=1K\x0a", 13); |
| 123 | |
| 124 | } |
| 125 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "PrintAlignmentPage", 18) == 0) |
| 126 | { |
| 127 | /* |
| 128 | * Print alignment page... |
| 129 | */ |
| 130 | |
| 131 | int phase; |
| 132 | |
| 133 | phase = atoicxx . . $ atoi(5c4306d8553b3696).(lineptr + 18); |
| 134 | |
| 135 | if (phase==0) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@TestPrint=Auto\x0a", 16); |
| 136 | if (phase==1) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@TestPrint=Manual1\x0a", 19); |
| 137 | if (phase==2) pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@TestPrint=Manual2\x0a", 19); |
| 138 | |
| 139 | feedpage = 0; |
| 140 | } |
| 141 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "PrintSelfTestPage", 17) == 0) |
| 142 | { |
| 143 | /* |
| 144 | * Print version info and nozzle check... |
| 145 | */ |
| 146 | |
| 147 | pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("@TestPrint=NozzleCheck\x0a", 23); |
| 148 | |
| 149 | feedpage = 0; |
| 150 | } |
| 151 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "ReportLevels", 12) == 0) |
| 152 | { |
| 153 | /* |
| 154 | * Report ink levels... |
| 155 | */ |
| 156 | |
| 157 | } |
| 158 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "SetAlignment", 12) == 0) |
| 159 | { |
| 160 | /* |
| 161 | * Set head alignment... |
| 162 | */ |
| 163 | |
| 164 | } |
| 165 | else |
| 166 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Invalid printer command \"%s\"!\n", lineptr); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * Exit remote mode... |
| 171 | */ |
| 172 | |
| 173 | pwritecxx . . $ `src/cups/commandtocanon.c:25:9`!("BJLEND\x0a", 7); |
| 174 | |
| 175 | /* |
| 176 | * Eject the page as needed... |
| 177 | */ |
| 178 | |
| 179 | if (feedpage) |
| 180 | { |
| 181 | putcharcxx . . $ putchar(7864480464b09eea).(13); |
| 182 | putcharcxx . . $ putchar(7864480464b09eea).(10); |
| 183 | putcharcxx . . $ putchar(7864480464b09eea).(12); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Close the command file and return... |
| 188 | */ |
| 189 | |
| 190 | if (fp != stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!) |
| 191 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp); |
| 192 | |
| 193 | return (0); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | /* |
| 198 | */ |