]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
2 * "$Id: cupstestdsc.c 6649 2007-07-11 21:46:42Z mike $"
4 * DSC test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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/string.h>
31 #include <cups/cups.h>
32 #include <cups/file.h>
33 #include <cups/i18n.h>
42 static int check_file(const char *filename
);
43 static void usage(void);
47 * 'main()' - Main entry for test program.
50 int /* O - Exit status */
51 main(int argc
, /* I - Number of command-line args */
52 char *argv
[]) /* I - Command-line arguments */
54 int i
; /* Looping var */
55 int status
; /* Status of tests */
56 int num_files
; /* Number of files tested */
62 * Collect command-line arguments...
65 for (i
= 1, num_files
= 0, status
= 0; i
< argc
; i
++)
66 if (argv
[i
][0] == '-')
71 * Currently the only supported option is "-h" (help)...
79 status
+= check_file("(stdin)");
85 status
+= check_file(argv
[i
]);
96 * 'check()' - Check a file for conformance.
99 static int /* O - 0 on success, 1 on failure */
100 check_file(const char *filename
) /* I - File to read from */
102 int i
; /* Looping var */
103 cups_file_t
*fp
; /* File */
104 char line
[1024]; /* Line from file */
105 int ch
; /* Current character */
106 size_t bytes
; /* Length of line */
107 int status
; /* Status of test */
108 int linenum
; /* Line number */
109 int binary
; /* File contains binary data? */
110 float version
; /* DSC version */
111 int lbrt
[4]; /* Bounding box */
112 char page_label
[256]; /* Page label string */
113 int page_number
; /* Page number */
114 int last_page_number
; /* Last page number seen */
115 int level
; /* Embedded document level */
116 int saw_bounding_box
, /* %%BoundingBox seen? */
117 saw_pages
, /* %%Pages seen? */
118 saw_end_comments
, /* %%EndComments seen? */
119 saw_begin_prolog
, /* %%BeginProlog seen? */
120 saw_end_prolog
, /* %%EndProlog seen? */
121 saw_begin_setup
, /* %%BeginSetup seen? */
122 saw_end_setup
, /* %%EndSetup seen? */
123 saw_page
, /* %%Page seen? */
124 saw_trailer
, /* %%Trailer seen? */
125 saw_long_line
; /* Saw long lines? */
132 if (!strcmp(filename
, "(stdin)"))
133 fp
= cupsFileStdin();
135 fp
= cupsFileOpen(filename
, "r");
148 last_page_number
= 0;
151 saw_begin_prolog
= 0;
153 saw_bounding_box
= 0;
154 saw_end_comments
= 0;
164 _cupsLangPrintf(stdout
, "%s: ", filename
);
167 while ((bytes
= cupsFileGetLine(fp
, line
, sizeof(line
))) > 0)
176 _cupsLangPuts(stdout
, _("FAIL\n"));
179 _cupsLangPrintf(stdout
,
180 _(" Line %d is longer than 255 characters (%d)!\n"
181 " REF: Page 25, Line Length\n"),
182 linenum
, (int)bytes
);
190 if (strncmp(line
, "%!PS-Adobe-", 11))
193 _cupsLangPuts(stdout
, _("FAIL\n"));
196 _cupsLangPuts(stdout
,
197 _(" Missing %!PS-Adobe-3.0 on first line!\n"
198 " REF: Page 17, 3.1 Conforming Documents\n"));
203 version
= atof(line
+ 11);
207 if (!strncmp(line
, "%%BeginDocument:", 16))
209 else if (!strncmp(line
, "%%EndDocument", 13))
212 else if (saw_trailer
)
214 if (!strncmp(line
, "%%Pages:", 8))
216 if (atoi(line
+ 8) <= 0)
219 _cupsLangPuts(stdout
, _("FAIL\n"));
222 _cupsLangPrintf(stdout
,
223 _(" Bad %%%%Pages: on line %d!\n"
224 " REF: Page 43, %%%%Pages:\n"),
230 else if (!strncmp(line
, "%%BoundingBox:", 14))
232 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
236 _cupsLangPuts(stdout
, _("FAIL\n"));
239 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
240 " REF: Page 39, %%%%BoundingBox:\n"),
244 saw_bounding_box
= 1;
247 else if (!saw_end_comments
)
249 if (!strncmp(line
, "%%EndComments", 13))
250 saw_end_comments
= 1;
251 else if (line
[0] != '%')
252 saw_end_comments
= -1;
253 else if (!strncmp(line
, "%%Pages:", 8))
255 if (strstr(line
+ 8, "(atend)"))
257 else if (atoi(line
+ 8) <= 0)
260 _cupsLangPuts(stdout
, _("FAIL\n"));
263 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d!\n"
264 " REF: Page 43, %%%%Pages:\n"),
270 else if (!strncmp(line
, "%%BoundingBox:", 14))
272 if (strstr(line
, "(atend)"))
273 saw_bounding_box
= -1;
274 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
278 _cupsLangPuts(stdout
, _("FAIL\n"));
281 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
282 " REF: Page 39, %%%%BoundingBox:\n"),
286 saw_bounding_box
= 1;
289 else if (saw_begin_prolog
&& !saw_end_prolog
)
291 if (!strncmp(line
, "%%EndProlog", 11))
294 else if (saw_begin_setup
&& !saw_end_setup
)
296 if (!strncmp(line
, "%%EndSetup", 10))
299 else if (saw_end_comments
)
301 if (!strncmp(line
, "%%Page:", 7))
303 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2 ||
304 page_number
!= (last_page_number
+ 1) || page_number
< 1)
307 _cupsLangPuts(stdout
, _("FAIL\n"));
310 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d!\n"
311 " REF: Page 53, %%%%Page:\n"),
316 last_page_number
= page_number
;
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 6649 2007-07-11 21:46:42Z mike $".