File: s_function_loop.py

package info (click to toggle)
wiredtiger 3.2.1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 25,456 kB
  • sloc: ansic: 102,922; python: 52,573; sh: 6,915; java: 6,130; cpp: 2,311; makefile: 1,018; xml: 176
file content (28 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Mark outer loop boundaries with {@ and }@ .  Nested loops are not marked.
# Each input line is the content of a C function.
import re, sys

p = re.compile('((for |while |_FOREACH|FOREACH_BEGIN)\([^{)]*\)|do) {')
for line in sys.stdin:
    matched = 0
    m = p.search(line)
    while m != None:
        matched = 1
        pos = m.end()
        out = line[:pos] + "@"
        level = 1
        length = len(line)
        while level > 0 and pos < length:
            c = line[pos:pos+1]
            pos += 1
            out += c
            if c == "}":
                level -= 1
            elif c == "{":
                level += 1
        out += "@"
        sys.stdout.write(out)
        line = line[pos:]
        m = p.search(line)
    if matched != 0:
        sys.stdout.write(line)