void asm_echo(const char *msg, struct atom *atom) { struct vec_iterator i[1]; struct expr **exprp; int count = 0; i32 e[10]; if(atom != NULL) { if(atom->type != ATOM_TYPE_EXPRS || vec_count(atom->u.exprs) > 10) { LOG(LOG_ERROR, ("echo arguments must be a string followed by none " "or at most ten expressions.\n")); exit(1); } vec_get_iterator(atom->u.exprs, i); while((exprp = vec_iterator_next(i)) != NULL) { e[count++] = resolve_expr(*exprp); } } for(; count < 10; ++count) { e[count] = 0; } fprintf(stdout, msg, e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9]); fprintf(stdout, "\n"); }
int settings_test_object_name(settings_t* sttngs, const char* oname) { int rv = 0; for (int i=0; i<vec_count(sttngs->black_list); i++) { if (strcmp(sttngs->black_list[i], oname)==0) { rv = 1; break; } } return rv; }
struct atom *exprs_to_word_exprs(struct atom *atom) { if(atom->type != ATOM_TYPE_EXPRS) { LOG(LOG_ERROR, ("can't convert exprs of type %d to word exprs.\n", atom->type)); exit(1); } atom->type = ATOM_TYPE_WORD_EXPRS; pc_add(vec_count(atom->u.exprs) * 2); return atom; }
struct atom *exprs_to_byte_exprs(struct atom *atom) { if(atom->type != ATOM_TYPE_EXPRS) { LOG(LOG_ERROR, ("can't convert atom of type %d to byte exprs.\n", atom->type)); exit(1); } atom->type = ATOM_TYPE_BYTE_EXPRS; pc_add(vec_count(atom->u.exprs)); return atom; }
void settings_free(settings_t* sttngs) { if (sttngs) { sfree(sttngs->report_html_font_size); for(int i=0; i<vec_count(sttngs->black_list); i++) { free(sttngs->black_list[i]); } vec_free(sttngs->black_list); sfree(sttngs->dir); sfree(sttngs->orb_file); free(sttngs); } }
void settings_dump(settings_t* sttngs) { char* start_str = time2str(sttngs->start, 1); char* end_str = time2str(sttngs->stop, 1); printf("settings dump:\n\tstart: %s\n\tstop: %s\n\tmag:%.2f\n\tRA_min:%.2f\n\tRA_max:%.2f\n\tdecl_min:%.2f\n\tdecl_max:%.2f\n\tra_position_min:%f\n\tra_position_max:%f\n\treport_html_font_size:%s\n\tdir:\"%s\"\n\tBlack list:", start_str, end_str, sttngs->mag_min, sttngs->ra_rate_min, sttngs->ra_rate_max, sttngs->decl_rate_min, sttngs->decl_rate_max, sttngs->ra_position_min, sttngs->ra_position_max, sttngs->report_html_font_size, sttngs->dir); for (int i=0; i<vec_count(sttngs->black_list); i++) { printf(" %s", sttngs->black_list[i]); } printf("\n\tuse_orb_file: %s", sttngs->use_orb_file?"Yes":"No"); if (sttngs->orb_file) { printf("\n\torb_file: %s", sttngs->orb_file); } printf("\n\n"); free(start_str); free(end_str); }
void output_atoms(struct membuf *out, struct vec *atoms) { struct vec_iterator i[1]; struct vec_iterator i2[1]; struct atom **atomp; struct atom *atom; struct expr **exprp; struct expr *expr; struct membuf *in; const char *p; i32 value; i32 value2; dump_sym_table(LOG_DEBUG, s->sym_table); vec_get_iterator(atoms, i); while((atomp = vec_iterator_next(i)) != NULL) { atom = *atomp; LOG(LOG_DEBUG, ("yadda\n")); switch(atom->type) { case ATOM_TYPE_OP_ARG_NONE: LOG(LOG_DEBUG, ("output: $%02X\n", atom->u.op.code)); membuf_append_char(out, atom->u.op.code); break; case ATOM_TYPE_OP_ARG_U8: /* op with argument */ value = resolve_expr(atom->u.op.arg); if(!is_valid_u8(value)) { LOG(LOG_ERROR, ("value %d out of range for op $%02X @%p\n", value, atom->u.op.code, (void*)atom)); exit(1); } LOG(LOG_DEBUG, ("output: $%02X $%02X\n", atom->u.op.code, value & 255)); membuf_append_char(out, atom->u.op.code); membuf_append_char(out, value); break; case ATOM_TYPE_OP_ARG_I8: /* op with argument */ value = resolve_expr(atom->u.op.arg); if(!is_valid_i8(value)) { LOG(LOG_ERROR, ("value %d out of range for op $%02X @%p\n", value, atom->u.op.code, (void*)atom)); exit(1); } LOG(LOG_DEBUG, ("output: $%02X $%02X\n", atom->u.op.code, value & 255)); membuf_append_char(out, atom->u.op.code); membuf_append_char(out, value); break; case ATOM_TYPE_OP_ARG_UI8: /* op with argument */ value = resolve_expr(atom->u.op.arg); if(!is_valid_ui8(value)) { LOG(LOG_ERROR, ("value %d out of range for op $%02X @%p\n", value, atom->u.op.code, (void*)atom)); exit(1); } LOG(LOG_DEBUG, ("output: $%02X $%02X\n", atom->u.op.code, value & 255)); membuf_append_char(out, atom->u.op.code); membuf_append_char(out, value); break; case ATOM_TYPE_OP_ARG_U16: /* op with argument */ value = resolve_expr(atom->u.op.arg); if(!is_valid_u16(value)) { LOG(LOG_ERROR, ("value %d out of range for op $%02X @%p\n", value, atom->u.op.code, (void*)atom)); exit(1); } value2 = value / 256; value = value % 256; LOG(LOG_DEBUG, ("output: $%02X $%02X $%02X\n", atom->u.op.code, value, value2)); membuf_append_char(out, atom->u.op.code); membuf_append_char(out, value); membuf_append_char(out, value2); break; case ATOM_TYPE_RES: /* reserve memory statement */ value = resolve_expr(atom->u.res.length); if(!is_valid_u16(value)) { LOG(LOG_ERROR, ("length %d for .res(length, value) " "is out of range\n", value)); exit(1); } value2 = resolve_expr(atom->u.res.value); if(!is_valid_ui8(value2)) { LOG(LOG_ERROR, ("value %d for .res(length, value) " "is out of range\n", value)); exit(1); } LOG(LOG_DEBUG, ("output: .RES %d, %d\n", value, value2)); while(--value >= 0) { membuf_append_char(out, value2); } break; case ATOM_TYPE_BUFFER: /* include binary file statement */ value = atom->u.buffer.skip; if(!is_valid_u16(value)) { LOG(LOG_ERROR, ("value %d for .res(length, value) " "is out of range\n", value)); exit(1); } value2 = atom->u.buffer.length; if(!is_valid_u16(value2)) { LOG(LOG_ERROR, ("length %d for .incbin(name, skip, length) " "is out of range\n", value2)); exit(1); } LOG(LOG_DEBUG, ("output: .INCBIN \"%s\", %d, %d\n", atom->u.buffer.name, value, value2)); in = get_named_buffer(s->named_buffer, atom->u.buffer.name); p = membuf_get(in); p += value; while(--value2 >= 0) { membuf_append_char(out, *p++); } break; case ATOM_TYPE_WORD_EXPRS: vec_get_iterator(atom->u.exprs, i2); while((exprp = vec_iterator_next(i2)) != NULL) { expr = *exprp; value = resolve_expr(expr); if(!is_valid_ui16(value)) { LOG(LOG_ERROR, ("value %d for .word(value, ...) " "is out of range\n", value)); } value2 = value / 256; value = value % 256; membuf_append_char(out, value); membuf_append_char(out, value2); } LOG(LOG_DEBUG, ("output: %d words\n", vec_count(atom->u.exprs))); break; case ATOM_TYPE_BYTE_EXPRS: vec_get_iterator(atom->u.exprs, i2); while((exprp = vec_iterator_next(i2)) != NULL) { expr = *exprp; value = resolve_expr(expr); if(!is_valid_ui8(value)) { LOG(LOG_ERROR, ("value %d for .byte(value, ...) " "is out of range\n", value)); } membuf_append_char(out, value); } LOG(LOG_DEBUG, ("output: %d bytes\n", vec_count(atom->u.exprs))); break; default: LOG(LOG_ERROR, ("invalid atom_type %d @%p\n", atom->type, (void*)atom)); exit(1); } } }