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

+ 19
- 2
src/options.cpp View File

30
     // If we're a flag, we take no arguments, nor do we allow = signs or whatever.
30
     // If we're a flag, we take no arguments, nor do we allow = signs or whatever.
31
     if ( isFlagArgument[validIndex] ) {
31
     if ( isFlagArgument[validIndex] ) {
32
         if ( argument != std::string()+"-"+validCharArguments[validIndex] ) {
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
         } else {
52
         } else {
36
             arguments.push_back( std::string()+argument[1] );
53
             arguments.push_back( std::string()+argument[1] );
37
             values.push_back("");
54
             values.push_back("");