]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add BCP and TBCP port monitors.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 7 Feb 2006 03:43:29 +0000 (03:43 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 7 Feb 2006 03:43:29 +0000 (03:43 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5087 7a7537e8-13f0-0310-91df-b6672ffda945

Makefile
monitor/Dependencies [new file with mode: 0644]
monitor/Makefile [new file with mode: 0644]
monitor/bcp.c [new file with mode: 0644]
monitor/tbcp.c [new file with mode: 0644]
packaging/cups.spec.in

index 79d585915bbfb816febd6eaf68adc6c6643e1ee4..cb4d77403d621ccf023cb0d3eded41575d86d553 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,8 +28,9 @@ include Makedefs
 # Directories to make...
 #
 
-DIRS   =       cups backend berkeley cgi-bin filter locale man pdftops \
-               notifier scheduler systemv test
+DIRS   =       cups backend berkeley cgi-bin filter locale man monitor \
+               notifier pdftops scheduler systemv test
+
 
 #
 # Make all targets...
@@ -42,6 +43,7 @@ all:
                (cd $$dir ; $(MAKE) $(MFLAGS)) || exit 1;\
        done
 
+
 #
 # Remove object and target files...
 #
@@ -52,6 +54,7 @@ clean:
                (cd $$dir; $(MAKE) $(MFLAGS) clean) || exit 1;\
        done
 
+
 #
 # Make dependencies
 #
@@ -166,6 +169,7 @@ pkg:
 tardist:
        epm $(EPMFLAGS) -f tardist cups packaging/cups.list
 
+
 #
 # End of "$Id$".
 #
diff --git a/monitor/Dependencies b/monitor/Dependencies
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/monitor/Makefile b/monitor/Makefile
new file mode 100644 (file)
index 0000000..ffcbebf
--- /dev/null
@@ -0,0 +1,95 @@
+#
+# "$Id$"
+#
+#   Port monitor makefile for the Common UNIX Printing System (CUPS).
+#
+#   Copyright 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.
+#
+
+include ../Makedefs
+
+TARGETS        =       bcp tbcp
+
+OBJS   =       bcp.o tbcp.o
+
+
+#
+# Make all targets...
+#
+
+all:   $(TARGETS)
+
+
+#
+# Clean all object files...
+#
+
+clean:
+       $(RM) $(OBJS) $(TARGETS)
+
+
+#
+# Update dependencies (without system header dependencies...)
+#
+
+depend:
+       makedepend -Y -I.. -fDependencies $(OBJS:.o=.c) >/dev/null 2>&1
+
+
+#
+# Install all targets...
+#
+
+install:       all
+       $(INSTALL_DIR) -m 755 $(SERVERBIN)/monitor
+       for file in $(TARGETS); do \
+               $(INSTALL_BIN) $$file $(SERVERBIN)/monitor; \
+       done
+
+
+#
+# bcp
+#
+
+bcp:   bcp.o ../cups/$(LIBCUPS)
+       echo Linking $@...
+       $(CC) $(LDFLAGS) -o $@ bcp.o $(LIBS)
+
+
+#
+# tbcp
+#
+
+tbcp:  tbcp.o ../cups/$(LIBCUPS)
+       echo Linking $@...
+       $(CC) $(LDFLAGS) -o $@ tbcp.o $(LIBS)
+
+
+#
+# Dependencies...
+#
+  
+include Dependencies
+
+
+#
+# End of "$Id$".
+#
diff --git a/monitor/bcp.c b/monitor/bcp.c
new file mode 100644 (file)
index 0000000..2a74a0c
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * "$Id$"
+ *
+ *   TBCP port monitor for the Common UNIX Printing System (CUPS).
+ *
+ *   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:
+ *
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include <cups/string.h>
+#include <cups/cups.h>
+
+
+/*
+ * Local functions...
+ */
+
+static char            *psgets(char *buf, size_t *bytes, FILE *fp);
+static size_t          pswrite(const char *buf, size_t bytes, FILE *fp);
+
+
+/*
+ * 'main()' - Main entry...
+ */
+
+int                                    /* O - Exit status */
+main(int  argc,                                /* I - Number of command-line args */
+     char *argv[])                     /* I - Command-line arguments */
+{
+  FILE         *fp;                    /* File to print */
+  int          copies;                 /* Number of copies left */
+  char         line[1024];             /* Line/buffer from stream/file */
+  size_t       linelen;                /* Length of line */
+  ppd_file_t   *ppd;                   /* PPD file */
+
+
+ /*
+  * Check command-line...
+  */
+
+  if (argc < 6 || argc > 7)
+  {
+    fputs("ERROR: tbcp job-id user title copies options [file]\n", stderr);
+    return (1);
+  }
+
+  if (argc == 6)
+  {
+    copies = 1;
+    fp     = stdin;
+  }
+  else
+  {
+    copies = atoi(argv[4]);
+    fp     = fopen(argv[6], "rb");
+
+    if (!fp)
+    {
+      perror(argv[6]);
+      return (1);
+    }
+  }
+
+ /*
+  * Open the PPD file as needed...
+  */
+
+  ppd = ppdOpenFile(getenv("PPD"));
+
+ /*
+  * Copy the print file to stdout...
+  */
+
+  while (copies > 0)
+  {
+    copies --;
+
+    if (ppd && ppd->jcl_begin)
+      fputs(ppd->jcl_begin, stdout);
+    if (ppd && ppd->jcl_ps)
+      fputs(ppd->jcl_ps, stdout);
+
+    if (!ppd || ppd->language_level == 1)
+    {
+     /*
+      * Use setsoftwareiomode for BCP mode...
+      */
+
+      puts("%!PS-Adobe-3.0 ExitServer");
+      puts("%%Title: (BCP - Level 1)");
+      puts("%%EndComments");
+      puts("%%BeginExitServer: 0");
+      puts("serverdict begin 0 exitserver");
+      puts("%%EndExitServer");
+      puts("statusdict begin");
+      puts("/setsoftwareiomode known {100 setsoftwareiomode}");
+      puts("end");
+      puts("%EOF");
+    }
+    else
+    {
+     /*
+      * Use setdevparams for BCP mode...
+      */
+
+      puts("%!PS-Adobe-3.0");
+      puts("%%Title: (BCP - Level 2)");
+      puts("%%EndComments");
+      puts("currentsysparams");
+      puts("/CurInputDevice 2 copy known {");
+      puts("get");
+      puts("<</Protocol /Binary>> setdevparams");
+      puts("}{");
+      puts("pop pop");
+      puts("} ifelse");
+      puts("%EOF");
+    }
+
+    if (ppd && ppd->jcl_end)
+      fputs(ppd->jcl_end, stdout);
+    else if (!ppd || ppd->num_filters == 0)
+      putchar(0x04);
+
+   /*
+    * Loop until we see end-of-file...
+    */
+
+    do
+    {
+      linelen = sizeof(line);
+      if (psgets(line, &linelen, fp) == NULL)
+       break;
+    }
+    while (pswrite(line, linelen, stdout) > 0);
+
+    fflush(stdout);
+  }
+
+  return (0);
+}
+
+
+/*
+ * 'psgets()' - Get a line from a file.
+ *
+ * Note:
+ *
+ *   This function differs from the gets() function in that it
+ *   handles any combination of CR, LF, or CR LF to end input
+ *   lines.
+ */
+
+static char *                          /* O  - String or NULL if EOF */
+psgets(char   *buf,                    /* I  - Buffer to read into */
+       size_t *bytes,                  /* IO - Length of buffer */
+       FILE   *fp)                     /* I  - File to read from */
+{
+  char         *bufptr;                /* Pointer into buffer */
+  int          ch;                     /* Character from file */
+  size_t       len;                    /* Max length of string */
+
+
+  len    = *bytes - 1;
+  bufptr = buf;
+  ch     = EOF;
+
+  while ((bufptr - buf) < len)
+  {
+    if ((ch = getc(fp)) == EOF)
+      break;
+
+    if (ch == '\r')
+    {
+     /*
+      * Got a CR; see if there is a LF as well...
+      */
+
+      ch = getc(fp);
+
+      if (ch != EOF && ch != '\n')
+      {
+        ungetc(ch, fp);        /* Nope, save it for later... */
+        ch = '\r';
+      }
+      else
+        *bufptr++ = '\r';
+      break;
+    }
+    else if (ch == '\n')
+      break;
+    else
+      *bufptr++ = ch;
+  }
+
+ /*
+  * Add a trailing newline if it is there...
+  */
+
+  if (ch == '\n' || ch == '\r')
+  {
+    if ((bufptr - buf) < len)
+      *bufptr++ = ch;
+    else
+      ungetc(ch, fp);
+  }
+
+ /*
+  * Nul-terminate the string and return it (or NULL for EOF).
+  */
+
+  *bufptr = '\0';
+  *bytes  = bufptr - buf;
+
+  if (ch == EOF && bufptr == buf)
+    return (NULL);
+  else
+    return (buf);
+}
+
+
+/*
+ * 'pswrite()' - Write data from a file.
+ */
+
+static size_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       count;                  /* Remaining bytes */
+
+
+  for (count = bytes; count > 0; count --, buf ++)
+    switch (*buf)
+    {
+      case 0x01 : /* CTRL-A */
+      case 0x03 : /* CTRL-C */
+      case 0x04 : /* CTRL-D */
+      case 0x05 : /* CTRL-E */
+      case 0x11 : /* CTRL-Q */
+      case 0x13 : /* CTRL-S */
+      case 0x14 : /* CTRL-T */
+      case 0x1c : /* CTRL-\ */
+         if (putchar(0x01) < 0)
+           return (-1);
+         if (putchar(*buf ^ 0x40) < 0)
+           return (-1);
+         break;
+
+      default :
+         if (putchar(*buf) < 0)
+           return (-1);
+         break;
+    }
+
+  return (bytes);
+}
+
+
+/*
+ * End of "$Id$".
+ */
diff --git a/monitor/tbcp.c b/monitor/tbcp.c
new file mode 100644 (file)
index 0000000..5ce91d8
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+ * "$Id$"
+ *
+ *   TBCP port monitor for the Common UNIX Printing System (CUPS).
+ *
+ *   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.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include <cups/string.h>
+#include <cups/cups.h>
+
+
+/*
+ * Local functions...
+ */
+
+static char            *psgets(char *buf, size_t *bytes, FILE *fp);
+static size_t          pswrite(const char *buf, size_t bytes, FILE *fp);
+
+
+/*
+ * 'main()' - Main entry...
+ */
+
+int                                    /* O - Exit status */
+main(int  argc,                                /* I - Number of command-line args */
+     char *argv[])                     /* I - Command-line arguments */
+{
+  FILE         *fp;                    /* File to print */
+  int          copies;                 /* Number of copies left */
+  char         line[1024];             /* Line/buffer from stream/file */
+  size_t       linelen;                /* Length of line */
+
+
+ /*
+  * Check command-line...
+  */
+
+  if (argc < 6 || argc > 7)
+  {
+    fputs("ERROR: tbcp job-id user title copies options [file]\n", stderr);
+    return (1);
+  }
+
+  if (argc == 6)
+  {
+    copies = 1;
+    fp     = stdin;
+  }
+  else
+  {
+    copies = atoi(argv[4]);
+    fp     = fopen(argv[6], "rb");
+
+    if (!fp)
+    {
+      perror(argv[6]);
+      return (1);
+    }
+  }
+
+ /*
+  * Copy the print file to stdout...
+  */
+
+  while (copies > 0)
+  {
+    copies --;
+
+   /*
+    * Read the first line...
+    */
+
+    linelen = sizeof(line);
+    if (psgets(line, &linelen, fp) == NULL)
+    {
+      fputs("ERROR: Empty print file!\n", stderr);
+      return (1);
+    }
+
+   /*
+    * Handle leading PJL fun...
+    */
+
+    if (!strncmp(line, "\033%-12345X", 9) || !strncmp(line, "@PJL ", 5))
+    {
+     /*
+      * Yup, we have leading PJL fun, so copy it until we hit a line
+      * with "ENTER LANGUAGE"...
+      */
+
+      while (strstr(line, "ENTER LANGUAGE") == NULL)
+      {
+        fwrite(line, 1, linelen, stdout);
+
+       linelen = sizeof(line);
+       if (psgets(line, &linelen, fp) == NULL)
+          break;
+      }
+    }
+    else
+    {
+     /*
+      * No PJL stuff, add it...
+      */
+
+      puts("\033%-12345X@PJL");
+      puts("@PJL ENTER LANGUAGE = POSTSCRIPT");
+    }
+
+   /*
+    * Switch to TBCP mode...
+    */
+
+    fputs("\001M", stdout);
+
+   /*
+    * Loop until we see end-of-file...
+    */
+
+    while (pswrite(line, linelen, stdout) > 0)
+    {
+      linelen = sizeof(line);
+      if (psgets(line, &linelen, fp) == NULL)
+       break;
+    }
+
+    fflush(stdout);
+  }
+
+  return (0);
+}
+
+
+/*
+ * 'psgets()' - Get a line from a file.
+ *
+ * Note:
+ *
+ *   This function differs from the gets() function in that it
+ *   handles any combination of CR, LF, or CR LF to end input
+ *   lines.
+ */
+
+static char *                          /* O  - String or NULL if EOF */
+psgets(char   *buf,                    /* I  - Buffer to read into */
+       size_t *bytes,                  /* IO - Length of buffer */
+       FILE   *fp)                     /* I  - File to read from */
+{
+  char         *bufptr;                /* Pointer into buffer */
+  int          ch;                     /* Character from file */
+  size_t       len;                    /* Max length of string */
+
+
+  len    = *bytes - 1;
+  bufptr = buf;
+  ch     = EOF;
+
+  while ((bufptr - buf) < len)
+  {
+    if ((ch = getc(fp)) == EOF)
+      break;
+
+    if (ch == '\r')
+    {
+     /*
+      * Got a CR; see if there is a LF as well...
+      */
+
+      ch = getc(fp);
+
+      if (ch != EOF && ch != '\n')
+      {
+        ungetc(ch, fp);        /* Nope, save it for later... */
+        ch = '\r';
+      }
+      else
+        *bufptr++ = '\r';
+      break;
+    }
+    else if (ch == '\n')
+      break;
+    else
+      *bufptr++ = ch;
+  }
+
+ /*
+  * Add a trailing newline if it is there...
+  */
+
+  if (ch == '\n' || ch == '\r')
+  {
+    if ((bufptr - buf) < len)
+      *bufptr++ = ch;
+    else
+      ungetc(ch, fp);
+  }
+
+ /*
+  * Nul-terminate the string and return it (or NULL for EOF).
+  */
+
+  *bufptr = '\0';
+  *bytes  = bufptr - buf;
+
+  if (ch == EOF && bufptr == buf)
+    return (NULL);
+  else
+    return (buf);
+}
+
+
+/*
+ * 'pswrite()' - Write data from a file.
+ */
+
+static size_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       count;                  /* Remaining bytes */
+
+
+  for (count = bytes; count > 0; count --, buf ++)
+    switch (*buf)
+    {
+      case 0x01 : /* CTRL-A */
+      case 0x03 : /* CTRL-C */
+      case 0x04 : /* CTRL-D */
+      case 0x05 : /* CTRL-E */
+      case 0x11 : /* CTRL-Q */
+      case 0x13 : /* CTRL-S */
+      case 0x14 : /* CTRL-T */
+      case 0x1b : /* CTRL-[ (aka ESC) */
+      case 0x1c : /* CTRL-\ */
+         if (putchar(0x01) < 0)
+           return (-1);
+         if (putchar(*buf ^ 0x40) < 0)
+           return (-1);
+         break;
+
+      default :
+         if (putchar(*buf) < 0)
+           return (-1);
+         break;
+    }
+
+  return (bytes);
+}
+
+
+/*
+ * End of "$Id$".
+ */
index 20772dd84b67a6aa81bda466421ceaa38795658f..7a9af104dda5f15f208c2fa566837e7ff48408f5 100644 (file)
@@ -1,5 +1,5 @@
 #
-# "$Id: cups.spec 4787 2005-10-13 20:13:21Z mike $"
+# "$Id$"
 #
 #   RPM "spec" file for the Common UNIX Printing System (CUPS).
 #
@@ -181,6 +181,8 @@ rm -rf $RPM_BUILD_ROOT
 %dir /usr/lib/cups/driver
 %dir /usr/lib/cups/filter
 /usr/lib/cups/filter/*
+%dir /usr/lib/cups/monitor
+/usr/lib/cups/monitor/*
 %dir /usr/lib/cups/notifier
 /usr/lib/cups/notifier/*
 
@@ -264,5 +266,5 @@ rm -rf $RPM_BUILD_ROOT
 /usr/share/man/man8/cups-lpd.8.gz
 
 #
-# End of "$Id: cups.spec 4787 2005-10-13 20:13:21Z mike $".
+# End of "$Id$".
 #