serge-sans-paille | 6c40e9c | 2020-07-15 09:31:13 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Patrick Meredith | d629d5f | 2005-10-13 16:26:50 +0000 | [diff] [blame] | 2 | |
Tobias Hieta | 3c76287 | 2023-05-15 11:02:42 +0200 | [diff] [blame^] | 3 | # changelog: |
| 4 | # 10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove |
| 5 | # nodes such as %tmp.1.i and %tmp._i.3 |
| 6 | # 10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just |
Patrick Meredith | d629d5f | 2005-10-13 16:26:50 +0000 | [diff] [blame] | 7 | #%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in |
Tobias Hieta | 3c76287 | 2023-05-15 11:02:42 +0200 | [diff] [blame^] | 8 | # the comments |
| 9 | # 10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather |
| 10 | # than removing all lines for which the lable CONTAINS %tmp.# |
Serge Guelton | bf2f82e | 2019-01-03 14:11:33 +0000 | [diff] [blame] | 11 | |
| 12 | from __future__ import print_function |
| 13 | |
Patrick Meredith | d629d5f | 2005-10-13 16:26:50 +0000 | [diff] [blame] | 14 | import re |
| 15 | import sys |
Tobias Hieta | 3c76287 | 2023-05-15 11:02:42 +0200 | [diff] [blame^] | 16 | |
| 17 | if len(sys.argv) < 3: |
| 18 | print("usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>") |
| 19 | sys.exit(1) |
| 20 | # get a file object |
| 21 | input = open(sys.argv[1], "r") |
| 22 | output = open(sys.argv[2], "w") |
| 23 | # we'll get this one line at a time...while we could just put the whole thing in a string |
| 24 | # it would kill old computers |
Patrick Meredith | d629d5f | 2005-10-13 16:26:50 +0000 | [diff] [blame] | 25 | buffer = input.readline() |
Tobias Hieta | 3c76287 | 2023-05-15 11:02:42 +0200 | [diff] [blame^] | 26 | while buffer != "": |
| 27 | if re.compile('label(\s*)=(\s*)"\s%tmp(.\w*)*(\s*)"').search(buffer): |
| 28 | # skip next line, write neither this line nor the next |
| 29 | buffer = input.readline() |
| 30 | else: |
| 31 | # this isn't a tmp Node, we can write it |
| 32 | output.write(buffer) |
| 33 | # prepare for the next iteration |
| 34 | buffer = input.readline() |
Patrick Meredith | d629d5f | 2005-10-13 16:26:50 +0000 | [diff] [blame] | 35 | input.close() |
| 36 | output.close() |