]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdc-file.cxx
Merge changes from CUPS 1.4svn-r7715.
[thirdparty/cups.git] / ppdc / ppdc-file.cxx
CommitLineData
ac884b6a
MS
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
4509bb49
MS
34ppdcFile::ppdcFile(const char *f, // I - File to open
35 cups_file_t *ffp) // I - File pointer to use
ac884b6a 36{
4509bb49
MS
37 if (ffp)
38 {
39 fp = ffp;
40 cupsFileRewind(fp);
41 }
42 else
43 fp = cupsFileOpen(f, "r");
44
ac884b6a
MS
45 filename = f;
46 line = 1;
47
48 if (!fp)
49 fprintf(stderr, "ppdc: Unable to open %s: %s\n", f, strerror(errno));
50}
51
52
53//
54// 'ppdcFile::~ppdcFile()' - Delete (close) a file.
55//
56
57ppdcFile::~ppdcFile()
58{
59 if (fp)
60 cupsFileClose(fp);
61}
62
63
64//
65// 'ppdcFile::get()' - Get a character from a file.
66//
67
68int
69ppdcFile::get()
70{
71 int ch; // Character from file
72
73
74 // Return EOF if there is no open file...
75 if (!fp)
76 return (EOF);
77
78 // Get the character...
79 ch = cupsFileGetChar(fp);
80
81 // Update the line number as needed...
82 if (ch == '\n')
83 line ++;
84
85 // Return the character...
86 return (ch);
87}
88
89
90//
91// 'ppdcFile::peek()' - Look at the next character from a file.
92//
93
94int // O - Next character in file
95ppdcFile::peek()
96{
97 // Return immediaely if there is no open file...
98 if (!fp)
99 return (EOF);
100
101 // Otherwise return the next character without advancing...
102 return (cupsFilePeekChar(fp));
103}
104
105
106//
107// End of "$Id$".
108//