void dump_font (int f) { int i,x; set_font_used(f,0); font_tables[f]->charinfo_cache = NULL; dump_things(*(font_tables[f]), 1); dump_string(font_name(f)); dump_string(font_area(f)); dump_string(font_filename(f)); dump_string(font_fullname(f)); dump_string(font_encodingname(f)); dump_string(font_cidregistry(f)); dump_string(font_cidordering(f)); dump_things(*param_base(f),(font_params(f)+1)); if (has_left_boundary(f)) { dump_int(1); dump_charinfo(f,left_boundarychar); } else { dump_int(0); } if (has_right_boundary(f)) { dump_int(1); dump_charinfo(f,right_boundarychar); } else { dump_int(0); } for(i=font_bc(f); i<=font_ec(f); i++) { if (char_exists(f,i)) { dump_charinfo(f,i); } } }
static unsigned char * dump_char_size(char *c, unsigned char *d, int *off, ssize_t size, int convert) { char *p = c; if (c == NULL) { size = 0; d = dump_int(size, d, off); return d; } if (convert && !is_ascii (c, size)) { p = mutt_substrdup (c, c + size); if (mutt_convert_string (&p, Charset, "utf-8", 0) == 0) { c = p; size = mutt_strlen (c) + 1; } } d = dump_int(size, d, off); lazy_realloc(&d, *off + size); memcpy(d + *off, p, size); *off += size; if (p != c) FREE(&p); return d; }
static unsigned char * dump_envelope(ENVELOPE * e, unsigned char *d, int *off, int convert) { d = dump_address(e->return_path, d, off, convert); d = dump_address(e->from, d, off, convert); d = dump_address(e->to, d, off, convert); d = dump_address(e->cc, d, off, convert); d = dump_address(e->bcc, d, off, convert); d = dump_address(e->sender, d, off, convert); d = dump_address(e->reply_to, d, off, convert); d = dump_address(e->mail_followup_to, d, off, convert); d = dump_char(e->list_post, d, off, convert); d = dump_char(e->subject, d, off, convert); if (e->real_subj) d = dump_int(e->real_subj - e->subject, d, off); else d = dump_int(-1, d, off); d = dump_char(e->message_id, d, off, 0); d = dump_char(e->supersedes, d, off, 0); d = dump_char(e->date, d, off, 0); d = dump_char(e->x_label, d, off, convert); d = dump_buffer(e->spam, d, off, convert); d = dump_list(e->references, d, off, 0); d = dump_list(e->in_reply_to, d, off, 0); d = dump_list(e->userhdrs, d, off, convert); return d; }
void dump_2d_float_array(float **array, int dim1, int dim2, FILE *fp) { dump_int(dim1, fp); dump_int(dim2, fp); if (dim1 > 0 && dim2 > 0) { fwrite_safe(*array, sizeof(float), dim1 * dim2, fp); } return; }
void dump_string ( char *string, FILE *fp ) { int len; if (string == NULL) { dump_int(-1, fp); } else { len = strlen(string); dump_int(len, fp); fwrite_safe(string, sizeof(char), len + 1, fp); } return; }
static void dump_method(struct method *method) { struct param_list *params = method->params; struct keyword_param *k; int param_info, nkeys; int nclosure_vars; struct closes_over *over; if (params->rest_param) param_info = 1; else param_info = 0; if (params->all_keys) param_info |= 2; if (params->allow_keys) { nkeys = 0; for (k = params->keyword_params; k != NULL; k = k->next) nkeys++; param_info = param_info | (nkeys+1)<<2; } nclosure_vars = 0; for (over = method->closes_over; over != NULL; over = over->next) nclosure_vars++; if (param_info < 256 && nclosure_vars < 256) { dump_op(fop_SHORT_METHOD); dump_byte(param_info); dump_byte(nclosure_vars); } else { dump_op(fop_METHOD); dump_int(param_info); dump_int(nclosure_vars); } for (k = params->keyword_params; k != NULL; k = k->next) { struct literal_expr *def = (struct literal_expr *)k->def; dump_symbol(k->keyword); if (def) { if (def->kind != expr_LITERAL) lose("non-literal keyword default made it though expand?"); dump_literal(def->lit); } else dump_op(fop_FALSE); } dump_component(method->component); }
void dump_sysinfo(CTX, kOutputStream *w, int isALL) { const knh_sysinfo_t *sysinfo = knh_getsysinfo(); dump_string(_ctx, w, "konoha.type", sysinfo->konoha_type, isALL); dump_string(_ctx, w, "konoha.version", sysinfo->konoha_version, isALL); dump_int(_ctx, w, "konoha.patch.level", sysinfo->konoha_patch_level, isALL); dump_string(_ctx, w, "konoha.options", sysinfo->konoha_options, isALL); dump_int(_ctx, w, "konoha.systembits", sysinfo->konoha_systembits, isALL); dump_string(_ctx, w, "konoha.config", sysinfo->konoha_config, isALL); dump_string(_ctx, w, "konoha.built.cc", sysinfo->konoha_cc, isALL); dump_string(_ctx, w, "konoha.built.date", sysinfo->konoha_builtdate, isALL); dump_string(_ctx, w, "konoha.dist_type", sysinfo->konoha_disttype, isALL); dump_string(_ctx, w, "konoha.dist_url", sysinfo->konoha_disturl, isALL); dump_string(_ctx, w, "kern.ostype", sysinfo->kern_ostype, isALL); dump_string(_ctx, w, "kern.version", sysinfo->kern_version, isALL); dump_string(_ctx, w, "kern.desc", sysinfo->kern_desc, isALL); dump_string(_ctx, w, "hw.machine", sysinfo->hw_machine, isALL); dump_string(_ctx, w, "hw.model", sysinfo->hw_model, isALL); dump_string(_ctx, w, "cpu.desc", sysinfo->cpu_desc, isALL); dump_int(_ctx, w, "hw.ncpu", sysinfo->hw_ncpu, isALL); dump_int(_ctx, w, "hw.availcpu", sysinfo->hw_availcpu, isALL); dump_int(_ctx, w, "hw.physmem", sysinfo->hw_physmem, isALL); dump_int(_ctx, w, "hw.usermem", sysinfo->hw_usermem, isALL); dump_int(_ctx, w, "hw.cpufrequency", sysinfo->hw_cpufrequency, isALL); dump_int(_ctx, w, "hw.l2cachesize", sysinfo->hw_l2cachesize, isALL); }
void dump_primitives(void) { int p,q; for(p= 0;p<=prim_size;p++) dump_hh(prim[p]); for(p= 0;p<=prim_size;p++) dump_wd(prim_eqtb[p]); for(p= 0;p<=last_cmd;p++){ dump_int(prim_data[p].offset); dump_int(prim_data[p].subids); for(q= 0;q<prim_data[p].subids;q++){ dump_int(prim_data[p].names[q]); } } }
/* * NAME: dump_chars() * DESCRIPTION: output a range of characters */ static void dump_chars(char *p, unsigned int n) { while (n > 0) { dump_int(*p++); --n; } }
static void dump_vector_header(int length) { switch (length) { case 0: dump_op(fop_VECTOR0); break; case 1: dump_op(fop_VECTOR1); break; case 2: dump_op(fop_VECTOR2); break; case 3: dump_op(fop_VECTOR3); break; case 4: dump_op(fop_VECTOR4); break; case 5: dump_op(fop_VECTOR5); break; case 6: dump_op(fop_VECTOR6); break; case 7: dump_op(fop_VECTOR7); break; case 8: dump_op(fop_VECTOR8); break; default: dump_op(fop_VECTORN); if (length-9 < 254) dump_byte(length-9); else if (length-9-254 <= USHRT_MAX) { dump_byte(254); dump_short((short)(length-9-254)); } else { dump_byte(255); dump_int(length-9-254-USHRT_MAX-1); } break; } }
/* This function transforms a header into a char so that it is useable by * db_store. */ static void * mutt_hcache_dump(header_cache_t *h, HEADER * header, int *off, unsigned int uidvalidity, mutt_hcache_store_flags_t flags) { unsigned char *d = NULL; HEADER nh; int convert = !Charset_is_utf8; *off = 0; d = lazy_malloc(sizeof (validate)); if (flags & M_GENERATE_UIDVALIDITY) { struct timeval now; gettimeofday(&now, NULL); memcpy(d, &now, sizeof (struct timeval)); } else memcpy(d, &uidvalidity, sizeof (uidvalidity)); *off += sizeof (validate); d = dump_int(h->crc, d, off); lazy_realloc(&d, *off + sizeof (HEADER)); memcpy(&nh, header, sizeof (HEADER)); /* some fields are not safe to cache */ nh.tagged = 0; nh.changed = 0; nh.threaded = 0; nh.recip_valid = 0; nh.searched = 0; nh.matched = 0; nh.collapsed = 0; nh.limited = 0; nh.num_hidden = 0; nh.recipient = 0; nh.pair = 0; nh.attach_valid = 0; nh.path = NULL; nh.tree = NULL; nh.thread = NULL; #ifdef MIXMASTER nh.chain = NULL; #endif #if defined USE_POP || defined USE_IMAP nh.data = NULL; #endif memcpy(d + *off, &nh, sizeof (HEADER)); *off += sizeof (HEADER); d = dump_envelope(nh.env, d, off, convert); d = dump_body(nh.content, d, off, convert); d = dump_char(nh.maildir_flags, d, off, convert); return d; }
nbool wbxmlDecoder_decode(NWbxmlDecoder* decoder) { nbool result = N_FALSE; WBXMLParser *wbxml_parser = NULL; WBXMLContentHandler parse_handler = { NULL, NULL, wbxml_start_element, wbxml_end_element, wbxml_characters, NULL}; if (decoder->srcPos <= 0) return N_FALSE; wbxml_parser = wbxml_parser_create(); if (wbxml_parser) { WBXMLError ret = WBXML_OK; decoder->dstMax = decoder->srcMax * 2; decoder->dst = (char*)NBK_malloc(decoder->dstMax); decoder->dstPos = 0; #if DEBUG_DECODER dump_char(decoder->page, "decoding...", -1); dump_return(decoder->page); #endif wbxml_parser_set_user_data(wbxml_parser, decoder); wbxml_parser_set_content_handler(wbxml_parser, &parse_handler); ret = wbxml_parser_parse(wbxml_parser, decoder->src, decoder->srcPos); wbxml_parser_destroy(wbxml_parser); #if DEBUG_DECODER dump_char(decoder->page, "decoded!", -1); dump_int(decoder->page, decoder->srcPos); dump_int(decoder->page, decoder->dstPos); dump_return(decoder->page); #endif if (ret == WBXML_OK) result = N_TRUE; } return result; }
static unsigned char * dump_buffer(BUFFER * b, unsigned char *d, int *off, int convert) { if (!b) { d = dump_int(0, d, off); return d; } else d = dump_int(1, d, off); d = dump_char_size(b->data, d, off, b->dsize + 1, convert); d = dump_int(b->dptr - b->data, d, off); d = dump_int(b->dsize, d, off); d = dump_int(b->destroy, d, off); return d; }
void save(Chunk *chunk, char *filename) { FILE *fp = fopen(filename, "wb"); if (!fp) { fatal("Could not open bytecode cache file."); } int mag = MAGIC_BYTE; int maj = MAJOR_VERSION; int min = MINOR_VERSION; dump_int(fp, mag); dump_int(fp, maj); dump_int(fp, min); dump_chunk(chunk, fp); fclose(fp); }
void dump_chunk(Chunk *chunk, FILE *fp) { // TODO - may be wasteful, check size limits dump_int(fp, chunk->numtemps); dump_int(fp, chunk->numconstants); dump_int(fp, chunk->numinstructions); dump_int(fp, chunk->numchildren); dump_int(fp, chunk->numlocals); dump_int(fp, chunk->numupvars); dump_int(fp, chunk->numparams); int i; for (i = 0; i < chunk->numinstructions; i++) { dump_int(fp, chunk->instructions[i]); } for (i = 0; i < chunk->numconstants; i++) { // TODO - wasteful, doesn't need nearly 32 bits dump_int(fp, chunk->constants[i]->type); switch (chunk->constants[i]->type) { case CONST_INT: case CONST_BOOL: dump_int(fp, chunk->constants[i]->value.i); break; case CONST_REAL: dump_real(fp, chunk->constants[i]->value.d); break; case CONST_NULL: break; case CONST_STRING: { dump_string(fp, chunk->constants[i]->value.s); } break; } } for (i = 0; i < chunk->numchildren; i++) { dump_chunk(chunk->children[i], fp); } }
void wbxmlDecoder_setSourceLength(NWbxmlDecoder* decoder, int length) { int size = 0; if (length > 0) size = BUFFER_GROW * ((length / BUFFER_GROW) + 1); else size = BUFFER_GROW; decoder->src = (uint8*)NBK_malloc(size); decoder->dstMax = size; #if DEBUG_DECODER dump_char(decoder->page, "init alloc", -1); dump_int(decoder->page, length); dump_int(decoder->page, decoder->srcMax); dump_return(decoder->page); #endif }
/* * NAME: dump_imap() * DESCRIPTION: output imap table */ static void dump_imap(control *ctrl) { int i; printf("\nstatic char imap[] = {\n"); size = 0; for (i = 0; i < ctrl->imapsz; i++) { dump_int(ctrl->imap[i]); } printf("\n};\n"); }
static void dump_ref(int handle) { if (handle <= USHRT_MAX) { dump_op(fop_SHORT_REF); dump_short((short)handle); } else { dump_op(fop_REF); dump_int(handle); } }
static void dump_string_guts(int short_op, int long_op, char *str, int length) { if (length < 256) { dump_op(short_op); dump_byte(length); } else { dump_op(long_op); dump_int(length); } dump_bytes(str, length); }
static void grow_buffer(uint8** buf, int* max, int length, void* page) { int size = BUFFER_GROW * ((length * 2 / BUFFER_GROW) + 1); *max += size; *buf = (uint8*)NBK_realloc(*buf, *max); #if DEBUG_DECODER dump_char(page, "grow buffer", -1); dump_int(page, *max); dump_return(page); #endif }
void dump_luac_registers(void) { int x; int k, n; bytecode b; dump_int(luabytecode_max); if (lua_bytecode_registers != NULL) { n = 0; for (k = 0; k <= luabytecode_max; k++) { if (lua_bytecode_registers[k].size != 0) n++; } dump_int(n); for (k = 0; k <= luabytecode_max; k++) { b = lua_bytecode_registers[k]; if (b.size != 0) { dump_int(k); dump_int(b.size); do_zdump((char *) b.buf, 1, (b.size), DUMP_FILE); } } } for (k = 0; k < 65536; k++) { char *a = luanames[k]; if (a != NULL) { x = (int) strlen(a) + 1; dump_int(x); dump_things(*a, x); } else { x = 0; dump_int(x); } } }
static void dump_component(struct component *c) { struct constant *constant; struct block *block; int bytes; if (c->nconstants <= UCHAR_MAX && c->bytes <= USHRT_MAX) { dump_op(fop_SHORT_COMPONENT); dump_byte(c->nconstants); dump_short((short)(c->bytes)); } else { dump_op(fop_COMPONENT); dump_int(c->nconstants); dump_int(c->bytes); } if (c->debug_name) dump_literal(c->debug_name); else dump_op(fop_FALSE); dump_integer(c->frame_size); dump_debug_info(c); for (constant = c->constants; constant != NULL; constant = constant->next) dump_constant(constant); bytes = 0; for (block = c->blocks; block != NULL; block = block->next) { int count = block->end - block->bytes; dump_bytes(block->bytes, count); bytes += count; } if (bytes != c->bytes) lose("Planned on writing %d bytes, but ended up writing %d instead.", c->bytes, bytes); }
void wbxmlDecoder_addSourceData(NWbxmlDecoder* decoder, uint8* data, int length) { #if DEBUG_DECODER dump_char(decoder->page, "add data", -1); dump_int(decoder->page, length); dump_return(decoder->page); #endif if (decoder->srcMax - decoder->srcPos < length) grow_buffer(&decoder->src, &decoder->srcMax, length, decoder->page); NBK_memcpy(&decoder->src[decoder->srcPos], data, length); decoder->srcPos += length; }
static unsigned char * dump_address(ADDRESS * a, unsigned char *d, int *off, int convert) { unsigned int counter = 0; unsigned int start_off = *off; d = dump_int(0xdeadbeef, d, off); while (a) { #ifdef EXACT_ADDRESS d = dump_char(a->val, d, off, convert); #endif d = dump_char(a->personal, d, off, convert); d = dump_char(a->mailbox, d, off, 0); d = dump_int(a->group, d, off); a = a->next; counter++; } memcpy(d + start_off, &counter, sizeof (int)); return d; }
void dump_setup_output(char *source, FILE *file) { struct stat buf; time_t tv; int statres; File = file; #if ! NO_SHARP_BANG fprintf(File, "#! /usr/bin/env mindy -x\n"); #endif fprintf(File, "# %s (%d.%d) of %s\n", "compilation", file_MajorVersion, file_MinorVersion, source); statres = stat(source, &buf); if (statres >= 0) fprintf(File, "# last modified on %s", ctime(&buf.st_mtime)); fprintf(File, "# produced with the %s version of mindycomp\n", Version); time(&tv); fprintf(File, "# at %s", ctime(&tv)); dump_op(fop_HEADER); dump_byte(file_MajorVersion); dump_byte(file_MinorVersion); dump_byte(sizeof(short)); dump_byte(sizeof(int)); dump_byte(sizeof(long)); dump_byte(sizeof(float)); dump_byte(sizeof(double)); dump_byte(sizeof(long double)); dump_short(1); dump_int(dbc_MagicNumber); dump_op(fop_IN_LIBRARY); if (LibraryName) dump_symbol(LibraryName); else dump_symbol(sym_DylanUser); if (source != NULL) { dump_op(fop_SOURCE_FILE); if (statres >= 0) dump_integer(buf.st_mtime); else dump_integer(0); dump_string_guts(fop_SHORT_STRING, fop_STRING, source, strlen(source)); } }
static unsigned char * dump_list(LIST * l, unsigned char *d, int *off, int convert) { unsigned int counter = 0; unsigned int start_off = *off; d = dump_int(0xdeadbeef, d, off); while (l) { d = dump_char(l->data, d, off, convert); l = l->next; counter++; } memcpy(d + start_off, &counter, sizeof (int)); return d; }
static void dump_integer(long value) { if (SCHAR_MIN <= value && value <= SCHAR_MAX) { dump_op(fop_SIGNED_BYTE); dump_byte(value); } else if (SHRT_MIN <= value && value <= SHRT_MAX) { dump_op(fop_SIGNED_SHORT); dump_short((short)value); } else if (INT_MIN <= value && value <= INT_MAX) { dump_op(fop_SIGNED_INT); dump_int(value); } else { dump_op(fop_SIGNED_LONG); dump_long(value); } }
static void dump_varref(struct id *id, bool written) { if (id->line) { dump_op(fop_NOTE_REFERENCE); dump_int(id->line); } if (id->internal) if (written) dump_op(fop_BUILTIN_WRITABLE_VALUE_CELL); else dump_op(fop_BUILTIN_VALUE_CELL); else if (written) dump_op(fop_WRITABLE_VALUE_CELL); else dump_op(fop_VALUE_CELL); dump_symbol(id->symbol); }
static unsigned char * dump_parameter(PARAMETER * p, unsigned char *d, int *off, int convert) { unsigned int counter = 0; unsigned int start_off = *off; d = dump_int(0xdeadbeef, d, off); while (p) { d = dump_char(p->attribute, d, off, 0); d = dump_char(p->value, d, off, convert); p = p->next; counter++; } memcpy(d + start_off, &counter, sizeof (int)); return d; }
void dump_string(FILE *fp, char *s) { int n = strlen(s) + 1; dump_int(fp, n); fwrite(s, sizeof(char), n, fp); }