Project

General

Profile

1
#!/bin/sh
2
# Translates a Redmine HTML page to a thesaurus
3
# Usage: self <page
4

    
5
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
6

    
7
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
8

    
9
ambigTerm=
10
term=
11
sed -n 's/^<h[1-4][^>]*>(<del>)?(<img [^>]*title="([^"]*):"[^>]*>|([[:alpha:] ]+):)? *<a href="#[^"]+" class="wiki-page">([^<]+).*$/"\3\4" "\5"/p'\
12
|while read -r line; do
13
    eval set -- $line # split to $@
14
    type="$1" name="$2"
15
    
16
    # Handle synonyms
17
    if test "$type" = Synonym; then echo "$name,$term"
18
    else
19
        term="$name"
20
        
21
        # Handle ambiguous terms
22
        if test -n "$type"; then # alternative of ambiguous term
23
            echo "$ambigTerm,$term"
24
        else # potentially ambiguous term
25
            ambigTerm="$term"
26
        fi
27
    fi
28
done
(59-59/83)