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
Read()14 int 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
PPDFile(const char * file,PPDFile * previousFile)26 PPDFile::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
~PPDFile()36 PPDFile::~PPDFile()
37 {
38 // nothing to do
39 }
40
InitCheck()41 status_t PPDFile::InitCheck()
42 {
43 return fFile.InitCheck();
44 }
45
GetCurrentChar()46 int PPDFile::GetCurrentChar()
47 {
48 return fCurrentChar;
49 }
50
NextChar()51 void 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
GetPosition()66 Position PPDFile::GetPosition()
67 {
68 return fCurrentPosition;
69 }
70
GetPreviousFile()71 PPDFile* PPDFile::GetPreviousFile()
72 {
73 return fPreviousFile;
74 }
75
GetFileName()76 const char* PPDFile::GetFileName()
77 {
78 return fFileName.String();
79 }
80