patches by Rostislav Beneš: mc-28-fix

rest of fixes in files cmc.c, main.c (xterm title), panelize.c, subshell.c,
tree.c, tty.c, user.c, util.c, win.c

now, basic mc's function should work well, editor and view are still broken.
This commit is contained in:
Slava Zanko 2008-12-29 01:53:08 +02:00
parent 753f65c242
commit 75cf62902d
9 changed files with 84 additions and 91 deletions

View File

@ -973,7 +973,7 @@ void edit_symlink_cmd (void)
p = selection (current_panel)->fname; p = selection (current_panel)->fname;
q = g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p, 32)); q = g_strdup_printf (_(" Symlink `%s\' points to: "), str_trunc (p, 32));
i = readlink (p, buffer, MC_MAXPATHLEN - 1); i = readlink (p, buffer, MC_MAXPATHLEN - 1);
if (i > 0) { if (i > 0) {

View File

@ -706,7 +706,7 @@ load_prompt (int fd, void *unused)
int prompt_len; int prompt_len;
tmp_prompt = strip_ctrl_codes (subshell_prompt); tmp_prompt = strip_ctrl_codes (subshell_prompt);
prompt_len = strlen (tmp_prompt); prompt_len = str_term_width1 (tmp_prompt);
/* Check for prompts too big */ /* Check for prompts too big */
if (COLS > 8 && prompt_len > COLS - 8) { if (COLS > 8 && prompt_len > COLS - 8) {
@ -1607,17 +1607,12 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
void void
update_xterm_title_path (void) update_xterm_title_path (void)
{ {
char *p, *s; const char *p;
if (xterm_flag && xterm_title) { if (xterm_flag && xterm_title) {
p = s = g_strdup (strip_home_and_password (current_panel->cwd)); p = strip_home_and_password (current_panel->cwd);
do { fprintf (stdout, "\33]0;mc - %s\7", str_term_form (p));
if (!is_printable ((unsigned char) *s))
*s = '?';
} while (*++s);
fprintf (stdout, "\33]0;mc - %s\7", p);
fflush (stdout); fflush (stdout);
g_free (p);
} }
} }
@ -2065,7 +2060,7 @@ handle_args (int argc, char *argv[])
char *end = tmp + strlen (tmp), *p = end; char *end = tmp + strlen (tmp), *p = end;
if (p > tmp && p[-1] == ':') if (p > tmp && p[-1] == ':')
p--; p--;
while (p > tmp && isdigit ((unsigned char) p[-1])) while (p > tmp && g_ascii_isdigit ((gchar) p[-1]))
p--; p--;
if (tmp < p && p < end && p[-1] == ':') { if (tmp < p && p < end && p[-1] == ':') {
struct stat st; struct stat st;
@ -2083,7 +2078,7 @@ handle_args (int argc, char *argv[])
} }
} else { } else {
try_plus_filename: try_plus_filename:
if (*tmp == '+' && isdigit ((unsigned char) tmp[1])) { if (*tmp == '+' && g_ascii_isdigit ((gchar) tmp[1])) {
int start_line = atoi (tmp); int start_line = atoi (tmp);
if (start_line > 0) { if (start_line > 0) {
char *file = poptGetArg (ctx); char *file = poptGetArg (ctx);

View File

@ -44,6 +44,7 @@
#include "main.h" /* repaint_screen */ #include "main.h" /* repaint_screen */
#include "panelize.h" #include "panelize.h"
#include "history.h" #include "history.h"
#include "strutil.h"
#define UX 5 #define UX 5
#define UY 2 #define UY 2
@ -129,7 +130,7 @@ init_panelize (void)
i = sizeof (panelize_but) / sizeof (panelize_but[0]); i = sizeof (panelize_but) / sizeof (panelize_but[0]);
while (i--) { while (i--) {
panelize_but[i].text = _(panelize_but[i].text); panelize_but[i].text = _(panelize_but[i].text);
maxlen += strlen (panelize_but[i].text) + 5; maxlen += str_term_width1 (panelize_but[i].text) + 5;
} }
maxlen += 10; maxlen += 10;
@ -138,11 +139,11 @@ init_panelize (void)
panelize_cols = max (panelize_cols, maxlen); panelize_cols = max (panelize_cols, maxlen);
panelize_but[2].x = panelize_but[2].x =
panelize_but[3].x + strlen (panelize_but[3].text) + 7; panelize_but[3].x + str_term_width1 (panelize_but[3].text) + 7;
panelize_but[1].x = panelize_but[1].x =
panelize_but[2].x + strlen (panelize_but[2].text) + 5; panelize_but[2].x + str_term_width1 (panelize_but[2].text) + 5;
panelize_but[0].x = panelize_but[0].x =
panelize_cols - strlen (panelize_but[0].text) - 8 - BX; panelize_cols - str_term_width1 (panelize_but[0].text) - 8 - BX;
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */

View File

@ -52,6 +52,7 @@
#include "cons.saver.h" /* handle_console() */ #include "cons.saver.h" /* handle_console() */
#include "key.h" /* XCTRL */ #include "key.h" /* XCTRL */
#include "subshell.h" #include "subshell.h"
#include "strutil.h"
#ifndef WEXITSTATUS #ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
@ -700,8 +701,10 @@ static char *
subshell_name_quote (const char *s) subshell_name_quote (const char *s)
{ {
char *ret, *d; char *ret, *d;
const char *su, *n;
const char quote_cmd_start[] = "\"`printf \"%b\" '"; const char quote_cmd_start[] = "\"`printf \"%b\" '";
const char quote_cmd_end[] = "'`\""; const char quote_cmd_end[] = "'`\"";
int c;
/* Factor 5 because we need \, 0 and 3 other digits per character. */ /* Factor 5 because we need \, 0 and 3 other digits per character. */
d = ret = g_malloc (1 + (5 * strlen (s)) + (sizeof(quote_cmd_start) - 1) d = ret = g_malloc (1 + (5 * strlen (s)) + (sizeof(quote_cmd_start) - 1)
@ -724,13 +727,19 @@ subshell_name_quote (const char *s)
* sequence of the form \0nnn, where "nnn" is the numeric value of the * sequence of the form \0nnn, where "nnn" is the numeric value of the
* character converted to octal number. * character converted to octal number.
*/ */
for (; *s; s++) { su = s;
if (isalnum ((unsigned char) *s)) { for (; su[0] != '\0'; ) {
*d++ = (unsigned char) *s; n = str_cget_next_char_safe (su);
if (str_isalnum (su)) {
memcpy (d, su, n - su);
d+= n - su;
} else { } else {
sprintf (d, "\\0%03o", (unsigned char) *s); for (c = 0; c < n - su; c++) {
d += 5; sprintf (d, "\\0%03o", (unsigned char) su[c]);
d += 5;
}
} }
su = n;
} }
strcpy (d, quote_cmd_end); strcpy (d, quote_cmd_end);

View File

@ -50,6 +50,7 @@
#include "treestore.h" #include "treestore.h"
#include "cmd.h" #include "cmd.h"
#include "history.h" #include "history.h"
#include "strutil.h"
#define tlines(t) (t->is_panel ? t->widget.lines-2 - (show_mini_info ? 2 : 0) : t->widget.lines) #define tlines(t) (t->is_panel ? t->widget.lines-2 - (show_mini_info ? 2 : 0) : t->widget.lines)
@ -177,12 +178,14 @@ static void tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols)
attrset (DLG_FOCUSC (h)); attrset (DLG_FOCUSC (h));
addch (PATH_SEP); addch (PATH_SEP);
addstr ((char *) name_trunc (tree->search_buffer, tree_cols-2)); addstr (str_fit_to_term (tree->search_buffer,
tree_cols - 2, J_LEFT_FIT));
addch (' '); addch (' ');
attrset (DLG_FOCUSC (h)); attrset (DLG_FOCUSC (h));
} else { } else {
/* Show full name of selected directory */ /* Show full name of selected directory */
addstr ((char *) name_trunc (tree->selected_ptr->name, tree_cols)); addstr (str_fit_to_term (tree->selected_ptr->name,
tree_cols, J_LEFT_FIT));
} }
} }
@ -268,7 +271,7 @@ static void show_tree (WTree *tree)
} }
/* Show full name */ /* Show full name */
addstr ((char *) name_trunc (current->name, tree_cols - 6)); addstr (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
} else{ } else{
/* Sub level directory */ /* Sub level directory */
@ -302,8 +305,8 @@ static void show_tree (WTree *tree)
/* Show sub-name */ /* Show sub-name */
addch (' '); addch (' ');
addstr ((char *) name_trunc (current->subname, addstr (str_fit_to_term (current->subname,
tree_cols - 2 - 4 - 3 * j)); tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT));
} }
addch (' '); addch (' ');

View File

@ -32,6 +32,7 @@
#include "global.h" #include "global.h"
#include "color.h" #include "color.h"
#include "main.h" /* for slow_terminal */ #include "main.h" /* for slow_terminal */
#include "strutil.h"
#ifdef USE_NCURSES #ifdef USE_NCURSES
#define WANT_TERM_H #define WANT_TERM_H
@ -159,9 +160,9 @@ extern void
tty_print_string(const char *s) tty_print_string(const char *s)
{ {
#ifdef HAVE_SLANG #ifdef HAVE_SLANG
SLsmg_write_string(str_unconst(s)); SLsmg_write_string (str_unconst (str_term_form (s)));
#else #else
addstr(s); addstr (str_term_form (s));
#endif #endif
} }

View File

@ -34,6 +34,7 @@
#include "execute.h" #include "execute.h"
#include "setup.h" #include "setup.h"
#include "history.h" #include "history.h"
#include "strutil.h"
#include "../edit/edit.h" /* BLOCK_FILE */ #include "../edit/edit.h" /* BLOCK_FILE */
#include "../edit/edit-widget.h" /* WEdit */ #include "../edit/edit-widget.h" /* WEdit */
@ -184,7 +185,7 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
if (edit_one_file != NULL) if (edit_one_file != NULL)
fname = edit_widget->filename; fname = edit_widget->filename;
else { else {
if (islower ((unsigned char) c)) if (g_ascii_islower ((gchar) c))
panel = current_panel; panel = current_panel;
else { else {
if (get_other_type () != view_listing) if (get_other_type () != view_listing)
@ -199,7 +200,7 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
else else
quote_func = fake_name_quote; quote_func = fake_name_quote;
c_lc = tolower ((unsigned char) c); c_lc = g_ascii_tolower ((gchar) c);
switch (c_lc) { switch (c_lc) {
case 'f': case 'f':
@ -324,16 +325,22 @@ check_patterns (char *p)
point after argument. */ point after argument. */
static char *extract_arg (char *p, char *arg, int size) static char *extract_arg (char *p, char *arg, int size)
{ {
char *np;
while (*p && (*p == ' ' || *p == '\t' || *p == '\n')) while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
p++; p++;
/* support quote space .mnu */ /* support quote space .mnu */
while (size > 1 && *p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') { while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
*arg++ = *p++; np = str_get_next_char (p);
size--; if (np - p >= size) break;
memcpy (arg, p, np - p);
arg+= np - p;
size-= np - p;
p = np;
} }
*arg = 0; *arg = 0;
if (!*p || *p == '\n') if (!*p || *p == '\n')
p --; str_prev_char (&p);
return p; return p;
} }
@ -410,7 +417,7 @@ static char *test_condition (WEdit *edit_widget, char *p, int *condition)
case '!': case '!':
p = test_condition (edit_widget, p, condition); p = test_condition (edit_widget, p, condition);
*condition = ! *condition; *condition = ! *condition;
p--; str_prev_char (&p);
break; break;
case 'f': /* file name pattern */ case 'f': /* file name pattern */
p = extract_arg (p, arg, sizeof (arg)); p = extract_arg (p, arg, sizeof (arg));
@ -554,7 +561,7 @@ static char *test_line (WEdit *edit_widget, char *p, int *result)
debug_out (NULL, NULL, 1); debug_out (NULL, NULL, 1);
if (!*p || *p == '\n') if (!*p || *p == '\n')
p --; str_prev_char (&p);
return p; return p;
} }
@ -627,9 +634,9 @@ execute_menu_command (WEdit *edit_widget, const char *commands)
} }
} else if (expand_prefix_found){ } else if (expand_prefix_found){
expand_prefix_found = 0; expand_prefix_found = 0;
if (isdigit ((unsigned char) *commands)) { if (g_ascii_isdigit ((gchar) *commands)) {
do_quote = atoi (commands); do_quote = atoi (commands);
while (isdigit ((unsigned char) *commands)) while (g_ascii_isdigit ((gchar) *commands))
commands++; commands++;
} }
if (*commands == '{') if (*commands == '{')
@ -746,7 +753,7 @@ user_menu_cmd (struct WEdit *edit_widget)
/* Parse the menu file */ /* Parse the menu file */
old_patterns = easy_patterns; old_patterns = easy_patterns;
p = check_patterns (data); p = check_patterns (data);
for (menu_lines = col = 0; *p; p++){ for (menu_lines = col = 0; *p; str_next_char (&p)){
if (menu_lines >= menu_limit){ if (menu_lines >= menu_limit){
char ** new_entries; char ** new_entries;
@ -789,7 +796,7 @@ user_menu_cmd (struct WEdit *edit_widget)
selected = menu_lines; selected = menu_lines;
} }
} }
else if (*p != ' ' && *p != '\t' && is_printable (*p)) { else if (*p != ' ' && *p != '\t' && str_isprint (p)) {
/* A menu entry title line */ /* A menu entry title line */
if (accept_entry) if (accept_entry)
entries [menu_lines] = p; entries [menu_lines] = p;

View File

@ -230,27 +230,7 @@ fake_name_quote (const char *s, int quote_percent)
const char * const char *
name_trunc (const char *txt, int trunc_len) name_trunc (const char *txt, int trunc_len)
{ {
static char x[MC_MAXPATHLEN + MC_MAXPATHLEN]; return str_trunc (txt, trunc_len);
int txt_len;
char *p;
if ((size_t) trunc_len > sizeof (x) - 1) {
trunc_len = sizeof (x) - 1;
}
txt_len = strlen (txt);
if (txt_len <= trunc_len) {
strcpy (x, txt);
} else {
int y = (trunc_len / 2) + (trunc_len % 2);
strncpy (x, txt, y);
strncpy (x + y, txt + txt_len - (trunc_len / 2), trunc_len / 2);
x[y] = '~';
}
x[trunc_len] = 0;
for (p = x; *p; p++)
if (!is_printable (*p))
*p = '?';
return x;
} }
/* /*
@ -260,10 +240,9 @@ name_trunc (const char *txt, int trunc_len)
*/ */
const char * const char *
path_trunc (const char *path, int trunc_len) { path_trunc (const char *path, int trunc_len) {
const char *ret;
char *secure_path = strip_password (g_strdup (path), 1); char *secure_path = strip_password (g_strdup (path), 1);
ret = name_trunc (secure_path, trunc_len); const char *ret = str_trunc (secure_path, trunc_len);
g_free (secure_path); g_free (secure_path);
return ret; return ret;
@ -810,7 +789,7 @@ _icase_search (const char *text, const char *data, int *lng)
e += 2; e += 2;
dlng += 2; dlng += 2;
} }
if (toupper((unsigned char) *d) == toupper((unsigned char) *e)) if (g_ascii_toupper((gchar) *d) == g_ascii_toupper((gchar) *e))
d++; d++;
else { else {
e -= d - text; e -= d - text;
@ -856,19 +835,23 @@ unix_error_string (int error_num)
const char * const char *
skip_separators (const char *s) skip_separators (const char *s)
{ {
for (;*s; s++) const char *su = s;
if (*s != ' ' && *s != '\t' && *s != ',')
break; for (;*su; str_cnext_char (&su))
return s; if (*su != ' ' && *su != '\t' && *su != ',') break;
return su;
} }
const char * const char *
skip_numbers (const char *s) skip_numbers (const char *s)
{ {
for (;*s; s++) const char *su = s;
if (!isdigit ((unsigned char) *s))
break; for (;*su; str_cnext_char (&su))
return s; if (!str_isdigit (su)) break;
return su;
} }
/* Remove all control sequences from the argument string. We define /* Remove all control sequences from the argument string. We define
@ -889,6 +872,7 @@ strip_ctrl_codes (char *s)
{ {
char *w; /* Current position where the stripped data is written */ char *w; /* Current position where the stripped data is written */
char *r; /* Current position where the original data is read */ char *r; /* Current position where the original data is read */
char *n;
if (!s) if (!s)
return 0; return 0;
@ -910,9 +894,12 @@ strip_ctrl_codes (char *s)
continue; continue;
} }
if (is_printable(*r)) n = str_get_next_char (r);
*w++ = *r; if (str_isprint (r)) {
++r; memmove (w, r, n - r);
w+= n - r;
}
r = n;
} }
*w = 0; *w = 0;
return s; return s;
@ -1473,21 +1460,10 @@ save_file_position (const char *filename, long line, long column)
extern const char * extern const char *
cstrcasestr (const char *haystack, const char *needle) cstrcasestr (const char *haystack, const char *needle)
{ {
const char *hptr; char *nee = str_create_search_needle (needle, 0);
size_t i, needle_len; const char *result = str_search_first (haystack, nee, 0);
str_release_search_needle (nee, 0);
needle_len = strlen (needle); return result;
for (hptr = haystack; *hptr != '\0'; hptr++) {
for (i = 0; i < needle_len; i++) {
if (toupper ((unsigned char) hptr[i]) !=
toupper ((unsigned char) needle[i]))
goto next_try;
}
return hptr;
next_try:
(void) 0;
}
return NULL;
} }
const char * const char *

View File

@ -34,6 +34,7 @@
#include "win.h" #include "win.h"
#include "key.h" /* XCTRL and ALT macros */ #include "key.h" /* XCTRL and ALT macros */
#include "layout.h" #include "layout.h"
#include "strutil.h"
/* /*
* Common handler for standard movement keys in a text area. Provided * Common handler for standard movement keys in a text area. Provided
@ -217,7 +218,7 @@ int lookup_key (char *keyname)
int i; int i;
for (i = 0; key_name_conv_tab [i].code; i++){ for (i = 0; key_name_conv_tab [i].code; i++){
if ( g_strcasecmp (key_name_conv_tab [i].name, keyname)) if (str_casecmp (key_name_conv_tab [i].name, keyname))
continue; continue;
return key_name_conv_tab [i].code; return key_name_conv_tab [i].code;
} }