@@ -18,7 +18,16 @@ def apply_opt(name, val, conf=None):
18
18
if name == "lcd" : name , val = val , "on"
19
19
20
20
# Create a regex to match the option and capture parts of the line
21
- regex = re .compile (rf'^(\s*)(//\s*)?(#define\s+)({ name } \b)(\s*)(.*?)(\s*)(//.*)?$' , re .IGNORECASE )
21
+ # 1: Indentation
22
+ # 2: Comment
23
+ # 3: #define and whitespace
24
+ # 4: Option name
25
+ # 5: First space after name
26
+ # 6: Remaining spaces between name and value
27
+ # 7: Option value
28
+ # 8: Whitespace after value
29
+ # 9: End comment
30
+ regex = re .compile (rf'^(\s*)(//\s*)?(#define\s+)({ name } \b)(\s?)(\s*)(.*?)(\s*)(//.*)?$' , re .IGNORECASE )
22
31
23
32
# Find and enable and/or update all matches
24
33
for file in ("Configuration.h" , "Configuration_adv.h" ):
@@ -37,10 +46,11 @@ def apply_opt(name, val, conf=None):
37
46
newline = re .sub (r'^(\s*)(#define)(\s{1,3})?(\s*)' , r'\1//\2 \4' , line )
38
47
else :
39
48
# For options with values, enable and set the value
40
- newline = match [1 ] + match [3 ] + match [4 ] + match [5 ] + val
41
- if match [8 ]:
42
- sp = match [7 ] if match [7 ] else ' '
43
- newline += sp + match [8 ]
49
+ addsp = '' if match [5 ] else ' '
50
+ newline = match [1 ] + match [3 ] + match [4 ] + match [5 ] + addsp + val + match [6 ]
51
+ if match [9 ]:
52
+ sp = match [8 ] if match [8 ] else ' '
53
+ newline += sp + match [9 ]
44
54
lines [i ] = newline
45
55
blab (f"Set { name } to { val } " )
46
56
0 commit comments