int spc_exec_special (const char *buffer, int32_t size, double x_user, double y_user, double mag) { int error = -1; int i, found; struct spc_env spe; struct spc_arg args; struct spc_handler special; if (verbose > 3) { dump(buffer, buffer + size); } init_special(&special, &spe, &args, buffer, size, x_user, y_user, mag); for (i = 0; known_specials[i].key != NULL; i++) { found = known_specials[i].check_func(buffer, size); if (found) { error = known_specials[i].setup_func(&special, &spe, &args); if (!error) { error = special.exec(&spe, &args); } if (error) { print_error(known_specials[i].key, &spe, &args); } break; } } check_garbage(&args); return error; }
/** * Given a program struct, will process the (already opened) input file and * begin compilation line by line. */ void process_input_program(struct program *program){ print_asterisk(GRN_C, stdout); printf("Processing File...\n"); char *tok; char buf[MAX_LINE_LEN+1]; buf[MAX_LINE_LEN] = 0; // parse input file do{ program->line_count++; #ifdef DEBUG fprintf(stderr, "*** Reading Line %d...\n", program->line_count); #endif fgetpos(program->in, &program->str_line); tok = read_next_token(buf, program->in, MAX_LINE_LEN); #ifdef DEBUG fprintf(stderr, "Read Token '%s'\n", tok); #endif if(!tok){ continue; // just a whitespace line, move on } else{ process_token(tok, program); } // the instruction processor should have consumed all relevant tokens, // check if there is garbage at the end of the line if(!program->error_code) check_garbage(program); }while(!check_EOF(program->in) && !program->error_code); if(program->error_code) return; // resolve constants/labels #ifdef DEBUG fprintf(stderr, "LAST TERM: '%s' TRANS: %d\n", program->end_term->term, program->end_term->trans); #endif translate_terms(program->terms, program); // write terms to out file struct Term *t = program->terms; write_terms(t, program); // process warnings if(warnings){ check_warnings(program); } #ifdef DEBUG // why did we quit? if(program->error_code){ fprintf(stderr, "Stopped processing because of an error.\n"); } else if(check_EOF(program->in)){ fprintf(stderr, "Stopped processing because EOF reached.\n"); } #endif }