]>
Commit | Line | Data |
---|---|---|
ac884b6a | 1 | // |
503b54c9 | 2 | // File class for the CUPS PPD Compiler. |
ac884b6a | 3 | // |
503b54c9 MS |
4 | // Copyright 2007-2010 by Apple Inc. |
5 | // Copyright 2002-2005 by Easy Software Products. | |
ac884b6a | 6 | // |
e3101897 | 7 | // Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ac884b6a MS |
8 | // |
9 | ||
10 | // | |
11 | // Include necessary headers... | |
12 | // | |
13 | ||
38e73f87 | 14 | #include "ppdc-private.h" |
ac884b6a MS |
15 | |
16 | ||
17 | // | |
18 | // 'ppdcFile::ppdcFile()' - Create (open) a file. | |
19 | // | |
20 | ||
4509bb49 MS |
21 | ppdcFile::ppdcFile(const char *f, // I - File to open |
22 | cups_file_t *ffp) // I - File pointer to use | |
ac884b6a | 23 | { |
4509bb49 MS |
24 | if (ffp) |
25 | { | |
26 | fp = ffp; | |
27 | cupsFileRewind(fp); | |
28 | } | |
29 | else | |
30 | fp = cupsFileOpen(f, "r"); | |
31 | ||
82cc1f9a MS |
32 | close_on_delete = !ffp; |
33 | filename = f; | |
34 | line = 1; | |
ac884b6a MS |
35 | |
36 | if (!fp) | |
0837b7e8 | 37 | _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f, |
61cf44e2 | 38 | strerror(errno)); |
ac884b6a MS |
39 | } |
40 | ||
41 | ||
42 | // | |
43 | // 'ppdcFile::~ppdcFile()' - Delete (close) a file. | |
44 | // | |
45 | ||
46 | ppdcFile::~ppdcFile() | |
47 | { | |
82cc1f9a | 48 | if (close_on_delete && fp) |
ac884b6a MS |
49 | cupsFileClose(fp); |
50 | } | |
51 | ||
52 | ||
53 | // | |
54 | // 'ppdcFile::get()' - Get a character from a file. | |
55 | // | |
56 | ||
57 | int | |
58 | ppdcFile::get() | |
59 | { | |
60 | int ch; // Character from file | |
61 | ||
62 | ||
63 | // Return EOF if there is no open file... | |
64 | if (!fp) | |
65 | return (EOF); | |
66 | ||
67 | // Get the character... | |
68 | ch = cupsFileGetChar(fp); | |
69 | ||
70 | // Update the line number as needed... | |
71 | if (ch == '\n') | |
72 | line ++; | |
73 | ||
74 | // Return the character... | |
75 | return (ch); | |
76 | } | |
77 | ||
78 | ||
79 | // | |
80 | // 'ppdcFile::peek()' - Look at the next character from a file. | |
81 | // | |
82 | ||
83 | int // O - Next character in file | |
84 | ppdcFile::peek() | |
85 | { | |
86 | // Return immediaely if there is no open file... | |
87 | if (!fp) | |
88 | return (EOF); | |
89 | ||
90 | // Otherwise return the next character without advancing... | |
91 | return (cupsFilePeekChar(fp)); | |
92 | } |