| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
| 2 |
"http://www.w3.org/TR/html4/strict.dtd">
|
| 3 |
<html>
|
| 4 |
<head>
|
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
| 6 |
<title>fileread</title>
|
| 7 |
<meta http-equiv="Content-Style-Type" content="text/css">
|
| 8 |
<link rel="stylesheet" href="../../style.css" type="text/css">
|
| 9 |
</head>
|
| 10 |
|
| 11 |
<body>
|
| 12 |
|
| 13 |
|
| 14 |
<h1>fileread</h1>
|
| 15 |
|
| 16 |
<p>
|
| 17 |
Reads a file.
|
| 18 |
</p>
|
| 19 |
|
| 20 |
<pre class="macro-syntax">
|
| 21 |
fileread <file handle> <read byte> <strvar>
|
| 22 |
</pre>
|
| 23 |
|
| 24 |
<h2>Remarks</h2>
|
| 25 |
|
| 26 |
<p>
|
| 27 |
Reads specified byte data from the file specified by <file handle>.<br>
|
| 28 |
The data are written into the string variable <strvar>. The file pointer is moved to reading bytes. <br>
|
| 29 |
If the file pointer reaches the end of the file while reading the data, the system variable "result" is set to 1. Otherwise, "result" is set to zero.<br>
|
| 30 |
The range of <read byte> argument must be from 1 to 511.<br>
|
| 31 |
Also, a null character('\0) is added at the end of the string variable <strvar>.
|
| 32 |
</p>
|
| 33 |
|
| 34 |
<h2>Example</h2>
|
| 35 |
|
| 36 |
<pre class="macro-example">
|
| 37 |
filename = 'foo.txt'
|
| 38 |
|
| 39 |
fileopen fp filename 0
|
| 40 |
|
| 41 |
:loop
|
| 42 |
<strong>fileread</strong> fp 10 data
|
| 43 |
messagebox data filename
|
| 44 |
if result goto fclose
|
| 45 |
goto loop
|
| 46 |
|
| 47 |
:fclose
|
| 48 |
fileclose fp
|
| 49 |
</pre>
|
| 50 |
|
| 51 |
<pre class="macro-example">
|
| 52 |
; Send 32 bytes from a binary file.
|
| 53 |
filename = 'sample.bin'
|
| 54 |
|
| 55 |
fileopen fhandle filename 0
|
| 56 |
if fhandle == -1 goto the_end
|
| 57 |
|
| 58 |
call send_16_bytes ; send first 16 bytes
|
| 59 |
fileseek fhandle 16 1 ; seek past next 16 without sending
|
| 60 |
call send_16_bytes ; send next (last) 16 bytes
|
| 61 |
fileclose fhandle
|
| 62 |
goto the_end
|
| 63 |
|
| 64 |
;#########################################
|
| 65 |
:send_16_bytes
|
| 66 |
for i 1 16
|
| 67 |
fileread fhandle 1 str ; read one byte at a time so we can detect zero.
|
| 68 |
if result == 1 break
|
| 69 |
str2code integer str ; if zero then str will be empty and integer will be set to zero
|
| 70 |
;sprintf 'integer = 0x%02X' integer
|
| 71 |
;messagebox inputstr 'test'
|
| 72 |
send integer
|
| 73 |
next
|
| 74 |
return
|
| 75 |
;#########################################
|
| 76 |
:the_end
|
| 77 |
</pre>
|
| 78 |
|
| 79 |
|
| 80 |
<h2>Reference</h2>
|
| 81 |
|
| 82 |
<a href="fileopen.html">fileopen</a><br>
|
| 83 |
<a href="fileclose.html">fileclose</a><br>
|
| 84 |
|
| 85 |
</body>
|
| 86 |
</html>
|