diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-07-29 20:07:13 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-07-29 20:07:13 -0700 |
commit | b625c6304eca827c04eda719fa6f7927294b80bc (patch) | |
tree | ec6e3f97bf2fc66e6d17f1c9768570bf2b0b9e55 /511image.mu | |
parent | e55d3f5814d0f243d9d6a51f05433c14f0939055 (diff) | |
download | mu-b625c6304eca827c04eda719fa6f7927294b80bc.tar.gz |
support non-line-oriented processing in next-word
Immediately this simplifies support for comments in image data.
Diffstat (limited to '511image.mu')
-rw-r--r-- | 511image.mu | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/511image.mu b/511image.mu index 94787d66..7d4127f4 100644 --- a/511image.mu +++ b/511image.mu @@ -18,7 +18,7 @@ fn initialize-image _self: (addr image), in: (addr stream byte) { var self/esi: (addr image) <- copy _self var mode-storage: slice var mode/ecx: (addr slice) <- address mode-storage - next-word in, mode + next-word-skipping-comments in, mode { var P1?/eax: boolean <- slice-equal? mode, "P1" compare P1?, 0/false @@ -90,10 +90,10 @@ fn initialize-image-from-pbm _self: (addr image), in: (addr stream byte) { var curr-word-storage: slice var curr-word/ecx: (addr slice) <- address curr-word-storage # load width, height - next-word in, curr-word + next-word-skipping-comments in, curr-word var tmp/eax: int <- parse-decimal-int-from-slice curr-word var width/edx: int <- copy tmp - next-word in, curr-word + next-word-skipping-comments in, curr-word tmp <- parse-decimal-int-from-slice curr-word var height/ebx: int <- copy tmp # save width, height @@ -112,7 +112,7 @@ fn initialize-image-from-pbm _self: (addr image), in: (addr stream byte) { { compare i, capacity break-if->= - next-word in, curr-word + next-word-skipping-comments in, curr-word var src/eax: int <- parse-decimal-int-from-slice curr-word { var dest/ecx: (addr byte) <- index data, i @@ -202,14 +202,14 @@ fn initialize-image-from-pgm _self: (addr image), in: (addr stream byte) { var curr-word-storage: slice var curr-word/ecx: (addr slice) <- address curr-word-storage # load width, height - next-word in, curr-word + next-word-skipping-comments in, curr-word var tmp/eax: int <- parse-decimal-int-from-slice curr-word var width/edx: int <- copy tmp - next-word in, curr-word + next-word-skipping-comments in, curr-word tmp <- parse-decimal-int-from-slice curr-word var height/ebx: int <- copy tmp # check and save color levels - next-word in, curr-word + next-word-skipping-comments in, curr-word { tmp <- parse-decimal-int-from-slice curr-word compare tmp, 0xff @@ -234,7 +234,7 @@ fn initialize-image-from-pgm _self: (addr image), in: (addr stream byte) { { compare i, capacity break-if->= - next-word in, curr-word + next-word-skipping-comments in, curr-word var src/eax: int <- parse-decimal-int-from-slice curr-word { var dest/ecx: (addr byte) <- index data, i @@ -688,13 +688,13 @@ fn initialize-image-from-ppm _self: (addr image), in: (addr stream byte) { var curr-word-storage: slice var curr-word/ecx: (addr slice) <- address curr-word-storage # load width, height - next-word in, curr-word + next-word-skipping-comments in, curr-word var tmp/eax: int <- parse-decimal-int-from-slice curr-word var width/edx: int <- copy tmp - next-word in, curr-word + next-word-skipping-comments in, curr-word tmp <- parse-decimal-int-from-slice curr-word var height/ebx: int <- copy tmp - next-word in, curr-word + next-word-skipping-comments in, curr-word # check color levels { tmp <- parse-decimal-int-from-slice curr-word @@ -725,7 +725,7 @@ fn initialize-image-from-ppm _self: (addr image), in: (addr stream byte) { { compare i, capacity break-if->= - next-word in, curr-word + next-word-skipping-comments in, curr-word var src/eax: int <- parse-decimal-int-from-slice curr-word { var dest/ecx: (addr byte) <- index data, i @@ -1111,3 +1111,10 @@ fn scale-image-height _img: (addr image), width: int -> _/ebx: int { var result/ebx: int <- convert result-f return result } + +fn next-word-skipping-comments line: (addr stream byte), out: (addr slice) { + next-word line, out + var retry?/eax: boolean <- slice-starts-with? out, "#" + compare retry?, 0/false + loop-if-!= +} |