]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
df69d9425953c684e7fe12449874ce33b7ad87a6
2 * DSC test program for CUPS.
4 * Copyright 2007-2010 by Apple Inc.
5 * Copyright 2006 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * PostScript is a trademark of Adobe Systems, Inc.
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include <cups/cups-private.h>
29 static int check_file(const char *filename
);
30 static void usage(void) __attribute__((noreturn
));
34 * 'main()' - Main entry for test program.
37 int /* O - Exit status */
38 main(int argc
, /* I - Number of command-line args */
39 char *argv
[]) /* I - Command-line arguments */
41 int i
; /* Looping var */
42 int status
; /* Status of tests */
43 int num_files
; /* Number of files tested */
49 * Collect command-line arguments...
52 for (i
= 1, num_files
= 0, status
= 0; i
< argc
; i
++)
53 if (argv
[i
][0] == '-')
58 * Currently the only supported option is "-h" (help)...
66 status
+= check_file("(stdin)");
72 status
+= check_file(argv
[i
]);
83 * 'check()' - Check a file for conformance.
86 static int /* O - 0 on success, 1 on failure */
87 check_file(const char *filename
) /* I - File to read from */
89 int i
; /* Looping var */
90 cups_file_t
*fp
; /* File */
91 char line
[1024]; /* Line from file */
92 int ch
; /* Current character */
93 size_t bytes
; /* Length of line */
94 int status
; /* Status of test */
95 int linenum
; /* Line number */
96 int binary
; /* File contains binary data? */
97 float version
; /* DSC version */
98 int lbrt
[4]; /* Bounding box */
99 char page_label
[256]; /* Page label string */
100 int page_number
; /* Page number */
101 int last_page_number
; /* Last page number seen */
102 int level
; /* Embedded document level */
103 int saw_bounding_box
, /* %%BoundingBox seen? */
104 saw_pages
, /* %%Pages seen? */
105 saw_end_comments
, /* %%EndComments seen? */
106 saw_begin_prolog
, /* %%BeginProlog seen? */
107 saw_end_prolog
, /* %%EndProlog seen? */
108 saw_begin_setup
, /* %%BeginSetup seen? */
109 saw_end_setup
, /* %%EndSetup seen? */
110 saw_page
, /* %%Page seen? */
111 saw_trailer
, /* %%Trailer seen? */
112 saw_long_line
; /* Saw long lines? */
119 if (!strcmp(filename
, "(stdin)"))
120 fp
= cupsFileStdin();
122 fp
= cupsFileOpen(filename
, "r");
135 last_page_number
= 0;
138 saw_begin_prolog
= 0;
140 saw_bounding_box
= 0;
141 saw_end_comments
= 0;
152 printf("%s: ", filename
);
155 while ((bytes
= cupsFileGetLine(fp
, line
, sizeof(line
))) > 0)
164 _cupsLangPuts(stdout
, _("FAIL"));
167 _cupsLangPrintf(stdout
,
168 _(" Line %d is longer than 255 characters (%d).\n"
169 " REF: Page 25, Line Length"),
170 linenum
, (int)bytes
);
178 if (strncmp(line
, "%!PS-Adobe-", 11))
181 _cupsLangPuts(stdout
, _("FAIL"));
183 _cupsLangPuts(stdout
,
184 _(" Missing %!PS-Adobe-3.0 on first line.\n"
185 " REF: Page 17, 3.1 Conforming Documents"));
190 version
= atof(line
+ 11);
194 if (!strncmp(line
, "%%BeginDocument:", 16))
196 else if (!strncmp(line
, "%%EndDocument", 13))
199 else if (saw_trailer
)
201 if (!strncmp(line
, "%%Pages:", 8))
203 if (atoi(line
+ 8) <= 0)
206 _cupsLangPuts(stdout
, _("FAIL"));
209 _cupsLangPrintf(stdout
,
210 _(" Bad %%%%Pages: on line %d.\n"
211 " REF: Page 43, %%%%Pages:"),
217 else if (!strncmp(line
, "%%BoundingBox:", 14))
219 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
223 _cupsLangPuts(stdout
, _("FAIL"));
226 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d.\n"
227 " REF: Page 39, %%%%BoundingBox:"),
231 saw_bounding_box
= 1;
234 else if (!saw_end_comments
)
236 if (!strncmp(line
, "%%EndComments", 13))
237 saw_end_comments
= 1;
238 else if (line
[0] != '%')
239 saw_end_comments
= -1;
240 else if (!strncmp(line
, "%%Pages:", 8))
242 if (strstr(line
+ 8, "(atend)"))
244 else if (atoi(line
+ 8) <= 0)
247 _cupsLangPuts(stdout
, _("FAIL"));
250 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d.\n"
251 " REF: Page 43, %%%%Pages:"),
257 else if (!strncmp(line
, "%%BoundingBox:", 14))
259 if (strstr(line
, "(atend)"))
260 saw_bounding_box
= -1;
261 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
265 _cupsLangPuts(stdout
, _("FAIL"));
268 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d.\n"
269 " REF: Page 39, %%%%BoundingBox:"),
273 saw_bounding_box
= 1;
276 else if (saw_begin_prolog
&& !saw_end_prolog
)
278 if (!strncmp(line
, "%%EndProlog", 11))
281 else if (saw_begin_setup
&& !saw_end_setup
)
283 if (!strncmp(line
, "%%EndSetup", 10))
286 else if (saw_end_comments
)
288 if (!strncmp(line
, "%%Page:", 7))
290 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2 ||
291 page_number
!= (last_page_number
+ 1) || page_number
< 1)
294 _cupsLangPuts(stdout
, _("FAIL"));
297 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d.\n"
298 " REF: Page 53, %%%%Page:"),
303 last_page_number
= page_number
;
307 else if (!strncmp(line
, "%%BeginProlog", 13))
308 saw_begin_prolog
= 1;
309 else if (!strncmp(line
, "%%BeginSetup", 12))
311 else if (!strncmp(line
, "%%BeginDocument:", 16))
313 else if (!strncmp(line
, "%%EndDocument", 13))
315 else if (!strncmp(line
, "%%Trailer", 9))
319 for (i
= 0; !binary
&& i
< bytes
; i
++)
323 if ((ch
< ' ' || (ch
& 0x80)) && ch
!= '\n' && ch
!= '\r' && ch
!= '\t')
328 if (saw_bounding_box
<= 0)
331 _cupsLangPuts(stdout
, _("FAIL"));
334 _cupsLangPuts(stdout
, _(" Missing or bad %%BoundingBox: comment.\n"
335 " REF: Page 39, %%BoundingBox:"));
341 _cupsLangPuts(stdout
, _("FAIL"));
344 _cupsLangPuts(stdout
, _(" Missing or bad %%Pages: comment.\n"
345 " REF: Page 43, %%Pages:"));
348 if (!saw_end_comments
)
351 _cupsLangPuts(stdout
, _("FAIL"));
354 _cupsLangPuts(stdout
, _(" Missing %%EndComments comment."
355 " REF: Page 41, %%EndComments"));
361 _cupsLangPuts(stdout
, _("FAIL"));
364 _cupsLangPuts(stdout
, _(" Missing or bad %%Page: comments.\n"
365 " REF: Page 53, %%Page:"));
371 _cupsLangPuts(stdout
, _("FAIL"));
374 _cupsLangPuts(stdout
, _(" Too many %%EndDocument comments."));
379 _cupsLangPuts(stdout
, _("FAIL"));
382 _cupsLangPuts(stdout
, _(" Too many %%BeginDocument comments."));
385 if (saw_long_line
> 1)
386 _cupsLangPrintf(stderr
,
387 _(" Saw %d lines that exceeded 255 characters."),
391 _cupsLangPuts(stdout
, _("PASS"));
394 _cupsLangPuts(stdout
, _(" Warning: file contains binary data."));
397 _cupsLangPrintf(stdout
,
398 _(" Warning: obsolete DSC version %.1f in file."),
401 if (saw_end_comments
< 0)
402 _cupsLangPuts(stdout
, _(" Warning: no %%EndComments comment in file."));
411 * 'usage()' - Show program usage.
417 _cupsLangPuts(stdout
, _("Usage: cupstestdsc [options] filename.ps [... "
419 _cupsLangPuts(stdout
, _(" cupstestdsc [options] -"));
420 _cupsLangPuts(stdout
, "");
421 _cupsLangPuts(stdout
, _("Options:"));
422 _cupsLangPuts(stdout
, "");
423 _cupsLangPuts(stdout
, _(" -h Show program usage"));
424 _cupsLangPuts(stdout
, "");
425 _cupsLangPuts(stdout
, _("Note: this program only validates the DSC comments, "
426 "not the PostScript itself."));