Fixed length records: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 505: | Line 505: | ||
text2block("block.txt", "block2.dat") |
text2block("block.txt", "block2.dat") |
||
}</lang> |
}</lang> |
||
=={{header|M2000 Interpreter}}== |
|||
Form Buffer object (hold a memory block) we can read a byte at offset. So Print Eval(Line80,3) return the 4th byte, and Return Line80, 2:=255,5:=0 set two bytes (unsigned, we place any number and interpreter convert it to byte). |
|||
<lang M2000 Interpreter> |
|||
Module FixedFile { |
|||
Read fixed$ |
|||
OldLocale=Locale |
|||
\\ chr$(string_argument$) |
|||
\\ use Locale to convert from Ansi to Utf-16LE |
|||
\\ Read Ansi form files also use Locale |
|||
Locale 1032 |
|||
Try ok { |
|||
\\ Make the file first |
|||
Const Center=2 |
|||
Font "Courier New" |
|||
Bold 0 |
|||
Italic 0 |
|||
Def long m, z=1, f |
|||
Def text2read$,test3write$ |
|||
Form 100, 50 ' 100 by 60 characters |
|||
Document txt$={Line 1...1.........2.........3.........4.........5.........6.........7.........8 |
|||
Line 2 |
|||
Line 3 |
|||
Line 4 |
|||
Line 6 |
|||
Line 7 |
|||
Indented line 8............................................................ |
|||
Line 9 RT MARGIN |
|||
} |
|||
\\ use Help Open in M2000 console for details |
|||
\\ Method one |
|||
Report Center, "Make file" |
|||
\\ for WIDE Random \\ for Utf-16 |
|||
Open fixed$ for Random Exclusive as #f len=80 |
|||
m=Paragraph(txt$, 0) |
|||
z=1 |
|||
If forward(txt$, m) then |
|||
while m, z<10 |
|||
text2write$=Paragraph$(txt$,(m)) |
|||
Print format$("Len:{0}, Data: {1}",Len(text2write$),text2write$) |
|||
Put #f, text2write$ , z |
|||
\\ record number from 1 |
|||
\\ if number is total records plus one |
|||
\\ we append a record |
|||
z++ |
|||
End while |
|||
End If |
|||
Print "Press any key" |
|||
Push Key$ : Drop |
|||
Form 80, 40 |
|||
Report Center, "Method1" |
|||
For z=1 to 9 |
|||
Get #f, text2read$, z |
|||
text2read$=StrRev$(text2read$) |
|||
Put #f, text2read$, z |
|||
Print text2read$ |
|||
Next z |
|||
Close #f |
|||
Report Center, "Method2" |
|||
\\ Method2 |
|||
\\ Buffer Clear Line80 ... \\ to clear memory |
|||
\\ here we write all bytes so not needed |
|||
Buffer Line80 as byte*80 |
|||
m=filelen(fixed$) |
|||
If m mod 80=0 Then |
|||
m=1 |
|||
\\ now Get/Put read write at byte position |
|||
\\ we have to use seek to move to byte position |
|||
\\ This way used for Binary files |
|||
Open fixed$ for Input as #f1 |
|||
Open fixed$ for Append as #f2 |
|||
while not eof(#f1) |
|||
seek #f1, m |
|||
Rem Print seek(#f) |
|||
Get #f1, Line80 |
|||
Return line80,0:=Str$(StrRev$(Chr$(Eval$(line80,0,80)))) |
|||
seek #f2, m |
|||
Put #f2, Line80 |
|||
seek #f1, m |
|||
Get #f1, Line80 |
|||
Print Chr$(Eval$(line80,0,80)) |
|||
m+=80 |
|||
End While |
|||
Close #f1 |
|||
Close #f2 |
|||
End if |
|||
} |
|||
\\ use Close with no parameters for close all files if something happen |
|||
If error then Close: Print Error$ |
|||
Locale OldLocale |
|||
} |
|||
FixedFile "fixed.random" |
|||
</lang> |
|||
=={{header|Neko}}== |
=={{header|Neko}}== |
||
<lang ActionScript>/** |
<lang ActionScript>/** |