]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-file.cxx
Merge CUPS 1.4svn-r7319.
[thirdparty/cups.git] / ppdc / ppdc-file.cxx
1 //
2 // "$Id$"
3 //
4 // File class for the CUPS PPD Compiler.
5 //
6 // Copyright 2007 by Apple Inc.
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"
28
29
30 //
31 // 'ppdcFile::ppdcFile()' - Create (open) a file.
32 //
33
34 ppdcFile::ppdcFile(const char *f) // I - File to open
35 {
36 fp = cupsFileOpen(f, "r");
37 filename = f;
38 line = 1;
39
40 if (!fp)
41 fprintf(stderr, "ppdc: Unable to open %s: %s\n", f, strerror(errno));
42 }
43
44
45 //
46 // 'ppdcFile::~ppdcFile()' - Delete (close) a file.
47 //
48
49 ppdcFile::~ppdcFile()
50 {
51 if (fp)
52 cupsFileClose(fp);
53 }
54
55
56 //
57 // 'ppdcFile::get()' - Get a character from a file.
58 //
59
60 int
61 ppdcFile::get()
62 {
63 int ch; // Character from file
64
65
66 // Return EOF if there is no open file...
67 if (!fp)
68 return (EOF);
69
70 // Get the character...
71 ch = cupsFileGetChar(fp);
72
73 // Update the line number as needed...
74 if (ch == '\n')
75 line ++;
76
77 // Return the character...
78 return (ch);
79 }
80
81
82 //
83 // 'ppdcFile::peek()' - Look at the next character from a file.
84 //
85
86 int // O - Next character in file
87 ppdcFile::peek()
88 {
89 // Return immediaely if there is no open file...
90 if (!fp)
91 return (EOF);
92
93 // Otherwise return the next character without advancing...
94 return (cupsFilePeekChar(fp));
95 }
96
97
98 //
99 // End of "$Id$".
100 //