Blame ppdc/ppdc-file.cxx

Packit 2fc92b
//
Packit 2fc92b
// File class for the CUPS PPD Compiler.
Packit 2fc92b
//
Packit 2fc92b
// Copyright 2007-2010 by Apple Inc.
Packit 2fc92b
// Copyright 2002-2005 by Easy Software Products.
Packit 2fc92b
//
Packit 2fc92b
// These coded instructions, statements, and computer programs are the
Packit 2fc92b
// property of Apple Inc. and are protected by Federal copyright
Packit 2fc92b
// law.  Distribution and use rights are outlined in the file "LICENSE.txt"
Packit 2fc92b
// which should have been included with this file.  If this file is
Packit 2fc92b
// missing or damaged, see the license at "http://www.cups.org/".
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
//
Packit 2fc92b
// Include necessary headers...
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
#include "ppdc-private.h"
Packit 2fc92b
Packit 2fc92b
Packit 2fc92b
//
Packit 2fc92b
// 'ppdcFile::ppdcFile()' - Create (open) a file.
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
ppdcFile::ppdcFile(const char  *f,		// I - File to open
Packit 2fc92b
                   cups_file_t *ffp)		// I - File pointer to use
Packit 2fc92b
{
Packit 2fc92b
  if (ffp)
Packit 2fc92b
  {
Packit 2fc92b
    fp = ffp;
Packit 2fc92b
    cupsFileRewind(fp);
Packit 2fc92b
  }
Packit 2fc92b
  else
Packit 2fc92b
    fp = cupsFileOpen(f, "r");
Packit 2fc92b
Packit 2fc92b
  close_on_delete = !ffp;
Packit 2fc92b
  filename        = f;
Packit 2fc92b
  line            = 1;
Packit 2fc92b
Packit 2fc92b
  if (!fp)
Packit 2fc92b
    _cupsLangPrintf(stderr, _("ppdc: Unable to open %s: %s"), f,
Packit 2fc92b
                    strerror(errno));
Packit 2fc92b
}
Packit 2fc92b
Packit 2fc92b
Packit 2fc92b
//
Packit 2fc92b
// 'ppdcFile::~ppdcFile()' - Delete (close) a file.
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
ppdcFile::~ppdcFile()
Packit 2fc92b
{
Packit 2fc92b
  if (close_on_delete && fp)
Packit 2fc92b
    cupsFileClose(fp);
Packit 2fc92b
}
Packit 2fc92b
Packit 2fc92b
Packit 2fc92b
//
Packit 2fc92b
// 'ppdcFile::get()' - Get a character from a file.
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
int
Packit 2fc92b
ppdcFile::get()
Packit 2fc92b
{
Packit 2fc92b
  int	ch;					// Character from file
Packit 2fc92b
Packit 2fc92b
Packit 2fc92b
  // Return EOF if there is no open file...
Packit 2fc92b
  if (!fp)
Packit 2fc92b
    return (EOF);
Packit 2fc92b
Packit 2fc92b
  // Get the character...
Packit 2fc92b
  ch = cupsFileGetChar(fp);
Packit 2fc92b
Packit 2fc92b
  // Update the line number as needed...
Packit 2fc92b
  if (ch == '\n')
Packit 2fc92b
    line ++;
Packit 2fc92b
Packit 2fc92b
  // Return the character...
Packit 2fc92b
  return (ch);
Packit 2fc92b
}
Packit 2fc92b
Packit 2fc92b
Packit 2fc92b
//
Packit 2fc92b
// 'ppdcFile::peek()' - Look at the next character from a file.
Packit 2fc92b
//
Packit 2fc92b
Packit 2fc92b
int					// O - Next character in file
Packit 2fc92b
ppdcFile::peek()
Packit 2fc92b
{
Packit 2fc92b
  // Return immediaely if there is no open file...
Packit 2fc92b
  if (!fp)
Packit 2fc92b
    return (EOF);
Packit 2fc92b
Packit 2fc92b
  // Otherwise return the next character without advancing...
Packit 2fc92b
  return (cupsFilePeekChar(fp));
Packit 2fc92b
}