Esempio n. 1
0
int main(int argc, char ** argv)
{
  printf ("In main of %s: argc=%d\n",argv[0], argc);

  if (argc < 3) {
    usage();
    exit (1);
  }

  if (0 == strcmp(argv[1],"-c")) {
    createdevice(argv[2]);

  }
  else if (0 == strcmp(argv[1],"-r")) {
    removedevice(argv[2]);
  }
  else if (0 == strcmp(argv[1], "-p")) {
    if (argc < 4)
      goto usage;

    putdata(argv[2], argv[3]);
  }
  else if (0 == strcmp(argv[1], "-g")) {
    if (argc < 4)
        goto usage;

    if (0 == strcmp(argv[3], "new")) {
      getnewdata(argv[2]);

    } else {
      getolddata(argv[2]);

    }
  } else if (0 == strcmp(argv[1], "-ga")) {
    getalldata(argv[2]);
  } else if (0 == strcmp(argv[1], "-gb")) {
    getwithwait(argv[2]);
  } else if (0 == strcmp(argv[1], "-s")) {
    if (argc < 4)
      goto usage;
    selecttest(argv[2], argv[3]);
  } else {
    goto usage;
  }

  return 0;

 usage:
      usage();
      exit(1);

      return 1;

}
Esempio n. 2
0
void dojudge(int type) {
  LOG("Runid: " + Inttostring(bott->Getrunid()) + " Type: " +
      Inttostring(type));
  vector <string> in_files;
  if (!getalldata(bott->Getpid(), in_files, type) || in_files.size() == 0) {
    retbott.Settype(RESULT_REPORT);
    retbott.Setrunid(bott->Getrunid());
    retbott.Settime_used(0);
    retbott.Setmemory_used(0);
    retbott.Setresult("Judge Error (No Data)");
    retbott.Setout_filename("results/" + Inttostring(retbott.Getrunid()));
    retbott.toFile();
    send_result(retbott.Getout_filename());
    return;
  }
  string inpfile = CONFIG->GetTmpfile_path() + tmpnam();
  string stdout_file = CONFIG->GetTmpfile_path() + tmpnam();
  retbott.Settype(RESULT_REPORT);
  retbott.Setrunid(bott->Getrunid());
  usrprogram = new Program;
  usrprogram->Setlanguage(bott->Getlanguage());
  usrprogram->Setsource(bott->Getsrc());
  usrprogram->Sethas_input(true);
  usrprogram->Setin_filename(inpfile);
  usrprogram->Setout_filename(CONFIG->GetTmpfile_path() + tmpnam());
  usrprogram->Seterr_filename(CONFIG->GetTmpfile_path() + tmpnam());
  if (type == NEED_JUDGE)
    usrprogram->Settotal_time_limit(bott->Gettime_limit());
  else usrprogram->Settotal_time_limit(bott->Getcase_limit() * in_files.size());
  usrprogram->Setcase_time_limit(bott->Getcase_limit());
  usrprogram->Setmemory_limit(bott->Getmemory_limit());
  bool aced, peed, jeed = false, has = false;
  aced = peed = true;
  cmp = new Comparator;
  cmp->Setin_filename(inpfile);
  cmp->Setout_filename(usrprogram->Getout_filename());
  cmp->Setisspj(bott->Getspj());
  cmp->Setpid(bott->Getpid());
  for (unsigned int i = 0; i < in_files.size(); i++) {
    system(((string) "cp " + in_files[i] + ".in " + inpfile).c_str());
    LOG((string) "Do " + in_files[i]);
    usrprogram->Run();
    if (usrprogram->Getresult() != "Normal") {
      retbott.Setresult(usrprogram->Getresult());
      has = true;
      break;
    } else {
      system(((string) "cp " + in_files[i] + ".out " + stdout_file).c_str());
      system(((string) "chmod 755 " + stdout_file).c_str());
      system(((string) "chmod 755 " + inpfile).c_str());
      cmp->Setstdout_filename(stdout_file);
      cmp->Setsrc_filename(usrprogram->Getsrc_filename());
      int cres = cmp->Compare();
      system(((string) "rm " + stdout_file).c_str());
      system(((string) "chmod 600 " + inpfile).c_str());
      if (cres == PE_STATUS) aced = false;
      else if (cres == JE_STATUS) {
        jeed = false;
        break;
      } else if (cres != AC_STATUS) {
        aced = peed = false;
        break;
      }
    }
  }
  retbott.Setce_info(usrprogram->Getce_info());
  retbott.Settime_used(usrprogram->Gettime_used());
  retbott.Setmemory_used(usrprogram->Getmemory_used());
  if (has) retbott.Setresult(usrprogram->Getresult());
  else if (jeed) retbott.Setresult("Judge Error (No SPJ)");
  else if (aced) {
    if (type == DO_PRETEST) retbott.Setresult("Pretest Passed");
    else retbott.Setresult("Accepted");
  } else if (peed) retbott.Setresult("Presentation Error");
  else retbott.Setresult("Wrong Answer");
  retbott.Setout_filename("results/" + Inttostring(retbott.Getrunid()));
  retbott.toFile();
  delete cmp;
  delete usrprogram;
  send_result(retbott.Getout_filename());
}