]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add new ppdLastError() and ppdErrorString() functions to provide better
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 29 Jan 2003 17:03:38 +0000 (17:03 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 29 Jan 2003 17:03:38 +0000 (17:03 +0000)
feedback about PPD errors.

Add missing PPD attribute functions from 1.2.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@3279 7a7537e8-13f0-0310-91df-b6672ffda945

cups/Dependencies
cups/Makefile
cups/attr.c [new file with mode: 0644]
cups/ppd.c
cups/ppd.h
systemv/cupstestppd.c

index 2efdcf98fcb91a0a8504d721ab7cd747400990a2..a136b8812bb2bfe19aaa7bb22c8f17b11d3754dc 100644 (file)
@@ -1,8 +1,9 @@
 # DO NOT DELETE
 
-dest.o: cups.h ipp.h http.h md5.h ppd.h language.h string.h ../config.h
+attr.o: ppd.h debug.h string.h ../config.h
+dest.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h language.h
 emit.o: ppd.h string.h ../config.h
-encode.o: cups.h ipp.h http.h md5.h ppd.h string.h ../config.h debug.h
+encode.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h debug.h
 http.o: string.h ../config.h http.h md5.h http-private.h debug.h
 http-addr.o: string.h ../config.h http.h md5.h
 http-support.o: string.h ../config.h http.h md5.h ipp.h
@@ -11,15 +12,15 @@ ipp-support.o: string.h ../config.h language.h ipp.h http.h md5.h debug.h
 language.o: string.h ../config.h language.h cups_C.h
 mark.o: ppd.h string.h ../config.h debug.h
 md5.o: md5.h string.h ../config.h
-md5passwd.o: http.h md5.h string.h ../config.h
-options.o: cups.h ipp.h http.h md5.h ppd.h string.h ../config.h debug.h
+md5passwd.o: http.h string.h ../config.h md5.h
+options.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h debug.h
 page.o: ppd.h string.h ../config.h
 ppd.o: ppd.h string.h ../config.h language.h debug.h
 snprintf.o: string.h ../config.h
 string.o: string.h ../config.h
-tempfile.o: cups.h ipp.h http.h md5.h ppd.h string.h ../config.h debug.h
-usersys.o: cups.h ipp.h http.h md5.h ppd.h string.h ../config.h
-util.o: cups.h ipp.h http.h md5.h ppd.h language.h string.h ../config.h
+tempfile.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h debug.h
+usersys.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h
+util.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h language.h
 util.o: debug.h
-testhttp.o: http.h md5.h
+testhttp.o: http.h string.h ../config.h md5.h
 testlang.o: language.h
index 3ef6b2084f866c4a5387332bd0756190beb0dfba..80f3a546fe0e3f55e5ab0bf888cdad58796614fe 100644 (file)
@@ -1,5 +1,5 @@
 #
-# "$Id: Makefile,v 1.80 2003/01/28 15:33:18 mike Exp $"
+# "$Id: Makefile,v 1.81 2003/01/29 17:03:37 mike Exp $"
 #
 #   Support library Makefile for the Common UNIX Printing System (CUPS).
 #
@@ -30,10 +30,10 @@ include ../Makedefs
 # Object files...
 #
 
-LIBOBJS        =       dest.o emit.o encode.o http.o http-addr.o http-support.o \
-               ipp.o ipp-support.o language.o mark.o md5.o md5passwd.o \
-               options.o page.o ppd.o snprintf.o string.o tempfile.o \
-               usersys.o util.o
+LIBOBJS        =       attr.o dest.o emit.o encode.o http.o http-addr.o \
+               http-support.o ipp.o ipp-support.o language.o mark.o \
+               md5.o md5passwd.o options.o page.o ppd.o snprintf.o \
+               string.o tempfile.o usersys.o util.o
 OBJS   =       $(LIBOBJS) testhttp.o testlang.o
 
 
@@ -198,5 +198,5 @@ include Dependencies
 
 
 #
-# End of "$Id: Makefile,v 1.80 2003/01/28 15:33:18 mike Exp $".
+# End of "$Id: Makefile,v 1.81 2003/01/29 17:03:37 mike Exp $".
 #
diff --git a/cups/attr.c b/cups/attr.c
new file mode 100644 (file)
index 0000000..0dbfe4f
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * "$Id: attr.c,v 1.2 2003/01/29 17:03:37 mike Exp $"
+ *
+ *   PPD model-specific attribute routines for the Common UNIX Printing System
+ *   (CUPS).
+ *
+ *   Copyright 1997-2003 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-3111 USA
+ *
+ *       Voice: (301) 373-9600
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "ppd.h"
+#include "debug.h"
+#include "string.h"
+#include <stdlib.h>
+
+
+/*
+ * Private function...
+ */
+
+extern int     _ppd_attr_compare(ppd_attr_t **a, ppd_attr_t **b);
+
+
+/*
+ * 'ppdFindAttr()' - Find the first matching attribute...
+ */
+
+const char *                   /* O - Value or NULL if not found */
+ppdFindAttr(ppd_file_t *ppd,   /* I - PPD file data */
+            const char *name,  /* I - Attribute name */
+            const char *spec)  /* I - Specifier string or NULL */
+{
+  ppd_attr_t   key,            /* Search key */
+               *keyptr,        /* Pointer to key */
+               **match;        /* Matching attribute */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (ppd == NULL || name == NULL || ppd->num_attrs == 0)
+    return (NULL);
+
+ /*
+  * Do a binary search for a matching attribute...
+  */
+
+  memset(&key, 0, sizeof(key));
+  strncpy(key.name, name, sizeof(key.name) - 1);
+  if (spec)
+    strncpy(key.spec, spec, sizeof(key.spec) - 1);
+
+  keyptr = &key;
+
+  match = bsearch(&keyptr, ppd->attrs, ppd->num_attrs, sizeof(ppd_attr_t *),
+                  (int (*)(const void *, const void *))_ppd_attr_compare);
+
+  if (match == NULL)
+  {
+   /* 
+    * No match!
+    */
+
+    ppd->cur_attr = -1;
+    return (NULL);
+  }
+
+  if (match > ppd->attrs && spec == NULL)
+  {
+   /*
+    * Find the first attribute with the same name...
+    */
+
+    while (match > ppd->attrs)
+    {
+      if (strcmp(match[-1]->name, name) != 0)
+        break;
+
+      match --;
+    }
+  }
+
+ /*
+  * Save the current attribute and return its value...
+  */
+
+  ppd->cur_attr = match - ppd->attrs;
+
+  if ((*match)->value)
+    return ((*match)->value);
+  else
+    return ("");
+}
+
+
+/*
+ * 'ppdFindNextAttr()' - Find the next matching attribute...
+ */
+
+const char *                           /* O - Value or NULL if not found */
+ppdFindNextAttr(ppd_file_t *ppd,       /* I - PPD file data */
+                const char *name,      /* I - Attribute name */
+               const char *spec)       /* I - Specifier string or NULL */
+{
+  ppd_attr_t   **match;                /* Matching attribute */
+
+
+ /*
+  * Range check input...
+  */
+
+  if (ppd == NULL || name == NULL || ppd->num_attrs == 0 || ppd->cur_attr < 0)
+    return (NULL);
+
+ /*
+  * See if there are more attributes to return...
+  */
+
+  ppd->cur_attr ++;
+
+  if (ppd->cur_attr >= ppd->num_attrs)
+  {
+   /*
+    * Nope...
+    */
+
+    ppd->cur_attr = -1;
+    return (NULL);
+  }
+
+ /*
+  * Check the next attribute to see if it is a match...
+  */
+
+  match = ppd->attrs + ppd->cur_attr;
+
+  if (strcmp((*match)->name, name) != 0 ||
+      (spec != NULL && strcmp((*match)->spec, spec) != 0))
+  {
+   /*
+    * Nope...
+    */
+
+    ppd->cur_attr = -1;
+    return (NULL);
+  }
+  
+ /*
+  * Return the next attribute's value...
+  */
+
+  if ((*match)->value)
+    return ((*match)->value);
+  else
+    return ("");
+}
+
+
+/*
+ * End of "$Id: attr.c,v 1.2 2003/01/29 17:03:37 mike Exp $".
+ */
index fba0f7b28d7f1d271aa045a6d1f6a858d2779b06..10869988891aff0b12901c43d8b30108d56f87d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.c,v 1.81 2003/01/28 20:21:53 mike Exp $"
+ * "$Id: ppd.c,v 1.82 2003/01/29 17:03:37 mike Exp $"
  *
  *   PPD file routines for the Common UNIX Printing System (CUPS).
  *
@@ -36,6 +36,8 @@
  *
  *   _ppd_attr_compare()   - Compare two attributes.
  *   ppdClose()            - Free all memory used by the PPD file.
+ *   ppdErrorString()      - Returns the text assocated with a status.
+ *   ppdLastError()        - Return the status from the last ppdOpen*().
  *   ppdOpen()             - Read a PPD file into memory.
  *   ppdOpenFd()           - Read a PPD file into memory.
  *   ppdOpenFile()         - Read a PPD file into memory.
 #define PPD_STRING     8               /* Line contained a string or code */
 
 
+/*
+ * Local globals...
+ */
+
+static ppd_status_t    ppd_status = PPD_OK;
+                                       /* Status of last ppdOpen*() */
+static int             ppd_line = 1;   /* Current line number */
+
+
 /*
  * Local functions...
  */
@@ -269,6 +280,49 @@ ppdClose(ppd_file_t *ppd)          /* I - PPD file record */
 }
 
 
+/*
+ * 'ppdErrorString()' - Returns the text assocated with a status.
+ */
+
+const char *                           /* O - Status string */
+ppdErrorString(ppd_status_t status)    /* I - PPD status */
+{
+  static const char * const messages[] =/* Status messages */
+               {
+                 "OK",
+                 "Unable to open PPD file",
+                 "NULL PPD file pointer",
+                 "Missing PPD-Adobe-4.x header",
+                 "Memory allocation error",
+                 "Missing value string",
+                 "Internal error",
+                 "OpenGroup without a CloseGroup first",
+                 "Bad OrderDependency",
+                 "Bad UIConstraints",
+               };
+
+
+  if (status < PPD_OK || status > PPD_BAD_UI_CONSTRAINTS)
+    return ("Unknown");
+  else
+    return (messages[status]);
+}
+
+
+/*
+ * 'ppdLastError()' - Return the status from the last ppdOpen*().
+ */
+
+ppd_status_t                           /* O - Status code */
+ppdLastError(int *line)                        /* O - Line number */
+{
+  if (line)
+    *line = ppd_line;
+
+  return (ppd_status);
+}
+
+
 /*
  * 'ppdOpen()' - Read a PPD file into memory.
  */
@@ -305,12 +359,22 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
   cups_lang_t          *language;      /* Default language */
 
 
+ /*
+  * Default to "OK" status...
+  */
+
+  ppd_status = PPD_OK;
+  ppd_line   = 1;
+
  /*
   * Range check input...
   */
 
   if (fp == NULL)
+  {
+    ppd_status = PPD_NULL_FILE;
     return (NULL);
+  }
 
  /*
   * Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
@@ -326,6 +390,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
     * Either this is not a PPD file, or it is not a 4.x PPD file.
     */
 
+    ppd_status = PPD_MISSING_PPDADOBE4;
+
     ppd_free(string);
 
     return (NULL);
@@ -340,7 +406,11 @@ ppdOpen(FILE *fp)                  /* I - File to read from */
   */
 
   if ((ppd = calloc(sizeof(ppd_file_t), 1)) == NULL)
+  {
+    ppd_status = PPD_ALLOC_ERROR;
+
     return (NULL);
+  }
 
   ppd->language_level = 1;
   ppd->color_device   = 0;
@@ -411,6 +481,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
       setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+      ppd_status = PPD_MISSING_VALUE;
+
       return (NULL);
     }
 
@@ -577,6 +649,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -619,6 +693,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
       
@@ -663,6 +739,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
           setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+          ppd_status = PPD_ALLOC_ERROR;
+
          return (NULL);
        }
 
@@ -680,6 +758,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
           setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+          ppd_status = PPD_ALLOC_ERROR;
+
          return (NULL);
        }
       }
@@ -698,6 +778,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -762,6 +844,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
             setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+            ppd_status = PPD_ALLOC_ERROR;
+
            return (NULL);
          }
 
@@ -781,6 +865,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
             setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+            ppd_status = PPD_ALLOC_ERROR;
+
            return (NULL);
          }
         }
@@ -801,6 +887,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
           setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+          ppd_status = PPD_ALLOC_ERROR;
+
          return (NULL);
        }
 
@@ -825,6 +913,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_INTERNAL_ERROR;
+
        return (NULL);
       }
 
@@ -844,6 +934,8 @@ ppdOpen(FILE *fp)                   /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_INTERNAL_ERROR;
+
        return (NULL);
       }
 
@@ -932,6 +1024,8 @@ ppdOpen(FILE *fp)                  /* I - File to read from */
           setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+          ppd_status = PPD_ALLOC_ERROR;
+
          return (NULL);
        }
 
@@ -991,6 +1085,8 @@ ppdOpen(FILE *fp)                  /* I - File to read from */
           setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+          ppd_status = PPD_ALLOC_ERROR;
+
          return (NULL);
        }
 
@@ -1015,6 +1111,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1079,6 +1177,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1105,6 +1205,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1147,6 +1249,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_NESTED_OPEN_GROUP;
+
        return (NULL);
       }
 
@@ -1191,6 +1295,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_BAD_ORDER_DEPENDENCY;
+
        return (NULL);
       }
 
@@ -1294,6 +1400,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1309,7 +1417,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
        case 1 : /* Error */
            ppdClose(ppd);
            ppd_free(string);
-           break;
+           ppd_status = PPD_BAD_UI_CONSTRAINTS;
+           return (NULL);
 
        case 2 : /* Two options... */
           /*
@@ -1385,6 +1494,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1413,6 +1524,8 @@ ppdOpen(FILE *fp)                 /* I - File to read from */
         setlocale(LC_ALL, oldlocale);
 #endif /* LC_NUMERIC */
 
+        ppd_status = PPD_ALLOC_ERROR;
+
        return (NULL);
       }
 
@@ -1576,6 +1689,10 @@ ppdOpen(FILE *fp)                        /* I - File to read from */
     qsort(ppd->attrs, ppd->num_attrs, sizeof(ppd_attr_t *),
           (int (*)(const void *, const void *))_ppd_attr_compare);
 
+ /*
+  * Return the PPD file structure...
+  */
+
   return (ppd);
 }
 
@@ -1591,12 +1708,22 @@ ppdOpenFd(int fd)                       /* I - File to read from */
   ppd_file_t   *ppd;                   /* PPD file record */
 
 
+ /*
+  * Set the line number to 1...
+  */
+
+  ppd_line = 1;
+
  /*
   * Range check input...
   */
 
   if (fd < 0)
+  {
+    ppd_status = PPD_NULL_FILE;
+
     return (NULL);
+  }
 
  /*
   * Try to open the file and parse it...
@@ -1608,10 +1735,13 @@ ppdOpenFd(int fd)                       /* I - File to read from */
 
     ppd = ppdOpen(fp);
 
-    ppd_free(fp);
+    fclose(fp);
   }
   else
-    ppd = NULL;
+  {
+    ppd_status = PPD_FILE_OPEN_ERROR;
+    ppd        = NULL;
+  }
 
   return (ppd);
 }
@@ -1628,12 +1758,22 @@ ppdOpenFile(const char *filename)       /* I - File to read from */
   ppd_file_t   *ppd;                   /* PPD file record */
 
 
+ /*
+  * Set the line number to 1...
+  */
+
+  ppd_line = 1;
+
  /*
   * Range check input...
   */
 
   if (filename == NULL)
+  {
+    ppd_status = PPD_NULL_FILE;
+
     return (NULL);
+  }
 
  /*
   * Try to open the file and parse it...
@@ -1646,7 +1786,10 @@ ppdOpenFile(const char *filename)        /* I - File to read from */
     fclose(fp);
   }
   else
-    ppd = NULL;
+  {
+    ppd_status = PPD_FILE_OPEN_ERROR;
+    ppd        = NULL;
+  }
 
   return (ppd);
 }
@@ -2102,6 +2245,8 @@ ppd_read(FILE *fp,                        /* I - File to read from */
        * Line feed or carriage return...
        */
 
+        ppd_line ++;
+
        if (lineptr == line)            /* Skip blank lines */
           continue;
 
@@ -2331,5 +2476,5 @@ ppd_read(FILE *fp,                        /* I - File to read from */
 
 
 /*
- * End of "$Id: ppd.c,v 1.81 2003/01/28 20:21:53 mike Exp $".
+ * End of "$Id: ppd.c,v 1.82 2003/01/29 17:03:37 mike Exp $".
  */
index 3a567ef01858b41087e996675e2d4c1ae7ae5169..48bd428aef3211fb07fce4d64dc8137744aba54d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ppd.h,v 1.28 2003/01/28 15:29:14 mike Exp $"
+ * "$Id: ppd.h,v 1.29 2003/01/29 17:03:37 mike Exp $"
  *
  *   PostScript Printer Description definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -100,6 +100,20 @@ typedef enum                       /**** Colorspaces ****/
   PPD_CS_N                     /* DeviceN colorspace */
 } ppd_cs_t;
 
+typedef enum                   /**** Status Codes ****/
+{
+  PPD_OK = 0,                  /* OK */
+  PPD_FILE_OPEN_ERROR,         /* Unable to open PPD file */
+  PPD_NULL_FILE,               /* NULL PPD file pointer */
+  PPD_MISSING_PPDADOBE4,       /* Missing PPD-Adobe-4.x header */
+  PPD_ALLOC_ERROR,             /* Memory allocation error */
+  PPD_MISSING_VALUE,           /* Missing value string */
+  PPD_INTERNAL_ERROR,          /* Internal error */
+  PPD_NESTED_OPEN_GROUP,       /* OpenGroup without a CloseGroup first */
+  PPD_BAD_ORDER_DEPENDENCY,    /* Bad OrderDependency */
+  PPD_BAD_UI_CONSTRAINTS       /* Bad UIConstraints */
+} ppd_status_t;
+
 typedef struct                 /**** PPD Attribute Structure ****/
 {
   char         name[PPD_MAX_NAME],
@@ -281,10 +295,12 @@ extern ppd_size_t *ppdPageSize(ppd_file_t *ppd, const char *name);
 extern float           ppdPageWidth(ppd_file_t *ppd, const char *name);
 
 /**** New in CUPS 1.1.19 ****/
+extern const char      *ppdErrorString(ppd_status_t status);
 extern const char      *ppdFindAttr(ppd_file_t *ppd, const char *name,
                                     const char *spec);
 extern const char      *ppdFindNextAttr(ppd_file_t *ppd, const char *name,
                                         const char *spec);
+extern ppd_status_t    ppdLastError(int *line);
 
 /*
  * C++ magic...
@@ -296,5 +312,5 @@ extern const char   *ppdFindNextAttr(ppd_file_t *ppd, const char *name,
 #endif /* !_CUPS_PPD_H_ */
 
 /*
- * End of "$Id: ppd.h,v 1.28 2003/01/28 15:29:14 mike Exp $".
+ * End of "$Id: ppd.h,v 1.29 2003/01/29 17:03:37 mike Exp $".
  */
index 8adc3b78638b84b6332be92f46c65258a2590465..4e59ae6b8eceb96276f7384ffc037f64aa56ef8a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cupstestppd.c,v 1.4 2003/01/29 01:40:16 mike Exp $"
+ * "$Id: cupstestppd.c,v 1.5 2003/01/29 17:03:38 mike Exp $"
  *
  *   PPD test program for the Common UNIX Printing System (CUPS).
  *
@@ -59,9 +59,12 @@ main(int  argc,                      /* I - Number of command-line arguments */
      char *argv[])             /* I - Command-line arguments */
 {
   int          i, j, k, m;     /* Looping vars */
+  int          files;          /* Number of files */
   int          verbose;        /* Want verbose output? */
   int          status;         /* Exit status */
   int          errors;         /* Number of conformance errors */
+  ppd_status_t error;          /* Status of ppdOpen*() */
+  int          line;           /* Line number for error */
   ppd_file_t   *ppd;           /* PPD file record */
   ppd_size_t   *size;          /* Size record */
   ppd_group_t  *group;         /* UI group */
@@ -80,6 +83,7 @@ main(int  argc,                       /* I - Number of command-line arguments */
 
   verbose = 0;
   ppd     = NULL;
+  files   = 0;
   status  = ERROR_NONE;
 
   for (i = 1; i < argc; i ++)
@@ -116,6 +120,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
       * Open the PPD file...
       */
 
+      files ++;
+
       if (argv[i][0] == '-')
       {
        /*
@@ -141,7 +147,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
       if (ppd == NULL)
       {
-        if (errno)
+        error = ppdLastError(&line);
+
+       if (error <= PPD_NULL_FILE)
        {
          status = ERROR_FILE_OPEN;
 
@@ -153,7 +161,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
          status = ERROR_PPD_FORMAT;
 
           if (verbose >= 0)
-           puts("    Unable to open PPD file using CUPS functions!\n");
+           printf("    Unable to open PPD file - %s on line %d.\n",
+                  ppdErrorString(error), line);
         }
 
        continue;
@@ -444,7 +453,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       ppdClose(ppd);
     }
 
-  if (!ppd && verbose >= 0)
+  if (!files && verbose >= 0)
   {
     puts("Usage: cupstestppd [-q] [-v] filename1.ppd [... filenameN.ppd]");
     puts("       program | cupstestppd [-q] [-v] -");
@@ -457,5 +466,5 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
 
 /*
- * End of "$Id: cupstestppd.c,v 1.4 2003/01/29 01:40:16 mike Exp $".
+ * End of "$Id: cupstestppd.c,v 1.5 2003/01/29 17:03:38 mike Exp $".
  */