-
Notifications
You must be signed in to change notification settings - Fork 0
/qq
executable file
·122 lines (115 loc) · 2.64 KB
/qq
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
#!/bin/bash
# called from ccweb (which is called from the corpas .cgi script)
# also called from SC++ (see dentry.cxx)
# also intended as something you could use from the command line too
# Usage: qq --max=NUM [--html] [--mutate] SEARCHTERMS
LIBEXECPATH=/usr/local/libexec
MAXHITS=250
MUTATER=cat
# one argument is the regexp matching search terms to highlight
xmltohtml()
{
sed -n '
/^<tu>/{
s/.*/<hr>/
p
}
/^<prop.*document.>/{
s/<prop[^>]*>\([^<]*\)<.*/<a href="\/corpas\/ll.html">\1<\/a>:/
p
}
/^<prop.*line.>/{
s/<prop[^>]*>\([^<]*\)<.*/\1<br><br>/
p
}
/^<\/tuv/{
N
s/\n//
s/<\/tuv><tuv.*>/<br><br>/
s/<\/tuv><\/tu>/<br>/
p
}
/^<seg>/{
p
}
' |
sed "
/^<seg>/{
s/\([^a-zA-ZáéíóúÁÉÍÓÚ]\)${1}\([^a-zA-ZáéíóúÁÉÍÓÚ]\)/\1<b class=\"gramadoir\">\2<\/b>\3/gI
s/^<seg>//
s/<\/seg>$//
}
"
}
versionout()
{
echo "<p>"
echo "<a href="/corpas/">Corpas Comhthreomhar Gaeilge-Béarla</a>, leagan 0.01<br>"
echo "Copyright © 2004-2016 <a href=\"//borel.slu.edu/\">Kevin P. Scannell</a><br><br>"
echo "<i>"
echo "Is saorbhogearra an ríomhchlár seo; féach ar an bhunchód le haghaidh coinníollacha cóipeála. Níl baránta AR BITH ann; go fiú níl baránta ann d'INDÍOLTACHT nó FEILIÚNACHT D'FHEIDHM AR LEITH, an oiread atá ceadaithe de réir dlí."
echo "</i></p>"
}
tmx()
{
${LIBEXECPATH}/mivec "${MAXHITS}" "${MUTATER}" "$@"
}
html()
{
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
echo "\"http://www.w3.org/TR/html4/strict.dtd\">"
echo "<html lang=\"ga\">"
echo "<head>"
echo "<title>Corpas Comhthreomhar Gaeilge-Béarla: Torthaí</title>"
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"
echo "<link rel=\"stylesheet\" href=\"//borel.slu.edu/kps.css\" type=\"text/css\">"
echo "</head>"
echo "<body>"
versionout
FILTERED=`for term in "$@"; do echo "$term"; done | ${MUTATER} | tr "\n" "_" | sed 's/_/\\\\\\|/g' | sed 's/^/\\\\\\(/; s/..$/\\\\\\)/'`
${LIBEXECPATH}/mivec "${MAXHITS}" "${MUTATER}" "$@" | xmltohtml "${FILTERED}"
echo "<hr>"
echo "</body>"
echo "</html>"
}
ACTION=tmx
while [ ${1%%[^-]*} ]
do
if echo "${1}" | grep "=" > /dev/null
then
JUSTOPT=`echo "${1}" | sed 's/=.*//'`
OPTARG=`echo "${1}" | sed 's/^[^=]*=//'`
case "${JUSTOPT}" in
"--max" )
MAXHITS="${OPTARG}"
;;
"--version" | "--html" | "--mutate" )
echo "Unnecessary argument: ${1}" >&2
exit 1
;;
* )
echo "Unrecognized option: ${1}" >&2
exit 1
;;
esac
else
case "${1}" in
"--html" )
ACTION=html
;;
"--mutate" )
MUTATER=/usr/local/bin/mutate
;;
"--version" )
versionout
exit 0
;;
* )
echo "Unrecognized option: ${1}" >&2
exit 1
;;
esac
fi
shift
done
${ACTION} "$@"