changeset 23935:b4a1d0cf4c11

Test for reserved identifiers. Identifiers with two initial underscores or an initial underscore followed by an uppercase letter are reserved globally for use by the compiler.
author ivo
date Tue, 31 Jul 2007 07:45:06 +0000
parents 88bed2131f19
children c0b23a73d5f1
files TOOLS/checktree.sh
diffstat 1 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/TOOLS/checktree.sh	Tue Jul 31 07:04:07 2007 +0000
+++ b/TOOLS/checktree.sh	Tue Jul 31 07:45:06 2007 +0000
@@ -27,6 +27,7 @@
 _stupid=no
 _showcont=no
 _gnu=no
+_res=no
 
 _color=yes
 _head=yes
@@ -54,6 +55,7 @@
     _charset=yes
     _stupid=yes
     _gnu=yes
+    _res=yes
 }
 
 disable_all_tests() {
@@ -67,6 +69,7 @@
     _charset=no
     _stupid=no
     _gnu=no
+    _res=no
 }
 
 printoption() {
@@ -109,6 +112,7 @@
         printoption "charset   " "test for wrong charset" "$_charset"
         printoption "stupid    " "test for stupid code" "$_stupid"
         printoption "gnu       " "test for GNUisms" "$_gnu"
+        printoption "res       " "test for reserved identifiers" "$_res"
         echo
         printoption "all       " "enable all tests" "no"
         echo  "                   (-noall can be specified as -none)"
@@ -217,6 +221,12 @@
     -nognu)
         _gnu=no
         ;;
+    -res)
+        _res=yes
+        ;;
+    -nores)
+        _res=no
+        ;;
     -*)
         echo "unknown option: $i" >&2
         exit 0
@@ -243,6 +253,12 @@
 
 filelist=`all_filenames`
 
+if [ "$_stupid" = "yes" -o "$_res" = "yes" ] ; then
+    # generate 'shortlist' to avoid false positives in xpm files, docs, etc,
+    # when one only needs to check .c and .h files
+    chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
+fi
+
 if [ "$_showcont" = "yes" ]; then
   _diffopts="-u"
   _grepopts="-n -I"
@@ -315,6 +331,14 @@
 
 # -----------------------------------------------------------------------------
 
+if [ "$_res" = "yes" ]; then
+    printhead "checking for reserved identifiers ..."
+    grep $_grepopts "#[ $TAB]*define[ $TAB]\+_[[:upper:]].*" $chfilelist
+    grep $_grepopts "#[ $TAB]*define[ $TAB]\+__.*" $chfilelist
+fi
+
+# -----------------------------------------------------------------------------
+
 if [ "$_charset" = "yes" ]; then
     printhead "checking bad charsets ..."
     for I in $filelist ; do
@@ -335,9 +359,6 @@
 if [ "$_stupid" = "yes" ]; then
     printhead "checking for stupid code ..."
 
-    # avoid false-positives in xpm files, docs, etc, only check .c and .h files
-    chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
-
   if [ -n "$chfilelist" ]; then
     for i in calloc malloc realloc memalign av_malloc av_mallocz faad_malloc \
              lzo_malloc safe_malloc mpeg2_malloc _ogg_malloc; do