comparison enc-text/ucs2.c @ 2:a16b1b9728f6

enc-text: sms-encode-text program written
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 02:07:22 +0000
parents
children 265b8103530c
comparison
equal deleted inserted replaced
1:13518c86b73c 2:a16b1b9728f6
1 /*
2 * In this module we implement SMS encoding in UCS-2.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <unistd.h>
11 #include "defs.h"
12
13 extern int concat_enable, concat_refno_set;
14 extern char msgtext[MAX_MSG_CHARS*2+2];
15 extern u_char concat_refno;
16
17 ucs2_mode_main()
18 {
19 u_short msgtext_uni[MAX_MSG_UNI];
20 unsigned msgtext_unilen;
21 int rc;
22 unsigned nparts, n;
23 u_char udh[6], ucs2_be[140];
24 unsigned pos, remain, chunk;
25
26 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen);
27 if (rc == -1) {
28 fprintf(stderr, "error: invalid UTF-8 message\n");
29 exit(1);
30 }
31 if (rc == -2) {
32 fprintf(stderr, "error: message too long for max concat SMS\n");
33 exit(1);
34 }
35 if (msgtext_unilen <= 70) {
36 fputs("dcs 8 octet\nmsg ", stdout);
37 if (msgtext_unilen) {
38 ucs2_out_bigend(msgtext_uni, ucs2_be, msgtext_unilen);
39 emit_hex_out(ucs2_be, msgtext_unilen * 2, stdout);
40 } else
41 fputs("empty", stdout);
42 putchar('\n');
43 exit(0);
44 }
45 if (!concat_enable) {
46 fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n");
47 exit(1);
48 }
49 if (!concat_refno_set)
50 concat_refno = get_concsms_refno_from_host_fs();
51 puts("dcs 8 octet");
52 nparts = (msgtext_unilen + 66) / 67;
53 udh[0] = 5;
54 udh[1] = 0x00;
55 udh[2] = 0x03;
56 udh[3] = concat_refno;
57 udh[4] = nparts;
58 pos = 0;
59 remain = msgtext_unilen;
60 for (n = 1; n <= nparts; n++) {
61 udh[5] = n;
62 chunk = 67;
63 if (chunk > remain)
64 chunk = remain;
65 fputs("msg-udh ", stdout);
66 emit_hex_out(udh, 6, stdout);
67 ucs2_out_bigend(msgtext_uni + pos, ucs2_be, chunk);
68 emit_hex_out(ucs2_be, chunk * 2, stdout);
69 putchar('\n');
70 pos += chunk;
71 remain -= chunk;
72 }
73 exit(0);
74 }