From b0729f75fb3406f58cb09de750941da35de97047 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Mon, 6 Apr 2009 10:31:12 +0000 Subject: [PATCH] replace isalpha to g_ascii_isalpha replace strlen to str_term_width1 add #include "strutil.h" if need --- edit/edit.c | 18 +++++++++--------- edit/editcmd.c | 31 ++++++++++++++++--------------- edit/editdraw.c | 5 +++-- edit/editlock.c | 5 +++-- edit/syntax.c | 3 ++- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index eb61c29a7..cb262e258 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -44,7 +44,7 @@ #include "../src/user.h" /* user_menu_cmd() */ #include "../src/wtools.h" /* query_dialog() */ #include "../src/timefmt.h" /* time formatting */ - +#include "../src/strutil.h" /* utf string functions */ /* what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL @@ -195,9 +195,9 @@ static int edit_find_filter (const char *filename) size_t i, l, e; if (!filename) return -1; - l = strlen (filename); + l = str_term_width1 (filename); for (i = 0; i < sizeof (all_filters) / sizeof (all_filters[0]); i++) { - e = strlen (all_filters[i].extension); + e = (all_filters[i].extension); if (l > e) if (!strcmp (all_filters[i].extension, filename + l - e)) return i; @@ -214,8 +214,8 @@ edit_get_filter (const char *filename) if (i < 0) return 0; quoted_name = name_quote (filename, 0); - l = strlen (quoted_name); - p = g_malloc (strlen (all_filters[i].read) + l + 2); + l = str_term_width1 (quoted_name); + p = g_malloc (str_term_width1 (all_filters[i].read) + l + 2); sprintf (p, all_filters[i].read, quoted_name); g_free (quoted_name); return p; @@ -230,8 +230,8 @@ edit_get_write_filter (const char *write_name, const char *filename) if (i < 0) return 0; writename = name_quote (write_name, 0); - l = strlen (writename); - p = g_malloc (strlen (all_filters[i].write) + l + 2); + l = str_term_width1 (writename); + p = g_malloc (str_term_width1 (all_filters[i].write) + l + 2); sprintf (p, all_filters[i].write, writename); g_free (writename); return p; @@ -507,7 +507,7 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename, if (option_whole_chars_search_buf != option_whole_chars_search) { size_t i; - size_t len = strlen (option_whole_chars_search); + size_t len = str_term_width1 (option_whole_chars_search); strcpy (option_whole_chars_search_buf, option_whole_chars_search); @@ -1689,7 +1689,7 @@ my_type_of (int c) c = 'A'; else if (islower (c)) c = 'a'; - else if (isalpha (c)) + else if (g_ascii_isalpha (c)) c = 'a'; else if (isdigit (c)) c = '0'; diff --git a/edit/editcmd.c b/edit/editcmd.c index d3f8ecf03..dd4154ac8 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -59,6 +59,7 @@ #include "../src/wtools.h" /* message() */ #include "../src/charsets.h" #include "../src/selcodepage.h" +#include "../src/strutil.h" /* utf string functions */ struct selection { unsigned char * text; @@ -136,11 +137,11 @@ catstrs (const char *first,...) if (!first) return 0; - len = strlen (first); + len = str_term_width1 (first); va_start (ap, first); while ((data = va_arg (ap, char *)) != 0) - len += strlen (data); + len += str_term_width1 (data); len++; @@ -440,23 +441,23 @@ void menu_save_mode_cmd (void) size_t l1; /* OK/Cancel buttons */ - l1 = strlen (_(widgets[0].text)) + strlen (_(widgets[1].text)) + 5; + l1 = str_term_width1 (_(widgets[0].text)) + str_term_width1 (_(widgets[1].text)) + 5; maxlen = max (maxlen, l1); for (i = 0; i < 3; i++ ) { str[i] = _(str[i]); - maxlen = max (maxlen, strlen (str[i]) + 7); + maxlen = max (maxlen, str_term_width1 (str[i]) + 7); } i18n_flag = 1; - dlg_x = maxlen + strlen (_(widgets[3].text)) + 5 + 1; - widgets[2].hotkey_pos = strlen (_(widgets[3].text)); /* input field length */ + dlg_x = maxlen + str_term_width1 (_(widgets[3].text)) + 5 + 1; + widgets[2].hotkey_pos = str_term_width1 (_(widgets[3].text)); /* input field length */ dlg_x = min (COLS, dlg_x); dialog.xlen = dlg_x; i = (dlg_x - l1)/3; widgets[1].relative_x = i; - widgets[0].relative_x = i + strlen (_(widgets[1].text)) + i + 4; + widgets[0].relative_x = i + str_term_width1 (_(widgets[1].text)) + i + 4; widgets[2].relative_x = widgets[3].relative_x = maxlen + 2; @@ -599,7 +600,7 @@ raw_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) int edit_raw_key_query (const char *heading, const char *query, int cancel) { - int w = strlen (query) + 7; + int w = str_term_width1 (query) + 7; struct Dlg_head *raw_dlg = create_dlg (0, 0, 7, w, dialog_colors, raw_callback, NULL, heading, @@ -1461,7 +1462,7 @@ static long edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit_getbyte_fn get_byte, void *data, int once_only, void *d) { long p, q = 0; - long l = strlen ((char *) exp), f = 0; + long l = str_term_width1 ((char *) exp), f = 0; int n = 0; for (p = 0; p < l; p++) /* count conversions... */ @@ -1523,7 +1524,7 @@ edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit start++; buf++; /* move the window along */ if (buf == mbuf + MAX_REPL_LEN) { /* the window is about to go past the end of array, so... */ - memmove (mbuf, buf, strlen ((char *) buf) + 1); /* reset it */ + memmove (mbuf, buf, str_term_width1 ((char *) buf) + 1); /* reset it */ buf = mbuf; } q--; @@ -1572,7 +1573,7 @@ edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit if (buf[q - 1] != '\n') { /* incomplete line: try to recover */ buf = mbuf + MAX_REPL_LEN / 2; - q = strlen ((const char *) buf); + q = str_term_width1 ((const char *) buf); memmove (mbuf, buf, q); p = start + q; move_win = 1; @@ -1582,7 +1583,7 @@ edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit } } } else { - *len = strlen ((const char *) exp); + *len = str_term_width1 ((const char *) exp); if (replace_case) { for (p = start; p <= last_byte - l; p++) { if ((*get_byte) (data, p) == (unsigned char)exp[0]) { /* check if first char matches */ @@ -1721,7 +1722,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...) if (*p == '*') { p++; strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace field width with a number */ - p1 += strlen (p1); + p1 += str_term_width1 (p1); } else { while (is_digit (*p) && p1 < q1 + 20) *p1++ = *p++; @@ -1733,7 +1734,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...) if (*p == '*') { p++; strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace precision with a number */ - p1 += strlen (p1); + p1 += str_term_width1 (p1); } else { while (is_digit (*p) && p1 < q1 + 32) *p1++ = *p++; @@ -1767,7 +1768,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...) q = p; } va_end (ap); - n = strlen (q); + n = str_term_width1 (q); if (n >= (size_t) (e - s)) return -1; memcpy (s, q, n + 1); diff --git a/edit/editdraw.c b/edit/editdraw.c index 86ea3f9c7..3c9dbe77f 100644 --- a/edit/editdraw.c +++ b/edit/editdraw.c @@ -46,6 +46,7 @@ #include "../src/widget.h" /* buttonbar_redraw() */ #include "../src/key.h" /* is_idle() */ #include "../src/charsets.h" +#include "../src/strutil.h" /* utf string functions */ /* Text styles */ #define MOD_ABNORMAL (1 << 8) @@ -123,11 +124,11 @@ edit_status (WEdit *edit) const int preferred_fname_len = 16; status_string (edit, status, status_size); - status_len = (int) strlen (status); + status_len = (int) str_term_width1 (status); if (edit->filename) fname = edit->filename; - fname_len = strlen(fname); + fname_len = str_term_width1 (fname); if (fname_len < preferred_fname_len) fname_len = preferred_fname_len; diff --git a/edit/editlock.c b/edit/editlock.c index c9434a252..bf201ba76 100644 --- a/edit/editlock.c +++ b/edit/editlock.c @@ -42,6 +42,7 @@ #include "editlock.h" #include "../src/wtools.h" /* edit_query_dialog () */ +#include "../src/strutil.h" /* utf string functions */ #define BUF_SIZE 255 #define PID_BUF_SIZE 10 @@ -112,7 +113,7 @@ lock_extract_info (const char *str) static char pid[PID_BUF_SIZE], who[BUF_SIZE]; static struct lock_s lock; - for (p = str + strlen (str) - 1; p >= str; p--) + for (p = str + str_term_width1 (str) - 1; p >= str; p--) if (*p == '.') break; @@ -125,7 +126,7 @@ lock_extract_info (const char *str) /* Treat text between '.' and ':' or '\0' as pid */ i = 0; for (p = p + 1; - p < str + strlen (str) && *p != ':' && i < PID_BUF_SIZE; p++) + p < str + str_term_width1 (str) && *p != ':' && i < PID_BUF_SIZE; p++) pid[i++] = *p; pid[i] = '\0'; diff --git a/edit/syntax.c b/edit/syntax.c index b517b4a0a..e7deb4003 100644 --- a/edit/syntax.c +++ b/edit/syntax.c @@ -39,6 +39,7 @@ #include "../src/color.h" /* use_colors */ #include "../src/main.h" /* mc_home */ #include "../src/wtools.h" /* message() */ +#include "../src/strutil.h" /* utf string functions */ /* bytes */ #define SYNTAX_MARKER_DENSITY 512 @@ -178,7 +179,7 @@ compare_word_to_right (WEdit *edit, long i, const char *text, if (strchr (whole_left, c)) return -1; - for (p = (unsigned char *) text, q = p + strlen ((char *) p); p < q; p++, i++) { + for (p = (unsigned char *) text, q = p + str_term_width1 ((char *) p); p < q; p++, i++) { switch (*p) { case SYNTAX_TOKEN_STAR: if (++p > q)