int CDECL main() { char filename[256]; char tmplogname[256]; char redologname[256]; int remove; print_banner(); filename[0] = 0; redologname[0] = 0; if (ask_string("\nWhat is the flat image name?\n", "c.img", filename) < 0) fatal(EOF_ERR); snprintf(tmplogname,256,"%s%s", filename, UNDOABLE_REDOLOG_EXTENSION); if (ask_string("\nWhat is the redolog name?\n", tmplogname, redologname) < 0) fatal(EOF_ERR); if (ask_yn("\nShall I remove the redolog afterwards?\n", 1, &remove) < 0) fatal(EOF_ERR); commit_redolog(filename, redologname); if (remove) { if (unlink(redologname) != 0) fatal("ERROR: while removing the redolog !\n"); } // make picky compilers (c++, gcc) happy, // even though we leave via 'myexit' just above return 0; }
int bx_write_rc(char *rc) { char oldrc[CI_PATH_LENGTH], newrc[CI_PATH_LENGTH]; if (rc == NULL) { if (SIM->get_default_rc(oldrc, CI_PATH_LENGTH) < 0) strcpy(oldrc, "none"); } else { strncpy(oldrc, rc, CI_PATH_LENGTH); } while (1) { if (ask_string("Save configuration to what file? To cancel, type 'none'.\n[%s] ", oldrc, newrc) < 0) return -1; if (!strcmp(newrc, "none")) return 0; // try with overwrite off first int status = SIM->write_rc(newrc, 0); if (status >= 0) { fprintf(stderr, "Wrote configuration to '%s'.\n", newrc); return 0; } else if (status == -2) { // return code -2 indicates the file already exists, and overwrite // confirmation is required. Bit32u overwrite = 0; char prompt[256]; sprintf(prompt, "Configuration file '%s' already exists. Overwrite it? [no] ", newrc); if (ask_yn(prompt, "", 0, &overwrite) < 0) return -1; if (!overwrite) continue; // if "no", start loop over, asking for a different file // they confirmed, so try again with overwrite bit set if (SIM->write_rc(newrc, 1) >= 0) { fprintf(stderr, "Overwriting existing configuration '%s'.\n", newrc); return 0; } else { fprintf(stderr, "Write failed to '%s'.\n", newrc); } } } }
static int prompt_loop(const char *text, char **l, bool (*is_valid)(const char *name), char **ret) { int r; assert(text); assert(is_valid); assert(ret); for (;;) { _cleanup_free_ char *p = NULL; unsigned u; r = ask_string(&p, "%s %s (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET), text); if (r < 0) { log_error("Failed to query user: %s", strerror(-r)); return r; } if (isempty(p)) { log_warning("No data entered, skipping."); return 0; } r = safe_atou(p, &u); if (r >= 0) { char *c; if (u <= 0 || u > strv_length(l)) { log_error("Specified entry number out of range."); continue; } log_info("Selected '%s'.", l[u-1]); c = strdup(l[u-1]); if (!c) return log_oom(); free(*ret); *ret = c; return 0; } if (!is_valid(p)) { log_error("Entered data invalid."); continue; } free(*ret); *ret = p; p = 0; return 0; } }
static FILE * ask_filename(const char *prompt, char *fname_buf, size_t bufsz) { char *answer; FILE *new_f; answer = ask_string(prompt, fname_buf, bufsz); if (answer == NULL) { return (NULL); } new_f = fopen(fname_buf, "w"); return (new_f); }
int bx_read_rc(char *rc) { if (rc && SIM->read_rc(rc) >= 0) return 0; char oldrc[CI_PATH_LENGTH]; if (SIM->get_default_rc(oldrc, CI_PATH_LENGTH) < 0) strcpy(oldrc, "none"); char newrc[CI_PATH_LENGTH]; while (1) { if (ask_string("\nWhat is the configuration file name?\nTo cancel, type 'none'. [%s] ", oldrc, newrc) < 0) return -1; if (!strcmp(newrc, "none")) return -1; if (SIM->read_rc(newrc) >= 0) return 0; fprintf(stderr, "The file '%s' could not be found.\n", newrc); } }
int bx_param_string_c::text_ask(FILE *fpin, FILE *fpout) { fprintf(fpout, "\n"); int status; const char *prompt = get_ask_format(); if (prompt == NULL) { if (options & SELECT_FOLDER_DLG) { fprintf(fpout, "%s\n\n", get_label()); prompt = "Enter a path to an existing folder or press enter to cancel\n"; } else { // default prompt, if they didn't set an ask format string text_print(fpout); fprintf(fpout, "\n"); prompt = "Enter a new value, '?' for help, or press return for no change.\n"; } } while (1) { char buffer[1024]; status = ask_string(prompt, getptr(), buffer); if (status == -2) { fprintf(fpout, "\n%s\n", get_description()); continue; } if (status < 0) return status; int opts = options; char buffer2[1024]; strcpy(buffer2, buffer); if (status == 1 && opts & RAW_BYTES) { // copy raw hex into buffer status = parse_raw_bytes(buffer, buffer2, maxsize, separator); if (status < 0) { fprintf(fpout, "Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator); continue; } } if (!equals(buffer)) set(buffer); return 0; } }
static int prompt_hostname(void) { int r; if (arg_hostname) return 0; if (!arg_prompt_hostname) return 0; print_welcome(); putchar('\n'); for (;;) { _cleanup_free_ char *h = NULL; r = ask_string(&h, "%s Please enter hostname for new system (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET)); if (r < 0) { log_error("Failed to query hostname: %s", strerror(-r)); return r; } if (isempty(h)) { log_warning("No hostname entered, skipping."); break; } if (!hostname_is_valid(h)) { log_error("Specified hostname invalid."); continue; } arg_hostname = h; h = NULL; break; } return 0; }
static int prompt_hostname(void) { int r; if (arg_hostname) return 0; if (!arg_prompt_hostname) return 0; print_welcome(); putchar('\n'); for (;;) { _cleanup_free_ char *h = NULL; r = ask_string(&h, "%s Please enter hostname for new system (empty to skip): ", draw_special_char(DRAW_TRIANGULAR_BULLET)); if (r < 0) return log_error_errno(r, "Failed to query hostname: %m"); if (isempty(h)) { log_warning("No hostname entered, skipping."); break; } if (!hostname_is_valid(h, true)) { log_error("Specified hostname invalid."); continue; } /* Get rid of the trailing dot that we allow, but don't want to see */ arg_hostname = hostname_cleanup(h); h = NULL; break; } return 0; }
int main (int argc, char *argv[]) { Bit64s sectors = 0; char filename[256]; char bochsrc_line[256]; WRITE_IMAGE write_function=NULL; #ifdef WIN32 WRITE_IMAGE_WIN32 writefn_win32=NULL; #endif if (!parse_cmdline (argc, argv)) myexit(1); print_banner (); if (bx_interactive) { if (ask_menu (fdhd_menu, fdhd_n_choices, fdhd_choices, bx_hdimage, &bx_hdimage) < 0) fatal (EOF_ERR); } if (bx_hdimage) { unsigned int cyl; int hdsize, heads=16, spt=63; int mode; if (bx_interactive) { if (ask_menu (hdmode_menu, hdmode_n_choices, hdmode_choices, bx_hdimagemode, &mode) < 0) fatal (EOF_ERR); if (ask_int ("\nEnter the hard disk size in megabytes, between 1 and 129023\n", 1, 129023, bx_hdsize, &hdsize) < 0) fatal (EOF_ERR); } else { mode = bx_hdimagemode; hdsize = bx_hdsize; } cyl = (unsigned int) (hdsize*1024.0*1024.0/16.0/63.0/512.0); assert (cyl < 262144); sectors = cyl*heads*spt; printf ("\nI will create a '%s' hard disk image with\n", hdmode_choices[mode]); printf (" cyl=%d\n", cyl); printf (" heads=%d\n", heads); printf (" sectors per track=%d\n", spt); printf (" total sectors=" FMT_LL "d\n", sectors); printf (" total size=%.2f megabytes\n", (float)(Bit64s)(sectors/2)/1024.0); if (bx_interactive) { if (!strlen(bx_filename)) strcpy(bx_filename, "c.img"); if (ask_string ("\nWhat should I name the image?\n", bx_filename, filename) < 0) fatal (EOF_ERR); } else { strcpy(filename, bx_filename); } sprintf (bochsrc_line, "ata0-master: type=disk, path=\"%s\", mode=%s, cylinders=%d, heads=%d, spt=%d", filename, hdmode_choices[mode], cyl, heads, spt); switch (mode) { case 1: write_function=make_sparse_image; break; case 2: write_function=make_growing_image; break; default: #ifdef WIN32 writefn_win32=make_flat_image_win32; #else write_function=make_flat_image; #endif } } else { int fdsize, cyl=0, heads=0, spt=0; if (bx_interactive) { if (ask_menu (fdsize_menu, fdsize_n_choices, fdsize_choices, bx_fdsize_idx, &fdsize) < 0) fatal (EOF_ERR); } else { fdsize = bx_fdsize_idx; } switch (fdsize) { case 0: cyl=40; heads=1; spt=8; break; /* 0.16 meg */ case 1: cyl=40; heads=1; spt=9; break; /* 0.18 meg */ case 2: cyl=40; heads=2; spt=8; break; /* 0.32 meg */ case 3: cyl=40; heads=2; spt=9; break; /* 0.36 meg */ case 4: cyl=80; heads=2; spt=9; break; /* 0.72 meg */ case 5: cyl=80; heads=2; spt=15; break; /* 1.2 meg */ case 6: cyl=80; heads=2; spt=18; break; /* 1.44 meg */ case 7: cyl=80; heads=2; spt=21; break; /* 1.68 meg */ case 8: cyl=82; heads=2; spt=21; break; /* 1.72 meg */ case 9: cyl=80; heads=2; spt=36; break; /* 2.88 meg */ default: fatal ("ERROR: fdsize out of range"); } sectors = cyl*heads*spt; printf ("I will create a floppy image with\n"); printf (" cyl=%d\n", cyl); printf (" heads=%d\n", heads); printf (" sectors per track=%d\n", spt); printf (" total sectors=" FMT_LL "d\n", sectors); printf (" total bytes=" FMT_LL "d\n", sectors*512); if (bx_interactive) { if (!strlen(bx_filename)) strcpy(bx_filename, "a.img"); if (ask_string ("\nWhat should I name the image?\n", bx_filename, filename) < 0) fatal (EOF_ERR); } else { strcpy(filename, bx_filename); } sprintf (bochsrc_line, "floppya: image=\"%s\", status=inserted", filename); write_function=make_flat_image; } if (sectors < 1) fatal ("ERROR: Illegal disk size!"); if (strlen (filename) < 1) fatal ("ERROR: Illegal filename"); #ifdef WIN32 if (writefn_win32 != NULL) { make_image_win32 (sectors, filename, writefn_win32); } else #endif { make_image (sectors, filename, write_function); } printf ("\nI wrote " FMT_LL "u bytes to ", sectors*512); printf ("%s.\n", filename); printf ("\nThe following line should appear in your bochsrc:\n"); printf (" %s\n", bochsrc_line); #ifdef WIN32 if (OpenClipboard(NULL)) { HGLOBAL hgClip; EmptyClipboard(); hgClip = GlobalAlloc(GMEM_DDESHARE, (strlen(bochsrc_line) + 1)); strcpy((char *)GlobalLock(hgClip), bochsrc_line); GlobalUnlock(hgClip); SetClipboardData(CF_TEXT, hgClip); CloseClipboard(); printf("(The line is stored in your windows clipboard, use CTRL-V to paste)\n"); } #endif myexit(0); // make picky compilers (c++, gcc) happy, // even though we leave via 'myexit' just above return 0; }
int bx_config_interface(int menu) { Bit32u choice; char sr_path[CI_PATH_LENGTH]; while (1) { switch (menu) { case BX_CI_INIT: bx_config_interface_init(); return 0; case BX_CI_START_SIMULATION: SIM->begin_simulation(bx_startup_flags.argc, bx_startup_flags.argv); // we don't expect it to return, but if it does, quit SIM->quit_sim(1); break; case BX_CI_START_MENU: { Bit32u n_choices = 7; Bit32u default_choice; switch (SIM->get_param_enum(BXPN_BOCHS_START)->get()) { case BX_LOAD_START: default_choice = 2; break; case BX_EDIT_START: default_choice = 3; break; default: default_choice = 6; break; } if (ask_uint(startup_menu_prompt, "", 1, n_choices, default_choice, &choice, 10) < 0) return -1; switch (choice) { case 1: fprintf(stderr, "I reset all options back to their factory defaults.\n\n"); SIM->reset_all_param(); SIM->get_param_enum(BXPN_BOCHS_START)->set(BX_EDIT_START); break; case 2: // Before reading a new configuration, reset every option to its // original state. SIM->reset_all_param(); if (bx_read_rc(NULL) >= 0) SIM->get_param_enum(BXPN_BOCHS_START)->set(BX_RUN_START); break; case 3: bx_config_interface(BX_CI_START_OPTS); SIM->get_param_enum(BXPN_BOCHS_START)->set(BX_RUN_START); break; case 4: bx_write_rc(NULL); break; case 5: if (ask_string("\nWhat is the path to restore the Bochs state from?\nTo cancel, type 'none'. [%s] ", "none", sr_path) >= 0) { if (strcmp(sr_path, "none")) { SIM->get_param_bool(BXPN_RESTORE_FLAG)->set(1); SIM->get_param_string(BXPN_RESTORE_PATH)->set(sr_path); bx_config_interface(BX_CI_START_SIMULATION); } } break; case 6: bx_config_interface(BX_CI_START_SIMULATION); break; case 7: SIM->quit_sim(1); return -1; default: BAD_OPTION(menu, choice); } } break; case BX_CI_START_OPTS: if (ask_uint(startup_options_prompt, "", 0, 15+BX_PLUGINS, 0, &choice, 10) < 0) return -1; switch (choice) { case 0: return 0; case 2: bx_log_options(0); break; case 3: bx_log_options(1); break; case 1: do_menu("log"); break; case 4: do_menu("cpu"); break; case 5: do_menu("cpuid"); break; case 6: do_menu("memory"); break; case 7: do_menu("clock_cmos"); break; case 8: do_menu("pci"); break; case 9: do_menu("display"); break; case 10: do_menu("keyboard_mouse"); break; case 11: do_menu(BXPN_MENU_DISK); break; case 12: do_menu("ports"); break; case 13: do_menu("network"); break; case 14: do_menu("sound"); break; case 15: do_menu("misc"); break; #if BX_PLUGINS case 16: do_menu("user"); break; #endif default: BAD_OPTION(menu, choice); } break; case BX_CI_RUNTIME: { bx_list_c *cdromop = NULL; char pname[80]; char prompt[1024]; build_runtime_options_prompt(runtime_menu_prompt, prompt, 1024); if (ask_uint(prompt, "", 1, BX_CI_RT_QUIT, BX_CI_RT_CONT, &choice, 10) < 0) return -1; switch (choice) { case BX_CI_RT_FLOPPYA: if (SIM->get_param_enum(BXPN_FLOPPYA_DEVTYPE)->get() != BX_FDD_NONE) do_menu(BXPN_FLOPPYA); break; case BX_CI_RT_FLOPPYB: if (SIM->get_param_enum(BXPN_FLOPPYB_DEVTYPE)->get() != BX_FDD_NONE) do_menu(BXPN_FLOPPYB); break; case BX_CI_RT_CDROM1: case BX_CI_RT_CDROM2: case BX_CI_RT_CDROM3: case BX_CI_RT_CDROM4: int device; if (SIM->get_cdrom_options(choice - BX_CI_RT_CDROM1, &cdromop, &device) && SIM->get_param_bool("present", cdromop)->get()) { cdromop->get_param_path(pname, 80); do_menu(pname); } break; case BX_CI_RT_IPS: // not implemented yet because I would have to mess with // resetting timers and pits and everything on the fly. // askparam(BXPN_IPS); break; case BX_CI_RT_LOGOPTS1: bx_log_options(0); break; case BX_CI_RT_LOGOPTS2: bx_log_options(1); break; case BX_CI_RT_INST_TR: NOT_IMPLEMENTED(choice); break; case BX_CI_RT_USB: do_menu(BXPN_MENU_RUNTIME_USB); break; case BX_CI_RT_MISC: do_menu(BXPN_MENU_RUNTIME_MISC); break; case BX_CI_RT_CONT: SIM->update_runtime_options(); fprintf(stderr, "Continuing simulation\n"); return 0; case BX_CI_RT_QUIT: fprintf(stderr, "You chose quit on the configuration interface.\n"); bx_user_quit = 1; #if !BX_DEBUGGER bx_atexit(); SIM->quit_sim(1); #else bx_dbg_exit(1); #endif return -1; default: fprintf(stderr, "Menu choice %d not implemented.\n", choice); } } break; default: fprintf(stderr, "Unknown config interface menu type.\n"); assert(menu >=0 && menu < BX_CI_N_MENUS); } } }