Last active
February 10, 2021 17:14
-
-
Save ryohji/2138a7e11ec66556769450a1bbc1d2f3 to your computer and use it in GitHub Desktop.
umoria roff
This file contains 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
static vtype roffbuf; // Line buffer. | |
static char *roffp = roffbuf; // Pointer into line buffer. | |
static int roffpline = 0; // Place to print line now being loaded. | |
static uint8_t count_previous_non_blank_chars(const char *from); | |
// Print out strings, filling up lines as we go. | |
static void roff(const char *p) { | |
uint8_t count; | |
loop: | |
switch (*p) { | |
case '\0': | |
return; | |
case '\n': | |
p += 1; | |
count = 0; | |
goto flush; | |
default: | |
if (roffp + 1 == END_OF(roffbuf)) { | |
*roffp = *p++; | |
count = count_previous_non_blank_chars(roffp); | |
flush: | |
roffp[-count] = '\0'; | |
prt(roffbuf, roffpline, 0); | |
roffpline += 1; | |
memcpy(roffbuf, roffp - count + 1, count); | |
roffp = roffbuf + count; | |
} else { | |
*roffp++ = *p++; | |
} | |
goto loop; | |
} | |
} | |
inline static uint8_t count_previous_non_blank_chars(const char *from) { | |
uint8_t offset = 0; | |
while (from[-offset] != ' ') { | |
offset += 1; | |
} | |
return offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment