3 # @(#) mk2knr.pl - generates a perl script that converts lexemes to K&R-style
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
12 # BUGS: This script does not ignore strings inside comments or strings inside
13 # quotes (it probably should).
15 # set this to something else if you want
16 $convertme = 'convertme.pl';
18 # internal-use variables (don't touch)
23 # prepare the "convert me" file
24 open(CM, ">$convertme") or die "convertme.pl $!";
25 print CM "#!/usr/bin/perl -p -i\n\n";
27 # process each file passed on the cmd line
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
35 # tokenize the string into just the variables
36 while (/([a-zA-Z_][a-zA-Z0-9_]*)/g) {
39 # ignore the word "BusyBox"
40 next if ($var =~ /BusyBox/);
42 # this checks for javaStyle or szHungarianNotation
43 $convert++ if ($var =~ /^[a-z]+[A-Z][a-z]+/);
45 # this checks for PascalStyle
46 $convert++ if ($var =~ /^[A-Z][a-z]+[A-Z][a-z]+/);
51 # skip ahead if we've already dealt with this one
52 next if ($converted{$var});
54 # record that we've dealt with this var
57 print CM "s/\\b$var\\b/"; # more to come in just a minute
59 # change the first letter to lower-case
62 # put underscores before all remaining upper-case letters
63 $var =~ s/([A-Z])/_$1/g;
65 # now change the remaining characters to lower-case
73 # tidy up and make the $convertme script executable
75 chmod 0755, $convertme;