(linenum→info "unix/slp.c:2238")

bsd-games/2.17/substscr

    1: #!/bin/sh
    2: # substscr - substitute parameters to create a file from a .in.
    3: #
    4: # Copyright (c) 1999, 2004 Joseph Samuel Myers.
    5: # All rights reserved.
    6: #
    7: # Redistribution and use in source and binary forms, with or without
    8: # modification, are permitted provided that the following conditions
    9: # are met:
   10: # 1. Redistributions of source code must retain the above copyright
   11: #    notice, this list of conditions and the following disclaimer.
   12: # 2. Redistributions in binary form must reproduce the above copyright
   13: #    notice, this list of conditions and the following disclaimer in the
   14: #    documentation and/or other materials provided with the distribution.
   15: # 3. The name of the author may not be used to endorse or promote products
   16: #    derived from this software without specific prior written permission.
   17: #
   18: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   19: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   20: # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   21: # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   22: # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   23: # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   24: # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
   25: # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   26: # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28: # SUCH DAMAGE.
   29: 
   30: # First argument is some combination of:
   31: # r to generate makefile rules
   32: # g to generate the file in question
   33: 
   34: # Second argument gives the style of comment:
   35: # c for C comment
   36: # h for generic # comment
   37: # m for manpage comment
   38: # n for none
   39: # s for shell comment
   40: 
   41: # Third argument is the source file.
   42: 
   43: # Fourth argument is the target file.
   44: 
   45: # The target gets its execute permissions from the source.
   46: 
   47: set -e
   48: 
   49: if [ $# != 4 ]; then
   50:     echo "usage: $0 action comment-style source target" >&2
   51:     exit 1
   52: fi
   53: 
   54: action="$1"
   55: style="$2"
   56: source="$3"
   57: target="$4"
   58: 
   59: if echo $action |grep -q g; then
   60:     echo "Generating $target from $source"
   61:     rm -f $target
   62: 
   63:     case "$style" in
   64:         (c)
   65:             echo "/* Automatically generated from $source.  Do not edit.  */" >"$target"
   66:             ;;
   67:         (h)
   68:             echo "# Automatically generated from $source.  Do not edit." >"$target"
   69:             ;;
   70:         (m)
   71:             echo ".\\\" Automatically generated from $source.  Do not edit." >"$target"
   72:             ;;
   73:         (n)
   74:             : >"$target"
   75:             ;;
   76:         (s)
   77:             echo "#!/bin/sh" >"$target"
   78:             echo "# Automatically generated from $source.  Do not edit." >>"$target"
   79:             ;;
   80:         (*)
   81:             echo "$0: unknown comment style $style" >&2
   82:             exit 1
   83:     esac
   84: 
   85:     sed -f subst.sed <"$source" >>"$target"
   86: 
   87:     if [ -x "$source" ]; then
   88:         chmod a+x "$target"
   89:     fi
   90: fi
   91: 
   92: if echo $action |grep -q r; then
   93:     # Append to subst.rules.
   94:     cat >>subst.rules <<EOF
   95: $target:        $source subst.sed substscr
   96:         ./substscr g $style $source $target
   97: 
   98: EOF
   99: fi
Syntax (Markdown)