File: debiandoc2ps

package info (click to toggle)
debiandoc-sgml 1.0.18
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 292 kB
  • ctags: 41
  • sloc: makefile: 245; perl: 211; sh: 188
file content (107 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
set -e

usageversion () {
	echo >&2 \
'debiandoc2ps Copyright (C)1996 Ian Jackson
This is free software; see the GNU General Public Licence
version 2 or later for copying conditions.  There is NO warranty.

usage: debiandoc2ps [options] <filename>.sgml
options:  -k              keep intermediate files
          -p<papersize>   generate output for named paper size
          -O              send output to stdout instead of <filename>.ps
          -1              do not do 2-up printing'
}

usageerror () { echo >&2 "debiandoc2lout: $@"; usageversion; exit 2; }

nup=true
stdout=false
keep=false
keepopt=''

while [ $# != 0 ]
do
	case "$1" in
	-k)	keep=true; keepopt="-k"	;;
	-O)	stdout=true		;;
	-1)	nup=false		;;
	-p*)	PAPERCONF="`echo \"x$1\" | sed -e 's/^x-p//'`"; export PAPERCONF ;;
	-?*)	usageerror "unknown option \`$1'" ;;
	--)	shift; break		;;
	*)	break			;;
	esac
	shift
done

usageerror () { echo >&2 "debiandoc2ps: $@"; usageversion; exit 2; }

[ $# = 1 ] || usageerror "need exactly one input filename"

case "$1" in
-)	louti="-"
	stdout=true
	if $keep; then usageerror "-k not allowed with input from stdin"; fi
	;;
-?*)	louti="./$1"
	bn="`basename \"$1\" .sgml`"
	;;
*)	louti="$1"
	bn="`basename \"$1\" .sgml`"
	;;
esac

case "$bn" in -*) bn="./$bn" ;; esac

rc=2

tf1="$bn.lout"
tf2="$bn.ps1"
tf3="$bn.ps1x"

debiandoc2lout $keepopt -O "$louti" >"$tf1"

(
	if $nup
	then
		exec >"$tf2"
	else
		$stdout || exec >"$bn.ps"
	fi
	set +e
	lout "$tf1" >/dev/null 2>&1
	lout "$tf1" >/dev/null 2>&1
	set -e
	lout "$tf1"
)

if ! $nup; then rc=0; exit 0; fi

perl -e '
	while (<>) {
		if (m/^\%\%Page: /) {
			print(<<END) || die $!;
%%Page: 0 0
%%BeginPageSetup
%%PageResources:
%%EndPageSetup
END
			last;
		}
		print || die $!;
	}
	do { print || die $!; } while (<>);
	close(STDOUT) || die $!;
' <"$tf2" >"$tf3"

$stdout || exec >"$bn.ps"

psnup -p"`paperconf -n`" -2 <"$tf3"

if ! $keep
then
    rm -f $tf1 $tf1.ld $tf2 $tf3 lout.li
fi

rc=0