Removed parameter values 'all'.
authorFlorian Pose <fp@igh-essen.com>
Mon, 28 Jul 2008 11:43:08 +0000
changeset 1158 f65164fa4a58
parent 1157 04d1c950cf9d
child 1159 25cc77cf3993
Removed parameter values 'all'.
TODO
tool/main.cpp
--- a/TODO	Mon Jul 28 11:29:28 2008 +0000
+++ b/TODO	Mon Jul 28 11:43:08 2008 +0000
@@ -23,7 +23,6 @@
     - Remove MasterDevice::slaveCount().
     - Alias index?
     - Add 'etherlab version'.
-    - Remove 'all' parameter values.
 
 Future issues:
 
--- a/tool/main.cpp	Mon Jul 28 11:29:28 2008 +0000
+++ b/tool/main.cpp	Mon Jul 28 11:43:08 2008 +0000
@@ -95,8 +95,8 @@
 
 void getOptions(int argc, char **argv)
 {
-    int c, argCount, optionIndex, number;
-	char *remainder;
+    int c, argCount;
+    stringstream str;
 
     static struct option longOptions[] = {
         //name,      has_arg,           flag, val
@@ -113,61 +113,59 @@
     };
 
     do {
-        c = getopt_long(argc, argv, "m:a:p:d:t:fqvh",
-                longOptions, &optionIndex);
+        c = getopt_long(argc, argv, "m:a:p:d:t:fqvh", longOptions, NULL);
 
         switch (c) {
             case 'm':
-                number = strtoul(optarg, &remainder, 0);
-                if (remainder == optarg || *remainder || number < 0) {
+                str.clear();
+                str.str("");
+                str << optarg;
+                str >> resetiosflags(ios::basefield) // guess base from prefix
+                    >> masterIndex;
+                if (str.fail() || masterIndex < 0) {
                     cerr << "Invalid master number " << optarg << "!" << endl
                         << endl << usage();
                     exit(1);
                 }
-				masterIndex = number;
                 break;
 
             case 'a':
-                if (!strcmp(optarg, "all")) {
-                    slaveAlias = -1;
-                } else {
-                    number = strtoul(optarg, &remainder, 0);
-                    if (remainder == optarg || *remainder
-                            || number < 0 || number > 0xFFFF) {
-                        cerr << "Invalid slave alias " << optarg << "!"
-                            << endl << endl << usage();
-                        exit(1);
-                    }
-                    slaveAlias = number;
+                str.clear();
+                str.str("");
+                str << optarg;
+                str >> resetiosflags(ios::basefield) // guess base from prefix
+                    >> slaveAlias;
+                if (str.fail() || slaveAlias < 0 || slaveAlias > 0xFFFF) {
+                    cerr << "Invalid slave alias " << optarg << "!" << endl
+                        << endl << usage();
+                    exit(1);
                 }
                 break;
 
             case 'p':
-                if (!strcmp(optarg, "all")) {
-                    slavePosition = -1;
-                } else {
-                    number = strtoul(optarg, &remainder, 0);
-                    if (remainder == optarg || *remainder
-                            || number < 0 || number > 0xFFFF) {
-                        cerr << "Invalid slave position " << optarg << "!"
-                            << endl << endl << usage();
-                        exit(1);
-                    }
-                    slavePosition = number;
+                str.clear();
+                str.str("");
+                str << optarg;
+                str >> resetiosflags(ios::basefield) // guess base from prefix
+                    >> slavePosition;
+                if (str.fail()
+                        || slavePosition < 0 || slavePosition > 0xFFFF) {
+                    cerr << "Invalid slave position " << optarg << "!" << endl
+                        << endl << usage();
+                    exit(1);
                 }
                 break;
 
             case 'd':
-                if (!strcmp(optarg, "all")) {
-                    domainIndex = -1;
-                } else {
-                    number = strtoul(optarg, &remainder, 0);
-                    if (remainder == optarg || *remainder || number < 0) {
-                        cerr << "Invalid domain index "
-							<< optarg << "!" << endl << endl << usage();
-                        exit(1);
-                    }
-                    domainIndex = number;
+                str.clear();
+                str.str("");
+                str << optarg;
+                str >> resetiosflags(ios::basefield) // guess base from prefix
+                    >> domainIndex;
+                if (str.fail() || domainIndex < 0) {
+                    cerr << "Invalid domain index " << optarg << "!" << endl
+                        << endl << usage();
+                    exit(1);
                 }
                 break;