1 #!/bin/bash
   2 
   3 PARSE_ONLY=0
   4 
   5 function just_body {
   6     if [[ $PARSE_ONLY == 1 ]]; then
   7         sed -e '/^[[:space:]]*$/d' -e '/^#/d' \
   8             -e 's/^[[:space:]]\+//' -e 's/[[:space:]]\+/ /g'
   9     else
  10         sed -e '/^#/d' -e '/^$/d'
  11     fi
  12 }
  13 
  14 function test_file {
  15     file=$1
  16     diff -L "$file (Sun cpp)" -L "$file (Joyent cpp)" -u \
  17         <(/usr/lib/cpp $file 2>/dev/null | just_body) \
  18         <(./cpp $file 2>/dev/null | just_body)
  19 }
  20 
  21 while getopts p name; do
  22     case $name in
  23         p) PARSE_ONLY=1;;
  24     esac
  25 done
  26 shift $(($OPTIND - 1))
  27 
  28 if (( $# > 0 )); then
  29     while (( $# > 0 )); do
  30         test_file $1
  31         shift;
  32     done
  33 else
  34     for elt in /usr/include/**/*.h; do
  35         # C++ that will never parse
  36         [[ $elt == */firefox/* ]] && continue
  37         # Triggers pre-ANSI infinitely recursive expansion
  38         [[ $elt == */ncurses/* ]] && continue
  39         print -u2 "*** $elt"
  40         test_file $elt
  41     done
  42 fi