-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_io.src
182 lines (155 loc) · 2.62 KB
/
file_io.src
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# file_io.src
# Module for performing various i/o operations on a single file
# $Id: file_io.src,v 1.3 2000/10/26 11:36:52 rswindell Exp $
# @format.tab-size 8, @format.use-tabs true
!include file_io.inc
# Variables
int file
int len
int pos
int time
int int
str buf
str name
# Get filename to open
print "\r\nFilename: "
getstr
copy name str
fopen file O_RDWR|O_CREAT|O_DENYNONE str
if_false
printf "Failed to open %s\r\n" name
return
end_if
cmd_home
fget_length file len
fget_pos file pos
crlf
printf "Filename=%s\r\n" name
fget_time file time
time_str str time
printf "Buf=%s\r\nInt=%ld Pos=%ld Len=%ld Time=%s\r\n" buf int pos len str
feof file
if_true
print "At EOF\r\n"
end_if
crlf
print "[R] Read buf [W] Write buf\r\n"
print "[G] Get int [P] Put int\r\n"
print "[S] Seek [B] Rewind\r\n"
print "[L] Lock [U] Unlock\r\n"
print "[F] Fprintf [C] Change len\r\n"
print "[D] Change date [Z] End of file\r\n"
print "[E] ETX Char\r\n"
crlf
print "Which or [Q]uit: "
getkey
printkey
crlf
cmdkey Q
print "Close: "
fclose file
call success
cmdpop
return
end_cmd
cmdkey S
print "Seek to: "
getstr
copy pos str
fset_pos file pos
call success
end_cmd
cmdkey B
print "Rewinding...\r\n"
fset_pos file 0
call success
end_cmd
cmdkey Z
print "Seeking to End of File...\r\n"
fset_pos file 0 SEEK_END
call success
end_cmd
cmdkey R
print "Length to read: "
getstr
copy len str
fread file buf len
call success
end_cmd
cmdkey G
print "Length to read: "
getstr
copy len str
fread file int len
call success
end_cmd
cmdkey P
print "Length to write: "
getstr
copy len str
print "Int: "
getstr
copy int str
fwrite file int len
call success
end_cmd
cmdkey W
print "Length to write: "
getstr
copy len str
print "String: "
getstr
fwrite file str len
call success
end_cmd
cmdkey F
print "String: "
getstr
fprintf file "%s" str
call success
end_cmd
cmdkey L
print "Length to lock: "
getstr
copy len str
flock file len
call success
end_cmd
cmdkey U
print "Length to unlock: "
getstr
copy len str
funlock file len
call success
end_cmd
cmdkey C
print "New length of file: "
getstr
copy len str
fset_length file len
call success
end_cmd
cmdkey E
yes_no "Use ETX (3) instead of NULL (0) for terminating text"
if_true
fset_etx 3
else
fset_etx 0
end_if
end_cmd
cmdkey D
print "New file date (MM/DD/YY): "
getstr
date_int time str
fset_time file time
call success
end_cmd
end_cmd
# Print "Successful" or "Unsuccessful" based on the current logic state
:success
if_true
print "Successful\r\n"
else
print "Unsuccessful\r\n"
end_if
return