]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/backend.c
Merge changes from CUPS 1.4svn-r7817.
[thirdparty/cups.git] / cups / backend.c
index 021dad2e21ce3adfb72f7c2f85516ee76592a1da..ca4fad2f3cb3076c13cb7fd7f1c3d2d77e650090 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: backend.c 7583 2008-05-16 17:47:16Z mike $"
+ * "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $"
  *
  *   Backend functions for the Common UNIX Printing System (CUPS).
  *
@@ -17,6 +17,8 @@
  * Contents:
  *
  *   cupsBackendDeviceURI() - Get the device URI for a backend.
+ *   cupsBackendReport()    - Write a device line from a backend.
+ *   quote_string()         - Write a quoted string to stdout, escaping \ and ".
  */
 
 /*
 #include "globals.h"
 
 
+/*
+ * Local functions...
+ */
+
+static void    quote_string(const char *s);
+
+
 /*
  * 'cupsBackendDeviceURI()' - Get the device URI for a backend.
  *
@@ -58,5 +67,64 @@ cupsBackendDeviceURI(char **argv)    /* I - Command-line arguments */
 
 
 /*
- * End of "$Id: backend.c 7583 2008-05-16 17:47:16Z mike $".
+ * 'cupsBackendReport()' - Write a device line from a backend.
+ *
+ * This function writes a single device line to stdout for a backend.
+ * It handles quoting of special characters in the device-make-and-model,
+ * device-info, device-id, and device-location strings.
+ */
+
+void
+cupsBackendReport(
+    const char *device_scheme,         /* I - device-scheme string */
+    const char *device_uri,            /* I - device-uri string */
+    const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */
+    const char *device_info,           /* I - device-info string or @code NULL@ */
+    const char *device_id,             /* I - device-id string or @code NULL@ */
+    const char *device_location)       /* I - device-location string or @code NULL@ */
+{
+  if (!device_scheme || !device_uri)
+    return;
+
+  printf("%s %s", device_scheme, device_uri);
+  if (device_make_and_model && *device_make_and_model)
+    quote_string(device_make_and_model);
+  else
+    quote_string("unknown");
+  quote_string(device_info);
+  quote_string(device_id);
+  quote_string(device_location);
+  putchar('\n');
+  fflush(stdout);
+}
+
+
+/*
+ * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
+ */
+
+static void
+quote_string(const char *s)            /* I - String to write */
+{
+  fputs(" \"", stdout);
+
+  if (s)
+  {
+    while (*s)
+    {
+      if (*s == '\\' || *s == '\"')
+       putchar('\\');
+
+      putchar(*s);
+
+      s ++;
+    }
+  }
+
+  putchar('\"');
+}
+
+
+/*
+ * End of "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $".
  */