• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
8 //
9 
10 //
11 // Include necessary headers...
12 //
13 
14 #include "ppdc-private.h"
15 
16 
17 //
18 // 'ppdcFile::ppdcFile()' - Create (open) a file.
19 //
20 
ppdcFile(const char * f,cups_file_t * ffp)21 ppdcFile::ppdcFile(const char  *f,		// I - File to open
22                    cups_file_t *ffp)		// I - File pointer to use
23 {
24   if (ffp)
25   {
26     fp = ffp;
27     cupsFileRewind(fp);
28   }
29   else
30     fp = cupsFileOpen(f, "r");
31 
32   close_on_delete = !ffp;
33   filename        = f;
34   line            = 1;
35 
36   if (!fp)
37     _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f,
38                     strerror(errno));
39 }
40 
41 
42 //
43 // 'ppdcFile::~ppdcFile()' - Delete (close) a file.
44 //
45 
~ppdcFile()46 ppdcFile::~ppdcFile()
47 {
48   if (close_on_delete && fp)
49     cupsFileClose(fp);
50 }
51 
52 
53 //
54 // 'ppdcFile::get()' - Get a character from a file.
55 //
56 
57 int
get()58 ppdcFile::get()
59 {
60   int	ch;					// Character from file
61 
62 
63   // Return EOF if there is no open file...
64   if (!fp)
65     return (EOF);
66 
67   // Get the character...
68   ch = cupsFileGetChar(fp);
69 
70   // Update the line number as needed...
71   if (ch == '\n')
72     line ++;
73 
74   // Return the character...
75   return (ch);
76 }
77 
78 
79 //
80 // 'ppdcFile::peek()' - Look at the next character from a file.
81 //
82 
83 int					// O - Next character in file
peek()84 ppdcFile::peek()
85 {
86   // Return immediaely if there is no open file...
87   if (!fp)
88     return (EOF);
89 
90   // Otherwise return the next character without advancing...
91   return (cupsFilePeekChar(fp));
92 }
93