1/* 2 * Copyright 2008, Haiku. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Michael Pfeiffer <laplace@users.sourceforge.net> 7 */ 8 9#include "CharacterClasses.h" 10#include "Scanner.h" 11 12#include <stdio.h> 13 14int FileBuffer::Read() 15{ 16 if (fIndex >= fSize) { 17 fSize = fFile->Read(fBuffer, kReadBufferSize); 18 fIndex = 0; 19 } 20 if (fSize <= 0) { 21 return -1; 22 } 23 return (int)fBuffer[fIndex ++]; 24} 25 26PPDFile::PPDFile(const char* file, PPDFile* previousFile) 27 : fFileName(file) 28 , fFile(file, B_READ_ONLY) 29 , fPreviousFile(previousFile) 30 , fCurrentPosition(0, 1) 31 , fCurrentChar(-1) 32 , fBuffer(&fFile) 33{ 34} 35 36PPDFile::~PPDFile() 37{ 38 // nothing to do 39} 40 41status_t PPDFile::InitCheck() 42{ 43 return fFile.InitCheck(); 44} 45 46int PPDFile::GetCurrentChar() 47{ 48 return fCurrentChar; 49} 50 51void PPDFile::NextChar() { 52 fCurrentChar = fBuffer.Read(); 53 if (fCurrentChar != -1) { 54#if TRACE_SCANNER 55 fprintf(stderr, "%c ", fCurrentChar); 56#endif 57 if (fCurrentChar == kCr) { 58 fCurrentPosition.x = 0; 59 fCurrentPosition.y ++; 60 } else { 61 fCurrentPosition.x ++; 62 } 63 } 64} 65 66Position PPDFile::GetPosition() 67{ 68 return fCurrentPosition; 69} 70 71PPDFile* PPDFile::GetPreviousFile() 72{ 73 return fPreviousFile; 74} 75 76const char* PPDFile::GetFileName() 77{ 78 return fFileName.String(); 79} 80