]> nuage.metani.fr Git - 3GPP.git/blob - bin/docx2asn
Changing the shebang of .awk files to "awk -f", so that they can be executed.
[3GPP.git] / bin / docx2asn
1 #!/bin/bash
2
3 if [[ $# -eq 0 ]] ; then
4 echo "Usage: ${0##*/} file [files]"
5 echo "Extract ASN.1 from one or more 3GPP 38.331 docx files and save then to .asn files"
6 exit 1
7 fi
8
9 if [[ ! -w . ]] ; then
10 echo "Cannot write to current directory"
11 exit 1
12 fi
13
14 if [[ ! -x $(which libreoffice) ]] ; then
15 echo "Cannot find executable libreoffice"
16 exit 1
17 fi
18
19 while [ "$#" -gt 0 ]; do
20
21 echo "Processing parameter: $1"
22
23 if [[ ! -f "$1" ]] || [[ ! -r "$1" ]] ; then
24 echo "$1 is not a readable file"
25 shift
26 continue
27 fi
28
29 if [[ -e "${1%.docx}.txt" ]] ; then
30 echo "${1%.docx}.txt already exists: skipping conversion"
31
32 else
33 libreoffice --convert-to txt "$1"
34
35 if [[ ! -f "${1%.docx}.txt" ]] || [[ ! -r "${1%.docx}.txt" ]] ; then
36 echo "libreoffice did not create ${1%.docx}.txt"
37 shift
38 continue
39 fi
40 fi
41
42 if [[ -e "${1%.docx}.asn" ]] ; then
43 echo "${1%.docx}.asn already exists: not regenerated"
44 shift
45 continue
46 fi
47
48 cat "${1%.docx}.txt" | awk '/^-- ASN1START$/,/^-- ASN1STOP$/' | grep -Evxe '-- ASN1ST(ART|OP)' | grep -v '^--' | awk 'NF || p; { p = NF }' p=0 > "${1%.docx}.asn"
49
50 if [[ -e "${1%.docx}.asn" ]] ; then
51 echo "${1%.docx}.asn was generated"
52 fi
53 shift
54 done
55