forked from shashankkumar/CodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·120 lines (106 loc) · 3.38 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**************************************************************************
CodeRunner - the online judge
Author: Shashank Kumar <[email protected]>
Copyright (c): 2011 All rights reserved
Version: 1.5
* This is a free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
You may contact the author of CodeRunner by e-mail at:
****************************************************************************/
#include "includeh.h"
#include "FileInfo.h"
#include "ContentParser.h"
#include "FileHandle.h"
int main(int argc, char* argv[])
{
if(chdir(PATH)==-1)
{
printf("%d\n", errno);
printf("IE ERROR Cannot change directory to the one specified in config.h");
return 1;
}
int opt;
int SleepInterval = SLEEPINTERVAL;
bool RunOnce = false;
bool DownloadSourceFile = true;
FileInfoFetchOptionsStruct* FileInfoFetchOptions = new FileInfoFetchOptionsStruct();
FileInfoFetchOptions->Init();
while((opt = getopt(argc, argv, "ncbfr:p:l:s:")) != -1){
switch(opt){
case 'f':
FileInfoFetchOptions->f=true;
FileInfoFetchOptions->FileInfo.FileId = atoi(optarg);
break;
case 'p':
FileInfoFetchOptions->p=true;
strcpy(FileInfoFetchOptions->FileInfo.ProblemId, optarg);
break;
case 'l':
FileInfoFetchOptions->l=true;
strcpy(FileInfoFetchOptions->FileInfo.lang, optarg);
break;
case 'b':
CurlWrapper::ForcePushResult=true;
break;
case 'c':
FileHandle::Clean=true;
break;
case 'n':
FileHandle::SendResultsVar=false;
break;
case 's':
SleepInterval = atoi(optarg);
break;
case 'r':
RunOnce = true;
break;
case 'd':
FileHandle::DownloadSourceFile = false;
break;
case 'v':
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-f fileid [-d -p problemcode -t timelimit -m memorylimit -l lang] | [-p problemcode] [-l language] ] [-s sleepinterval] [-b] [-n] [-c] [-r] [-d] [-v]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
if(FileInfoFetchOptions->f && (FileInfoFetchOptions->p || FileInfoFetchOptions->l)){
fprintf(stderr, "Usage: %s [-f fileid | [-p problemcode] [-l language]] [-b]\n", argv[0]);
exit(EXIT_FAILURE);
}
Logs::OpenLogFile();
Logs::CodeRunnerStarted();
Logs::CloseLogFile();
do{
Logs::OpenLogFile();
bool CurrentIteration = true;
ContentParser *ContentVar = new ContentParser();
if(ContentVar->FetchFileInfoList(FileInfoFetchOptions)==-1){
CurrentIteration = false;
}
if(CurrentIteration && ContentVar->EndOfContent()){
Logs::WriteLine("File Queue Empty. Nothing to evaluate.");
CurrentIteration = false;
}
while(CurrentIteration && !ContentVar->EndOfContent()){
FileInfoStruct* FileInfo = ContentVar->GetNextFileInfo();
FileHandle F(FileInfo);
F.Action();
//delete FileInfo;
}
if(CurrentIteration) Logs::WriteLine("Current batch of files evaluated.");
delete ContentVar;
Logs::GoToSleep();
Logs::CloseLogFile();
sleep(SleepInterval);
}while(!RUNONCE);
return 0;
}