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