guile-snarf.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. # Extract the initialization actions from source files.
  3. #
  4. # Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002 Free Software Foundation, Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this software; see the file COPYING. If not, write to
  18. # the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. # Boston, MA 02111-1307 USA
  20. # Commentary:
  21. # Usage: guile-snarf [-d | -D] [-o OUTFILE] INFILE [CPP-OPTIONS ...]
  22. #
  23. # Process INFILE using the C pre-processor and some other programs.
  24. # Write output to a file named OUTFILE or to the standard output when no
  25. # OUTFILE has been specified or when OUTFILE is "-".
  26. #
  27. # If there are errors during processing, delete OUTFILE and exit with
  28. # non-zero status.
  29. #
  30. # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
  31. # defined.
  32. #
  33. # Optional arg "-d" means grep INFILE for deprecated macros and
  34. # issue a warning if any are found. Alternatively, "-D" means
  35. # do the same thing but signal error and exit w/ non-zero status.
  36. #
  37. # If env var CPP is set, use its value instead of the C pre-processor
  38. # determined at Guile configure-time: "@CPP@".
  39. # Code:
  40. ## config
  41. deprecated_list="
  42. SCM_CONST_LONG
  43. SCM_VCELL
  44. SCM_VCELL_INIT
  45. SCM_GLOBAL_VCELL
  46. SCM_GLOBAL_VCELL_INIT
  47. "
  48. ## funcs
  49. old_school_snarf () # writes stdout
  50. {
  51. ${cpp} -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
  52. grep "^ *SCM__I" ${temp} | sed -e 's/^ *SCM__I//' -e 's/SCM__D.*$//g'
  53. }
  54. modern_snarf () # writes stdout
  55. {
  56. ## Apparently, AIX's preprocessor is unhappy if you try to #include an
  57. ## empty file.
  58. echo "/* source: $infile */" ;
  59. echo "/* cpp arguments: $@ */" ;
  60. ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
  61. grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//" -e "s/\^\ *:\ *\^.*/;/"
  62. }
  63. grep_deprecated () # $1 is the filename
  64. {
  65. regexp="(^greetings!spooks!hows!life)"
  66. for dep in `echo $deprecated_list` ; do
  67. regexp="(^${dep}[^_A-Z])|${regexp}"
  68. done
  69. egrep -n ${regexp} $1 /dev/null > ${temp}
  70. if [ -s ${temp} ] ; then
  71. if $grep_dep_exit_p ; then hey=ERROR ; else hey=WARNING ; fi
  72. echo $0: $hey: deprecated macros found:
  73. sed -e 's/.clean.c:/:/g' ${temp}
  74. $grep_dep_exit_p && exit 1
  75. fi
  76. }
  77. ## main
  78. # process command line
  79. if [ x"$1" = x--help ] ; then
  80. @AWK@ '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  81. | sed -e 1,2d -e 's/^. *//g'
  82. exit 0
  83. fi
  84. case x"$1" in x-d) grep_dep_p=true ; grep_dep_exit_p=false ; shift ;;
  85. x-D) grep_dep_p=true ; grep_dep_exit_p=true ; shift ;;
  86. *) grep_dep_p=false ;;
  87. esac
  88. if [ x"$1" = x-o ]
  89. then outfile=$2 ; shift ; shift ; infile=$1 ; shift
  90. else outfile="-"; infile=$1 ; shift
  91. fi
  92. [ x"$infile" = x ] && { echo $0: No input file ; exit 1 ; }
  93. [ ! -f "$infile" ] && { echo $0: No such file: $infile ; exit 1 ; }
  94. # set vars and handler -- handle CPP override
  95. cpp_ok_p=false
  96. temp="/tmp/snarf.$$"
  97. if [ x"$CPP" = x ] ; then cpp="@CPP@" ; else cpp="$CPP" ; fi
  98. trap "rm -f $temp" 0 1 2 15
  99. if [ ! "$outfile" = "-" ]; then
  100. old_school_snarf "$@" $infile > $outfile
  101. else
  102. old_school_snarf "$@" $infile
  103. fi
  104. # grep deprecated
  105. $grep_dep_p && grep_deprecated $infile
  106. # zonk outfile if errors occurred
  107. if $cpp_ok_p ; then
  108. exit 0
  109. else
  110. [ ! "$outfile" = "-" ] && rm -f $outfile
  111. exit 1
  112. fi
  113. # guile-snarf ends here