Debian Codegraph @

texmf-dist/doc/eplain/util/trimsee

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # (This file is public domain.)
3 # This file is part of the Eplain macro package.
4
5 helpscip-shell shell texlive-extra 2026.20260527-1 help(). ()
6 {
7 catscip-shell system . . cat. <<EOF
8 Usage: trimsee [-i IS] [-o OS] [-s SEE]
9 trimsee {-h|--help|-v|--version}
10 Remove commas (or other page list separators) in front
11 of see / see also commands in the output of MakeIndex.
12 Input is read from stdin, output is directed to stdout.
13
14 -i IS use IS as a regular expression matching separator
15 in front of see / see also commands in the input
16 (default: '$DEFAULT_IS')
17 -o OS use OS as a separator to replace IS in front of
18 see / see also commands (default: '$DEFAULT_OS')
19 -s SEE use SEE as a regular expression matching see /
20 see also commands (default: '$DEFAULT_SEE')
21 -h, --help show this help message
22 -v, --version show version
23 EOF
24 }
25
26 check_missing_argscip-shell shell texlive-extra 2026.20260527-1 check_missing_arg(). ()
27 {
28 if testscip-shell system . . test. "$1" -lt 2; then
29 echoscip-shell system . . echo. "Missing argument to option '$2'" 1>&2
30 exit 1
31 fi
32 }
33
34 VERSION='0.1'
35
36 DEFAULT_SEE='\\indexsee'
37 DEFAULT_IS=', \+'
38 DEFAULT_OS=' '
39
40 SEE=$DEFAULT_SEE
41 IS=$DEFAULT_IS
42 OS=$DEFAULT_OS
43
44 while [scip-shell system . . `[`. $# != 0 ]
45 do
46 case "$1" in
47 -i)
48 check_missing_argscip-shell shell texlive-extra 2026.20260527-1 check_missing_arg(). $# "$1"
49 IS=$2
50 shift
51 ;;
52 -o)
53 check_missing_argscip-shell shell texlive-extra 2026.20260527-1 check_missing_arg(). $# "$1"
54 OS=$2
55 shift
56 ;;
57 -s)
58 check_missing_argscip-shell shell texlive-extra 2026.20260527-1 check_missing_arg(). $# "$1"
59 SEE=$2
60 shift
61 ;;
62 -h | --help)
63 helpscip-shell shell texlive-extra 2026.20260527-1 help().
64 exit 0
65 ;;
66 -v | --version)
67 echoscip-shell system . . echo. "trimsee version $VERSION"
68 exit 0
69 ;;
70 *)
71 echoscip-shell system . . echo. "Unknown option '$1'" 1>&2
72 exit 1
73 ;;
74 esac
75 shift
76 done
77
78
79 # The idea is to implement line output delayed by one line. When we
80 # read next line, we check if it starts with a see/see also entry, and
81 # if it does, we remove the comma at the end of the previous line
82 # before printing it. We keep previous lines in the hold buffer.
83
84 sedscip-shell system . . sed. -n '
85
86 # Remove all commas in front of see/see also inside each line.
87 s/'"$IS$SEE/$OS$SEE"'/g
88
89 # If this line does not start with see/see also, we will print the
90 # previous line intact. NOTE: There are two characters inside the
91 # brackets: a space and a tab.
92 /^[ ]*'"$SEE"'/! { x; b PRINT; }
93
94 # This line starts with see/see also, so remove comma at the end of
95 # the previous line before we print it.
96 x
97 s/'"$IS"'$/'"$OS"'/
98
99 # Print the previous line.
100 :PRINT
101 1! p
102
103 # At the end of the input, print the last line.
104 $ { x; p; }
105
106 '