diff options
| author | fig02 <fig02srl@gmail.com> | 2021-03-12 15:51:39 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-12 15:51:39 -0500 |
| commit | 55718b1090083e1f5e9b1b1cc09ebcb329baa74f (patch) | |
| tree | ae890ccd6bfeded507518d227a0002f8fc136bcf /ZAPD/OutputFormatter.cpp | |
| parent | 1e67767cf988af08e79d8cea4ee1e4d47658fe29 (diff) | |
Use libgfxd (gfxdis) for display lists (#84)
* start
* dlists work
* progress
* vtx works
* texture wip
* debugging
* palletes sorta working
* pal issue sort of fixed
* progress
* fiix
* switching to master
* progress
* OK
* fixes
* whitespace
* libgfxd update
* prep for merge
* use new seg2filespace function
* vtx
Diffstat (limited to 'ZAPD/OutputFormatter.cpp')
| -rw-r--r-- | ZAPD/OutputFormatter.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/ZAPD/OutputFormatter.cpp b/ZAPD/OutputFormatter.cpp new file mode 100644 index 0000000..5e7c35c --- /dev/null +++ b/ZAPD/OutputFormatter.cpp @@ -0,0 +1,103 @@ +#include "OutputFormatter.h" + +int OutputFormatter::write(const char *buf, int count) +{ + for (int i = 0; i < count; i++) + { + char c = buf[i]; + + if (c == '\n') + { + col = 0; + current_indent = nest_indent[nest]; + } + else if (c == '\t') + { + int n = tab_size - (col % tab_size); + for (int j = 0; j < n - 1; j++) + *space_p++ = ' '; + c = ' '; + col += n; + } + else + { + col++; + } + + if (c == '(') + { + nest++; + nest_indent[nest] = col; + current_indent = col; + } + else if (c == ')') + { + nest--; + } + + if (c == ' ' || c == '\t' || c == '\n') + { + str.append(word, word_p - word); + word_p = word; + + *space_p++ = c; + } + else + { + if (col > line_limit) + { + str.append(1, '\n'); + str.append(current_indent, ' '); + col = current_indent + 1 + (word_p - word); + } + else + { + str.append(space, space_p - space); + } + space_p = space; + + *word_p++ = c; + } + } + + return count; +} + +OutputFormatter* OutputFormatter::static_instance; + +int OutputFormatter::write_static(const char *buf, int count) +{ + return static_instance->write(buf, count); +} + +int (*OutputFormatter::static_writer())(const char *buf, int count) +{ + static_instance = this; + return &write_static; +} + +OutputFormatter::OutputFormatter(int tab_size , int default_indent, + int line_limit) + : + tab_size{tab_size}, + default_indent{default_indent}, + line_limit{line_limit}, + col{0}, + nest{0}, + nest_indent{default_indent}, + current_indent{default_indent}, + word_p{word}, + space_p{space} +{ +} + +std::string OutputFormatter::get_output() +{ + str.append(space, space_p - space); + space_p = space; + + str.append(word, word_p - word); + word_p = word; + + return std::move(str); +} |
