diff options
author | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-03-14 21:04:07 +0000 |
---|---|---|
committer | markw <markw@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-03-14 21:04:07 +0000 |
commit | 7b42c1c0e57110a1d2a56d0df77653b067834ede (patch) | |
tree | c71e4a27b1bc81ab1acf0ec2d67c9d83ba9bbcfe | |
parent | cc515eae0e8e97bca1d7b19c376ad314205874bb (diff) | |
download | busybox-w32-7b42c1c0e57110a1d2a56d0df77653b067834ede.tar.gz busybox-w32-7b42c1c0e57110a1d2a56d0df77653b067834ede.tar.bz2 busybox-w32-7b42c1c0e57110a1d2a56d0df77653b067834ede.zip |
Script that generates a script that will convert oddball variable names to K&R
style.
git-svn-id: svn://busybox.net/trunk/busybox@2080 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rwxr-xr-x | examples/mk2knr.pl | 76 | ||||
-rwxr-xr-x | scripts/mk2knr.pl | 76 |
2 files changed, 152 insertions, 0 deletions
diff --git a/examples/mk2knr.pl b/examples/mk2knr.pl new file mode 100755 index 000000000..29f94a188 --- /dev/null +++ b/examples/mk2knr.pl | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # | ||
3 | # @(#) mk2knr.pl - generates a perl script that converts lexemes to K&R-style | ||
4 | # | ||
5 | # How to use this script: | ||
6 | # - In the busybox directory type 'scripts/mk2knr.pl files-you-want-to-convert' | ||
7 | # - Review the 'convertme.pl' script generated and remove / edit any of the | ||
8 | # substitutions in there (please especially check for false positives) | ||
9 | # - Type './convertme.pl same-files-as-before' | ||
10 | # - Compile and see if it works | ||
11 | # | ||
12 | # BUGS: This script does not ignore strings inside comments or strings inside | ||
13 | # quotes (it probably should). | ||
14 | |||
15 | # set this to something else if you want | ||
16 | $convertme = 'convertme.pl'; | ||
17 | |||
18 | # internal-use variables (don't touch) | ||
19 | $convert = 0; | ||
20 | %converted = (); | ||
21 | |||
22 | |||
23 | # prepare the "convert me" file | ||
24 | open(CM, ">$convertme") or die "convertme.pl $!"; | ||
25 | print CM "#!/usr/bin/perl -p -i\n\n"; | ||
26 | |||
27 | # process each file passed on the cmd line | ||
28 | while (<>) { | ||
29 | |||
30 | # if the line says "getopt" in it anywhere, we don't want to muck with it | ||
31 | # because option lists tend to include strings like "cxtzvOf:" which get | ||
32 | # matched by the javaStyle / Hungarian and PascalStyle regexps below | ||
33 | next if /getopt/; | ||
34 | |||
35 | # tokenize the string into just the variables | ||
36 | while (/([a-zA-Z_][a-zA-Z0-9_]*)/g) { | ||
37 | $var = $1; | ||
38 | |||
39 | # ignore the word "BusyBox" | ||
40 | next if ($var =~ /BusyBox/); | ||
41 | |||
42 | # this checks for javaStyle or szHungarianNotation | ||
43 | $convert++ if ($var =~ /^[a-z]+[A-Z][a-z]+/); | ||
44 | |||
45 | # this checks for PascalStyle | ||
46 | $convert++ if ($var =~ /^[A-Z][a-z]+[A-Z][a-z]+/); | ||
47 | |||
48 | if ($convert) { | ||
49 | $convert = 0; | ||
50 | |||
51 | # skip ahead if we've already dealt with this one | ||
52 | next if ($converted{$var}); | ||
53 | |||
54 | # record that we've dealt with this var | ||
55 | $converted{$var} = 1; | ||
56 | |||
57 | print CM "s/\\b$var\\b/"; # more to come in just a minute | ||
58 | |||
59 | # change the first letter to lower-case | ||
60 | $var = lcfirst($var); | ||
61 | |||
62 | # put underscores before all remaining upper-case letters | ||
63 | $var =~ s/([A-Z])/_$1/g; | ||
64 | |||
65 | # now change the remaining characters to lower-case | ||
66 | $var = lc($var); | ||
67 | |||
68 | print CM "$var/g;\n"; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | # tidy up and make the $convertme script executable | ||
74 | close(CM); | ||
75 | chmod 0755, $convertme; | ||
76 | |||
diff --git a/scripts/mk2knr.pl b/scripts/mk2knr.pl new file mode 100755 index 000000000..29f94a188 --- /dev/null +++ b/scripts/mk2knr.pl | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # | ||
3 | # @(#) mk2knr.pl - generates a perl script that converts lexemes to K&R-style | ||
4 | # | ||
5 | # How to use this script: | ||
6 | # - In the busybox directory type 'scripts/mk2knr.pl files-you-want-to-convert' | ||
7 | # - Review the 'convertme.pl' script generated and remove / edit any of the | ||
8 | # substitutions in there (please especially check for false positives) | ||
9 | # - Type './convertme.pl same-files-as-before' | ||
10 | # - Compile and see if it works | ||
11 | # | ||
12 | # BUGS: This script does not ignore strings inside comments or strings inside | ||
13 | # quotes (it probably should). | ||
14 | |||
15 | # set this to something else if you want | ||
16 | $convertme = 'convertme.pl'; | ||
17 | |||
18 | # internal-use variables (don't touch) | ||
19 | $convert = 0; | ||
20 | %converted = (); | ||
21 | |||
22 | |||
23 | # prepare the "convert me" file | ||
24 | open(CM, ">$convertme") or die "convertme.pl $!"; | ||
25 | print CM "#!/usr/bin/perl -p -i\n\n"; | ||
26 | |||
27 | # process each file passed on the cmd line | ||
28 | while (<>) { | ||
29 | |||
30 | # if the line says "getopt" in it anywhere, we don't want to muck with it | ||
31 | # because option lists tend to include strings like "cxtzvOf:" which get | ||
32 | # matched by the javaStyle / Hungarian and PascalStyle regexps below | ||
33 | next if /getopt/; | ||
34 | |||
35 | # tokenize the string into just the variables | ||
36 | while (/([a-zA-Z_][a-zA-Z0-9_]*)/g) { | ||
37 | $var = $1; | ||
38 | |||
39 | # ignore the word "BusyBox" | ||
40 | next if ($var =~ /BusyBox/); | ||
41 | |||
42 | # this checks for javaStyle or szHungarianNotation | ||
43 | $convert++ if ($var =~ /^[a-z]+[A-Z][a-z]+/); | ||
44 | |||
45 | # this checks for PascalStyle | ||
46 | $convert++ if ($var =~ /^[A-Z][a-z]+[A-Z][a-z]+/); | ||
47 | |||
48 | if ($convert) { | ||
49 | $convert = 0; | ||
50 | |||
51 | # skip ahead if we've already dealt with this one | ||
52 | next if ($converted{$var}); | ||
53 | |||
54 | # record that we've dealt with this var | ||
55 | $converted{$var} = 1; | ||
56 | |||
57 | print CM "s/\\b$var\\b/"; # more to come in just a minute | ||
58 | |||
59 | # change the first letter to lower-case | ||
60 | $var = lcfirst($var); | ||
61 | |||
62 | # put underscores before all remaining upper-case letters | ||
63 | $var =~ s/([A-Z])/_$1/g; | ||
64 | |||
65 | # now change the remaining characters to lower-case | ||
66 | $var = lc($var); | ||
67 | |||
68 | print CM "$var/g;\n"; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | # tidy up and make the $convertme script executable | ||
74 | close(CM); | ||
75 | chmod 0755, $convertme; | ||
76 | |||