]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
87207d7f593d16461ed528063bdc2097181d54c2
2 * "$Id: cupstestdsc.c 7720 2008-07-11 22:46:21Z mike $"
4 * DSC test program for CUPS.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 2006 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This file is subject to the Apple OS-Developed Software exception.
21 * main() - Main entry for test program.
22 * check() - Check a file for conformance.
23 * usage() - Show program usage.
27 * Include necessary headers...
30 #include <cups/cups-private.h>
37 static int check_file(const char *filename
);
38 static void usage(void);
42 * 'main()' - Main entry for test program.
45 int /* O - Exit status */
46 main(int argc
, /* I - Number of command-line args */
47 char *argv
[]) /* I - Command-line arguments */
49 int i
; /* Looping var */
50 int status
; /* Status of tests */
51 int num_files
; /* Number of files tested */
57 * Collect command-line arguments...
60 for (i
= 1, num_files
= 0, status
= 0; i
< argc
; i
++)
61 if (argv
[i
][0] == '-')
66 * Currently the only supported option is "-h" (help)...
74 status
+= check_file("(stdin)");
80 status
+= check_file(argv
[i
]);
91 * 'check()' - Check a file for conformance.
94 static int /* O - 0 on success, 1 on failure */
95 check_file(const char *filename
) /* I - File to read from */
97 int i
; /* Looping var */
98 cups_file_t
*fp
; /* File */
99 char line
[1024]; /* Line from file */
100 int ch
; /* Current character */
101 size_t bytes
; /* Length of line */
102 int status
; /* Status of test */
103 int linenum
; /* Line number */
104 int binary
; /* File contains binary data? */
105 float version
; /* DSC version */
106 int lbrt
[4]; /* Bounding box */
107 char page_label
[256]; /* Page label string */
108 int page_number
; /* Page number */
109 int last_page_number
; /* Last page number seen */
110 int level
; /* Embedded document level */
111 int saw_bounding_box
, /* %%BoundingBox seen? */
112 saw_pages
, /* %%Pages seen? */
113 saw_end_comments
, /* %%EndComments seen? */
114 saw_begin_prolog
, /* %%BeginProlog seen? */
115 saw_end_prolog
, /* %%EndProlog seen? */
116 saw_begin_setup
, /* %%BeginSetup seen? */
117 saw_end_setup
, /* %%EndSetup seen? */
118 saw_page
, /* %%Page seen? */
119 saw_trailer
, /* %%Trailer seen? */
120 saw_long_line
; /* Saw long lines? */
127 if (!strcmp(filename
, "(stdin)"))
128 fp
= cupsFileStdin();
130 fp
= cupsFileOpen(filename
, "r");
143 last_page_number
= 0;
146 saw_begin_prolog
= 0;
148 saw_bounding_box
= 0;
149 saw_end_comments
= 0;
159 _cupsLangPrintf(stdout
, "%s: ", filename
);
162 while ((bytes
= cupsFileGetLine(fp
, line
, sizeof(line
))) > 0)
171 _cupsLangPuts(stdout
, _("FAIL\n"));
174 _cupsLangPrintf(stdout
,
175 _(" Line %d is longer than 255 characters (%d)\n"
176 " REF: Page 25, Line Length\n"),
177 linenum
, (int)bytes
);
185 if (strncmp(line
, "%!PS-Adobe-", 11))
188 _cupsLangPuts(stdout
, _("FAIL\n"));
190 _cupsLangPuts(stdout
,
191 _(" Missing %!PS-Adobe-3.0 on first line\n"
192 " REF: Page 17, 3.1 Conforming Documents\n"));
197 version
= atof(line
+ 11);
201 if (!strncmp(line
, "%%BeginDocument:", 16))
203 else if (!strncmp(line
, "%%EndDocument", 13))
206 else if (saw_trailer
)
208 if (!strncmp(line
, "%%Pages:", 8))
210 if (atoi(line
+ 8) <= 0)
213 _cupsLangPuts(stdout
, _("FAIL\n"));
216 _cupsLangPrintf(stdout
,
217 _(" Bad %%%%Pages: on line %d\n"
218 " REF: Page 43, %%%%Pages:\n"),
224 else if (!strncmp(line
, "%%BoundingBox:", 14))
226 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
230 _cupsLangPuts(stdout
, _("FAIL\n"));
233 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d\n"
234 " REF: Page 39, %%%%BoundingBox:\n"),
238 saw_bounding_box
= 1;
241 else if (!saw_end_comments
)
243 if (!strncmp(line
, "%%EndComments", 13))
244 saw_end_comments
= 1;
245 else if (line
[0] != '%')
246 saw_end_comments
= -1;
247 else if (!strncmp(line
, "%%Pages:", 8))
249 if (strstr(line
+ 8, "(atend)"))
251 else if (atoi(line
+ 8) <= 0)
254 _cupsLangPuts(stdout
, _("FAIL\n"));
257 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d\n"
258 " REF: Page 43, %%%%Pages:\n"),
264 else if (!strncmp(line
, "%%BoundingBox:", 14))
266 if (strstr(line
, "(atend)"))
267 saw_bounding_box
= -1;
268 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
272 _cupsLangPuts(stdout
, _("FAIL\n"));
275 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d\n"
276 " REF: Page 39, %%%%BoundingBox:\n"),
280 saw_bounding_box
= 1;
283 else if (saw_begin_prolog
&& !saw_end_prolog
)
285 if (!strncmp(line
, "%%EndProlog", 11))
288 else if (saw_begin_setup
&& !saw_end_setup
)
290 if (!strncmp(line
, "%%EndSetup", 10))
293 else if (saw_end_comments
)
295 if (!strncmp(line
, "%%Page:", 7))
297 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2 ||
298 page_number
!= (last_page_number
+ 1) || page_number
< 1)
301 _cupsLangPuts(stdout
, _("FAIL\n"));
304 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d\n"
305 " REF: Page 53, %%%%Page:\n"),
310 last_page_number
= page_number
;
314 else if (!strncmp(line
, "%%BeginProlog", 13))
315 saw_begin_prolog
= 1;
316 else if (!strncmp(line
, "%%BeginSetup", 12))
318 else if (!strncmp(line
, "%%BeginDocument:", 16))
320 else if (!strncmp(line
, "%%EndDocument", 13))
322 else if (!strncmp(line
, "%%Trailer", 9))
326 for (i
= 0; !binary
&& i
< bytes
; i
++)
330 if ((ch
< ' ' || (ch
& 0x80)) && ch
!= '\n' && ch
!= '\r' && ch
!= '\t')
335 if (saw_bounding_box
<= 0)
338 _cupsLangPuts(stdout
, _("FAIL\n"));
341 _cupsLangPuts(stdout
, _(" Missing or bad %%BoundingBox: comment\n"
342 " REF: Page 39, %%BoundingBox:\n"));
348 _cupsLangPuts(stdout
, _("FAIL\n"));
351 _cupsLangPuts(stdout
, _(" Missing or bad %%Pages: comment\n"
352 " REF: Page 43, %%Pages:\n"));
355 if (!saw_end_comments
)
358 _cupsLangPuts(stdout
, _("FAIL\n"));
361 _cupsLangPuts(stdout
, _(" Missing %%EndComments comment\n"
362 " REF: Page 41, %%EndComments\n"));
368 _cupsLangPuts(stdout
, _("FAIL\n"));
371 _cupsLangPuts(stdout
, _(" Missing or bad %%Page: comments\n"
372 " REF: Page 53, %%Page:\n"));
378 _cupsLangPuts(stdout
, _("FAIL\n"));
381 _cupsLangPuts(stdout
, _(" Too many %%EndDocument comments\n"));
386 _cupsLangPuts(stdout
, _("FAIL\n"));
389 _cupsLangPuts(stdout
, _(" Too many %%BeginDocument comments\n"));
392 if (saw_long_line
> 1)
393 _cupsLangPrintf(stderr
,
394 _(" Saw %d lines that exceeded 255 characters\n"),
398 _cupsLangPuts(stdout
, _("PASS\n"));
401 _cupsLangPuts(stdout
, _(" Warning: file contains binary data\n"));
404 _cupsLangPrintf(stdout
,
405 _(" Warning: obsolete DSC version %.1f in file\n"),
408 if (saw_end_comments
< 0)
409 _cupsLangPuts(stdout
, _(" Warning: no %%EndComments comment in file\n"));
418 * 'usage()' - Show program usage.
424 _cupsLangPuts(stdout
,
425 _("Usage: cupstestdsc [options] filename.ps [... filename.ps]\n"
426 " cupstestdsc [options] -\n"
430 " -h Show program usage\n"
432 " Note: this program only validates the DSC comments, "
433 "not the PostScript itself.\n"));
440 * End of "$Id: cupstestdsc.c 7720 2008-07-11 22:46:21Z mike $".