#!/bin/ksh # Time-stamp: <2010-09-08 13:35:25 sager> # # Find all the C pre-processor flags used in the current TM5 base, projects # and branches. Does not look into ".svn", "TM", and "release" (since they # are frozen) directories. # # Look for: # "#ifdef with_", "#ifdef without_", "#ifndef with_", # "#ifndef without_" , "#if defined (with" # # flags, and in $PWD. # # The script looks down $1 if argument is passed, else down $PWD. # It also accounts for stuff like : #if defined(with_...) || defined(with_...) # # See TIP at end of the script. # # Examples : # to look down $PWD # --------- find_cpp # # # to look down ~/TM5, and save result: # find_cpp ~/TM5 > ~/ctm5-cpp #----------------- # search function #----------------- function gsvn { find . -name .svn -prune -o -name release -prune -o -name TM -prune -o \ -name '*.F90' -o -name '*.h' | xargs egrep "$@" } #----------------- # search function #2 : same but also skips mdf* and tmm* files, as well as # obsolete projects #----------------- function gsvn_2 { find . -name .svn -prune -o -name release -prune -o -name TM -prune \ -o -name ipcc -prune -o -name aero -prune \ -o \( -name '*.F90' ! -name tmm* ! -name mdf* \) | xargs egrep "$@" } #---------- # Argument #---------- [[ -d $1 ]] || set -- $PWD ; cd $1 #--------------------------- # Get list of C-preprocessor #--------------------------- # Note - Could probably speed things up by combining all 3 searches into 1 # search: # gsvn_2 -i "^[[:blank:]]*#if.*def.*with" > ~/findcpptem.txt # # and then (the tricky part) combine the 2 sed into one. Leave it for future # exercise... #--------------------------- # Look for : #ifdef and #ifndef gsvn_2 -i "^[[:blank:]]*#ifn?def with(out)?_[:word:]*" > ~/findcpptemp1.txt # Look for : #if defined gsvn_2 -i "^[[:blank:]]*#if defined *\(with(out)?_" | \ sed "s/#if defined *(\([^|]*\)).*/#ifdef \1/" >> ~/findcpptemp1.txt # Look for : "|| defined" after a #if defined gsvn_2 -i "^[[:blank:]]*#if defined.*\|\|" | \ sed "s/#if defined.*defined(\([^|]*\)).*/#ifdef \1/" >> ~/findcpptemp1.txt awk '{print $2}' ~/findcpptemp1.txt | sort | uniq -c > ~/findcpptemp2.txt #----------------------------------------------- # Get number of files using each C-preprocessor #----------------------------------------------- echo " NFiles NOccur Cpp-flag" { while read nn cppflag do nfiles=$(grep "$cppflag\>" ~/findcpptemp1.txt | awk -F ":" '{print $1}' | \ sort | uniq | wc -l) printf '%7i %7i %s\n' $nfiles $nn $cppflag done } < ~/findcpptemp2.txt #--------------------------- # Clean up #--------------------------- rm -f ~/findcpptemp*.txt #------------------------------------------- # TIP : add gsvn to your shell resource file (.bashrc, .user_kshrc, ...) #------------------------------------------- # gsvn is as powerful as egrep, since it is a wrapper for the # latter. So you can pass any option flag accepted by egrep. # # For example, to find which Fortran routines is using "with_lapack": # # gsvn -il "with_lapack" # # or better: # # gsvn -il "^[[:blank:]]*#if.*def.* with_lapack\>" | uniq # # To proove that the module user_output_cf is only used within an #ifdef with_cf_output: # # gsvn -inC 1 "^[[:blank:]]*use *user_output_cf"