]> nuage.metani.fr Git - 3GPP.git/blob - bin/38331-convert.sh
ead185983d8c60cddbe4838df09fdf9f185598d8
[3GPP.git] / bin / 38331-convert.sh
1 #!/bin/bash
2
3 if [[ ! $# -eq 1 ]] ; then
4 echo "Usage: ${0##*/} 38331-xyz.docx"
5 echo "38331-xyz.docx is a version of TS 38.331"
6 echo "Creates one .asn pure ASN.1 text file per ASN.1 module in TS 38.331"
7 echo "Message, IE, field and presence condition descriptions are included as comments"
8 echo "Produces 2 versions:"
9 echo " - one with descriptions of fields and presence conditions at the end of the IE definition"
10 echo " - one with those descriptions before the concerned field(s)"
11 exit 1
12 fi
13
14 if [[ ! -w . ]] ; then
15 echo "Cannot write to current directory"
16 exit 1
17 fi
18
19 if [[ ! -f "$1" ]] || [[ ! -r "$1" ]] ; then
20 echo "$1 is not a readable file"
21 exit
22 fi
23
24 if [[ -e "${1%.docx}.txt" ]] ; then
25 echo "${1%.docx}.txt already exists: skipping conversion"
26 else
27 platform=$(uname)
28 case $platform in
29 Linux) libreoffice="libreoffice" ;;
30 CYGWIN*) libreoffice="soffice" ;;
31 *) echo "Unkown platform $platform"
32 exit 1;;
33 esac
34
35 if [[ ! -x $(which "$libreoffice") ]] ; then
36 echo "Cannot find libreoffice executable"
37 echo "Make sure it is installed and the PATH variable includes its path"
38 exit 1
39 fi
40 $libreoffice --convert-to txt "$1"
41
42 if [[ ! -f "${1%.docx}.txt" ]] || [[ ! -r "${1%.docx}.txt" ]] ; then
43 echo "libreoffice did not create ${1%.docx}.txt"
44 exit
45 fi
46
47 case $platform in
48 # Replace EN-DASH (UTF-8 encoding) at line start with -
49 Linux) LC_ALL=C sed -i $'s/^\u2013/-/g' "${1%.docx}.txt" ;;
50
51 # Replace EN-DASH (Windows-1252 encoding) at line start with -
52 # Remove CR (0x0d) put by libreoffice in windows before each LF (0x0a)
53 CYGWIN*) LC_ALL=C sed -i $'s/^\x96/-/g; s/\r$//' "${1%.docx}.txt" ;;
54 *) echo "Unkown platform $platform"
55 exit 1;;
56 esac
57
58 # Changes things that should not be so in the specification
59 # Change "-- Cond N3C MP" to "-- Cond N3C-MP" (to respect condition naming rules)
60 LC_ALL=C sed -i 's/-- Cond N3C MP/-- Cond N3C-MP/' "${1%.docx}.txt"
61 LC_ALL=C sed -i 's/^N3C MP/N3C-MP/' "${1%.docx}.txt"
62 LC_ALL=C sed -i 's/-- Cond HOAndServCellAdd,$/-- Cond HOAndServCellAdd/' "${1%.docx}.txt"
63 fi
64
65 cat "${1%.docx}.txt" | awk '/^-- ASN1START$/,/^-- ASN1STOP$/' | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
66
67 if [[ ! -e "${1%.docx}.asncheck" ]] ; then
68 echo "${1%.docx}.asn generation failed"
69 exit
70 fi
71
72 mkdir -p by-IE
73 cd by-IE
74 txt2asn.awk "../${1%.docx}.txt" > "${1%.docx}.asn"
75 cat "${1%.docx}.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
76 compare1=$(diff -b -B "../${1%.docx}.asncheck" "${1%.docx}.asncheck")
77 if [[ "$compare1" ]] ; then
78 echo "The ASN.1 in by-IE/${1%.docx}.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
79 echo "Check with:"
80 echo " diff -b -B by-IE/${1%.docx}.asncheck ${1%.docx}.asncheck"
81 else
82 rm "${1%.docx}.asncheck"
83 fi
84
85 cd ..
86 mkdir -p before-field
87 cd before-field
88 txt2asn-integrated.awk "../${1%.docx}.txt" > "${1%.docx}.asn"
89 cat "${1%.docx}.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
90 compare2=$(diff -b -B "../${1%.docx}.asncheck" "${1%.docx}.asncheck")
91 if [[ "$compare2" ]] ; then
92 echo "The ASN.1 in before-field/${1%.docx}.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
93 echo "Check with:"
94 echo " diff -b -B before-field/${1%.docx}.asncheck ${1%.docx}.asncheck"
95 else
96 rm "${1%.docx}.asncheck"
97 fi
98
99 cd ..
100 if [[ "$compare1" ]] || [[ "$compare1" ]] ; then
101 exit
102 else
103 rm "${1%.docx}.asncheck"
104 fi