File: debiandoc2ps

package info (click to toggle)
debiandoc-sgml 1.1.12
  • links: PTS
  • area: main
  • in suites: slink
  • size: 448 kB
  • ctags: 150
  • sloc: perl: 1,060; sh: 401; makefile: 302
file content (129 lines) | stat: -rw-r--r-- 2,187 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
set -e

usageversion () {
	echo >&2 \
'debiandoc2ps version 1.1

Copyright (C) 1998 Ardo van Rangelrooij
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 "debiandoc2ps: $@"; 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

[ $# = 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

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

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

if command -v lout >/dev/null 2>&1;
then
    (
	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"
    )
else
    usageerror "lout not found"
fi

if ! $nup; then exit 0; fi

if ! command -v psnup >/dev/null 2>&1;
then
    usageerror "psnup not found"
fi

if ! command -v paperconf >/dev/null 2>&1;
then
    usageerror "paperconf not found"
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