X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=filebrowser%2Fselfile.c;h=2e3495589291cf45700edfcd2816971b1d3453b0;hb=715e33a60133ac9ac76b3aa0a5cf6f14f0f3930f;hp=c0a2ce270e417b9a2bc0b0fa1853e826961c4b1d;hpb=18c9024957df2892adb21cd851cb7a27b9502d54;p=xboard.git diff --git a/filebrowser/selfile.c b/filebrowser/selfile.c index c0a2ce2..2e34955 100644 --- a/filebrowser/selfile.c +++ b/filebrowser/selfile.c @@ -61,6 +61,16 @@ extern int errno; #include #include "selfile.h" +#include "xstat.h" + +/* added missing prototypes */ +extern void SFdrawList(int,int); +extern void SFinitFont(); +extern void SFcreateGC(); +extern int SFchdir(char *); +extern void SFupdatePath(); +extern void SFsetText(char *); +extern char SFstatChar(struct stat*); #ifndef MAXPATHLEN #define MAXPATHLEN 1024 @@ -129,6 +139,8 @@ XtIntervalId SFdirModTimerId; int (*SFfunc)(); +Boolean SFpathFlag; // [HGM] + static char *oneLineTextEditTranslations = "\ Return: redraw-display()\n\ CtrlM: redraw-display()\n\ @@ -146,7 +158,7 @@ SFexposeList(w, n, event, cont) return; } - SFdrawList(n, SF_DO_NOT_SCROLL); + SFdrawList((int)(intptr_t)n, SF_DO_NOT_SCROLL); } /* ARGSUSED */ @@ -418,9 +430,9 @@ SFcreateWidgets(toplevel, prompt, ok, cancel) scrollbarWidgetClass, selFileLists[n], arglist, i); XtAddCallback(selFileVScrolls[n], XtNjumpProc, - SFvFloatSliderMovedCallback, (XtPointer) n); + SFvFloatSliderMovedCallback, (XtPointer)(intptr_t) n); XtAddCallback(selFileVScrolls[n], XtNscrollProc, - SFvAreaSelectedCallback, (XtPointer) n); + SFvAreaSelectedCallback, (XtPointer)(intptr_t) n); i = 0; @@ -435,9 +447,9 @@ SFcreateWidgets(toplevel, prompt, ok, cancel) scrollbarWidgetClass, selFileLists[n], arglist, i); XtAddCallback(selFileHScrolls[n], XtNjumpProc, - SFhSliderMovedCallback, (XtPointer) n); + SFhSliderMovedCallback, (XtPointer)(intptr_t) n); XtAddCallback(selFileHScrolls[n], XtNscrollProc, - SFhAreaSelectedCallback, (XtPointer) n); + SFhAreaSelectedCallback, (XtPointer)(intptr_t) n); } i = 0; @@ -496,17 +508,17 @@ SFcreateWidgets(toplevel, prompt, ok, cancel) for (n = 0; n < NR; n++) { XtAddEventHandler(selFileLists[n], ExposureMask, True, - SFexposeList, (XtPointer) n); + SFexposeList, (XtPointer)(intptr_t) n); XtAddEventHandler(selFileLists[n], EnterWindowMask, False, - SFenterList, (XtPointer) n); + SFenterList, (XtPointer)(intptr_t) n); XtAddEventHandler(selFileLists[n], LeaveWindowMask, False, - SFleaveList, (XtPointer) n); + SFleaveList, (XtPointer)(intptr_t) n); XtAddEventHandler(selFileLists[n], PointerMotionMask, False, - SFmotionList, (XtPointer) n); + SFmotionList, (XtPointer)(intptr_t) n); XtAddEventHandler(selFileLists[n], ButtonPressMask, False, - SFbuttonPressList, (XtPointer) n); + SFbuttonPressList, (XtPointer)(intptr_t) n); XtAddEventHandler(selFileLists[n], ButtonReleaseMask, False, - SFbuttonReleaseList, (XtPointer) n); + SFbuttonReleaseList, (XtPointer)(intptr_t) n); } XtAddEventHandler(selFileField, KeyPressMask, False, @@ -593,11 +605,11 @@ SFtextChanged() { if ((SFtextBuffer[0] == '/') || (SFtextBuffer[0] == '~')) { - (void) strcpy(SFcurrentPath, SFtextBuffer); + (void) strncpy(SFcurrentPath, SFtextBuffer, MAXPATHLEN); SFtextPos = XawTextGetInsertionPoint(selFileField); } else { - (void) strcat(strcpy(SFcurrentPath, SFstartDir), SFtextBuffer); + (void) strcat(strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN), SFtextBuffer); SFtextPos = XawTextGetInsertionPoint(selFileField) + strlen(SFstartDir); @@ -666,6 +678,12 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed, cancel = "Cancel"; } + if(SFpathFlag != (mode && mode[0] == 'p')) { // [HGM] ignore everything that is not a directory + if(SFdirs) XtFree(SFdirs); + SFdirs = NULL; // kludge to throw away all cached info + SFpathFlag = !SFpathFlag; + } + if (firstTime) { firstTime = 0; SFdisplay = XtDisplay(toplevel); @@ -697,11 +715,11 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed, XtAppError(SFapp, "XsraSelFile: can't get current directory"); } (void) strcat(SFstartDir, "/"); - (void) strcpy(SFcurrentDir, SFstartDir); + (void) strncpy(SFcurrentDir, SFstartDir, MAXPATHLEN); if (init_path) { if (init_path[0] == '/') { - (void) strcpy(SFcurrentPath, init_path); + (void) strncpy(SFcurrentPath, init_path, MAXPATHLEN); if (strncmp( SFcurrentPath, SFstartDir, @@ -712,12 +730,12 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed, SFsetText(&(SFcurrentPath[strlen(SFstartDir)])); } } else { - (void) strcat(strcpy(SFcurrentPath, SFstartDir), + (void) strcat(strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN), init_path); SFsetText(&(SFcurrentPath[strlen(SFstartDir)])); } } else { - (void) strcpy(SFcurrentPath, SFstartDir); + (void) strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN); } SFfunc = show_entry; @@ -739,6 +757,10 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed, break; case SEL_FILE_OK: *name_return = SFgetText(); + if(mode && (mode[0] == 'p' || mode[0] == 'f')) { // [HGM] for use in file-option browse button + SFprepareToReturn(); + return stderr; + } if (fp = SFopenFile(*name_return, mode, prompt, failed)) { SFprepareToReturn();