faqts : Computers : Programming : Languages : Bbcbasic

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

BBCBASIC: Windows:File:Operation:Get:Can you give a simple program to read all characters from file?

Nov 18th, 2006 02:09
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 21 September 2020 - 10:20 pm ------------------
Idea:
You start from the beginning of the file
and you keep reading characters
until you encounter the end of file marker.
===
BNF
(program in file) is
(zero or one begin marker)
followed by (zero or more characters)
followed by (one end marker)
===
Regular expression
(program in file) = (begin marker)? (character)* (end of file marker)
===
or written in shorthand
P = B? C* E
where
 P = program
 B = begin of program marker
 ? = zero or one
 C = characer
 * = zero or more
 E = end of program marker
===
or written as a BNF diagram
                  +----<----+
                  |         |
 P = ->-+-(B)-+->-+->-(C)->-+->-(E)->-
        |     |   |         |
        +-->--+   +---->----+
===
because there is no begin marker here, you
can reduce this to
 P = C* E
===
or written as a diagram
        +----<----+
        |         |
 P = ->-+->-(C)->-+->-(E)->-
        |         |
        +---->----+
===
or written in pseudo code
 WHILE NOT (E)
  (C)
 ENDWHILE
 (E) 
===
state diagram
'file read all characters' =
                          +---<-----------+
                          |               |
->-[goto begin of file]->-+-[read char]->-+->-[found end file]->-
                          |               |
                          +--->-----------+
===
Steps: Overview:
 1. -E.g. create the following program
--- cut here: begin --------------------------------------------------
 REM --- MAIN --- REM
 PROCFileGetCharacterReadAllSimple( "c:\temp\ddd.ddd" )
 END
 :
 :
 :
 REM --- LIBRARY --- REM
 :
 REM library: file: get: character: read: all: simple [kn, ho, th, 21-
09-2006 22:14:55]
 DEF PROCFileGetCharacterReadAllSimple( fileName$ )
 REM e.g. PROCFileGetCharacterReadAllSimple( "c:\temp\ddd.ddd" )
 REM e.g. END
 REM e.g. :
 REM e.g. :
 REM e.g. :
 LOCAL P%
 REM goto begin of program in file
 P% = OPENIN( fileName$ )
 IF P% = 0 THEN PRINT "file:" + " " + fileName$ + " " + "could not be 
found" : ENDPROC
 REM
 REM no begin marker
 REM
 REM while not found end marker
 WHILE NOT ( EOF #P% ) : REM while not found end marker
  PRINT; BGET# P%; " "; : REM get character and goto next character
 ENDWHILE
 PRINT; BGET# P% : REM get end marker
 CLOSE #P%
 ENDPROC
--- cut here: end ----------------------------------------------------
 2. -Running this program will e.g. output (print) all the characters
     (bytes) of a given file
--- cut here: begin --------------------------------------------------
 33 13 10 34 13 10 35 13 10 36 13 10 37 13 10 38 13 10 39 13 10 40 13
 10 41 13 10 42 13 10 43 13 10 44 13 10 45 13 10 46 13 10 47 13 10 48
 13 10 49 13 10 50 13 10 51 13 10 52 13 10 53 13 10 54 13 10 55 13 10
 56 13 10 57 13 10 58 13 10 59 1 3 10 60 13 10 61 13 10 62 13 10 63 13
 10 64 13 10 65 13 10 66 13 10 67 13 10 68 13 10 69 13 10 70 13 10 71
 13 10 72 13 10 73 13 10 74 13 10 75 13 10 76 13 10 77 13 10 78 13 10
 79 13 10 80 13 10 81 13 10 82 13 10 83 13 10 84 13 10 85 13 10 86 13
 10 87 13 10 88 13 10 89 13 10 90 13 10 91 13 10 92 13 10 93 13 10 94
 13 10 95 13 10 96 13 10 97 13 10 98 13 10 9 9 13 10 100 13 10 101 13
 10 102 13 10 103 13 10 104 13 10 105 13 10 106 13 10 107 13 10 108 13
 10 109 13 10 110 13 10 1 11 13 10 112 13 10 113 13 10 114 13 10 115 13
 10 116 13 10 117 13 10 118 13 10 119 13 10 120 13 10 121 13 10 122 13
 10 123 13 10 124 13 10 125 13 10 126 13 10 127 13 10 128 13 10 129 13
 10 130 13 10 131 13 10 132 13 10 133 13 10 134 13 10 135 13 10 136 13
 10 137 13 10 138 13 10 139 13 10 140 13 10 141 13 10 142 13 10 143 13
 10 144 13 10 145 13 10 146 13 1 0 147 13 10 148 13 10 149 13 10 150 13
 10 151 13 10 152 13 10 153 13 10 154 13 10 155 13 10 156 13 10 157 13
 10 158 13 10 159 13 10 160 13 10 161 13 10 162 13 10 163 13 10 164 13
 10 165 13 10 166 13 10 167 13 10 168 13 10 169 13 10 170 13 10 171 13
 10 172 13 10 173 13 10 174 13 10 175 13 10 176 13 10 177 13 10 178 13
 10 179 13 10 180 13 10 181 13 10 182 1 3 10 183 13 10 184 13 10 185 13
 10 186 13 10 187 13 10 188 13 10 189 13 10 190 13 10 191 13 10 192 13
 10 193 13 10 194 13 10 195 13 10 196 13 10 197 13 10 198 13 10 199 13
 10 200 13 10 201 13 10 202 13 10 203 13 10 204 13 10 205 13 10 206 13
 10 207 13 10 208 13 10 209 13 10 210 13 10 211 13 10 212 13 10 213 13
 10 214 13 10 215 13 10 216 13 10 217 13 10 21 8 13 10 219 13 10 220 13
 10 221 13 10 222 13 10 223 13 10 224 13 10 225 13 10 226 13 10 227 13
 10 228 13 10 229 13 10 2 30 13 10 231 13 10 232 13 10 233 13 10 234 13
 10 235 13 10 236 13 10 237 13 10 238 13 10 239 13 10 240 13 10 241 13
 10 242 13 10 243 13 10 244 13 10 245 13 10 246 13 10 247 13 10 248 13
 10 249 13 10 250 13 10 251 13 10 252 13 10 253 13 10 254 13 10 255 13
 10 62 0
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
----------------------------------------------------------------------