Anonymous user
Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions
Reverse the order of lines in a text file while preserving the contents of each line (view source)
Revision as of 22:29, 30 November 2021
, 2 years agoAdded solution for Action!
(Reverse the order of lines in a text file while preserving the contents of each line en BASIC256) |
(Added solution for Action!) |
||
Line 21:
Reference: [https://linuxhint.com/bash_tac_command/ Bash tac command]
=={{header|Action!}}==
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/rodgers.txt rodgers.txt] is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
<lang Action!>DEFINE PTR="CARD"
DEFINE BUFFERSIZE="1000"
BYTE ARRAY buffer(BUFFERSIZE)
PTR ARRAY lines(100)
BYTE count=[0]
PROC AddLine(CHAR ARRAY line)
CHAR ARRAY dst
IF count=0 THEN
dst=buffer
ELSE
dst=lines(count-1)
dst==+dst(0)+1
FI
IF dst+line(0)+1>=buffer+BUFFERSIZE THEN
Print("End of memory!")
Break()
FI
SCopy(dst,line)
lines(count)=dst
count==+1
RETURN
PROC ReadFile(CHAR ARRAY fname)
CHAR ARRAY line(255)
BYTE dev=[1]
Close(dev)
Open(dev,fname,4)
WHILE Eof(dev)=0
DO
InputSD(dev,line)
AddLine(line)
OD
Close(dev)
RETURN
PROC Main()
CHAR ARRAY s
BYTE i,LMARGIN=$52,oldLMARGIN
oldLMARGIN=LMARGIN
LMARGIN=0 ;remove left margin on the screen
Put(125) PutE() ;clear the screen
ReadFile("H6:RODGERS.TXT")
FOR i=0 TO count-1
DO
s=lines(count-1-i)
PrintE(s)
OD
LMARGIN=oldLMARGIN ;restore left margin on the screen
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Reverse_the_order_of_lines_in_a_text_file_while_preserving_the_contents_of_each_line.png Screenshot from Atari 8-bit computer]
<pre>
--- Will Rodger
until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
=={{header|Ada}}==
|