static void add_section(struct section_64 *sect, t_file_info *file_info) { if (!ft_strcmp(sect->segname, SEG_TEXT) && !ft_strcmp(sect->sectname, SECT_TEXT)) { ft_printf("(__TEXT,__text) section\n"); if (sect->size > 0) print_sect(sect->addr, sect->size, file_info->data + sect->offset); } }
int edit(void) { union empobj_storage item; char *what; struct nstr_item ni; char *key, *ptr; struct natstr *np; int type, arg_index, ret; char buf[1024]; what = getstarg(player->argp[1], "Edit what (country, land, ship, plane, nuke, unit)? ", buf); if (!what) return RET_SYN; switch (what[0]) { case 'l': type = EF_SECTOR; break; case 'p': type = EF_PLANE; break; case 's': type = EF_SHIP; break; case 'u': type = EF_LAND; break; case 'n': type = EF_NUKE; break; case 'c': type = EF_NATION; break; default: pr("huh?\n"); return RET_SYN; } if (!snxtitem(&ni, type, player->argp[2], NULL)) return RET_SYN; while (nxtitem(&ni, &item)) { if (!player->argp[3]) { switch (type) { case EF_SECTOR: print_sect(&item.sect); break; case EF_SHIP: print_ship(&item.ship); break; case EF_PLANE: print_plane(&item.plane); break; case EF_LAND: print_land(&item.land); break; case EF_NUKE: print_nuke(&item.nuke); break; case EF_NATION: print_nat(&item.nat); break; default: CANT_REACH(); } } arg_index = 3; for (;;) { if (player->argp[arg_index]) { if (player->argp[arg_index+1]) { key = player->argp[arg_index++]; ptr = player->argp[arg_index++]; } else return RET_SYN; } else if (arg_index == 3) { key = getin(buf, &ptr); if (!key) return RET_SYN; if (!*key) break; } else break; if (!check_obj_ok(&item.gen)) return RET_FAIL; switch (type) { case EF_NATION: /* * edit_nat() may update the edited country by sending * it bulletins. Writing back item.nat would trigger * a seqno mismatch oops. Workaround: edit in-place. */ np = getnatp(item.nat.nat_cnum); ret = edit_nat(np, key, ptr); if (ret != RET_OK) return ret; if (!putnat(np)) return RET_FAIL; item.nat = *np; continue; case EF_SECTOR: ret = edit_sect(&item.sect, key, ptr); break; case EF_SHIP: ret = edit_ship(&item.ship, key, ptr); break; case EF_LAND: ret = edit_land(&item.land, key, ptr); break; case EF_PLANE: ret = edit_plane(&item.plane, key, ptr); break; case EF_NUKE: ret = edit_nuke(&item.nuke, key, ptr); break; default: CANT_REACH(); } if (ret != RET_OK) return ret; if (!put_empobj(type, item.gen.uid, &item.gen)) return RET_FAIL; } } return RET_OK; }