diff --git a/edit/edit.c b/edit/edit.c index faf39db8f..4e6f4c392 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -214,14 +214,15 @@ int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width) } if ( byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0 ) { - *char_width = 1; + *char_width = 0; return 0; } str = edit_get_byte_ptr (edit, byte_index); buf = edit_get_buf_ptr (edit, byte_index); /* get prev utf8 char */ - str = g_utf8_find_prev_char (buf, str); + if ( str != buf ) + str = g_utf8_find_prev_char (buf, str); res = g_utf8_get_char_validated (str, -1); if ( res < 0 ) { diff --git a/edit/editdraw.c b/edit/editdraw.c index c0b36ddca..9f28d3d72 100644 --- a/edit/editdraw.c +++ b/edit/editdraw.c @@ -66,6 +66,9 @@ static void status_string (WEdit * edit, char *s, int w) { char byte_str[16]; + unsigned char cur_byte = 0; + unsigned int cur_utf = 0; + int cw = 1; /* * If we are at the end of file, print , @@ -74,28 +77,32 @@ static void status_string (WEdit * edit, char *s, int w) */ if (edit->curs1 < edit->last_byte) { if ( !edit->utf8 ) { - unsigned char cur_byte = edit_get_byte (edit, edit->curs1); - g_snprintf (byte_str, sizeof (byte_str), "%c %3d 0x%02X", - is_printable (cur_byte) ? cur_byte : '.', + cur_byte = edit_get_byte (edit, edit->curs1); + + g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", (int) cur_byte, (unsigned) cur_byte); } else { - int cw = 1; - unsigned int cur_utf = edit_get_utf (edit, edit->curs1, &cw); + cur_utf = edit_get_utf (edit, edit->curs1, &cw); if ( cw > 0 ) { g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", (unsigned) cur_utf, (unsigned) cur_utf); + } else { + cur_utf = edit_get_byte (edit, edit->curs1); + g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", + (int) cur_utf, + (unsigned) cur_utf); } } } else { - strcpy (byte_str, ""); + strcpy (byte_str, " "); } /* The field lengths just prevent the status line from shortening too much */ g_snprintf (s, w, - "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s C:%s", + "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s cp:%s", edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', edit->macro_i < 0 ? '-' : 'R', @@ -110,7 +117,9 @@ static void status_string (WEdit * edit, char *s, int w) edit->curs1, edit->last_byte, byte_str, - get_codepage_id( source_codepage )); + get_codepage_id ( source_codepage ) + ); + } static inline void diff --git a/src/strutil.c b/src/strutil.c index 19ce0565a..c777dc654 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -37,9 +37,9 @@ //names, that are used for utf-8 static const char *str_utf8_encodings[] = { - "utf-8", - "utf8", - NULL + "utf-8", + "utf8", + NULL }; // standard 8bit encodings, no wide or multibytes characters @@ -284,17 +284,11 @@ str_translate_char (GIConv conv, char *keys, size_t ch_size, left = (ch_size == (size_t) (-1)) ? strlen (keys) : ch_size; cnv = g_iconv (conv, &keys, &left, &output, &out_size); - if (cnv == (size_t) (-1)) - { - if (errno == EINVAL) - return ESTR_PROBLEM; - else - return ESTR_FAILURE; - } - else - { - output[0] = '\0'; - return 0; + if (cnv == (size_t)(-1)) { + if (errno == EINVAL) return ESTR_PROBLEM; else return ESTR_FAILURE; + } else { + output[0] = '\0'; + return 0; } } @@ -316,7 +310,6 @@ str_test_encoding_class (const char *encoding, const char **table) result += (g_ascii_strncasecmp (encoding, table[t], strlen (table[t])) == 0); } - return result; } @@ -351,8 +344,9 @@ str_isutf8 (char *codeset_name) void str_init_strings (const char *termenc) { - codeset = g_strdup ((termenc != NULL) - ? termenc : str_detect_termencoding ()); + codeset = g_strdup ((termenc != NULL) + ? termenc + : str_detect_termencoding ()); str_cnv_not_convert = g_iconv_open (codeset, codeset); if (str_cnv_not_convert == INVALID_CONV) @@ -425,7 +419,7 @@ str_get_next_char (char *text) const char * str_cget_next_char (const char *text) { - used_class.cnext_char (&text); + used_class.cnext_char(&text); return text; } diff --git a/src/strutil8bit.c b/src/strutil8bit.c index 46af2b440..3b54fe28b 100644 --- a/src/strutil8bit.c +++ b/src/strutil8bit.c @@ -490,7 +490,7 @@ str_8bit_offset_to_pos (const char *text, size_t length) static int str_8bit_column_to_pos (const char *text, size_t pos) { - return (int) pos; + return (int)pos; } static char * diff --git a/src/strutilascii.c b/src/strutilascii.c index c55f18d10..0920929c9 100644 --- a/src/strutilascii.c +++ b/src/strutilascii.c @@ -512,7 +512,7 @@ str_ascii_offset_to_pos (const char *text, size_t length) static int str_ascii_column_to_pos (const char *text, size_t pos) { - return (int) pos; + return (int)pos; } static char * diff --git a/src/strutilutf8.c b/src/strutilutf8.c index 179c7be22..f1b8371b3 100644 --- a/src/strutilutf8.c +++ b/src/strutilutf8.c @@ -342,7 +342,6 @@ str_utf8_vfs_convert_to (GIConv coder, const char *string, result = 0; } else -// result = _str_utf8_vfs_convert_to (coder, string, size, buffer); result = str_nconvert (coder, (char *) string, size, buffer); return result; @@ -386,44 +385,31 @@ str_utf8_make_make_term_form (const char *text, size_t length) } } } - - while (length != 0 && text[0] != '\0') - { - uni = g_utf8_get_char_validated (text, -1); - if ((uni != (gunichar) (-1)) && (uni != (gunichar) (-2))) - { - if (g_unichar_isprint (uni)) - { - left = g_unichar_to_utf8 (uni, actual); - actual += left; - if (!str_unichar_iscombiningmark (uni)) - { - result.width++; - if (g_unichar_iswide (uni)) - result.width++; - } - else - result.compose = 1; - } - else - { - actual[0] = '.'; - actual++; - result.width++; - } - text = g_utf8_next_char (text); - } - else - { - text++; - //actual[0] = '?'; - memcpy (actual, replch, strlen (replch)); - actual += strlen (replch); - result.width++; - } - if (length != (size_t) (-1)) - length--; - } + + while (length != 0 && text[0] != '\0') { + uni = g_utf8_get_char_validated (text, -1); + if ((uni != (gunichar)(-1)) && (uni != (gunichar)(-2))) { + if (g_unichar_isprint(uni)) { + left = g_unichar_to_utf8 (uni, actual); + actual+= left; + if (!str_unichar_iscombiningmark (uni)) { + result.width++; + if (g_unichar_iswide(uni)) result.width++; + } else result.compose = 1; + } else { + actual[0] = '.'; + actual++; + result.width++; + } + text = g_utf8_next_char (text); + } else { + text++; + //actual[0] = '?'; + memcpy (actual, replch, strlen (replch)); + actual+= strlen (replch); + result.width++; + } + if (length != (size_t) (-1)) length--; } actual[0] = '\0'; return &result; @@ -1218,51 +1204,48 @@ str_utf8_create_key_gen (const char *text, int case_sen, gchar * (*keygen) (const gchar *, gssize size)) { char *result; + + if (case_sen) { + result = str_utf8_normalize (text); + } else { + const char *start, *end; + char *fold, *key; + GString *fixed = g_string_new (""); - if (case_sen) - { - result = str_utf8_normalize (text); - } - else - { - const char *start, *end; - char *fold, *key; - GString *fixed = g_string_new (""); + start = text; + while (!g_utf8_validate (start, -1, &end) && start[0] != '\0') + { + if (start != end) + { + fold = g_utf8_casefold (start, end - start); + key = keygen (fold, -1); + g_string_append (fixed, key); + g_free (key); + g_free (fold); + } + g_string_append_c (fixed, end[0]); + start = end + 1; + } - start = text; - while (!g_utf8_validate (start, -1, &end) && start[0] != '\0') - { - if (start != end) - { - fold = g_utf8_casefold (start, end - start); - key = keygen (fold, -1); - g_string_append (fixed, key); - g_free (key); - g_free (fold); - } - g_string_append_c (fixed, end[0]); - start = end + 1; - } - - if (start == text) - { - fold = g_utf8_casefold (text, -1); - result = keygen (fold, -1); - g_free (fold); - } - else - { - if (start[0] != '\0' && start != end) - { - fold = g_utf8_casefold (start, end - start); - key = keygen (fold, -1); - g_string_append (fixed, key); - g_free (key); - g_free (fold); - } - result = g_strdup (fixed->str); - } - g_string_free (fixed, TRUE); + if (start == text) + { + fold = g_utf8_casefold (text, -1); + result = keygen (fold, -1); + g_free (fold); + } + else + { + if (start[0] != '\0' && start != end) + { + fold = g_utf8_casefold (start, end - start); + key = keygen (fold, -1); + g_string_append (fixed, key); + g_free (key); + g_free (fold); + } + result = g_strdup (fixed->str); + } + g_string_free (fixed, TRUE); } return result; } @@ -1292,7 +1275,7 @@ str_utf8_release_key (char *key, int case_sen) g_free (key); } -struct str_class +struct str_class str_utf8_init () { struct str_class result; diff --git a/src/view.c b/src/view.c index 277a18d22..91af2fbec 100644 --- a/src/view.c +++ b/src/view.c @@ -2457,24 +2457,24 @@ view_display_text (WView * view) } else { addch ('.'); } - } else { - GString *comb = g_string_new (""); - if (str_isprint (info.cact)) { - g_string_append(comb,info.cact); - } else { - g_string_append(comb,"."); - } - while (str_iscombiningmark (info.cnxt)) { - view_read_continue (view, &info); - g_string_append(comb,info.cact); - } - addstr (str_term_form (comb->str)); - g_string_free (comb, TRUE); - } + } else { + GString *comb = g_string_new (""); + if (str_isprint (info.cact)) { + g_string_append(comb,info.cact); + } else { + g_string_append(comb,"."); + } + while (str_iscombiningmark (info.cnxt)) { + view_read_continue (view, &info); + g_string_append(comb,info.cact); + } + addstr (str_term_form (comb->str)); + g_string_free (comb, TRUE); + } } else { - while (str_iscombiningmark (info.cnxt)) { - view_read_continue (view, &info); - } + while (str_iscombiningmark (info.cnxt)) { + view_read_continue (view, &info); + } } col+= w; @@ -2780,7 +2780,6 @@ view_get_line_at (WView *view, offset_type from, GString * buffer, continue; if (view_read_test_nroff_back (view, &info)) { -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! g_string_truncate (buffer, buffer->len-1); continue; } @@ -3653,12 +3652,13 @@ static void view_cmk_moveto_bottom (void *w, int n) { static void view_select_encoding (WView *view) { - char *enc; + char *enc = NULL; GIConv conv; struct cache_line *line; - enc = input_dialog ("Encoding", "Paste encoding", NULL, ""); + do_select_codepage (); + enc = g_strdup( get_codepage_id ( source_codepage ) ); if (enc != NULL) { conv = str_crt_conv_from (enc); if (conv != (iconv_t)(-1)) { @@ -3668,7 +3668,9 @@ view_select_encoding (WView *view) line = view_offset_to_line (view, view->dpy_start); view_set_first_showed (view, line); } + g_free(enc); } + } diff --git a/vfs/vfs.c b/vfs/vfs.c index 568898346..f16339f11 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -382,7 +382,7 @@ vfs_supported_enconding (const char *encoding) { * buffer - used to store result of translation */ static int -_vfs_translate_path (const char *path, int size, +_vfs_translate_path (const char *path, int size, GIConv defcnv, GString *buffer) { const char *semi; @@ -459,7 +459,7 @@ char * vfs_translate_path (const char *path) { int state; - + g_string_set_size(vfs_str_buffer,0); state = _vfs_translate_path (path, -1, str_cnv_from_term, vfs_str_buffer); // strict version @@ -1218,7 +1218,7 @@ vfs_shut (void) (*vfs->done) (vfs); g_slist_free (vfs_openfiles); - + g_string_free (vfs_str_buffer, TRUE); }