FreeCalypso > hg > sms-coding-utils
annotate enc-text/ucs2.c @ 33:a91fb88a57b2 default tip
add INSTALL document
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 14 Jun 2024 20:29:17 +0000 |
parents | e56bb9f09ff1 |
children |
rev | line source |
---|---|
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement SMS encoding in UCS-2. |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "defs.h" |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
23
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
13 extern int allow_escape; |
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int concat_enable, concat_refno_set; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern char msgtext[MAX_MSG_CHARS*2+2]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern u_char concat_refno; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ucs2_mode_main() |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u_short msgtext_uni[MAX_MSG_UNI]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned msgtext_unilen; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned nparts, n; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 u_char udh[6], ucs2_be[140]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned pos, remain, chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
23
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
27 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen, |
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
28 allow_escape); |
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (rc == -1) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fprintf(stderr, "error: invalid UTF-8 message\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (rc == -2) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, "error: message too long for max concat SMS\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
23
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
37 if (rc == -3) { |
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
38 fprintf(stderr, |
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
39 "error: message contains invalid backslash escape\n"); |
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
40 exit(1); |
e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
41 } |
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (msgtext_unilen <= 70) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 fputs("dcs 8 octet\nmsg ", stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (msgtext_unilen) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 ucs2_out_bigend(msgtext_uni, ucs2_be, msgtext_unilen); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 emit_hex_out(ucs2_be, msgtext_unilen * 2, stdout); |
8
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
47 } else { |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
48 putchar('"'); |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
49 putchar('"'); |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
50 } |
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 putchar('\n'); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(0); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (!concat_enable) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!concat_refno_set) |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 concat_refno = get_concsms_refno_from_host_fs(); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 puts("dcs 8 octet"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 nparts = (msgtext_unilen + 66) / 67; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 udh[0] = 5; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 udh[1] = 0x00; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 udh[2] = 0x03; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 udh[3] = concat_refno; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 udh[4] = nparts; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 pos = 0; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 remain = msgtext_unilen; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (n = 1; n <= nparts; n++) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 udh[5] = n; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 chunk = 67; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 if (chunk > remain) |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 chunk = remain; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 fputs("msg-udh ", stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 emit_hex_out(udh, 6, stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 ucs2_out_bigend(msgtext_uni + pos, ucs2_be, chunk); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 emit_hex_out(ucs2_be, chunk * 2, stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 putchar('\n'); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 pos += chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 remain -= chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 exit(0); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |