⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editcmd.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
		break;	    }	}    }    CDestroyWidget ("status_prompt");    CDestroyWidget ("status_input");    CRestoreState (&s);    return;}extern struct look *look;void edit_search_replace_dialog (Window parent, int x, int y, char **search_text,				 char **replace_text, char **arg_order, char *heading, int option){    (*look->search_replace_dialog) (parent, x, y, search_text, replace_text, arg_order, heading, option);}void edit_search_dialog (WEdit * edit, char **search_text){/* Heads the 'Search' dialog box */    edit_search_replace_dialog (WIN_MESSAGES, search_text, 0, 0, _(" Search "), SEARCH_DIALOG_OPTION_BACKWARDS | SEARCH_DIALOG_OPTION_BOOKMARK);}void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text, char **arg_order){/* Heads the 'Replace' dialog box */    edit_search_replace_dialog (WIN_MESSAGES, search_text, replace_text, arg_order, _(" Replace "), SEARCH_DIALOG_OPTION_BACKWARDS);}#else#include <libgnomeui/gtkcauldron.h>#include <libgnomeui/gnome-stock.h>void edit_search_dialog (WEdit * edit, char **search_text){    char *s;    s = gtk_dialog_cauldron (				"Search", GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB,				" ( (Enter search text)d | %Eogxf )xf / ( ( %Cd // %Cd // %Cd ) || ( %Cd // %Cd )xf )xf / ( %Bxfgrq || %Bxfgq )f",				search_text, "search",				"&Whole word", &replace_whole,				"Case &sensitive", &replace_case,				"&Regular expression", &replace_regexp,				"&Backwards", &replace_backwards,				"Scanf &expression", &replace_scanf,				GNOME_STOCK_BUTTON_OK,				GNOME_STOCK_BUTTON_CANCEL	);    if (s == GTK_CAULDRON_ESCAPE || !s || s == GNOME_STOCK_BUTTON_CANCEL)	*search_text = 0;    return;}void edit_replace_dialog (WEdit * edit, char **search_text, char **replace_text, char **arg_order){    char *s;    s = gtk_dialog_cauldron (				"Search", GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB,				" ( (Enter search text)d | %Eogxf )xf / ( (Enter replace text)d | %Egxf )xf / ( (Enter argument order)d | %Egxf )xf / ( ( %Cd // %Cd // %Cd // %Cd ) || ( %Cd // %Cd // %Cd )xf )xf / ( %Bxfgrq || %Bxfgq )f",				search_text, "search",				replace_text, "replace",				arg_order, "arg_order",				"&Whole word", &replace_whole,				"Case &sensitive", &replace_case,				"&Regular expression", &replace_regexp,				"&Backwards", &replace_backwards,				"Pr&ompt on replace", &replace_prompt,				"Replace &all", &replace_all,				"Scanf &expression", &replace_scanf,				GNOME_STOCK_BUTTON_OK,				GNOME_STOCK_BUTTON_CANCEL	);    if (s == GTK_CAULDRON_ESCAPE || !s || s == GNOME_STOCK_BUTTON_CANCEL)	*search_text = 0;    return;}#endif#ifdef GTKint edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos){    char *s;    s = gtk_dialog_cauldron (		    "Replace", GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB,				" ( (Replace with:)d %Ld )xf / ( %Bxfrq || %Bxfq || %Bxfq || %Bxfq || %Bxfgq )f",				replace_text,			 "Replace", "Skip", "Replace all", "Replace one",				GNOME_STOCK_BUTTON_CANCEL	);    if (s == GTK_CAULDRON_ESCAPE || !s || s == GNOME_STOCK_BUTTON_CANCEL)	return B_CANCEL;    if (!strcmp (s, "Replace all"))	return B_REPLACE_ALL;    if (!strcmp (s, "Replace one"))	return B_REPLACE_ONE;    if (!strcmp (s, "Skip"))	return B_SKIP_REPLACE;    if (!strcmp (s, "Replace"))	return B_ENTER;}#elseint edit_replace_prompt (WEdit * edit, char *replace_text, int xpos, int ypos){    int q, x[] =    {	B_CANCEL, B_ENTER, B_SKIP_REPLACE, B_REPLACE_ALL, B_REPLACE_ONE, B_CANCEL    };    q = CQueryDialog (WIN_MESSAGES + (edit->curs_line < 8 ? edit->num_widget_lines / 2 * FONT_PIX_PER_LINE + CYof (edit->widget) : 0),		      _ (" Replace "), catstrs (_ (" Replace with: "), replace_text, 0), _ ("Replace"), _ ("Skip"), _ ("Replace all"), _ ("Replace one"), _ ("Cancel"), 0);    edit->force |= REDRAW_COMPLETELY;    return x[q + 1];}#endif#endiflong sargs[NUM_REPL_ARGS][256 / sizeof (long)];#define SCANF_ARGS sargs[0], sargs[1], sargs[2], sargs[3], \		     sargs[4], sargs[5], sargs[6], sargs[7], \		     sargs[8], sargs[9], sargs[10], sargs[11], \		     sargs[12], sargs[13], sargs[14], sargs[15]#define PRINTF_ARGS sargs[argord[0]], sargs[argord[1]], sargs[argord[2]], sargs[argord[3]], \		     sargs[argord[4]], sargs[argord[5]], sargs[argord[6]], sargs[argord[7]], \		     sargs[argord[8]], sargs[argord[9]], sargs[argord[10]], sargs[argord[11]], \		     sargs[argord[12]], sargs[argord[13]], sargs[argord[14]], sargs[argord[15]]/* This function is a modification of mc-3.2.10/src/view.c:regexp_view_search() *//* returns -3 on error in pattern, -1 on not found, found_len = 0 if either */int string_regexp_search (char *pattern, char *string, int len, int match_type, int match_bol, int icase, int *found_len, void *d){    static regex_t r;    static char *old_pattern = NULL;    static int old_type, old_icase;    regmatch_t *pmatch;    static regmatch_t s[1];    pmatch = (regmatch_t *) d;    if (!pmatch)	pmatch = s;    if (!old_pattern || strcmp (old_pattern, pattern) || old_type != match_type || old_icase != icase) {	if (old_pattern) {	    regfree (&r);	    free (old_pattern);	    old_pattern = 0;	}	if (regcomp (&r, pattern, REG_EXTENDED | (icase ? REG_ICASE : 0))) {	    *found_len = 0;	    return -3;	}	old_pattern = (char *) strdup (pattern);	old_type = match_type;	old_icase = icase;    }    if (regexec (&r, string, d ? NUM_REPL_ARGS : 1, pmatch, ((match_bol || match_type != match_normal) ? 0 : REG_NOTBOL)) != 0) {	*found_len = 0;	return -1;    }    *found_len = pmatch[0].rm_eo - pmatch[0].rm_so;    return (pmatch[0].rm_so);}/* thanks to  Liviu Daia <daia@stoilow.imar.ro>  for getting this   (and the above) routines to work properly - paul */long edit_find_string (long start, unsigned char *exp, int *len, long last_byte, int (*get_byte) (void *, long), void *data, int once_only, void *d){    long p, q = 0;    long l = strlen ((char *) exp), f = 0;    int n = 0;    for (p = 0; p < l; p++)	/* count conversions... */	if (exp[p] == '%')	    if (exp[++p] != '%')	/* ...except for "%%" */		n++;    if (replace_scanf || replace_regexp) {	int c;	unsigned char *buf;	unsigned char mbuf[MAX_REPL_LEN * 2 + 3];	replace_scanf = (!replace_regexp);	/* can't have both */	buf = mbuf;	if (replace_scanf) {	    unsigned char e[MAX_REPL_LEN];	    if (n >= NUM_REPL_ARGS)		return -3;	    if (replace_case) {		for (p = start; p < last_byte && p < start + MAX_REPL_LEN; p++)		    buf[p - start] = (*get_byte) (data, p);	    } else {		for (p = 0; exp[p] != 0; p++)		    exp[p] = my_lower_case (exp[p]);		for (p = start; p < last_byte && p < start + MAX_REPL_LEN; p++) {		    c = (*get_byte) (data, p);		    buf[p - start] = my_lower_case (c);		}	    }	    buf[(q = p - start)] = 0;	    strcpy ((char *) e, (char *) exp);	    strcat ((char *) e, "%n");	    exp = e;	    while (q) {		*((int *) sargs[n]) = 0;	/* --> here was the problem - now fixed: good */		if (n == sscanf ((char *) buf, (char *) exp, SCANF_ARGS)) {		    if (*((int *) sargs[n])) {			*len = *((int *) sargs[n]);			return start;		    }		}		if (once_only)		    return -2;		if (q + start < last_byte) {		    if (replace_case) {			buf[q] = (*get_byte) (data, q + start);		    } else {			c = (*get_byte) (data, q + start);			buf[q] = my_lower_case (c);		    }		    q++;		}		buf[q] = 0;		start++;		buf++;		/* move the window along */		if (buf == mbuf + MAX_REPL_LEN) {	/* the window is about to go past the end of array, so... */		    memmove (mbuf, buf, strlen ((char *) buf) + 1);	/* reset it */		    buf = mbuf;		}		q--;	    }	} else {	/* regexp matching */	    long offset = 0;	    int found_start, match_bol, move_win = 0; 	    while (start + offset < last_byte) {		match_bol = (offset == 0 || (*get_byte) (data, start + offset - 1) == '\n');		if (!move_win) {		    p = start + offset;		    q = 0;		}		for (; p < last_byte && q < MAX_REPL_LEN; p++, q++) {		    mbuf[q] = (*get_byte) (data, p);		    if (mbuf[q] == '\n')			break;		}		q++;		offset += q;		mbuf[q] = 0;		buf = mbuf;		while (q) {		    found_start = string_regexp_search ((char *) exp, (char *) buf, q, match_normal, match_bol, !replace_case, len, d);		    if (found_start <= -2) {	/* regcomp/regexec error */			*len = 0;			return -3;		    }		    else if (found_start == -1)	/* not found: try next line */			break;		    else if (*len == 0) { /* null pattern: try again at next character */			q--;			buf++;			match_bol = 0;			continue;		    }		    else	/* found */			return (start + offset - q + found_start);		}		if (once_only)		    return -2;		if (buf[q - 1] != '\n') { /* incomplete line: try to recover */		    buf = mbuf + MAX_REPL_LEN / 2;		    q = strlen ((char *) buf);		    memmove (mbuf, buf, q);		    p = start + q;		    move_win = 1;		}		else		    move_win = 0;	    }	}    } else { 	*len = strlen ((char *) exp);	if (replace_case) {	    for (p = start; p <= last_byte - l; p++) { 		if ((*get_byte) (data, p) == (unsigned char)exp[0]) {	/* check if first char matches */		    for (f = 0, q = 0; q < l && f < 1; q++) 			if ((*get_byte) (data, q + p) != (unsigned char)exp[q])			    f = 1;		    if (f == 0)			return p;		}		if (once_only)		    return -2;	    }	} else {	    for (p = 0; exp[p] != 0; p++)		exp[p] = my_lower_case (exp[p]);	    for (p = start; p <= last_byte - l; p++) {		if (my_lower_case ((*get_byte) (data, p)) == (unsigned char)exp[0]) {		    for (f = 0, q = 0; q < l && f < 1; q++)			if (my_lower_case ((*get_byte) (data, q + p)) != (unsigned char)exp[q])			    f = 1;		    if (f == 0)			return p;		}		if (once_only)		    return -2;	    }	}    }    return -2;}long edit_find_forwards (long search_start, unsigned char *exp, int *len, long last_byte, int (*get_byte) (void *, long), void *data, int once_only, void *d){				/*front end to find_string to check for				   whole words */    long p;    p = search_start;    while ((p = edit_find_string (p, exp, len, last_byte, get_byte, data, once_only, d)) >= 0) {	if (replace_whole) {/*If the bordering chars are not in option_whole_chars_search then word is whole */	    if (!strcasechr (option_whole_chars_search, (*get_byte) (data, p - 1))		&& !strcasechr (option_whole_chars_search, (*get_byte) (data, p + *len)))		return p;	    if (once_only)		return -2;	} else	    return p;	if (once_only)	    break;	p++;			/*not a whole word so continue search. */    }    return p;}long edit_find (long search_start, unsigned char *exp, int *len, long last_byte, int (*get_byte) (void *, long), void *data, void *d){    long p;    if (replace_backwards) {	while (search_start >= 0) {	    p = edit_find_forwards (search_start, exp, len, last_byte, get_byte, data, 1, d);	    if (p == search_start)		return p;	    search_start--;	}    } else {	return edit_find_forwards (search_start, exp, len, last_byte, get_byte, data, 0, d);    }    return -2;}#define is_digit(x) ((x) >= '0' && (x) <= '9')#define snprintf(v) { \		*p1++ = *p++; \		*p1++ = '%'; \		*p1++ = 'n'; \		*p1 = '\0'; \		sprintf(s,q1,v,&n); \		s += n; \	    }/* this function uses the sprintf command to do a vprintf *//* it takes pointers to arguments instead of the arguments themselves */int sprintf_p (char *str, const char *fmt,...){    va_list ap;    int n;    char *q, *p, *s = str;    char q1[32];    char *p1;    va_start (ap, fmt);    p = q = (char *) fmt;    while ((p = strchr (p, '%'))) {	n = (int) ((unsigned long) p - (unsigned long) q);	strncpy (s, q, n);	/* copy stuff between format specifiers */	s += n;	*s = 0;	q = p;	p1 = q1;	*p1++ = *p++;	if (*p == '%') {	    p++;	    *s++ = '%';	    q = p;	    continue;	}	if (*p == 'n') {	    p++;/* do nothing */	    q = p;	    continue;	}	if (*p == '#')	    *p1++ = *p++;	if (*p == '0')	    *p1++ = *p++;	if (*p == '-')	    *p1++ = *p++;	if (*p == '+')	    *p1++ = *p++;	if (*p == '*') {	    p++;	    strcpy (p1, itoa (*va_arg (ap, int *)));	/* replace field width with a number */	    p1 += strlen (p1);	} else {	    while (is_digit (*p))		*p1++ = *p++;	}	if (*p == '.')	    *p1++ = *p++;	if (*p == '*') {	    p++;	    strcpy (p1, itoa (*va_arg (ap, int *)));	/* replace precision with a number */	    p1 += strlen (p1);	} else {	    while (is_digit (*p))		*p1++ = *p++;	}/* flags done, now get argument */	if (*p == 's') {	    snprintf (va_arg (ap, char *));	} else if (*p == 'h') {	    if (strchr ("diouxX", *p))		snprintf (*va_arg (ap, short *));	} else if (*p == 'l') {	    *p1++ = *p++;	    if (strchr ("diouxX", *p))		snprintf (*va_arg (ap, long *));	} else if (strchr ("cdiouxX", *p)) {	    snprintf (*va_arg (ap, int *));	} else if (*p == 'L') {	    *p1++ = *p++;	    if (strchr ("EefgG", *p))		snprintf (*va_arg (ap, double *));	/* should be long double */	} else if (strchr ("EefgG", *p)) {	    snprintf (*va_arg (ap, double *));	} else if (strchr ("DOU", *p)) {	    snprintf (*va_arg (ap, long *));	} else if (*p == 'p') {	    snprintf (*va_arg (ap, void **));	}	q = p;    }    va_end (ap);    sprintf (s, q);		/* print trailing leftover */    return (unsigned long) s - (unsigned long) str + strlen (s);}static void regexp_error (WEdit *edit){/* "Error: Syntax error in regular expression, or scanf expression contained too many %'s */    edit_error_dialog (_(" Error "), _(" Invalid regular expression, or scanf expression with to many conversions "));}/* call with edit = 0 before shutdown to close memory leaks */void edit_replace_cmd (WEdit * edit, int again){    static regmatch_t pmatch[NUM_REPL_ARGS];    static char *old1 = NULL;    static char *old2 = NULL;    static char *old3 = NULL;    char *exp1 = "";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -