]>
nuage.metani.fr Git - 3GPP.git/blob - bin/38331-convert.sh
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)"
14 if [[ ! -w .
]] ; then
15 echo "Cannot write to current directory"
19 if [[ ! -f "$1" ]] || [[ ! -r "$1" ]] ; then
20 echo "$1 is not a readable file"
24 if [[ -e "${1%.docx}.txt" ]] ; then
25 echo "${1%.docx}.txt already exists: skipping conversion"
29 Linux
) libreoffice
="libreoffice" ;;
30 CYGWIN
*) libreoffice
="soffice" ;;
31 *) echo "Unkown platform $platform"
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"
40 $libreoffice --convert-to txt
"$1"
42 if [[ ! -f "${1%.docx}.txt" ]] || [[ ! -r "${1%.docx}.txt" ]] ; then
43 echo "libreoffice did not create ${1%.docx}.txt"
48 # Replace EN-DASH (UTF-8 encoding) at line start with -
49 Linux
) LC_ALL
=C
sed -i $
's/^\u2013/-/g' "${1%.docx}.txt" ;;
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"
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"
64 iconv -f UTF
-8 -t ASCII
//TRANSLIT
"${1%.docx}.txt" > "${1%.docx}.ascii"
65 mv "${1%.docx}.ascii" "${1%.docx}.txt"
68 cat "${1%.docx}.txt" | awk '/^-- ASN1START$/,/^-- ASN1STOP$/' | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
70 if [[ ! -e "${1%.docx}.asncheck" ]] ; then
71 echo "${1%.docx}.asn generation failed"
77 txt2asn.
awk "../${1%.docx}.txt" | awk '/^$/{ if (! blank++) print; next } { blank=0; print }' > "${1%.docx}.asn"
78 cat "${1%.docx}.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
79 compare1
=$(diff -b -B "../${1%.docx}.asncheck" "${1%.docx}.asncheck")
80 if [[ "$compare1" ]] ; then
81 echo "The ASN.1 in by-IE/${1%.docx}.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
83 echo " diff -b -B by-IE/${1%.docx}.asncheck ${1%.docx}.asncheck"
85 rm "${1%.docx}.asncheck"
86 asn1
-split.
awk "${1%.docx}.asn"
92 txt2asn
-integrated.
awk "../${1%.docx}.txt" | awk '/^$/{ if (! blank++) print; next } { blank=0; print }' > "${1%.docx}.asn"
93 cat "${1%.docx}.asn" | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
94 compare2
=$(diff -b -B "../${1%.docx}.asncheck" "${1%.docx}.asncheck")
95 if [[ "$compare2" ]] ; then
96 echo "The ASN.1 in before-field/${1%.docx}.asn does not fully match with the ASN.1 in ${1%.docx}.asncheck"
98 echo " diff -b -B before-field/${1%.docx}.asncheck ${1%.docx}.asncheck"
100 rm "${1%.docx}.asncheck"
101 asn1
-split.
awk "${1%.docx}.asn"
105 if [[ "$compare1" ]] || [[ "$compare1" ]] ; then
108 rm "${1%.docx}.asncheck"