diff uptools/atcmd/smsend_main.c @ 380:a8abaa85c378

fcup-smsend: preparations for adding UCS-2 support
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Mar 2018 00:43:36 +0000
parents 0bd06f481223
children 40b1498ec39d
line wrap: on
line diff
--- a/uptools/atcmd/smsend_main.c	Fri Mar 09 00:27:24 2018 +0000
+++ b/uptools/atcmd/smsend_main.c	Fri Mar 09 00:43:36 2018 +0000
@@ -11,13 +11,15 @@
 #include "../../rvinterf/include/exitcodes.h"
 
 #define	MAX_MSG_CHARS	(153*255)
+#define	MAX_MSG_UNI	(67*255)
 
-int sms_write_mode, text_mode, utf8_input;
+int sms_write_mode, text_mode, utf8_input, ucs2_mode;
 int concat_enable, concat_refno_set, concat_quiet;
 u_char dest_addr[12];
 char msgtext[MAX_MSG_CHARS*2+2];
 u_char msgtext_gsm7[MAX_MSG_CHARS];
-unsigned msgtext_gsmlen;
+u_short msgtext_uni[MAX_MSG_UNI];
+unsigned msgtext_gsmlen, msgtext_unilen;
 u_char concat_refno;
 
 process_cmdline(argc, argv)
@@ -27,7 +29,7 @@
 	extern int optind;
 	extern char *optarg;
 
-	while ((c = getopt(argc, argv, "B:cC:np:qRtuwWX:")) != EOF) {
+	while ((c = getopt(argc, argv, "B:cC:np:qRtuUwWX:")) != EOF) {
 		if (atinterf_cmdline_opt(c))
 			continue;
 		switch (c) {
@@ -48,6 +50,9 @@
 		case 'u':
 			utf8_input = 1;
 			continue;
+		case 'U':
+			ucs2_mode = 1;
+			continue;
 		case 'w':
 			sms_write_mode = 1;
 			continue;
@@ -66,6 +71,11 @@
 			argv[0]);
 		exit(ERROR_USAGE);
 	}
+	if (ucs2_mode && text_mode) {
+		fprintf(stderr, "%s error: UCS-2 not supported in text mode\n",
+			argv[0]);
+		exit(ERROR_USAGE);
+	}
 	if (argc > optind + 2) {
 		fprintf(stderr, "usage: %s [options] dest-addr [message]\n",
 			argv[0]);
@@ -138,21 +148,17 @@
 	atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
 }
 
-main(argc, argv)
-	char **argv;
+gsm7_mode_main()
 {
 	int rc;
 	unsigned nparts, n;
 	u_char udh[5];
 	unsigned pos, remain, chunk;
 
-	if (!process_cmdline(argc, argv))
-		read_msgtext_from_stdin();
 	if (utf8_input && utf8_to_latin1(msgtext) < 0) {
 		fprintf(stderr, "error: invalid UTF-8 message\n");
 		exit(ERROR_USAGE);
 	}
-	trim_trailing_newlines();
 	if (text_mode) {
 		if (index(msgtext, '\n')) {
 			fprintf(stderr,
@@ -222,3 +228,12 @@
 		printf("Message sent as %u SMS segments\n", nparts);
 	exit(0);
 }
+
+main(argc, argv)
+	char **argv;
+{
+	if (!process_cmdline(argc, argv))
+		read_msgtext_from_stdin();
+	trim_trailing_newlines();
+	gsm7_mode_main();
+}