]>
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 | // |
503b54c9 MS |
7 | // These coded instructions, statements, and computer programs are the |
8 | // property of Apple Inc. and are protected by Federal copyright | |
9 | // law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
10 | // which should have been included with this file. If this file is | |
11 | // file is missing or damaged, see the license at "http://www.cups.org/". | |
ac884b6a MS |
12 | // |
13 | ||
14 | // | |
15 | // Include necessary headers... | |
16 | // | |
17 | ||
38e73f87 | 18 | #include "ppdc-private.h" |
ac884b6a MS |
19 | |
20 | ||
21 | // | |
22 | // 'ppdcFile::ppdcFile()' - Create (open) a file. | |
23 | // | |
24 | ||
4509bb49 MS |
25 | ppdcFile::ppdcFile(const char *f, // I - File to open |
26 | cups_file_t *ffp) // I - File pointer to use | |
ac884b6a | 27 | { |
4509bb49 MS |
28 | if (ffp) |
29 | { | |
30 | fp = ffp; | |
31 | cupsFileRewind(fp); | |
32 | } | |
33 | else | |
34 | fp = cupsFileOpen(f, "r"); | |
35 | ||
82cc1f9a MS |
36 | close_on_delete = !ffp; |
37 | filename = f; | |
38 | line = 1; | |
ac884b6a MS |
39 | |
40 | if (!fp) | |
0837b7e8 | 41 | _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f, |
61cf44e2 | 42 | strerror(errno)); |
ac884b6a MS |
43 | } |
44 | ||
45 | ||
46 | // | |
47 | // 'ppdcFile::~ppdcFile()' - Delete (close) a file. | |
48 | // | |
49 | ||
50 | ppdcFile::~ppdcFile() | |
51 | { | |
82cc1f9a | 52 | if (close_on_delete && fp) |
ac884b6a MS |
53 | cupsFileClose(fp); |
54 | } | |
55 | ||
56 | ||
57 | // | |
58 | // 'ppdcFile::get()' - Get a character from a file. | |
59 | // | |
60 | ||
61 | int | |
62 | ppdcFile::get() | |
63 | { | |
64 | int ch; // Character from file | |
65 | ||
66 | ||
67 | // Return EOF if there is no open file... | |
68 | if (!fp) | |
69 | return (EOF); | |
70 | ||
71 | // Get the character... | |
72 | ch = cupsFileGetChar(fp); | |
73 | ||
74 | // Update the line number as needed... | |
75 | if (ch == '\n') | |
76 | line ++; | |
77 | ||
78 | // Return the character... | |
79 | return (ch); | |
80 | } | |
81 | ||
82 | ||
83 | // | |
84 | // 'ppdcFile::peek()' - Look at the next character from a file. | |
85 | // | |
86 | ||
87 | int // O - Next character in file | |
88 | ppdcFile::peek() | |
89 | { | |
90 | // Return immediaely if there is no open file... | |
91 | if (!fp) | |
92 | return (EOF); | |
93 | ||
94 | // Otherwise return the next character without advancing... | |
95 | return (cupsFilePeekChar(fp)); | |
96 | } |