All Classes Files Functions Variables Enumerations Enumerator Macros
readArgs.cpp
Go to the documentation of this file.
1 #include "options.hpp"
10 
16 // Read command line args into their appropriate vars
17 bool ConfigOpts::argsRead( int argCount, char **argVar )
18 {
19  // Create an error flag and set to false
20  bool errorFlag = 0;
21  // Create an error argument holder
22  string errorArg = "";
23  // Create a pointer to a bool array to work with arguments
24  bool *p_hyph = new bool[ argCount ];
25  // Create a pointer to a string array to work with arguments
26  string *p_args = new string[ argCount ];
27 
28  // Skip the first argument - program name.
29  for( int i = 1; i <= argCount; i++ )
30  {
31  // Store each argument into an array
32  p_args[i-1] = argVar[i];
33  }
34 
35  // Check each argument for a hyphen
36  for( int i = 0; i < argCount; i++ )
37  {
38  // If the argument starts with '-'
39  if( p_args[i][0] == '-' )
40  {
41  // Set the flag array element to true
42  p_hyph[i] = 1;
43  }
44  // If the argument doesn't start with '-'
45  else
46  {
47  // Set the flag array element to false
48  p_hyph[i] = 0;
49  }
50  }
51 
52  // Check each of the flagged items
53  for( int i = 0; i < argCount && errorFlag == 0; i++ )
54  {
55  // If the first char is a hyphen, and there is no error
56  if( p_hyph[i] == 1 && errorFlag == 0 )
57  {
58  // Go through and check for valid flags and set the vars
59  for( unsigned int j = 1; j < p_args[i].length() && errorFlag == 0; j++ )
60  {
61  // User flag switch
62  switch( p_args[i][j] ) {
63  case 'R':
64  // Recurse directories
66  break;
67  case 'D':
68  // Season folder is double digits
70  break;
71  case 'B':
72  // Blacklist location
73  if( i+1 <= argCount-1 )
74  {
75  setOptions( BlackListLocation_opt, p_args[i+1] );
76  }
77  break;
78  case 'S':
79  // Showlist location
80  if( i+1 <= argCount-1 )
81  {
82  setOptions( ShowListLocation_opt, p_args[i+1] );
83  }
84  break;
85  case 'i':
86  // Input directory or file
87  if( i+1 <= argCount-1 )
88  {
89  setOptions( InputSourceArgument_opt, p_args[i+1] );
91  }
92  break;
93  case 'o':
94  // Output directory
95  if( i+1 <= argCount-1 )
96  {
97  setOptions( OutputSourceArgument_opt, p_args[i+1] );
99  }
100  break;
101  case 'e':
102  // Perform the execution internally
104  break;
105  case 't':
106  // Do not execute - output to stdout
108  break;
109  case 'b':
110  // Write a script for execution
111  if( i+1 <= argCount-1 )
112  {
113  setOptions( ScriptFileLocation_opt, p_args[i+1] );
115  }
116  break;
117  case 'r':
118  // Rename the input files
120  break;
121  case 'm':
122  // Move the input files
124  break;
125  case 'c':
126  // Copy the input files
128  break;
129  case 'q':
130  // Output nothing
132  break;
133  case 's':
134  // Output summary information
136  break;
137  case 'v':
138  // Output summary and error information
140  break;
141  case 'l':
142  // Log file name and location
143  if( i+1 <= argCount-1 )
144  {
145  setOptions( LogFileLocation_opt, p_args[i+1] );
147  }
148  break;
149  case 'x':
150  // XML file name and location
151  if( i+1 <= argCount-1 )
152  {
153  setOptions( XmlFileLocation_opt, p_args[i+1] );
155  }
156  break;
157  case 'g':
158  // Gap file name and location
159  if( i+1 <= argCount-1 )
160  {
161  setOptions( GapFileLocation_opt, p_args[i+1] );
163  }
164  break;
165  default:
166  // Set the error flag to true
167  errorFlag = 1;
168  // Store the unmatched argument
169  errorArg = p_args[i][j];
170  }//end switch
171  }//end for
172  }//end if
173  } //end for
174 
175  // Check command line args
176  errorFlag = argsCheck( errorFlag, errorArg );
177 
178  // Clean up
179  delete [] p_hyph;
180  delete [] p_args;
181 
182  // Return 0 = success
183  return errorFlag;
184 }
185 
191 // Read command line args into their appropriate vars
192 bool ConfigOpts::argsCheck( int errorFlag, string errorArg )
193 {
194  // If the error flag is true
195  if( errorFlag == 1 )
196  {
197  // Print the argument that caused the error
198  cout << "Incorrect argument: -" << errorArg << endl
199  << "run 'clerk -h' for more information" << endl;
200  }
201  // If config file not found flag is true
203  {
204  // Print how to create files
205  cout << "run 'clerk -F <DIR>' to create clerk.conf" << endl
206  << "in one of the above directories" << endl;
207  }
208  // If the error flag is set to false
209  if( errorFlag == 0 )
210  {
211  // Place the input directory/file into a temporary holder
212  string inputArg = getOptions( InputSourceArgument_opt );
213  // Check for trailing slashes on the input argument
214  while( inputArg[inputArg.length()-1] == SLASH[0] )
215  {
216  // Remove the last character
217  inputArg.erase( inputArg.length()-1, 1 );
218  }
219  // Save the input directory/file
220  setOptions( InputSourceArgument_opt, inputArg );
221  // Place the output directory into a temporary holder
222  string outputArg = getOptions( OutputSourceArgument_opt );
223  // Check for trailing slashes on the output argument
224  while( outputArg[outputArg.length()-1] == SLASH[0] )
225  {
226  // Remove the last character
227  outputArg.erase( outputArg.length()-1, 1 );
228  }
229  // Save the output directory
230  setOptions( OutputSourceArgument_opt, outputArg );
231  }
232 
233  // Return 1 = failure
234  return errorFlag;
235 }
season is double digit
Definition: options.hpp:113
static bool getFlags(flagValue)
Retrieves the user configuration flags from an array.
Definition: mainPublic.cpp:280
output summary and error information
Definition: options.hpp:109
move the input files
Definition: options.hpp:105
perform an internal action instead of writing a script
Definition: options.hpp:101
the location of the blacklist file
Definition: options.hpp:70
static bool argsCheck(int, string)
Reads command line args into their appropriate variables. (WTF?)
Definition: readArgs.cpp:192
copy the input files
Definition: options.hpp:106
rewrite showlist, blacklist, config files
Definition: options.hpp:114
not sure if needed (WTF?)
Definition: options.hpp:99
holds xml file name and location
Definition: options.hpp:89
#define SLASH
Definition: options.hpp:32
static string getOptions(optionValue)
Retrieves the user configuration options from an array.
Definition: mainPublic.cpp:129
output directory from args
Definition: options.hpp:80
not sure if needed (WTF?)
Definition: options.hpp:100
static bool argsRead(int, char **)
Reads command line args into their appropriate variables.
Definition: readArgs.cpp:17
holds gap file name and location
Definition: options.hpp:90
recurse directories
Definition: options.hpp:98
holds script file name and location
Definition: options.hpp:82
take no real actions - just output to stdout
Definition: options.hpp:102
write a script instead of internal action
Definition: options.hpp:103
output to log instead of stdout
Definition: options.hpp:110
rename the input files
Definition: options.hpp:104
The ConfigOpts class stores all config options, settings, and flags for clerk.
input directory/file from args
Definition: options.hpp:79
static void setFlags(flagValue)
Sets the user configuration flags into an array.
Definition: mainPublic.cpp:137
holds log file name and location
Definition: options.hpp:81
the location of the showlist file
Definition: options.hpp:71
static void setOptions(optionValue, string)
Sets the user configuration options into an array.
Definition: mainPublic.cpp:105