-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs-util.adb
156 lines (131 loc) · 5.16 KB
/
fs-util.adb
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
-------------------------------------------------------------------------
-- --
-- RTEMS FILE-SYSTEM SUPPORT --
-- --
-- F S . F S --
-- --
-- B o d y --
-- --
-- $ Revision: 1.0 $ --
-- --
-- Alejandro Villanueva Uribarri (Universidad de Zaragoza) --
-- --
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-- --
-------------------------------------------------------------------------
with fs.fs;
use fs.fs;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
package body fs.util is
procedure Get_BCD (The_File: in out File_Handler;
Sector: in out DWord;
The_Byte: in Byte;
Where: in out Integer;
The_Block: out Data_Block;
The_Number: out Natural;
Found: out Boolean) is
At_EOF: Natural;
Final: Natural;
S: DWord := Sector;
From: Natural := Where + 1;
Zero: constant Natural := 48; -- '0'
begin
The_Number := 0;
Found := False;
Main_Loop:
loop
The_File.Read_Sector (The_Block, At_EOF, S);
if At_EOF = 512 then
Final := 511;
else
Final := At_EOF;
end if;
for I in From .. Final loop
if The_Block (I) = The_Byte then
Sector := S;
Where := I;
Found := True;
exit Main_Loop;
else
The_Number := 10 * The_Number +
Integer (The_Block (I)) - Zero;
end if;
end loop;
S := S + 1;
From := 0;
exit when Final = At_EOF;
end loop Main_Loop;
end Get_BCD;
procedure Get_String (The_File: in out File_Handler;
Sector: in out DWord;
The_Byte: in Byte;
Where: in out Integer;
The_Block: out Data_Block;
The_String: out Unbounded_String;
Found: out Boolean) is
At_EOF: Natural;
Final: Natural;
S: DWord := Sector;
From: Natural := Where + 1;
begin
The_String := To_Unbounded_String ("");
Found := False;
Main_Loop:
loop
The_File.Read_Sector (The_Block, At_EOF, S);
if At_EOF = 512 then
Final := 511;
else
Final := At_EOF;
end if;
for I in From .. Final loop
if The_Block (I) = The_Byte then
Sector := S;
Where := I;
Found := True;
exit Main_Loop;
else
Append (The_String, Character'Val (The_Block (I)));
end if;
end loop;
S := S + 1;
From := 0;
exit when Final = At_EOF;
end loop Main_Loop;
end Get_String;
procedure Find_Byte (The_File: in out File_Handler;
Sector: in out DWord;
The_Byte: in Byte;
Where: in out Integer;
The_Block: out Data_Block;
Found: out Boolean) is
At_EOF: Natural;
Final: Natural;
S: DWord := Sector;
From: Natural := Where + 1;
begin
Found := False;
Main_Loop:
loop
The_File.Read_Sector (The_Block, At_EOF, S);
if At_EOF = 512 then
Final := 511;
else
Final := At_EOF;
end if;
for I in From .. Final loop
if The_Block (I) = The_Byte then
Sector := S;
Where := I;
Found := True;
exit Main_Loop;
end if;
end loop;
S := S + 1;
From := 0;
exit when Final = At_EOF;
end loop Main_Loop;
end Find_Byte;
end fs.util;