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

📄 source.c

📁 如果RH
💻 C
📖 第 1 页 / 共 3 页
字号:
	fileTable[i] = NULL;	close(fd);	return -1;    }    fileTable[i]->buf[n] = '\0';    fileTable[i]->pathname = XtNewString(pathname);    fileTable[i]->filename = XtNewString(filename);    fileTable[i]->currentline = 1;    fileTable[i]->topline = 1;    fileTable[i]->bottomline = 0;    fileTable[i]->topPosition = 0;    BuildLinePos(fileTable[i]);    close(fd);    *file = fileTable[i];    return 0;}/*   *  Remember file position and current line before closing. */static void SaveDisplayedFileInfo(){    XawTextPosition pos;    if (displayedFile) {    	displayedFile->topPosition = XawTextTopPosition(sourceWindow);	pos = XawTextGetInsertionPoint(sourceWindow);	displayedFile->currentline = TextPositionToLine(pos);    }}/*   DisplayFile() displays the file onto the source window.  It *     uses topPosition to remember where it was last opened.  But it *     must recalculate bottomline because the window size might be *     different. */static void DisplayFile(file)FileRec *file;{    Arg 	args[MAXARGS];    Cardinal 	n;    TextWidget 	ctx = (TextWidget) sourceWindow;    n = 0;    XtSetArg(args[n], XtNdisplayPosition, (XtArgVal)file->topPosition);	n++;    XtSetArg(args[n], XtNstring, (XtArgVal) file->pathname);		n++;    XtSetArg(args[n], XtNeditType, (XtArgVal) XawtextRead);		n++;    XtSetValues(sourceWindow, args, n);    file->lines = ctx->text.lt.lines;    file->bottomline = MIN (file->topline + file->lines - 1, file->lastline);}/*  Given a filename starting with a tilde (`~'), it expands ~[user] to *  the home directory of that user, or to the login home directory if user *  is not specified. */static char *expand(filename)char *filename;{    struct passwd *pwd;    char 	  *string, *name, newfile[MAXNAME];    string = XtNewString(filename+1);    if (*string == '\0' || *string == '/')	name = (char *) getlogin();    else    	name = (char *) strtok(string, "/");    if (name == NULL)	return filename;    pwd = (struct passwd *) getpwnam(name);    if (pwd && pwd->pw_dir) {    	sprintf(newfile, "%s%s", pwd->pw_dir, filename+strlen(name)+1);    	return XtNewString(newfile);    }    else	return filename;}/*  Create a list of directories for searching source files. *  It reads the list of directories specified by the user, adding *  the current directory into the list if it is not already there. * *  With fix from Dave Gagne (daveg@fs1.ee.ubc.ca) 7/30/90 */void MakeDirList(output)char *output;{    /* fix bug where if text of a directories command is > 1k, crashes.  Now works to 4k */    char *s, list[LINESIZ], command[LINESIZ];    int  i, use_cwd;    for (i=0; dirList[i]; i++)			/* remove old list */	XtFree(dirList[i]);    i = 0;    use_cwd = TRUE;    if (output) {                                        /* create list */#ifdef GDB	/* GDB uses ':' as separator character */        s = (char *) strtok(output, ": \n");#else        s = (char *) strtok(output, " \n");#endif /* GDB */        while (s) {            dirList[i] = XtNewString(s);            if (dirList[i][0] == '~')                   /* expand '~' */                dirList[i] = expand(dirList[i]);            if (LASTCH(dirList[i]) == '/')              /* remove last '/' */                LASTCH(dirList[i]) = '\0';            if (strcmp(dirList[i], ".") == 0)        /* watch for "." */                use_cwd = FALSE;            ++i;#ifdef GDB	/* GDB uses ':' as separator character */            s = (char *) strtok(NULL, ": \n");#else            s = (char *) strtok(NULL, " \n");#endif /* GDB */        }        dirList[i] = NULL;    }    if (use_cwd) {				/* include current dir */	dirList[i++] = XtNewString(".");		    	dirList[i] = NULL;    }#if defined(NeXT) && defined(GDB)	/* for NeXT computer, send 'directory' command for each directory */    for (i=0; dirList[i]; i++) {    sprintf(command, "directory %s\n", dirList[i]);    query_gdb (command, PARSE_OFF | ECHO_OFF | FILTER_OFF);    }#else /* not NeXT */    strcpy(list, "");				/* tell dbx our new list */    for (i=0; dirList[i]; i++) {	strcat(list, dirList[i]);	strcat(list, " ");    }#ifdef GDB    sprintf(command, "directory %s\n", list);    query_gdb (command, PARSE_OFF | ECHO_OFF | FILTER_OFF);#else    sprintf(command, "use %s\n", list);    Parse = False;    query_dbx(command);#endif /* GDB */#endif /* not NeXT */}/*  Returns the full pathname of a given file. *  It searches for the file from a list of directories. */char *GetPathname(filename)char *filename;{    char	pathname[LINESIZ];    int 	i;    if (filename == NULL || strcmp(filename, "") == 0)		return NULL;    for (i=0; dirList[i]; i++) {		if (*filename == '/' && access(filename, R_OK) == -1) { 			/* this handles the exceptional case of sun4 dbx output */			strcpy(filename, &filename[1]);		}		if (*filename == '/' || *filename == '~')			strcpy(pathname, filename);		else if (strcmp(dirList[i], ".") == 0)			sprintf(pathname, "%s/%s", cwd, filename);	     #ifdef GDB	/* (PW)(SH)11SEP91 : for gdb 4.0 */		else if (strcmp(dirList[i], "$cwd") == 0)			sprintf(pathname, "%s/%s", cwd, filename);		else if (strcmp(dirList[i], "$cdir") == 0)			sprintf(pathname, "%s/%s", cdir, filename);#endif /* GDB */		else if (*dirList[i] == '/' || *dirList[i] == '~')			sprintf(pathname, "%s/%s", dirList[i], filename);		else			sprintf(pathname, "%s/%s/%s", cwd, dirList[i], filename);#ifdef GDB 		simplify_path (pathname);  /* be sure to get only significant path */#endif	     		if (access(pathname, R_OK) == 0) {			if (debug)				fprintf(stderr,"Full path of %s is \"%s\"\n", filename, pathname);			return XtNewString(pathname);		}		if (*filename == '/' || *filename == '~') {			break;	/* no need to loop over all directories */		}    }    UpdateMessageWindow("File not found: %s", filename);	bell(0);    return NULL;}/* * Given a file name, LoadFile attempts to open it and displays it onto * the source window: *   1. get the full pathname of the file *   2. LookUpFileTable() returns a pointer to the file's entry if it's *      already in the table; else, creates an entry and return a pointer. *   3. save the current displayedFile info *   4. display the file *   5. update the file label and the various signs on the source window. *  LoadFile returns 0 upon successful completion, -1 otherwise. */int LoadFile(filename)char *filename;{    FileRec 	*file;    char	*pathname;    pathname = GetPathname(filename);    if (pathname == NULL) { 	return -1;    }    if (LookUpFileTable(pathname, filename, &file) != -1) {	if (file) {	/* load new file */	    SaveDisplayedFileInfo();	    DisplayFile(file);	    UpdateFileLabel(pathname);	    XawTextUnsetSelection(sourceWindow);	    XawTextSetInsertionPoint(sourceWindow, file->linepos[file->currentline]);	    UpdateLineLabel(file->currentline);	    UpdateStops(file);	    UpdateArrow(file);	    UpdateUpdown(file);	    UpdateBomb(file);	    displayedFile = file;	}    	return 0;    }    else {		/* LookUpFileTable() fails */    	return -1;    }}int LoadCurrentFile(){#ifdef GDB    query_gdb ("info line\n", PARSE_ON | ECHO_OFF | FILTER_OFF);#else    query_dbx("file\n");#endif /* GDB */    return LoadFile(CurrentFile);}#ifdef EDIT_BUTTON/* simply add editor button that calls  $XXGDBWINEDIT, $WINEDIT, xxgdbedit in that order *//* allow invocation of fav. editor from within interface *//* button and the EdAction action procedure for the source window */void StartEditor (){  XawTextPosition pos;  char* editor;  char string[128];  int result;    if (displayedFile == NULL) return;  editor = (char *) getenv("XXGDBWINEDIT");  if (editor == NULL)    editor = (char *) getenv("WINEDIT");  if (editor == NULL)    editor = "xxgdbedit";  pos = XawTextGetInsertionPoint(sourceWindow);  displayedFile->currentline = TextPositionToLine(pos);  sprintf(string, "nohup %s +%d %s&\n",	  editor, displayedFile->currentline, displayedFile->pathname);  result =  system(string);  printf("result from system call: %d \n", result);  /* the following is more efficient but needs some work  {  int pid;  if (!(pid = fork()))    {       execlp(editor, editor, linenum, displayedFile->pathname, (char *) 0);      printf("editor command fails\n");    }  else     {      if (pid == -1) printf("unable to start editor\n");    }  }  */}#endif /* EDIT_BUTTON */#ifdef GDB/* * Function to get the full path of a source file. * * This function is implemented by doing a 'list sourcefile;1' * and then a 'info source'. That is the only way I found to * get this fullpath. If there is a better way, change here. * * Note that we have to save and restore the current source * file in case it is not the same as 'filename'. * */char *GetSourcePathname (filename)char *filename;{char *srcpath;char curr_src [MAXPATHLEN];char list_src_cmd [MAXPATHLEN+10]; /* +10 for room for "list :1\n" */    if (filename == NULL || strcmp(filename, "") == 0)	return NULL;	/* (PW)19NOV93: it is important to get new string because,	   "info source" below will free Token.file (which could be	   same as filename here.	   */	filename = XtNewString (filename);	/* get current source */	query_gdb("info source\n", PARSE_ON | ECHO_OFF | FILTER_OFF);		strcpy (curr_src, source_path);	if (*curr_src == 0)	{		srcpath = GetPathname (filename);	/* when info source is not supported */	} else {		/* tell gdb to go to filename */		sprintf (list_src_cmd,"list %s:1\n", filename);		query_gdb(list_src_cmd, PARSE_OFF | ECHO_OFF | FILTER_OFF);		/* get source of filename  */		query_gdb("info source\n", PARSE_ON | ECHO_OFF | FILTER_OFF);		if (*source_fullpath)			srcpath = XtNewString (source_fullpath);		else			srcpath = NULL;		/* reset original source */		sprintf (list_src_cmd,"list %s:1\n", curr_src);		query_gdb(list_src_cmd, PARSE_OFF | ECHO_OFF | FILTER_OFF);		if (srcpath == NULL)			srcpath = GetPathname (filename);	/* when info source is not supported */	}	XtFree (filename);	return 	srcpath;}#endif /* GDB */

⌨️ 快捷键说明

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