3
#include "yacasprivate.h"
6
// For lack of better place to put it...
7
InputStatus::~InputStatus()
12
StdFileInput::StdFileInput(FILE* aFile,InputStatus& aStatus)
17
StdFileInput::StdFileInput(LispLocalFile& aFile,InputStatus& aStatus)
25
LispChar StdFileInput::Next()
34
LispChar StdFileInput::Peek()
36
LispChar c = fgetc(iFile);
41
void StdFileInput::Rewind()
43
fseek(iFile,0,SEEK_SET);
46
LispBoolean StdFileInput::EndOfStream()
51
LispCharPtr StdFileInput::StartPtr()
56
LispInt StdFileInput::Position()
64
StdFileOutput::StdFileOutput(FILE* aFile) : iFile(aFile) { }
65
StdFileOutput::StdFileOutput(LispLocalFile& aFile) : iFile(aFile.iFile) { }
68
void StdFileOutput::PutChar(LispChar aChar)
79
CachedStdFileInput::~CachedStdFileInput()
84
CachedStdFileInput::CachedStdFileInput(LispLocalFile& aFile,InputStatus& aStatus) : StdFileInput(aFile,aStatus)
87
fseek(iFile,0,SEEK_END);
88
iNrBytes = ftell(iFile);
89
fseek(iFile,0,SEEK_SET);
90
// Read in the full buffer
91
iBuffer = PlatAlloc(iNrBytes+1);
92
Check(iBuffer!=NULL,KLispErrNotEnoughMemory);
94
fread(iBuffer,iNrBytes,1,iFile);
95
iBuffer[iNrBytes] = '\0';
98
LispChar CachedStdFileInput::Next()
101
LISPASSERT(iCurrentPos < iNrBytes);
102
c = iBuffer[iCurrentPos++];
111
LispChar CachedStdFileInput::Peek()
113
LISPASSERT(iCurrentPos < iNrBytes);
114
return iBuffer[iCurrentPos];
118
void CachedStdFileInput::Rewind()
123
LispBoolean CachedStdFileInput::EndOfStream()
125
return (iCurrentPos >= iNrBytes);
128
LispCharPtr CachedStdFileInput::StartPtr()
132
LispInt CachedStdFileInput::Position()
138
void InternalFindFile(LispCharPtr aFileName, InputDirectories& aInputDirectories,
139
LispCharPtr aFoundFile)
141
strcpy(aFoundFile,aFileName);
142
FILE* file = fopen(aFileName,"rb");
144
while (file == NULL && i<aInputDirectories.NrItems())
146
strcpy(aFoundFile,aInputDirectories[i]->String());
147
strcat(aFoundFile,aFileName);
148
file = fopen(aFoundFile,"rb");
157
aFoundFile[0] = '\0';
161
LispLocalFile::LispLocalFile(LispEnvironment& aEnvironment,
162
LispCharPtr aFileName, LispBoolean aRead,
163
InputDirectories& aInputDirectories)
164
: iEnvironment(aEnvironment)
168
LispChar othername[1024];//TODO
169
strcpy(othername,aFileName);
170
iFile = fopen(aFileName,"rb");
172
while (iFile == NULL && i<aInputDirectories.NrItems())
174
strcpy(othername,aInputDirectories[i]->String());
175
strcat(othername,aFileName);
176
iFile = fopen(othername,"rb");
181
iFile = fopen(aFileName,"w");
188
SAFEPUSH(iEnvironment,*this);
191
//aRead is for opening in read mode (otherwise opened in write mode)
192
LispLocalFile::~LispLocalFile()
194
SAFEPOP(iEnvironment);
198
void LispLocalFile::Delete()
208
CachedStdUserInput::CachedStdUserInput(InputStatus& aStatus) :
209
StdUserInput(aStatus)
211
//printf("CachedStdUserInput:construct\n");
214
LispChar CachedStdUserInput::Next()
216
//printf("CachedStdUserInput:Next\n");
223
LispChar CachedStdUserInput::Peek()
225
if (iCurrentPos == iBuffer.NrItems())
227
iBuffer.Append(fgetc(iFile));
229
return iBuffer[iCurrentPos];
232
LispBoolean CachedStdUserInput::EndOfStream()
237
void CachedStdUserInput::Rewind()
239
// Make sure there is a buffer to point to.
241
iBuffer.SetNrItems(0);
245
LispCharPtr CachedStdUserInput::StartPtr()
247
if (iBuffer.NrItems() == 0)
252
LispInt CachedStdUserInput::Position()