📄 filemenu.c
字号:
/***************************************************************************** * * xdbx - X Window System interface to the dbx debugger * * Copyright 1989 The University of Texas at Austin * Copyright 1990 Microelectronics and Computer Technology Corporation * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of The University of Texas * and Microelectronics and Computer Technology Corporation (MCC) not be * used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. The * University of Texas and MCC makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Po Cheung * Created: March 10, 1989 * ***************************************************************************** * * xxgdb - X Window System interface to the gdb debugger * * Copyright 1990,1993 Thomson Consumer Electronics, Inc. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of Thomson Consumer * Electronics (TCE) not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior * permission. TCE makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. * * TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT * SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * * Adaptation to GDB: Pierre Willard * XXGDB Created: December, 1990 * *****************************************************************************//* filemenu.c * * Construct a file menu (directory browser) which allows a user to go * up and down the directory tree, to select text files to display, and * to select executable files to debug. The file menu is popped up by * the 'file' command button. * Duane Voth (duanev@mcc.com) contributed to the layout of the file menu, * plus some code and ideas. * * changeDir(): Record the current working directory. * InList(): Select files to be displayed in the menu. * ScanDir(): Scan the directory and record selected filenames. * DisplayMenuFile(): Callback for the file menu. * CancelFileMenu(): Pop down the file menu. * SetUpFileMenu(): Create the file menu popupshell. * UpdateFileMenu(): Update entries in the file menu. * File(): Command callback for the 'file' command button. */#include <ctype.h>#include <X11/Xos.h>#include <sys/stat.h>#ifdef SYSV #include <stdio.h>#include <sys/param.h>#include <sys/types.h>#include <dirent.h>#ifdef _POSIX_SOURCE#ifndef S_IFDIR#define S_IFDIR 0040000 /* directory */#endif#ifndef S_IEXEC#define S_IEXEC 00100 /* execute/search permission, owner */#endif#endif /* _POSIX_SOURCE */#else /* SYSV */#ifdef SUNOS4#include <dirent.h>#else#include <sys/dir.h>#endif#endif /* SYSV */#include "global.h"#define MAXCOLUMNS 8 /* max number of columns in file menu */#define FILES_PER_COL 10 /* # of files per column in file menu */static char fileMenuDir[MAXPATHLEN];/* current directory of file menu */static char **filelist; /* list of file names in fileMenu */static int nfiles = 0; /* number of files in filelist */static Widget popupshell, /* parent of popup */ popup, /* vpane widget containing file menu */ fileMenu, /* list widget as file menu */ fileMenuLabel; /* label widget as file menu label */void File();static void UpdateFileMenu();/* Change working directory to 'dir'. * For Berkeley dbx, modify static global variable, cwd, to keep track of * current working directory. * For Sun dbx, change working directory of dbx. */static void changeDir(dir)char *dir;{ char command[LINESIZ]; char store[LINESIZ]; int i,j; if(!strcmp(dir, "./")) return;#if defined(BSD) if (dir[0] == '/' || dir[0] == '~') strcpy(cwd, dir); if (strcmp(dir, "../") == 0) { for (i=strlen(cwd); cwd[i] != '/' && i > 0; i--); cwd[i] = '\0'; if (strcmp(cwd, "") == 0) strcpy(cwd, "/"); } else { sprintf(cwd, "%s/%s", cwd, dir); LASTCH(cwd) = '\0'; }#else /* not BSD */ if(!strcmp(dir,"../")) { for(i=0,j=0; cwd[i]; i++) if(cwd[i]=='/')j++; if( j == 1 ) strcpy(store,"/"); else strcpy(store,".."); } else { if(!strcmp(cwd, "/"))cwd[0]='\0'; sprintf(store,"%s/%s", cwd, dir); LASTCH(store)='\0'; } sprintf(command, "cd %s\n", store);#ifdef GDB /* because silly gdb 4.0 displays nothing with cd command when confirm is on (possibly a gdb bug) , I just reset confirm to on just for this command !. */ if (new_gdb4()) query_gdb("set confirm on\n", PARSE_OFF | ECHO_OFF | FILTER_OFF); query_gdb(command, PARSE_ON | ECHO_OFF | FILTER_OFF); if (new_gdb4()) /* reset confirm to off */ query_gdb("set confirm off\n", PARSE_OFF | ECHO_OFF | FILTER_OFF);#else query_dbx(command);#endif /* not GDB */#endif /* BSD */}/* Determines if a directory entry should appear in the file menu. * The files included in the menu are : * .. (parent directory) * directories * text files * executable files */#ifndef SYSVstatic int InList(entry)Directory *entry;{ char pathname[LINESIZ]; struct stat statbuf; if (strcmp(entry->d_name, ".") == 0 || /* ignore current directory */ LASTCH(entry->d_name) == '~' || /* ignore Emacs backup files */ (LASTCH(entry->d_name) == 'o' && SECLASTCH(entry->d_name) == '.')) /* ignore object files */ return False; if (entry->d_name[0] == '.' && entry->d_name[1] != '.') return False; /* ignore hidden files */ if (strcmp(cwd, "")) /* give full path name */ sprintf(pathname, "%s/%s", cwd, entry->d_name); else strcpy(pathname, entry->d_name); if (stat(pathname, &statbuf) == -1) return False; if (statbuf.st_mode & S_IFDIR) { /* is directory */ strcat(entry->d_name, "/"); ++(entry->d_namlen); return True; } if (statbuf.st_mode & S_IEXEC) { /* is executable */ strcat(entry->d_name, "*"); ++(entry->d_namlen); return True; } return True;}#endif /* not SYSV *//* Scans the working directory for files selected by InList(), sorted * alphabetically, and stored in an array of pointers to directory * entries called namelist. * The names of the selected files are stored in filelist. */static void ScanDir(dir)char *dir;{#ifndef SYSV extern alphasort(); Directory **namelist;#else struct dirent *WorkingDirEntry; DIR *WorkingDir; char store[LINESIZ];#endif register int i,j;#ifdef SYSV if(!(WorkingDir = opendir(dir))) { UpdateMessageWindow("scandir: cannot open %s", dir); return; } nfiles=0; while(readdir(WorkingDir))nfiles++; rewinddir(WorkingDir);#else nfiles = scandir(dir, &namelist, InList, alphasort); if (nfiles == -1) { UpdateMessageWindow("scandir: cannot open %s", dir); return; }#endif if (filelist) { for (i=0; filelist[i]; i++) XtFree(filelist[i]); XtFree((void*)filelist); } filelist = (char **) XtMalloc((nfiles+1) * sizeof(char *)); i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -