Browse Source

Allow for truncating of flag arguments

naelstrof 7 years ago
parent
commit
816a4dc788
2 changed files with 21 additions and 3 deletions
  1. 2
    1
      README.md
  2. 19
    2
      src/options.cpp

+ 2
- 1
README.md View File

@@ -7,7 +7,7 @@ This just a re-write with less dependencies, inaccuracies, etc.
7 7
 TODO:
8 8
 - [x] Window Selection
9 9
 - [x] Keyboard
10
-- [ ] Shaders (Partially complete, need more robust features still).
10
+- [x] Shaders
11 11
 - [x] Custom output formatting
12 12
 - [ ] Manpages
13 13
 - [x] Option parsing
@@ -15,6 +15,7 @@ TODO:
15 15
 - [x] Mouse stuff
16 16
 - [x] Drawing stuff
17 17
 - [x] Printing stuff
18
+- [ ] Librarify (so I can plug it into maim)
18 19
 
19 20
 Avoiding:
20 21
 - [ ] Themes (Not going to happen. It'd add a texture library dependency.)

+ 19
- 2
src/options.cpp View File

@@ -30,8 +30,25 @@ int Options::parseCharOption( int argc, char** argv, int argumentIndex, int vali
30 30
     // If we're a flag, we take no arguments, nor do we allow = signs or whatever.
31 31
     if ( isFlagArgument[validIndex] ) {
32 32
         if ( argument != std::string()+"-"+validCharArguments[validIndex] ) {
33
-            throw new std::invalid_argument( std::string()+"Unexpected characters around flag `" + argument + "`." );
34
-            return 0;
33
+            for( int o=1;o<argument.length();o++ ) {
34
+                bool isValid = false;
35
+                for( int i=0;i<validArgumentCount&&!isValid;i++ ) {
36
+                    if ( argument[o] == validCharArguments[i] ) {
37
+                        if ( isFlagArgument[i] ) {
38
+                            isValid = true;
39
+                            arguments.push_back( std::string()+validCharArguments[i] );
40
+                            values.push_back("");
41
+                            break;
42
+                        } else {
43
+                            throw new std::invalid_argument( std::string()+"Truncating non-flag arguments is not allowed. Split this up: `" + argument + "`." );
44
+                        }
45
+                    }
46
+                }
47
+                if (!isValid) {
48
+                    throw new std::invalid_argument( std::string()+"Unexpected characters around flag `" + argument + "`." );
49
+                }
50
+            }
51
+            return 1;
35 52
         } else {
36 53
             arguments.push_back( std::string()+argument[1] );
37 54
             values.push_back("");