]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestdsc.c
2 * "$Id: cupstestdsc.c 5925 2006-09-05 19:43:11Z 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.
30 * main() - Main entry for test program.
31 * check() - Check a file for conformance.
32 * usage() - Show program usage.
36 * Include necessary headers...
39 #include <cups/string.h>
40 #include <cups/cups.h>
41 #include <cups/file.h>
42 #include <cups/i18n.h>
51 static int check_file(const char *filename
);
52 static void usage(void);
56 * 'main()' - Main entry for test program.
59 int /* O - Exit status */
60 main(int argc
, /* I - Number of command-line args */
61 char *argv
[]) /* I - Command-line arguments */
63 int i
; /* Looping var */
64 int status
; /* Status of tests */
65 int num_files
; /* Number of files tested */
71 * Collect command-line arguments...
74 for (i
= 1, num_files
= 0, status
= 0; i
< argc
; i
++)
75 if (argv
[i
][0] == '-')
80 * Currently the only supported option is "-h" (help)...
88 status
+= check_file("(stdin)");
94 status
+= check_file(argv
[i
]);
105 * 'check()' - Check a file for conformance.
108 static int /* O - 0 on success, 1 on failure */
109 check_file(const char *filename
) /* I - File to read from */
111 int i
; /* Looping var */
112 cups_file_t
*fp
; /* File */
113 char line
[1024]; /* Line from file */
114 int ch
; /* Current character */
115 size_t bytes
; /* Length of line */
116 int status
; /* Status of test */
117 int linenum
; /* Line number */
118 int binary
; /* File contains binary data? */
119 float version
; /* DSC version */
120 int lbrt
[4]; /* Bounding box */
121 char page_label
[256]; /* Page label string */
122 int page_number
; /* Page number */
123 int last_page_number
; /* Last page number seen */
124 int level
; /* Embedded document level */
125 int saw_bounding_box
, /* %%BoundingBox seen? */
126 saw_pages
, /* %%Pages seen? */
127 saw_end_comments
, /* %%EndComments seen? */
128 saw_begin_prolog
, /* %%BeginProlog seen? */
129 saw_end_prolog
, /* %%EndProlog seen? */
130 saw_begin_setup
, /* %%BeginSetup seen? */
131 saw_end_setup
, /* %%EndSetup seen? */
132 saw_page
, /* %%Page seen? */
133 saw_trailer
, /* %%Trailer seen? */
134 saw_long_line
; /* Saw long lines? */
141 if (!strcmp(filename
, "(stdin)"))
142 fp
= cupsFileStdin();
144 fp
= cupsFileOpen(filename
, "r");
157 last_page_number
= 0;
160 saw_begin_prolog
= 0;
162 saw_bounding_box
= 0;
163 saw_end_comments
= 0;
173 _cupsLangPrintf(stdout
, "%s: ", filename
);
176 while ((bytes
= cupsFileGetLine(fp
, line
, sizeof(line
))) > 0)
185 _cupsLangPuts(stdout
, _("FAIL\n"));
188 _cupsLangPrintf(stdout
,
189 _(" Line %d is longer than 255 characters (%d)!\n"
190 " REF: Page 25, Line Length\n"),
191 linenum
, (int)bytes
);
199 if (strncmp(line
, "%!PS-Adobe-", 11))
202 _cupsLangPuts(stdout
, _("FAIL\n"));
205 _cupsLangPuts(stdout
,
206 _(" Missing %!PS-Adobe-3.0 on first line!\n"
207 " REF: Page 17, 3.1 Conforming Documents\n"));
212 version
= atof(line
+ 11);
216 if (!strncmp(line
, "%%BeginDocument:", 16))
218 else if (!strncmp(line
, "%%EndDocument", 13))
221 else if (saw_trailer
)
223 if (!strncmp(line
, "%%Pages:", 8))
225 if (atoi(line
+ 8) <= 0)
228 _cupsLangPuts(stdout
, _("FAIL\n"));
231 _cupsLangPrintf(stdout
,
232 _(" Bad %%%%Pages: on line %d!\n"
233 " REF: Page 43, %%%%Pages:\n"),
239 else if (!strncmp(line
, "%%BoundingBox:", 14))
241 if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
245 _cupsLangPuts(stdout
, _("FAIL\n"));
248 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
249 " REF: Page 39, %%%%BoundingBox:\n"),
253 saw_bounding_box
= 1;
256 else if (!saw_end_comments
)
258 if (!strncmp(line
, "%%EndComments", 13))
259 saw_end_comments
= 1;
260 else if (line
[0] != '%')
261 saw_end_comments
= -1;
262 else if (!strncmp(line
, "%%Pages:", 8))
264 if (strstr(line
+ 8, "(atend)"))
266 else if (atoi(line
+ 8) <= 0)
269 _cupsLangPuts(stdout
, _("FAIL\n"));
272 _cupsLangPrintf(stdout
, _(" Bad %%%%Pages: on line %d!\n"
273 " REF: Page 43, %%%%Pages:\n"),
279 else if (!strncmp(line
, "%%BoundingBox:", 14))
281 if (strstr(line
, "(atend)"))
282 saw_bounding_box
= -1;
283 else if (sscanf(line
+ 14, "%d%d%d%d", lbrt
+ 0, lbrt
+ 1, lbrt
+ 2,
287 _cupsLangPuts(stdout
, _("FAIL\n"));
290 _cupsLangPrintf(stdout
, _(" Bad %%%%BoundingBox: on line %d!\n"
291 " REF: Page 39, %%%%BoundingBox:\n"),
295 saw_bounding_box
= 1;
298 else if (saw_begin_prolog
&& !saw_end_prolog
)
300 if (!strncmp(line
, "%%EndProlog", 11))
303 else if (saw_begin_setup
&& !saw_end_setup
)
305 if (!strncmp(line
, "%%EndSetup", 10))
308 else if (saw_end_comments
)
310 if (!strncmp(line
, "%%Page:", 7))
312 if (sscanf(line
+ 7, "%255s%d", page_label
, &page_number
) != 2 ||
313 page_number
!= (last_page_number
+ 1) || page_number
< 1)
316 _cupsLangPuts(stdout
, _("FAIL\n"));
319 _cupsLangPrintf(stdout
, _(" Bad %%%%Page: on line %d!\n"
320 " REF: Page 53, %%%%Page:\n"),
325 last_page_number
= page_number
;
329 else if (!strncmp(line
, "%%BeginProlog", 13))
330 saw_begin_prolog
= 1;
331 else if (!strncmp(line
, "%%BeginSetup", 12))
333 else if (!strncmp(line
, "%%BeginDocument:", 16))
335 else if (!strncmp(line
, "%%EndDocument", 13))
337 else if (!strncmp(line
, "%%Trailer", 9))
341 for (i
= 0; !binary
&& i
< bytes
; i
++)
345 if ((ch
< ' ' || (ch
& 0x80)) && ch
!= '\n' && ch
!= '\r' && ch
!= '\t')
350 if (saw_bounding_box
<= 0)
353 _cupsLangPuts(stdout
, _("FAIL\n"));
356 _cupsLangPuts(stdout
, _(" Missing or bad %%BoundingBox: comment!\n"
357 " REF: Page 39, %%BoundingBox:\n"));
363 _cupsLangPuts(stdout
, _("FAIL\n"));
366 _cupsLangPuts(stdout
, _(" Missing or bad %%Pages: comment!\n"
367 " REF: Page 43, %%Pages:\n"));
370 if (!saw_end_comments
)
373 _cupsLangPuts(stdout
, _("FAIL\n"));
376 _cupsLangPuts(stdout
, _(" Missing %%EndComments comment!\n"
377 " REF: Page 41, %%EndComments\n"));
383 _cupsLangPuts(stdout
, _("FAIL\n"));
386 _cupsLangPuts(stdout
, _(" Missing or bad %%Page: comments!\n"
387 " REF: Page 53, %%Page:\n"));
393 _cupsLangPuts(stdout
, _("FAIL\n"));
396 _cupsLangPuts(stdout
, _(" Too many %%EndDocument comments!\n"));
401 _cupsLangPuts(stdout
, _("FAIL\n"));
404 _cupsLangPuts(stdout
, _(" Too many %%BeginDocument comments!\n"));
407 if (saw_long_line
> 1)
408 _cupsLangPrintf(stderr
,
409 _(" Saw %d lines that exceeded 255 characters!\n"),
413 _cupsLangPuts(stdout
, _("PASS\n"));
416 _cupsLangPuts(stdout
, _(" Warning: file contains binary data!\n"));
419 _cupsLangPrintf(stdout
,
420 _(" Warning: obsolete DSC version %.1f in file!\n"),
423 if (saw_end_comments
< 0)
424 _cupsLangPuts(stdout
, _(" Warning: no %%EndComments comment in file!\n"));
433 * 'usage()' - Show program usage.
439 _cupsLangPuts(stdout
,
440 _("Usage: cupstestdsc [options] filename.ps [... filename.ps]\n"
441 " cupstestdsc [options] -\n"
445 " -h Show program usage\n"
447 " Note: this program only validates the DSC comments, "
448 "not the PostScript itself.\n"));
455 * End of "$Id: cupstestdsc.c 5925 2006-09-05 19:43:11Z mike $".