- if not first_entry:
- first_entry = m.group(1)
- elif m.group(1) == first_entry:
- # second time we see this, so we're past the externs
- if state != 'idle':
- # tack driver on to the end of the list
- out += tmpl(TMPL_DRIVERS_EXTERN)
- state = 'pointer'
- if state == 'extern':
- if m.group(1) > names['upper']:
- out += tmpl(TMPL_DRIVERS_EXTERN)
- state = 'idle'
- elif state == 'pointer':
- if m.group(1) > names['upper']:
- out += tmpl(TMPL_DRIVERS_POINTER)
- state = 'done'
- elif state == 'pointer' and not re.match('(\s*&|#endif|$)', line):
+ if iflevel == 0:
+ if not first_entry:
+ first_entry = m.group(1)
+ elif m.group(1) == first_entry:
+ # second time we see this, so we're past the externs
+ if state != 'idle':
+ # tack driver on to the end of the list
+ out += tmpl(TMPL_DRIVERS_EXTERN)
+ state = 'pointer'
+ if state == 'extern':
+ if m.group(1) > names['upper']:
+ out += tmpl(TMPL_DRIVERS_EXTERN)
+ state = 'idle'
+ elif state == 'pointer':
+ if m.group(1) > names['upper']:
+ out += tmpl(TMPL_DRIVERS_POINTER)
+ state = 'done'
+ iflevel += 1
+ elif re.match(r'\s*#\s*endif\b', line):
+ iflevel -= 1
+ elif iflevel == 0 and state == 'pointer':