X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=filebrowser%2Fpath.c;h=a44a16677c6d68ee023f46fa332a660dae82aedb;hb=20e3f2756231ecf4af48cfd63e04e1932b2aaacc;hp=6379e79968a70609e0bff835d8fe6b2987519fda;hpb=373488935bf19680e26a3b51e617c9586dd438c6;p=xboard.git diff --git a/filebrowser/path.c b/filebrowser/path.c index 6379e79..a44a166 100644 --- a/filebrowser/path.c +++ b/filebrowser/path.c @@ -25,6 +25,8 @@ */ #include +#include /* for qsort */ +#include "../config.h" #ifdef SEL_FILE_IGNORE_CASE #include @@ -36,10 +38,21 @@ #include "xstat.h" #include -#if defined(SVR4) || defined(SYSV) || defined(USG) +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif /* ndef MAXPATHLEN */ + +#ifdef HAS_DIRENT_H extern uid_t getuid(); -extern void qsort(); -#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */ +#endif /* def HAS_DIRENT_H */ + +/* added missing prototypes */ +extern void SFtextChanged(); +extern int SFgetDir(SFDir *); +extern void SFdrawLists(int); +extern void SFdrawList(int, int); +extern void SFclearList(int, int); +extern void SFmotionList(Widget, int, XMotionEvent*); typedef struct { char *name; @@ -64,6 +77,8 @@ static SFLogin *SFlogins; static int SFtwiddle = 0; +void SFsetText(char *path); + int SFchdir(path) char *path; @@ -75,14 +90,14 @@ SFchdir(path) if (strcmp(path, SFcurrentDir)) { result = chdir(path); if (!result) { - (void) strcpy(SFcurrentDir, path); + (void) strncpy(SFcurrentDir, path, MAXPATHLEN); } } return result; } -static +static void SFfree(i) int i; { @@ -103,17 +118,19 @@ SFfree(i) XtFree(dir->dir); dir->dir = NULL; + return; } -static +static void SFstrdup(s1, s2) char **s1; char *s2; { *s1 = strcpy(XtMalloc((unsigned) (strlen(s2) + 1)), s2); + return; } -static +static void SFunreadableDir(dir) SFDir *dir; { @@ -125,6 +142,7 @@ SFunreadableDir(dir) dir->entries[0].shown = dir->entries[0].real; dir->nEntries = 1; dir->nChars = strlen(cannotOpen); + return; } #ifdef SEL_FILE_IGNORE_CASE @@ -172,7 +190,24 @@ SFstrncmp(p, q, n) } #endif /* def SEL_FILE_IGNORE_CASE */ -static +void +SFsetText(path) + char *path; +{ + XawTextBlock text; + + text.firstPos = 0; + text.length = strlen(path); + text.ptr = path; + text.format = FMT8BIT; + + XawTextReplace(selFileField, 0, strlen(SFtextBuffer), &text); + XawTextSetInsertionPoint(selFileField, strlen(SFtextBuffer)); + + return; +} + +static void SFreplaceText(dir, str) SFDir *dir; char *str; @@ -193,6 +228,7 @@ SFreplaceText(dir, str) } SFtextChanged(); + return; } static void @@ -356,7 +392,7 @@ SFfindFile(dir, str) return 0; } -static +static void SFunselect() { SFDir *dir; @@ -367,6 +403,7 @@ SFunselect() } dir->beginSelection = -1; dir->endSelection = -1; + return; } static int @@ -376,7 +413,7 @@ SFcompareLogins(p, q) return strcmp(p->name, q->name); } -static +static void SFgetHomeDirs() { struct passwd *pw; @@ -441,17 +478,13 @@ SFgetHomeDirs() SFhomeDir.beginSelection = -1 ; SFhomeDir.endSelection = -1 ; -#if defined(SVR4) || defined(SYSV) || defined(USG) - qsort((char *) entries, (unsigned)i, sizeof(SFEntry), SFcompareEntries); - qsort((char *) SFlogins, (unsigned)i, sizeof(SFLogin), SFcompareLogins); -#else /* defined(SVR4) || defined(SYSV) || defined(USG) */ - qsort((char *) entries, i, sizeof(SFEntry), SFcompareEntries); - qsort((char *) SFlogins, i, sizeof(SFLogin), SFcompareLogins); -#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */ + qsort((char *) entries, (size_t)i, sizeof(SFEntry), SFcompareEntries); + qsort((char *) SFlogins, (size_t)i, sizeof(SFLogin), SFcompareLogins); for (i--; i >= 0; i--) { (void) strcat(entries[i].real, "/"); } + return; } static int @@ -469,8 +502,9 @@ SFfindHomeDir(begin, end) if (!strcmp(SFhomeDir.entries[i].real, begin)) { *end = save; SFstrdup(&theRest, end); - (void) strcat(strcat(strcpy(SFcurrentPath, - SFlogins[i].dir), "/"), theRest); + (void) strcat(strcat(strncpy(SFcurrentPath,SFlogins[i].dir, + MAXPATHLEN), "/"), + theRest); XtFree(theRest); SFsetText(SFcurrentPath); SFtextChanged(); @@ -483,6 +517,7 @@ SFfindHomeDir(begin, end) return 0; } +void SFupdatePath() { static int alloc; @@ -670,20 +705,7 @@ SFupdatePath() } } } -} - -SFsetText(path) - char *path; -{ - XawTextBlock text; - - text.firstPos = 0; - text.length = strlen(path); - text.ptr = path; - text.format = FMT8BIT; - - XawTextReplace(selFileField, 0, strlen(SFtextBuffer), &text); - XawTextSetInsertionPoint(selFileField, strlen(SFtextBuffer)); + return; } /* ARGSUSED */ @@ -693,6 +715,10 @@ SFbuttonPressList(w, n, event) int n; XButtonPressedEvent *event; { + int dir = 0; + if(event->button == Button4) dir = -2; // kludge to indicate relative motion + if(event->button == Button5) dir = -1; + if(dir) SFvSliderMovedCallback(w, n, dir); else SFbuttonPressed = 1; } @@ -704,7 +730,9 @@ SFbuttonReleaseList(w, n, event) XButtonReleasedEvent *event; { SFDir *dir; + static int lastClick; + if(event->button == Button4 || event->button == Button5) return; // [HGM] mouse wheel does not select SFbuttonPressed = 0; if (SFcurrentInvert[n] != -1) { @@ -717,8 +745,10 @@ SFbuttonReleaseList(w, n, event) dir, dir->entries[dir->vOrigin + SFcurrentInvert[n]].shown ); - SFmotionList(w, n, event); + SFmotionList(w, n, (XMotionEvent *) event); + if(lastClick == 256*n + SFcurrentInvert[n]) SFstatus = SEL_FILE_OK; // [HGM] double click implies OK } + lastClick = 256*n + SFcurrentInvert[n]; } static int @@ -795,6 +825,25 @@ SFcheckDir(n, dir) return 0; } +/* Return a single character describing what kind of file STATBUF is. */ + +char +SFstatChar (statBuf) + struct stat *statBuf; +{ + if (S_ISDIR (statBuf->st_mode)) { + return '/'; + } else if (S_ISREG (statBuf->st_mode)) { + return S_ISXXX (statBuf->st_mode) ? '*' : ' '; +#ifdef S_ISSOCK + } else if (S_ISSOCK (statBuf->st_mode)) { + return '='; +#endif /* S_ISSOCK */ + } else { + return ' '; + } +} + static int SFcheckFiles(dir) SFDir *dir; @@ -879,22 +928,3 @@ SFdirModTimer(cl, id) SFdirModTimerId = XtAppAddTimeOut(SFapp, (unsigned long) 1000, SFdirModTimer, (XtPointer) NULL); } - -/* Return a single character describing what kind of file STATBUF is. */ - -char -SFstatChar (statBuf) - struct stat *statBuf; -{ - if (S_ISDIR (statBuf->st_mode)) { - return '/'; - } else if (S_ISREG (statBuf->st_mode)) { - return S_ISXXX (statBuf->st_mode) ? '*' : ' '; -#ifdef S_ISSOCK - } else if (S_ISSOCK (statBuf->st_mode)) { - return '='; -#endif /* S_ISSOCK */ - } else { - return ' '; - } -}