File: testsuite_fileio_include.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (88 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download | duplicates (2)
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
# testsuite_fileio_include section for BASIC256

# Modification History
# date		programmer	description
# 20140103	j.m.reneau	split from main testsuite

currentsuite = "fileio"

# regular file io

b$ = "testsuite_file.txt"
print "new file - 0 to 255 on random length lines"
fileno = 3
open fileno,b$
reset fileno
for t = 0 to 255
   r = rand
   if r<.20 then
      writeline fileno, string(t)
   else
      if r<.40 then
         write fileno, string(t) + chr(9)
      else
         write fileno, string(t) + " "
      end if
   end if
next t
close fileno
# read tokens from file
open b$
a = 0
while not eof
   t$ = read
   a += int(t$)
end while
call n("read data sum", a, 32640)
close
# read lines from file and explode
open b$
a = 0
while not eof
   t$ = readline
   c$ = explodex(t$,"\t| ")
   for t = 0 to c$[?]-1
      if instrx(c$[t],"^[0123456789]+") then
         a += int(c$[t])
      endif
   next t
end while
call n("readline data sum", a, 32640)
close
kill b$
# test freefile
for t = 0 to 7
   call n("freefile", freefile, t)
   open freefile,"testsuite_"+t+".txt"
next t
for t = 0 to 7
   close t
   kill "testsuite_"+t+".txt"
next t
call n("freefile", freefile, 0)

# binary file io

b$ = "testsuite_binary.dat"
print "new file"
openb b$
reset
for t = 0 to 255
   writebyte t
next t
close
openb b$
a = 0
while not eof
   a+= readbyte()
end while
call n("bindata sum", a, 32640)
print "position to 10 and read"
seek 10
a=0
while not eof
   a+= readbyte()
end while
call n("bindata sum from 10", a, 32595)
close
kill b$