summaryrefslogtreecommitdiffstats
path: root/mbbsd/i18n.c
diff options
context:
space:
mode:
authorjack <jack@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-30 15:09:44 +0800
committerjack <jack@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-30 15:09:44 +0800
commit04fe0c49c67bbb1bd033b7d500cec449f2b79840 (patch)
tree1e3abdac211fdedfef32fb78b070f9f214e79cd0 /mbbsd/i18n.c
parent45a5058a15fae9664b45729fbf7617138fd470f6 (diff)
downloadpttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar.gz
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar.bz2
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar.lz
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar.xz
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.tar.zst
pttbbs-04fe0c49c67bbb1bd033b7d500cec449f2b79840.zip
add parse escape sequence to i18n.c
git-svn-id: http://opensvn.csie.org/pttbbs/branches/Jaky.i18n@1900 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/i18n.c')
-rw-r--r--mbbsd/i18n.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/mbbsd/i18n.c b/mbbsd/i18n.c
index ddae4213..b23216d6 100644
--- a/mbbsd/i18n.c
+++ b/mbbsd/i18n.c
@@ -1,14 +1,62 @@
#include "bbs.h"
+/* Created by Chia-Kuang Yu, Apr 26th, 2004 */
+
#define MAX_LANGFILE_SIZE (512 * 1024)
#define MAX_STRING_LEN 4096
#define MAX_BUFFER_SIZE (MAX_LANG * MAX_STRING * 20)
#ifdef I18N
+int parse_hex(unsigned char *buf, unsigned char *ret) {
+ unsigned char table[] = "0123456789ABCDEF";
+ unsigned char digit[2];
+ char ptr[2];
+ digit[0] = toupper(*buf);
+ digit[1] = toupper(*(buf + 1));
+ if ((ptr[0] = strchr(table, digit[0])) &&
+ (ptr[1] = strchr(table, digit[1]))) {
+ *ret = (char)((ptr[0] - table) << 4 + (ptr[1] - table));
+ return 0;
+ }
+ return -1;
+}
+
+int parse_oct(unsigned char *buf, unsigned char *ret) {
+ int i;
+ *ret = 0;
+ for (i = 0; i < 3; i++) {
+ if (buf[i] - '0' < 0 && buf[i] - '0' > 8)
+ return -1;
+ *ret = (char)(*ret * 8 + buf[i] - '0');
+ }
+ return 0;
+}
+unsigned char parse_escape(char *buf, int *length) {
+ unsigned char input[] = "abfnrtv\\?'\"";
+ unsigned char output[] = "\a\b\f\n\r\t\v\\\?\'\"";
+ unsigned char ret = *buf;
+ *length = 1;
+ for (unsigned char *ptr = input; *ptr != 0; ptr++)
+ if (*buf == *ptr)
+ return output[ptr - input];
+
+ /* hexidecimal number*/
+ if (*buf == 'x')
+ if (parse_hex(buf + 1, &ret) != -1)
+ length = 2;
+
+ /* octal number */
+ else if(isdigit(*buf))
+ if (parse_oct(buf, &ret) != -1)
+ length = 3;
+ return ret;
+}
+
void load_language(char *filename, char *lang_str[MAX_STRING], int *_offset) {
int i, num_string, string_index, filesize;
- int inside_string, digit;
+ int inside_string, digit, length;
char *buf, *start, temp[256];
+ char escape_sequence;
FILE *f;
char *p_str_head = SHM->i18nstrbody;
int offset = *_offset;
@@ -42,14 +90,16 @@ void load_language(char *filename, char *lang_str[MAX_STRING], int *_offset) {
p_str_head[offset] = 0;
if (string_index >= 0 && string_index < MAX_STRING) {
lang_str[string_index] = start;
- //printf ("%d \"%s\"\n", string_index, start);
- //printf("%d\n", strlen(lang_str[string_index]));
- //fflush(0);
}
string_index = 0;
offset++;
continue;
}
+ else if (buf[i] == '\\' && inside_string == TRUE) {
+ escape_sequence = parse_escape(buf + i + 1, &length);
+ i += length;
+ buf[i] = escape_sequence;
+ }
if (inside_string == TRUE) {
if (offset < MAX_BUFFER_SIZE) {
p_str_head[offset] = buf[i];
@@ -79,6 +129,5 @@ void load_i18nstring() {
offset = 1;
for (i = 0; i < MAX_LANG; i++)
load_language(lang_file[i], SHM->i18nstr[i], &offset);
- //printf ("%d\n", offset);
}
#endif