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

📄 editcmd.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    char *exp2 = "";    char *exp3 = "";    int replace_yes;    int replace_continue;    int treplace_prompt = 0;    int i = 0;    long times_replaced = 0, last_search;    char fin_string[64];    int argord[NUM_REPL_ARGS];    if (!edit) {	if (old1) {	    free (old1);	    old1 = 0;	}	if (old2) {	    free (old2);	    old2 = 0;	}	if (old3) {	    free (old3);	    old3 = 0;	}	return;    }    last_search = edit->last_byte;    edit->force |= REDRAW_COMPLETELY;    exp1 = old1 ? old1 : exp1;    exp2 = old2 ? old2 : exp2;    exp3 = old3 ? old3 : exp3;    if (again) {	if (!old1 || !old2)	    return;	exp1 = (char *) strdup (old1);	exp2 = (char *) strdup (old2);	exp3 = (char *) strdup (old3);    } else {	edit_push_action (edit, KEY_PRESS + edit->start_display);	edit_replace_dialog (edit, &exp1, &exp2, &exp3);	treplace_prompt = replace_prompt;    }    if (!exp1 || !*exp1) {	edit->force = REDRAW_COMPLETELY;	if (exp1) {	    free (exp1);	    free (exp2);	    free (exp3);	}	return;    }    if (old1)	free (old1);    if (old2)	free (old2);    if (old3)	free (old3);    old1 = (char *) strdup (exp1);    old2 = (char *) strdup (exp2);    old3 = (char *) strdup (exp3);    {	char *s;	int ord;	while ((s = strchr (exp3, ' ')))	    memmove (s, s + 1, strlen (s));	s = exp3;	for (i = 0; i < NUM_REPL_ARGS; i++) {	    if ((unsigned long) s != 1 && s < exp3 + strlen (exp3)) {		if ((ord = atoi (s)))		    argord[i] = ord - 1;		else		    argord[i] = i;		s = strchr (s, ',') + 1;	    } else		argord[i] = i;	}    }    replace_continue = replace_all;    if (edit->found_len && edit->search_start == edit->found_start + 1 && replace_backwards)	edit->search_start--;    if (edit->found_len && edit->search_start == edit->found_start - 1 && !replace_backwards)	edit->search_start++;    do {	int len = 0;	long new_start;	new_start = edit_find (edit->search_start, (unsigned char *) exp1, &len, last_search,	   (int (*)(void *, long)) edit_get_byte, (void *) edit, pmatch);	if (new_start == -3) {	    regexp_error (edit);	    break;	}	edit->search_start = new_start;	/*returns negative on not found or error in pattern */	if (edit->search_start >= 0) {	    edit->found_start = edit->search_start;	    i = edit->found_len = len;	    edit_cursor_move (edit, edit->search_start - edit->curs1);	    edit_scroll_screen_over_cursor (edit);	    replace_yes = 1;	    if (treplace_prompt) {		int l;		l = edit->curs_row - edit->num_widget_lines / 3;		if (l > 0)		    edit_scroll_downward (edit, l);		if (l < 0)		    edit_scroll_upward (edit, -l);		edit_scroll_screen_over_cursor (edit);		edit->force |= REDRAW_PAGE;		edit_render_keypress (edit);		/*so that undo stops at each query */		edit_push_key_press (edit);		switch (edit_replace_prompt (edit, exp2,	/*and prompt 2/3 down */					     edit->num_widget_columns / 2 - 33, edit->num_widget_lines * 2 / 3)) {		case B_ENTER:		    break;		case B_SKIP_REPLACE:		    replace_yes = 0;		    break;		case B_REPLACE_ALL:		    treplace_prompt = 0;		    replace_continue = 1;		    break;		case B_REPLACE_ONE:		    replace_continue = 0;		    break;		case B_CANCEL:		    replace_yes = 0;		    replace_continue = 0;		    break;		}	    }	    if (replace_yes) {	/* delete then insert new */		if (replace_scanf || replace_regexp) {		    char repl_str[MAX_REPL_LEN + 2];		    if (replace_regexp) {	/* we need to fill in sargs just like with scanf */			int k, j;			for (k = 1; k < NUM_REPL_ARGS && pmatch[k].rm_eo >= 0; k++) {			    unsigned char *t;			    t = (unsigned char *) &sargs[k - 1][0];			    for (j = 0; j < pmatch[k].rm_eo - pmatch[k].rm_so && j < 255; j++, t++)				*t = (unsigned char) edit_get_byte (edit, edit->search_start - pmatch[0].rm_so + pmatch[k].rm_so + j);			    *t = '\0';			}			for (; k <= NUM_REPL_ARGS; k++)			    sargs[k - 1][0] = 0;		    }		    if (sprintf_p (repl_str, exp2, PRINTF_ARGS) >= 0) {			times_replaced++;			while (i--)			    edit_delete (edit);			while (repl_str[++i])			    edit_insert (edit, repl_str[i]);		    } else {			edit_error_dialog (_ (" Replace "),/* "Invalid regexp string or scanf string" */			    _ (" Error in replacement format string. "));			replace_continue = 0;		    }		} else {		    times_replaced++;		    while (i--)			edit_delete (edit);		    while (exp2[++i])			edit_insert (edit, exp2[i]);		}		edit->found_len = i;	    }/* so that we don't find the same string again */	    if (replace_backwards) {		last_search = edit->search_start;		edit->search_start--;	    } else {		edit->search_start += i;		last_search = edit->last_byte;	    }	    edit_scroll_screen_over_cursor (edit);	} else {	    edit->search_start = edit->curs1;	/* try and find from right here for next search */	    edit_update_curs_col (edit);	    edit->force |= REDRAW_PAGE;	    edit_render_keypress (edit);	    if (times_replaced) {		sprintf (fin_string, _ (" %ld replacements made. "), times_replaced);		edit_message_dialog (_ (" Replace "), fin_string);	    } else		edit_message_dialog (_ (" Replace "), _ (" Search string not found. "));	    replace_continue = 0;	}    } while (replace_continue);    free (exp1);    free (exp2);    free (exp3);    edit->force = REDRAW_COMPLETELY;    edit_scroll_screen_over_cursor (edit);}void edit_search_cmd (WEdit * edit, int again){    static char *old = NULL;    char *exp = "";    if (!edit) {	if (old) {	    free (old);	    old = 0;	}	return;    }    exp = old ? old : exp;    if (again) {		/*ctrl-hotkey for search again. */	if (!old)	    return;	exp = (char *) strdup (old);    } else {	edit_search_dialog (edit, &exp);	edit_push_action (edit, KEY_PRESS + edit->start_display);    }    if (exp) {	if (*exp) {	    int len = 0;	    if (old)		free (old);	    old = (char *) strdup (exp);	    if (search_create_bookmark) {		int found = 0, books = 0;		int l = 0, l_last = -1;		long p, q = 0;		for (;;) {		    p = edit_find (q, (unsigned char *) exp, &len, edit->last_byte,				   (int (*)(void *, long)) edit_get_byte, (void *) edit, 0);		    if (p < 0)			break;		    found++;		    l += edit_count_lines (edit, q, p);		    if (l != l_last) {			book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR);			books++;		    }		    l_last = l;		    q = p + 1;		}		if (found) {		    char fin_string[64];/* in response to number of bookmarks added because of string being found %d times */		    sprintf (fin_string, _ (" %d finds made, %d bookmarks added "), found, books);		    edit_message_dialog (_ (" Search "), fin_string);		} else {		    edit_error_dialog (_ (" Search "), _ (" Search string not found. "));		}	    } else {		if (edit->found_len && edit->search_start == edit->found_start + 1 && replace_backwards)		    edit->search_start--;		if (edit->found_len && edit->search_start == edit->found_start - 1 && !replace_backwards)		    edit->search_start++;		edit->search_start = edit_find (edit->search_start, (unsigned char *) exp, &len, edit->last_byte,		(int (*)(void *, long)) edit_get_byte, (void *) edit, 0);		if (edit->search_start >= 0) {		    edit->found_start = edit->search_start;		    edit->found_len = len;		    edit_cursor_move (edit, edit->search_start - edit->curs1);		    edit_scroll_screen_over_cursor (edit);		    if (replace_backwards)			edit->search_start--;		    else			edit->search_start++;		} else if (edit->search_start == -3) {		    edit->search_start = edit->curs1;		    regexp_error (edit);		} else {		    edit->search_start = edit->curs1;		    edit_error_dialog (_ (" Search "), _ (" Search string not found. "));		}	    }	}	free (exp);    }    edit->force |= REDRAW_COMPLETELY;    edit_scroll_screen_over_cursor (edit);}/* Real edit only */void edit_quit_cmd (WEdit * edit){    edit_push_action (edit, KEY_PRESS + edit->start_display);#ifndef MIDNIGHT    if (edit->stopped)	return;#endif    edit->force |= REDRAW_COMPLETELY;    if (edit->modified) {#ifdef GTK	char *r;	r = gtk_dialog_cauldron (_ (" Quit "), GTK_CAULDRON_TOPLEVEL | GTK_CAULDRON_GRAB, " [ ( %Lxf )xf ]xf / ( %Bgxfq || %Bgxfq || %Bgxfq ) ",				     _ (" Current text was modified without a file save. \n Save with exit? "), GNOME_STOCK_BUTTON_CANCEL, GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO);	if (!strcmp (r, GNOME_STOCK_BUTTON_YES)) {	    edit_push_markers (edit);	    edit_set_markers (edit, 0, 0, 0, 0);	    if (!edit_save_cmd (edit))		return;	} else if (!strcmp (r, GNOME_STOCK_BUTTON_NO)) {	    if (edit->delete_file)		unlink (catstrs (edit->dir, edit->filename, 0));	} else {	    return;	}#else#ifdef MIDNIGHT	switch (edit_query_dialog3 (_ (" Quit "), _ (" File was modified, Save with exit? "), _ ("Cancel quit"), _ ("&Yes"), _ ("&No"))) {#else/* Confirm 'Quit' dialog box */	switch (edit_query_dialog3 (_ (" Quit "),				    _ (" Current text was modified without a file save. \n Save with exit? "), _ (" &Cancel quit "), _ (" &Yes "), _ (" &No "))) {#endif	case 1:	    edit_push_markers (edit);	    edit_set_markers (edit, 0, 0, 0, 0);	    if (!edit_save_cmd (edit))		return;	    break;	case 2:#ifdef MIDNIGHT	    if (edit->delete_file)		unlink (catstrs (edit->dir, edit->filename, 0));#endif	    break;	case 0:	case -1:	    return;	}#endif    }#if defined(MIDNIGHT) || defined(GTK)    else if (edit->delete_file)	unlink (catstrs (edit->dir, edit->filename, 0));#endif#ifdef MIDNIGHT    dlg_stop (edit->widget.parent);#else#ifdef GTK    {           extern char *edit_one_file;           if (edit_one_file)                   gtk_main_quit ();    }#endif    edit->stopped = 1;#endif}#define TEMP_BUF_LEN 1024/* returns a null terminated length of text. Result must be free'd */unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l){    unsigned char *s, *r;    r = s = malloc (finish - start + 1);    if (column_highlighting) {	*l = 0;	while (start < finish) {	/* copy from buffer, excluding chars that are out of the column 'margins' */	    int c, x;	    x = edit_move_forward3 (edit, edit_bol (edit, start), 0, start);	    c = edit_get_byte (edit, start);	    if ((x >= edit->column1 && x < edit->column2)	     || (x >= edit->column2 && x < edit->column1) || c == '\n') {		*s++ = c;		(*l)++;	    }	    start++;	}    } else {	*l = finish - start;	while (start < finish)	    *s++ = edit_get_byte (edit, start++);    }    *s = 0;    return r;}/* save block, returns 1 on success */int edit_save_block (WEdit * edit, const char *filename, long start, long finish){    int len, file;    if ((file = open ((char *) filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)	return 0;    if (column_highlighting) {	unsigned char *block, *p;	int r;	p = block = edit_get_block (edit, start, finish, &len);	while (len) {	    r = write (file, p, len);	    if (r < 0)		break;	    p += r;	    len -= r;	}	free (block);    } else {	unsigned char *buf;	int i = start, end;	len = finish - start;	buf = malloc (TEMP_BUF_LEN);	while (start != finish) {	    end = min (finish, start + TEMP_BUF_LEN);	    for (; i < end; i++)		buf[i - start] = edit_get_byte (edit, i);	    len -= write (file, (char *) buf, end - start);	    start = end;	}	free (buf);    }    close (file);    if (len)	return 0;    return 1;}/* copies a block to clipboard file */static int edit_save_block_to_clip_file (WEdit * edit, long start, long finish){    return edit_save_block (edit, catstrs (home_dir, CLIP_FILE, 0), start, finish);}#ifndef MIDNIGHTvoid paste_text (WEdit * edit, unsigned char *data, unsigned int nitems){    if (data) {	data += nitems - 1;	while (nitems--)	    edit_insert_ahead (edit, *data--);    }    edit->force |= REDRAW_COMPLETELY;}char *selection_get_line (void *data, int line){    static unsigned char t[1024];    struct selection *s;    int i = 0;    s = (struct selection *) data;    line = (current_selection + line + 1) % NUM_SELECTION_HISTORY;    if (s[line].text) {	unsigned char *p = s[line].text;	int c, j;	for (j = 0; j < s[line].len; j++) {	    c = *p++;	    if (!isprint (c)) {		t[i++] = '_';		t[i++] = '\b';		t[i++] = '\\';		t[i++] 

⌨️ 快捷键说明

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