Created
October 29, 2019 11:38
-
-
Save bitmappergit/808823d974192980e3e855fec7caf58c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implement Liner; | |
include "sys.m"; | |
include "draw.m"; | |
include "bufio.m"; | |
sys : Sys; | |
bufio : Bufio; | |
Iobuf : import bufio; | |
Liner : module { | |
init : fn(ctxt : ref Draw->Context, argv : list of string); | |
}; | |
init(nil : ref Draw->Context, argv : list of string) { | |
param := tl argv; | |
while (param != nil) { | |
liner(hd param); | |
param = tl param; | |
} | |
} | |
liner(filename : string) { | |
lines : list of string; | |
temp_line : string; | |
sys = load Sys Sys->PATH; | |
bufio = load Bufio Bufio->PATH; | |
file_buf := bufio->open(filename, sys->ORDWR); | |
while () { | |
temp_line = file_buf.gets('\n'); | |
if (temp_line == "") | |
break; | |
else | |
lines = temp_line::lines; | |
} | |
file_buf.seek(0,0); | |
lines = reorder(lines); | |
i := 1; | |
while (lines != nil) { | |
file_buf.puts(string i + "\t" + hd lines); | |
lines = tl lines; | |
i++; | |
} | |
file_buf.flush(); | |
} | |
reorder(flist : list of string) : list of string { | |
rlist : list of string; | |
while (flist != nil) { | |
rlist = hd flist::rlist; | |
flist = tl flist; | |
} | |
return rlist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment