[MOAB-dev] r3896 - MOAB/trunk/tools

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Thu May 13 09:22:20 CDT 2010


Author: kraftche
Date: 2010-05-13 09:22:20 -0500 (Thu, 13 May 2010)
New Revision: 3896

Modified:
   MOAB/trunk/tools/mbmem.cpp
Log:
Trival fixed to mbmem utility:

o Make -h print help like other MOAB utils do
o Changing existing -h option to -H 
o Print error message for invalid flag (not just usage info)


Modified: MOAB/trunk/tools/mbmem.cpp
===================================================================
--- MOAB/trunk/tools/mbmem.cpp	2010-05-13 05:40:27 UTC (rev 3895)
+++ MOAB/trunk/tools/mbmem.cpp	2010-05-13 14:22:20 UTC (rev 3896)
@@ -14,18 +14,24 @@
 #include <sys/resource.h>
 #endif
 
-void usage( const char* argv0 )
+void usage( const char* argv0, bool help = false )
 {
-  std::cerr << "Usage: " << argv0 << " [-h|-b|-k|-m] <filename> [<filename> ...]" << std::endl
-            << "Usage: " << argv0 << " [-h|-b|-k|-m] -T" << std::endl
-            << "  -h : human readable units" << std::endl
+  std::ostream& str = help ? std::cout : std::cerr;
+  str << "Usage: " << argv0 << " [-H|-b|-k|-m] <filename> [<filename> ...]" << std::endl
+      << "       " << argv0 << " [-H|-b|-k|-m] -T" << std::endl;
+  if (!help) {
+    str << "       " << argv0 << " -h" << std::endl;
+    std::exit(1);
+  }
+  
+  std::cerr << "  -H : human readable units" << std::endl
             << "  -b : bytes" << std::endl
             << "  -k : kilobytes (1 kB == 1024 bytes)" << std::endl
             << "  -m : megabytes (1 MB == 1024 kB)" << std::endl
             << "  -g : gigabytes (1 GB == 1024 MB)" << std::endl
             << "  -T : test mode" << std::endl
             << std::endl;
-  std::exit(1);
+  std::exit(0);
 }
 
 enum Units { HUMAN, BYTES, KILOBYTES, MEGABYTES, GIGABYTES };
@@ -52,7 +58,7 @@
     // load each file specified on command line
   for (int i = 1; i < argc; ++i) {
     if (!no_more_flags && argv[i][0] == '-') {
-      if (!strcmp(argv[i],"-h"))
+      if (!strcmp(argv[i],"-H"))
         UNITS = HUMAN;
       else if(!strcmp(argv[i],"-b"))
         UNITS = BYTES;
@@ -64,10 +70,14 @@
         UNITS = GIGABYTES;
       else if(!strcmp(argv[i],"-T"))
         test_mode = true;
+      else if(!strcmp(argv[i],"-h"))
+        usage(argv[0],true);
       else if(!strcmp(argv[i],"--"))
         no_more_flags = true;


More information about the moab-dev mailing list