]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/file.c
Merge changes from CUPS 1.4svn-r8033.
[thirdparty/cups.git] / cups / file.c
index 815e1d3c5f005dc79264a950b064e4979066d5ef..bbaac6fe0a1f9245fbca5dda5d186ca30e136426 100644 (file)
@@ -1253,6 +1253,67 @@ cupsFilePutChar(cups_file_t *fp, /* I - CUPS file */
 }
 
 
+/*
+ * 'cupsFilePutConf()' - Write a configuration line.
+ *
+ * This function handles any comment escaping of the value.
+ *
+ * @since CUPS 1.4@
+ */
+
+ssize_t                                        /* O - Number of bytes written or -1 on error */
+cupsFilePutConf(cups_file_t *fp,       /* I - CUPS file */
+                const char *directive, /* I - Directive */
+               const char *value)      /* I - Value */
+{
+  ssize_t      bytes,                  /* Number of bytes written */
+               temp;                   /* Temporary byte count */
+  const char   *ptr;                   /* Pointer into value */
+
+
+  if (!fp || !directive || !*directive)
+    return (-1);
+
+  if ((bytes = cupsFilePuts(fp, directive)) < 0)
+    return (-1);
+
+  if (cupsFilePutChar(fp, ' ') < 0)
+    return (-1);
+  bytes ++;
+
+  if (value && *value)
+  {
+    if ((ptr = strchr(value, '#')) != NULL)
+    {
+     /*
+      * Need to quote the first # in the info string...
+      */
+
+      if ((temp = cupsFileWrite(fp, value, ptr - value)) < 0)
+        return (-1);
+      bytes += temp;
+
+      if (cupsFilePutChar(fp, '\\') < 0)
+        return (-1);
+      bytes ++;
+
+      if ((temp = cupsFilePuts(fp, ptr)) < 0)
+        return (-1);
+      bytes += temp;
+    }
+    else if ((temp = cupsFilePuts(fp, value)) < 0)
+      return (-1);
+    else
+      bytes += temp;
+  }
+
+  if (cupsFilePutChar(fp, '\n') < 0)
+    return (-1);
+  else
+    return (bytes + 1);
+}
+
+
 /*
  * 'cupsFilePuts()' - Write a string.
  *