]>
Commit | Line | Data |
---|---|---|
4bc98872 | 1 | // |
2 | // "$Id$" | |
3 | // | |
4 | // File class for the CUPS PPD Compiler. | |
5 | // | |
3d94661a | 6 | // Copyright 2007-2010 by Apple Inc. |
4bc98872 | 7 | // Copyright 2002-2005 by Easy Software Products. |
8 | // | |
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/". | |
14 | // | |
15 | // Contents: | |
16 | // | |
17 | // ppdcFile::ppdcFile() - Create (open) a file. | |
18 | // ppdcFile::~ppdcFile() - Delete (close) a file. | |
19 | // ppdcFile::get() - Get a character from a file. | |
20 | // ppdcFile::peek() - Look at the next character from a file. | |
21 | // | |
22 | ||
23 | // | |
24 | // Include necessary headers... | |
25 | // | |
26 | ||
56569b06 | 27 | #include "ppdc-private.h" |
4bc98872 | 28 | |
29 | ||
30 | // | |
31 | // 'ppdcFile::ppdcFile()' - Create (open) a file. | |
32 | // | |
33 | ||
d1a632e7 | 34 | ppdcFile::ppdcFile(const char *f, // I - File to open |
35 | cups_file_t *ffp) // I - File pointer to use | |
4bc98872 | 36 | { |
d1a632e7 | 37 | if (ffp) |
38 | { | |
39 | fp = ffp; | |
40 | cupsFileRewind(fp); | |
41 | } | |
42 | else | |
43 | fp = cupsFileOpen(f, "r"); | |
44 | ||
4bc98872 | 45 | filename = f; |
46 | line = 1; | |
47 | ||
48 | if (!fp) | |
4c4eea89 | 49 | _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f, |
b4b731f0 | 50 | strerror(errno)); |
4bc98872 | 51 | } |
52 | ||
53 | ||
54 | // | |
55 | // 'ppdcFile::~ppdcFile()' - Delete (close) a file. | |
56 | // | |
57 | ||
58 | ppdcFile::~ppdcFile() | |
59 | { | |
60 | if (fp) | |
61 | cupsFileClose(fp); | |
62 | } | |
63 | ||
64 | ||
65 | // | |
66 | // 'ppdcFile::get()' - Get a character from a file. | |
67 | // | |
68 | ||
69 | int | |
70 | ppdcFile::get() | |
71 | { | |
72 | int ch; // Character from file | |
73 | ||
74 | ||
75 | // Return EOF if there is no open file... | |
76 | if (!fp) | |
77 | return (EOF); | |
78 | ||
79 | // Get the character... | |
80 | ch = cupsFileGetChar(fp); | |
81 | ||
82 | // Update the line number as needed... | |
83 | if (ch == '\n') | |
84 | line ++; | |
85 | ||
86 | // Return the character... | |
87 | return (ch); | |
88 | } | |
89 | ||
90 | ||
91 | // | |
92 | // 'ppdcFile::peek()' - Look at the next character from a file. | |
93 | // | |
94 | ||
95 | int // O - Next character in file | |
96 | ppdcFile::peek() | |
97 | { | |
98 | // Return immediaely if there is no open file... | |
99 | if (!fp) | |
100 | return (EOF); | |
101 | ||
102 | // Otherwise return the next character without advancing... | |
103 | return (cupsFilePeekChar(fp)); | |
104 | } | |
105 | ||
106 | ||
107 | // | |
108 | // End of "$Id$". | |
109 | // |