-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineArguments.cpp
More file actions
62 lines (59 loc) · 1.89 KB
/
CommandLineArguments.cpp
File metadata and controls
62 lines (59 loc) · 1.89 KB
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
#include "CommandLineArguments.h"
CommandLineArguments::CommandLineArguments()
{
memset(input_file_name,0,COMMAND_LINE_ARGUMENT_MAX_SIZE);
memset(output_file_name,0,COMMAND_LINE_ARGUMENT_MAX_SIZE);
memset(error_string,0,ERROR_STRING_MAX_SIZE);
mappers = 0;
reducers = 0;
sample_size = 0;
}
bool CommandLineArguments::parser(int argc,char ** argv)
{
if ( argc %2 == 0 || argc < 2) return false;
else
{
for ( uint8_t i = 1 ; i < argc ; i +=2)
{
if ( strcmp(argv[i],"--input-file") == 0)
strncpy(input_file_name,argv[i+1],COMMAND_LINE_ARGUMENT_MAX_SIZE-1);
else if ( strcmp(argv[i],"--output-file") == 0)
strncpy(output_file_name,argv[i+1],COMMAND_LINE_ARGUMENT_MAX_SIZE-1);
else if ( strcmp(argv[i],"--mappers") == 0)
{
mappers =atoi(argv[i+1]);
}
else if ( strcmp(argv[i],"--reducers") == 0)
{
reducers =atoi(argv[i+1]);
}
else if ( strcmp(argv[i],"--sample-size") == 0)
{
sample_size =atoi(argv[i+1]);
}
else
{
sprintf(error_string,"undefined parameter: %s\n",argv[i]);
return false;
}
}
if ( strcmp (input_file_name,"") == 0 || strcmp (output_file_name,"") == 0 ||
mappers == 0 || reducers == 0 | sample_size == 0 ) return false;
else return true;
}
}
bool CommandLineArguments::execute()
{
TeraSort <TeraSortItem,teraitem_r> * teraSort =
new TeraSort <TeraSortItem,teraitem_r> (input_file_name,output_file_name,mappers,reducers,sample_size);
teraSort->execute();
delete(teraSort);
return true;
}
char * CommandLineArguments::getErrorString()
{
return error_string;
}
CommandLineArguments::~CommandLineArguments()
{
}