This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0082.pas
More file actions
167 lines (149 loc) · 3.9 KB
/
Copy path0082.pas
File metadata and controls
167 lines (149 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Unit WGTFile; {TextFile Reader for CRLF or LF TEXT FILES!}
{eventually this unit will be a decendant of WGBFILE!}
{$I WGDEFINE.INC} { SEE WGFFIND.PAS for this include }
Interface
Uses
WGBFile,
{$IFDEF WINDOWS}
WinDos;
{$ELSE}
Dos;
{$ENDIF}
Type
TFile = Object
Decendant:FFileObj; {short cut for now!}
StringFound:Boolean;
MyIOResult:Word;
Constructor Init(BSize:Word);
Destructor Done;
Procedure Open(FilePath:String); Virtual;
Procedure CloseFile; Virtual;
{ Function EraseFile; Virtual;}
Function GetString:String; {Get CRLF string from file}
Function GetUString:String; {Get LF delimited string}
Function Found:Boolean; {Was a string found}
Function SeekFile(SeekPos:LongInt):Boolean; {Seek to position}
Function FilePos:LongInt; {Get text file position}
Function RawSize:LongInt; {Get text file position}
End;
Implementation
Constructor TFile.Init(BSize:Word);
Begin
Decendant.Init(BSize);
If Decendant.MyIOResult<>0 then Fail;
MyIOResult:=0;
StringFound:=False;
End;
Destructor TFile.Done;
Begin
If Decendant.IsOpen then Decendant.CloseFile;
Decendant.Done;
StringFound:=False;
End;
Procedure TFile.Open(FilePath:String);
Begin
Decendant.Open(FilePath,fmReadOnly+fmDenyNone);
MyIOResult:=Decendant.MyIOResult;
End;
Procedure TFile.CloseFile;
Begin
Decendant.Closefile;
MyIOResult:=Decendant.MyIOResult;
End;
Function TFile.GetString:String;
Var
TempStr:String;
GDone:Boolean;
Ch:Char;
NRead:Word;
Begin
TempStr:='';
StringFound:=False;
If Decendant.FilePos>=Decendant.RawSize then GDone:=True
Else GDone:=False;
While Not GDone Do Begin
Decendant.BlkRead(Ch,1,NRead);
MyIOResult:=Decendant.MYIOResult;
If (MYIOResult<>0) or (NRead<>1) then Ch:=#0;
Case Ch Of
#0:If Decendant.FilePos>=Decendant.RawSize Then GDone:=True
Else Begin
Inc(TempStr[0]);
TempStr[Ord(TempStr[0])]:=Ch;
StringFound:=True;
If Length(TempStr)=255 Then GDone:=True;
End;
#10:;
#26:;
#13: Begin
GDone:=True;
StringFound:=True;
End;
Else Begin
Inc(TempStr[0]);
TempStr[Ord(TempStr[0])]:=Ch;
StringFound:=True;
If Length(TempStr)=255 Then GDone:=True;
End;
End; {case}
End;
GetString:=TempStr;
End;
Function TFile.GetUString:String;
Var
TempStr:String;
GDone:Boolean;
Ch:Char;
NRead:Word;
Begin
TempStr:='';
StringFound:=False;
If Decendant.FilePos>=Decendant.RawSize then GDone:=True
Else GDone:=False;
While Not GDone Do Begin
Decendant.BlkRead(Ch,1,NRead);
MyIOResult:=Decendant.MYIOResult;
If (MYIOResult<>0) or (NRead<>1) then Ch:=#0;
Case Ch Of
#0:If Decendant.FilePos>=Decendant.RawSize Then GDone:=True
Else Begin
Inc(TempStr[0]);
TempStr[Ord(TempStr[0])]:=Ch;
StringFound:=True;
If Length(TempStr)=255 Then GDone:=True;
End;
#13:;
#26:;
#10:Begin
GDone:=True;
StringFound:=True;
End;
Else Begin
Inc(TempStr[0]);
TempStr[Ord(TempStr[0])]:=Ch;
StringFound:=True;
If Length(TempStr)=255 Then GDone:=True;
End;
End; {case}
End;
GetUString:=TempStr;
End;
Function TFile.Found:Boolean;
Begin
Found:=StringFound;
End;
Function TFile.SeekFile(SeekPos:LongInt):Boolean; {Seek to position}
Begin
Decendant.SeekFile(SeekPos);
MyIOResult:=Decendant.MyIOResult;
End;
Function TFile.FilePos:LongInt; {Get text file position}
Begin
FilePos:=Decendant.FilePos;
End;
Function TFile.RawSize:LongInt; {Get text file position}
Begin
RawSize:=Decendant.RawSize;
End;
End.