1#!/usr/local/bin/bash
2
3#
4# Copyright (c) 2015-2018 Samuel Thibault <samuel.thibault@ens-lyon.org>
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24# THE SOFTWARE.
25#
26
27# Make sure we have enough options
28if [ $# != 5 -a $# != 6 ]; then
29  echo "ERROR: $0 jobid user name nb options [filename]" >&2
30  exit 1
31fi
32
33NB=$4
34OPTIONS=$5
35FILE=$6
36
37. @CUPS_SERVERBIN@/filter/indexv4.sh
38printf "$INIT"
39
40# Enter 4-dot graphic mode
41# TODO: use image mode instead, to benefit from much better resolution
42printf "\033\007"
43
44echo "INFO: Writing text to Index embosser" >&2
45( if [ -z "$FILE" ]
46then
47  cat
48else
49  cat "$FILE"
50fi ) | sed \
51	-e 's/⠀/@@/g' \
52	-e 's/⠁/A@/g' \
53	-e 's/⠂/B@/g' \
54	-e 's/⠃/C@/g' \
55	-e 's/⠄/D@/g' \
56	-e 's/⠅/E@/g' \
57	-e 's/⠆/F@/g' \
58	-e 's/⠇/G@/g' \
59	-e 's/⡀/H@/g' \
60	-e 's/⡁/I@/g' \
61	-e 's/⡂/J@/g' \
62	-e 's/⡃/K@/g' \
63	-e 's/⡄/L@/g' \
64	-e 's/⡅/M@/g' \
65	-e 's/⡆/N@/g' \
66	-e 's/⡇/O@/g' \
67	-e 's/⠈/@A/g' \
68	-e 's/⠉/AA/g' \
69	-e 's/⠊/BA/g' \
70	-e 's/⠋/CA/g' \
71	-e 's/⠌/DA/g' \
72	-e 's/⠍/EA/g' \
73	-e 's/⠎/FA/g' \
74	-e 's/⠏/GA/g' \
75	-e 's/⡈/HA/g' \
76	-e 's/⡉/IA/g' \
77	-e 's/⡊/JA/g' \
78	-e 's/⡋/KA/g' \
79	-e 's/⡌/LA/g' \
80	-e 's/⡍/MA/g' \
81	-e 's/⡎/NA/g' \
82	-e 's/⡏/OA/g' \
83	-e 's/⠐/@B/g' \
84	-e 's/⠑/AB/g' \
85	-e 's/⠒/BB/g' \
86	-e 's/⠓/CB/g' \
87	-e 's/⠔/DB/g' \
88	-e 's/⠕/EB/g' \
89	-e 's/⠖/FB/g' \
90	-e 's/⠗/GB/g' \
91	-e 's/⡐/HB/g' \
92	-e 's/⡑/IB/g' \
93	-e 's/⡒/JB/g' \
94	-e 's/⡓/KB/g' \
95	-e 's/⡔/LB/g' \
96	-e 's/⡕/MB/g' \
97	-e 's/⡖/NB/g' \
98	-e 's/⡗/OB/g' \
99	-e 's/⠘/@C/g' \
100	-e 's/⠙/AC/g' \
101	-e 's/⠚/BC/g' \
102	-e 's/⠛/CC/g' \
103	-e 's/⠜/DC/g' \
104	-e 's/⠝/EC/g' \
105	-e 's/⠞/FC/g' \
106	-e 's/⠟/GC/g' \
107	-e 's/⡘/HC/g' \
108	-e 's/⡙/IC/g' \
109	-e 's/⡚/JC/g' \
110	-e 's/⡛/KC/g' \
111	-e 's/⡜/LC/g' \
112	-e 's/⡝/MC/g' \
113	-e 's/⡞/NC/g' \
114	-e 's/⡟/OC/g' \
115	-e 's/⠠/@D/g' \
116	-e 's/⠡/AD/g' \
117	-e 's/⠢/BD/g' \
118	-e 's/⠣/CD/g' \
119	-e 's/⠤/DD/g' \
120	-e 's/⠥/ED/g' \
121	-e 's/⠦/FD/g' \
122	-e 's/⠧/GD/g' \
123	-e 's/⡠/HD/g' \
124	-e 's/⡡/ID/g' \
125	-e 's/⡢/JD/g' \
126	-e 's/⡣/KD/g' \
127	-e 's/⡤/LD/g' \
128	-e 's/⡥/MD/g' \
129	-e 's/⡦/ND/g' \
130	-e 's/⡧/OD/g' \
131	-e 's/⠨/@E/g' \
132	-e 's/⠩/AE/g' \
133	-e 's/⠪/BE/g' \
134	-e 's/⠫/CE/g' \
135	-e 's/⠬/DE/g' \
136	-e 's/⠭/EE/g' \
137	-e 's/⠮/FE/g' \
138	-e 's/⠯/GE/g' \
139	-e 's/⡨/HE/g' \
140	-e 's/⡩/IE/g' \
141	-e 's/⡪/JE/g' \
142	-e 's/⡫/KE/g' \
143	-e 's/⡬/LE/g' \
144	-e 's/⡭/ME/g' \
145	-e 's/⡮/NE/g' \
146	-e 's/⡯/OE/g' \
147	-e 's/⠰/@F/g' \
148	-e 's/⠱/AF/g' \
149	-e 's/⠲/BF/g' \
150	-e 's/⠳/CF/g' \
151	-e 's/⠴/DF/g' \
152	-e 's/⠵/EF/g' \
153	-e 's/⠶/FF/g' \
154	-e 's/⠷/GF/g' \
155	-e 's/⡰/HF/g' \
156	-e 's/⡱/IF/g' \
157	-e 's/⡲/JF/g' \
158	-e 's/⡳/KF/g' \
159	-e 's/⡴/LF/g' \
160	-e 's/⡵/MF/g' \
161	-e 's/⡶/NF/g' \
162	-e 's/⡷/OF/g' \
163	-e 's/⠸/@G/g' \
164	-e 's/⠹/AG/g' \
165	-e 's/⠺/BG/g' \
166	-e 's/⠻/CG/g' \
167	-e 's/⠼/DG/g' \
168	-e 's/⠽/EG/g' \
169	-e 's/⠾/FG/g' \
170	-e 's/⠿/GG/g' \
171	-e 's/⡸/HG/g' \
172	-e 's/⡹/IG/g' \
173	-e 's/⡺/JG/g' \
174	-e 's/⡻/KG/g' \
175	-e 's/⡼/LG/g' \
176	-e 's/⡽/MG/g' \
177	-e 's/⡾/NG/g' \
178	-e 's/⡿/OG/g' \
179	-e 's/⢀/@H/g' \
180	-e 's/⢁/AH/g' \
181	-e 's/⢂/BH/g' \
182	-e 's/⢃/CH/g' \
183	-e 's/⢄/DH/g' \
184	-e 's/⢅/EH/g' \
185	-e 's/⢆/FH/g' \
186	-e 's/⢇/GH/g' \
187	-e 's/⣀/HH/g' \
188	-e 's/⣁/IH/g' \
189	-e 's/⣂/JH/g' \
190	-e 's/⣃/KH/g' \
191	-e 's/⣄/LH/g' \
192	-e 's/⣅/MH/g' \
193	-e 's/⣆/NH/g' \
194	-e 's/⣇/OH/g' \
195	-e 's/⢈/@I/g' \
196	-e 's/⢉/AI/g' \
197	-e 's/⢊/BI/g' \
198	-e 's/⢋/CI/g' \
199	-e 's/⢌/DI/g' \
200	-e 's/⢍/EI/g' \
201	-e 's/⢎/FI/g' \
202	-e 's/⢏/GI/g' \
203	-e 's/⣈/HI/g' \
204	-e 's/⣉/II/g' \
205	-e 's/⣊/JI/g' \
206	-e 's/⣋/KI/g' \
207	-e 's/⣌/LI/g' \
208	-e 's/⣍/MI/g' \
209	-e 's/⣎/NI/g' \
210	-e 's/⣏/OI/g' \
211	-e 's/⢐/@J/g' \
212	-e 's/⢑/AJ/g' \
213	-e 's/⢒/BJ/g' \
214	-e 's/⢓/CJ/g' \
215	-e 's/⢔/DJ/g' \
216	-e 's/⢕/EJ/g' \
217	-e 's/⢖/FJ/g' \
218	-e 's/⢗/GJ/g' \
219	-e 's/⣐/HJ/g' \
220	-e 's/⣑/IJ/g' \
221	-e 's/⣒/JJ/g' \
222	-e 's/⣓/KJ/g' \
223	-e 's/⣔/LJ/g' \
224	-e 's/⣕/MJ/g' \
225	-e 's/⣖/NJ/g' \
226	-e 's/⣗/OJ/g' \
227	-e 's/⢘/@K/g' \
228	-e 's/⢙/AK/g' \
229	-e 's/⢚/BK/g' \
230	-e 's/⢛/CK/g' \
231	-e 's/⢜/DK/g' \
232	-e 's/⢝/EK/g' \
233	-e 's/⢞/FK/g' \
234	-e 's/⢟/GK/g' \
235	-e 's/⣘/HK/g' \
236	-e 's/⣙/IK/g' \
237	-e 's/⣚/JK/g' \
238	-e 's/⣛/KK/g' \
239	-e 's/⣜/LK/g' \
240	-e 's/⣝/MK/g' \
241	-e 's/⣞/NK/g' \
242	-e 's/⣟/OK/g' \
243	-e 's/⢠/@L/g' \
244	-e 's/⢡/AL/g' \
245	-e 's/⢢/BL/g' \
246	-e 's/⢣/CL/g' \
247	-e 's/⢤/DL/g' \
248	-e 's/⢥/EL/g' \
249	-e 's/⢦/FL/g' \
250	-e 's/⢧/GL/g' \
251	-e 's/⣠/HL/g' \
252	-e 's/⣡/IL/g' \
253	-e 's/⣢/JL/g' \
254	-e 's/⣣/KL/g' \
255	-e 's/⣤/LL/g' \
256	-e 's/⣥/ML/g' \
257	-e 's/⣦/NL/g' \
258	-e 's/⣧/OL/g' \
259	-e 's/⢨/@M/g' \
260	-e 's/⢩/AM/g' \
261	-e 's/⢪/BM/g' \
262	-e 's/⢫/CM/g' \
263	-e 's/⢬/DM/g' \
264	-e 's/⢭/EM/g' \
265	-e 's/⢮/FM/g' \
266	-e 's/⢯/GM/g' \
267	-e 's/⣨/HM/g' \
268	-e 's/⣩/IM/g' \
269	-e 's/⣪/JM/g' \
270	-e 's/⣫/KM/g' \
271	-e 's/⣬/LM/g' \
272	-e 's/⣭/MM/g' \
273	-e 's/⣮/NM/g' \
274	-e 's/⣯/OM/g' \
275	-e 's/⢰/@N/g' \
276	-e 's/⢱/AN/g' \
277	-e 's/⢲/BN/g' \
278	-e 's/⢳/CN/g' \
279	-e 's/⢴/DN/g' \
280	-e 's/⢵/EN/g' \
281	-e 's/⢶/FN/g' \
282	-e 's/⢷/GN/g' \
283	-e 's/⣰/HN/g' \
284	-e 's/⣱/IN/g' \
285	-e 's/⣲/JN/g' \
286	-e 's/⣳/KN/g' \
287	-e 's/⣴/LN/g' \
288	-e 's/⣵/MN/g' \
289	-e 's/⣶/NN/g' \
290	-e 's/⣷/ON/g' \
291	-e 's/⢸/@O/g' \
292	-e 's/⢹/AO/g' \
293	-e 's/⢺/BO/g' \
294	-e 's/⢻/CO/g' \
295	-e 's/⢼/DO/g' \
296	-e 's/⢽/EO/g' \
297	-e 's/⢾/FO/g' \
298	-e 's/⢿/GO/g' \
299	-e 's/⣸/HO/g' \
300	-e 's/⣹/IO/g' \
301	-e 's/⣺/JO/g' \
302	-e 's/⣻/KO/g' \
303	-e 's/⣼/LO/g' \
304	-e 's/⣽/MO/g' \
305	-e 's/⣾/NO/g' \
306	-e 's/⣿/OO/g' \
307	\
308	-e 's/@*$//' \
309	-e 's/^$/'$'\015''/' -e 's/\([^'$'\015'']\)$/\1'$'\015''/'
310
311# Exit 4-dot graphic mode
312printf '\033\006'
313# Finish document
314printf '\032'
315
316echo "INFO: Ready" >&2
317