14420c1ceSMichael Pfeiffer/*
24420c1ceSMichael Pfeiffer * Copyright 2008, Haiku.
34420c1ceSMichael Pfeiffer * Distributed under the terms of the MIT license.
44420c1ceSMichael Pfeiffer *
54420c1ceSMichael Pfeiffer * Authors:
64420c1ceSMichael Pfeiffer *		Michael Pfeiffer <laplace@users.sourceforge.net>
74420c1ceSMichael Pfeiffer */
84420c1ceSMichael Pfeiffer
94420c1ceSMichael Pfeiffer#include "CharacterClasses.h"
104420c1ceSMichael Pfeiffer#include "Scanner.h"
114420c1ceSMichael Pfeiffer
124420c1ceSMichael Pfeiffer#include <stdio.h>
134420c1ceSMichael Pfeiffer
144420c1ceSMichael Pfeifferint FileBuffer::Read()
154420c1ceSMichael Pfeiffer{
164420c1ceSMichael Pfeiffer	if (fIndex >= fSize) {
174420c1ceSMichael Pfeiffer		fSize = fFile->Read(fBuffer, kReadBufferSize);
184420c1ceSMichael Pfeiffer		fIndex = 0;
194420c1ceSMichael Pfeiffer	}
204420c1ceSMichael Pfeiffer	if (fSize <= 0) {
214420c1ceSMichael Pfeiffer		return -1;
224420c1ceSMichael Pfeiffer	}
234420c1ceSMichael Pfeiffer	return (int)fBuffer[fIndex ++];
244420c1ceSMichael Pfeiffer}
254420c1ceSMichael Pfeiffer
264420c1ceSMichael PfeifferPPDFile::PPDFile(const char* file, PPDFile* previousFile)
274420c1ceSMichael Pfeiffer	: fFileName(file)
284420c1ceSMichael Pfeiffer	, fFile(file, B_READ_ONLY)
294420c1ceSMichael Pfeiffer	, fPreviousFile(previousFile)
304420c1ceSMichael Pfeiffer	, fCurrentPosition(0, 1)
314420c1ceSMichael Pfeiffer	, fCurrentChar(-1)
324420c1ceSMichael Pfeiffer	, fBuffer(&fFile)
334420c1ceSMichael Pfeiffer{
344420c1ceSMichael Pfeiffer}
354420c1ceSMichael Pfeiffer
364420c1ceSMichael PfeifferPPDFile::~PPDFile()
374420c1ceSMichael Pfeiffer{
384420c1ceSMichael Pfeiffer	// nothing to do
394420c1ceSMichael Pfeiffer}
404420c1ceSMichael Pfeiffer
414420c1ceSMichael Pfeifferstatus_t PPDFile::InitCheck()
424420c1ceSMichael Pfeiffer{
434420c1ceSMichael Pfeiffer	return fFile.InitCheck();
444420c1ceSMichael Pfeiffer}
454420c1ceSMichael Pfeiffer
464420c1ceSMichael Pfeifferint PPDFile::GetCurrentChar()
474420c1ceSMichael Pfeiffer{
484420c1ceSMichael Pfeiffer	return fCurrentChar;
494420c1ceSMichael Pfeiffer}
504420c1ceSMichael Pfeiffer
514420c1ceSMichael Pfeiffervoid PPDFile::NextChar() {
524420c1ceSMichael Pfeiffer	fCurrentChar = fBuffer.Read();
534420c1ceSMichael Pfeiffer	if (fCurrentChar != -1) {
544420c1ceSMichael Pfeiffer#if TRACE_SCANNER
554420c1ceSMichael Pfeiffer		fprintf(stderr, "%c ", fCurrentChar);
564420c1ceSMichael Pfeiffer#endif
574420c1ceSMichael Pfeiffer		if (fCurrentChar == kCr) {
584420c1ceSMichael Pfeiffer			fCurrentPosition.x = 0;
594420c1ceSMichael Pfeiffer			fCurrentPosition.y ++;
604420c1ceSMichael Pfeiffer		} else {
614420c1ceSMichael Pfeiffer			fCurrentPosition.x ++;
624420c1ceSMichael Pfeiffer		}
634420c1ceSMichael Pfeiffer	}
644420c1ceSMichael Pfeiffer}
654420c1ceSMichael Pfeiffer
664420c1ceSMichael PfeifferPosition PPDFile::GetPosition()
674420c1ceSMichael Pfeiffer{
684420c1ceSMichael Pfeiffer	return fCurrentPosition;
694420c1ceSMichael Pfeiffer}
704420c1ceSMichael Pfeiffer
714420c1ceSMichael PfeifferPPDFile* PPDFile::GetPreviousFile()
724420c1ceSMichael Pfeiffer{
734420c1ceSMichael Pfeiffer	return fPreviousFile;
744420c1ceSMichael Pfeiffer}
754420c1ceSMichael Pfeiffer
764420c1ceSMichael Pfeifferconst char* PPDFile::GetFileName()
774420c1ceSMichael Pfeiffer{
784420c1ceSMichael Pfeiffer	return fFileName.String();
794420c1ceSMichael Pfeiffer}
80