+//Print out usage for errors in command line
+void printUse() {
+ std::cout << "USAGE: ar [-X32_64] [-]{dmpqrstx}[abcfilNoPsSuvV] [member-name] [count] archive-file [files..]\n\n";
+
+ std::cout << "commands:\n" <<
+ "d - delete file(s) from the archive\n"
+ << "m[ab] - move file(s) in the archive\n"
+ << "p - print file(s) found in the archive\n"
+ << "q[f] - quick append file(s) to the archive\n"
+ << "r[ab][f][u] - replace existing or insert new file(s) into the archive\n"
+ << "t - display contents of archive\n"
+ << "x[o] - extract file(s) from the archive\n";
+
+ std::cout << "\ncommand specific modifiers:\n"
+ << "[a] - put file(s) after [member-name]\n"
+ << "[b] - put file(s) before [member-name] (same as [i])\n"
+ << "[N] - use instance [count] of name\n"
+ << "[f] - truncate inserted file names\n"
+ << "[P] - use full path names when matching\n"
+ << "[o] - preserve original dates\n"
+ << "[u] - only replace files that are newer than current archive contents\n";
+
+ std::cout << "generic modifiers:\n"
+ << "[c] - do not warn if the library had to be created\n"
+ << "[s] - create an archive index (cf. ranlib)\n"
+ << "[S] - do not build a symbol table\n"
+ << "[v] - be verbose\n"
+ << "[V] - display the version number\n";
+ exit(1);
+}
+
+
+//Print version
+void printVersion() {
+ cout << VERSION;
+ exit(0);
+}
+
+//Extract the memberfile name from the command line
+void getRelPos() {
+ if(RestofArgs.size() > 0) {
+ RelPos = RestofArgs[0];
+ RestofArgs.erase(RestofArgs.begin());
+ }
+ //Throw error if needed and not present
+ else
+ printUse();
+}
+
+//Extract count from the command line
+void getCount() {
+ if(RestofArgs.size() > 0) {
+ Count = atoi(RestofArgs[0].c_str());
+ RestofArgs.erase(RestofArgs.begin());
+ }
+ //Throw error if needed and not present
+ else
+ printUse();
+}
+
+//Get the Archive File Name from the command line
+void getArchive() {
+ std::cerr << RestofArgs.size() << "\n";
+ if(RestofArgs.size() > 0) {
+ Archive = RestofArgs[0];
+ RestofArgs.erase(RestofArgs.begin());
+ }
+ //Throw error if needed and not present
+ else
+ printUse();
+}
+
+
+//Copy over remaining items in RestofArgs to our Member File vector.
+//This is just for clarity.
+void getMembers() {
+ std::cerr << RestofArgs.size() << "\n";
+ if(RestofArgs.size() > 0)
+ Members = vector<string>(RestofArgs);
+}
+
+// Parse the operations and operation modifiers
+// FIXME: Not all of these options has been implemented, but we still
+// do all the command line parsing for them.
+void parseCL() {
+
+ //Keep track of number of operations. We can only specify one
+ //per execution
+ unsigned NumOperations = 0;
+
+ for(unsigned i=0; i<Options.size(); ++i) {
+ switch(Options[i]) {
+ case 'd':
+ ++NumOperations;
+ Delete = true;
+ break;
+ case 'm':
+ ++NumOperations;
+ Move = true;
+ break;
+ case 'p':
+ ++NumOperations;
+ Print = true;
+ break;
+ case 'r':
+ ++NumOperations;
+ InsertWithReplacement = true;
+ break;
+ case 't':
+ ++NumOperations;
+ DisplayTable = true;
+ break;
+ case 'x':
+ ++NumOperations;
+ Extract = true;
+ break;
+ case 'a':
+ AddAfter = true;
+ getRelPos();
+ break;
+ case 'b':
+ AddBefore = true;
+ getRelPos();
+ break;
+ case 'c':
+ Create = true;
+ break;
+ case 'f':
+ TruncateNames = true;
+ break;
+ case 'i':
+ InsertBefore = true;
+ getRelPos();
+ break;
+ case 'l':
+ break;
+ case 'N':
+ UseCount = true;
+ getCount();
+ break;
+ case 'o':
+ OriginalDates = true;
+ break;
+ case 'P':
+ FullPath = true;
+ break;
+ case 's':
+ SymTable = true;
+ break;
+ case 'S':
+ SymTable = false;
+ break;
+ case 'u':
+ OnlyUpdate = true;
+ break;
+ case 'v':
+ Verbose = true;
+ break;
+ case 'V':
+ printVersion();
+ break;
+ default:
+ printUse();
+ }
+ }
+
+ //Check that only one operation has been specified
+ if(NumOperations > 1)
+ printUse();
+
+ getArchive();
+ getMembers();
+
+}