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

📄 source.c

📁 如果RH
💻 C
📖 第 1 页 / 共 3 页
字号:
    XEvent *event;    String *params;    Cardinal *num_params;{  PopupSearch(w, NULL, NULL);}/*  *  On top of a form widget, we have a text widget with scrollbar, label *  widgets for the stop sign, arrow sign, and updown signs. *//* add popupsearch which is triggered by ^S in file window also add-editor switch which can be set to vi or emacs (default is emacs) andhave operative keys in the editor window for moving around (move stopsigns and such around too) */void CreateSourceWindow(parent)Widget parent;{    TextWidget ctx;    Arg args[MAXARGS];    Cardinal n;    static XtActionsRec sbar_actions[] = {        {"NotifyResize",   NotifyResize},        {"Update", 	   Update},        {NULL, NULL}    };    /* fixes keybindings in source window */    static XtActionsRec text_actions[] = {        {"Update", 	   Update},#ifdef EDIT_BUTTON        {"Editor",         EdAction},#endif		{"Search",         Search},        {NULL, NULL}    };#ifdef EDIT_BUTTON    static String eTextTranslations = "#override \n\        Ctrl<Key>V:    next-page() Update(warp) \n\        Meta<Key>V:    previous-page() Update(warp) \n\        Ctrl<Key>N:    next-line() Update() \n\        Ctrl<Key>P:    previous-line() Update() \n\        Ctrl<Key>Z:    scroll-one-line-up() Update(warp) \n\        Meta<Key>Z:    scroll-one-line-down() Update(warp) \n\        Meta<Key>]:    forward-paragraph() Update(warp) \n\        Meta<Key>[:    backward-paragraph() Update(warp) \n\        Meta<Key>F:    forward-word() Update() \n\        Meta<Key>B:    backward-word() Update() \n\        Ctrl<Key>F:    forward-character() Update() \n\        Ctrl<Key>B:    backward-character() Update() \n\        Meta<Key>E:    Editor() \n\        Meta<Key><:   beginning-of-file() Update(warp) \n\        Meta<Key>>:   end-of-file() Update(warp) \n\        <Key>L:        redraw-display() Update() \n\        <Key>S:        Search() Update() \n\        <Key>R:        Search() Update() \n\        <Btn1Down>:             SelectStart() SelectWord() \n\	Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \n\	<Btn1Up>:               Update() SelectEnd() \n\      ";      static String vTextTranslations = "#override \n\        Ctrl<Key>F:    next-page() Update(warp) \n\        Ctrl<Key>B:    previous-page() Update(warp) \n\        Ctrl<Key>D:    next-page() Update() \n\        Ctrl<Key>U:    previous-page() Update() \n\        <Key>Return:   next-line() Update() \n\        <Key>-:        previous-line() Update() \n\        <Key>j:        next-line() Update() \n\        <Key>k:        previous-line() Update() \n\        <Key>space:    forward-character() Update() \n\        <Key>BackSpace: backward-character() Update() \n\        <Key>1:        beginning-of-file() Update(warp) \n\        <Key>G:        end-of-file() Update(warp) \n\        <Key>E:        Editor() \n\        <Key>L:        redraw-display() Update() \n\        <Key>/:        Search() Update() \n\        <Key>?:        Search() Update() \n\        <Btn1Down>:             SelectStart() SelectWord() \n\	Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \n\	<Btn1Up>:               Update() SelectEnd() \n\    ";#else /* not EDIT_BUTTON */    static String eTextTranslations = "#override \n\        Ctrl<Key>V:    next-page() Update(warp) \n\        Meta<Key>V:    previous-page() Update(warp) \n\        Ctrl<Key>N:    next-line() Update() \n\        Ctrl<Key>P:    previous-line() Update() \n\        Ctrl<Key>Z:    scroll-one-line-up() Update(warp) \n\        Meta<Key>Z:    scroll-one-line-down() Update(warp) \n\        Meta<Key>]:    forward-paragraph() Update(warp) \n\        Meta<Key>[:    backward-paragraph() Update(warp) \n\        Meta<Key>F:    forward-word() Update() \n\        Meta<Key>B:    backward-word() Update() \n\        Ctrl<Key>F:    forward-character() Update() \n\        Ctrl<Key>B:    backward-character() Update() \n\        Meta<Key><:   beginning-of-file() Update(warp) \n\        Meta<Key>>:   end-of-file() Update(warp) \n\        <Key>L:        redraw-display() Update() \n\        <Key>S:        Search() Update() \n\        <Key>R:        Search() Update() \n\        <Btn1Down>:             SelectStart() SelectWord() \n\	Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \n\	<Btn1Up>:               Update() SelectEnd() \n\      ";      static String vTextTranslations = "#override \n\        Ctrl<Key>F:    next-page() Update(warp) \n\        Ctrl<Key>B:    previous-page() Update(warp) \n\        Ctrl<Key>D:    next-page() Update() \n\        Ctrl<Key>U:    previous-page() Update() \n\        <Key>Return:   next-line() Update() \n\        <Key>-:        previous-line() Update() \n\        <Key>j:        next-line() Update() \n\        <Key>k:        previous-line() Update() \n\        <Key>space:    forward-character() Update() \n\        <Key>BackSpace: backward-character() Update() \n\        <Key>1:        beginning-of-file() Update(warp) \n\        <Key>G:        end-of-file() Update(warp) \n\        <Key>L:        redraw-display() Update() \n\        <Key>/:        Search() Update() \n\        <Key>?:        Search() Update() \n\        <Btn1Down>:             SelectStart() SelectWord() \n\	Shift<Btn1Up>:          Update() SelectEnd() PrintSelection() \n\	<Btn1Up>:               Update() SelectEnd() \n\    ";#endif /* EDIT_BUTTON */    /* fixes keybindings in source window */    static String sbarTranslations = "\        <Configure>:    NotifyResize() \n\        <Btn2Down>:     StartScroll(Continuous) MoveThumb() NotifyThumb() \                        Update() \n\        <Btn2Motion>:   MoveThumb() NotifyThumb() Update() \n\        <BtnUp>:        NotifyScroll(Proportional) EndScroll() Update() \n\    ";    n = 0;    XtSetArg(args[n], XtNdefaultDistance, 0);                           n++;    sourceForm = XtCreateManagedWidget("sourceForm", formWidgetClass, 					 parent, args, n);    n = 0;    XtSetArg(args[n], XtNborderWidth, 0);				n++;    XtSetArg(args[n], XtNtype, (XtArgVal)XawAsciiFile);			n++;    XtSetArg(args[n], XtNstring, (XtArgVal)"/dev/null");		n++;    XtSetArg(args[n], XtNscrollVertical, (XtArgVal) XawtextScrollAlways);n++;    sourceWindow = XtCreateManagedWidget("sourceWindow", asciiTextWidgetClass,					  sourceForm, args, n);    ctx = (TextWidget) sourceWindow;    if (ctx->text.vbar)    	XtOverrideTranslations(ctx->text.vbar, 				XtParseTranslationTable(sbarTranslations));    XtAppAddActions(app_context, sbar_actions, XtNumber(sbar_actions));    /* fixes keybindings in source window */    XtAppAddActions(app_context, text_actions, XtNumber(text_actions));    if (app_resources.bindings && strcmp(app_resources.bindings, "vi") == 0)      XtOverrideTranslations((Widget) ctx, XtParseTranslationTable(vTextTranslations));    else      XtOverrideTranslations((Widget) ctx, XtParseTranslationTable(eTextTranslations));	/* setup tabulation */	if (app_resources.tabstop >= 0) {		int tab, tabs[256];		for (n = 0, tab = 0; n < sizeof tabs / sizeof *tabs; n++)			tabs[n] = (tab += app_resources.tabstop);		XawTextSinkSetTabs(ctx->text.sink, sizeof tabs / sizeof *tabs, tabs);	}}/* *  Build the array which gives the starting text position of each line. *  > Estimate the number of lines in the file and allocate memory buffer. *  > Starting position of line #1 is 0, and is stored in linepos[1]. *  > Search for '\n' till end of buffer. */static void BuildLinePos(file)FileRec *file;{    char *p;    int	 line, nlines;    nlines = MAX(1, file->filesize/CHARS_PER_LINE);    file->linepos = (XawTextPosition *)		    XtMalloc ((nlines+2) * sizeof(XawTextPosition));    p = file->buf;    line = 0;    file->linepos[line++] = 0;    file->linepos[line++] = 0;    while (*p) {	if (*p++ == '\n') {	    if (line == nlines) { 	/* buffer full, need more memory */                file->linepos = (XawTextPosition *) XtRealloc ((void*)file->linepos, 			  (nlines + ADD_LINES) * sizeof(XawTextPosition));		nlines += ADD_LINES;            }            file->linepos[line++] = p - file->buf;	}    }    file->lastline = line - 2;    file->linepos = (XawTextPosition *) XtRealloc 	/* shrink to min size */			((void*)file->linepos, line * sizeof(XawTextPosition));}/* * Function to check the file table. * This might be useful after a 'dir' or 'cd' command when * there might be another path to the same files. */static void CheckLookUpFileTable(){	int i;	char * newfullname;	for (i=0; fileTable && i<fileTableSize; i++)		{		if (fileTable[i] != NULL)			{			newfullname = GetPathname(fileTable[i]->filename);			if (newfullname != NULL)				{				/* if the two files are different, then it means there				is a new full path for this file. So we better forget				everything about the old file.				*/				if (strcmp (newfullname, fileTable[i]->pathname))					{					/* if filenames  are different */					if (debug)						fprintf (stderr, "Clearing file table entry \"%s\" : was \"%s\" : is \"%s\"\n",							fileTable[i]->filename,							fileTable[i]->pathname,							newfullname);					AppendDialogText("Warning : new path to \"");					AppendDialogText(fileTable[i]->filename);					AppendDialogText("\" is \"");					AppendDialogText(newfullname);					AppendDialogText("\".\n");					if (displayedFile ==  fileTable[i])					  	{						displayedFile = NULL;						}					XtFree((char *)fileTable[i]->buf);					XtFree((char *)fileTable[i]->linepos);					XtFree((char *)fileTable[i]);					fileTable[i] = NULL;					}				XtFree (newfullname);				}			}		}}/* * Function to clean up the file table and update the * display if necessary. * */void CleanUpFileTable (){	CheckLookUpFileTable();	if (displayedFile == NULL)		LoadCurrentFile();}/* * Look up the file table for an entry with "filename" * If not found, create an entry and initialize proper fields, * else, return pointer to entry found. */static int LookUpFileTable(pathname, filename, file)char *pathname, *filename;FileRec **file;{    struct stat fileinfo;    int  	fd;    int 	i, j, n;	int 	available;		available = -1;    for (i=0; fileTable && i<fileTableSize; i++) {	if (fileTable[i] == NULL) {		if (available != -1)			available = i;	} else {		if (strcmp(fileTable[i]->pathname, pathname) == 0) /* file found */			{	   		if (stat(pathname, &fileinfo) == -1)				{				UpdateMessageWindow("Error: cannot stat file %s", pathname);	        	*file = fileTable[i];				return 0;	    		}	    	if (fileinfo.st_mtime > fileTable[i]->mtime) /* file modified */				{				XtFree((char *)fileTable[i]->buf);				XtFree((char *)fileTable[i]->linepos);				XtFree((char *)fileTable[i]);				fileTable[i] = NULL;				UpdateMessageWindow("WARNING : file %s was modified", pathname);	    		}	    	if (displayedFile && 		/* same as displayed file */		     	strcmp(pathname, displayedFile->pathname) == 0)				{				if (fileTable[i] == NULL) /* means file was modified */					displayedFile = NULL;				else					{					*file = NULL;					return 0;	    			}				}	    	else				{	    		*file = fileTable[i];				return 0;	    		}	  		}		}    }    /* Record file into file table */    if (available == -1) {		/* file table full, enlarge it */	available = fileTableSize;	fileTableSize += ADD_SIZE;	fileTable = (FileRec **) 		     XtRealloc ((void*)fileTable, fileTableSize * sizeof(FileRec *));	for (j=available; j<fileTableSize; j++)	    fileTable[j] = NULL;    }    if ((fd = open(pathname, O_RDONLY)) == -1) {	UpdateMessageWindow("Error: cannot open file %s", pathname);	return -1;    }    if (fstat(fd, &fileinfo) == -1) {	UpdateMessageWindow("Error: cannot fstat file %s", pathname);	close(fd);	return -1;    }	i = available;    fileTable[i] = (FileRec *) XtMalloc (sizeof(FileRec));    fileTable[i]->filesize = fileinfo.st_size + 1;    fileTable[i]->mtime = fileinfo.st_mtime;    fileTable[i]->buf = XtMalloc((int)fileTable[i]->filesize);    if ((n = read(fd, fileTable[i]->buf, (int) fileTable[i]->filesize)) == -1) {	UpdateMessageWindow("Error: cannot read file %s", pathname);	XtFree(fileTable[i]->buf);	XtFree((void*)fileTable[i]);

⌨️ 快捷键说明

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