| 1 |
#!/bin/sh |
| 2 |
#****************************************************************************** |
| 3 |
# File: @(#)$Id: catppd,v 1.2 2001/03/16 07:57:12 Martin Rel $ |
| 4 |
# Contents: Primitive *Include resolver for PPD files |
| 5 |
# Call: catppd <top-level file> <target directory or file> |
| 6 |
# Author: Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig, |
| 7 |
# Germany; [email protected] |
| 8 |
# |
| 9 |
#****************************************************************************** |
| 10 |
# * |
| 11 |
# Copyright (C) 2001 by Martin Lottermoser * |
| 12 |
# All rights reserved * |
| 13 |
# * |
| 14 |
#****************************************************************************** |
| 15 |
# |
| 16 |
# All PPD files included with relative path names must be accessible from the |
| 17 |
# current working directory. |
| 18 |
# |
| 19 |
#****************************************************************************** |
| 20 |
|
| 21 |
name=catppd |
| 22 |
|
| 23 |
# Collect the arguments |
| 24 |
if [ $# -ne 2 ]; then |
| 25 |
printf '? Usage: %s <top-level file> <target directory or file>\n' "$0" >&2 |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
infile="$1" |
| 29 |
if [ -d "$2" ]; then |
| 30 |
outfile="$2"/`basename "$infile"` |
| 31 |
else |
| 32 |
outfile="$2" |
| 33 |
fi |
| 34 |
|
| 35 |
# Check arguments for validity |
| 36 |
if [ ! -f "$infile" -o ! -r "$infile" ]; then |
| 37 |
printf '? %s: `%s'\'' is not accessible.\n' "$name" "$infile" >&2 |
| 38 |
exit 1 |
| 39 |
fi |
| 40 |
if [ -f "$outfile" ]; then |
| 41 |
printf '? %s: There is already a file %s.\n' "$name" "$outfile" >&2 |
| 42 |
exit 1 |
| 43 |
fi |
| 44 |
|
| 45 |
# Create awk script |
| 46 |
tmp="${TMPDIR:-/tmp}/$$.tmp" |
| 47 |
rm -f "$tmp" |
| 48 |
: ${AWK:=awk} |
| 49 |
cat << '---' | sed -e "s,@AWK@,$AWK," -e "s,@TMP@,$tmp," > "$tmp" || exit 1 |
| 50 |
NR == 1 && first == "" && $1 ~ /^\*PPD-Adobe:/ {next} |
| 51 |
/^\*Include: *".*"$/ { |
| 52 |
quote = index($0, "\"") |
| 53 |
lastquote = length($0) |
| 54 |
file = substr($0, quote+1, lastquote-quote-1) |
| 55 |
# No support for hexadecimal substrings. |
| 56 |
printf "*%% Begin included file \"%s\"\n", file |
| 57 |
if (system("@AWK@ -f @TMP@ " file) != 0) exit 1 |
| 58 |
printf "*%% End included file \"%s\"\n", file |
| 59 |
next |
| 60 |
} |
| 61 |
{print $0} |
| 62 |
--- |
| 63 |
|
| 64 |
# Create output file |
| 65 |
$AWK -f "$tmp" -v first=yes "$infile" > "$outfile" || \ |
| 66 |
{ rm -f "$tmp" "$outfile"; exit 1; } |
| 67 |
|
| 68 |
# Clean up |
| 69 |
rm -f "$tmp" |
| 70 |
|
| 71 |
exit 0 |