All Classes Files Functions Variables Enumerations Enumerator Macros
testArgs.cpp
Go to the documentation of this file.
1 #include "options.hpp"
7 
12 // Read command line args into their appropriate vars
13 bool ConfigOpts::argsTest( int argCount, char **argVar )
14 {
15  // Create an error flag and set to false
16  bool errorFlag = 0;
17  // Create a pointer to a bool array to work with arguments
18  bool *p_hyph = new bool[ argCount ];
19  // Create a pointer to a string array to work with arguments
20  string *p_args = new string[ argCount ];
21 
22  // Skip the first argument - program name
23  for( int i = 1; i <= argCount; i++ )
24  {
25  // Store each argument into an array
26  p_args[i-1] = argVar[i];
27  }
28 
29  // Check each argument for a hyphen
30  for( int i = 0; i < argCount; i++ )
31  {
32  // If the argument starts with '-'
33  if( p_args[i][0] == '-' )
34  {
35  // Set the flag array element to true
36  p_hyph[i] = 1;
37  }
38  // If the argument doesn't start with '-'
39  else
40  {
41  // Set the flag array element to false
42  p_hyph[i] = 0;
43  }
44  }
45 
46  // Check each of the flagged items
47  for( int i = 0; i < argCount && errorFlag == 0; i++ )
48  {
49  // If the first char is a hyphen
50  if( p_hyph[i] == 1 )
51  {
52  // Go through and check for test flags
53  for( unsigned int j = 1; j < p_args[i].length() && errorFlag == 0; j++ )
54  {
55  // Argument switch
56  switch( p_args[i][j] )
57  {
58  case 'h':
59  // Output help info
60  printHelp();
61  // Set error flag to true
62  errorFlag = 1;
63  break;
64  case 'V':
65  // Output version information
66  printVersion();
67  // Set error flag to true
68  errorFlag = 1;
69  break;
70  case 'F':
71  // Rewrite showlist, blacklist, config location
72  if( i+1 <= argCount-1 )
73  {
74  // Place the input directory/file into a temporary holder
75  string inputArg = p_args[i+1];
76  // Check for trailing slashes on the input argument
77  while( inputArg[inputArg.length()-1] == SLASH[0] )
78  {
79  // Remove the last character
80  inputArg.erase( inputArg.length()-1, 1 );
81  }
82  // Rewrite showlist, blacklist, and config files
83  writeFout( inputArg );
84  }
85  // Set error flag to true
86  errorFlag = 1;
87  break;
88  }//end switch
89  }//end for
90  }//end if
91  } //end for
92 
93  // Clean up
94  delete [] p_hyph;
95  delete [] p_args;
96 
97  // Return 0 = success
98  return errorFlag;
99 };
static bool argsTest(int, char **)
Reads command line arguments into their appropriate variables.
Definition: testArgs.cpp:13
static void printVersion()
Outputs the version information to the console.
Definition: outPut.cpp:110
static void writeFout(string)
Recreates the showlist, blacklist, and configuration files.
Definition: outPut.cpp:16
#define SLASH
Definition: options.hpp:32
The ConfigOpts class stores all config options, settings, and flags for clerk.
static void printHelp()
Outputs the help information to the console.
Definition: outPut.cpp:53