リビジョン | 2d40bc03ff78e25dd514c2e4078ea9900ea10b8f (tree) |
---|---|
日時 | 2012-12-26 10:24:23 |
作者 | Shinya TAKEBAYASHI <omoikanenomikoto@gmai...> |
コミッター | Shinya TAKEBAYASHI |
Merged general.py
@@ -1,7 +1,9 @@ | ||
1 | 1 | #!/usr/bin/env python |
2 | 2 | |
3 | 3 | import sys, os, re, signal |
4 | -from libs import term, config, general | |
4 | +from libs import term, config | |
5 | + | |
6 | +version_number = "$Id$" | |
5 | 7 | |
6 | 8 | include_path = [] |
7 | 9 |
@@ -9,14 +11,17 @@ def generate_code(): | ||
9 | 11 | code = '#include <stdio.h> \n int main(int argc, char **argv){return 0;}\n' |
10 | 12 | open('tmp.c', 'w').write(code) |
11 | 13 | |
14 | + | |
12 | 15 | def ulink(): |
13 | 16 | os.remove('tmp.c') |
14 | 17 | os.remove('a.out') |
15 | 18 | |
19 | + | |
16 | 20 | def rungcc(): |
17 | 21 | L = ['gcc', '-v', 'tmp.c', '-o', 'a.out'] |
18 | 22 | os.spawnlp(os.P_WAIT, 'gcc', L) |
19 | 23 | |
24 | + | |
20 | 25 | def findheader2(target, rootdir): |
21 | 26 | path = None |
22 | 27 | for root, dirs, files in os.walk(rootdir): |
@@ -25,6 +30,7 @@ def findheader2(target, rootdir): | ||
25 | 30 | break |
26 | 31 | return path |
27 | 32 | |
33 | + | |
28 | 34 | def findheader(filename): |
29 | 35 | pattern = re.compile("^#.*include [<\"].*[>\"]") |
30 | 36 | delimiter = re.compile('[<>"]') |
@@ -59,21 +65,22 @@ def findheader(filename): | ||
59 | 65 | |
60 | 66 | print('') |
61 | 67 | |
68 | + | |
62 | 69 | def sigint(num, frame): |
63 | 70 | print('process interrupted.') |
64 | 71 | sys.exit(2) |
65 | 72 | |
66 | -if __name__ == '__main__': | |
67 | - signal.signal(signal.SIGINT, sigint) | |
68 | 73 | |
69 | - if len(sys.argv) == 1: | |
70 | - general.print_usage() | |
71 | - sys.exit(2) | |
74 | +def print_usage(): | |
75 | + print_version() | |
76 | + print("usage: %s [target]..." % (sys.argv[0])) | |
72 | 77 | |
73 | - term.color_mode = True | |
74 | 78 | |
75 | - include_path = config.get_include_dir() | |
79 | +def print_version(): | |
80 | + print("hl version %s" % (version_number[5:-2])) | |
76 | 81 | |
82 | + | |
83 | +def print_header(): | |
77 | 84 | print('-' * 40) |
78 | 85 | print("*Processing " + term.green("%d " % (len(sys.argv) - 1)) + "file(s).") |
79 | 86 | print("*header search dirs: ") |
@@ -82,5 +89,18 @@ if __name__ == '__main__': | ||
82 | 89 | print('-' * 40) |
83 | 90 | print('') |
84 | 91 | |
92 | + | |
93 | +if __name__ == '__main__': | |
94 | + signal.signal(signal.SIGINT, sigint) | |
95 | + | |
96 | + if len(sys.argv) == 1: | |
97 | + general.print_usage() | |
98 | + sys.exit(2) | |
99 | + | |
100 | + term.color_mode = True | |
101 | + | |
102 | + include_path = config.get_include_dir() | |
103 | + print_header() | |
104 | + | |
85 | 105 | for target in sys.argv[1:]: |
86 | 106 | findheader(target) |
@@ -1,11 +0,0 @@ | ||
1 | -import sys | |
2 | - | |
3 | -version_number = "$Id$" | |
4 | - | |
5 | -def print_usage(): | |
6 | - print_version() | |
7 | - print("usage: %s [target]..." % (sys.argv[0])) | |
8 | - | |
9 | - | |
10 | -def print_version(): | |
11 | - print("hl version %s" % (version_number[5:-2])) |