]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
2 * "$Id: cupstestdsc.c 7720 2008-07-11 22:46:21Z mike $"
4 * DSC test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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"));
195 _cupsLangPuts(stdout
,
196 _(" Missing %!PS-Adobe-3.0 on first line!\n"
197 " REF: Page 17, 3.1 Conforming Documents\n"));
202 version
= atof(line
+ 11);
206 if (!strncmp(line
, "%%BeginDocument:", 16))
208 else if (!strncmp(line
, "%%EndDocument", 13))
211 else if (saw_trailer
)
213 if (!strncmp(line
, "%%Pages:", 8))
215 if (atoi(line
+ 8) <= 0)
218 _cupsLangPuts(stdout
, _("FAIL\n"));
221 _cupsLangPrintf(stdout
,
222 _(" Bad %%%%Pages: on line %d!\n"
223 " REF: Page 43, %%%%Pages:\n"),
229 else if (!strncmp(line
, "%%BoundingBox:", 14))
231 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
235 _cupsLangPuts(stdout
, _("FAIL\n"));
238 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
239 " REF: Page 39, %%%%BoundingBox:\n"),
243 saw_bounding_box
= 1;
246 else if (!saw_end_comments
)
248 if (!strncmp(line
, "%%EndComments", 13))
249 saw_end_comments
= 1;
250 else if (line
[0] != '%')
251 saw_end_comments
= -1;
252 else if (!strncmp(line
, "%%Pages:", 8))
254 if (strstr(line
+ 8, "(atend)"))
256 else if (atoi(line
+ 8) <= 0)
259 _cupsLangPuts(stdout
, _("FAIL\n"));
262 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d!\n"
263 " REF: Page 43, %%%%Pages:\n"),
269 else if (!strncmp(line
, "%%BoundingBox:", 14))
271 if (strstr(line
, "(atend)"))
272 saw_bounding_box
= -1;
273 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
277 _cupsLangPuts(stdout
, _("FAIL\n"));
280 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
281 " REF: Page 39, %%%%BoundingBox:\n"),
285 saw_bounding_box
= 1;
288 else if (saw_begin_prolog
&& !saw_end_prolog
)
290 if (!strncmp(line
, "%%EndProlog", 11))
293 else if (saw_begin_setup
&& !saw_end_setup
)
295 if (!strncmp(line
, "%%EndSetup", 10))
298 else if (saw_end_comments
)
300 if (!strncmp(line
, "%%Page:", 7))
302 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2 ||
303 page_number
!= (last_page_number
+ 1) || page_number
< 1)
306 _cupsLangPuts(stdout
, _("FAIL\n"));
309 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d!\n"
310 " REF: Page 53, %%%%Page:\n"),
315 last_page_number
= page_number
;
319 else if (!strncmp(line
, "%%BeginProlog", 13))
320 saw_begin_prolog
= 1;
321 else if (!strncmp(line
, "%%BeginSetup", 12))
323 else if (!strncmp(line
, "%%BeginDocument:", 16))
325 else if (!strncmp(line
, "%%EndDocument", 13))
327 else if (!strncmp(line
, "%%Trailer", 9))
331 for (i
= 0; !binary
&& i
< bytes
; i
++)
335 if ((ch
< ' ' || (ch
& 0x80)) && ch
!= '\n' && ch
!= '\r' && ch
!= '\t')
340 if (saw_bounding_box
<= 0)
343 _cupsLangPuts(stdout
, _("FAIL\n"));
346 _cupsLangPuts(stdout
, _(" Missing or bad %%BoundingBox: comment!\n"
347 " REF: Page 39, %%BoundingBox:\n"));
353 _cupsLangPuts(stdout
, _("FAIL\n"));
356 _cupsLangPuts(stdout
, _(" Missing or bad %%Pages: comment!\n"
357 " REF: Page 43, %%Pages:\n"));
360 if (!saw_end_comments
)
363 _cupsLangPuts(stdout
, _("FAIL\n"));
366 _cupsLangPuts(stdout
, _(" Missing %%EndComments comment!\n"
367 " REF: Page 41, %%EndComments\n"));
373 _cupsLangPuts(stdout
, _("FAIL\n"));
376 _cupsLangPuts(stdout
, _(" Missing or bad %%Page: comments!\n"
377 " REF: Page 53, %%Page:\n"));
383 _cupsLangPuts(stdout
, _("FAIL\n"));
386 _cupsLangPuts(stdout
, _(" Too many %%EndDocument comments!\n"));
391 _cupsLangPuts(stdout
, _("FAIL\n"));
394 _cupsLangPuts(stdout
, _(" Too many %%BeginDocument comments!\n"));
397 if (saw_long_line
> 1)
398 _cupsLangPrintf(stderr
,
399 _(" Saw %d lines that exceeded 255 characters!\n"),
403 _cupsLangPuts(stdout
, _("PASS\n"));
406 _cupsLangPuts(stdout
, _(" Warning: file contains binary data!\n"));
409 _cupsLangPrintf(stdout
,
410 _(" Warning: obsolete DSC version %.1f in file!\n"),
413 if (saw_end_comments
< 0)
414 _cupsLangPuts(stdout
, _(" Warning: no %%EndComments comment in file!\n"));
423 * 'usage()' - Show program usage.
429 _cupsLangPuts(stdout
,
430 _("Usage: cupstestdsc [options] filename.ps [... filename.ps]\n"
431 " cupstestdsc [options] -\n"
435 " -h Show program usage\n"
437 " Note: this program only validates the DSC comments, "
438 "not the PostScript itself.\n"));
445 * End of "$Id: cupstestdsc.c 7720 2008-07-11 22:46:21Z mike $".