diff options
Diffstat (limited to 'apps/browse')
-rw-r--r-- | apps/browse/file-state.mu | 45 | ||||
-rw-r--r-- | apps/browse/main.mu | 28 |
2 files changed, 15 insertions, 58 deletions
diff --git a/apps/browse/file-state.mu b/apps/browse/file-state.mu deleted file mode 100644 index d42bf8bf..00000000 --- a/apps/browse/file-state.mu +++ /dev/null @@ -1,45 +0,0 @@ -type file-state { - source: (handle buffered-file) - eof?: boolean -} - -fn init-file-state _self: (addr file-state), filename: (addr array byte) { - var self/eax: (addr file-state) <- copy _self - load-file self, filename - var eof/eax: (addr boolean) <- get self, eof? - copy-to *eof, 0 # false -} - -fn load-file _self: (addr file-state), filename: (addr array byte) { - var self/eax: (addr file-state) <- copy _self - var out/esi: (addr handle buffered-file) <- get self, source - open filename, 0, out # 0 = read mode -} - -fn next-char _self: (addr file-state) -> result/eax: byte { - var self/ecx: (addr file-state) <- copy _self - var source/eax: (addr handle buffered-file) <- get self, source - var in/eax: (addr buffered-file) <- lookup *source - result <- read-byte-buffered in - # if result == EOF, set eof? - compare result, 0xffffffff # EOF marker - { - var eof/ecx: (addr boolean) <- get self, eof? - copy-to *eof, 1 # true - } -} - -fn done-reading? _self: (addr file-state) -> result/eax: boolean { - var self/eax: (addr file-state) <- copy _self - var eof/eax: (addr boolean) <- get self, eof? - result <- copy *eof -} - -fn dump in: (addr buffered-file) { - var c/eax: byte <- read-byte-buffered in - compare c, 0xffffffff # EOF marker - break-if-= - var g/eax: grapheme <- copy c - print-grapheme 0, g - loop -} diff --git a/apps/browse/main.mu b/apps/browse/main.mu index 1a1eb09d..d710c1a6 100644 --- a/apps/browse/main.mu +++ b/apps/browse/main.mu @@ -1,9 +1,11 @@ fn main args: (addr array addr array byte) -> exit-status/ebx: int { # initialize fs from args[1] var filename/eax: (addr array byte) <- first-arg args - var file-state-storage: file-state - var fs/esi: (addr file-state) <- address file-state-storage - init-file-state fs, filename + var file-storage: (handle buffered-file) + var file-storage-addr/esi: (addr handle buffered-file) <- address file-storage + open filename, 0, file-storage-addr + var _fs/eax: (addr buffered-file) <- lookup file-storage + var fs/esi: (addr buffered-file) <- copy _fs # enable-screen-grid-mode enable-keyboard-immediate-mode @@ -23,12 +25,12 @@ fn main args: (addr array addr array byte) -> exit-status/ebx: int { exit-status <- copy 0 } -fn render screen: (addr screen), fs: (addr file-state), state: (addr screen-position-state) { +fn render screen: (addr screen), fs: (addr buffered-file), state: (addr screen-position-state) { start-drawing state render-normal screen, fs, state } -fn render-normal screen: (addr screen), fs: (addr file-state), state: (addr screen-position-state) { +fn render-normal screen: (addr screen), fs: (addr buffered-file), state: (addr screen-position-state) { var newline-seen?/esi: boolean <- copy 0 # false var start-of-paragraph?/edi: boolean <- copy 1 # true var previous-char/ebx: byte <- copy 0 @@ -37,7 +39,7 @@ $render-normal:loop: { var done?/eax: boolean <- done-drawing? state compare done?, 0 # false break-if-!= - var c/eax: byte <- next-char fs + var c/eax: byte <- read-byte-buffered fs $render-normal:loop-body: { # if (c == EOF) break compare c, 0xffffffff # EOF marker @@ -138,7 +140,7 @@ $render-normal:whitespace-separated-regions: { } # $render-normal:loop } -fn render-header-line screen: (addr screen), fs: (addr file-state), state: (addr screen-position-state) { +fn render-header-line screen: (addr screen), fs: (addr buffered-file), state: (addr screen-position-state) { $render-header-line:body: { # compute color based on number of '#'s var header-level/esi: int <- copy 1 # caller already grabbed one @@ -151,7 +153,7 @@ $render-header-line:body: { break-if-!= $render-header-line:body } # - c <- next-char fs + c <- read-byte-buffered fs # if (c != '#') break compare c, 0x23 # '#' break-if-!= @@ -169,7 +171,7 @@ $render-header-line:body: { break-if-!= } # - c <- next-char fs + c <- read-byte-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= @@ -217,14 +219,14 @@ $start-heading:body: { } } -fn render-until-asterisk fs: (addr file-state), state: (addr screen-position-state) { +fn render-until-asterisk fs: (addr buffered-file), state: (addr screen-position-state) { { # if done-drawing?(state) break var done?/eax: boolean <- done-drawing? state compare done?, 0 # false break-if-!= # - var c/eax: byte <- next-char fs + var c/eax: byte <- read-byte-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= @@ -238,14 +240,14 @@ fn render-until-asterisk fs: (addr file-state), state: (addr screen-position-sta } } -fn render-until-underscore fs: (addr file-state), state: (addr screen-position-state) { +fn render-until-underscore fs: (addr buffered-file), state: (addr screen-position-state) { { # if done-drawing?(state) break var done?/eax: boolean <- done-drawing? state compare done?, 0 # false break-if-!= # - var c/eax: byte <- next-char fs + var c/eax: byte <- read-byte-buffered fs # if (c == EOF) break compare c, 0xffffffff # EOF marker break-if-= |