]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - monitor/tbcp.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / monitor / tbcp.c
index 400e1ce0b37c2667c58348704a02053e6e242d00..20c5dcfb9c2b7f9e136af050b0d1b4df6764df96 100644 (file)
@@ -1,41 +1,18 @@
 /*
- * "$Id: tbcp.c 5087 2006-02-07 03:43:29Z mike $"
+ * TBCP port monitor for CUPS.
  *
- *   TBCP port monitor for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1993-2006 by Easy Software Products.
  *
- *   Copyright 1993-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main()    - Main entry...
- *   psgets()  - Get a line from a file.
- *   pswrite() - Write data from a file.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <cups/string.h>
-#include <cups/cups.h>
+#include <cups/cups-private.h>
+#include <cups/ppd.h>
 
 
 /*
@@ -43,7 +20,7 @@
  */
 
 static char            *psgets(char *buf, size_t *bytes, FILE *fp);
-static size_t          pswrite(const char *buf, size_t bytes, FILE *fp);
+static ssize_t         pswrite(const char *buf, size_t bytes);
 
 
 /*
@@ -66,7 +43,9 @@ main(int  argc,                               /* I - Number of command-line args */
 
   if (argc < 6 || argc > 7)
   {
-    fputs("ERROR: tbcp job-id user title copies options [file]\n", stderr);
+    _cupsLangPrintf(stderr,
+                    _("Usage: %s job-id user title copies options [file]"),
+                   argv[0]);
     return (1);
   }
 
@@ -100,11 +79,8 @@ main(int  argc,                             /* I - Number of command-line args */
     */
 
     linelen = sizeof(line);
-    if (psgets(line, &linelen, fp) == NULL)
-    {
-      fputs("ERROR: Empty print file!\n", stderr);
-      return (1);
-    }
+    if (!psgets(line, &linelen, fp))
+      break;
 
    /*
     * Handle leading PJL fun...
@@ -129,11 +105,10 @@ main(int  argc,                           /* I - Number of command-line args */
     else
     {
      /*
-      * No PJL stuff, add it...
+      * No PJL stuff, just add the UEL...
       */
 
-      puts("\033%-12345X@PJL");
-      puts("@PJL ENTER LANGUAGE = POSTSCRIPT");
+      fputs("\033%-12345X", stdout);
     }
 
    /*
@@ -146,7 +121,7 @@ main(int  argc,                             /* I - Number of command-line args */
     * Loop until we see end-of-file...
     */
 
-    while (pswrite(line, linelen, stdout) > 0)
+    while (pswrite(line, linelen) > 0)
     {
       linelen = sizeof(line);
       if (psgets(line, &linelen, fp) == NULL)
@@ -184,7 +159,7 @@ psgets(char   *buf,                 /* I  - Buffer to read into */
   bufptr = buf;
   ch     = EOF;
 
-  while ((bufptr - buf) < len)
+  while ((size_t)(bufptr - buf) < len)
   {
     if ((ch = getc(fp)) == EOF)
       break;
@@ -209,7 +184,7 @@ psgets(char   *buf,                 /* I  - Buffer to read into */
     else if (ch == '\n')
       break;
     else
-      *bufptr++ = ch;
+      *bufptr++ = (char)ch;
   }
 
  /*
@@ -218,8 +193,8 @@ psgets(char   *buf,                 /* I  - Buffer to read into */
 
   if (ch == '\n' || ch == '\r')
   {
-    if ((bufptr - buf) < len)
-      *bufptr++ = ch;
+    if ((size_t)(bufptr - buf) < len)
+      *bufptr++ = (char)ch;
     else
       ungetc(ch, fp);
   }
@@ -229,7 +204,7 @@ psgets(char   *buf,                 /* I  - Buffer to read into */
   */
 
   *bufptr = '\0';
-  *bytes  = bufptr - buf;
+  *bytes  = (size_t)(bufptr - buf);
 
   if (ch == EOF && bufptr == buf)
     return (NULL);
@@ -242,10 +217,9 @@ psgets(char   *buf,                        /* I  - Buffer to read into */
  * 'pswrite()' - Write data from a file.
  */
 
-static size_t                          /* O - Number of bytes written */
+static ssize_t                         /* O - Number of bytes written */
 pswrite(const char *buf,               /* I - Buffer to write */
-        size_t     bytes,              /* I - Bytes to write */
-       FILE       *fp)                 /* I - File to write to */
+        size_t     bytes)              /* I - Bytes to write */
 {
   size_t       count;                  /* Remaining bytes */
 
@@ -253,9 +227,19 @@ pswrite(const char *buf,           /* I - Buffer to write */
   for (count = bytes; count > 0; count --, buf ++)
     switch (*buf)
     {
+      case 0x04 : /* CTRL-D */
+          if (bytes == 1)
+         {
+          /*
+           * Don't quote the last CTRL-D...
+           */
+
+           putchar(0x04);
+           break;
+         }
+
       case 0x01 : /* CTRL-A */
       case 0x03 : /* CTRL-C */
-      case 0x04 : /* CTRL-D */
       case 0x05 : /* CTRL-E */
       case 0x11 : /* CTRL-Q */
       case 0x13 : /* CTRL-S */
@@ -274,10 +258,5 @@ pswrite(const char *buf,           /* I - Buffer to write */
          break;
     }
 
-  return (bytes);
+  return ((ssize_t)bytes);
 }
-
-
-/*
- * End of "$Id: tbcp.c 5087 2006-02-07 03:43:29Z mike $".
- */