]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
9e38aa42c482199ce1eceb047423a9957e6e0e9c
2 * "$Id: cupstestdsc.c 5320 2006-03-21 19:03:25Z mike $"
4 * DSC test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
26 * This file is subject to the Apple OS-Developed Software exception.
33 * Include necessary headers...
36 #include <cups/string.h>
37 #include <cups/cups.h>
38 #include <cups/file.h>
39 #include <cups/i18n.h>
48 static int check_file(const char *filename
);
49 static void usage(void);
53 * 'main()' - Main entry for test program.
56 int /* O - Exit status */
57 main(int argc
, /* I - Number of command-line args */
58 char *argv
[]) /* I - Command-line arguments */
60 int i
; /* Looping var */
61 int status
; /* Status of tests */
62 int num_files
; /* Number of files tested */
66 * Collect command-line arguments...
69 for (i
= 1, num_files
= 0, status
= 0; i
< argc
; i
++)
70 if (argv
[i
][0] == '-')
75 * Currently the only supported option is "-h" (help)...
83 status
+= check_file("(stdin)");
89 status
+= check_file(argv
[i
]);
100 * 'check()' - Main entry for test program.
103 static int /* O - 0 on success, 1 on failure */
104 check_file(const char *filename
) /* I - File to read from */
106 int i
; /* Looping var */
107 cups_file_t
*fp
; /* File */
108 char line
[1024]; /* Line from file */
109 int ch
; /* Current character */
110 size_t bytes
; /* Length of line */
111 int status
; /* Status of test */
112 int linenum
; /* Line number */
113 int binary
; /* File contains binary data? */
114 float version
; /* DSC version */
115 int lbrt
[4]; /* Bounding box */
116 char page_label
[256]; /* Page label string */
117 int page_number
; /* Page number */
118 int level
; /* Embedded document level */
119 int saw_bounding_box
, /* %%BoundingBox seen? */
120 saw_pages
, /* %%Pages seen? */
121 saw_end_comments
, /* %%EndComments seen? */
122 saw_begin_prolog
, /* %%BeginProlog seen? */
123 saw_end_prolog
, /* %%EndProlog seen? */
124 saw_begin_setup
, /* %%BeginSetup seen? */
125 saw_end_setup
, /* %%EndSetup seen? */
126 saw_page
, /* %%Page seen? */
127 saw_trailer
, /* %%Trailer seen? */
128 saw_eof
, /* %%EOF seen? */
129 saw_long_line
; /* Saw long lines? */
136 if (!strcmp(filename
, "(stdin)"))
137 fp
= cupsFileStdin();
139 fp
= cupsFileOpen(filename
, "r");
154 saw_begin_prolog
= 0;
156 saw_bounding_box
= 0;
157 saw_end_comments
= 0;
168 _cupsLangPrintf(stdout
, "%s: ", filename
);
171 while ((bytes
= cupsFileGetLine(fp
, line
, sizeof(line
))) > 0)
180 _cupsLangPuts(stdout
, _("FAIL\n"));
183 _cupsLangPrintf(stdout
,
184 _(" Line %d is longer than 255 characters (%d)!\n"
185 " REF: Page 25, Line Length\n"),
186 linenum
, (int)bytes
);
194 if (strncmp(line
, "%!PS-Adobe-", 11))
197 _cupsLangPuts(stdout
, _("FAIL\n"));
200 _cupsLangPuts(stdout
,
201 _(" Missing %!PS-Adobe-3.0 on first line!\n"
202 " REF: Page 17, 3.1 Conforming Documents\n"));
207 version
= atof(line
+ 11);
211 if (!strncmp(line
, "%%BeginDocument:", 16))
213 else if (!strncmp(line
, "%%EndDocument", 13))
216 else if (saw_trailer
)
218 if (!strncmp(line
, "%%Pages:", 8))
220 if (atoi(line
+ 8) <= 0)
223 _cupsLangPuts(stdout
, _("FAIL\n"));
226 _cupsLangPrintf(stdout
,
227 _(" Bad %%%%Pages: on line %d!\n"
228 " REF: Page 43, %%%%Pages:\n"),
234 else if (!strncmp(line
, "%%BoundingBox:", 14))
236 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
240 _cupsLangPuts(stdout
, _("FAIL\n"));
243 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
244 " REF: Page 39, %%%%BoundingBox:\n"),
248 saw_bounding_box
= 1;
251 else if (!saw_end_comments
)
253 if (!strncmp(line
, "%%EndComments", 13))
254 saw_end_comments
= 1;
255 else if (line
[0] != '%')
256 saw_end_comments
= -1;
257 else if (!strncmp(line
, "%%Pages:", 8))
259 if (strstr(line
+ 8, "(atend)"))
261 else if (atoi(line
+ 8) <= 0)
264 _cupsLangPuts(stdout
, _("FAIL\n"));
267 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d!\n"
268 " REF: Page 43, %%%%Pages:\n"),
274 else if (!strncmp(line
, "%%BoundingBox:", 14))
276 if (strstr(line
, "(atend)"))
277 saw_bounding_box
= -1;
278 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
282 _cupsLangPuts(stdout
, _("FAIL\n"));
285 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
286 " REF: Page 39, %%%%BoundingBox:\n"),
290 saw_bounding_box
= 1;
293 else if (saw_begin_prolog
&& !saw_end_prolog
)
295 if (!strncmp(line
, "%%EndProlog", 11))
298 else if (saw_begin_setup
&& !saw_end_setup
)
300 if (!strncmp(line
, "%%EndSetup", 10))
303 else if (saw_end_comments
)
305 if (!strncmp(line
, "%%Page:", 7))
307 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2)
310 _cupsLangPuts(stdout
, _("FAIL\n"));
313 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d!\n"
314 " REF: Page 53, %%%%Page:\n"),
320 else if (!strncmp(line
, "%%BeginProlog", 13))
321 saw_begin_prolog
= 1;
322 else if (!strncmp(line
, "%%BeginSetup", 12))
324 else if (!strncmp(line
, "%%BeginDocument:", 16))
326 else if (!strncmp(line
, "%%EndDocument", 13))
328 else if (!strncmp(line
, "%%Trailer", 9))
332 for (i
= 0; !binary
&& i
< bytes
; i
++)
336 if ((ch
< ' ' || (ch
& 0x80)) && ch
!= '\n' && ch
!= '\r' && ch
!= '\t')
341 if (saw_bounding_box
<= 0)
344 _cupsLangPuts(stdout
, _("FAIL\n"));
347 _cupsLangPuts(stdout
, _(" Missing or bad %%BoundingBox: comment!\n"
348 " REF: Page 39, %%BoundingBox:\n"));
354 _cupsLangPuts(stdout
, _("FAIL\n"));
357 _cupsLangPuts(stdout
, _(" Missing or bad %%Pages: comment!\n"
358 " REF: Page 43, %%Pages:\n"));
361 if (!saw_end_comments
)
364 _cupsLangPuts(stdout
, _("FAIL\n"));
367 _cupsLangPuts(stdout
, _(" Missing %%EndComments comment!\n"
368 " REF: Page 41, %%EndComments\n"));
374 _cupsLangPuts(stdout
, _("FAIL\n"));
377 _cupsLangPuts(stdout
, _(" Missing or bad %%Page: comments!\n"
378 " REF: Page 53, %%Page:\n"));
384 _cupsLangPuts(stdout
, _("FAIL\n"));
387 _cupsLangPuts(stdout
, _(" Too many %%EndDocument comments!\n"));
392 _cupsLangPuts(stdout
, _("FAIL\n"));
395 _cupsLangPuts(stdout
, _(" Too many %%BeginDocument comments!\n"));
398 if (saw_long_line
> 1)
399 _cupsLangPrintf(stderr
,
400 _(" Saw %d lines that exceeded 255 characters!\n"),
404 _cupsLangPuts(stdout
, _("PASS\n"));
407 _cupsLangPuts(stdout
, _(" Warning: file contains binary data!\n"));
410 _cupsLangPrintf(stdout
,
411 _(" Warning: obsolete DSC version %.1f in file!\n"),
414 if (saw_end_comments
< 0)
415 _cupsLangPuts(stdout
, _(" Warning: no %%EndComments comment in file!\n"));
424 * 'usage()' - Show program usage.
430 _cupsLangPuts(stdout
,
431 _("Usage: cupstestdsc [options] filename.ps [... filename.ps]\n"
432 " cupstestdsc [options] -\n"
436 " -h Show program usage\n"
438 " Note: this program only validates the DSC comments, "
439 "not the PostScript itself.\n"));
446 * End of "$Id: cupstestdsc.c 5320 2006-03-21 19:03:25Z mike $".