summaryrefslogtreecommitdiff
path: root/src/escputil/escputil.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/escputil/escputil.c')
-rw-r--r--src/escputil/escputil.c194
1 files changed, 99 insertions, 95 deletions
diff --git a/src/escputil/escputil.c b/src/escputil/escputil.c
index 5394b77..a28cd07 100644
--- a/src/escputil/escputil.c
+++ b/src/escputil/escputil.c
@@ -1,5 +1,5 @@
/*
- * "$Id: escputil.c,v 1.87.8.1 2007/05/29 01:47:27 rlk Exp $"
+ * "$Id: escputil.c,v 1.87.8.3 2007/12/29 20:42:25 rlk Exp $"
*
* Printer maintenance utility for EPSON Stylus (R) printers
*
@@ -150,11 +150,12 @@ Examples: escputil --ink-level --raw-device /dev/usb/lp0\n\
Default is the default system printer.\n\
-r|--raw-device Specify the name of the device to write to directly\n\
rather than going through a printer queue.\n\
+ -m|--model Specify the printer model.\n\
-u|--new The printer is a new printer (Stylus Color 740 or\n\
- newer). Only needed when not using a raw device.\n\
+ newer). Only needed when not using a raw device or\n\
+ when the model is not specified.\n\
-q|--quiet Suppress the banner.\n\
-S|--short-name Print the short name of the printer with --identify.\n\
- -m|--model Specify the precise printer model for head alignment.\n\
-C|--choices Specify the number of pattern choices for alignment\n\
-p|--patterns Specify the number of sets of patterns for alignment\n");
#else
@@ -207,6 +208,7 @@ char *printer_model = NULL;
char printer_cmd[1025];
int bufpos = 0;
int isnew = 0;
+int interchangeable_inks = 0;
int found_unknown_old_printer = 0;
int print_short_name = 0;
const stp_printer_t *the_printer_t = NULL;
@@ -286,7 +288,9 @@ main(int argc, char **argv)
/* Set up gettext */
#ifdef HAVE_LOCALE_H
- setlocale (LC_ALL, "");
+ char *locale = stp_strdup(setlocale (LC_ALL, ""));
+#endif
+#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
#endif
@@ -300,9 +304,9 @@ main(int argc, char **argv)
{
#if defined(HAVE_GETOPT_H) && defined(HAVE_GETOPT_LONG)
int option_index = 0;
- c = getopt_long(argc, argv, "P:r:iecnasduqm:hlMS", optlist, &option_index);
+ c = getopt_long(argc, argv, "P:r:iecnasduqm:hlMSC:p:", optlist, &option_index);
#else
- c = getopt(argc, argv, "P:r:iecnasduqm:hlMS");
+ c = getopt(argc, argv, "P:r:iecnasduqm:hlMSC:p:");
#endif
if (c == -1)
break;
@@ -649,28 +653,6 @@ do_remote_cmd_only(const char *cmd, int nargs, ...)
}
static void
-add_string(const char *str, int size)
-{
- if (size > 0)
- {
- memcpy(printer_cmd + bufpos, str, size);
- bufpos += size;
- }
-}
-
-static void
-add_newlines(int count)
-{
- int i;
- STP_DEBUG(fprintf(stderr, "Add %d newlines\n", count));
- for (i = 0; i < count; i++)
- {
- printer_cmd[bufpos++] = '\r';
- printer_cmd[bufpos++] = '\n';
- }
-}
-
-static void
add_resets(int count)
{
int i;
@@ -759,14 +741,54 @@ open_raw_device(void)
return fd;
}
+static void
+set_printer_model(void)
+{
+ int i = 0;
+ int printer_count = stp_printer_model_count();
+ for (i = 0; i < printer_count; i++)
+ {
+ the_printer_t = stp_get_printer_by_index(i);
+
+ if (strcmp(stp_printer_get_family(the_printer_t), "escp2") == 0)
+ {
+ const char *short_name = stp_printer_get_driver(the_printer_t);
+ const char *long_name = stp_printer_get_long_name(the_printer_t);
+ if (!strcasecmp(printer_model, short_name) ||
+ !strcasecmp(printer_model, long_name) ||
+ (!strncmp(short_name, "escp2-", strlen("escp2-")) &&
+ !strcasecmp(printer_model, short_name + strlen("escp2-"))) ||
+ (!strncasecmp(long_name, "Epson ", strlen("Epson ")) &&
+ !strcasecmp(printer_model, long_name + strlen("Epson "))))
+ {
+ const stp_vars_t *printvars;
+ stp_parameter_t desc;
+
+ printvars = stp_printer_get_defaults(the_printer_t);
+ stp_describe_parameter(printvars, "SupportsPacketMode",
+ &desc);
+ if (desc.p_type == STP_PARAMETER_TYPE_BOOLEAN)
+ isnew = desc.deflt.boolean;
+ stp_parameter_description_destroy(&desc);
+ stp_describe_parameter(printvars, "InterchangeableInk",
+ &desc);
+ if (desc.p_type == STP_PARAMETER_TYPE_BOOLEAN)
+ interchangeable_inks = desc.deflt.boolean;
+ stp_parameter_description_destroy(&desc);
+ STP_DEBUG(fprintf(stderr, "Found it! %s\n", printer_model));
+ return;
+ }
+ }
+ }
+ fprintf(stderr, _("Unknown printer %s!\n"), printer_model);
+ the_printer_t = NULL;
+}
+
static const stp_printer_t *
initialize_printer(int quiet, int fail_if_not_found)
{
- int printer_count = stp_printer_model_count();
- int found = 0;
int packet_initialized = 0;
int fd;
- int i;
int credit;
int retry = 4;
int tries = 0;
@@ -847,15 +869,16 @@ initialize_printer(int quiet, int fail_if_not_found)
do
{
status = readData(fd, socket_id, (unsigned char*)buf, 1023);
- if (status <= -1 )
- return NULL;
STP_DEBUG(fprintf(stderr, "readData try %d status %d\n",
retry, status));
+ if (status <= -1 )
+ return NULL;
}
while ( (retry-- != 0) && strncmp("di", (char*)buf, 2) &&
strncmp("@EJL ID", (char*)buf, 7));
if (!retry)
{
+ STP_DEBUG(fprintf(stderr, "No retries left!\n"));
return NULL;
}
}
@@ -905,7 +928,10 @@ initialize_printer(int quiet, int fail_if_not_found)
printer_model = c_strdup("escp2-photo");
}
else
- return NULL;
+ {
+ STP_DEBUG(fprintf(stderr, "Can't get response to @EJL ID\n"));
+ return NULL;
+ }
}
else
{
@@ -917,38 +943,7 @@ initialize_printer(int quiet, int fail_if_not_found)
}
}
- i = 0;
- while ((i < printer_count) && !found)
- {
- the_printer_t = stp_get_printer_by_index(i);
-
- if (strcmp(stp_printer_get_family(the_printer_t), "escp2") == 0)
- {
- const char *short_name = stp_printer_get_driver(the_printer_t);
- const char *long_name = stp_printer_get_long_name(the_printer_t);
- if (!strcasecmp(printer_model, short_name) ||
- !strcasecmp(printer_model, long_name) ||
- (!strncmp(short_name, "escp2-", strlen("escp2-")) &&
- !strcasecmp(printer_model, short_name + strlen("escp2-"))) ||
- (!strncasecmp(long_name, "Epson ", strlen("Epson ")) &&
- !strcasecmp(printer_model, long_name + strlen("Epson "))))
- {
- const stp_vars_t *printvars;
- stp_parameter_t desc;
-
- printvars = stp_printer_get_defaults(the_printer_t);
- stp_describe_parameter(printvars, "SupportsPacketMode",
- &desc);
- if (desc.p_type == STP_PARAMETER_TYPE_BOOLEAN)
- isnew = desc.deflt.boolean;
- stp_parameter_description_destroy(&desc);
- found = 1;
- STP_DEBUG(fprintf(stderr, "Found it! %s\n", printer_model));
-
- }
- }
- i++;
- }
+ set_printer_model();
if (isnew && !packet_initialized)
{
@@ -956,9 +951,8 @@ initialize_printer(int quiet, int fail_if_not_found)
}
close(fd);
- STP_DEBUG(fprintf(stderr, "new? %s found? %s\n", isnew?"yes":"no",
- found?"yes":"no"));
- return (found)?the_printer_t:NULL;
+ STP_DEBUG(fprintf(stderr, "new? %s\n", isnew ? "yes" : "no"));
+ return the_printer_t;
}
static const stp_printer_t *
@@ -1003,18 +997,18 @@ static const char *aux_colors[] =
N_("Cyan"), /* 1 */
N_("Magenta"), /* 2 */
N_("Yellow"), /* 3 */
- N_("Unknown"), /* 4 */
- N_("Unknown"), /* 5 */
- N_("Unknown"), /* 6 */
- N_("Unknown"), /* 7 */
- N_("Unknown"), /* 8 */
+ NULL, /* 4 */
+ NULL, /* 5 */
+ NULL, /* 6 */
+ NULL, /* 7 */
+ NULL, /* 8 */
N_("Red"), /* 9 */
N_("Blue"), /* a */
- N_("Unknown"), /* b */
- N_("Unknown"), /* c */
- N_("Unknown"), /* d */
- N_("Unknown"), /* e */
- N_("Unknown"), /* f */
+ NULL, /* b */
+ NULL, /* c */
+ NULL, /* d */
+ NULL, /* e */
+ NULL, /* f */
};
static int aux_color_count = sizeof(aux_colors) / sizeof(const char *);
@@ -1239,24 +1233,26 @@ do_new_status(status_cmd_t cmd, char *buf, int bytes,
STP_DEBUG(fprintf(stderr, "Header: %x param count: %d\n", hdr, total_param_count));
if (hdr == 0x0f) /* Always report ink */
{
- size_t count = (total_param_count - 1) / 3;
+ size_t count = (total_param_count - 1) / param;
ind = buf + i + 3;
if (cmd == CMD_STATUS)
printf(_("Ink Levels:\n"));
printf("%18s %20s\n", _("Ink color"), _("Percent remaining"));
for (j = 0; j < count; j++)
{
- if (ind[0] < color_count)
+ if (ind[0] < color_count && param == 3 &&
+ (interchangeable_inks || ind[1] >= aux_color_count ||
+ ! aux_colors[(int) ind[1]]))
printf("%18s %20d\n",
gettext(colors_new[(int) ind[0]]), ind[2]);
- else if (ind[j] == 0x40 && ind[1] < aux_color_count)
+ else if (ind[1] < aux_color_count && aux_colors[(int) ind[1]])
printf("%18s %20d\n",
gettext(aux_colors[(int) ind[1]]), ind[2]);
else
printf("%8s 0x%2x 0x%2x %20d\n",
_("Unknown"), (unsigned char) ind[0],
(unsigned char) ind[1], ind[2]);
- ind += 3;
+ ind += param;
}
if (cmd == CMD_STATUS)
printf("\n");
@@ -1362,7 +1358,7 @@ do_status_command_internal(status_cmd_t cmd)
if (!found_unknown_old_printer)
STP_DEBUG(fprintf(stderr, "%s found %s%s\n", gettext(cmd_name),
printer ? stp_printer_get_long_name(printer) :
- printer_model,
+ printer_model ? printer_model : "(null)",
printer ? "" : "(Unknown model)"));
fd = open_raw_device();
@@ -1471,7 +1467,7 @@ do_extended_ink_info(int extended_output)
else
fprintf(stderr,
"Warning! Printer %s is not known; information may be incomplete or incorrect\n",
- printer_model);
+ printer_model ? printer_model : "(unknown printer)");
fd = open_raw_device();
@@ -1599,7 +1595,7 @@ do_extended_ink_info(int extended_output)
{
int j;
printf("%18s %20s %12s %7s\n",
- _("Ink color"), _("Percent remaining"), _("Part number"),
+ _("Ink cartridge"), _("Percent remaining"), _("Part number"),
_("Date"));
printf("%18s %20d T0%03d %2d%02d-%02d\n",
gettext(stp_string_list_param(color_list, 0)->text),
@@ -1623,7 +1619,7 @@ do_extended_ink_info(int extended_output)
{
int j;
printf("%18s %20s %12s %7s\n",
- _("Ink color"), _("Percent remaining"), _("Part number"),
+ _("Ink cartridge"), _("Percent remaining"), _("Part number"),
_("Date"));
printf("%18s %20d T0%03d %2d%02d-%02d\n",
gettext(stp_string_list_param(color_list, 0)->text),
@@ -1643,7 +1639,7 @@ do_extended_ink_info(int extended_output)
{
if (i == 0)
printf("%18s %20s %12s %7s\n",
- _("Ink color"), _("Percent remaining"), _("Part number"),
+ _("Ink cartridge"), _("Percent remaining"), _("Part number"),
_("Date"));
printf("%18s %20d T0%03d %2d%02d-%02d\n",
gettext(stp_string_list_param(color_list, i)->text),
@@ -1706,7 +1702,9 @@ do_status(void)
void
do_head_clean(void)
{
- if (raw_device)
+ if (printer_model)
+ set_printer_model();
+ else if (raw_device)
(void) get_printer(1, 0);
initialize_print_cmd(1);
do_remote_cmd("CH", 2, 0, 0);
@@ -1717,7 +1715,9 @@ do_head_clean(void)
void
do_nozzle_check(void)
{
- if (raw_device)
+ if (printer_model)
+ set_printer_model();
+ else if (raw_device)
(void) get_printer(1, 0);
initialize_print_cmd(1);
start_remote_sequence();
@@ -1905,7 +1905,7 @@ do_final_alignment(void)
}
const char *printer_msg =
-N_("This procedure assumes that your printer is an Epson %s.\n"
+N_("This procedure assumes that your printer is an %s.\n"
"If this is not your printer model, please type control-C now and\n"
"choose your actual printer model.\n\n"
"Please place a sheet of paper in your printer to begin the head\n"
@@ -1921,16 +1921,20 @@ do_align(void)
long answer;
char *endptr;
int curpass;
- const stp_printer_t *printer = get_printer(0, 0);
stp_parameter_t desc;
const char *printer_name;
stp_vars_t *v = stp_vars_create();
- if (!printer || found_unknown_old_printer)
+ if (printer_model)
+ set_printer_model();
+ else if (raw_device)
+ (void) get_printer(0, 0);
+
+ if (!the_printer_t || found_unknown_old_printer)
return;
- printer_name = stp_printer_get_long_name(printer);
- stp_set_driver(v, stp_printer_get_driver(printer));
+ printer_name = stp_printer_get_long_name(the_printer_t);
+ stp_set_driver(v, stp_printer_get_driver(the_printer_t));
if (alignment_passes == 0)
{