| 1 | /* |
| 2 | * EPSON ESC/P2 command filter for the Common UNIX Printing System. |
| 3 | * |
| 4 | * Copyright 1993-2000 by Easy Software Products. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free |
| 8 | * Software Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Contents: |
| 20 | * |
| 21 | * main() - Main entry and command processing. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Include necessary headers... |
| 26 | */ |
| 27 | |
| 28 | #include <cups/cups.h> |
| 29 | #include <ctype.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <stdio.h> |
| 33 | #include <strings.h> |
| 34 | |
| 35 | /* |
| 36 | * Macros... |
| 37 | */ |
| 38 | |
| 39 | #define pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!(s,n) fwrite((s), 1, (n), stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!) |
| 40 | |
| 41 | |
| 42 | /* |
| 43 | * 'main()' - Main entry and processing of driver. |
| 44 | */ |
| 45 | |
| 46 | int /* O - Exit status */ |
| 47 | maincxx . . $ main(afcd3168fc1188a4).(int argc, /* I - Number of command-line arguments */ |
| 48 | char *argv[]) /* I - Command-line arguments */ |
| 49 | { |
| 50 | FILEcxx . . $ FILE# *fp; /* Command file */ |
| 51 | char line[1024], /* Line from file */ |
| 52 | *lineptr; /* Pointer into line */ |
| 53 | int feedpage; /* Feed the page */ |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * Check for valid arguments... |
| 58 | */ |
| 59 | |
| 60 | if (argc < 6 || argc > 7) |
| 61 | { |
| 62 | /* |
| 63 | * We don't have the correct number of arguments; write an error message |
| 64 | * and return. |
| 65 | */ |
| 66 | |
| 67 | fputscxx . . $ fputs(874fa6a5e59ab9bd).("ERROR: commandtoepson job-id user title copies options [file]\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 68 | return (1); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Open the command file as needed... |
| 73 | */ |
| 74 | |
| 75 | if (argc == 7) |
| 76 | { |
| 77 | if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[6], "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 78 | { |
| 79 | perrorcxx . . $ perror(85c52e162fed56f9).("ERROR: Unable to open command file - "); |
| 80 | return (1); |
| 81 | } |
| 82 | } |
| 83 | else |
| 84 | fp = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!; |
| 85 | |
| 86 | /* |
| 87 | * Reset the printer... |
| 88 | */ |
| 89 | |
| 90 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("\033@", 2); |
| 91 | |
| 92 | /* |
| 93 | * Enter remote mode... |
| 94 | */ |
| 95 | |
| 96 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("\033(R\010\000\000REMOTE1", 13); |
| 97 | feedpage = 0; |
| 98 | |
| 99 | /* |
| 100 | * Read the commands from the file and send the appropriate commands... |
| 101 | */ |
| 102 | |
| 103 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(line, sizeof(line), fp) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 104 | { |
| 105 | /* |
| 106 | * Drop trailing newline... |
| 107 | */ |
| 108 | |
| 109 | lineptr = line + strlencxx . . $ strlen(751346f8406fd082).(line) - 1; |
| 110 | if (*lineptr == '\n') |
| 111 | *lineptr = '\0'; |
| 112 | |
| 113 | /* |
| 114 | * Skip leading whitespace... |
| 115 | */ |
| 116 | |
| 117 | for (lineptr = line; isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*lineptr); lineptr ++); |
| 118 | |
| 119 | /* |
| 120 | * Skip comments and blank lines... |
| 121 | */ |
| 122 | |
| 123 | if (*lineptr == '#' || !*lineptr) |
| 124 | continue; |
| 125 | |
| 126 | /* |
| 127 | * Parse the command... |
| 128 | */ |
| 129 | |
| 130 | if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "Clean", 5) == 0) |
| 131 | { |
| 132 | /* |
| 133 | * Clean heads... |
| 134 | */ |
| 135 | |
| 136 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("CH\002\000\000\000", 6); |
| 137 | } |
| 138 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "PrintAlignmentPage", 18) == 0) |
| 139 | { |
| 140 | /* |
| 141 | * Print alignment page... |
| 142 | */ |
| 143 | |
| 144 | int phase; |
| 145 | |
| 146 | phase = atoicxx . . $ atoi(5c4306d8553b3696).(lineptr + 18); |
| 147 | |
| 148 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("DT\003\000\000", 5); |
| 149 | putcharcxx . . $ putchar(7864480464b09eea).(phase & 255); |
| 150 | putcharcxx . . $ putchar(7864480464b09eea).(phase >> 8); |
| 151 | feedpage = 1; |
| 152 | } |
| 153 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "PrintSelfTestPage", 17) == 0) |
| 154 | { |
| 155 | /* |
| 156 | * Print version info and nozzle check... |
| 157 | */ |
| 158 | |
| 159 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("VI\002\000\000\000", 6); |
| 160 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("NC\002\000\000\000", 6); |
| 161 | feedpage = 1; |
| 162 | } |
| 163 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "ReportLevels", 12) == 0) |
| 164 | { |
| 165 | /* |
| 166 | * Report ink levels... |
| 167 | */ |
| 168 | |
| 169 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("IQ\001\000\001", 5); |
| 170 | } |
| 171 | else if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(lineptr, "SetAlignment", 12) == 0) |
| 172 | { |
| 173 | /* |
| 174 | * Set head alignment... |
| 175 | */ |
| 176 | |
| 177 | int phase, x; |
| 178 | |
| 179 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(lineptr + 12, "%d%d", &phase, &x) != 2) |
| 180 | { |
| 181 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Invalid printer command \"%s\"!\n", lineptr); |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("DA\004\000", 4); |
| 186 | putcharcxx . . $ putchar(7864480464b09eea).(0); |
| 187 | putcharcxx . . $ putchar(7864480464b09eea).(phase); |
| 188 | putcharcxx . . $ putchar(7864480464b09eea).(0); |
| 189 | putcharcxx . . $ putchar(7864480464b09eea).(x); |
| 190 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("SV\000\000", 4); |
| 191 | } |
| 192 | else |
| 193 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Invalid printer command \"%s\"!\n", lineptr); |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Exit remote mode... |
| 198 | */ |
| 199 | |
| 200 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("\033\000\000\000", 4); |
| 201 | |
| 202 | /* |
| 203 | * Eject the page as needed... |
| 204 | */ |
| 205 | |
| 206 | if (feedpage) |
| 207 | { |
| 208 | putcharcxx . . $ putchar(7864480464b09eea).(13); |
| 209 | putcharcxx . . $ putchar(7864480464b09eea).(10); |
| 210 | putcharcxx . . $ putchar(7864480464b09eea).(12); |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Reset the printer... |
| 215 | */ |
| 216 | |
| 217 | pwritecxx . . $ `src/cups/commandtoepson.c:39:9`!("\033@", 2); |
| 218 | |
| 219 | /* |
| 220 | * Close the command file and return... |
| 221 | */ |
| 222 | |
| 223 | if (fp != stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!) |
| 224 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp); |
| 225 | |
| 226 | return (0); |
| 227 | } |