Debian Codegraph @

contrib/toacme/src/prof.c

raw symbols SCIP
1 // ToACME - converts other source codes to ACME format.
2 // Copyright (C) 1999-2019 Marco Baye
3 // Have a look at "main.c" for further info
4 //
5 // "Professional Ass by Oliver Stiller" stuff (NOT "Profi-Ass" by Data Becker!)
6 // Kickoff:
7 // http://www.forum64.de/wbb4/index.php?thread/60047-toacme-demn%C3%A4chst-als-win32-release/
8
9 #include <stdio.h>
10 //#include "config.h"
11 //#include "acme.h"
12 //#include "mnemo.h"
13 #include "io.h"
14 #include "scr2iso.h"
15
16 // format of input files:
17 // load address, lo
18 // load address, hi
19 // for each line:
20 // total line length, including this byte
21 // amount of indentation
22 // actual line as screen code (this part might be missing in case of empty line)
23 // total line length, including this byte (yes, the same value again, for upscrolling)
24 // that's it!
25
26 // special directives:
27 // '.' is for pseudo opcodes?
28 // .setpc is *=
29 // .fill (length, data) ?
30 // .b is !by, .w is !wo, .macro reads a macro argument?
31 // .goto is used to skip macro definitions?!
32 // what do .begin and .end do? local label scope?
33 // .print str$(*-$1060) wow... O_o
34 // '-' prefix means local label definition?
35 // '+' prefix means global label definition?
36 // '_' starts a macro definition? ".endmacro" ends definition?
37 // '*' prefix is a macro call?
38
39 #define TABSIZE 8 // anything else is heresy
40 #define REV_START ";-=#"
41 #define REV_END "#=-"
42
43 enum linestate {
44 LINESTATE_REMOVEPLUS, // before label def
45 LINESTATE_DOUBLENEXTSPACE, // entered when removing '+'
46 LINESTATE_NOTHINGSPECIAL // afterward
47 };
48
49 // main
50 void prof_main(void)
51 {
52 int length1,
53 indent,
54 ii,
55 byte,
56 hibit,
57 length2;
58 enum linestate linestate;
59
60 IO_set_input_padding(0);
61 IO_process_load_address();
62 for (;;) {
63 length1 = IO_get_byte();
64 if (length1 == EOF)
65 break;
66 if (length1 < 3) {
67 fprintf(stderr, "Error: Short line (%d bytes), stopping.\n", length1);
68 return;
69 }
70 // read amount of indentation and output tabs/spaces
71 indent = IO_get_byte();
72 if (indent < 0) {
73 fprintf(stderr, "Error: Negative indentation (%d)\n", indent);
74 } else {
75 for (ii = 0; ii + TABSIZE <= indent; ii += TABSIZE)
76 IO_put_byte('\t');
77 for (; ii < indent; ii++)
78 IO_put_byte(' ');
79 }
80 // now convert line
81 hibit = 0;
82 linestate = LINESTATE_REMOVEPLUS;
83 for (ii = 0; ii < length1 - 3; ii++) {
84 byte = IO_get_byte();
85 if ((byte & 128) != hibit) {
86 hibit = byte & 128;
87 IO_put_string(hibit ? REV_START : REV_END);
88 }
89 byte = SCR2ISO(byte & 127);
90 // outside of comments, remove leading '+'
91 if (hibit == 0) {
92 if (byte == '+') {
93 if (linestate == LINESTATE_REMOVEPLUS) {
94 linestate = LINESTATE_DOUBLENEXTSPACE;
95 continue; // eat '+'
96 }
97 } else if (byte == ' ') {
98 if (linestate == LINESTATE_DOUBLENEXTSPACE) {
99 linestate = LINESTATE_NOTHINGSPECIAL;
100 IO_put_byte(' '); // add space to compensate for eaten '+'
101 }
102 } else {
103 // any other char -> do not remove any '+'
104 if (linestate == LINESTATE_REMOVEPLUS) {
105 linestate = LINESTATE_NOTHINGSPECIAL;
106 }
107 }
108 }
109 IO_put_byte(byte);
110 }
111 if (hibit)
112 IO_put_string(REV_END);
113 // and add newline
114 IO_put_byte('\n');
115 // now check second length byte
116 length2 = IO_get_byte();
117 if (length1 != length2)
118 fprintf(stderr, "Error: Length bytes differ (%d != %d)\n", length1, length2);
119 }
120 }