~ chicken-core (chicken-5) /scripts/csc-trans


 1#!/bin/sh
 2
 3INDENT=indent
 4INDENT_OPTS="-st"
 5ENSCRIPT=enscript
 6ENSCRIPT_OPTS="-q -Ec"
 7CSC_OPTS="-to-stdout"
 8CSC=csc
 9
10# check for options
11COLOR="--color"
12MODE=""
13OUTPUT=-
14ALL=0
15while getopts ":a23ufbihprcotlI:" opt; do
16   case $opt in
17      a ) ALL="1";;
18      h ) MODE="--language=html";;
19      p ) MODE="--language=PostScript";;
20      r ) MODE="--language=rtf";;
21      t ) NOENSCRIPT="1";;
22      c ) COLOR="";; # disable color (on by default)
23      o ) OUTPUT=$OPTARG;;
24      u ) CSC_OPTS="$CSC_OPTS -unsafe";;
25      b ) CSC_OPTS="$CSC_OPTS -block";;
26      f ) CSC_OPTS="$CSC_OPTS -fixnum-arithmetic";;
27      i ) CSC_OPTS="$CSC_OPTS -inline";;
28      I ) CSC_OPTS="$CSC_OPTS -disable-interrupts";;
29      2 ) CSC_OPTS="$CSC_OPTS -O2";;
30      3 ) CSC_OPTS="$CSC_OPTS -O3";;
31      l ) CSC="./csc -compiler ./chicken-static";;
32   esac
33done
34shift $(($OPTIND - 1))
35
36# First argument after options is the file
37FILE=$1
38if [ "x$FILE" = "x" ]; then
39    FILE="/dev/stdin"
40fi
41
42# Only prettify output if the appropriate programs are installed
43if type $INDENT >/dev/null 2>&1; then
44  PASS2="$INDENT $INDENT_OPTS"
45else
46  PASS2=cat
47fi
48if type $ENSCRIPT >/dev/null 2>&1; then
49  PASS3="$ENSCRIPT $ENSCRIPT_OPTS $MODE $COLOR -o $OUTPUT"
50else
51  PASS3=cat
52fi
53if [ -n "$NOENSCRIPT" ]; then
54    PASS3=cat
55fi
56
57# Are we filtering out just the user code?
58if [ "x$ALL" = "x1" ]; then
59  $CSC $CSC_OPTS $FILE | $PASS2 2>/dev/null | $PASS3 2>/dev/null
60else
61  $CSC $CSC_OPTS $FILE |\
62  perl -an000e 'print if /C_trace/&&!/##sys#implicit/ || (/\/\* [-!%\w]+ in k\d+ / && ! /\/\* k\d+ /)' |\
63  $PASS2 | $PASS3
64fi
Trap