24 FILE *input = fopen(path,
"rt");
30 if (fseek(input, 0, 2)==-1) {
34 int data_size = (
int)ftell(input);
43 buffer = (
char *)malloc(data_size+1);
44 data_size = fread(buffer, 1, data_size, input);
45 buffer[data_size] = 0;
53 inline int max(
int i,
int j) {
return i<j ? j : i; }
59 for (
int i = 0; i<count; ++i) len[i] = strlen(queue[i]);
62 int max_mark_pos = -1;
64 for (
int i = 0; i<count; ++i) {
65 char *
line = queue[i];
67 mark_pos[i] = mark ? mark-line : -1;
68 max_mark_pos =
max(max_mark_pos, mark_pos[i]);
70 if (max_mark_pos == -1)
break;
72 for (
int i = 0; i<count; ++i) {
73 if (mark_pos[i] >= 0) {
74 int insert = max_mark_pos-mark_pos[i];
77 int new_len = len[i]+insert;
78 char *new_line = (
char*)malloc(new_len+1);
80 memcpy(new_line, queue[i], mark_pos[i]);
81 memset(new_line+mark_pos[i],
' ', insert);
82 strcpy(new_line+max_mark_pos, queue[i]+mark_pos[i]+1);
85 freeset(queue[i], new_line);
90 offset = max_mark_pos;
93 for (
int i = 0; i<count; ++i) {
134 if (!queue.empty()) {
137 for (PrintQueue::iterator i = queue.begin(); i != queue.end(); ++i) {
155 print_error(&started_at,
"PMSTART without matching PMEND");
167 void Output::setup() {
173 have_open_loc =
false;
175 void Output::cleanup() {
180 maybe->not_destroyed_error();
211 if (maybe) maybe->will_print();
213 int res = formatter.write(line);
226 for (
int i = 0; i < 256; i++) {
230 outtab[(
unsigned char)
'n'] =
'\n';
231 outtab[(
unsigned char)
't'] =
'\t';
233 outtab[(
unsigned char)
'0'] = 0;
234 outtab[(
unsigned char)
'1'] = 0;
235 outtab[(
unsigned char)
'2'] = 0;
236 outtab[(
unsigned char)
'3'] = 0;
237 outtab[(
unsigned char)
'4'] = 0;
238 outtab[(
unsigned char)
'5'] = 0;
239 outtab[(
unsigned char)
'6'] = 0;
240 outtab[(
unsigned char)
'7'] = 0;
241 outtab[(
unsigned char)
'8'] = 0;
242 outtab[(
unsigned char)
'9'] = 0;
243 outtab[(
unsigned char)
'\\'] = 0;
251 while ((c = *(p++))) {
257 if (!outtab[(
unsigned)(c)]) {
261 else if (isdigit(c)) {
262 int pos = tabs[c -
'0'];
268 c = outtab[(unsigned)(c)];
272 int pos = ((
column/tabstop)+1)*tabstop;
275 else if (c ==
'\n') {
284 if (strncmp(p,
"SETSOURCE", 9) == 0) {
306 bool Interpreter::set_data(
const char *dataBlock,
int offset_in_line) {
319 for (
int i=0; i<argc; i++) {
320 write_var(
formatted(
"argv[%i]", i), argv[i]);
322 write_var(
"argc",
formatted(
"%i", argc));
334 fputs(
"Nothing to execute\n", stderr);
337 if (compile_program()) {
338 fprintf(stderr,
"Compilation of '%s' failed\n", argv[1]);
345 fputs(
"AISC reports errors\n", stderr);
359 int main(
int argc,
char ** argv) {
363 fprintf(stderr,
"AISC - ARB integrated source compiler\n");
364 fprintf(stderr,
"Usage: aisc [fileToCompile]+\n");
365 fprintf(stderr,
"Error: missing file name\n");
371 catch (
const char *err) {
372 fprintf(stderr,
"\nAISC: exception: %s [terminating]\n", err);
376 fprintf(stderr,
"\nAISC: unknown exception [terminating]\n");
static void pop(PrintMaybe *&head)
PrintMaybe(PrintMaybe *head, Output &out_, const Location &loc)
int write(const char *line)
char * read_aisc_file(const char *path, const Location *loc)
int main(int argc, char **argv)
static const Interpreter * instance
const char * formatted(const char *format,...)
char buffer[MESSAGE_BUFFERSIZE]
static int get_error_count()
void alignInto(LineQueue &dest)
#define print_error(code_or_loc, err)
void add(const char *line)
void set_tokens(TokenListBlock *newRoot)
void not_destroyed_error()
list< queued_line > PrintQueue
class Code * parse_program(const char *in, const char *filename)
fputs(TRACE_PREFIX, stderr)
int maybe_write(const char *line)
TokenListBlock * parseTokenListBlock(const char *&in)
void set_source(const Location &other)
#define printf_error(code_or_loc, format, arg)
void set_line_start(const char *start, int offset_in_line)
queued_line(const char *line_, int indent)
int launch(int argc, char **argv)
Formatter & get_formatter()
const TokenListBlock * get_tokens() const
#define aisc_assert(cond)
static const char ALIGN_MARKER