All Classes Files Functions Variables Enumerations Enumerator Macros
readOpts.cpp
Go to the documentation of this file.
1 #include "options.hpp"
10 
12 // Read config args into their appropriate vars
14 {
15  // Create a input file stream object
16  ifstream infile;
17  // Create an error flag and set to false
18  bool errorFlag = 0;
19  // Define 3 possible locations for the config file
20  string location[3] = { LOC1"clerk.conf", LOC2"clerk.conf", LOC3"clerk.conf" };
21 
22  // Check each of the 3 possible locations for the config file
23  for( int i = 0; i < 3; i++ )
24  {
25  // Create a char array that can used by the input file stream object and set it to one of the locations
26  const char *fileLocation = location[i].c_str();
27  // Attempt to open the file
28  infile.open( fileLocation );
29  // If the file doesn't exist at the location
30  if( !infile.is_open() )
31  {
32  // Set the error flag to true
33  errorFlag = 1;
34  }
35  // If the the file does exist at the location
36  else
37  {
38  // Set the error flag to false
39  errorFlag = 0;
40  // Stop searching for the config file
41  break;
42  }
43  }
44 
45  // If the error flag is set to true
46  if( errorFlag )
47  {
48  cout << "Warning: clerk.conf not found at "LOC1" or "LOC2" or "LOC3 << endl
49  << "Using default configuration options as follows:" << endl << endl;
50  // Set the flag - clerk.conf not found
52  }
53  else
54  {
55  // Read the configuration options
56  // Create a temporary config line counter
57  int count = 0;
58 
59  // Read the config file until EOF
60  while( !infile.eof() )
61  {
62  // Create a temporary line holder
63  string temp = "";
64  // Read a line from the config file and store in the temporary holder
65  getline( infile, temp );
66  // Count a line read from the config file and store in the temporary counter
67  count++;
68  // If the line isn't commented out and more than 2 characters
69  if( temp[0] != '#' && temp.length() > 2 )
70  {
71  // Create argument and value holders
72  string Arg, Val;
73  // Store anything before the = as the argument
74  Arg = temp.substr( 0, temp.find( '=' ) );
75  // Store anything after the = as the value
76  Val = temp.substr( temp.find( '=' )+1 );
77 
78  // The location of the blacklist file
79  if( Arg == "BLACKLIST" )
80  {
82  }
83  // The location of the showlist file
84  else if( Arg == "SHOWLIST" )
85  {
87  }
88  // The delimters used to parse showlist lines
89  else if( Arg == "SHOWDELIM" )
90  {
92  }
93  // Recurse directories
94  else if( Arg == "RECURSE" )
95  {
96  setOptions( Recurse_opt, Val );
97  if ( Val == "YES" || Val == "Yes" || Val == "yes" || Val == "ON" || Val == "On" || Val == "on" )
98  {
100  }
101  }
102  // Input directory or file
103  else if( Arg == "INPUT" )
104  {
106  if( Val.length() > 0 )
107  {
108  setFlags( Input_flag );
109  }
110  }
111  // Output directory
112  else if( Arg == "OUTPUT" )
113  {
115  if( Val.length() > 0 )
116  {
118  }
119  }
120  // Select the operation mode
121  else if( Arg == "MODE" )
122  {
123  setOptions( Mode_opt, Val );
124  // Rename the input files
125  if( Val == "rename" )
126  {
128  }
129  // Move the input files
130  else if( Val == "move" )
131  {
133  }
134  // Copy the input files
135  else if( Val == "copy" )
136  {
138  }
139  }
140  // Select the execution mode
141  else if( Arg == "EXEC" )
142  {
143  setOptions( Execute_opt, Val );
144  // Perform the execution internally
145  if( Val == "execute" )
146  {
148  }
149  // Write a script for execution
150  else if( Val == "script" )
151  {
153  }
154  // Do not execute - output to stdout
155  else if( Val == "test" )
156  {
158  }
159  }
160  // Script file name and location
161  else if( Arg == "SCRIPT" )
162  {
164  }
165  // Log file name and location
166  else if( Arg == "LOG" )
167  {
169  if( Val.length() > 0 )
170  {
172  }
173  }
174  // Choose the output level
175  else if( Arg == "LEVEL" )
176  {
178  // Output nothing
179  if( Val == "quiet" )
180  {
182  }
183  // Output summary information
184  if( Val == "summary" )
185  {
187  }
188  // Output summary and error information
189  if( Val == "verbose" )
190  {
192  }
193  }
194  // Max size of a episode, in bytes
195  else if( Arg == "SIZE" )
196  {
198  }
199  // Add a seperator between the season and title information
200  else if( Arg == "SEPARATE" )
201  {
202  setOptions( TitleFormat_opt, Val );
203  }
204  // File types that should be filtered out
205  else if( Arg == "FILTER" )
206  {
208  }
209  // The delimters used to parse the file filter
210  else if( Arg == "FILTERDELIM" )
211  {
213  }
214  // Space filler
215  else if( Arg == "FILLER" )
216  {
217  setOptions( Filler_opt, Val );
218  }
219  // Words that should not be uppercased
220  else if( Arg == "NOCASE" )
221  {
223  }
224  // The delimters used to parse the no uppercased word list
225  else if( Arg == "NOCASEDELIM" )
226  {
228  }
229  else if( Arg == "SEASONDD" )
230  {
231  setOptions( SeasonDigit_opt, Val );
232  if( Val == "YES" || Val == "Yes" || Val == "yes" || Val == "ON" || Val == "On" || Val == "on" )
233  {
235  }
236  }
237  // XML file name and location
238  else if( Arg == "XML" )
239  {
241  if( Val.length() > 0 )
242  {
244  }
245  }
246  // Gap file name and location
247  else if( Arg == "GAP" )
248  {
250  if( Val.length() > 0 )
251  {
253  }
254  }
255  else
256  {
257  cout << "Error: Incorrect argument in config file." << endl;
258  cout << "Line " << count << ": " << temp << endl << endl;
259  }
260  }
261  }
262 
263  // Close the opened file
264  infile.close();
265  }
266 
267  // Check if every configuration option is set, set to default for each that aren't
268  configCheck();
269 };
270 
272 // Set unset config options to default values
274 {
275  // Check if blacklist location option is set
276  if( getOptions( BlackListLocation_opt ).length() == 0 )
277  {
278  // Set blacklist location option
279  setOptions( BlackListLocation_opt, LOC1"blacklist" );
280  // If config.conf exists
282  {
283  cout << "Consider adding the following line to the config file:" << endl;
284  }
285  cout << "BLACKLIST="LOC1"blacklist" << endl << endl;
286  }
287 
288  // Check if showlist location option is set
289  if( getOptions( ShowListLocation_opt ).length() == 0 )
290  {
291  // Set showlist location option
292  setOptions( ShowListLocation_opt, LOC1"showlist" );
293  // If config.conf exists
295  {
296  cout << "Consider adding the following line to the config file:" << endl;
297  }
298  cout << "SHOWLIST="LOC1"showlist" << endl << endl;
299  }
300 
301  // Check if recurse option is set
302  if( getOptions( Recurse_opt ).length() == 0 )
303  {
304  // If config.conf exists
306  {
307  cout << "Consider adding the following line to the config file:" << endl;
308  }
309  cout << "RECURSE=NO" << endl << endl;
310  }
311 
312  // Check if input option is set
313  if( getOptions( InputSourceArgument_opt ).length() == 0 )
314  {
315  // Set to default
317  // Set to default
318  setFlags( Input_flag );
319  // If config.conf exists
321  {
322  cout << "Consider adding the following line to the config file:" << endl;
323  }
324  cout << "INPUT="SLASH"mnt"SLASH"vids" << endl << endl;
325  }
326 
327  // Check if output option is set
328  if( getOptions( OutputSourceArgument_opt ).length() == 0 )
329  {
330  // Set to default
332  // Set to default
334  // If config.conf exists
336  {
337  cout << "Consider adding the following line to the config file:" << endl;
338  }
339  cout << "OUTPUT="SLASH"mnt"SLASH"vids" << endl << endl;
340  }
341 
342  // Check if script option is set
343  if( getOptions( ScriptFileLocation_opt ).length() == 0 )
344  {
345  // Set to default
347  // If config.conf exists
349  {
350  cout << "Consider adding the following line to the config file:" << endl;
351  }
352  cout << "SCRIPT="LOC1"clerk."SCRIPT2 << endl << endl;
353  }
354 
355  // Check if log option is set
357  {
358  // Set to default
359  setOptions( LogFileLocation_opt, LOC1"clerk.log" );
360  // Set to default
362  cout << "LOG="LOC1"clerk.log" << endl << endl;
363  }
364 
365  // Check if XML option is set
367  {
368  // Set to default
369  setOptions( XmlFileLocation_opt, LOC1"clerk.xml" );
370  // Set to default
372  cout << "XML="LOC1"clerk.xml" << endl << endl;
373  }
374 
375  // Check if gap option is set and there's no config file
377  {
378  // Set to default
379  setOptions( GapFileLocation_opt, LOC1"clerk.gap" );
380  // Set to default
382  cout << "GAP="LOC1"clerk.gap" << endl << endl;
383  }
384 
385  // Check if mode option is set
386  if( getOptions( Mode_opt ).length() == 0 )
387  {
388  // Set to move
390  // If config.conf exists
392  {
393  cout << "Consider adding the following line to the config file:" << endl;
394  }
395  cout << "MODE=move" << endl << endl;
396  }
397 
398  // Check if execute option is set
399  if( getOptions( Execute_opt ).length() == 0 )
400  {
401  // Set to script
403  // If config.conf exists
405  {
406  cout << "Consider adding the following line to the config file:" << endl;
407  }
408  cout << "EXEC=script" << endl << endl;
409  }
410 
411  // Check if output level option is set
412  if( getOptions( VerbosityLevel_opt ).length() == 0 )
413  {
414  // Set to verbose
416  // If config.conf exists
418  {
419  cout << "Consider adding the following line to the config file:" << endl;
420  }
421  cout << "LEVEL=verbose" << endl << endl;
422  }
423 
424  // Check if max episode size option is set
425  if( getOptions( MaxEpisodeSize_opt ).length() == 0 )
426  {
427  // Set max episode size option to 600MB
428  setOptions( MaxEpisodeSize_opt, "629145600" );
429  // If config.conf exists
431  {
432  cout << "Consider adding the following line to the config file:" << endl;
433  }
434  cout << "SIZE=2516582400" << endl << endl;
435  }
436 
437  // Check if the file filter option is set
438  if( getOptions( FileTypeFilter_opt ).length() == 0 )
439  {
440  // Set the file filter
441  setOptions( FileTypeFilter_opt, "txt;jpg;png;gif;nfo;rar;zip;cbz;url;srt;idx;sub;sfv;mht;htm;html;css;torrent;vob;exe;event;db;ini;r;" );
442  // Set the delimeter filter option
444  // If config.conf exists
446  {
447  cout << "Consider adding the following lines to the config file:" << endl;
448  }
449  cout << "FILTER=txt;jpg;png;gif;nfo;rar;zip;cbz;url;srt;idx;sub;sfv;mht;htm;html;css;torrent;vob;exe;event;db;ini;r;" << endl << endl;
450  cout << "FILTERDELIM=;" << endl << endl;
451  }
452 
453  // Check if the file filter delimeter option is set
454  if( getOptions( DelimiterFilter_opt ).length() == 0 )
455  {
456  // Set the file filter
457  setOptions( FileTypeFilter_opt, "txt;jpg;png;gif;nfo;rar;zip;cbz;url;srt;idx;sub;sfv;mht;htm;html;css;torrent;vob;exe;event;db;ini;r;" );
458  // Set the delimeter filter option
460  // If config.conf exists
462  {
463  cout << "Consider adding the following lines to the config file:" << endl;
464  }
465  cout << "FILTER=txt;jpg;png;gif;nfo;rar;zip;cbz;url;srt;idx;sub;sfv;mht;htm;html;css;torrent;vob;exe;event;db;ini;r;" << endl << endl;
466  cout << "FILTERDELIM=;" << endl << endl;
467  }
468 
469  // Check if delimShowList is empty
470  if( getOptions( ShowListDelimiter_opt ).length() == 0 )
471  {
472  // Set delimShowList to default
474  // If config.conf exists
476  {
477  cout << "Consider adding the following line to the config file:" << endl;
478  }
479  cout << "SHOWDELIM=/;*" << endl << endl;
480  }
481 
482  // Check if filler characters are defined
483  if( getOptions( Filler_opt ).length() == 0 )
484  {
485  // Default filler characters to remove
486  setOptions( Filler_opt, "._" );
487  // If config.conf exists
489  {
490  cout << "Consider adding the following line to the config file:" << endl;
491  }
492  cout << "FILLER=._" << endl << endl;
493  }
494 
495  // Check if title format options is set
496  if( getOptions( TitleFormat_opt ).length() == 0 )
497  {
498  // Set to default
499  setOptions( TitleFormat_opt, " - " );
501  cout << "Consider adding the following line to the config file:" << endl;
502  cout << "SEPARATE= - " << endl << endl;
503  }
504 
505  // Check if season digit option is set
506  if( getOptions( SeasonDigit_opt ).length() == 0 )
507  {
508  // If config.conf exists
510  {
511  cout << "Consider adding the following line to the config file:" << endl;
512  }
513  cout << "SEASONDD=NO" << endl << endl;
514  }
515 
516  // If the no capitalization list is not filled
517  if( getOptions( LowerCaseWords_opt ).length() == 0 )
518  {
519  // Fill the no capitalization list with articles, coordinate conjunctions, and prepositions
520  setOptions( LowerCaseWords_opt, " A * Amid * An * And * As * At * Atop * But * By * Down * For * From * In * Into * Is * Like * No * Nor * Near * Next * Of * Off * On * Onto * Or * Out * Over * Pace * Past * Per * Plus * Pro * Qua * Save * So * Than * The * Then * Till * To * Up * Upon * Vs * Via * Vice * With * Yet *" );
521  // Set the no capitalization delimeter to *
523  // If config.conf exists
525  {
526  cout << "Consider adding the following lines to the config file:" << endl;
527  }
528  cout << "NOCASE= A * Amid * An * And * As * At * Atop * But * By * Down * For * From * In * Into * Is * Like * No * Nor * Near * Next * Of * Off * On * Onto * Or * Out * Over * Pace * Past * Per * Plus * Pro * Qua * Save * So * Than * The * Then * Till * To * Up * Upon * Vs * Via * Vice * With * Yet *" << endl << endl;
529  cout << "NOCASEDELIM=*" << endl << endl;
530  }
531 
532  // If the no capitalization delimeter is not filled
533  if( getOptions( DelimiterWords_opt ).length() == 0 )
534  {
535  // Fill the no capitalization list with articles, coordinate conjunctions, and prepositions
536  setOptions( LowerCaseWords_opt, " A * Amid * An * And * As * At * Atop * But * By * Down * For * From * In * Into * Is * Like * No * Nor * Near * Next * Of * Off * On * Onto * Or * Out * Over * Pace * Past * Per * Plus * Pro * Qua * Save * So * Than * The * Then * Till * To * Up * Upon * Vs * Via * Vice * With * Yet *" );
537  // Set the no capitalization delimeter to *
539  // If config.conf exists
541  {
542  cout << "Consider adding the following lines to the config file:" << endl;
543  }
544  cout << "NOCASE= A * Amid * An * And * As * At * Atop * But * By * Down * For * From * In * Into * Is * Like * No * Nor * Near * Next * Of * Off * On * Onto * Or * Out * Over * Pace * Past * Per * Plus * Pro * Qua * Save * So * Than * The * Then * Till * To * Up * Upon * Vs * Via * Vice * With * Yet *" << endl << endl;
545  cout << "NOCASEDELIM=*" << endl << endl;
546  }
547 };
season is double digit
Definition: options.hpp:113
static bool getFlags(flagValue)
Retrieves the user configuration flags from an array.
Definition: mainPublic.cpp:280
max size of a episode, in bytes
Definition: options.hpp:69
#define LOC3
Definition: options.hpp:35
output summary and error information
Definition: options.hpp:109
move the input files
Definition: options.hpp:105
file types that should be filtered
Definition: options.hpp:73
perform an internal action instead of writing a script
Definition: options.hpp:101
holds season digit option
Definition: options.hpp:88
the location of the blacklist file
Definition: options.hpp:70
holds the output level option
Definition: options.hpp:87
#define SCRIPT2
Definition: options.hpp:31
copy the input files
Definition: options.hpp:106
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
#define LOC1
Definition: options.hpp:33
holds the execute option
Definition: options.hpp:86
not sure if needed (WTF?)
Definition: options.hpp:100
the delimters used to parse the file filter
Definition: options.hpp:74
the delimiters used to parse showlist lines
Definition: options.hpp:72
holds gap file name and location
Definition: options.hpp:90
recurse directories
Definition: options.hpp:98
static void configRead()
Reads configuration arguments into their appropriate variables from the configuration file...
Definition: readOpts.cpp:13
the delimters used to parse the no uppercased words
Definition: options.hpp:77
holds script file name and location
Definition: options.hpp:82
holds the recurse option
Definition: options.hpp:84
#define LOC2
Definition: options.hpp:34
take no real actions - just output to stdout
Definition: options.hpp:102
write a script instead of internal action
Definition: options.hpp:103
static void configCheck()
Sets any unset configuration options to their default values.
Definition: readOpts.cpp:273
output to log instead of stdout
Definition: options.hpp:110
holds the mode option
Definition: options.hpp:85
holds the season/episode and title separator
Definition: options.hpp:78
words that should not be uppercased
Definition: options.hpp:76
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