|
static bool | is_a_line_end (int c) |
|
static int | skip_new_line (struct ppd_file *ppd_d, int c) |
|
static int | get_next_char (struct ppd_file *ppd_d) |
|
static int | print_length_error (struct ppd_file *ppd_d, const char *name, const unsigned char *string) |
|
static int | print_character_error (struct ppd_file *ppd_d, const char *name, int c) |
|
static int | mature_end_of_file (struct ppd_file *ppd_d, const char *name, int c) |
|
static int | mature_end_of_line (struct ppd_file *ppd_d, const char *name, int c) |
|
static int | append_char_to_string (unsigned char *dst, size_t sz, int c) |
|
static int | add_to_keyword (struct ppd_file *ppd_d, int c) |
|
static int | add_to_name (struct ppd_file *ppd_d, int c) |
|
static int | add_to_description (struct ppd_file *ppd_d, int c) |
|
static int | add_to_value (struct ppd_file *ppd_d, int c) |
|
static void | reset_input_strings (struct ppd_file *ppd_d) |
|
static int | read_comment (struct ppd_file *ppd_d) |
|
static int | read_keyword (struct ppd_file *ppd_d, int c) |
|
static int | skip_whitespace (struct ppd_file *ppd_d, int c) |
|
static int | read_name (struct ppd_file *ppd_d, int c) |
|
static int | read_description (struct ppd_file *ppd_d) |
|
static int | read_quoted_string (struct ppd_file *ppd_d, int quote) |
|
static int | read_value (struct ppd_file *ppd_d) |
|
static int | read_one_line (struct ppd_file *ppd_d, int c) |
|
static int | read_ppd_file (struct caps_ppd_options_table *pot, struct ppd_file *ppd_d) |
|
static int | open_ppd_file_for_read (struct ppd_file *ppd_d, const char *file_name) |
|
static void | close_ppd_file (struct ppd_file *ppd_d) |
|
int | caps_ppd_options_table_file_read (struct caps_ppd_options_table *pot, const char *ppd_file_name) |
|
This is a very simple scanner for PPD files. I started with different attempts to scan this kind of files. One attempt was to use FLEX to do the job. But the syntax used in PPD files is such simple and FLEX is a huge beast, so I decided to do it by myself.
Each line in a PPD file conforms to:
*KEYWORD[ [*]NAME[/DESCRIPTION]]:[ ]VALUE
KEYWORD
's encoding is ISOLatin1, allowed chars are [:alpha:][:digit:]_.-
NAME
's encoding is ISOLatin1, allowed chars are [:alpha:][:digit:]_.- (and '*'!)
DESCRIPTION
's encoding is UTF8, all printable chars are allowed, except ':'
VALUE
's encoding is ISOLatin1, all printable chars are allowed, NL terminates VALUE
, to include NL into VALUE
, it must be double quoted
Refer: Adobe TechNote #5003: PostScript Printer Description File Format Specification Version 4.3
This technote defines our KEYWORD
to "main keyword" and our NAME
to "option keyword". This technote defines the length of each line is up to 255 chars including the newline char(s)
Some things are still to be discussed:
- how long can a keyword, name, description or value be?
- from the spec: 40 characters is the maximum length for main keywords
- from the spec: 40 characters is the maximum length for option keywords, including any extensions or qualifiers separated by dots
- should we limit a line to 255 chars?
- "emit an error message or not to emit an error message"?
- a 'newline' can be
10
and/or 13
- Todo:
Handle hex characters (e.g. "<[\t :digit:abcdefABCDEF]+>")
"Newlines may occur and should be ignored, except in translation strings,
where they are illegal."
Handle "*?" keywords
static int read_quoted_string |
( |
struct ppd_file * |
ppd_d, |
|
|
int |
quote |
|
) |
| |
|
static |
Read a quoted value entry
- Parameters
-
[in,out] | ppd_d | all info about the PPD |
[in] | quote | quote character to define the end of the string |
- Returns
- Last char read or BAD_CHAR in case of a bad value string
Allowed characters for 'value' are
- 0x20...0x7e printable ASCII characters
- 0xa0...0xff FIXME??? Not 0x80...0xff???
- '"' terminates the string
- EOF is an failure
- Todo:
- Should a '\n' be part of the resulting string or be skipped?
From the spec:
Everything between the double quotes is treated as literal; that is, newlines and hexadecimal substrings are allowed and are placed in the output file to be passed on to the interpreter. Note that, unlike other values, a newline does not terminate an InvocationValue and a slash does not mark the beginning of a translation string.
[...] byte codes outside the range of printable 7-bit ASCII [are forbidden] <- InvocationValue
Issue: two types of double quoted values are possible: InvocationValue or QuotedValue Both handle their characters differently.
For QuotedValue the newline is not part of the resulting string. And all characters are allowed.
- Todo:
- Fix line counting here!