gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9731: use the new way of option proc


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9731: use the new way of option processing.
Date: Fri, 14 Nov 2008 20:34:53 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9731
committer: address@hidden
branch nick: rtmp
timestamp: Fri 2008-11-14 20:34:53 -0700
message:
  use the new way of option processing.
modified:
  testsuite/libnet.all/test_cache.cpp
=== modified file 'testsuite/libnet.all/test_cache.cpp'
--- a/testsuite/libnet.all/test_cache.cpp       2008-11-13 02:13:44 +0000
+++ b/testsuite/libnet.all/test_cache.cpp       2008-11-15 03:34:53 +0000
@@ -44,6 +44,7 @@
 #include "dejagnu.h"
 #include "network.h"
 #include "diskstream.h"
+#include "arg_parser.h"
 
 using namespace gnash;
 using namespace std;
@@ -54,31 +55,51 @@
 static void test_remove (void);
 static void create_file(const std::string &, size_t);
 
+static bool dump = false;
+
 static TestState runtest;
-
 LogFile& dbglogfile = LogFile::getDefaultInstance();
 
 int
 main(int argc, char *argv[])
 {
-    int c;
-    
-    while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
-        switch (c) {
-          case 'h':
-              usage ();
-              break;
-              
-          case 'v':
-              dbglogfile.setVerbosity();
-              break;
-              
-          default:
-              usage ();
-              break;
-        }
-    }
-
+    const Arg_parser::Option opts[] =
+        {
+            { 'h', "help",          Arg_parser::no  },
+            { 'v', "verbose",       Arg_parser::no  },
+            { 'd', "dump",          Arg_parser::no  },
+        };
+    
+    Arg_parser parser(argc, argv, opts);
+    if( ! parser.error().empty() ) {
+        cout << parser.error() << endl;
+        exit(EXIT_FAILURE);
+    }
+    
+    for( int i = 0; i < parser.arguments(); ++i ) {
+        const int code = parser.code(i);
+        try {
+            switch( code ) {
+              case 'h':
+                  usage ();
+                  exit(EXIT_SUCCESS);
+              case 'v':
+                  dbglogfile.setVerbosity();
+                  // This happens once per 'v' flag 
+                  log_debug(_("Verbose output turned on"));
+                  break;
+              case 'd':
+                  dump= true;
+                  break;
+           }
+        }
+        
+        catch (Arg_parser::ArgParserException &e) {
+            cerr << _("Error parsing command line options: ") << e.what() << 
endl;
+            cerr << _("This is a Gnash bug.") << endl;
+        }
+    }
+    
     test();
     test_errors();
     test_remove();
@@ -174,7 +195,7 @@
     cache.addPath("barfoo", "/foo/bar/barfoo");
     cache.addPath("foobar", "/foo/bar/foobar");
 
-     if (dbglogfile.getVerbosity() > 0) {
+     if (dump) {
          cache.dump();
      }
     // now remove one in the middle
@@ -344,11 +365,13 @@
 static void
 usage (void)
 {
-    cerr << "This program tests HTTP protocol support." << endl;
-    cerr << "Usage: test_http [hv]" << endl;
-    cerr << "-h\tHelp" << endl;
-    cerr << "-v\tVerbose" << endl;
-    exit (-1);
+    cerr << "This program tests the Cache class." << endl
+         << endl
+         << _("Usage: test_diskstream [options...]") << endl
+         << _("  -h,  --help          Print this help and exit") << endl
+         << _("  -v,  --verbose       Output verbose debug info") << endl
+         << _("  -d,  --dump          Dump data structures") << endl
+         << endl;
 }
 
 #else  // no DejaGnu support


reply via email to

[Prev in Thread] Current Thread [Next in Thread]