# HG changeset patch # User Francisco J Ballesteros # Date 1317232826 -7200 # Node ID 18d9411028dff09048491db303895946d7e7e06c # Parent 5e8d97b0d457bec8d1053b490aec3b9e88c7ef7d rename: c/... is now s/... ask OS X's FS why. R=nix-dev, rminnich CC=nix-dev http://codereview.appspot.com/5128058 diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/argsused --- a/rc/bin/c/argsused Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#!/bin/rc - -cat $* | ssam ', x/\n[a-zA-Z0-9_]+\(.*\)\n{\n}\n/ x/\(.*\)/ { - t +1 - +1 a/\n/ - } - , x/\n\(.*\)\n/ { - x/[a-zA-Z0-9_]+[,)]/ { - i/USED(/ - x/,/c/)/ - } - } - , x/\n{\n\(.*\)\n/ x/\(.*/ s/\)/);/g - , x/\n{\n\(.*/ x/\(.*/ y/USED\([a-zA-Z0-9_]*\);/c/\n / - , x/\n{\n\n/c/\n{\n/ - , x/\n \n}\n/c/\n}\n/ - ,p' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/badexterns --- a/rc/bin/c/badexterns Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#!/bin/rc -# -# check out externs used just in one place; and warn. -# -rfork e - -if(~ $#* 0 1){ - echo usage: $0 files >[1=2] - exit usage -} - -nms=`{ {for(o in $*){ nm $o | grep ' [TDB] ' }} | awk '{print $NF}' | sort -u} - -nm $* >/tmp/nmout -for(n in $nms){ - if(~ `{grep ' '^$n^'$' /tmp/nmout | wc -l} 1) - grep ' '^$n^'$' /tmp/nmout -} -rm /tmp/nmout -exit '' - diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/badglobals --- a/rc/bin/c/badglobals Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#!/bin/rc -# -# check out that we seem to use our globals -# -rfork e - -NOT READY - -if(~ $#* 0 ){ - echo usage: $0 files >[1=2] - exit usage -} - -for(o in $*){ - nms=`{nm $o | grep ' [TDBtdb] ' | awk '{print $NF}'} - for(n in $nms){ - c=`{echo $o | sed 's/\.[0-9]$/.c/'} - grep '(^'^$n^[^a-z0-9A-Z_]')|(^[^a-z0-9A-Z_]'^$n^'[^a-z0-9A-Z_])' $c - } -} -exit '' - diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/enum2sw --- a/rc/bin/c/enum2sw Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/rc - -sed -e 's/^ / case /' \ - -e 's/[ ]=.*,/,/' \ - -e 's/,/:/' \ - -e 's/$/\n break;/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/f2p --- a/rc/bin/c/f2p Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/rc - -cat $* | ssam ', y/.+\n[π∏∆∂A-Za-z0-9_]+\(.*\n/c// ' \ - ', s/\n([π∏∆∂A-Za-z0-9_]+\()/ \1/g' ', p' | \ -grep -v '^static' | grep -v threadmain | sed -e 's/$/;/' -e 's/^/extern /' | sort +2 -exit '' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/ifs --- a/rc/bin/c/ifs Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -#!/bin/rc -cat $* | sed -e 's/(if|for|while) \(/\1(/' -e 's/\) {/){/' -e 's/} else/}else/' -e 's/else {/else{/' \ - -e 's/enum ?{/enum\n{/' \ - -e 's/^struct ?([^{]+){/struct\n\1 {/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/mkdeps --- a/rc/bin/c/mkdeps Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#!/bin/rc -# -# generate list of HFILES and dependencies for each .$O -# -rfork e - -if(~ $#* 0 1){ - echo usage: $0 files >[1=2] - exit usage -} - -cs=$* -hdrs=`{grep -h '^#include[ ]*"' $cs | sed 's/#include[ ]*"([^"]+)".*/\1/' | sort -u} - -echo 'HFILES=\' - -all=() -for(h in $hdrs){ - nh=`{grep '^#include[ ]*"'^$h^'"' $cs | wc -l} - if(~ $nh $#cs){ - echo ' '^$h^'\' - all=($all $h) - } -} - -for(c in $cs){ - hs=`{grep -h '^#include[ ]*"' $c | sed 's/#include[ ]*"([^"]+)".*/\1/' } - echo -n `{echo $c | sed 's/\.c$/.$O:/'} - for(h in $hs) - if(! ~ $h $all) - echo -n ' '^$h - echo -} -exit '' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/mktypedefs --- a/rc/bin/c/mktypedefs Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#!/bin/rc - -grep '^struct[ ]+' $* | - sed -e 's/struct[ ]+([∏πa-zA-Z0-9_]+).*/typedef struct \1 \1;/' | - sort -u - - diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/p2f --- a/rc/bin/c/p2f Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -#!/bin/rc -cat $* | sed 's/[a-z_0-9∏π∂∆]+\(/\n&/' | sed 's/;$/\n{\n}\n/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/psort --- a/rc/bin/c/psort Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/rc - -sort -f +1 -2 diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/c/rep --- a/rc/bin/c/rep Wed Sep 28 10:34:58 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/bin/rc -rfork e -tmp=/tmp/rep.$pid -if(~ $#* 0){ - echo usage $0 from to.... - exit usage -} -orig=$1 -shift -cat >$tmp ; for(f in $*) { cat $tmp | sed s/$orig/$"f/g} -rm -f $tmp -exit '' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/argsused --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/argsused Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,17 @@ +#!/bin/rc + +cat $* | ssam ', x/\n[a-zA-Z0-9_]+\(.*\)\n{\n}\n/ x/\(.*\)/ { + t +1 + +1 a/\n/ + } + , x/\n\(.*\)\n/ { + x/[a-zA-Z0-9_]+[,)]/ { + i/USED(/ + x/,/c/)/ + } + } + , x/\n{\n\(.*\)\n/ x/\(.*/ s/\)/);/g + , x/\n{\n\(.*/ x/\(.*/ y/USED\([a-zA-Z0-9_]*\);/c/\n / + , x/\n{\n\n/c/\n{\n/ + , x/\n \n}\n/c/\n}\n/ + ,p' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/badexterns --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/badexterns Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,21 @@ +#!/bin/rc +# +# check out externs used just in one place; and warn. +# +rfork e + +if(~ $#* 0 1){ + echo usage: $0 files >[1=2] + exit usage +} + +nms=`{ {for(o in $*){ nm $o | grep ' [TDB] ' }} | awk '{print $NF}' | sort -u} + +nm $* >/tmp/nmout +for(n in $nms){ + if(~ `{grep ' '^$n^'$' /tmp/nmout | wc -l} 1) + grep ' '^$n^'$' /tmp/nmout +} +rm /tmp/nmout +exit '' + diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/badglobals --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/badglobals Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,22 @@ +#!/bin/rc +# +# check out that we seem to use our globals +# +rfork e + +NOT READY + +if(~ $#* 0 ){ + echo usage: $0 files >[1=2] + exit usage +} + +for(o in $*){ + nms=`{nm $o | grep ' [TDBtdb] ' | awk '{print $NF}'} + for(n in $nms){ + c=`{echo $o | sed 's/\.[0-9]$/.c/'} + grep '(^'^$n^[^a-z0-9A-Z_]')|(^[^a-z0-9A-Z_]'^$n^'[^a-z0-9A-Z_])' $c + } +} +exit '' + diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/enum2sw --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/enum2sw Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,6 @@ +#!/bin/rc + +sed -e 's/^ / case /' \ + -e 's/[ ]=.*,/,/' \ + -e 's/,/:/' \ + -e 's/$/\n break;/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/f2p --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/f2p Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,6 @@ +#!/bin/rc + +cat $* | ssam ', y/.+\n[π∏∆∂A-Za-z0-9_]+\(.*\n/c// ' \ + ', s/\n([π∏∆∂A-Za-z0-9_]+\()/ \1/g' ', p' | \ +grep -v '^static' | grep -v threadmain | sed -e 's/$/;/' -e 's/^/extern /' | sort +2 +exit '' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/ifs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/ifs Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,4 @@ +#!/bin/rc +cat $* | sed -e 's/(if|for|while) \(/\1(/' -e 's/\) {/){/' -e 's/} else/}else/' -e 's/else {/else{/' \ + -e 's/enum ?{/enum\n{/' \ + -e 's/^struct ?([^{]+){/struct\n\1 {/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/mkdeps --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/mkdeps Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,34 @@ +#!/bin/rc +# +# generate list of HFILES and dependencies for each .$O +# +rfork e + +if(~ $#* 0 1){ + echo usage: $0 files >[1=2] + exit usage +} + +cs=$* +hdrs=`{grep -h '^#include[ ]*"' $cs | sed 's/#include[ ]*"([^"]+)".*/\1/' | sort -u} + +echo 'HFILES=\' + +all=() +for(h in $hdrs){ + nh=`{grep '^#include[ ]*"'^$h^'"' $cs | wc -l} + if(~ $nh $#cs){ + echo ' '^$h^'\' + all=($all $h) + } +} + +for(c in $cs){ + hs=`{grep -h '^#include[ ]*"' $c | sed 's/#include[ ]*"([^"]+)".*/\1/' } + echo -n `{echo $c | sed 's/\.c$/.$O:/'} + for(h in $hs) + if(! ~ $h $all) + echo -n ' '^$h + echo +} +exit '' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/mktypedefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/mktypedefs Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,7 @@ +#!/bin/rc + +grep '^struct[ ]+' $* | + sed -e 's/struct[ ]+([∏πa-zA-Z0-9_]+).*/typedef struct \1 \1;/' | + sort -u + + diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/p2f --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/p2f Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,2 @@ +#!/bin/rc +cat $* | sed 's/[a-z_0-9∏π∂∆]+\(/\n&/' | sed 's/;$/\n{\n}\n/' diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/psort --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/psort Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,3 @@ +#!/bin/rc + +sort -f +1 -2 diff -r 5e8d97b0d457 -r 18d9411028df rc/bin/s/rep --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rc/bin/s/rep Wed Sep 28 20:00:26 2011 +0200 @@ -0,0 +1,12 @@ +#!/bin/rc +rfork e +tmp=/tmp/rep.$pid +if(~ $#* 0){ + echo usage $0 from to.... + exit usage +} +orig=$1 +shift +cat >$tmp ; for(f in $*) { cat $tmp | sed s/$orig/$"f/g} +rm -f $tmp +exit '' diff -r 5e8d97b0d457 -r 18d9411028df sys/man/1/f2p --- a/sys/man/1/f2p Wed Sep 28 10:34:58 2011 -0700 +++ b/sys/man/1/f2p Wed Sep 28 20:00:26 2011 +0200 @@ -1,48 +1,48 @@ .TH F2P 1 .SH NAME -argsused, badexterns, badglobals, enum2sw, f2p, ifs, mkdeps, mktypedefs, p2f, psort, rep \- tiny C tools +argsused, badexterns, badglobals, enum2sw, f2p, ifs, mkdeps, mktypedefs, p2f, psort, rep \- tiny source code tools .SH SYNOPSIS -.B c/argsused +.B s/argsused [ .I file ... ] .PP -.B c/badexterns +.B s/badexterns .I files ... .PP -.B c/badglobals +.B s/badglobals .I files ... .PP -.B c/enum2sw +.B s/enum2sw .PP -.B c/f2p +.B s/f2p [ .I file ... ] .PP -.B c/ifs +.B s/ifs [ .I file ... ] .PP -.B c/mkdeps +.B s/mkdeps [ .I file ... ] .PP -.B c/mktypedefs +.B s/mktypedefs [ .I file ... ] .PP -.B c/p2f +.B s/p2f [ .I file ... ] .PP -.B c/psort +.B s/psort .PP -.B c/rep +.B s/rep .I from .I to... .SH DESCRIPTION @@ -52,61 +52,61 @@ Many of them use standard input if no file is given as an argument, and are suitable for use within .IR acme (1). -.TF c/mktypedefs +.TF s/mktypedefs .TP -.B c/argsused +.B s/argsused generates a .I USED(x) sentence for each argument in the functions found in the input files or standard input. .TP -.B c/badexterns +.B s/badexterns receives a series of object files as arguments and locates external symbols used in just one file. Those should perhaps be declared as static symbols. .TP -.B c/badglobals +.B s/badglobals receives a series of object tiles as arguments and locates global symbols that appear to be unused. They could probably go. .TP -.B c/enum2sw +.B s/enum2sw receives as input a declaration of values (e.g., part of declarations within a .IR enum ) and generates a .I switch statement for them. .TP -.B c/f2p +.B s/f2p generates a prototype declaration for each non-static function found in the input. .TP -.B c/p2f +.B s/p2f does the opposite, and writes an empty function definition for each prototype found in the input. .TP -.B c/ifs +.B s/ifs gets rid of spaces that should not be there according to the Plan 9 C style. .TP -.B c/mkdeps +.B s/mkdeps generates dependencies for .I mk (1) according to .I include directives found in the input. .TP -.B c/mktypedefs +.B s/mktypedefs generates .I typedef declarations for each .I struct definition found in the input. .TP -.B c/psort +.B s/psort sorts prototypes by name. .TP -.B c/rep +.B s/rep repeats the text found in the input so that .I from is replaced each time by one of the values given as .I to . .SH SOURCE -.B /rc/bin/c +.B /rs/bin/s .SH BUGS Many. All these tools are tiny shell scripts and do not perform much error checking. Also, they assume code is written using the style of