File: sms2unicode

package info (click to toggle)
smstools 3.1.15-1.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,656 kB
  • ctags: 879
  • sloc: ansic: 14,857; sh: 1,195; php: 115; makefile: 48; awk: 17
file content (44 lines) | stat: -rwxr-xr-x 999 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

# This script converts a received sms file into a pure unicode text file.

if [ $# -ne 1 ]; then
  echo "Usage: sms2unicode filename"
  exit 1
fi

if grep "Alphabet:.*UCS" $1 >/dev/null; then
  ucs2=true
else
  ucs2=false
fi

echo -en "\xFE\xFF"
text=`od -t x1 $1 | cut -c8-99`
foundstart="false"
previous=""
for character in $text; do
  # Search for the start of the 16 bit part. Starts after "0a 0a"
  if [ "$foundstart" = "false" ]; then
    if [ "$character" = "0a" ] && [ "$previous" = "0a" ]; then
      foundstart="true"
    fi
    if [ "$character" = "0a" ] && [ "$previous" != "0d" ]; then
      echo -en "\x00\x0d\x00\x$character"
    else  
      echo -en "\x00\x$character"
    fi  
  else
    if [ "$ucs2" = "false" ]; then
      if [ "$character" = "0a" ] && [ "$previous" != "0d" ]; then
        echo -en "\x00\x0d\x00\x$character"
      else
        echo -en "\x00\x$character"
      fi
    else
      echo -en "\x$character"
    fi  
  fi
  previous="$character"
done