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