add preparser tool see README.preparser

This commit is contained in:
Karsten Keil 1999-09-12 16:36:44 +00:00
parent 184682ae0e
commit 7c86b69bd3
5 changed files with 319 additions and 35 deletions

61
README.preparser Normal file
View File

@ -0,0 +1,61 @@
"preparser" is a little tool to resolve special macros and conditional
preprocessor code in C files.
The special marcro and conditions are given in a control file.
The control file use the same syntax like the C preprocessor directives
"#define" and "#undef" plus a "#delete" command.
You can also use C-Comments in it.
Here are 2 implicit conditional defines in "preparser" for "#if 0"
and "#if 1" code segments.
Control file syntax:
#delete <item to delete>
#define <name> <value>
#undef <name>
<name> maybe also a function.
/* example control file */
#delete #include <linux/isdn_compat.h>
#define GET_USER get_user
#define PUT_USER put_user
#define idev_kfree_skb(a,b) dev_kfree_skb(a)
#define COMPAT_HAS_NEW_SYMTAB
#undef COMPAT_HAS_NEW_SETUP
/* end of example control file */
What does the Programm ?
1. It copies a input file into a output file (or stdout)
2. While copying it deletes all items given in #delete (exact string
matching).
3. While copying it resolve the marcros given in the control file.
4. It resolve any "#ifdef" "#ifndef" "#if" related to the marcros given in
the control file. Note: in the moment it don't calculate a value after
an "#if" directive, if here is a "#define" in the control file for
the string after "#if" and the value of that "#define" is empty, "#if" is
handled as false, if a value is given it is handled as true.
5. All items inside "strings" or C comments are not modified.
Usage
./preparser [options] <input file> [output file]
Valid options are:
-d increase debug level
-c,-C <controlfile> Use control file
-? Usage ; printout this information
"preparser" was written to write Linux portable Linux kernel code (portable
in the sense "portable between various kernel versions") and to remove
experimental code from C files. This avoid that contructs based on
KERNELVERSION are going into standard kernel.
Karsten Keil
keil@isdn4linux.de
PS: If you like to get the source, request it by mail.

BIN
preparser Executable file

Binary file not shown.

157
std2kern
View File

@ -2,14 +2,19 @@
KERNELDIR=/usr/src/linux KERNELDIR=/usr/src/linux
DOCP=docpd DOCP=docpd
PREPARSER="./preparser"
UNIQUE=false
VERBOSE=false
docpd() { docpd() {
if ! cmp -s $1 $2 ; then if ! cmp -s $1 $2 ; then
echo Copying $1 ... echo Copying $1 ...
mkdir -p `dirname $2` mkdir -p `dirname $2`
cp $1 $2 cp $1 $2
# else else
# echo $2 is up to date, NOT converted if $VERBOSE ; then
echo $2 is up to date, NOT converted
fi
fi fi
} }
@ -18,11 +23,60 @@ docp() {
echo Copying $1 ... echo Copying $1 ...
mkdir -p `dirname $2` mkdir -p `dirname $2`
cp $1 $2 cp $1 $2
# else else
# echo $2 is up to date, NOT converted if $VERBOSE ; then
echo $2 is up to date, NOT converted
fi
fi fi
} }
docpuni() {
if $VERBOSE ; then
echo -n "Processing $1 ... "
fi
TMPNAME=/tmp/`basename $1`.$$
$PREPARSER -c $CTRLNAME $1 $TMPNAME
RES=$?
if [ "$RES" -eq "0" ] ; then
if ! cmp -s $1 $2 ; then
if $VERBOSE ; then
echo copying original
else
echo "Processing $1 ... copying original"
fi
mkdir -p `dirname $2`
cp $1 $2
else
if $VERBOSE ; then
echo original file is up to date
fi
fi
rm $TMPNAME
return 0
fi
if [ "$RES" -eq "2" ] ; then
if ! cmp -s $TMPNAME $2 ; then
if $VERBOSE ; then
echo copying modified
else
echo "Processing $1 ... copying modified"
fi
mkdir -p `dirname $2`
cp $TMPNAME $2
else
if $VERBOSE ; then
echo modified file is up to date
fi
fi
rm $TMPNAME
return 0
fi
echo
echo "problem with $PREPARSER retcode $RES"
exit 1
}
# #
# Print usage and exit # Print usage and exit
# #
@ -32,13 +86,17 @@ usage() {
std2kern is used for updating your kernel-tree from within std2kern is used for updating your kernel-tree from within
this directory. this directory.
std2kern [-d] [-h] [-k DIR] [files ...] std2kern [-d] [-h] [-k DIR] [-v] [-u] [-c FILE] [files ...]
Options: Options:
-h This Text. -h This Text.
-d Copy depends on modification date instead of file-compare. -d Copy depends on modification date instead of file-compare.
-k DIR Kerneltree is in DIR instead of /usr/src/linux -k DIR Kerneltree is in DIR instead of /usr/src/linux
-v More mesages about processing
-u Make a diff for a unique kernel-tree
(preprocessing with $PREPARSER)
-c FILE Use FILE as control file for $PREPARSER (only with -u)
Without any files given, within the whole tree, the "right" Without any files given, within the whole tree, the "right"
files are copied. When any files are given in the commandline, files are copied. When any files are given in the commandline,
@ -61,7 +119,31 @@ checkkernel() {
exit 1 exit 1
} }
while getopts :dhk: a ; do #
# Determine a control file name
#
calc_ctrl_file() {
eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $KERNELDIR/Makefile`
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL"
if [ -z "$CTRLNAME" ] ; then
CTRLNAME=v$VERSION.$PATCHLEVEL.$SUBLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=v$VERSION.$PATCHLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=default.ctrl
fi
if [ -f $CTRLNAME ] ; then
return 0
fi
echo "No control file found"
exit 1
}
while getopts :dhk:uc:v a ; do
case $a in case $a in
\?) case $OPTARG in \?) case $OPTARG in
k) echo "-k requires Kernel directory parameter" k) echo "-k requires Kernel directory parameter"
@ -75,6 +157,12 @@ while getopts :dhk: a ; do
k) checkkernel $OPTARG k) checkkernel $OPTARG
KERNELDIR=$OPTARG KERNELDIR=$OPTARG
;; ;;
c) CTRLNAME=$OPTARG
;;
u) UNIQUE=true
;;
v) VERBOSE=true
;;
d) DOCP=docp d) DOCP=docp
;; ;;
h) usage h) usage
@ -83,6 +171,19 @@ while getopts :dhk: a ; do
done done
shift `expr $OPTIND - 1` shift `expr $OPTIND - 1`
if $UNIQUE ; then
DOCP=docpuni
calc_ctrl_file
fi
echo -n "Using $DOCP"
if $UNIQUE ; then
echo " with controlfile $CTRLNAME"
else
echo
fi
if [ $# != 0 ]; then if [ $# != 0 ]; then
for i in $* ; do for i in $* ; do
$DOCP $i $KERNELDIR/$i $DOCP $i $KERNELDIR/$i
@ -98,7 +199,14 @@ else
$DOCP $i $KERNELDIR/$i $DOCP $i $KERNELDIR/$i
done done
for i in drivers/isdn/hisax/*.[ch] drivers/isdn/hisax/md5sums.asc ; do for i in drivers/isdn/hisax/*.[ch] drivers/isdn/hisax/md5sums.asc ; do
$DOCP $i $KERNELDIR/$i if [ "$i" == "drivers/isdn/hisax/md5sums.asc" -a \
"$UNIQUE" == "true" ] ; then
if $VERBOSE ; then
echo "$i skipped"
fi
else
$DOCP $i $KERNELDIR/$i
fi
done done
for i in drivers/isdn/sc/*.[ch] ; do for i in drivers/isdn/sc/*.[ch] ; do
$DOCP $i $KERNELDIR/$i $DOCP $i $KERNELDIR/$i
@ -130,20 +238,34 @@ else
patch -d $KERNELDIR/Documentation < Documentation/Configure.help.eicon.diff patch -d $KERNELDIR/Documentation < Documentation/Configure.help.eicon.diff
fi fi
fi fi
mkdir -p -m 755 $KERNELDIR/drivers/isdn/eicon
for i in drivers/isdn/eicon/*.[ch] ; do for i in drivers/isdn/eicon/*.[ch] ; do
$DOCP $i $KERNELDIR/$i $DOCP $i $KERNELDIR/$i
done done
for i in include/linux/*.h ; do for i in include/linux/*.h ; do
$DOCP $i $KERNELDIR/$i if [ "$i" == "include/linux/isdn_compat.h" -a \
"$UNIQUE" == "true" ] ; then
if $VERBOSE ; then
echo "$i skipped"
fi
else
$DOCP $i $KERNELDIR/$i
fi
done done
for i in Documentation/isdn/CREDITS Documentation/isdn/README* \ for i in Documentation/isdn/CREDITS Documentation/isdn/README* \
Documentation/isdn/*.FAQ Documentation/isdn/INTERFACE* \ Documentation/isdn/*.FAQ Documentation/isdn/INTERFACE* \
Documentation/isdn/HiSax* Documentation/isdn/00-INDEX ; do Documentation/isdn/HiSax* Documentation/isdn/00-INDEX ; do
$DOCP $i $KERNELDIR/$i if $UNIQUE ; then
docpd $i $KERNELDIR/$i
else
$DOCP $i $KERNELDIR/$i
fi
done done
for i in drivers/isdn/Config.in ; do for i in drivers/isdn/Config.in ; do
$DOCP $i $KERNELDIR/$i if $UNIQUE ; then
docpd $i $KERNELDIR/$i
else
$DOCP $i $KERNELDIR/$i
fi
done done
for i in drivers/isdn/Makefile drivers/isdn/icn/Makefile \ for i in drivers/isdn/Makefile drivers/isdn/icn/Makefile \
drivers/isdn/hisax/Makefile \ drivers/isdn/hisax/Makefile \
@ -151,11 +273,20 @@ else
drivers/isdn/act2000/Makefile \ drivers/isdn/act2000/Makefile \
drivers/isdn/isdnloop/Makefile \ drivers/isdn/isdnloop/Makefile \
drivers/isdn/eicon/Makefile \ drivers/isdn/eicon/Makefile \
drivers/isdn/divert/Makefile \
drivers/isdn/avmb1/Makefile; do drivers/isdn/avmb1/Makefile; do
if [ -f $i.kernel ] ; then if [ -f $i.kernel ] ; then
$DOCP $i.kernel $KERNELDIR/$i if $UNIQUE ; then
docpd $i.kernel $KERNELDIR/$i
else
$DOCP $i.kernel $KERNELDIR/$i
fi
else else
$DOCP $i $KERNELDIR/$i if $UNIQUE ; then
docpd $i $KERNELDIR/$i
else
$DOCP $i $KERNELDIR/$i
fi
fi fi
done done
fi fi

120
stddiff
View File

@ -1,18 +1,41 @@
#!/bin/sh #!/bin/sh
KERNELDIR=/usr/src/linux KERNELDIR=/usr/src/linux
PATCHLEVEL=`head -3 $KERNELDIR/Makefile | grep PATCHLEVEL | awk '{print $3}'`
KERNFIRST=false KERNFIRST=false
PREPARSER="./preparser"
DODIFF=dodiff
UNIQUE=false
dodiff() { dodiff() {
if $KERNFIRST ; then if $KERNFIRST ; then
diff -u $2 $1 diff -u $EXTRAOPT $2 $1
else else
diff -u $1 $2 diff -u $EXTRAOPT $1 $2
fi fi
} }
dodiffuni() {
echo -n "Processing $1 ... "
TMPNAME=/tmp/`basename $1`.$$
$PREPARSER -c $CTRLNAME $1 $TMPNAME
RES=$?
if [ "$RES" -eq "0" ] ; then
echo diff original
dodiff $1 $2
rm $TMPNAME
return 0
fi
if [ "$RES" -eq "2" ] ; then
echo diff modified
dodiff $TMPNAME $2
rm $TMPNAME
return 0
fi
echo "problem with $PREPARSER retcode $RES"
exit 1
}
# #
# Print usage and exit # Print usage and exit
# #
@ -22,13 +45,17 @@ usage() {
stddiff is used for generating diffs of the cvs-tree stddiff is used for generating diffs of the cvs-tree
versus the kernel-tree. versus the kernel-tree.
stddiff [-r] [-h] [-k DIR] [files ...] stddiff [-r] [-h] [-k DIR] [-u] [-c FILE] [-w] [files ...]
Options: Options:
-h This Text. -h This Text.
-r Reverse direction (kernel versus cvs). -r Reverse direction (kernel versus cvs).
-k DIR Kerneltree is in DIR instead of /usr/src/linux -k DIR Kerneltree is in DIR instead of /usr/src/linux
-u Make a diff for a unique kernel-tree
(preprocessing with $PREPARSER)
-c FILE Use FILE as control file for $PREPARSER (only with -u)
-w Ignore white space when comparing lines
Without any files given, within the whole tree, the "right" Without any files given, within the whole tree, the "right"
files are diffed. When any files are given in the commandline, files are diffed. When any files are given in the commandline,
@ -51,7 +78,31 @@ checkkernel() {
exit 1 exit 1
} }
while getopts :rhk: a ; do #
# Determine a control file name
#
calc_ctrl_file() {
eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $KERNELDIR/Makefile`
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL"
if [ -z "$CTRLNAME" ] ; then
CTRLNAME=v$VERSION.$PATCHLEVEL.$SUBLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=v$VERSION.$PATCHLEVEL.ctrl
if [ -f $CTRLNAME ] ; then
return 0
fi
CTRLNAME=default.ctrl
fi
if [ -f $CTRLNAME ] ; then
return 0
fi
echo "No control file found"
exit 1
}
while getopts :rhk:uc:w a ; do
case $a in case $a in
\?) case $OPTARG in \?) case $OPTARG in
k) echo "-k requires Kernel directory parameter" k) echo "-k requires Kernel directory parameter"
@ -65,55 +116,80 @@ while getopts :rhk: a ; do
k) checkkernel $OPTARG k) checkkernel $OPTARG
KERNELDIR=$OPTARG KERNELDIR=$OPTARG
;; ;;
c) CTRLNAME=$OPTARG
;;
u) UNIQUE=true
;;
r) KERNFIRST=true r) KERNFIRST=true
;; ;;
w) EXTRAOPT=-w
;;
h) usage h) usage
;; ;;
esac esac
done done
shift `expr $OPTIND - 1` shift `expr $OPTIND - 1`
if $UNIQUE ; then
DODIFF=dodiffuni
calc_ctrl_file
fi
echo -n "Using $DODIFF $EXTRAOPT"
if $UNIQUE ; then
echo " with controlfile $CTRLNAME"
else
echo
fi
if [ $# != 0 ]; then if [ $# != 0 ]; then
for i in $* ; do for i in $* ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
else else
for i in drivers/isdn/isdn_*.[ch] ; do for i in drivers/isdn/isdn_*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/divert/*.[ch] ; do for i in drivers/isdn/divert/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/icn/icn.[ch] ; do for i in drivers/isdn/icn/icn.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/hisax/*.[ch] drivers/isdn/hisax/md5sums.asc ; do for i in drivers/isdn/hisax/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/avmb1/*.[ch] ; do for i in drivers/isdn/avmb1/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/sc/*.[ch] ; do for i in drivers/isdn/sc/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/pcbit/*.[ch] ; do for i in drivers/isdn/pcbit/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/act2000/*.[ch] ; do for i in drivers/isdn/act2000/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/isdnloop/*.[ch] ; do for i in drivers/isdn/isdnloop/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in drivers/isdn/eicon/*.[ch] ; do for i in drivers/isdn/eicon/*.[ch] ; do
dodiff $i $KERNELDIR/$i $DODIFF $i $KERNELDIR/$i
done done
for i in include/linux/*.h ; do for i in include/linux/*.h ; do
dodiff $i $KERNELDIR/$i if [ "$i" == "include/linux/isdn_compat.h" -a \
"$UNIQUE" == "true" ] ; then
echo "$i skipped"
else
$DODIFF $i $KERNELDIR/$i
fi
done done
for i in Documentation/isdn/CREDITS Documentation/isdn/README* \ for i in Documentation/isdn/CREDITS Documentation/isdn/README* \
Documentation/isdn/*.FAQ \ Documentation/isdn/*.FAQ \
Documentation/isdn/INTERFACE Documentation/isdn/HiSax*; do Documentation/isdn/INTERFACE Documentation/isdn/HiSax* \
drivers/isdn/hisax/md5sums.asc ; do
dodiff $i $KERNELDIR/$i dodiff $i $KERNELDIR/$i
done done
for i in drivers/isdn/Config.in ; do for i in drivers/isdn/Config.in ; do
@ -129,9 +205,9 @@ else
drivers/isdn/hisax/Makefile \ drivers/isdn/hisax/Makefile \
drivers/isdn/pcbit/Makefile ; do drivers/isdn/pcbit/Makefile ; do
if [ -f $i.kernel ] ; then if [ -f $i.kernel ] ; then
dodiff $i.kernel $KERNELDIR/$i dodiff $i.kernel $KERNELDIR/$i
else else
dodiff $i $KERNELDIR/$i dodiff $i $KERNELDIR/$i
fi fi
done done
fi fi

16
v2.3.ctrl Normal file
View File

@ -0,0 +1,16 @@
#delete #include <linux/isdn_compat.h>
#define GET_USER get_user
#define PUT_USER put_user
#define RWTYPE long
#define LSTYPE long long
#define RWARG unsigned long
#define LSARG long long
#define SET_SKB_FREE(x)
#define idev_kfree_skb(a,b) dev_kfree_skb(a)
#define COMPAT_HAS_NEW_SYMTAB
#define CLOSETYPE int
#define CLOSEVAL (0)
#define COMPAT_HAS_NEW_PCI
#define get_pcibase(ps, nr) ps->resource[nr].start
#define COMPAT_HAS_NEW_WAITQ
#define COMPAT_HAS_NEW_SETUP