Commit: 4d597ce941612fbf29a062c28ca39b97ba7910a8
Parent: df9ba351b04742bc3c3d62c0e03f76e31d338805
Author: opask
Date: Fri, 17 Aug 2018 21:06:05 -0600
simplification in language.c
Diffstat:
4 files changed, 21 insertions(+), 120 deletions(-)
diff --git a/language.c b/language.c
@@ -4,102 +4,43 @@
*/
#include "links.h"
+#include "language.h"
struct translation {
int code;
const char *name;
};
-struct translation_desc {
- const struct translation *t;
-};
-
-unsigned char dummyarray[T__N_TEXTS];
-
#include "language.inc"
-static unsigned char **translation_array[1];
-
-void init_trans(void)
-{
- int j;
- for (j = 0; j < 1; j++)
- translation_array[j] = NULL;
-}
-
-void shutdown_trans(void)
-{
- int j, k;
- for (j = 0; j < 1; j++)
- if (translation_array[j]) {
- for (k = 0; k < T__N_TEXTS; k++) {
- unsigned char *txt = translation_array[j][k];
- if (txt
- && txt != cast_uchar translation_english[k].name)
- free(txt);
- }
- free(translation_array[j]);
- }
-}
-
-int get_language_from_lang(unsigned char *lang)
-{
- unsigned char *p;
- lang = stracpy(lang);
- lang[strcspn(cast_const_char lang, ".@")] = 0;
- if (!casestrcmp(lang, cast_uchar "nn_NO"))
- strcpy((char *)lang, "no");
- for (p = lang; *p; p++) {
- if (*p >= 'A' && *p <= 'Z')
- *p += 'a' - 'A';
- if (*p == '_')
- *p = '-';
- }
-search_again:
- p = cast_uchar translations[0].t[T__ACCEPT_LANGUAGE].name;
- p = stracpy(p);
- p[strcspn(cast_const_char p, ",;")] = 0;
- if (!casestrcmp(lang, p)) {
- free(p);
- free(lang);
- return 0;
- }
- free(p);
-
- if ((p = cast_uchar strchr((const char *)lang, '-'))) {
- *p = 0;
- goto search_again;
- }
- free(lang);
- return -1;
-}
+unsigned char dummyarray[T__N_TEXTS];
int get_default_charset(void)
{
- unsigned char *lang, *p;
+ char *lang, *p;
+ int r;
- lang = cast_uchar getenv("LC_CTYPE");
- if (!lang)
- lang = cast_uchar getenv("LANG");
- if (!lang)
- return 0;
- if ((p = cast_uchar strchr(cast_const_char lang, '.')))
+ if (!(lang = getenv("LC_CTYPE")))
+ if (!(lang = getenv("LANG")))
+ return 0;
+
+ if ((p = strchr(lang, '.')))
p++;
else {
- if (strlen((const char *)lang) > 5
- && !casestrcmp(cast_uchar (strchr((const char *)lang, 0) - 5),
- cast_uchar "@euro")) {
- p = cast_uchar "ISO-8859-15";
- } else {
- p = cast_uchar translations[0].t[T__DEFAULT_CHAR_SET].name;
+ if (strlen(lang) > 5
+ && !casestrcmp((unsigned char *)(strchr(lang, 0) - 5),
+ (unsigned char *)"@euro"))
+ p = "ISO-8859-15";
+ else {
+ p = (char *)translation[T__DEFAULT_CHAR_SET].name;
if (!p)
- p = cast_uchar "";
+ p = "";
}
}
- if ((get_cp_index(p)) < 0)
+ if ((r = get_cp_index((unsigned char *)p)) < 0)
return 0;
- return get_cp_index(p);
+ return r;
}
int get_commandline_charset(void)
@@ -114,43 +55,14 @@ static inline int is_direct_text(unsigned char *text)
unsigned char *get_text_translation(unsigned char *text, struct terminal *term)
{
- unsigned char **current_tra;
- unsigned char *trn;
- int charset;
- if (!term)
- charset = 0;
- else if (term->spec)
- charset = term_charset(term);
- else
- charset = utf8_table;
if (is_direct_text(text))
return text;
- if ((current_tra = translation_array[charset])) {
- unsigned char *tt;
- if ((trn = current_tra[text - dummyarray]))
- return trn;
- if (!(tt = cast_uchar translations[0].t[text - dummyarray].name))
- trn = cast_uchar translation_english[text - dummyarray].name;
- else {
- struct document_options l_opt;
- memset(&l_opt, 0, sizeof(l_opt));
- l_opt.plain = 0;
- l_opt.cp = charset;
- trn = convert(0, charset, tt, &l_opt);
- if (!strcmp(cast_const_char trn, cast_const_char tt)) {
- free(trn);
- trn = tt;
- }
- }
- current_tra[text - dummyarray] = trn;
- } else if (!(trn = (u_char *)translations[0].t[text - dummyarray].name))
- trn = (u_char *)translation_english[text - dummyarray].name;
- return trn;
+ return (unsigned char *)translation[text - dummyarray].name;
}
unsigned char *get_english_translation(unsigned char *text)
{
if (is_direct_text(text))
return text;
- return cast_uchar translation_english[text - dummyarray].name;
+ return (unsigned char *)translation[text - dummyarray].name;
}
diff --git a/language.inc b/language.inc
@@ -1,6 +1,6 @@
/* Automatically generated by gen-intl */
-static const struct translation translation_english [] = {
+static const struct translation translation[] = {
{ 0, NULL },
{T__CHAR_SET, "us-ascii" },
{T__LANGUAGE, "English" },
@@ -685,9 +685,3 @@ static const struct translation translation_english [] = {
{T_URL_CALIBRATION, "http://links.twibright.com/calibration.html" },
{ 0, NULL }
};
-
-static const struct translation_desc translations [] = {
- { translation_english },
- { NULL }
-};
-
diff --git a/links.h b/links.h
@@ -1636,9 +1636,6 @@ extern unsigned char dummyarray[];
extern int current_language;
-void init_trans(void);
-void shutdown_trans(void);
-int get_language_from_lang(unsigned char *);
int get_default_charset(void);
int get_commandline_charset(void);
unsigned char *get_text_translation(unsigned char *, struct terminal *term);
diff --git a/main.c b/main.c
@@ -424,7 +424,6 @@ static void init(void)
static void initialize_all_subsystems(void)
{
init_charset();
- init_trans();
set_sigcld();
init_home();
init_dns();
@@ -474,7 +473,6 @@ static void terminate_all_subsystems(void)
check_bottom_halves();
end_config();
free_strerror_buf();
- shutdown_trans();
GF(free_dither());
GF(shutdown_graphics());
os_free_clipboard();