Merge upstream changes from Marlin 2.1.2.5

This commit is contained in:
Stefan Kalscheuer
2024-11-23 13:43:26 +01:00
parent c41a85354a
commit c8ff13654b
376 changed files with 4922 additions and 3840 deletions

View File

@@ -27,6 +27,13 @@ def rpad(astr, fill, c=' '):
need = fill - len(astr)
return astr if need <= 0 else astr + (need * c)
# Concatenate a string, adding a space if necessary
# to avoid merging two words
def concat_with_space(s1, s2):
if not s1.endswith(' ') and not s2.startswith(' '):
s1 += ' '
return s1 + s2
# Pin patterns
mpatt = [ r'-?\d{1,3}', r'P[A-I]\d+', r'P\d_\d+', r'Pin[A-Z]\d\b' ]
mstr = '|'.join(mpatt)
@@ -36,7 +43,7 @@ mexpr = [ re.compile(f'^{m}$') for m in mpatt ]
ppad = [ 3, 4, 5, 5 ]
# Match a define line
definePatt = re.compile(rf'^\s*(//)?#define\s+[A-Z_][A-Z0-9_]+\s+({mstr})\s*(//.*)?$')
definePinPatt = re.compile(rf'^\s*(//)?#define\s+[A-Z_][A-Z0-9_]+?_PIN\s+({mstr})\s*(//.*)?$')
def format_pins(argv):
src_file = 'stdin'
@@ -45,6 +52,7 @@ def format_pins(argv):
scnt = 0
for arg in argv:
if arg == '-v':
global do_log
do_log = True
elif scnt == 0:
# Get a source file if specified. Default destination is the same file
@@ -85,7 +93,7 @@ def get_pin_pattern(txt):
# Find the most common matching pattern
match_threshold = 5
for line in txt.split('\n'):
r = definePatt.match(line)
r = definePinPatt.match(line)
if r == None: continue
ind = -1
for p in mexpr:
@@ -135,7 +143,7 @@ def process_text(txt):
logmsg("pin:", line)
pinnum = r[4] if r[4][0] == 'P' else lpad(r[4], patt['pad'])
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + pinnum
line = concat_with_space(rpad(line, col_value_lj), pinnum)
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
@@ -149,7 +157,7 @@ def process_text(txt):
if r == None: return False
logmsg("pin -1:", line)
line = f'{r[1]} {r[3]}'
line = rpad(line, col_value_lj) + '-1'
line = concat_with_space(rpad(line, col_value_lj), '-1')
if r[5]: line = rpad(line, col_comment) + r[5]
d['line'] = line
return True
@@ -179,8 +187,8 @@ def process_text(txt):
if r == None: return False
logmsg("alias:", line)
line = f'{r[1]} {r[3]}'
line += lpad(r[4], col_value_rj + 1 - len(line))
if r[5]: line = rpad(line, col_comment) + r[5]
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = concat_with_space(rpad(line, col_comment), r[5])
d['line'] = line
return True
@@ -193,7 +201,7 @@ def process_text(txt):
if r == None: return False
logmsg("switch:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
d['check_comment_next'] = True
return True
@@ -207,7 +215,7 @@ def process_text(txt):
if r == None: return False
logmsg("def:", line)
line = f'{r[1]} {r[3]} '
line += lpad(r[4], col_value_rj + 1 - len(line))
line = concat_with_space(line, lpad(r[4], col_value_rj + 1 - len(line)))
if r[5]: line = rpad(line, col_comment - 1) + ' ' + r[5]
d['line'] = line
return True
@@ -221,7 +229,7 @@ def process_text(txt):
if r == None: return False
logmsg("undef:", line)
line = f'{r[1]} {r[3]}'
if r[4]: line = rpad(line, col_comment) + r[4]
if r[4]: line = concat_with_space(rpad(line, col_comment), r[4])
d['line'] = line
return True
@@ -233,7 +241,7 @@ def process_text(txt):
r = condPatt.match(line)
if r == None: return False
logmsg("cond:", line)
line = rpad(r[1], col_comment) + r[5]
line = concat_with_space(rpad(r[1], col_comment), r[5])
d['line'] = line
d['check_comment_next'] = True
return True
@@ -263,7 +271,7 @@ def process_text(txt):
elif tryUndef(wDict): pass #undef ...
elif tryCond(wDict): pass #if|ifdef|ifndef|elif ...
out += wDict['line'] + '\n'
out += wDict['line'].rstrip() + '\n'
return re.sub('\n\n$', '\n', re.sub(r'\n\n+', '\n\n', out))