Exemplo n.º 1
0
Arquivo: fix-db.c Projeto: NUOG/ejudge
int
main(int argc, char *argv[])
{
  program_name = os_GetBasename(argv[0]);
  logger_set_level(-1, LOG_WARNING);

  if (argc < 1) die("not enough parameters");

  if (argc == 2) {
    if (!strcmp(argv[1], "--help")) {
      write_help();
    } else if (!strcmp(argv[1], "--version")) {
      write_version();
    }
  }

#if defined EJUDGE_XML_PATH
  if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH;
#endif /* EJUDGE_XML_PATH */
  if (!ejudge_xml_path) die("ejudge.xml path is not specified");
  if (!(ejudge_config = ejudge_cfg_parse(ejudge_xml_path, 1))) return 1;
  if (!ejudge_config->contests_dir) die("<contests_dir> tag is not set!");
  if (contests_set_directory(ejudge_config->contests_dir) < 0)
    die("contests directory is invalid");

  load_mysql_plugin();

  /* consult the main compilation configuration */
  compile_cfg_path[0] = 0;
  if (ejudge_config->compile_home_dir) {
    snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/conf/compile.cfg",
             ejudge_config->compile_home_dir);
  }
  if (!compile_cfg_path[0] && ejudge_config->contests_home_dir) {
    snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/compile/conf/compile.cfg",
             ejudge_config->contests_home_dir);
  }
#if defined EJUDGE_CONTESTS_HOME_DIR
  if (!compile_cfg_path[0]) {
    snprintf(compile_cfg_path, sizeof(compile_cfg_path), "%s/compile/conf/compile.cfg",
             EJUDGE_CONTESTS_HOME_DIR);
  }
#endif

  cs_config = prepare_parse_config_file(compile_cfg_path, 0);
  if (!cs_config) {
    die("failed to parse compilation configuration file %s", compile_cfg_path);
  }
  handle_cs_config();

  process_all_contests();

  return 0;
}
Exemplo n.º 2
0
static void write_help_adapter(slice_index si, stip_structure_traversal *st)
{
  state_type * const state = st->param;
  stip_length_type const save_length = state->length;
  structure_traversal_level_type const save_level = state->branch_level;

  state->branch_level = st->level;
  state->length = SLICE_U(si).branch.length;

  if (is_series(si))
    write_series(si,st);
  else
    write_help(si,st);

  state->length = save_length;
  state->branch_level = save_level;
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
  int i = 1, r = 0;
  const char *command = 0;
  const char *ejudge_xml_path = 0;
  struct ejudge_cfg *config = 0;
  int cmd = 0;
  int super_serve_fd = -1;
  int signum = 0;
  const unsigned char *signame = "";
  int pid;

  program_name = os_GetBasename(argv[0]);
  if (argc < 2) startup_error("not enough parameters");

  if (!strcmp(argv[i], "--help")) {
    write_help();
  } else if (!strcmp(argv[i], "--version")) {
    write_version();
  }

  command = argv[i];
  i++;

  if (i < argc) {
    ejudge_xml_path = argv[i];
    i++;
  }

  if (i < argc) startup_error("too many parameters");

#if defined EJUDGE_XML_PATH
  if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH;
#endif /* EJUDGE_XML_PATH */

  if (!ejudge_xml_path) startup_error("ejudge.xml path is not specified");

  if (!(config = ejudge_cfg_parse(ejudge_xml_path))) return 1;

  if (!strcmp(command, "stop")) {
    cmd = SSERV_CMD_STOP;
    signum = START_STOP;
    signame = "TERM";
  } else if (!strcmp(command, "restart")) {
    cmd = SSERV_CMD_RESTART;
    signum = START_RESTART;
    signame = "HUP";
  } else {
    startup_error("invalid command");
  }

  (void) signame;
  (void) signum;

  if (!(pid = start_find_process("ej-super-server", 0))) {
    op_error("ej-super-server is not running");
  } else if (pid > 0) {
    /*
    fprintf(stderr, "%s: ej-super-server is running as pid %d\n",
            program_name, pid);
    fprintf(stderr, "%s: sending it the %s signal\n", program_name, signame);
    if (start_kill(pid, signum) < 0) op_error("failed: %s", os_ErrorMsg());
    return 0;
    */
  }

  if ((super_serve_fd = super_clnt_open(config->super_serve_socket)) < 0)
    op_error("ej-super-server is not running");
  r = super_clnt_control(super_serve_fd, cmd);
  if (r < 0) op_error("%s", super_proto_strerror(-r));

  return 0;
}
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
  int i = 1;
  char *eptr = 0;
  int total_clars, clar_id;
  struct clar_entry_v2 clar;
  unsigned char *text = 0;
  size_t size = 0;

  program_name = os_GetBasename(argv[0]);

  if (argc <= 1) die("not enough parameters");

  if (!strcmp(argv[1], "--help")) {
    write_help();
  } else if (!strcmp(argv[1], "--version")) {
    write_version();
  }

  i = 1;
  while (i < argc) {
    if (!strcmp(argv[i], "-f")) {
      if (i + 1 >= argc) die("argument expected for `-f'");
      ejudge_xml_path = argv[i + 1];
      i += 2;
    } else if (!strcmp(argv[i], "--")) {
      i++;
      break;
    } else if (argv[i][0] == '-') {
      die("invalid option `%s'", argv[i]);
    } else {
      break;
    }
  }

#if defined EJUDGE_XML_PATH
  if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH;
#endif /* EJUDGE_XML_PATH */
  if (!ejudge_xml_path) die("ejudge.xml path is not specified");
  if (!(config = ejudge_cfg_parse(ejudge_xml_path))) return 1;
  if (!config->contests_dir) die("<contests_dir> tag is not set!");
  if (contests_set_directory(config->contests_dir) < 0)
    die("contests directory is invalid");

  if (i >= argc) die("contest-id is expected");
  if (!argv[i][0]) die("contest-id is not specified");
  errno = 0;
  contest_id = strtol(argv[i], &eptr, 10);
  if (*eptr || errno || contest_id <= 0 || contest_id > EJ_MAX_CONTEST_ID)
    die("contest-id is invalid");
  i++;

  if (i >= argc) die("source plugin name is expected");
  src_plugin_name = argv[i];
  i++;

  if (i >= argc) die("destination plugin name is expected");
  dst_plugin_name = argv[i];
  i++;

  if (i < argc) die("extra parameters");
  if (!src_plugin_name || !*src_plugin_name) src_plugin_name = "file";
  if (!dst_plugin_name || !*dst_plugin_name) dst_plugin_name = "file";

  if (!strcmp(src_plugin_name, dst_plugin_name))
    die("plugins are the same");

  if (contests_get(contest_id, &cnts) < 0 || !cnts)
    die("cannot load contest %d", contest_id);

  if (!(src_clarlog = clar_init()))
    die("cannot open the source clarlog");
  if (!(dst_clarlog = clar_init()))
    die("cannot open the destination clarlog");

  if (clar_open(src_clarlog, config, cnts, 0, src_plugin_name, 0) < 0)
    die("cannot open the source clarlog");
  if (clar_open(dst_clarlog, config, cnts, 0, dst_plugin_name, 0) < 0)
    die("cannot open the destination clarlog");

  total_clars = clar_get_total(src_clarlog);
  for (clar_id = 0; clar_id < total_clars; clar_id++) {
    if (clar_get_record(src_clarlog, clar_id, &clar) < 0) continue;
    if (clar.id < 0) continue;
    if (!ej_uuid_is_nonempty(clar.uuid)) {
      ej_uuid_generate(&clar.uuid);
    }
    clar_put_record(dst_clarlog, clar_id, &clar);
    if (clar_get_raw_text(src_clarlog, clar_id, &text, &size) < 0) continue;
    clar_add_text(dst_clarlog, clar_id, &clar.uuid, text, size);
    xfree(text); text = 0; size = 0;
  }
  return 0;
}