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

📄 look-next.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
/* look-cool.c - look 'n feel type: COOL   Copyright (C) 1996-2000 Paul Sheer   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   02111-1307, USA. */#include <config.h>#include <stdio.h>#include <my_string.h>#include <stdlib.h>#include <stdarg.h>#include <X11/Intrinsic.h>#include "lkeysym.h"#include "stringtools.h"#include "app_glob.c"#include "coolwidget.h"#include "coollocal.h"#include "mad.h"#ifdef NEXT_LOOKextern struct look *look;/* {{{ search replace dialog */extern int replace_scanf;extern int replace_regexp;extern int replace_all;extern int replace_prompt;extern int replace_whole;extern int replace_case;extern int replace_backwards;extern int search_create_bookmark;static void look_next_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option){    Window win;    XEvent xev;    CEvent cev;    CState s;    int xh, yh, h, xb, ys, yc, yb, yr;    CWidget *m;    int text_input_width ;    CBackupState (&s);    CDisable ("*");    win = CDrawHeadedDialog ("replace", parent, x, y, heading);    CGetHintPos (&xh, &h);    xh += WINDOW_EXTRA_SPACING ;/* NLS hotkey ? */    CIdent ("replace")->position = WINDOW_ALWAYS_RAISED;/* An input line comes after the ':' */    (CDrawText ("replace.t1", win, xh, h, _(" Enter search text : ")))->hotkey = 'E';    CGetHintPos (0, &yh);    (m = CDrawTextInput ("replace.sinp", win, xh, yh, 10, AUTO_HEIGHT, 8192, *search_text))->hotkey = 'E';    if (replace_text) {	CGetHintPos (0, &yh);	(CDrawText ("replace.t2", win, xh, yh, _(" Enter replace text : ")))->hotkey = 'n';	CGetHintPos (0, &yh);	(CDrawTextInput ("replace.rinp", win, xh, yh, 10, AUTO_HEIGHT, 8192, *replace_text))->hotkey = 'n';	CSetToolHint ("replace.t2", _("You can enter regexp substrings with %s\n(not \\1, \\2 like sed) then use \"Enter...order\""));	CSetToolHint ("replace.rinp", _("You can enter regexp substrings with %s\n(not \\1, \\2 like sed) then use \"Enter...order\""));	CGetHintPos (0, &yh);	(CDrawText ("replace.t3", win, xh, yh, _(" Enter argument (or substring) order : ")))->hotkey = 'o';	CGetHintPos (0, &yh);	(CDrawTextInput ("replace.ainp", win, xh, yh, 10, AUTO_HEIGHT, 256, *arg_order))->hotkey = 'o';/* Tool hint */	CSetToolHint ("replace.ainp", _("Enter the order of replacement of your scanf\nformat specifiers or regexp substrings, eg 3,1,2"));	CSetToolHint ("replace.t3", _("Enter the order of replacement of your scanf\nformat specifiers or regexp substrings, eg 3,1,2"));    }    CGetHintPos (0, &yh);    ys = yh;/* The following are check boxes */    CDrawSwitch ("replace.ww", win, xh, yh, replace_whole, _(" Whole words only "), 0);    CGetHintPos (0, &yh);    CDrawSwitch ("replace.case", win, xh, yh, replace_case, _(" Case sensitive "), 0);    yc = yh;    CGetHintPos (0, &yh);    CDrawSwitch ("replace.reg", win, xh, yh, replace_regexp, _(" Regular expression "), 1);    CSetToolHint ("replace.reg", _("See the regex man page for how\nto compose a regular expression"));    CSetToolHint ("replace.reg.label", _("See the regex man page for how\nto compose a regular expression"));    yb = yh;    CGetHintPos (0, &yh);    CGetHintPos (&xb, 0);    xb += WINDOW_EXTRA_SPACING ;    if (option & SEARCH_DIALOG_OPTION_BACKWARDS) {	CDrawSwitch ("replace.bkwd", win, xh, yh, replace_backwards, _(" Backwards "), 0);/* Tool hint */	CSetToolHint ("replace.bkwd", _("Warning: Searching backward can be slow"));	CSetToolHint ("replace.bkwd.label", _("Warning: Searching backward can be slow"));    }    if (replace_text) {	yr = ys;	if (option & SEARCH_DIALOG_OPTION_BACKWARDS)	    yr = yc;    } else {	if (option & SEARCH_DIALOG_OPTION_BACKWARDS) {	    if (option & SEARCH_DIALOG_OPTION_BOOKMARK)		yr = yb;	    else		yr = yh;	} else {	    if (option & SEARCH_DIALOG_OPTION_BOOKMARK)		yr = yc;	    else		yr = yb;	}    }    if (replace_text) {	CDrawSwitch ("replace.pr", win, xb, yr, replace_prompt, _(" Prompt on replace "), 0);/* Tool hint */	CSetToolHint ("replace.pr", _("Ask before making each replacement"));	CGetHintPos (0, &yr);	CDrawSwitch ("replace.all", win, xb, yr, replace_all, _(" Replace all "), 0);/* Tool hint */	CSetToolHint ("replace.all", _("Replace repeatedly"));	CGetHintPos (0, &yr);    }    if (option & SEARCH_DIALOG_OPTION_BOOKMARK) {	CDrawSwitch ("replace.bkmk", win, xb, yr, search_create_bookmark, _(" Bookmarks "), 0);/* Tool hint */	CSetToolHint ("replace.bkmk", _("Create bookmarks at all lines found"));	CSetToolHint ("replace.bkmk.label", _("Create bookmarks at all lines found"));	CGetHintPos (0, &yr);    }    CDrawSwitch ("replace.scanf", win, xb, yr, replace_scanf, _(" Scanf expression "), 1);/* Tool hint */    CSetToolHint ("replace.scanf", _("Allows entering of a C format string,\nsee the scanf man page"));    get_hint_limits (&x, &y);    {      int btn_width, x, y ;	CGetHintPos (&x, &y);		y += WINDOW_EXTRA_SPACING * 2 ;	x += WINDOW_EXTRA_SPACING * 2 ;	CTextSize (&btn_width, 0, " Cancel ");	btn_width += 4 + BUTTON_RELIEF * 2;        x -= (btn_width + WINDOW_EXTRA_SPACING) * 2 + WINDOW_EXTRA_SPACING;	CDrawButton ("replace.ok", win, x+btn_width + WINDOW_EXTRA_SPACING * 2, y, AUTO_WIDTH, AUTO_HEIGHT, "   Ok   ");	CDrawButton ("replace.cancel", win, x, y, AUTO_WIDTH, AUTO_HEIGHT, " Cancel ");	CGetHintPos (0, &y);	x += (btn_width + WINDOW_EXTRA_SPACING) * 2 + WINDOW_EXTRA_SPACING;	reset_hint_pos (x, y + WINDOW_EXTRA_SPACING*2);    }/* Tool hint */    CSetToolHint ("replace.ok", _("Begin search, Enter"));    CSetToolHint ("replace.cancel", _("Abort this dialog, Esc"));    CSetSizeHintPos ("replace");    CMapDialog ("replace");    m = CIdent ("replace");    text_input_width = m->width - WIDGET_SPACING * 3 - 4 - WINDOW_EXTRA_SPACING*2 ;    CSetWidgetSize ("replace.sinp", text_input_width, (CIdent ("replace.sinp"))->height);    if (replace_text) {	CSetWidgetSize ("replace.rinp", text_input_width, (CIdent ("replace.rinp"))->height);	CSetWidgetSize ("replace.ainp", text_input_width, (CIdent ("replace.ainp"))->height);    }    CFocus (CIdent ("replace.sinp"));    for (;;) {	CNextEvent (&xev, &cev);	if (!CIdent ("replace")) {	    *search_text = 0;	    break;	}	if (!strcmp (cev.ident, "replace.cancel") || cev.command == CK_Cancel) {	    *search_text = 0;	    break;	}	if (!strcmp (cev.ident, "replace.reg") || !strcmp (cev.ident, "replace.scanf")) {	    if (CIdent ("replace.reg")->keypressed || CIdent ("replace.scanf")->keypressed) {		if (!(CIdent ("replace.case")->keypressed)) {		    CIdent ("replace.case")->keypressed = 1;		    CExpose ("replace.case");		}	    }	}	if (!strcmp (cev.ident, "replace.ok") || cev.command == CK_Enter) {	    if (replace_text) {		replace_all = CIdent ("replace.all")->keypressed;		replace_prompt = CIdent ("replace.pr")->keypressed;		*replace_text = (char *) strdup (CIdent ("replace.rinp")->text);		*arg_order = (char *) strdup (CIdent ("replace.ainp")->text);	    }	    *search_text = (char *) strdup (CIdent ("replace.sinp")->text);	    replace_whole = CIdent ("replace.ww")->keypressed;	    replace_case = CIdent ("replace.case")->keypressed;	    replace_scanf = CIdent ("replace.scanf")->keypressed;	    replace_regexp = CIdent ("replace.reg")->keypressed;	    if (option & SEARCH_DIALOG_OPTION_BACKWARDS) {		replace_backwards = CIdent ("replace.bkwd")->keypressed;	    } else {		replace_backwards = 0;	    }	    if (option & SEARCH_DIALOG_OPTION_BOOKMARK) {		search_create_bookmark = CIdent ("replace.bkmk")->keypressed;	    } else {		search_create_bookmark = 0;	    }	    break;	}    }    CDestroyWidget ("replace");    CRestoreState (&s);}/* }}} search replace dialog *//* {{{ file list stuff */#if 0static char *dname (struct dirent *directentry);#endif#ifdef HAVE_STRFTIME/* We want our own dates for NLS */#undef HAVE_STRFTIME#endif#undef gettext_noop#define gettext_noop(x) xvoid get_file_time (char *timestr, time_t file_time, int l);#if 0static char **get_filelist_line (void *data, int line_number, int *num_fields, int *tagged){    struct file_entry *directentry;    static char *fields[10], size[24], mode[12], timestr[32];    static char name[520], *n;    mode_t m;    *num_fields = 4;		/* name, size, date, mode only (for the mean time) */    directentry = (struct file_entry *) data;    if (directentry[line_number].options & FILELIST_LAST_ENTRY)	return 0;    n = name;    strcpy (name, directentry[line_number].name);    fields[0] = name;    sprintf (size, "\t%u", (unsigned int) directentry[line_number].stat.st_size);    fields[1] = size;    get_file_time (timestr, directentry[line_number].stat.st_mtime, 0);    fields[2] = timestr;    memset (mode, ' ', 11);    mode[11] = 0;    mode[0] = '-';    m = directentry[line_number].stat.st_mode;    switch ((int) m & S_IFMT) {    case S_IFLNK:	mode[0] = 'l';	break;    case S_IFDIR:	mode[0] = 'd';	break;    case S_IFCHR:	mode[0] = 'c';	break;    case S_IFBLK:	mode[0] = 'b';	break;    case S_IFIFO:	mode[0] = 'f';	break;    case S_IFSOCK:	mode[0] = 's';	break;    }    mode[1] = m & S_IRUSR ? 'r' : '-';    mode[2] = m & S_IWUSR ? 'w' : '-';    mode[3] = m & S_IXUSR ? 'x' : '-';    mode[4] = m & S_IRGRP ? 'r' : '-';    mode[5] = m & S_IWGRP ? 'w' : '-';    mode[6] = m & S_IXGRP ? 'x' : '-';    mode[7] = m & S_IROTH ? 'r' : '-';    mode[8] = m & S_IWOTH ? 'w' : '-';    mode[9] = m & S_IXOTH ? 'x' : '-';    if (S_ISLNK (m)) {	int l, i;	char *p;	p = directentry[line_number].name;	l = strlen (n);	for (i = 0; i < l; i++) {	    *n++ = '\b';	    *n++ = *p++;	}	*n++ = '\0';    } else if (m & (S_IXUSR | S_IXGRP | S_IXOTH)) {	int l, i;	char *p;	p = directentry[line_number].name;	l = strlen (n);	for (i = 0; i < l; i++) {	    *n++ = '\r';	    *n++ = *p++;	}	*n++ = '\0';    }    fields[3] = mode;    fields[*num_fields] = 0;    if (directentry[line_number].options & FILELIST_TAGGED_ENTRY)	*tagged = 1;    return fields;}#endifstatic char *get_filelist_line_short (void *data, int line_number, char buffer[512]){    struct file_entry *directentry;    static char ctimestr[32], mtimestr[32];    mode_t m;    char *ptr;    unsigned long size_bytes;    directentry = (struct file_entry *) data;    if (directentry[line_number].options & FILELIST_LAST_ENTRY)	return 0;    buffer[0] = 6;    strncpy (&(buffer[1]), directentry[line_number].name, 256);    ptr = &(buffer[strlen (buffer)]);    sprintf (ptr, "%c\nMode: %c", 27, 9);    ptr += strlen (ptr);    m = directentry[line_number].stat.st_mode;    switch ((int) m & S_IFMT) {    case S_IFLNK:	*ptr = 'l';	break;    case S_IFDIR:	*ptr = 'd';	break;    case S_IFCHR:	*ptr = 'c';	break;    case S_IFBLK:	*ptr = 'b';	break;    case S_IFIFO:	*ptr = 'f';	break;    case S_IFSOCK:	*ptr = 's';	break;    default:	*ptr = '-';    }    ptr++;    *(ptr++) = m & S_IRUSR ? 'r' : '-';    *(ptr++) = m & S_IWUSR ? 'w' : '-';    *(ptr++) = m & S_IXUSR ? 'x' : '-';    *(ptr++) = m & S_IRGRP ? 'r' : '-';    *(ptr++) = m & S_IWGRP ? 'w' : '-';    *(ptr++) = m & S_IXGRP ? 'x' : '-';    *(ptr++) = m & S_IROTH ? 'r' : '-';    *(ptr++) = m & S_IWOTH ? 'w' : '-';    *(ptr++) = m & S_IXOTH ? 'x' : '-';    size_bytes = directentry[line_number].stat.st_size;    sprintf (ptr, "%c ; Size: [%c%9lu%c] bytes or [%c%6lu%c] KBytes", 27, 7, size_bytes, 27, 7, size_bytes >> 10, 27);    ptr += strlen (ptr);    get_file_time (ctimestr, directentry[line_number].stat.st_ctime, 0);    get_file_time (mtimestr, directentry[line_number].stat.st_mtime, 0);    sprintf (ptr, "\nCreated on: %c%s%c ; Modified on: %c%s%c", 1, ctimestr, 27, 1, mtimestr, 27);    return buffer;}static Bool is_directory (struct file_entry * directentry, int line_number){    if (directentry[line_number].options & FILELIST_LAST_ENTRY)	return False;    switch ((int) (directentry[line_number].stat.st_mode) & S_IFMT) {    case S_IFLNK:	/* fixme : add check if it is linked to dir or file */	return True;    case S_IFDIR:	return True;    }    return False;}typedef struct FilelistCache {    Pixmap cache;    unsigned int width, height;    unsigned int firstline, hilited;    int current;    unsigned int rowheight;    unsigned long options;} FilelistCache;static void free_filelist_cache (void *vcache){    if (vcache) {	FilelistCache *cache = (FilelistCache *) vcache;	if (cache->cache) {	    XFreePixmap (CDisplay, cache->cache);	    cache->cache = None;	}	free (vcache);    }}#define NEXT_ARROW_SIZE  	8#define NEXT_ARROW_FIELD 	(NEXT_ARROW_SIZE*2)static void restrict_text_area (FilelistCache * cache){    XRectangle clip_rec;    clip_rec.x = 1;    clip_rec.y = 1;    clip_rec.width = cache->width - NEXT_ARROW_FIELD;    clip_rec.height = cache->height - 2;    XSetClipRectangles (CDisplay, CGC, 0, 0, &clip_rec, 1, YXSorted);}static void push_filelist_line (FilelistCache * cache, Bool pushed){    int y1, y2;    if (cache->current < 0)	return;    y1 = (cache->current - cache->firstline) * cache->rowheight;    y2 = y1 + cache->rowheight;    if (y1 < cache->height && y2 > 0) {	if (pushed)	    CSetColor (COLOR_BLACK);	else	    CSetColor ((cache->hilited == cache->current) ? color_wdiget (15) : COLOR_FLAT);	CLine (cache->cache, 0, y2, 0, y1);

⌨️ 快捷键说明

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