edit/editcmd.c: Fixed search and replace with scanf-search
Этот коммит содержится в:
родитель
0730efa2fc
Коммит
3802929f94
@ -88,6 +88,20 @@ static int edit_save_cmd (WEdit *edit);
|
|||||||
static unsigned char *edit_get_block (WEdit *edit, long start,
|
static unsigned char *edit_get_block (WEdit *edit, long start,
|
||||||
long finish, int *l);
|
long finish, int *l);
|
||||||
|
|
||||||
|
static int
|
||||||
|
editcmd_get_str_nlen(const char*str, int byte_len)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
if (!str || byte_len < 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
char *tmp = g_malloc(sizeof(char)*byte_len+1);
|
||||||
|
memcpy(tmp,str,byte_len);
|
||||||
|
tmp[byte_len] = '\0';
|
||||||
|
ret = str_length(tmp);
|
||||||
|
g_free(tmp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
static gchar *
|
static gchar *
|
||||||
my_lower_case (char *ch)
|
my_lower_case (char *ch)
|
||||||
{
|
{
|
||||||
@ -117,6 +131,8 @@ strcasechr (const char *s, char *c)
|
|||||||
{
|
{
|
||||||
gchar *tmp_c=NULL;
|
gchar *tmp_c=NULL;
|
||||||
|
|
||||||
|
if (!s || !c)
|
||||||
|
return NULL;
|
||||||
tmp_c = my_lower_case (c);
|
tmp_c = my_lower_case (c);
|
||||||
while ( strcmp(tmp_c, my_lower_case_static((char *)s))){
|
while ( strcmp(tmp_c, my_lower_case_static((char *)s))){
|
||||||
if (*s == '\0'){
|
if (*s == '\0'){
|
||||||
@ -1479,7 +1495,6 @@ edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit
|
|||||||
if (exp[p] == '%')
|
if (exp[p] == '%')
|
||||||
if (exp[++p] != '%') /* ...except for "%%" */
|
if (exp[++p] != '%') /* ...except for "%%" */
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (replace_scanf || replace_regexp) {
|
if (replace_scanf || replace_regexp) {
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
unsigned char mbuf[MAX_REPL_LEN * 2 + 3];
|
unsigned char mbuf[MAX_REPL_LEN * 2 + 3];
|
||||||
@ -1610,15 +1625,15 @@ edit_find_string (long start, unsigned char *exp, int *len, long last_byte, edit
|
|||||||
while ( p <= last_byte - l)
|
while ( p <= last_byte - l)
|
||||||
{
|
{
|
||||||
c = (*get_byte) (data, p);
|
c = (*get_byte) (data, p);
|
||||||
if ( !strncmp(c, exp, str_length_char(c)) )
|
if ( !strncmp((const char *)c, (const char *)exp, str_length_char((const char *) c)) )
|
||||||
{ /* check if first char matches */
|
{ /* check if first char matches */
|
||||||
f = 0;
|
f = 0;
|
||||||
q = 0;
|
q = 0;
|
||||||
while ( q < l && f < 1)
|
while ( q < l && f < 1)
|
||||||
{
|
{
|
||||||
tmp_exp1 = (*get_byte) (data, q + p);
|
tmp_exp1 = (*get_byte) (data, q + p);
|
||||||
tmp_len = str_length_char(tmp_exp1);
|
tmp_len = str_length_char((const char *)tmp_exp1);
|
||||||
if ( strncmp(tmp_exp1, &exp[q], (tmp_len==0)?1:tmp_len ) )
|
if ( strncmp((const char *)tmp_exp1, (const char *)&exp[q], (tmp_len==0)?1:tmp_len ) )
|
||||||
{
|
{
|
||||||
f = 1;
|
f = 1;
|
||||||
}
|
}
|
||||||
@ -1690,7 +1705,7 @@ edit_find_forwards (long search_start, unsigned char *exp, int *len, long last_b
|
|||||||
if (!strcasechr (option_whole_chars_search, (*get_byte) (data, p - 1))
|
if (!strcasechr (option_whole_chars_search, (*get_byte) (data, p - 1))
|
||||||
&& !strcasechr (option_whole_chars_search, (*get_byte) (data, p + *len))){
|
&& !strcasechr (option_whole_chars_search, (*get_byte) (data, p + *len))){
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
if (once_only)
|
if (once_only)
|
||||||
return -2;
|
return -2;
|
||||||
} else
|
} else
|
||||||
@ -1783,7 +1798,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...)
|
|||||||
if (*p == '*') {
|
if (*p == '*') {
|
||||||
p++;
|
p++;
|
||||||
strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace field width with a number */
|
strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace field width with a number */
|
||||||
p1 += str_term_width1 (p1);
|
p1 += strlen (p1);
|
||||||
} else {
|
} else {
|
||||||
while (is_digit (*p) && p1 < q1 + 20)
|
while (is_digit (*p) && p1 < q1 + 20)
|
||||||
*p1++ = *p++;
|
*p1++ = *p++;
|
||||||
@ -1795,7 +1810,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...)
|
|||||||
if (*p == '*') {
|
if (*p == '*') {
|
||||||
p++;
|
p++;
|
||||||
strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace precision with a number */
|
strcpy (p1, MY_itoa (*va_arg (ap, int *))); /* replace precision with a number */
|
||||||
p1 += str_term_width1 (p1);
|
p1 += strlen (p1);
|
||||||
} else {
|
} else {
|
||||||
while (is_digit (*p) && p1 < q1 + 32)
|
while (is_digit (*p) && p1 < q1 + 32)
|
||||||
*p1++ = *p++;
|
*p1++ = *p++;
|
||||||
@ -1829,7 +1844,7 @@ static int snprintf_p (char *str, size_t size, const char *fmt,...)
|
|||||||
q = p;
|
q = p;
|
||||||
}
|
}
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
n = str_term_width1 (q);
|
n = strlen (q);
|
||||||
if (n >= (size_t) (e - s))
|
if (n >= (size_t) (e - s))
|
||||||
return -1;
|
return -1;
|
||||||
memcpy (s, q, n + 1);
|
memcpy (s, q, n + 1);
|
||||||
@ -2030,17 +2045,11 @@ edit_replace_cmd (WEdit *edit, int again)
|
|||||||
for (j = 0;
|
for (j = 0;
|
||||||
j < pmatch[k].rm_eo - pmatch[k].rm_so
|
j < pmatch[k].rm_eo - pmatch[k].rm_so
|
||||||
&& j < 255; j++, t++)
|
&& j < 255; j++, t++)
|
||||||
*t = (unsigned char) edit_get_byte (edit,
|
*t = (unsigned char) edit_get_byte
|
||||||
edit->
|
(
|
||||||
search_start
|
edit,
|
||||||
-
|
edit->search_start - pmatch[0].rm_so + pmatch[k].rm_so + j
|
||||||
pmatch
|
);
|
||||||
[0].
|
|
||||||
rm_so +
|
|
||||||
pmatch
|
|
||||||
[k].
|
|
||||||
rm_so +
|
|
||||||
j);
|
|
||||||
*t = '\0';
|
*t = '\0';
|
||||||
}
|
}
|
||||||
for (; k <= NUM_REPL_ARGS; k++)
|
for (; k <= NUM_REPL_ARGS; k++)
|
||||||
@ -2052,16 +2061,15 @@ edit_replace_cmd (WEdit *edit, int again)
|
|||||||
PRINTF_ARGS);
|
PRINTF_ARGS);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
times_replaced++;
|
times_replaced++;
|
||||||
|
i = editcmd_get_str_nlen(edit_get_byte_ptr(edit,edit->found_start), i);
|
||||||
while (i--)
|
while (i--)
|
||||||
edit_delete (edit);
|
edit_delete (edit);
|
||||||
while (repl_str[++i])
|
while (repl_str[++i])
|
||||||
edit_insert (edit, repl_str[i]);
|
edit_insert (edit, repl_str[i]);
|
||||||
} else {
|
} else {
|
||||||
edit_error_dialog (_(" Replace "),
|
edit_error_dialog (_(" Replace "),
|
||||||
ret ==
|
ret == -2
|
||||||
-2 ?
|
? _(" Error in replacement format string. ")
|
||||||
_
|
|
||||||
(" Error in replacement format string. ")
|
|
||||||
: _(" Replacement too long. "));
|
: _(" Replacement too long. "));
|
||||||
replace_continue = 0;
|
replace_continue = 0;
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user