]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc-file.cxx
4bbe86dd338913d859fb7ad27ef709e00b879362
[thirdparty/cups.git] / ppdc / ppdc-file.cxx
1 //
2 // File class for the CUPS PPD Compiler.
3 //
4 // Copyright 2007-2010 by Apple Inc.
5 // Copyright 2002-2005 by Easy Software Products.
6 //
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/".
12 //
13
14 //
15 // Include necessary headers...
16 //
17
18 #include "ppdc-private.h"
19
20
21 //
22 // 'ppdcFile::ppdcFile()' - Create (open) a file.
23 //
24
25 ppdcFile::ppdcFile(const char *f, // I - File to open
26 cups_file_t *ffp) // I - File pointer to use
27 {
28 if (ffp)
29 {
30 fp = ffp;
31 cupsFileRewind(fp);
32 }
33 else
34 fp = cupsFileOpen(f, "r");
35
36 close_on_delete = !ffp;
37 filename = f;
38 line = 1;
39
40 if (!fp)
41 _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f,
42 strerror(errno));
43 }
44
45
46 //
47 // 'ppdcFile::~ppdcFile()' - Delete (close) a file.
48 //
49
50 ppdcFile::~ppdcFile()
51 {
52 if (close_on_delete && fp)
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 }