mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
Rework strutils for usage GString instread of self-made buffers.
This commit is contained in:
parent
21c88729a4
commit
dbf8dd1bc2
11
src/cmd.c
11
src/cmd.c
@ -1068,8 +1068,8 @@ get_random_hint (int force)
|
|||||||
int start;
|
int start;
|
||||||
static int last_sec;
|
static int last_sec;
|
||||||
static struct timeval tv;
|
static struct timeval tv;
|
||||||
str_conv_t conv;
|
GIConv conv;
|
||||||
struct str_buffer *buffer;
|
GString *buffer;
|
||||||
|
|
||||||
/* Do not change hints more often than one minute */
|
/* Do not change hints more often than one minute */
|
||||||
gettimeofday (&tv, NULL);
|
gettimeofday (&tv, NULL);
|
||||||
@ -1100,12 +1100,11 @@ get_random_hint (int force)
|
|||||||
/* try convert hint file from utf-8 to terminal encoding */
|
/* try convert hint file from utf-8 to terminal encoding */
|
||||||
conv = str_crt_conv_from ("UTF-8");
|
conv = str_crt_conv_from ("UTF-8");
|
||||||
if (conv != INVALID_CONV) {
|
if (conv != INVALID_CONV) {
|
||||||
buffer = str_get_buffer ();
|
buffer = g_string_new ("");
|
||||||
if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE) {
|
if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE) {
|
||||||
result = g_strdup (buffer->data);
|
result = g_strdup (buffer->str);
|
||||||
}
|
}
|
||||||
|
g_string_free (buffer, TRUE);
|
||||||
str_release_buffer (buffer);
|
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/help.c
18
src/help.c
@ -69,12 +69,6 @@
|
|||||||
#define STRING_LINK_END "\03"
|
#define STRING_LINK_END "\03"
|
||||||
#define STRING_NODE_END "\04"
|
#define STRING_NODE_END "\04"
|
||||||
|
|
||||||
/* every help file is supposed to be in utf-8 and is translated to terminal
|
|
||||||
* encoding */
|
|
||||||
/* buffer for translation */
|
|
||||||
static struct str_buffer *translated_data = NULL;
|
|
||||||
/* point into translated_data->data or in NULL,
|
|
||||||
* if help file could not be converted */
|
|
||||||
static char *data;
|
static char *data;
|
||||||
static int help_lines; /* Lines in help viewer */
|
static int help_lines; /* Lines in help viewer */
|
||||||
static int history_ptr; /* For the history queue */
|
static int history_ptr; /* For the history queue */
|
||||||
@ -775,26 +769,26 @@ interactive_display_finish (void)
|
|||||||
clear_link_areas ();
|
clear_link_areas ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* translate help file into terminal encoding
|
/* translate help file into terminal encoding */
|
||||||
* translated_data is initialized */
|
|
||||||
static void
|
static void
|
||||||
translate_file (char *filedata)
|
translate_file (char *filedata)
|
||||||
{
|
{
|
||||||
str_conv_t conv;
|
GIConv conv;
|
||||||
|
GString *translated_data;
|
||||||
|
|
||||||
if (translated_data == NULL) translated_data = str_get_buffer ();
|
translated_data = g_string_new ("");
|
||||||
|
|
||||||
str_reset_buffer (translated_data);
|
|
||||||
conv = str_crt_conv_from ("UTF-8");
|
conv = str_crt_conv_from ("UTF-8");
|
||||||
|
|
||||||
if (conv != INVALID_CONV) {
|
if (conv != INVALID_CONV) {
|
||||||
if (str_convert (conv, filedata, translated_data) != ESTR_FAILURE) {
|
if (str_convert (conv, filedata, translated_data) != ESTR_FAILURE) {
|
||||||
data = translated_data->data;
|
data = translated_data->str;
|
||||||
} else {
|
} else {
|
||||||
data = NULL;
|
data = NULL;
|
||||||
}
|
}
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
}
|
}
|
||||||
|
g_string_free (translated_data, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -218,20 +218,18 @@ do { \
|
|||||||
static void fill_listbox (void)
|
static void fill_listbox (void)
|
||||||
{
|
{
|
||||||
struct hotlist *current = current_group->head;
|
struct hotlist *current = current_group->head;
|
||||||
struct str_buffer *buff;
|
GString *buff = g_string_new ("");
|
||||||
|
|
||||||
buff = str_get_buffer ();
|
|
||||||
|
|
||||||
while (current){
|
while (current){
|
||||||
switch (current->type) {
|
switch (current->type) {
|
||||||
case HL_TYPE_GROUP:
|
case HL_TYPE_GROUP:
|
||||||
{
|
{
|
||||||
str_insert_string ("->", buff);
|
g_string_append(buff,"->");
|
||||||
str_insert_string (current->label, buff);
|
g_string_append(buff,current->label);
|
||||||
if (hotlist_state.moving)
|
if (hotlist_state.moving)
|
||||||
listbox_add_item (l_movelist, 0, 0, buff->data, current);
|
listbox_add_item (l_movelist, 0, 0, buff->str, current);
|
||||||
else
|
else
|
||||||
listbox_add_item (l_hotlist, 0, 0, buff->data, current);
|
listbox_add_item (l_hotlist, 0, 0, buff->str, current);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HL_TYPE_DOTDOT:
|
case HL_TYPE_DOTDOT:
|
||||||
@ -246,8 +244,7 @@ static void fill_listbox (void)
|
|||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
g_string_free (buff, TRUE);
|
||||||
str_release_buffer (buff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1203,7 +1200,7 @@ load_group (struct hotlist *grp)
|
|||||||
#define TKN_EOF 126
|
#define TKN_EOF 126
|
||||||
#define TKN_UNKNOWN 127
|
#define TKN_UNKNOWN 127
|
||||||
|
|
||||||
static struct str_buffer *tkn_buf = NULL;
|
static GString *tkn_buf = NULL;
|
||||||
|
|
||||||
static char *hotlist_file_name;
|
static char *hotlist_file_name;
|
||||||
static FILE *hotlist_file;
|
static FILE *hotlist_file;
|
||||||
@ -1221,41 +1218,47 @@ static int hot_skip_blanks (void)
|
|||||||
|
|
||||||
static int hot_next_token (void)
|
static int hot_next_token (void)
|
||||||
{
|
{
|
||||||
int c;
|
int c, ret=0;
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
if (tkn_buf == NULL) tkn_buf = str_get_buffer ();
|
|
||||||
str_reset_buffer (tkn_buf);
|
if (tkn_buf == NULL) tkn_buf = g_string_new ("");
|
||||||
|
g_string_set_size(tkn_buf,0);
|
||||||
|
|
||||||
again:
|
again:
|
||||||
c = hot_skip_blanks ();
|
c = hot_skip_blanks ();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case EOF:
|
case EOF:
|
||||||
return TKN_EOF;
|
ret = TKN_EOF;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
return TKN_EOL;
|
ret = TKN_EOL;
|
||||||
break;
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
while ((c = getc (hotlist_file)) != EOF && c != '\n') {
|
while ((c = getc (hotlist_file)) != EOF && c != '\n') {
|
||||||
str_insert_char (c, tkn_buf);
|
g_string_append_c (tkn_buf, c);
|
||||||
}
|
}
|
||||||
return TKN_COMMENT;
|
ret = TKN_COMMENT;
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
while ((c = getc (hotlist_file)) != EOF && c != '"') {
|
while ((c = getc (hotlist_file)) != EOF && c != '"') {
|
||||||
if (c == '\\')
|
if (c == '\\')
|
||||||
if ((c = getc (hotlist_file)) == EOF)
|
if ((c = getc (hotlist_file)) == EOF){
|
||||||
|
g_string_free (tkn_buf, TRUE);
|
||||||
return TKN_EOF;
|
return TKN_EOF;
|
||||||
str_insert_char (c == '\n' ? ' ' : c, tkn_buf);
|
}
|
||||||
|
g_string_append_c (tkn_buf, c == '\n' ? ' ' : c);
|
||||||
}
|
}
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return TKN_EOF;
|
ret = TKN_EOF;
|
||||||
return TKN_STRING;
|
else
|
||||||
|
ret = TKN_STRING;
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
if ((c = getc (hotlist_file)) == EOF)
|
if ((c = getc (hotlist_file)) == EOF){
|
||||||
|
g_string_free (tkn_buf, TRUE);
|
||||||
return TKN_EOF;
|
return TKN_EOF;
|
||||||
|
}
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
goto again;
|
goto again;
|
||||||
|
|
||||||
@ -1263,24 +1266,25 @@ again:
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
do {
|
do {
|
||||||
str_insert_char (g_ascii_toupper (c), tkn_buf);
|
g_string_append_c (tkn_buf, g_ascii_toupper (c));
|
||||||
} while ((c = fgetc (hotlist_file)) != EOF &&
|
} while ((c = fgetc (hotlist_file)) != EOF &&
|
||||||
(g_ascii_isalnum (c) || !isascii (c)));
|
(g_ascii_isalnum (c) || !isascii (c)));
|
||||||
if (c != EOF)
|
if (c != EOF)
|
||||||
ungetc (c, hotlist_file);
|
ungetc (c, hotlist_file);
|
||||||
l = tkn_buf->size - tkn_buf->remain;
|
l = tkn_buf->len;
|
||||||
if (strncmp (tkn_buf->data, "GROUP", l) == 0)
|
if (strncmp (tkn_buf->str, "GROUP", l) == 0)
|
||||||
return TKN_GROUP;
|
ret = TKN_GROUP;
|
||||||
else if (strncmp (tkn_buf->data, "ENTRY", l) == 0)
|
else if (strncmp (tkn_buf->str, "ENTRY", l) == 0)
|
||||||
return TKN_ENTRY;
|
ret = TKN_ENTRY;
|
||||||
else if (strncmp (tkn_buf->data, "ENDGROUP", l) == 0)
|
else if (strncmp (tkn_buf->str, "ENDGROUP", l) == 0)
|
||||||
return TKN_ENDGROUP;
|
ret = TKN_ENDGROUP;
|
||||||
else if (strncmp (tkn_buf->data, "URL", l) == 0)
|
else if (strncmp (tkn_buf->str, "URL", l) == 0)
|
||||||
return TKN_URL;
|
ret = TKN_URL;
|
||||||
else
|
else
|
||||||
return TKN_UNKNOWN;
|
ret = TKN_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SKIP_TO_EOL { \
|
#define SKIP_TO_EOL { \
|
||||||
@ -1310,22 +1314,22 @@ hot_load_group (struct hotlist * grp)
|
|||||||
switch (tkn) {
|
switch (tkn) {
|
||||||
case TKN_GROUP:
|
case TKN_GROUP:
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
new_grp = add2hotlist (g_strdup (tkn_buf->data), 0, HL_TYPE_GROUP, 0);
|
new_grp = add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, 0);
|
||||||
SKIP_TO_EOL;
|
SKIP_TO_EOL;
|
||||||
hot_load_group (new_grp);
|
hot_load_group (new_grp);
|
||||||
current_group = grp;
|
current_group = grp;
|
||||||
break;
|
break;
|
||||||
case TKN_ENTRY:
|
case TKN_ENTRY:
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
label = g_strdup (tkn_buf->data);
|
label = g_strdup (tkn_buf->str);
|
||||||
CHECK_TOKEN(TKN_URL);
|
CHECK_TOKEN(TKN_URL);
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
url = g_strdup (tkn_buf->data);
|
url = g_strdup (tkn_buf->str);
|
||||||
add2hotlist (label, url, HL_TYPE_ENTRY, 0);
|
add2hotlist (label, url, HL_TYPE_ENTRY, 0);
|
||||||
SKIP_TO_EOL;
|
SKIP_TO_EOL;
|
||||||
break;
|
break;
|
||||||
case TKN_COMMENT:
|
case TKN_COMMENT:
|
||||||
label = g_strdup (tkn_buf->data);
|
label = g_strdup (tkn_buf->str);
|
||||||
add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
|
add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
|
||||||
break;
|
break;
|
||||||
case TKN_EOF:
|
case TKN_EOF:
|
||||||
@ -1358,22 +1362,22 @@ hot_load_file (struct hotlist * grp)
|
|||||||
switch (tkn) {
|
switch (tkn) {
|
||||||
case TKN_GROUP:
|
case TKN_GROUP:
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
new_grp = add2hotlist (g_strdup (tkn_buf->data), 0, HL_TYPE_GROUP, 0);
|
new_grp = add2hotlist (g_strdup (tkn_buf->str), 0, HL_TYPE_GROUP, 0);
|
||||||
SKIP_TO_EOL;
|
SKIP_TO_EOL;
|
||||||
hot_load_group (new_grp);
|
hot_load_group (new_grp);
|
||||||
current_group = grp;
|
current_group = grp;
|
||||||
break;
|
break;
|
||||||
case TKN_ENTRY:
|
case TKN_ENTRY:
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
label = g_strdup (tkn_buf->data);
|
label = g_strdup (tkn_buf->str);
|
||||||
CHECK_TOKEN(TKN_URL);
|
CHECK_TOKEN(TKN_URL);
|
||||||
CHECK_TOKEN(TKN_STRING);
|
CHECK_TOKEN(TKN_STRING);
|
||||||
url = g_strdup (tkn_buf->data);
|
url = g_strdup (tkn_buf->str);
|
||||||
add2hotlist (label, url, HL_TYPE_ENTRY, 0);
|
add2hotlist (label, url, HL_TYPE_ENTRY, 0);
|
||||||
SKIP_TO_EOL;
|
SKIP_TO_EOL;
|
||||||
break;
|
break;
|
||||||
case TKN_COMMENT:
|
case TKN_COMMENT:
|
||||||
label = g_strdup (tkn_buf->data);
|
label = g_strdup (tkn_buf->str);
|
||||||
add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
|
add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
|
||||||
break;
|
break;
|
||||||
case TKN_EOL:
|
case TKN_EOL:
|
||||||
@ -1579,7 +1583,7 @@ void done_hotlist (void)
|
|||||||
current_group = 0;
|
current_group = 0;
|
||||||
|
|
||||||
if (tkn_buf){
|
if (tkn_buf){
|
||||||
str_release_buffer (tkn_buf);
|
g_string_free (tkn_buf, TRUE);
|
||||||
tkn_buf = NULL;
|
tkn_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/info.c
24
src/info.c
@ -63,8 +63,7 @@ info_show_info (struct WInfo *info)
|
|||||||
{
|
{
|
||||||
static int i18n_adjust=0;
|
static int i18n_adjust=0;
|
||||||
static const char *file_label;
|
static const char *file_label;
|
||||||
struct str_buffer *buff;
|
GString *buff;
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (!is_idle ())
|
if (!is_idle ())
|
||||||
@ -94,7 +93,7 @@ info_show_info (struct WInfo *info)
|
|||||||
i18n_adjust = str_term_width1(file_label) + 2;
|
i18n_adjust = str_term_width1(file_label) + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = str_get_buffer ();
|
buff = g_string_new ("");
|
||||||
|
|
||||||
switch (info->widget.lines-2){
|
switch (info->widget.lines-2){
|
||||||
/* Note: all cases are fall-throughs */
|
/* Note: all cases are fall-throughs */
|
||||||
@ -135,24 +134,21 @@ info_show_info (struct WInfo *info)
|
|||||||
widget_move (&info->widget, 13, 3);
|
widget_move (&info->widget, 13, 3);
|
||||||
str_printf (buff, _("Device: %s"),
|
str_printf (buff, _("Device: %s"),
|
||||||
str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
|
str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
|
||||||
addstr (str_term_form (buff->data));
|
addstr (str_term_form (buff->str));
|
||||||
str_reset_buffer (buff);
|
g_string_set_size(buff,0);
|
||||||
case 12:
|
case 12:
|
||||||
widget_move (&info->widget, 12, 3);
|
widget_move (&info->widget, 12, 3);
|
||||||
str_printf (buff, _("Filesystem: %s"),
|
str_printf (buff, _("Filesystem: %s"),
|
||||||
str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
|
str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
|
||||||
addstr (str_term_form (buff->data));
|
addstr (str_term_form (buff->str));
|
||||||
str_reset_buffer (buff);
|
|
||||||
case 11:
|
case 11:
|
||||||
widget_move (&info->widget, 11, 3);
|
widget_move (&info->widget, 11, 3);
|
||||||
str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
|
str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
|
||||||
addstr (str_term_form (buff->data));
|
addstr (str_term_form (buff->str));
|
||||||
str_reset_buffer (buff);
|
|
||||||
case 10:
|
case 10:
|
||||||
widget_move (&info->widget, 10, 3);
|
widget_move (&info->widget, 10, 3);
|
||||||
str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
|
str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
|
||||||
addstr (str_term_form (buff->data));
|
addstr (str_term_form (buff->str));
|
||||||
str_reset_buffer (buff);
|
|
||||||
case 9:
|
case 9:
|
||||||
widget_move (&info->widget, 9, 3);
|
widget_move (&info->widget, 9, 3);
|
||||||
/* TRANSLATORS: "Status changed", like in the stat(2) man page */
|
/* TRANSLATORS: "Status changed", like in the stat(2) man page */
|
||||||
@ -204,8 +200,7 @@ info_show_info (struct WInfo *info)
|
|||||||
str_printf (buff, file_label,
|
str_printf (buff, file_label,
|
||||||
str_trunc (current_panel->dir.list [current_panel->selected].fname,
|
str_trunc (current_panel->dir.list [current_panel->selected].fname,
|
||||||
info->widget.cols - i18n_adjust));
|
info->widget.cols - i18n_adjust));
|
||||||
addstr (str_term_form (buff->data));
|
addstr (str_term_form (buff->str));
|
||||||
str_reset_buffer (buff);
|
|
||||||
} else
|
} else
|
||||||
addstr (_("File: None"));
|
addstr (_("File: None"));
|
||||||
|
|
||||||
@ -214,8 +209,7 @@ info_show_info (struct WInfo *info)
|
|||||||
case 0:
|
case 0:
|
||||||
;
|
;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
|
g_string_free (buff, TRUE);
|
||||||
str_release_buffer (buff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void info_hook (void *data)
|
static void info_hook (void *data)
|
||||||
|
396
src/strutil.c
396
src/strutil.c
@ -39,7 +39,8 @@
|
|||||||
static const char *str_utf8_encodings[] = {
|
static const char *str_utf8_encodings[] = {
|
||||||
"utf-8",
|
"utf-8",
|
||||||
"utf8",
|
"utf8",
|
||||||
NULL};
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
// standard 8bit encodings, no wide or multibytes characters
|
// standard 8bit encodings, no wide or multibytes characters
|
||||||
static const char *str_8bit_encodings[] = {
|
static const char *str_8bit_encodings[] = {
|
||||||
@ -63,8 +64,6 @@ static const char *str_8bit_encodings[] = {
|
|||||||
static char *codeset;
|
static char *codeset;
|
||||||
// function for encoding specific operations
|
// function for encoding specific operations
|
||||||
static struct str_class used_class;
|
static struct str_class used_class;
|
||||||
// linked list of string buffers
|
|
||||||
static struct str_buffer *buffer_list = NULL;
|
|
||||||
|
|
||||||
iconv_t str_cnv_to_term;
|
iconv_t str_cnv_to_term;
|
||||||
iconv_t str_cnv_from_term;
|
iconv_t str_cnv_from_term;
|
||||||
@ -77,274 +76,194 @@ str_test_not_convert (const char *enc)
|
|||||||
return g_ascii_strcasecmp (enc, codeset) == 0;
|
return g_ascii_strcasecmp (enc, codeset) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
str_conv_t
|
GIConv
|
||||||
str_crt_conv_to (const char *to_enc)
|
str_crt_conv_to (const char *to_enc)
|
||||||
{
|
{
|
||||||
return (!str_test_not_convert (to_enc)) ? iconv_open (to_enc, codeset) :
|
return (!str_test_not_convert (to_enc))
|
||||||
str_cnv_not_convert;
|
? g_iconv_open (to_enc, codeset) : str_cnv_not_convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
str_conv_t
|
GIConv
|
||||||
str_crt_conv_from (const char *from_enc)
|
str_crt_conv_from (const char *from_enc)
|
||||||
{
|
{
|
||||||
return (!str_test_not_convert (from_enc)) ? iconv_open (codeset, from_enc) :
|
return (!str_test_not_convert (from_enc))
|
||||||
str_cnv_not_convert;
|
? g_iconv_open (codeset, from_enc) : str_cnv_not_convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
str_close_conv (str_conv_t conv)
|
str_close_conv (GIConv conv)
|
||||||
{
|
{
|
||||||
if (conv != str_cnv_not_convert)
|
if (conv != str_cnv_not_convert)
|
||||||
iconv_close (conv);
|
g_iconv_close (conv);
|
||||||
}
|
|
||||||
|
|
||||||
struct str_buffer *
|
|
||||||
str_get_buffer ()
|
|
||||||
{
|
|
||||||
struct str_buffer *result;
|
|
||||||
|
|
||||||
result = buffer_list;
|
|
||||||
|
|
||||||
while (result != NULL) {
|
|
||||||
if (!result->used) {
|
|
||||||
str_reset_buffer (result);
|
|
||||||
result->used = 1;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = result->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = g_new (struct str_buffer, 1);
|
|
||||||
result->size = BUF_TINY;
|
|
||||||
result->data = g_new0 (char, result->size);
|
|
||||||
result->data[0] = '\0';
|
|
||||||
result->actual = result->data;
|
|
||||||
result->remain = result->size;
|
|
||||||
|
|
||||||
result->next = buffer_list;
|
|
||||||
buffer_list = result;
|
|
||||||
|
|
||||||
result->used = 1;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
str_release_buffer (struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
buffer->used = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
str_incrase_buffer (struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
size_t offset;
|
|
||||||
|
|
||||||
offset = buffer->actual - buffer->data;
|
|
||||||
buffer->remain+= buffer->size;
|
|
||||||
buffer->size*= 2;
|
|
||||||
buffer->data = g_renew (char, buffer->data, buffer->size);
|
|
||||||
buffer->actual = buffer->data + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
str_reset_buffer (struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
buffer->data[0] = '\0';
|
|
||||||
buffer->actual = buffer->data;
|
|
||||||
buffer->remain = buffer->size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_str_convert (str_conv_t coder, char *string, struct str_buffer *buffer)
|
_str_convert (GIConv coder, char *string, int size, GString * buffer)
|
||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
|
gchar *tmp_buff;
|
||||||
size_t left;
|
gssize left;
|
||||||
size_t nconv;
|
gsize bytes_read, bytes_written;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if (used_class.is_valid_string (string)) {
|
if (used_class.is_valid_string (string))
|
||||||
|
{
|
||||||
state = 0;
|
state = 0;
|
||||||
|
if (size < 0)
|
||||||
left = strlen (string);
|
{
|
||||||
|
size = strlen (string);
|
||||||
if (coder == (iconv_t) (-1)) return ESTR_FAILURE;
|
}
|
||||||
|
else
|
||||||
iconv(coder, NULL, NULL, NULL, NULL);
|
{
|
||||||
|
left = strlen (string);
|
||||||
while (((int)left) > 0) {
|
if (left < size)
|
||||||
nconv = iconv(coder, &string, &left,
|
size = left;
|
||||||
&(buffer->actual), &(buffer->remain));
|
}
|
||||||
if (nconv == (size_t) (-1)) {
|
left = size;
|
||||||
switch (errno) {
|
|
||||||
case EINVAL:
|
if (coder == (GIConv) (-1))
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
case EILSEQ:
|
|
||||||
string++;
|
g_iconv (coder, NULL, NULL, NULL, NULL);
|
||||||
left--;
|
|
||||||
if (buffer->remain <= 0) {
|
while (left)
|
||||||
str_incrase_buffer (buffer);
|
{
|
||||||
|
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
||||||
|
left,
|
||||||
|
coder,
|
||||||
|
&bytes_read,
|
||||||
|
&bytes_written, &error);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
switch (error->code)
|
||||||
|
{
|
||||||
|
case G_CONVERT_ERROR_NO_CONVERSION:
|
||||||
|
/* Conversion between the requested character sets is not supported. */
|
||||||
|
tmp_buff = g_strnfill (strlen (string), '?');
|
||||||
|
g_string_append (buffer, tmp_buff);
|
||||||
|
g_free (tmp_buff);
|
||||||
|
g_error_free (error);
|
||||||
|
return ESTR_PROBLEM;
|
||||||
|
break;
|
||||||
|
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
|
||||||
|
/* Invalid byte sequence in conversion input. */
|
||||||
|
g_string_append (buffer, tmp_buff);
|
||||||
|
g_string_append (buffer, "?");
|
||||||
|
g_free (tmp_buff);
|
||||||
|
if (bytes_read < left)
|
||||||
|
{
|
||||||
|
string += bytes_read + 1;
|
||||||
|
size -= (bytes_read + 1);
|
||||||
|
left -= (bytes_read + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_error_free (error);
|
||||||
|
return ESTR_PROBLEM;
|
||||||
}
|
}
|
||||||
buffer->actual[0] = '?';
|
|
||||||
buffer->actual++;
|
|
||||||
buffer->remain--;
|
|
||||||
state = ESTR_PROBLEM;
|
state = ESTR_PROBLEM;
|
||||||
break;
|
break;
|
||||||
case E2BIG:
|
case G_CONVERT_ERROR_PARTIAL_INPUT:
|
||||||
str_incrase_buffer (buffer);
|
/* Partial character sequence at end of input. */
|
||||||
|
g_error_free (error);
|
||||||
|
g_string_append (buffer, tmp_buff);
|
||||||
|
g_free (tmp_buff);
|
||||||
|
if (bytes_read < left)
|
||||||
|
{
|
||||||
|
left = left - bytes_read;
|
||||||
|
tmp_buff = g_strnfill (left, '?');
|
||||||
|
g_string_append (buffer, tmp_buff);
|
||||||
|
g_free (tmp_buff);
|
||||||
|
}
|
||||||
|
return ESTR_PROBLEM;
|
||||||
break;
|
break;
|
||||||
}
|
case G_CONVERT_ERROR_BAD_URI: /* Don't know how handle this error :( */
|
||||||
}
|
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
|
||||||
};
|
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
|
||||||
|
default:
|
||||||
|
g_error_free (error);
|
||||||
|
if (tmp_buff)
|
||||||
|
g_free (tmp_buff);
|
||||||
|
|
||||||
|
return ESTR_FAILURE;
|
||||||
|
}
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_string_append (buffer, tmp_buff);
|
||||||
|
g_free (tmp_buff);
|
||||||
|
string += bytes_read;
|
||||||
|
left -= bytes_read;
|
||||||
|
}
|
||||||
|
}
|
||||||
return state;
|
return state;
|
||||||
} else return ESTR_FAILURE;
|
}
|
||||||
|
else
|
||||||
|
return ESTR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
str_convert (str_conv_t coder, char *string, struct str_buffer *buffer)
|
str_convert (GIConv coder, char *string, GString * buffer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result = _str_convert (coder, string, buffer);
|
result = _str_convert (coder, string, -1, buffer);
|
||||||
buffer->actual[0] = '\0';
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
_str_vfs_convert_from (str_conv_t coder, char *string,
|
|
||||||
struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
size_t left;
|
|
||||||
size_t nconv;
|
|
||||||
|
|
||||||
left = strlen (string);
|
|
||||||
|
|
||||||
if (coder == (iconv_t) (-1)) return ESTR_FAILURE;
|
|
||||||
|
|
||||||
iconv(coder, NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
do {
|
|
||||||
nconv = iconv(coder, &string, &left,
|
|
||||||
&(buffer->actual), &(buffer->remain));
|
|
||||||
if (nconv == (size_t) (-1)) {
|
|
||||||
switch (errno) {
|
|
||||||
case EINVAL:
|
|
||||||
return ESTR_FAILURE;
|
|
||||||
case EILSEQ:
|
|
||||||
return ESTR_FAILURE;
|
|
||||||
case E2BIG:
|
|
||||||
str_incrase_buffer (buffer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (left > 0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
str_vfs_convert_from (str_conv_t coder, char *string, struct str_buffer *buffer)
|
str_nconvert (GIConv coder, char *string, int size, GString * buffer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (coder == str_cnv_not_convert) {
|
result = _str_convert (coder, string, size, buffer);
|
||||||
str_insert_string (string, buffer);
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
str_vfs_convert_from (GIConv coder, char *string, GString * buffer)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
if (coder == str_cnv_not_convert)
|
||||||
|
{
|
||||||
|
g_string_append (buffer, string);
|
||||||
result = 0;
|
result = 0;
|
||||||
} else result = _str_vfs_convert_from (coder, string, buffer);
|
}
|
||||||
buffer->actual[0] = '\0';
|
else
|
||||||
|
result = _str_convert (coder, string, -1, buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
str_vfs_convert_to (str_conv_t coder, const char *string,
|
str_vfs_convert_to (GIConv coder, const char *string, int size,
|
||||||
int size, struct str_buffer *buffer)
|
GString * buffer)
|
||||||
{
|
{
|
||||||
return used_class.vfs_convert_to (coder, string, size, buffer);
|
return used_class.vfs_convert_to (coder, string, size, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
str_insert_string (const char *string, struct str_buffer *buffer)
|
str_printf (GString * buffer, const char *format, ...)
|
||||||
{
|
{
|
||||||
size_t s;
|
|
||||||
|
|
||||||
s = strlen (string);
|
|
||||||
while (buffer->remain < s) str_incrase_buffer (buffer);
|
|
||||||
|
|
||||||
memcpy (buffer->actual, string, s);
|
|
||||||
buffer->actual+= s;
|
|
||||||
buffer->remain-= s;
|
|
||||||
buffer->actual[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
str_insert_string2 (const char *string, int size, struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
size_t s;
|
|
||||||
|
|
||||||
s = (size >= 0) ? size : strlen (string);
|
|
||||||
while (buffer->remain < s) str_incrase_buffer (buffer);
|
|
||||||
|
|
||||||
memcpy (buffer->actual, string, s);
|
|
||||||
buffer->actual+= s;
|
|
||||||
buffer->remain-= s;
|
|
||||||
buffer->actual[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
str_printf (struct str_buffer *buffer, const char *format, ...)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start (ap, format);
|
va_start (ap, format);
|
||||||
size = vsnprintf (buffer->actual, buffer->remain, format, ap);
|
g_string_append_vprintf (buffer, format, ap);
|
||||||
while (buffer->remain <= size) {
|
|
||||||
str_incrase_buffer (buffer);
|
|
||||||
size = vsnprintf (buffer->actual, buffer->remain, format, ap);
|
|
||||||
}
|
|
||||||
buffer->actual+= size;
|
|
||||||
buffer->remain-= size;
|
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
str_insert_char (char ch, struct str_buffer *buffer)
|
str_insert_replace_char (GString * buffer)
|
||||||
{
|
|
||||||
if (buffer->remain <= 1) str_incrase_buffer (buffer);
|
|
||||||
|
|
||||||
buffer->actual[0] = ch;
|
|
||||||
buffer->actual++;
|
|
||||||
buffer->remain--;
|
|
||||||
buffer->actual[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
str_insert_replace_char (struct str_buffer *buffer)
|
|
||||||
{
|
{
|
||||||
used_class.insert_replace_char (buffer);
|
used_class.insert_replace_char (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
str_backward_buffer (struct str_buffer *buffer, int count)
|
|
||||||
{
|
|
||||||
char *prev;
|
|
||||||
|
|
||||||
while ((count > 0) && (buffer->actual > buffer->data)) {
|
|
||||||
prev = str_get_prev_char (buffer->actual);
|
|
||||||
buffer->remain+= buffer->actual - prev;
|
|
||||||
buffer->actual = prev;
|
|
||||||
buffer->actual[0] = '\0';
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
str_translate_char (str_conv_t conv, char *keys, size_t ch_size,
|
str_translate_char (str_conv_t conv, char *keys, size_t ch_size,
|
||||||
char *output, size_t out_size)
|
char *output, size_t out_size)
|
||||||
@ -357,9 +276,15 @@ str_translate_char (str_conv_t conv, char *keys, size_t ch_size,
|
|||||||
left = (ch_size == (size_t) (-1)) ? strlen (keys) : ch_size;
|
left = (ch_size == (size_t) (-1)) ? strlen (keys) : ch_size;
|
||||||
|
|
||||||
cnv = iconv (conv, &keys, &left, &output, &out_size);
|
cnv = iconv (conv, &keys, &left, &output, &out_size);
|
||||||
if (cnv == (size_t)(-1)) {
|
if (cnv == (size_t) (-1))
|
||||||
if (errno == EINVAL) return ESTR_PROBLEM; else return ESTR_FAILURE;
|
{
|
||||||
} else {
|
if (errno == EINVAL)
|
||||||
|
return ESTR_PROBLEM;
|
||||||
|
else
|
||||||
|
return ESTR_FAILURE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
output[0] = '\0';
|
output[0] = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -378,7 +303,8 @@ str_test_encoding_class (const char *encoding, const char **table)
|
|||||||
int t;
|
int t;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
for (t = 0; table[t] != NULL; t++) {
|
for (t = 0; table[t] != NULL; t++)
|
||||||
|
{
|
||||||
result += (g_ascii_strncasecmp (encoding, table[t],
|
result += (g_ascii_strncasecmp (encoding, table[t],
|
||||||
strlen (table[t])) == 0);
|
strlen (table[t])) == 0);
|
||||||
}
|
}
|
||||||
@ -389,11 +315,16 @@ str_test_encoding_class (const char *encoding, const char **table)
|
|||||||
static void
|
static void
|
||||||
str_choose_str_functions ()
|
str_choose_str_functions ()
|
||||||
{
|
{
|
||||||
if (str_test_encoding_class (codeset, str_utf8_encodings)) {
|
if (str_test_encoding_class (codeset, str_utf8_encodings))
|
||||||
|
{
|
||||||
used_class = str_utf8_init ();
|
used_class = str_utf8_init ();
|
||||||
} else if (str_test_encoding_class (codeset, str_8bit_encodings)) {
|
}
|
||||||
|
else if (str_test_encoding_class (codeset, str_8bit_encodings))
|
||||||
|
{
|
||||||
used_class = str_8bit_init ();
|
used_class = str_8bit_init ();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
used_class = str_ascii_init ();
|
used_class = str_ascii_init ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -402,7 +333,8 @@ int
|
|||||||
str_isutf8 (char *codeset_name)
|
str_isutf8 (char *codeset_name)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (str_test_encoding_class (codeset_name, str_utf8_encodings)) {
|
if (str_test_encoding_class (codeset_name, str_utf8_encodings))
|
||||||
|
{
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -412,18 +344,20 @@ void
|
|||||||
str_init_strings (const char *termenc)
|
str_init_strings (const char *termenc)
|
||||||
{
|
{
|
||||||
codeset = g_strdup ((termenc != NULL)
|
codeset = g_strdup ((termenc != NULL)
|
||||||
? termenc
|
? termenc : str_detect_termencoding ());
|
||||||
: str_detect_termencoding ());
|
|
||||||
|
|
||||||
str_cnv_not_convert = iconv_open (codeset, codeset);
|
str_cnv_not_convert = iconv_open (codeset, codeset);
|
||||||
if (str_cnv_not_convert == INVALID_CONV) {
|
if (str_cnv_not_convert == INVALID_CONV)
|
||||||
if (termenc != NULL) {
|
{
|
||||||
|
if (termenc != NULL)
|
||||||
|
{
|
||||||
g_free (codeset);
|
g_free (codeset);
|
||||||
codeset = g_strdup (str_detect_termencoding ());
|
codeset = g_strdup (str_detect_termencoding ());
|
||||||
str_cnv_not_convert = iconv_open (codeset, codeset);
|
str_cnv_not_convert = iconv_open (codeset, codeset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_cnv_not_convert == INVALID_CONV) {
|
if (str_cnv_not_convert == INVALID_CONV)
|
||||||
|
{
|
||||||
g_free (codeset);
|
g_free (codeset);
|
||||||
codeset = g_strdup ("ascii");
|
codeset = g_strdup ("ascii");
|
||||||
str_cnv_not_convert = iconv_open (codeset, codeset);
|
str_cnv_not_convert = iconv_open (codeset, codeset);
|
||||||
@ -436,26 +370,9 @@ str_init_strings (const char *termenc)
|
|||||||
str_choose_str_functions ();
|
str_choose_str_functions ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
str_release_buffer_list ()
|
|
||||||
{
|
|
||||||
struct str_buffer *buffer;
|
|
||||||
struct str_buffer *next;
|
|
||||||
|
|
||||||
buffer = buffer_list;
|
|
||||||
while (buffer != NULL) {
|
|
||||||
next = buffer->next;
|
|
||||||
g_free (buffer->data);
|
|
||||||
g_free (buffer);
|
|
||||||
buffer = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
str_uninit_strings ()
|
str_uninit_strings ()
|
||||||
{
|
{
|
||||||
str_release_buffer_list ();
|
|
||||||
|
|
||||||
iconv_close (str_cnv_not_convert);
|
iconv_close (str_cnv_not_convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,4 +739,3 @@ str_release_key (char *key, int case_sen)
|
|||||||
{
|
{
|
||||||
used_class.release_key (key, case_sen);
|
used_class.release_key (key, case_sen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,29 +74,11 @@ extern str_conv_t str_cnv_from_term;
|
|||||||
// from terminal encoding to terminal encoding
|
// from terminal encoding to terminal encoding
|
||||||
extern str_conv_t str_cnv_not_convert;
|
extern str_conv_t str_cnv_not_convert;
|
||||||
|
|
||||||
/* structure for growing strings
|
|
||||||
* try to avoid set any members manually
|
|
||||||
*/
|
|
||||||
struct str_buffer {
|
|
||||||
// all buffers are stored in linked list
|
|
||||||
struct str_buffer *next;
|
|
||||||
// if is buffer in use or not
|
|
||||||
int used;
|
|
||||||
// whole string
|
|
||||||
char *data;
|
|
||||||
// size of string
|
|
||||||
size_t size;
|
|
||||||
// end of string, actual[0] is always '\0'
|
|
||||||
char *actual;
|
|
||||||
// how many (chars)bytes remain after actual
|
|
||||||
size_t remain;
|
|
||||||
};
|
|
||||||
|
|
||||||
// all functions in str_class must be defined for every encoding
|
// all functions in str_class must be defined for every encoding
|
||||||
struct str_class {
|
struct str_class {
|
||||||
int (*vfs_convert_to) (str_conv_t coder, const char *string,
|
int (*vfs_convert_to) (str_conv_t coder, const char *string,
|
||||||
int size, struct str_buffer *buffer); //I
|
int size, GString *buffer); //I
|
||||||
void (*insert_replace_char) (struct str_buffer *buffer);
|
void (*insert_replace_char) (GString *buffer);
|
||||||
int (*is_valid_string) (const char *); //I
|
int (*is_valid_string) (const char *); //I
|
||||||
int (*is_valid_char) (const char *, size_t); //I
|
int (*is_valid_char) (const char *, size_t); //I
|
||||||
void (*cnext_char) (const char **);
|
void (*cnext_char) (const char **);
|
||||||
@ -151,84 +133,51 @@ struct str_class str_ascii_init ();
|
|||||||
/* create convertor from "from_enc" to terminal encoding
|
/* create convertor from "from_enc" to terminal encoding
|
||||||
* if "from_enc" is not supported return INVALID_CONV
|
* if "from_enc" is not supported return INVALID_CONV
|
||||||
*/
|
*/
|
||||||
str_conv_t str_crt_conv_from (const char *from_enc);
|
GIConv str_crt_conv_from (const char *);
|
||||||
|
|
||||||
/* create convertor from terminal encoding to "to_enc"
|
/* create convertor from terminal encoding to "to_enc"
|
||||||
* if "to_enc" is not supported return INVALID_CONV
|
* if "to_enc" is not supported return INVALID_CONV
|
||||||
*/
|
*/
|
||||||
str_conv_t str_crt_conv_to (const char *to_enc);
|
GIConv str_crt_conv_to (const char *);
|
||||||
|
|
||||||
/* close convertor, do not close str_cnv_to_term, str_cnv_from_term,
|
/* close convertor, do not close str_cnv_to_term, str_cnv_from_term,
|
||||||
* str_cnv_not_convert
|
* str_cnv_not_convert
|
||||||
*/
|
*/
|
||||||
void str_close_conv (str_conv_t conv);
|
void str_close_conv (GIConv);
|
||||||
|
|
||||||
/* return on of not used buffers (.used == 0) or create new
|
/* return on of not used buffers (.used == 0) or create new
|
||||||
* returned buffer has set .used to 1
|
* returned buffer has set .used to 1
|
||||||
*/
|
*/
|
||||||
struct str_buffer *str_get_buffer ();
|
|
||||||
|
|
||||||
/* clear buffer, in .data is empty string, .actual = .data, .remain = .size
|
|
||||||
* do not set .used
|
|
||||||
*/
|
|
||||||
void str_reset_buffer (struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* set .used of buffer to 0, so can be returned by str_get_buffer again
|
|
||||||
* data in buffer may stay valid after function return
|
|
||||||
*/
|
|
||||||
void str_release_buffer (struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* incrase capacity of buffer
|
|
||||||
*/
|
|
||||||
void str_incrase_buffer (struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* convert string using coder, result of conversion is appended at end of buffer
|
/* convert string using coder, result of conversion is appended at end of buffer
|
||||||
* return 0 if there was no problem.
|
* return 0 if there was no problem.
|
||||||
* otherwise return ESTR_PROBLEM or ESTR_FAILURE
|
* otherwise return ESTR_PROBLEM or ESTR_FAILURE
|
||||||
*/
|
*/
|
||||||
int str_convert (str_conv_t coder, char *string,
|
int str_convert (GIConv, char *, GString *);
|
||||||
struct str_buffer *buffer);
|
|
||||||
|
int str_nconvert (GIConv, char *, int, GString *);
|
||||||
|
|
||||||
/* return only 0 or ESTR_FAILURE, because vfs must be able to convert result to
|
/* return only 0 or ESTR_FAILURE, because vfs must be able to convert result to
|
||||||
* original string. (so no replace with questionmark)
|
* original string. (so no replace with questionmark)
|
||||||
* if coder is str_cnv_from_term or str_cnv_not_convert, string is only copied,
|
* if coder is str_cnv_from_term or str_cnv_not_convert, string is only copied,
|
||||||
* so is possible to show file, that is not valid in terminal encoding
|
* so is possible to show file, that is not valid in terminal encoding
|
||||||
*/
|
*/
|
||||||
int str_vfs_convert_from (str_conv_t coder, char *string,
|
int str_vfs_convert_from (GIConv, char *, GString *);
|
||||||
struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* if coder is str_cnv_to_term or str_cnv_not_convert, string is only copied,
|
/* if coder is str_cnv_to_term or str_cnv_not_convert, string is only copied,
|
||||||
* does replace with questionmark
|
* does replace with questionmark
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
int str_vfs_convert_to (str_conv_t coder, const char *string,
|
int str_vfs_convert_to (GIConv, const char *, int, GString *);
|
||||||
int size, struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* append string at the end of buffer
|
|
||||||
*/
|
|
||||||
void str_insert_string (const char *string, struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* append string at the end of buffer, limit to size
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
str_insert_string2 (const char *string, int size, struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* printf functin for str_buffer, append result of printf at the end of buffer
|
/* printf functin for str_buffer, append result of printf at the end of buffer
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
str_printf (struct str_buffer *buffer, const char *format, ...);
|
str_printf (GString *, const char *, ...);
|
||||||
|
|
||||||
/* append char at the end of buffer
|
|
||||||
*/
|
|
||||||
void str_insert_char (char ch, struct str_buffer *buffer);
|
|
||||||
|
|
||||||
/* add standard replacement character in terminal encoding
|
/* add standard replacement character in terminal encoding
|
||||||
*/
|
*/
|
||||||
void str_insert_replace_char (struct str_buffer *buffer);
|
void str_insert_replace_char (GString *);
|
||||||
|
|
||||||
/* rewind "count" characters buffer back
|
|
||||||
*/
|
|
||||||
void str_backward_buffer (struct str_buffer *buffer, int count);
|
|
||||||
|
|
||||||
/* init strings and set terminal encoding,
|
/* init strings and set terminal encoding,
|
||||||
* if is termenc NULL, detect terminal encoding
|
* if is termenc NULL, detect terminal encoding
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
static const char replch = '?';
|
static const char replch = '?';
|
||||||
|
|
||||||
static void
|
static void
|
||||||
str_8bit_insert_replace_char (struct str_buffer *buffer)
|
str_8bit_insert_replace_char (GString * buffer)
|
||||||
{
|
{
|
||||||
str_insert_char (replch, buffer);
|
g_string_append_c (buffer, replch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -72,19 +72,25 @@ str_8bit_cprev_char (const char **text)
|
|||||||
static int
|
static int
|
||||||
str_8bit_cnext_noncomb_char (const char **text)
|
str_8bit_cnext_noncomb_char (const char **text)
|
||||||
{
|
{
|
||||||
if (*text[0] != '\0') {
|
if (*text[0] != '\0')
|
||||||
|
{
|
||||||
(*text)++;
|
(*text)++;
|
||||||
return 1;
|
return 1;
|
||||||
} else return 0;
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
str_8bit_cprev_noncomb_char (const char **text, const char *begin)
|
str_8bit_cprev_noncomb_char (const char **text, const char *begin)
|
||||||
{
|
{
|
||||||
if ((*text) != begin) {
|
if ((*text) != begin)
|
||||||
|
{
|
||||||
(*text)--;
|
(*text)--;
|
||||||
return 1;
|
return 1;
|
||||||
} else return 0;
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -126,7 +132,8 @@ str_8bit_iscombiningmark (const char *text)
|
|||||||
static int
|
static int
|
||||||
str_8bit_toupper (const char *text, char **out, size_t * remain)
|
str_8bit_toupper (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1) return 0;
|
if (*remain <= 1)
|
||||||
|
return 0;
|
||||||
(*out)[0] = toupper ((unsigned char) text[0]);
|
(*out)[0] = toupper ((unsigned char) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -136,7 +143,8 @@ str_8bit_toupper (const char *text, char **out, size_t *remain)
|
|||||||
static int
|
static int
|
||||||
str_8bit_tolower (const char *text, char **out, size_t * remain)
|
str_8bit_tolower (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1) return 0;
|
if (*remain <= 1)
|
||||||
|
return 0;
|
||||||
(*out)[0] = tolower ((unsigned char) text[0]);
|
(*out)[0] = tolower ((unsigned char) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -155,57 +163,19 @@ str_8bit_length2 (const char *text, int size)
|
|||||||
return (size >= 0) ? min (strlen (text), size) : strlen (text);
|
return (size >= 0) ? min (strlen (text), size) : strlen (text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
_str_8bit_vfs_convert_to (str_conv_t coder, char *string,
|
|
||||||
int size, struct str_buffer *buffer)
|
|
||||||
{
|
|
||||||
int state;
|
|
||||||
size_t left;
|
|
||||||
size_t nconv;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
|
|
||||||
state = 0;
|
|
||||||
|
|
||||||
left = (size >= 0) ? size : strlen (string);
|
|
||||||
|
|
||||||
if (coder == (iconv_t) (-1)) return ESTR_FAILURE;
|
|
||||||
|
|
||||||
iconv(coder, NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
while (((int)left) > 0) {
|
|
||||||
nconv = iconv(coder, &string, &left,
|
|
||||||
&(buffer->actual), &(buffer->remain));
|
|
||||||
if (nconv == (size_t) (-1)) {
|
|
||||||
switch (errno) {
|
|
||||||
case EINVAL:
|
|
||||||
return ESTR_FAILURE;
|
|
||||||
case EILSEQ:
|
|
||||||
string++;
|
|
||||||
left--;
|
|
||||||
str_insert_char ('?', buffer);
|
|
||||||
state = ESTR_PROBLEM;
|
|
||||||
break;
|
|
||||||
case E2BIG:
|
|
||||||
str_incrase_buffer (buffer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
str_8bit_vfs_convert_to (str_conv_t coder, const char *string,
|
str_8bit_vfs_convert_to (str_conv_t coder, const char *string,
|
||||||
int size, struct str_buffer *buffer)
|
int size, GString * buffer)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (coder == str_cnv_not_convert) {
|
if (coder == str_cnv_not_convert)
|
||||||
str_insert_string2 (string, size, buffer);
|
{
|
||||||
|
g_string_append_len (buffer, string, size);
|
||||||
result = 0;
|
result = 0;
|
||||||
} else result = _str_8bit_vfs_convert_to (coder, (char*)string, size, buffer);
|
}
|
||||||
buffer->actual[0] = '\0';
|
else
|
||||||
|
result = str_nconvert (coder, (char *) string, size, buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -224,7 +194,8 @@ str_8bit_term_form (const char *text)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,9 +217,11 @@ str_8bit_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (length <= width) {
|
if (length <= width)
|
||||||
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode)) {
|
switch (HIDE_FIT (just_mode))
|
||||||
|
{
|
||||||
case J_CENTER_LEFT:
|
case J_CENTER_LEFT:
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (width - length) / 2;
|
ident = (width - length) / 2;
|
||||||
@ -258,41 +231,54 @@ str_8bit_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= ident) goto finally;
|
if (remain <= ident)
|
||||||
|
goto finally;
|
||||||
memset (actual, ' ', ident);
|
memset (actual, ' ', ident);
|
||||||
actual += ident;
|
actual += ident;
|
||||||
remain -= ident;
|
remain -= ident;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
if (width - length - ident > 0) {
|
if (width - length - ident > 0)
|
||||||
if (remain <= width - length - ident) goto finally;
|
{
|
||||||
|
if (remain <= width - length - ident)
|
||||||
|
goto finally;
|
||||||
memset (actual, ' ', width - length - ident);
|
memset (actual, ' ', width - length - ident);
|
||||||
actual += width - length - ident;
|
actual += width - length - ident;
|
||||||
remain -= width - length - ident;
|
remain -= width - length - ident;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (IS_FIT (just_mode)) {
|
else
|
||||||
|
{
|
||||||
|
if (IS_FIT (just_mode))
|
||||||
|
{
|
||||||
for (; pos + 1 <= width / 2 && remain > 1;
|
for (; pos + 1 <= width / 2 && remain > 1;
|
||||||
actual++, pos++, remain--) {
|
actual++, pos++, remain--)
|
||||||
|
{
|
||||||
|
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1) goto finally;
|
if (remain <= 1)
|
||||||
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode)) {
|
switch (HIDE_FIT (just_mode))
|
||||||
|
{
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (length - width) / 2;
|
ident = (length - width) / 2;
|
||||||
break;
|
break;
|
||||||
@ -303,7 +289,8 @@ str_8bit_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
|
|
||||||
pos += ident;
|
pos += ident;
|
||||||
for (; pos < ident + width && remain > 1;
|
for (; pos < ident + width && remain > 1;
|
||||||
pos++, actual++, remain--) {
|
pos++, actual++, remain--)
|
||||||
|
{
|
||||||
|
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
@ -328,24 +315,32 @@ str_8bit_term_trim (const char *text, int width)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (width < length) {
|
if (width < length)
|
||||||
if (width <= 3) {
|
{
|
||||||
|
if (width <= 3)
|
||||||
|
{
|
||||||
memset (actual, '.', width);
|
memset (actual, '.', width);
|
||||||
actual += width;
|
actual += width;
|
||||||
remain -= width;
|
remain -= width;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memset (actual, '.', 3);
|
memset (actual, '.', 3);
|
||||||
actual += 3;
|
actual += 3;
|
||||||
remain -= 3;
|
remain -= 3;
|
||||||
|
|
||||||
pos += length - width + 3;
|
pos += length - width + 3;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
else
|
||||||
|
{
|
||||||
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,8 +353,7 @@ static int
|
|||||||
str_8bit_term_width2 (const char *text, size_t length)
|
str_8bit_term_width2 (const char *text, size_t length)
|
||||||
{
|
{
|
||||||
return (length != (size_t) (-1))
|
return (length != (size_t) (-1))
|
||||||
? min (strlen (text), length)
|
? min (strlen (text), length) : strlen (text);
|
||||||
: strlen (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -386,15 +380,18 @@ str_8bit_msg_term_size (const char *text, int *lines, int *columns)
|
|||||||
int width;
|
int width;
|
||||||
p = tmp;
|
p = tmp;
|
||||||
|
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
q = strchr (p, '\n');
|
q = strchr (p, '\n');
|
||||||
if (q != NULL) {
|
if (q != NULL)
|
||||||
|
{
|
||||||
c = q[0];
|
c = q[0];
|
||||||
q[0] = '\0';
|
q[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
width = str_8bit_term_width1 (p);
|
width = str_8bit_term_width1 (p);
|
||||||
if (width > (*columns)) (*columns) = width;
|
if (width > (*columns))
|
||||||
|
(*columns) = width;
|
||||||
|
|
||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
break;
|
break;
|
||||||
@ -418,16 +415,19 @@ str_8bit_term_substring (const char *text, int start, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (start < length) {
|
if (start < length)
|
||||||
|
{
|
||||||
pos += start;
|
pos += start;
|
||||||
for (; pos < length && width > 0 && remain > 1;
|
for (; pos < length && width > 0 && remain > 1;
|
||||||
pos++, width--, actual++, remain--) {
|
pos++, width--, actual++, remain--)
|
||||||
|
{
|
||||||
|
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; width > 0 && remain > 1; actual++, remain--, width--) {
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
||||||
|
{
|
||||||
actual[0] = ' ';
|
actual[0] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,23 +448,30 @@ str_8bit_trunc (const char *text, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (length > width) {
|
if (length > width)
|
||||||
for (; pos + 1 <= width / 2 && remain > 1; actual++, pos++, remain--) {
|
{
|
||||||
|
for (; pos + 1 <= width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1) goto finally;
|
if (remain <= 1)
|
||||||
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
else
|
||||||
|
{
|
||||||
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,12 +516,14 @@ str_8bit_search_first (const char *text, const char *search, int case_sen)
|
|||||||
fold_search = (case_sen) ? (char *) text : g_strdown (g_strdup (search));
|
fold_search = (case_sen) ? (char *) text : g_strdown (g_strdup (search));
|
||||||
|
|
||||||
match = g_strstr_len (fold_text, -1, fold_search);
|
match = g_strstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL) {
|
if (match != NULL)
|
||||||
|
{
|
||||||
offsset = match - fold_text;
|
offsset = match - fold_text;
|
||||||
match = text + offsset;
|
match = text + offsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen) {
|
if (!case_sen)
|
||||||
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
@ -534,12 +543,14 @@ str_8bit_search_last (const char *text, const char *search, int case_sen)
|
|||||||
fold_search = (case_sen) ? (char *) text : g_strdown (g_strdup (search));
|
fold_search = (case_sen) ? (char *) text : g_strdown (g_strdup (search));
|
||||||
|
|
||||||
match = g_strrstr_len (fold_text, -1, fold_search);
|
match = g_strrstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL) {
|
if (match != NULL)
|
||||||
|
{
|
||||||
offsset = match - fold_text;
|
offsset = match - fold_text;
|
||||||
match = text + offsset;
|
match = text + offsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen) {
|
if (!case_sen)
|
||||||
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
@ -585,8 +596,7 @@ str_8bit_caseprefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& toupper (text[result]) == toupper (prefix[result]);
|
&& toupper (text[result]) == toupper (prefix[result]); result++);
|
||||||
result++);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,14 +616,17 @@ str_8bit_create_key (const char *text, int case_sen)
|
|||||||
static int
|
static int
|
||||||
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
|
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
|
||||||
{
|
{
|
||||||
if (case_sen) return strcmp (t1, t2);
|
if (case_sen)
|
||||||
else return strcoll (t1, t2);
|
return strcmp (t1, t2);
|
||||||
|
else
|
||||||
|
return strcoll (t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
str_8bit_release_key (char *key, int case_sen)
|
str_8bit_release_key (char *key, int case_sen)
|
||||||
{
|
{
|
||||||
if (!case_sen) g_free (key);
|
if (!case_sen)
|
||||||
|
g_free (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_class
|
struct str_class
|
||||||
|
@ -38,9 +38,9 @@
|
|||||||
static const char replch = '?';
|
static const char replch = '?';
|
||||||
|
|
||||||
static void
|
static void
|
||||||
str_ascii_insert_replace_char (struct str_buffer *buffer)
|
str_ascii_insert_replace_char (GString * buffer)
|
||||||
{
|
{
|
||||||
str_insert_char (replch, buffer);
|
g_string_append_c (buffer, replch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -70,19 +70,25 @@ str_ascii_cprev_char (const char **text)
|
|||||||
static int
|
static int
|
||||||
str_ascii_cnext_noncomb_char (const char **text)
|
str_ascii_cnext_noncomb_char (const char **text)
|
||||||
{
|
{
|
||||||
if (*text[0] != '\0') {
|
if (*text[0] != '\0')
|
||||||
|
{
|
||||||
(*text)++;
|
(*text)++;
|
||||||
return 1;
|
return 1;
|
||||||
} else return 0;
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
str_ascii_cprev_noncomb_char (const char **text, const char *begin)
|
str_ascii_cprev_noncomb_char (const char **text, const char *begin)
|
||||||
{
|
{
|
||||||
if ((*text) != begin) {
|
if ((*text) != begin)
|
||||||
|
{
|
||||||
(*text)--;
|
(*text)--;
|
||||||
return 1;
|
return 1;
|
||||||
} else return 0;
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -124,7 +130,8 @@ str_ascii_iscombiningmark (const char *text)
|
|||||||
static int
|
static int
|
||||||
str_ascii_toupper (const char *text, char **out, size_t * remain)
|
str_ascii_toupper (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1) return 0;
|
if (*remain <= 1)
|
||||||
|
return 0;
|
||||||
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
|
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -134,7 +141,8 @@ str_ascii_toupper (const char *text, char **out, size_t *remain)
|
|||||||
static int
|
static int
|
||||||
str_ascii_tolower (const char *text, char **out, size_t * remain)
|
str_ascii_tolower (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1) return 0;
|
if (*remain <= 1)
|
||||||
|
return 0;
|
||||||
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
|
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -154,10 +162,10 @@ str_ascii_length2 (const char *text, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
str_ascii_vfs_convert_to (str_conv_t coder, const char *string,
|
str_ascii_vfs_convert_to (GIConv coder, const char *string,
|
||||||
int size, struct str_buffer *buffer)
|
int size, GString * buffer)
|
||||||
{
|
{
|
||||||
str_insert_string2 (string, size, buffer);
|
g_string_append_len (buffer, string, size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +184,8 @@ str_ascii_term_form (const char *text)
|
|||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
/* go throw all characters and check, if they are ascii and printable */
|
/* go throw all characters and check, if they are ascii and printable */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
@ -199,9 +208,11 @@ str_ascii_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (length <= width) {
|
if (length <= width)
|
||||||
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode)) {
|
switch (HIDE_FIT (just_mode))
|
||||||
|
{
|
||||||
case J_CENTER_LEFT:
|
case J_CENTER_LEFT:
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (width - length) / 2;
|
ident = (width - length) / 2;
|
||||||
@ -212,36 +223,45 @@ str_ascii_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add space before text */
|
/* add space before text */
|
||||||
if (remain <= ident) goto finally;
|
if (remain <= ident)
|
||||||
|
goto finally;
|
||||||
memset (actual, ' ', ident);
|
memset (actual, ' ', ident);
|
||||||
actual += ident;
|
actual += ident;
|
||||||
remain -= ident;
|
remain -= ident;
|
||||||
|
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add space after text */
|
/* add space after text */
|
||||||
if (width - length - ident > 0) {
|
if (width - length - ident > 0)
|
||||||
if (remain <= width - length - ident) goto finally;
|
{
|
||||||
|
if (remain <= width - length - ident)
|
||||||
|
goto finally;
|
||||||
memset (actual, ' ', width - length - ident);
|
memset (actual, ' ', width - length - ident);
|
||||||
actual += width - length - ident;
|
actual += width - length - ident;
|
||||||
remain -= width - length - ident;
|
remain -= width - length - ident;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (IS_FIT (just_mode)) {
|
else
|
||||||
|
{
|
||||||
|
if (IS_FIT (just_mode))
|
||||||
|
{
|
||||||
/* copy prefix of text, that is not wider than width / 2 */
|
/* copy prefix of text, that is not wider than width / 2 */
|
||||||
for (; pos + 1 <= width / 2 && remain > 1;
|
for (; pos + 1 <= width / 2 && remain > 1;
|
||||||
actual++, pos++, remain--) {
|
actual++, pos++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos])
|
||||||
? text[pos] : '?';
|
? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||||
? actual[0] : '.';
|
? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1) goto finally;
|
if (remain <= 1)
|
||||||
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
@ -249,15 +269,19 @@ str_ascii_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos])
|
||||||
? text[pos] : '?';
|
? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||||
? actual[0] : '.';
|
? actual[0] : '.';
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode)) {
|
switch (HIDE_FIT (just_mode))
|
||||||
|
{
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (length - width) / 2;
|
ident = (length - width) / 2;
|
||||||
break;
|
break;
|
||||||
@ -270,7 +294,8 @@ str_ascii_fit_to_term (const char *text, int width, int just_mode)
|
|||||||
* characters from text */
|
* characters from text */
|
||||||
pos += ident;
|
pos += ident;
|
||||||
for (; pos < ident + width && remain > 1;
|
for (; pos < ident + width && remain > 1;
|
||||||
pos++, actual++, remain--) {
|
pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos])
|
||||||
? text[pos] : '?';
|
? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||||
@ -297,12 +322,16 @@ str_ascii_term_trim (const char *text, int width)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (width < length) {
|
if (width < length)
|
||||||
if (width <= 3) {
|
{
|
||||||
|
if (width <= 3)
|
||||||
|
{
|
||||||
memset (actual, '.', width);
|
memset (actual, '.', width);
|
||||||
actual += width;
|
actual += width;
|
||||||
remain -= width;
|
remain -= width;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
memset (actual, '.', 3);
|
memset (actual, '.', 3);
|
||||||
actual += 3;
|
actual += 3;
|
||||||
remain -= 3;
|
remain -= 3;
|
||||||
@ -310,16 +339,20 @@ str_ascii_term_trim (const char *text, int width)
|
|||||||
pos += length - width + 3;
|
pos += length - width + 3;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos])
|
||||||
? text[pos] : '?';
|
? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||||
? actual[0] : '.';
|
? actual[0] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
@ -333,8 +366,7 @@ static int
|
|||||||
str_ascii_term_width2 (const char *text, size_t length)
|
str_ascii_term_width2 (const char *text, size_t length)
|
||||||
{
|
{
|
||||||
return (length != (size_t) (-1))
|
return (length != (size_t) (-1))
|
||||||
? min (strlen (text), length)
|
? min (strlen (text), length) : strlen (text);
|
||||||
: strlen (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -361,15 +393,18 @@ str_ascii_msg_term_size (const char *text, int *lines, int *columns)
|
|||||||
int width;
|
int width;
|
||||||
p = tmp;
|
p = tmp;
|
||||||
|
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
q = strchr (p, '\n');
|
q = strchr (p, '\n');
|
||||||
if (q != NULL) {
|
if (q != NULL)
|
||||||
|
{
|
||||||
c = q[0];
|
c = q[0];
|
||||||
q[0] = '\0';
|
q[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
width = str_ascii_term_width1 (p);
|
width = str_ascii_term_width1 (p);
|
||||||
if (width > (*columns)) (*columns) = width;
|
if (width > (*columns))
|
||||||
|
(*columns) = width;
|
||||||
|
|
||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
break;
|
break;
|
||||||
@ -393,11 +428,13 @@ str_ascii_term_substring (const char *text, int start, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (start < length) {
|
if (start < length)
|
||||||
|
{
|
||||||
pos += start;
|
pos += start;
|
||||||
/* copy at most width characters from text from start */
|
/* copy at most width characters from text from start */
|
||||||
for (; pos < length && width > 0 && remain > 1;
|
for (; pos < length && width > 0 && remain > 1;
|
||||||
pos++, width--, actual++, remain--) {
|
pos++, width--, actual++, remain--)
|
||||||
|
{
|
||||||
|
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
@ -405,7 +442,8 @@ str_ascii_term_substring (const char *text, int start, int width)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if text is shorter then width, add space to the end */
|
/* if text is shorter then width, add space to the end */
|
||||||
for (; width > 0 && remain > 1; actual++, remain--, width--) {
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
||||||
|
{
|
||||||
actual[0] = ' ';
|
actual[0] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,14 +464,17 @@ str_ascii_trunc (const char *text, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (length > width) {
|
if (length > width)
|
||||||
|
{
|
||||||
/* copy prefix of text */
|
/* copy prefix of text */
|
||||||
for (; pos + 1 <= width / 2 && remain > 1; actual++, pos++, remain--) {
|
for (; pos + 1 <= width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1) goto finally;
|
if (remain <= 1)
|
||||||
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
@ -441,13 +482,17 @@ str_ascii_trunc (const char *text, int width)
|
|||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--) {
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
@ -493,12 +538,14 @@ str_ascii_search_first (const char *text, const char *search, int case_sen)
|
|||||||
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
|
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
|
||||||
|
|
||||||
match = g_strstr_len (fold_text, -1, fold_search);
|
match = g_strstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL) {
|
if (match != NULL)
|
||||||
|
{
|
||||||
offset = match - fold_text;
|
offset = match - fold_text;
|
||||||
match = text + offset;
|
match = text + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen) {
|
if (!case_sen)
|
||||||
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
@ -518,12 +565,14 @@ str_ascii_search_last (const char *text, const char *search, int case_sen)
|
|||||||
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
|
fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1);
|
||||||
|
|
||||||
match = g_strrstr_len (fold_text, -1, fold_search);
|
match = g_strrstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL) {
|
if (match != NULL)
|
||||||
|
{
|
||||||
offset = match - fold_text;
|
offset = match - fold_text;
|
||||||
match = text + offset;
|
match = text + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen) {
|
if (!case_sen)
|
||||||
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
@ -558,7 +607,8 @@ str_ascii_ncasecmp (const char *t1, const char *t2)
|
|||||||
static void
|
static void
|
||||||
str_ascii_fix_string (char *text)
|
str_ascii_fix_string (char *text)
|
||||||
{
|
{
|
||||||
for (; text[0] != '\0'; text++) {
|
for (; text[0] != '\0'; text++)
|
||||||
|
{
|
||||||
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
|
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,8 +644,8 @@ str_ascii_caseprefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& g_ascii_toupper (text[result]) == g_ascii_toupper (prefix[result]);
|
&& g_ascii_toupper (text[result]) ==
|
||||||
result++);
|
g_ascii_toupper (prefix[result]); result++);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
33
src/view.c
33
src/view.c
@ -235,7 +235,7 @@ struct WView {
|
|||||||
* used for both normal adn nroff mode */
|
* used for both normal adn nroff mode */
|
||||||
struct cache_line *first_showed_line;
|
struct cache_line *first_showed_line;
|
||||||
/* converter for translation of text */
|
/* converter for translation of text */
|
||||||
str_conv_t converter;
|
GIConv converter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -2458,18 +2458,18 @@ view_display_text (WView * view)
|
|||||||
addch ('.');
|
addch ('.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
struct str_buffer *comb = str_get_buffer ();
|
GString *comb = g_string_new ("");
|
||||||
if (str_isprint (info.cact)) {
|
if (str_isprint (info.cact)) {
|
||||||
str_insert_string (info.cact, comb);
|
g_string_append(comb,info.cact);
|
||||||
} else {
|
} else {
|
||||||
str_insert_string (".", comb);
|
g_string_append(comb,".");
|
||||||
}
|
}
|
||||||
while (str_iscombiningmark (info.cnxt)) {
|
while (str_iscombiningmark (info.cnxt)) {
|
||||||
view_read_continue (view, &info);
|
view_read_continue (view, &info);
|
||||||
str_insert_string (info.cact, comb);
|
g_string_append(comb,info.cact);
|
||||||
}
|
}
|
||||||
addstr (str_term_form (comb->data));
|
addstr (str_term_form (comb->str));
|
||||||
str_release_buffer (comb);
|
g_string_free (comb, TRUE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (str_iscombiningmark (info.cnxt)) {
|
while (str_iscombiningmark (info.cnxt)) {
|
||||||
@ -2731,7 +2731,7 @@ icase_search_p (WView *view, char *text, char *data, int nothing,
|
|||||||
|
|
||||||
/* read one whole line into buffer, return where line start and end */
|
/* read one whole line into buffer, return where line start and end */
|
||||||
static int
|
static int
|
||||||
view_get_line_at (WView *view, offset_type from, struct str_buffer * buffer,
|
view_get_line_at (WView *view, offset_type from, GString * buffer,
|
||||||
offset_type *buff_start, offset_type *buff_end)
|
offset_type *buff_start, offset_type *buff_end)
|
||||||
{
|
{
|
||||||
#define cmp(t1,t2) (strcmp((t1),(t2)) == 0)
|
#define cmp(t1,t2) (strcmp((t1),(t2)) == 0)
|
||||||
@ -2756,7 +2756,7 @@ view_get_line_at (WView *view, offset_type from, struct str_buffer * buffer,
|
|||||||
(*buff_start) = start;
|
(*buff_start) = start;
|
||||||
(*buff_end) = end;
|
(*buff_end) = end;
|
||||||
|
|
||||||
str_reset_buffer (buffer);
|
g_string_set_size(buffer,0);
|
||||||
|
|
||||||
view_read_start (view, &info, start);
|
view_read_start (view, &info, start);
|
||||||
while ((info.result != -1) && (info.next < end)) {
|
while ((info.result != -1) && (info.next < end)) {
|
||||||
@ -2766,7 +2766,7 @@ view_get_line_at (WView *view, offset_type from, struct str_buffer * buffer,
|
|||||||
if (cmp (info.cact, "")) {
|
if (cmp (info.cact, "")) {
|
||||||
if (info.actual < from) {
|
if (info.actual < from) {
|
||||||
/* '\0' before start offset, continue */
|
/* '\0' before start offset, continue */
|
||||||
str_reset_buffer (buffer);
|
g_string_set_size(buffer,0);
|
||||||
(*buff_start) = info.next;
|
(*buff_start) = info.next;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
@ -2780,11 +2780,12 @@ view_get_line_at (WView *view, offset_type from, struct str_buffer * buffer,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (view_read_test_nroff_back (view, &info)) {
|
if (view_read_test_nroff_back (view, &info)) {
|
||||||
str_backward_buffer (buffer, 1);
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
g_string_truncate (buffer, buffer->len-1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
str_insert_string (info.cact, buffer);
|
g_string_append(buffer,info.cact);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -2981,7 +2982,7 @@ static void
|
|||||||
view_search (WView *view, char *text,
|
view_search (WView *view, char *text,
|
||||||
int (*search) (WView *, char *, char *, int, size_t *, size_t *))
|
int (*search) (WView *, char *, char *, int, size_t *, size_t *))
|
||||||
{
|
{
|
||||||
struct str_buffer *buffer;
|
GString *buffer;
|
||||||
offset_type search_start;
|
offset_type search_start;
|
||||||
int search_status;
|
int search_status;
|
||||||
Dlg_head *d = 0;
|
Dlg_head *d = 0;
|
||||||
@ -2996,7 +2997,7 @@ view_search (WView *view, char *text,
|
|||||||
mc_refresh ();
|
mc_refresh ();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = str_get_buffer ();
|
buffer = g_string_new ("");
|
||||||
|
|
||||||
search_start = (view->direction != 1) ? view->search_start :
|
search_start = (view->direction != 1) ? view->search_start :
|
||||||
view->search_end;
|
view->search_end;
|
||||||
@ -3022,7 +3023,7 @@ view_search (WView *view, char *text,
|
|||||||
if (!view_get_line_at (view, search_start, buffer, &line_start, &line_end))
|
if (!view_get_line_at (view, search_start, buffer, &line_start, &line_end))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
search_status = (*search) (view, text, buffer->data, match_normal,
|
search_status = (*search) (view, text, buffer->str, match_normal,
|
||||||
&match_start, &match_end);
|
&match_start, &match_end);
|
||||||
|
|
||||||
if (search_status < 0) {
|
if (search_status < 0) {
|
||||||
@ -3058,7 +3059,7 @@ view_search (WView *view, char *text,
|
|||||||
message (D_NORMAL, _("Search"), _(" Search string not found "));
|
message (D_NORMAL, _("Search"), _(" Search string not found "));
|
||||||
view->search_end = view->search_start;
|
view->search_end = view->search_start;
|
||||||
}
|
}
|
||||||
str_release_buffer (buffer);
|
g_string_free (buffer, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search buffer (its size is len) in the complete buffer
|
/* Search buffer (its size is len) in the complete buffer
|
||||||
|
24
vfs/vfs.c
24
vfs/vfs.c
@ -75,7 +75,7 @@ static GSList *vfs_openfiles;
|
|||||||
#define VFS_FIRST_HANDLE 100
|
#define VFS_FIRST_HANDLE 100
|
||||||
|
|
||||||
static struct vfs_class *localfs_class;
|
static struct vfs_class *localfs_class;
|
||||||
static struct str_buffer *vfs_str_buffer;
|
static GString *vfs_str_buffer;
|
||||||
|
|
||||||
static const char *supported_encodings[] = {
|
static const char *supported_encodings[] = {
|
||||||
"UTF8",
|
"UTF8",
|
||||||
@ -383,7 +383,7 @@ vfs_supported_enconding (const char *encoding) {
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
_vfs_translate_path (const char *path, int size,
|
_vfs_translate_path (const char *path, int size,
|
||||||
str_conv_t defcnv, struct str_buffer *buffer)
|
str_conv_t defcnv, GString *buffer)
|
||||||
{
|
{
|
||||||
const char *semi;
|
const char *semi;
|
||||||
const char *ps;
|
const char *ps;
|
||||||
@ -430,9 +430,9 @@ _vfs_translate_path (const char *path, int size,
|
|||||||
if (slash != NULL) {
|
if (slash != NULL) {
|
||||||
state = str_vfs_convert_to (coder, slash,
|
state = str_vfs_convert_to (coder, slash,
|
||||||
path + size - slash, buffer);
|
path + size - slash, buffer);
|
||||||
} else if (buffer->data[0] == '\0') {
|
} else if (buffer->str[0] == '\0') {
|
||||||
/* exmaple "/#enc:utf-8" */
|
/* exmaple "/#enc:utf-8" */
|
||||||
str_insert_char (PATH_SEP, buffer);
|
g_string_append_c(buffer, PATH_SEP);
|
||||||
}
|
}
|
||||||
str_close_conv (coder);
|
str_close_conv (coder);
|
||||||
return state;
|
return state;
|
||||||
@ -460,11 +460,11 @@ vfs_translate_path (const char *path)
|
|||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
str_reset_buffer (vfs_str_buffer);
|
g_string_set_size(vfs_str_buffer,0);
|
||||||
state = _vfs_translate_path (path, -1, str_cnv_from_term, vfs_str_buffer);
|
state = _vfs_translate_path (path, -1, str_cnv_from_term, vfs_str_buffer);
|
||||||
// strict version
|
// strict version
|
||||||
//return (state == 0) ? vfs_str_buffer->data : NULL;
|
//return (state == 0) ? vfs_str_buffer->data : NULL;
|
||||||
return (state != ESTR_FAILURE) ? vfs_str_buffer->data : NULL;
|
return (state != ESTR_FAILURE) ? vfs_str_buffer->str : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -753,12 +753,12 @@ mc_readdir (DIR *dirp)
|
|||||||
do {
|
do {
|
||||||
entry = (*vfs->readdir) (dirinfo->info);
|
entry = (*vfs->readdir) (dirinfo->info);
|
||||||
if (entry == NULL) return NULL;
|
if (entry == NULL) return NULL;
|
||||||
str_reset_buffer (vfs_str_buffer);
|
g_string_set_size(vfs_str_buffer,0);
|
||||||
state = str_vfs_convert_from (dirinfo->converter,
|
state = str_vfs_convert_from (dirinfo->converter,
|
||||||
entry->d_name, vfs_str_buffer);
|
entry->d_name, vfs_str_buffer);
|
||||||
} while (state != 0);
|
} while (state != 0);
|
||||||
memcpy (&result, entry, sizeof (struct dirent));
|
memcpy (&result, entry, sizeof (struct dirent));
|
||||||
g_strlcpy (result.d_name, vfs_str_buffer->data, NAME_MAX + 1);
|
g_strlcpy (result.d_name, vfs_str_buffer->str, NAME_MAX + 1);
|
||||||
result.d_reclen = strlen (result.d_name);
|
result.d_reclen = strlen (result.d_name);
|
||||||
}
|
}
|
||||||
if (entry == NULL) errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
|
if (entry == NULL) errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
|
||||||
@ -854,10 +854,10 @@ _vfs_get_cwd (void)
|
|||||||
if (encoding == NULL) {
|
if (encoding == NULL) {
|
||||||
tmp = g_get_current_dir ();
|
tmp = g_get_current_dir ();
|
||||||
if (tmp != NULL) { /* One of the directories in the path is not readable */
|
if (tmp != NULL) { /* One of the directories in the path is not readable */
|
||||||
str_reset_buffer (vfs_str_buffer);
|
g_string_set_size(vfs_str_buffer,0);
|
||||||
state = str_vfs_convert_from (str_cnv_from_term, tmp, vfs_str_buffer);
|
state = str_vfs_convert_from (str_cnv_from_term, tmp, vfs_str_buffer);
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
sys_cwd = (state == 0) ? g_strdup (vfs_str_buffer->data) : NULL;
|
sys_cwd = (state == 0) ? g_strdup (vfs_str_buffer->str) : NULL;
|
||||||
if (!sys_cwd)
|
if (!sys_cwd)
|
||||||
return current_dir;
|
return current_dir;
|
||||||
|
|
||||||
@ -1174,7 +1174,7 @@ mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
|
|||||||
void
|
void
|
||||||
vfs_init (void)
|
vfs_init (void)
|
||||||
{
|
{
|
||||||
vfs_str_buffer = str_get_buffer ();
|
vfs_str_buffer = g_string_new("");
|
||||||
/* localfs needs to be the first one */
|
/* localfs needs to be the first one */
|
||||||
init_localfs();
|
init_localfs();
|
||||||
/* fallback value for vfs_get_class() */
|
/* fallback value for vfs_get_class() */
|
||||||
@ -1219,7 +1219,7 @@ vfs_shut (void)
|
|||||||
|
|
||||||
g_slist_free (vfs_openfiles);
|
g_slist_free (vfs_openfiles);
|
||||||
|
|
||||||
str_release_buffer (vfs_str_buffer);
|
g_string_free (vfs_str_buffer, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user