Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(73154)

Delta Between Two Patch Sets: Modules/_sha3/cleanup.py

Issue 16113: Add SHA-3 (Keccak) support
Left Patch Set: Created 7 years ago
Right Patch Set: Created 3 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/hashlib.h ('k') | Modules/_sha3/clinic/sha3module.c.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (C) 2012 Christian Heimes (christian@python.org) 2 # Copyright (C) 2012 Christian Heimes (christian@python.org)
3 # Licensed to PSF under a Contributor Agreement. 3 # Licensed to PSF under a Contributor Agreement.
4 # 4 #
5 # cleanup Keccak sources 5 # cleanup Keccak sources
6 6
7 import os 7 import os
8 import re 8 import re
9 9
10 CPP1 = re.compile("^//(.*)") 10 CPP1 = re.compile("^//(.*)")
11 CPP2 = re.compile("\ //(.*)") 11 CPP2 = re.compile("\ //(.*)")
12 12
13 STATICS = ("void ", "int ", "HashReturn ", "const UINT64 ", "UINT16 ") 13 STATICS = ("void ", "int ", "HashReturn ",
14 "const UINT64 ", "UINT16 ", " int prefix##")
14 15
15 HERE = os.path.dirname(os.path.abspath(__file__)) 16 HERE = os.path.dirname(os.path.abspath(__file__))
16 KECCAK = os.path.join(HERE, "keccak") 17 KECCAK = os.path.join(HERE, "kcp")
17 18
18 def getfiles(): 19 def getfiles():
19 for name in os.listdir(KECCAK): 20 for name in os.listdir(KECCAK):
20 name = os.path.join(KECCAK, name) 21 name = os.path.join(KECCAK, name)
21 if os.path.isfile(name): 22 if os.path.isfile(name):
22 yield name 23 yield name
23 24
24 def cleanup(f): 25 def cleanup(f):
25 buf = [] 26 buf = []
26 for line in f: 27 for line in f:
27 if line.startswith(STATICS): 28 # mark all functions and global data as static
28 buf.append("static " + line) 29 #if line.startswith(STATICS):
29 continue 30 # buf.append("static " + line)
31 # continue
32 # remove UINT64 typedef, we have our own
30 if line.startswith("typedef unsigned long long int"): 33 if line.startswith("typedef unsigned long long int"):
31 buf.append("/* %s */\n" % line.strip()) 34 buf.append("/* %s */\n" % line.strip())
32 continue 35 continue
36 ## remove #include "brg_endian.h"
33 if "brg_endian.h" in line: 37 if "brg_endian.h" in line:
34 buf.append("/* %s */\n" % line.strip()) 38 buf.append("/* %s */\n" % line.strip())
35 continue 39 continue
36 line = CPP1.sub(r"/* \1 */", line) 40 # transform C++ comments into ANSI C comments
37 line = CPP2.sub(r" /* \1 */", line) 41 line = CPP1.sub(r"/*\1 */\n", line)
42 line = CPP2.sub(r" /*\1 */\n", line)
38 buf.append(line) 43 buf.append(line)
39 return "".join(buf) 44 return "".join(buf)
40 45
41 for name in getfiles(): 46 for name in getfiles():
42 with open(name) as f: 47 with open(name) as f:
43 res = cleanup(f) 48 res = cleanup(f)
44 with open(name, "w") as f: 49 with open(name, "w") as f:
45 f.write(res) 50 f.write(res)
46
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+