Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/printutils/lpr.c

    r2725 r3232  
    1212 * See RFC 1179 for protocol description.
    1313 */
     14
     15//usage:#define lpr_trivial_usage
     16//usage:       "-P queue[@host[:port]] -U USERNAME -J TITLE -Vmh [FILE]..."
     17/* -C CLASS exists too, not shown.
     18 * CLASS is supposed to be printed on banner page, if one is requested */
     19//usage:#define lpr_full_usage "\n\n"
     20//usage:       "    -P  lp service to connect to (else uses $PRINTER)"
     21//usage:     "\n    -m  Send mail on completion"
     22//usage:     "\n    -h  Print banner page too"
     23//usage:     "\n    -V  Verbose"
     24//usage:
     25//usage:#define lpq_trivial_usage
     26//usage:       "[-P queue[@host[:port]]] [-U USERNAME] [-d JOBID]... [-fs]"
     27//usage:#define lpq_full_usage "\n\n"
     28//usage:       "    -P  lp service to connect to (else uses $PRINTER)"
     29//usage:     "\n    -d  Delete jobs"
     30//usage:     "\n    -f  Force any waiting job to be printed"
     31//usage:     "\n    -s  Short display"
     32
    1433#include "libbb.h"
    1534
     
    7190    int fd;
    7291
     92    queue = getenv("PRINTER");
     93    if (!queue)
     94        queue = "lp";
     95
    7396    // parse options
    7497    // TODO: set opt_complementary: s,d,f are mutually exclusive
     
    80103    argv += optind;
    81104
    82     // if queue is not specified -> use $PRINTER
    83     if (!(opts & OPT_P))
    84         queue = getenv("PRINTER");
    85     // if queue is still not specified ->
    86     if (!queue) {
    87         // ... queue defaults to "lp"
    88         // server defaults to "localhost"
    89         queue = "lp";
    90     // if queue is specified ->
    91     } else {
     105    {
    92106        // queue name is to the left of '@'
    93107        char *s = strchr(queue, '@');
     
    168182        }
    169183
     184        st.st_size = 0; /* paranoia: fstat may theoretically fail */
     185        fstat(dfd, &st);
     186
     187        /* Apparently, some servers are buggy and won't accept 0-sized jobs.
     188         * Standard lpr works around it by refusing to send such jobs:
     189         */
     190        if (st.st_size == 0) {
     191            bb_error_msg("nothing to print");
     192            continue;
     193        }
     194
    170195        /* "The name ... should start with ASCII "cfA",
    171196         * followed by a three digit job number, followed
     
    192217            , remote_filename
    193218        );
    194         // delete possible "\nX\n" patterns
     219        // delete possible "\nX\n" (that is, one-char) patterns
    195220        c = controlfile;
    196         cflen = (unsigned)strlen(controlfile);
    197221        while ((c = strchr(c, '\n')) != NULL) {
    198222            if (c[1] && c[2] == '\n') {
    199                 /* can't use strcpy, results are undefined */
    200                 memmove(c, c+2, cflen - (c-controlfile) - 1);
    201                 cflen -= 2;
     223                overlapping_strcpy(c, c+2);
    202224            } else {
    203225                c++;
     
    210232        /* "Acknowledgement processing must occur as usual
    211233         * after the command is sent." */
     234        cflen = (unsigned)strlen(controlfile);
    212235        fdprintf(fd, "\x2" "%u c%s\n", cflen, remote_filename);
    213236        get_response_or_say_and_die(fd, "sending control file");
     
    223246        if (opts & LPR_V)
    224247            bb_error_msg("sending data file");
    225         st.st_size = 0; /* paranoia: fstat may theoretically fail */
    226         fstat(dfd, &st);
    227248        fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename);
    228249        get_response_or_say_and_die(fd, "sending data file");
Note: See TracChangeset for help on using the changeset viewer.