]> nuage.metani.fr Git - 3GPP.git/blob - bin/38331-convert.sh
cd8267bada72bc6556e19261e85fc4613363bffa
[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 txt2asn.awk "${1%.docx}.txt" > "${1%.docx}-descriptions-at-IEs-end.asn"
73 cat "${1%.docx}-descriptions-at-IEs-end.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}-descriptions-at-IEs-end.asncheck"
74 compare1=$(diff -b -B "${1%.docx}.asncheck" "${1%.docx}-descriptions-at-IEs-end.asncheck")
75 if [[ "$compare1" ]] ; then
76 echo "The ASN.1 in ${1%.docx}-descriptions-at-IEs-end.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
77 echo "Check with:"
78 echo " diff -b -B ${1%.docx}.asncheck ${1%.docx}-descriptions-at-IEs-end.asncheck"
79 else
80 rm "${1%.docx}-descriptions-at-IEs-end.asncheck"
81 fi
82
83 txt2asn-integrated.awk "${1%.docx}.txt" > "${1%.docx}-description-before-field.asn"
84 cat "${1%.docx}-description-before-field.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}-description-before-field.asncheck"
85 compare2=$(diff -b -B "${1%.docx}.asncheck" "${1%.docx}-description-before-field.asncheck")
86 if [[ "$compare2" ]] ; then
87 echo "The ASN.1 in ${1%.docx}-description-before-field.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
88 echo "Check with:"
89 echo " diff -b -B ${1%.docx}.asncheck ${1%.docx}-description-before-field.asncheck"
90 else
91 rm "${1%.docx}-description-before-field.asncheck"
92 fi
93
94 if [[ "$compare1" ]] || [[ "$compare1" ]] ; then
95 exit
96 else
97 rm "${1%.docx}.asncheck"
98 fi