Debian Codegraph @

contrib/toacme/src/gighyp.c

raw symbols SCIP
1 // ToACME - converts other source codes to ACME format.
2 // Copyright (C) 1999-2025 Marco Baye
3 // Have a look at "main.c" for further info
4 //
5 // stuff needed for both "Hypra-Ass" and "Giga-Ass"
6
7 #include "acme.h"
8 #include "gighyp.h"
9 #include "io.h"
10 #include "pet2iso.h"
11 #include <string.h> // for strcmp()
12
13
14 // called with GotByte == ';'
15 void GigaHypra_comment(void)
16 {
17 // check whether anything follows (empty comments => empty lines)
18 if (IO_get_byte()) {
19 IO_put_byte(';');
20 do
21 IO_put_byte(PET2ISO(GotByte));
22 while (IO_get_byte());
23 }
24 }
25
26
27 // process operator
28 void GigaHypra_operator(void) // '!' was last read
29 {
30 char middle = PET2ISO(IO_get_byte());
31
32 if ((middle != ';') && (middle != '\0')) {
33 if (IO_get_byte() == '!') {
34 switch (middle) {
35 case 'n':
36 IO_put_byte('!');
37 break;
38 case 'o':
39 IO_put_byte('|');
40 break;
41 case 'a':
42 IO_put_byte('&');
43 break;
44 case '=':
45 IO_put_byte('=');
46 break;
47 case '<':
48 IO_put_string(" < ");
49 break;
50 case '>':
51 IO_put_string(" > ");
52 break;
53 default:
54 IO_put_byte('!');
55 IO_put_byte(middle);
56 IO_put_byte('!');
57 }
58 IO_get_byte();
59 } else {
60 IO_put_byte('!');
61 IO_put_byte(middle);
62 }
63 } else {
64 IO_put_byte('!');
65 }
66 // exit with unused byte pre-read
67 }
68
69
70 // output one or two TABs
71 void GigaHypra_indent(int indent)
72 {
73 if (indent < 8)
74 IO_put_byte('\t');
75 IO_put_byte('\t');
76 }
77
78
79 // Process opcode and arguments
80 void GigaHypra_argument_with_instructs(struct Instructs instructs, int indent)
81 {
82 int paren = 0; // number of open parentheses (to close)
83 int flags = instructs.flags;
84 bool ignore_after_comma = FALSE;
85
86 // if needed, add separating space between opcode and argument
87 if ((flags & FLAG_INSERT_SPACE) && (GotByte != SPACE)
88 && (GotByte != ';') && (GotByte != '\0'))
89 IO_put_byte(SPACE);
90 // character loop
91 while ((GotByte != ';') && (GotByte != '\0')) {
92 if ((GotByte == ',') && (flags & FLAG_TASK_WITH_COMMA)) {
93 if (strcmp(instructs.txtOpcode, ACME_po_pet) == 0) {
94 // repeat last pseudo-opcode
95 IO_put_byte('\n');
96 GigaHypra_indent(indent);
97 IO_put_string(ACME_po_pet);
98 IO_put_byte(' ');
99 IO_get_byte();
100 } else {
101 ignore_after_comma = TRUE;
102 }
103 }
104 if (ignore_after_comma == TRUE) {
105 // ignore everything after comma
106 IO_get_byte();
107 continue;
108 }
109
110 if (GotByte == '!')
111 GigaHypra_operator();
112 if (GotByte == '"') {
113 // don't parse inside quotes
114 IO_put_byte(GotByte);
115 IO_get_byte();
116 while ((GotByte != '\0') && (GotByte != '"')) {
117 if ((GotByte == 0x5f)
118 && (flags & FLAG_CHANGE_LEFTARROW))
119 IO_put_string("\", 13,\"");
120 else
121 IO_put_byte(PET2ISO(GotByte));
122 IO_get_byte();
123 }
124 IO_put_byte('"');
125 if (GotByte == '"') {
126 IO_get_byte();
127 if ((GotByte == '\0')
128 && (flags & FLAG_ADD_ZERO))
129 IO_put_string(", 0");
130 }
131 } else {
132 // most characters go here
133 switch (GotByte) {
134 case '(':
135 if (flags & FLAG_SKIP_OPENING) {
136 flags &= ~FLAG_SKIP_OPENING;
137 flags |= FLAG_SKIP_CLOSING;
138 } else {
139 paren++;
140 IO_put_byte(PET2ISO(GotByte));
141 }
142 break;
143 case ')':
144 if ((flags & FLAG_SKIP_CLOSING) && (paren == 0)) {
145 flags &= ~FLAG_SKIP_CLOSING;
146 } else {
147 paren--;
148 IO_put_byte(PET2ISO(GotByte));
149 }
150 break;
151 case SHIFTSPACE:
152 IO_put_byte(SPACE);
153 break;
154 default:
155 IO_put_byte(PET2ISO(GotByte));
156 }
157 IO_get_byte();
158 }
159 }
160 if (flags & FLAG_ADD_CBM)
161 IO_put_string(ACME_cbmformat);
162 if (flags & FLAG_ADD_LEFT_BRACE)
163 IO_put_byte('{');
164 }
165 // wrapper for fn above
166 void GigaHypra_argument(int flags)
167 {
168 struct Instructs instructs;
169
170 instructs.flags = flags;
171 GigaHypra_argument_with_instructs(instructs, 0);
172 }
173
174
175 // convert and send label name.
176 // returns length (for proper indentation).
177 int GigaHypra_label_definition(void)
178 {
179 int count = 0;
180
181 do {
182 IO_put_byte(PET2ISO(GotByte));
183 count++;
184 IO_get_byte();
185 } while ((GotByte != SPACE) && (GotByte != ';') && (GotByte != '\0'));
186 return count;
187 }