]>
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"
65 cat "${1%.docx}.txt" | awk '/^-- ASN1START$/,/^-- ASN1STOP$/' | awk '!/^[[:space:]]*--/ && !/^[[:space:]]*$/'| sed -e 's/--.*$//g' > "${1%.docx}.asncheck"
67 if [[ ! -e "${1%.docx}.asncheck" ]] ; then
68 echo "${1%.docx}.asn generation failed"
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"
78 echo " diff -b -B ${1%.docx}.asncheck ${1%.docx}-descriptions-at-IEs-end.asncheck"
80 rm "${1%.docx}-descriptions-at-IEs-end.asncheck"
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"
89 echo " diff -b -B ${1%.docx}.asncheck ${1%.docx}-description-before-field.asncheck"
91 rm "${1%.docx}-description-before-field.asncheck"
94 if [[ "$compare1" ]] || [[ "$compare1" ]] ; then
97 rm "${1%.docx}.asncheck"