diff mbox series

[2/6] smsutil: Move iso639_2_from_language to util

Message ID 20240213153524.1085649-2-denkenz@gmail.com (mailing list archive)
State Accepted
Commit f7fc3fb342e7ebf07a3fb0a52895468261a57a69
Headers show
Series [1/6] sim: Drop glib use from sim_efli_format | expand

Commit Message

Denis Kenzior Feb. 13, 2024, 3:35 p.m. UTC
Also while here, convert to using stdbool instead of gboolean
---
 src/sim.c     |   2 +-
 src/smsutil.c | 111 --------------------------------------------------
 src/smsutil.h |  27 +-----------
 src/util.c    | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/util.h    |  26 ++++++++++++
 5 files changed, 140 insertions(+), 137 deletions(-)
diff mbox series

Patch

diff --git a/src/sim.c b/src/sim.c
index 55ff5f448647..fedd000923b9 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -2211,7 +2211,7 @@  static GSList *parse_eflp(const unsigned char *eflp, int length)
 	GSList *ret = NULL;
 
 	for (i = 0; i < length; i++) {
-		if (iso639_2_from_language(eflp[i], code) == FALSE)
+		if (!iso639_2_from_language(eflp[i], code))
 			continue;
 
 		ret = g_slist_prepend(ret, g_strdup(code));
diff --git a/src/smsutil.c b/src/smsutil.c
index f46507f00e1c..d4f28c01bd79 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -3937,117 +3937,6 @@  gboolean cbs_extract_app_port(const struct cbs *cbs, int *dst, int *src,
 	return extract_app_port_common(&iter, dst, src, is_8bit);
 }
 
-gboolean iso639_2_from_language(enum cbs_language lang, char *iso639)
-{
-	switch (lang) {
-	case CBS_LANGUAGE_GERMAN:
-		iso639[0] = 'd';
-		iso639[1] = 'e';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_ENGLISH:
-		iso639[0] = 'e';
-		iso639[1] = 'n';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_ITALIAN:
-		iso639[0] = 'i';
-		iso639[1] = 't';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_FRENCH:
-		iso639[0] = 'f';
-		iso639[1] = 'r';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_SPANISH:
-		iso639[0] = 'e';
-		iso639[1] = 's';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_DUTCH:
-		iso639[0] = 'n';
-		iso639[1] = 'l';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_SWEDISH:
-		iso639[0] = 's';
-		iso639[1] = 'v';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_DANISH:
-		iso639[0] = 'd';
-		iso639[1] = 'a';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_PORTUGESE:
-		iso639[0] = 'p';
-		iso639[1] = 't';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_FINNISH:
-		iso639[0] = 'f';
-		iso639[1] = 'i';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_NORWEGIAN:
-		iso639[0] = 'n';
-		iso639[1] = 'o';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_GREEK:
-		iso639[0] = 'e';
-		iso639[1] = 'l';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_TURKISH:
-		iso639[0] = 't';
-		iso639[1] = 'r';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_HUNGARIAN:
-		iso639[0] = 'h';
-		iso639[1] = 'u';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_POLISH:
-		iso639[0] = 'p';
-		iso639[1] = 'l';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_CZECH:
-		iso639[0] = 'c';
-		iso639[1] = 's';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_HEBREW:
-		iso639[0] = 'h';
-		iso639[1] = 'e';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_ARABIC:
-		iso639[0] = 'a';
-		iso639[1] = 'r';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_RUSSIAN:
-		iso639[0] = 'r';
-		iso639[1] = 'u';
-		iso639[2] = '\0';
-		return TRUE;
-	case CBS_LANGUAGE_ICELANDIC:
-		iso639[0] = 'i';
-		iso639[1] = 's';
-		iso639[2] = '\0';
-		return TRUE;
-	default:
-		iso639[0] = '\0';
-		break;
-	}
-
-	return FALSE;
-}
-
 char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 {
 	GSList *l;
diff --git a/src/smsutil.h b/src/smsutil.h
index 01487de4b67c..5389757c309c 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -19,6 +19,8 @@ 
  *
  */
 
+enum cbs_language;
+
 #define CBS_MAX_GSM_CHARS 93
 #define SMS_MSGID_LEN 20
 
@@ -196,30 +198,6 @@  enum sms_pid_type {
 	SMS_PID_TYPE_USIM_DOWNLOAD = 0x7f,
 };
 
-enum cbs_language {
-	CBS_LANGUAGE_GERMAN = 0x0,
-	CBS_LANGUAGE_ENGLISH = 0x1,
-	CBS_LANGUAGE_ITALIAN = 0x2,
-	CBS_LANGUAGE_FRENCH = 0x3,
-	CBS_LANGUAGE_SPANISH = 0x4,
-	CBS_LANGUAGE_DUTCH = 0x5,
-	CBS_LANGUAGE_SWEDISH = 0x6,
-	CBS_LANGUAGE_DANISH = 0x7,
-	CBS_LANGUAGE_PORTUGESE = 0x8,
-	CBS_LANGUAGE_FINNISH = 0x9,
-	CBS_LANGUAGE_NORWEGIAN = 0xA,
-	CBS_LANGUAGE_GREEK = 0xB,
-	CBS_LANGUAGE_TURKISH = 0xC,
-	CBS_LANGUAGE_HUNGARIAN = 0xD,
-	CBS_LANGUAGE_POLISH = 0xE,
-	CBS_LANGUAGE_UNSPECIFIED = 0xF,
-	CBS_LANGUAGE_CZECH = 0x20,
-	CBS_LANGUAGE_HEBREW = 0x21,
-	CBS_LANGUAGE_ARABIC = 0x22,
-	CBS_LANGUAGE_RUSSIAN = 0x23,
-	CBS_LANGUAGE_ICELANDIC = 0x24
-};
-
 enum cbs_geo_scope {
 	CBS_GEO_SCOPE_CELL_IMMEDIATE,
 	CBS_GEO_SCOPE_PLMN,
@@ -576,7 +554,6 @@  gboolean cbs_dcs_decode(guint8 dcs, gboolean *udhi, enum sms_class *cls,
 			enum sms_charset *charset, gboolean *compressed,
 			enum cbs_language *language, gboolean *iso639);
 
-gboolean iso639_2_from_language(enum cbs_language lang, char *iso639);
 gboolean cbs_decode(const unsigned char *pdu, int len, struct cbs *out);
 gboolean cbs_encode(const struct cbs *cbs, int *len, unsigned char *pdu);
 gboolean cbs_extract_app_port(const struct cbs *cbs, int *dst, int *src,
diff --git a/src/util.c b/src/util.c
index 627be7eec097..0a5212a2bca4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3753,3 +3753,114 @@  unsigned char *convert_ucs2_to_gsm(const unsigned char *text, long len,
 						GSM_DIALECT_DEFAULT,
 						GSM_DIALECT_DEFAULT);
 }
+
+bool iso639_2_from_language(enum cbs_language lang, char *iso639)
+{
+	switch (lang) {
+	case CBS_LANGUAGE_GERMAN:
+		iso639[0] = 'd';
+		iso639[1] = 'e';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_ENGLISH:
+		iso639[0] = 'e';
+		iso639[1] = 'n';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_ITALIAN:
+		iso639[0] = 'i';
+		iso639[1] = 't';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_FRENCH:
+		iso639[0] = 'f';
+		iso639[1] = 'r';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_SPANISH:
+		iso639[0] = 'e';
+		iso639[1] = 's';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_DUTCH:
+		iso639[0] = 'n';
+		iso639[1] = 'l';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_SWEDISH:
+		iso639[0] = 's';
+		iso639[1] = 'v';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_DANISH:
+		iso639[0] = 'd';
+		iso639[1] = 'a';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_PORTUGESE:
+		iso639[0] = 'p';
+		iso639[1] = 't';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_FINNISH:
+		iso639[0] = 'f';
+		iso639[1] = 'i';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_NORWEGIAN:
+		iso639[0] = 'n';
+		iso639[1] = 'o';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_GREEK:
+		iso639[0] = 'e';
+		iso639[1] = 'l';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_TURKISH:
+		iso639[0] = 't';
+		iso639[1] = 'r';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_HUNGARIAN:
+		iso639[0] = 'h';
+		iso639[1] = 'u';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_POLISH:
+		iso639[0] = 'p';
+		iso639[1] = 'l';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_CZECH:
+		iso639[0] = 'c';
+		iso639[1] = 's';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_HEBREW:
+		iso639[0] = 'h';
+		iso639[1] = 'e';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_ARABIC:
+		iso639[0] = 'a';
+		iso639[1] = 'r';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_RUSSIAN:
+		iso639[0] = 'r';
+		iso639[1] = 'u';
+		iso639[2] = '\0';
+		return true;
+	case CBS_LANGUAGE_ICELANDIC:
+		iso639[0] = 'i';
+		iso639[1] = 's';
+		iso639[2] = '\0';
+		return true;
+	default:
+		iso639[0] = '\0';
+		break;
+	}
+
+	return false;
+}
diff --git a/src/util.h b/src/util.h
index 3e7dfea3e8bc..a70fb49f7ae5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -38,6 +38,30 @@  enum gsm_dialect {
 	GSM_DIALECT_URDU,
 };
 
+enum cbs_language {
+	CBS_LANGUAGE_GERMAN = 0x0,
+	CBS_LANGUAGE_ENGLISH = 0x1,
+	CBS_LANGUAGE_ITALIAN = 0x2,
+	CBS_LANGUAGE_FRENCH = 0x3,
+	CBS_LANGUAGE_SPANISH = 0x4,
+	CBS_LANGUAGE_DUTCH = 0x5,
+	CBS_LANGUAGE_SWEDISH = 0x6,
+	CBS_LANGUAGE_DANISH = 0x7,
+	CBS_LANGUAGE_PORTUGESE = 0x8,
+	CBS_LANGUAGE_FINNISH = 0x9,
+	CBS_LANGUAGE_NORWEGIAN = 0xA,
+	CBS_LANGUAGE_GREEK = 0xB,
+	CBS_LANGUAGE_TURKISH = 0xC,
+	CBS_LANGUAGE_HUNGARIAN = 0xD,
+	CBS_LANGUAGE_POLISH = 0xE,
+	CBS_LANGUAGE_UNSPECIFIED = 0xF,
+	CBS_LANGUAGE_CZECH = 0x20,
+	CBS_LANGUAGE_HEBREW = 0x21,
+	CBS_LANGUAGE_ARABIC = 0x22,
+	CBS_LANGUAGE_RUSSIAN = 0x23,
+	CBS_LANGUAGE_ICELANDIC = 0x24
+};
+
 char *convert_gsm_to_utf8(const unsigned char *text, long len, long *items_read,
 				long *items_written, unsigned char terminator);
 
@@ -105,3 +129,5 @@  unsigned char *convert_ucs2_to_gsm_with_lang(const unsigned char *text,
 unsigned char *convert_ucs2_to_gsm(const unsigned char *text, long len,
 					long *items_read, long *items_written,
 					unsigned char terminator);
+
+bool iso639_2_from_language(enum cbs_language lang, char *iso639);