| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include "io.h" |
| 14 |
#include "scr2iso.h" |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#define TABSIZE 8 // anything else is heresy |
| 40 |
#define REV_START ";-=#" |
| 41 |
#define REV_END "#=-" |
| 42 |
|
| 43 |
enum linestate { |
| 44 |
LINESTATE_REMOVEPLUS, |
| 45 |
LINESTATE_DOUBLENEXTSPACE, |
| 46 |
LINESTATE_NOTHINGSPECIAL |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 91 |
if (hibit == 0) { |
| 92 |
if (byte == '+') { |
| 93 |
if (linestate == LINESTATE_REMOVEPLUS) { |
| 94 |
linestate = LINESTATE_DOUBLENEXTSPACE; |
| 95 |
continue; |
| 96 |
} |
| 97 |
} else if (byte == ' ') { |
| 98 |
if (linestate == LINESTATE_DOUBLENEXTSPACE) { |
| 99 |
linestate = LINESTATE_NOTHINGSPECIAL; |
| 100 |
IO_put_byte(' '); |
| 101 |
} |
| 102 |
} else { |
| 103 |
|
| 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 |
|
| 114 |
IO_put_byte('\n'); |
| 115 |
|
| 116 |
length2 = IO_get_byte(); |
| 117 |
if (length1 != length2) |
| 118 |
fprintf(stderr, "Error: Length bytes differ (%d != %d)\n", length1, length2); |
| 119 |
} |
| 120 |
} |