X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=cups%2Fbackend.c;fp=cups%2Fbackend.c;h=ca4fad2f3cb3076c13cb7fd7f1c3d2d77e650090;hb=749b1e90a80fd8245f9cb84d2f78ab65034eeb81;hp=021dad2e21ce3adfb72f7c2f85516ee76592a1da;hpb=005dd1eb9e7844f4bf631111847c26c9a4b56df3;p=thirdparty%2Fcups.git diff --git a/cups/backend.c b/cups/backend.c index 021dad2e2..ca4fad2f3 100644 --- a/cups/backend.c +++ b/cups/backend.c @@ -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 ". */ /* @@ -28,6 +30,13 @@ #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 $". */