llvm-ar.cpp revision 4f2779b809f6a9bb5ca63b10d55f8302cca2c656
1//===-- llvm-ar.cpp - LLVM archive librarian utility ----------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// Builds up (relatively) standard unix archive files (.a) containing LLVM 11// bitcode or other files. 12// 13//===----------------------------------------------------------------------===// 14 15#include "Archive.h" 16#include "llvm/IR/LLVMContext.h" 17#include "llvm/IR/Module.h" 18#include "llvm/Support/CommandLine.h" 19#include "llvm/Support/FileSystem.h" 20#include "llvm/Support/Format.h" 21#include "llvm/Support/ManagedStatic.h" 22#include "llvm/Support/PrettyStackTrace.h" 23#include "llvm/Support/Signals.h" 24#include "llvm/Support/raw_ostream.h" 25#include <algorithm> 26#include <cstdlib> 27#include <fcntl.h> 28#include <memory> 29 30#if !defined(_MSC_VER) && !defined(__MINGW32__) 31#include <unistd.h> 32#else 33#include <io.h> 34#endif 35 36using namespace llvm; 37 38// Option for compatibility with AIX, not used but must allow it to be present. 39static cl::opt<bool> 40X32Option ("X32_64", cl::Hidden, 41 cl::desc("Ignored option for compatibility with AIX")); 42 43// llvm-ar operation code and modifier flags. This must come first. 44static cl::opt<std::string> 45Options(cl::Positional, cl::Required, cl::desc("{operation}[modifiers]...")); 46 47// llvm-ar remaining positional arguments. 48static cl::list<std::string> 49RestOfArgs(cl::Positional, cl::OneOrMore, 50 cl::desc("[relpos] [count] <archive-file> [members]...")); 51 52// MoreHelp - Provide additional help output explaining the operations and 53// modifiers of llvm-ar. This object instructs the CommandLine library 54// to print the text of the constructor when the --help option is given. 55static cl::extrahelp MoreHelp( 56 "\nOPERATIONS:\n" 57 " d[NsS] - delete file(s) from the archive\n" 58 " m[abiSs] - move file(s) in the archive\n" 59 " p[kN] - print file(s) found in the archive\n" 60 " q[ufsS] - quick append file(s) to the archive\n" 61 " r[abfiuRsS] - replace or insert file(s) into the archive\n" 62 " t - display contents of archive\n" 63 " x[No] - extract file(s) from the archive\n" 64 "\nMODIFIERS (operation specific):\n" 65 " [a] - put file(s) after [relpos]\n" 66 " [b] - put file(s) before [relpos] (same as [i])\n" 67 " [f] - truncate inserted file names\n" 68 " [i] - put file(s) before [relpos] (same as [b])\n" 69 " [N] - use instance [count] of name\n" 70 " [o] - preserve original dates\n" 71 " [P] - use full path names when matching\n" 72 " [s] - create an archive index (cf. ranlib)\n" 73 " [S] - do not build a symbol table\n" 74 " [u] - update only files newer than archive contents\n" 75 "\nMODIFIERS (generic):\n" 76 " [c] - do not warn if the library had to be created\n" 77 " [v] - be verbose about actions taken\n" 78); 79 80// This enumeration delineates the kinds of operations on an archive 81// that are permitted. 82enum ArchiveOperation { 83 Print, ///< Print the contents of the archive 84 Delete, ///< Delete the specified members 85 Move, ///< Move members to end or as given by {a,b,i} modifiers 86 QuickAppend, ///< Quickly append to end of archive 87 ReplaceOrInsert, ///< Replace or Insert members 88 DisplayTable, ///< Display the table of contents 89 Extract ///< Extract files back to file system 90}; 91 92// Modifiers to follow operation to vary behavior 93bool AddAfter = false; ///< 'a' modifier 94bool AddBefore = false; ///< 'b' modifier 95bool Create = false; ///< 'c' modifier 96bool TruncateNames = false; ///< 'f' modifier 97bool InsertBefore = false; ///< 'i' modifier 98bool UseCount = false; ///< 'N' modifier 99bool OriginalDates = false; ///< 'o' modifier 100bool FullPath = false; ///< 'P' modifier 101bool SymTable = true; ///< 's' & 'S' modifiers 102bool OnlyUpdate = false; ///< 'u' modifier 103bool Verbose = false; ///< 'v' modifier 104 105// Relative Positional Argument (for insert/move). This variable holds 106// the name of the archive member to which the 'a', 'b' or 'i' modifier 107// refers. Only one of 'a', 'b' or 'i' can be specified so we only need 108// one variable. 109std::string RelPos; 110 111// Select which of multiple entries in the archive with the same name should be 112// used (specified with -N) for the delete and extract operations. 113int Count = 1; 114 115// This variable holds the name of the archive file as given on the 116// command line. 117std::string ArchiveName; 118 119// This variable holds the list of member files to proecess, as given 120// on the command line. 121std::vector<std::string> Members; 122 123// This variable holds the (possibly expanded) list of path objects that 124// correspond to files we will 125std::set<std::string> Paths; 126 127// The Archive object to which all the editing operations will be sent. 128Archive* TheArchive = 0; 129 130// The name this program was invoked as. 131static const char *program_name; 132 133// show_help - Show the error message, the help message and exit. 134LLVM_ATTRIBUTE_NORETURN static void 135show_help(const std::string &msg) { 136 errs() << program_name << ": " << msg << "\n\n"; 137 cl::PrintHelpMessage(); 138 if (TheArchive) 139 delete TheArchive; 140 std::exit(1); 141} 142 143// fail - Show the error message and exit. 144LLVM_ATTRIBUTE_NORETURN static void 145fail(const std::string &msg) { 146 errs() << program_name << ": " << msg << "\n\n"; 147 if (TheArchive) 148 delete TheArchive; 149 std::exit(1); 150} 151 152// getRelPos - Extract the member filename from the command line for 153// the [relpos] argument associated with a, b, and i modifiers 154void getRelPos() { 155 if(RestOfArgs.size() == 0) 156 show_help("Expected [relpos] for a, b, or i modifier"); 157 RelPos = RestOfArgs[0]; 158 RestOfArgs.erase(RestOfArgs.begin()); 159} 160 161// getCount - Extract the [count] argument associated with the N modifier 162// from the command line and check its value. 163void getCount() { 164 if(RestOfArgs.size() == 0) 165 show_help("Expected [count] value with N modifier"); 166 167 Count = atoi(RestOfArgs[0].c_str()); 168 RestOfArgs.erase(RestOfArgs.begin()); 169 170 // Non-positive counts are not allowed 171 if (Count < 1) 172 show_help("Invalid [count] value (not a positive integer)"); 173} 174 175// getArchive - Get the archive file name from the command line 176void getArchive() { 177 if(RestOfArgs.size() == 0) 178 show_help("An archive name must be specified"); 179 ArchiveName = RestOfArgs[0]; 180 RestOfArgs.erase(RestOfArgs.begin()); 181} 182 183// getMembers - Copy over remaining items in RestOfArgs to our Members vector 184// This is just for clarity. 185void getMembers() { 186 if(RestOfArgs.size() > 0) 187 Members = std::vector<std::string>(RestOfArgs); 188} 189 190// parseCommandLine - Parse the command line options as presented and return the 191// operation specified. Process all modifiers and check to make sure that 192// constraints on modifier/operation pairs have not been violated. 193ArchiveOperation parseCommandLine() { 194 195 // Keep track of number of operations. We can only specify one 196 // per execution. 197 unsigned NumOperations = 0; 198 199 // Keep track of the number of positional modifiers (a,b,i). Only 200 // one can be specified. 201 unsigned NumPositional = 0; 202 203 // Keep track of which operation was requested 204 ArchiveOperation Operation; 205 206 for(unsigned i=0; i<Options.size(); ++i) { 207 switch(Options[i]) { 208 case 'd': ++NumOperations; Operation = Delete; break; 209 case 'm': ++NumOperations; Operation = Move ; break; 210 case 'p': ++NumOperations; Operation = Print; break; 211 case 'q': ++NumOperations; Operation = QuickAppend; break; 212 case 'r': ++NumOperations; Operation = ReplaceOrInsert; break; 213 case 't': ++NumOperations; Operation = DisplayTable; break; 214 case 'x': ++NumOperations; Operation = Extract; break; 215 case 'c': Create = true; break; 216 case 'f': TruncateNames = true; break; 217 case 'l': /* accepted but unused */ break; 218 case 'o': OriginalDates = true; break; 219 case 's': break; // Ignore for now. 220 case 'S': break; // Ignore for now. 221 case 'P': FullPath = true; break; 222 case 'u': OnlyUpdate = true; break; 223 case 'v': Verbose = true; break; 224 case 'a': 225 getRelPos(); 226 AddAfter = true; 227 NumPositional++; 228 break; 229 case 'b': 230 getRelPos(); 231 AddBefore = true; 232 NumPositional++; 233 break; 234 case 'i': 235 getRelPos(); 236 InsertBefore = true; 237 NumPositional++; 238 break; 239 case 'N': 240 getCount(); 241 UseCount = true; 242 break; 243 default: 244 cl::PrintHelpMessage(); 245 } 246 } 247 248 // At this point, the next thing on the command line must be 249 // the archive name. 250 getArchive(); 251 252 // Everything on the command line at this point is a member. 253 getMembers(); 254 255 // Perform various checks on the operation/modifier specification 256 // to make sure we are dealing with a legal request. 257 if (NumOperations == 0) 258 show_help("You must specify at least one of the operations"); 259 if (NumOperations > 1) 260 show_help("Only one operation may be specified"); 261 if (NumPositional > 1) 262 show_help("You may only specify one of a, b, and i modifiers"); 263 if (AddAfter || AddBefore || InsertBefore) { 264 if (Operation != Move && Operation != ReplaceOrInsert) 265 show_help("The 'a', 'b' and 'i' modifiers can only be specified with " 266 "the 'm' or 'r' operations"); 267 } 268 if (OriginalDates && Operation != Extract) 269 show_help("The 'o' modifier is only applicable to the 'x' operation"); 270 if (TruncateNames && Operation!=QuickAppend && Operation!=ReplaceOrInsert) 271 show_help("The 'f' modifier is only applicable to the 'q' and 'r' " 272 "operations"); 273 if (OnlyUpdate && Operation != ReplaceOrInsert) 274 show_help("The 'u' modifier is only applicable to the 'r' operation"); 275 if (Count > 1 && Members.size() > 1) 276 show_help("Only one member name may be specified with the 'N' modifier"); 277 278 // Return the parsed operation to the caller 279 return Operation; 280} 281 282// buildPaths - Convert the strings in the Members vector to sys::Path objects 283// and make sure they are valid and exist exist. This check is only needed for 284// the operations that add/replace files to the archive ('q' and 'r') 285bool buildPaths(bool checkExistence, std::string* ErrMsg) { 286 for (unsigned i = 0; i < Members.size(); i++) { 287 std::string aPath = Members[i]; 288 if (checkExistence) { 289 bool IsDirectory; 290 error_code EC = sys::fs::is_directory(aPath, IsDirectory); 291 if (EC) 292 fail(aPath + ": " + EC.message()); 293 if (IsDirectory) 294 fail(aPath + " Is a directory"); 295 296 Paths.insert(aPath); 297 } else { 298 Paths.insert(aPath); 299 } 300 } 301 return false; 302} 303 304// doPrint - Implements the 'p' operation. This function traverses the archive 305// looking for members that match the path list. It is careful to uncompress 306// things that should be and to skip bitcode files unless the 'k' modifier was 307// given. 308bool doPrint(std::string* ErrMsg) { 309 if (buildPaths(false, ErrMsg)) 310 return true; 311 unsigned countDown = Count; 312 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); 313 I != E; ++I ) { 314 if (Paths.empty() || 315 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) { 316 if (countDown == 1) { 317 const char* data = reinterpret_cast<const char*>(I->getData()); 318 319 // Skip things that don't make sense to print 320 if (I->isSVR4SymbolTable() || I->isBSD4SymbolTable()) 321 continue; 322 323 if (Verbose) 324 outs() << "Printing " << I->getPath().str() << "\n"; 325 326 unsigned len = I->getSize(); 327 outs().write(data, len); 328 } else { 329 countDown--; 330 } 331 } 332 } 333 return false; 334} 335 336// putMode - utility function for printing out the file mode when the 't' 337// operation is in verbose mode. 338void 339printMode(unsigned mode) { 340 if (mode & 004) 341 outs() << "r"; 342 else 343 outs() << "-"; 344 if (mode & 002) 345 outs() << "w"; 346 else 347 outs() << "-"; 348 if (mode & 001) 349 outs() << "x"; 350 else 351 outs() << "-"; 352} 353 354// doDisplayTable - Implement the 't' operation. This function prints out just 355// the file names of each of the members. However, if verbose mode is requested 356// ('v' modifier) then the file type, permission mode, user, group, size, and 357// modification time are also printed. 358bool 359doDisplayTable(std::string* ErrMsg) { 360 if (buildPaths(false, ErrMsg)) 361 return true; 362 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); 363 I != E; ++I ) { 364 if (Paths.empty() || 365 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) { 366 if (Verbose) { 367 // FIXME: Output should be this format: 368 // Zrw-r--r-- 500/ 500 525 Nov 8 17:42 2004 Makefile 369 outs() << " "; 370 unsigned mode = I->getMode(); 371 printMode((mode >> 6) & 007); 372 printMode((mode >> 3) & 007); 373 printMode(mode & 007); 374 outs() << " " << format("%4u", I->getUser()); 375 outs() << "/" << format("%4u", I->getGroup()); 376 outs() << " " << format("%8u", I->getSize()); 377 outs() << " " << format("%20s", I->getModTime().str().substr(4).c_str()); 378 outs() << " " << I->getPath().str() << "\n"; 379 } else { 380 outs() << I->getPath().str() << "\n"; 381 } 382 } 383 } 384 return false; 385} 386 387// doExtract - Implement the 'x' operation. This function extracts files back to 388// the file system. 389bool 390doExtract(std::string* ErrMsg) { 391 if (buildPaths(false, ErrMsg)) 392 return true; 393 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); 394 I != E; ++I ) { 395 if (Paths.empty() || 396 (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) { 397 398 // Open up a file stream for writing 399 int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT; 400#ifdef O_BINARY 401 OpenFlags |= O_BINARY; 402#endif 403 404 // Retain the original mode. 405 sys::fs::perms Mode = sys::fs::perms(I->getMode()); 406 407 int FD = open(I->getPath().str().c_str(), OpenFlags, Mode); 408 if (FD < 0) 409 return true; 410 411 { 412 raw_fd_ostream file(FD, false); 413 414 // Get the data and its length 415 const char* data = reinterpret_cast<const char*>(I->getData()); 416 unsigned len = I->getSize(); 417 418 // Write the data. 419 file.write(data, len); 420 } 421 422 // If we're supposed to retain the original modification times, etc. do so 423 // now. 424 if (OriginalDates) { 425 error_code EC = 426 sys::fs::setLastModificationAndAccessTime(FD, I->getModTime()); 427 if (EC) 428 fail(EC.message()); 429 } 430 if (close(FD)) 431 return true; 432 } 433 } 434 return false; 435} 436 437// doDelete - Implement the delete operation. This function deletes zero or more 438// members from the archive. Note that if the count is specified, there should 439// be no more than one path in the Paths list or else this algorithm breaks. 440// That check is enforced in parseCommandLine (above). 441bool 442doDelete(std::string* ErrMsg) { 443 if (buildPaths(false, ErrMsg)) 444 return true; 445 if (Paths.empty()) 446 return false; 447 unsigned countDown = Count; 448 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); 449 I != E; ) { 450 if (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end()) { 451 if (countDown == 1) { 452 Archive::iterator J = I; 453 ++I; 454 TheArchive->erase(J); 455 } else 456 countDown--; 457 } else { 458 ++I; 459 } 460 } 461 462 // We're done editting, reconstruct the archive. 463 if (TheArchive->writeToDisk(TruncateNames,ErrMsg)) 464 return true; 465 return false; 466} 467 468// doMore - Implement the move operation. This function re-arranges just the 469// order of the archive members so that when the archive is written the move 470// of the members is accomplished. Note the use of the RelPos variable to 471// determine where the items should be moved to. 472bool 473doMove(std::string* ErrMsg) { 474 if (buildPaths(false, ErrMsg)) 475 return true; 476 477 // By default and convention the place to move members to is the end of the 478 // archive. 479 Archive::iterator moveto_spot = TheArchive->end(); 480 481 // However, if the relative positioning modifiers were used, we need to scan 482 // the archive to find the member in question. If we don't find it, its no 483 // crime, we just move to the end. 484 if (AddBefore || InsertBefore || AddAfter) { 485 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end(); 486 I != E; ++I ) { 487 if (RelPos == I->getPath().str()) { 488 if (AddAfter) { 489 moveto_spot = I; 490 moveto_spot++; 491 } else { 492 moveto_spot = I; 493 } 494 break; 495 } 496 } 497 } 498 499 // Keep a list of the paths remaining to be moved 500 std::set<std::string> remaining(Paths); 501 502 // Scan the archive again, this time looking for the members to move to the 503 // moveto_spot. 504 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end(); 505 I != E && !remaining.empty(); ++I ) { 506 std::set<std::string>::iterator found = 507 std::find(remaining.begin(),remaining.end(), I->getPath()); 508 if (found != remaining.end()) { 509 if (I != moveto_spot) 510 TheArchive->splice(moveto_spot,*TheArchive,I); 511 remaining.erase(found); 512 } 513 } 514 515 // We're done editting, reconstruct the archive. 516 if (TheArchive->writeToDisk(TruncateNames,ErrMsg)) 517 return true; 518 return false; 519} 520 521// doQuickAppend - Implements the 'q' operation. This function just 522// indiscriminantly adds the members to the archive and rebuilds it. 523bool 524doQuickAppend(std::string* ErrMsg) { 525 // Get the list of paths to append. 526 if (buildPaths(true, ErrMsg)) 527 return true; 528 if (Paths.empty()) 529 return false; 530 531 // Append them quickly. 532 for (std::set<std::string>::iterator PI = Paths.begin(), PE = Paths.end(); 533 PI != PE; ++PI) { 534 if (TheArchive->addFileBefore(*PI, TheArchive->end(), ErrMsg)) 535 return true; 536 } 537 538 // We're done editting, reconstruct the archive. 539 if (TheArchive->writeToDisk(TruncateNames,ErrMsg)) 540 return true; 541 return false; 542} 543 544// doReplaceOrInsert - Implements the 'r' operation. This function will replace 545// any existing files or insert new ones into the archive. 546bool 547doReplaceOrInsert(std::string* ErrMsg) { 548 549 // Build the list of files to be added/replaced. 550 if (buildPaths(true, ErrMsg)) 551 return true; 552 if (Paths.empty()) 553 return false; 554 555 // Keep track of the paths that remain to be inserted. 556 std::set<std::string> remaining(Paths); 557 558 // Default the insertion spot to the end of the archive 559 Archive::iterator insert_spot = TheArchive->end(); 560 561 // Iterate over the archive contents 562 for (Archive::iterator I = TheArchive->begin(), E = TheArchive->end(); 563 I != E && !remaining.empty(); ++I ) { 564 565 // Determine if this archive member matches one of the paths we're trying 566 // to replace. 567 568 std::set<std::string>::iterator found = remaining.end(); 569 for (std::set<std::string>::iterator RI = remaining.begin(), 570 RE = remaining.end(); RI != RE; ++RI ) { 571 std::string compare(sys::path::filename(*RI)); 572 if (TruncateNames && compare.length() > 15) { 573 const char* nm = compare.c_str(); 574 unsigned len = compare.length(); 575 size_t slashpos = compare.rfind('/'); 576 if (slashpos != std::string::npos) { 577 nm += slashpos + 1; 578 len -= slashpos +1; 579 } 580 if (len > 15) 581 len = 15; 582 compare.assign(nm,len); 583 } 584 if (compare == I->getPath().str()) { 585 found = RI; 586 break; 587 } 588 } 589 590 if (found != remaining.end()) { 591 sys::fs::file_status Status; 592 error_code EC = sys::fs::status(*found, Status); 593 if (EC) 594 return true; 595 if (!sys::fs::is_directory(Status)) { 596 if (OnlyUpdate) { 597 // Replace the item only if it is newer. 598 if (Status.getLastModificationTime() > I->getModTime()) 599 if (I->replaceWith(*found, ErrMsg)) 600 return true; 601 } else { 602 // Replace the item regardless of time stamp 603 if (I->replaceWith(*found, ErrMsg)) 604 return true; 605 } 606 } else { 607 // We purposefully ignore directories. 608 } 609 610 // Remove it from our "to do" list 611 remaining.erase(found); 612 } 613 614 // Determine if this is the place where we should insert 615 if ((AddBefore || InsertBefore) && RelPos == I->getPath().str()) 616 insert_spot = I; 617 else if (AddAfter && RelPos == I->getPath().str()) { 618 insert_spot = I; 619 insert_spot++; 620 } 621 } 622 623 // If we didn't replace all the members, some will remain and need to be 624 // inserted at the previously computed insert-spot. 625 if (!remaining.empty()) { 626 for (std::set<std::string>::iterator PI = remaining.begin(), 627 PE = remaining.end(); PI != PE; ++PI) { 628 if (TheArchive->addFileBefore(*PI, insert_spot, ErrMsg)) 629 return true; 630 } 631 } 632 633 // We're done editting, reconstruct the archive. 634 if (TheArchive->writeToDisk(TruncateNames,ErrMsg)) 635 return true; 636 return false; 637} 638 639bool shouldCreateArchive(ArchiveOperation Op) { 640 switch (Op) { 641 case Print: 642 case Delete: 643 case Move: 644 case DisplayTable: 645 case Extract: 646 return false; 647 648 case QuickAppend: 649 case ReplaceOrInsert: 650 return true; 651 } 652 653 llvm_unreachable("Missing entry in covered switch."); 654} 655 656// main - main program for llvm-ar .. see comments in the code 657int main(int argc, char **argv) { 658 program_name = argv[0]; 659 // Print a stack trace if we signal out. 660 sys::PrintStackTraceOnErrorSignal(); 661 PrettyStackTraceProgram X(argc, argv); 662 LLVMContext &Context = getGlobalContext(); 663 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 664 665 // Have the command line options parsed and handle things 666 // like --help and --version. 667 cl::ParseCommandLineOptions(argc, argv, 668 "LLVM Archiver (llvm-ar)\n\n" 669 " This program archives bitcode files into single libraries\n" 670 ); 671 672 int exitCode = 0; 673 674 // Do our own parsing of the command line because the CommandLine utility 675 // can't handle the grouped positional parameters without a dash. 676 ArchiveOperation Operation = parseCommandLine(); 677 678 // Create or open the archive object. 679 if (shouldCreateArchive(Operation) && !llvm::sys::fs::exists(ArchiveName)) { 680 // Produce a warning if we should and we're creating the archive 681 if (!Create) 682 errs() << argv[0] << ": creating " << ArchiveName << "\n"; 683 TheArchive = Archive::CreateEmpty(ArchiveName, Context); 684 TheArchive->writeToDisk(); 685 } 686 687 if (!TheArchive) { 688 std::string Error; 689 TheArchive = Archive::OpenAndLoad(ArchiveName, Context, &Error); 690 if (TheArchive == 0) { 691 errs() << argv[0] << ": error loading '" << ArchiveName << "': " 692 << Error << "!\n"; 693 return 1; 694 } 695 } 696 697 // Make sure we're not fooling ourselves. 698 assert(TheArchive && "Unable to instantiate the archive"); 699 700 // Perform the operation 701 std::string ErrMsg; 702 bool haveError = false; 703 switch (Operation) { 704 case Print: haveError = doPrint(&ErrMsg); break; 705 case Delete: haveError = doDelete(&ErrMsg); break; 706 case Move: haveError = doMove(&ErrMsg); break; 707 case QuickAppend: haveError = doQuickAppend(&ErrMsg); break; 708 case ReplaceOrInsert: haveError = doReplaceOrInsert(&ErrMsg); break; 709 case DisplayTable: haveError = doDisplayTable(&ErrMsg); break; 710 case Extract: haveError = doExtract(&ErrMsg); break; 711 } 712 if (haveError) { 713 errs() << argv[0] << ": " << ErrMsg << "\n"; 714 return 1; 715 } 716 717 delete TheArchive; 718 TheArchive = 0; 719 720 // Return result code back to operating system. 721 return exitCode; 722} 723