int write_file(char *file_name, Boolean update_recent) { FILE *fp; if (!ok_to_write(file_name, "SAVE")) return (-1); if ((fp = fopen(file_name, "wb")) == NULL) { file_msg("Couldn't open file %s, %s", file_name, strerror(errno)); beep(); return (-1); } num_object = 0; if (write_objects(fp)) { file_msg("Error writing file %s, %s", file_name, strerror(errno)); beep(); exit (2); return (-1); } if (!update_figs) put_msg("%d object(s) saved in \"%s\"", num_object, file_name); /* update the recent list if caller desires */ if (update_recent) update_recent_list(file_name); return (0); }
caddr_t ctf_gen(iiburst_t *iiburst, size_t *resszp, int do_compress) { ctf_buf_t *buf = ctf_buf_new(); ctf_header_t h; caddr_t outbuf; int i; /* * Prepare the header, and create the CTF output buffers. The data * object section and function section are both lists of 2-byte * integers; we pad these out to the next 4-byte boundary if needed. */ h.cth_magic = CTF_MAGIC; h.cth_version = CTF_VERSION; h.cth_flags = do_compress ? CTF_F_COMPRESS : 0; h.cth_parlabel = strtab_insert(&buf->ctb_strtab, iiburst->iib_td->td_parlabel); h.cth_parname = strtab_insert(&buf->ctb_strtab, iiburst->iib_td->td_parname); h.cth_lbloff = 0; (void) list_iter(iiburst->iib_td->td_labels, write_label, buf); pad_buffer(buf, 2); h.cth_objtoff = ctf_buf_cur(buf); for (i = 0; i < iiburst->iib_nobjts; i++) write_objects(iiburst->iib_objts[i], buf); pad_buffer(buf, 2); h.cth_funcoff = ctf_buf_cur(buf); for (i = 0; i < iiburst->iib_nfuncs; i++) write_functions(iiburst->iib_funcs[i], buf); pad_buffer(buf, 4); h.cth_typeoff = ctf_buf_cur(buf); (void) list_iter(iiburst->iib_types, write_type, buf); debug(2, "CTF wrote %d types\n", list_count(iiburst->iib_types)); h.cth_stroff = ctf_buf_cur(buf); h.cth_strlen = strtab_size(&buf->ctb_strtab); /* * We only do compression for ctfmerge, as ctfconvert is only * supposed to be used on intermediary build objects. This is * significantly faster. */ if (do_compress) outbuf = write_compressed_buffer(&h, buf, resszp); else outbuf = write_buffer(&h, buf, resszp); ctf_buf_free(buf); return (outbuf); }
int main(void) { init(); format(); test_create_partition(); create_objects(); create_collection(); #ifdef FULL_TEST remove_objects(); write_objects(); read_objects(); #endif fini(); return 0; }
static void write_planes(wap::OutputStream &stream, const std::vector<wap_plane> &planes, const std::vector<wwd_plane_offsets> &planes_offsets) { auto plane_offsets = planes_offsets.cbegin(); for (const wap_plane &plane : planes) { auto &planep = plane.properties; uint32_t height_px = plane.tiles_high * planep.tile_height; uint32_t width_px = plane.tiles_wide * planep.tile_width; uint32_t objects_offset = plane.objects.empty() ? 0 : plane_offsets->objects_offset; stream.write( 160, 0, planep.flags, 0, planep.name, width_px, height_px, planep.tile_width, planep.tile_height, plane.tiles_wide, plane.tiles_high, 0, 0, planep.movement_x_percent, planep.movement_y_percent, planep.fill_color, (uint32_t)plane.image_sets.size(), (uint32_t)plane.objects.size(), plane_offsets->tiles_offset, plane_offsets->image_sets_offset, objects_offset, planep.z_coord, 0, 0, 0); ++plane_offsets; } for (const wap_plane &plane : planes) { for (uint32_t tile : plane.tiles) stream.write(tile); } for (const wap_plane &plane : planes) { for (const std::string &image_set : plane.image_sets) write_nullterminated_string(stream, image_set); } for (const wap_plane &plane : planes) { write_objects(stream, plane.objects); } }