Example #1
0
/**
 * @brief Searches for a entrant either by name or id given by the user.
 * The function prompts the user with the choice of searching by name or by
 * the entrant id.
 * 
 * @param event Event structure. The result will be stored in this variable.
 * 
 * @return If successful the function returns a pointer to the entrant. If it
 * fails NULL is returned.
 */
ENTRANT *query_entrant(EVENT *event) {
    int response, ret;

    do {
        printf("\nSearch by name or entrant number?\n");
        printf("1. Number.\n2. Name.\n\n0. Back\n>> ");
        ret = scanf(" %d", &response);

        if (ret != 1) {
            continue;
        }

        if (response == 1) {
            response = ask_int("\nPlease enter a entrant ID:\n0. Back.",
                    0, event->entrants->size);
            if (response == 0) {
                return NULL;
            }
            return entrant_id_search(response, event->entrants);
        } else if (response == 2) {
            char response_str[256];

            ask_str("\nPlease enter entrant name:\n0. Back", response_str);
            if (strcmp(response_str, "0") == 0) {
                return NULL;
            }

            return entrant_name_search(response_str, event->entrants);
        } else if (response == 0) {
            return NULL;
        }

    } while (1);
}
Example #2
0
/**
 * @brief Prompts the user with the choice of loading the check point data from
 * file or entering it manually.
 * 
 * @param event Event data structure. The result will be stored in this 
 * variable.
 */
void load_cp_data(EVENT *event) {
    int i_response;
    do {
        i_response = ask_int("\n1. From file.\n2. Enter manually:\n0. Back", 0, 2);
        if (i_response == 0) {
            return;
        } else if (i_response == 1) {
            get_cp_data(event);
            return;
        } else if (i_response == 2) {

            do {
                int ret, node_id, entrant_id;
                NODE *node = NULL;
                ENTRANT *entrant = NULL;
                char time[20];
                char status;

                printf("Enter the cp data:\n>> ");
                ret = scanf(" %c %d %d %5s",
                        &status,
                        &node_id,
                        &entrant_id,
                        time);

                if (ret != 4) {
                    fprintf(stderr, "[!] Format error.\n");
                    continue;
                }

                node = node_id_search(node_id, event->nodes);
                if (node == NULL) {
                    fprintf(stderr, "[!] Format error.\n");
                    fprintf(stderr, "Node with '%d' does not exist.\n\n", node_id);

                    continue;
                }

                entrant = entrant_id_search(entrant_id, event->entrants);
                if (entrant == NULL) {
                    fprintf(stderr, "[!] Format error.\n");
                    fprintf(stderr, "Entrant with id '%d' does not exist.\n\n", entrant_id);

                    continue;
                }

                add_cp(event, status, node, entrant, time);
                return;
            } while (1);
        }
    } while (1);
}
Example #3
0
void bx_log_options(int individual)
{
  if (individual) {
    int done = 0;
    while (!done) {
      bx_print_log_action_table();
      Bit32s id, level, action;
      Bit32s maxid = SIM->get_n_log_modules();
      if (ask_int(log_options_prompt1, "", -1, maxid-1, -1, &id) < 0)
        return;
      if (id < 0) return;
      fprintf(stderr, "Editing log options for the device %s\n", SIM->get_prefix(id));
      for (level=0; level<SIM->get_max_log_level(); level++) {
        char prompt[1024];
        int default_action = SIM->get_log_action(id, level);
        sprintf(prompt, "Enter action for %s event: [%s] ", SIM->get_log_level_name(level), SIM->get_action_name(default_action));
        // don't show the no change choice (choices=3)
        if (ask_menu(prompt, "", log_level_n_choices_normal, log_level_choices, default_action, &action)<0)
          return;
        SIM->set_log_action(id, level, action);
      }
    }
  } else {
    // provide an easy way to set log options for all devices at once
    bx_print_log_action_table();
    for (int level=0; level<SIM->get_max_log_level(); level++) {
      char prompt[1024];
      int action, default_action = 3;  // default to no change
      sprintf(prompt, "Enter action for %s event on all devices: [no change] ", SIM->get_log_level_name(level));
      // do show the no change choice (choices=4)
      if (ask_menu(prompt, "", log_level_n_choices_normal+1, log_level_choices, default_action, &action)<0)
        return;
      if (action < 3) {
        SIM->set_default_log_action(level, action);
        SIM->set_log_action(-1, level, action);
      }
    }
  }
}
Example #4
0
int main(void){
	int n = ask_int("How many iterrations of Sommecarre would you like?\n");

	printf("result: %d\n", Sommecarre(n));
}
Example #5
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;
}