--- hatari/src/gui-sdl/dlgFileSelect.c 2019/04/01 07:13:50 1.1.1.4 +++ hatari/src/gui-sdl/dlgFileSelect.c 2019/04/09 08:47:27 1.1.1.7 @@ -6,7 +6,7 @@ A file selection dialog for the graphical user interface for Hatari. */ -const char DlgFileSelect_rcsid[] = "Hatari $Id: dlgFileSelect.c,v 1.1.1.4 2019/04/01 07:13:50 root Exp $"; +const char DlgFileSelect_fileid[] = "Hatari dlgFileSelect.c : " __DATE__ " " __TIME__; #include #include @@ -76,7 +76,7 @@ static SGOBJ fsdlg[] = { SGTEXT, SG_EXIT, 0, 2,21, DLGFILENAMES_SIZE,1, dlgfilenames[15] }, { SGBUTTON, SG_TOUCHEXIT, 0, 62,6, 1,1, "\x01" }, /* Arrow up */ { SGBUTTON, SG_TOUCHEXIT, 0, 62,21, 1,1, "\x02" }, /* Arrow down */ - { SGCHECKBOX, SG_EXIT, SG_SELECTED, 2,23, 18,1, "Show hidden files" }, + { SGCHECKBOX, SG_EXIT, 0, 2,23, 18,1, "Show hidden files" }, { SGBUTTON, SG_DEFAULT, 0, 32,23, 8,1, "Okay" }, { SGBUTTON, SG_CANCEL, 0, 50,23, 8,1, "Cancel" }, { -1, 0, 0, 0,0, 0,0, NULL } @@ -84,16 +84,16 @@ static SGOBJ fsdlg[] = static int ypos; /* First entry number to be displayed */ -static BOOL refreshentries; /* Do we have to update the file names in the dialog? */ +static bool refreshentries; /* Do we have to update the file names in the dialog? */ static int entries; /* How many files are in the actual directory? */ /*-----------------------------------------------------------------------*/ /* Update the file name strings in the dialog. - Returns FALSE if it failed, TRUE on success. + Returns false if it failed, true on success. */ -static int DlgFileSelect_RefreshEntries(struct dirent **files, char *path, BOOL browsingzip) +static int DlgFileSelect_RefreshEntries(struct dirent **files, char *path, bool browsingzip) { int i; char *tempstr = malloc(FILENAME_MAX); @@ -101,7 +101,7 @@ static int DlgFileSelect_RefreshEntries( if (!tempstr) { perror("DlgFileSelect_RefreshEntries"); - return FALSE; + return false; } /* Copy entries to dialog: */ @@ -127,7 +127,7 @@ static int DlgFileSelect_RefreshEntries( { if( stat(tempstr, &filestat)==0 && S_ISDIR(filestat.st_mode) ) dlgfilenames[i][0] = SGFOLDER; /* Mark folders */ - if (ZIP_FileNameIsZIP(tempstr) && browsingzip == FALSE) + if (ZIP_FileNameIsZIP(tempstr) && browsingzip == false) dlgfilenames[i][0] = SGFOLDER; /* Mark .ZIP archives as folders */ } } @@ -136,7 +136,7 @@ static int DlgFileSelect_RefreshEntries( } free(tempstr); - return TRUE; + return true; } @@ -194,7 +194,7 @@ static void DlgFileSelect_ScrollUp(void) if (ypos > 0) { --ypos; - refreshentries = TRUE; + refreshentries = true; } } @@ -208,7 +208,7 @@ static void DlgFileSelect_ScrollDown(voi if (ypos+SGFS_NUMENTRIES < entries) { ++ypos; - refreshentries = TRUE; + refreshentries = true; } } @@ -252,7 +252,7 @@ static void DlgFileSelect_HandleSdlEvent if (ypos < 0) ypos = 0; if (ypos != oldypos) - refreshentries = TRUE; + refreshentries = true; } @@ -326,27 +326,26 @@ static void correct_zip_root(char *zippa Returns path/name user selected or NULL if user canceled input: zip_path = pointer's pointer to buffer to contain file path within a selected zip file, or NULL if browsing zip files is disallowed. - bAllowNew: TRUE if the user is allowed to insert new file names. + bAllowNew: true if the user is allowed to insert new file names. */ -char* SDLGui_FileSelect(const char *path_and_name, char **zip_path, BOOL bAllowNew) +char* SDLGui_FileSelect(const char *path_and_name, char **zip_path, bool bAllowNew) { struct dirent **files = NULL; char *pStringMem; char *retpath; char *home, *path, *fname; /* The actual file and path names */ - BOOL reloaddir = TRUE; /* Do we have to reload the directory file list? */ + bool reloaddir = true; /* Do we have to reload the directory file list? */ int retbut; int oldcursorstate; int selection = -1; /* The actual selection, -1 if none selected */ char *zipfilename; /* Filename in zip file */ char *zipdir; - BOOL browsingzip = FALSE; /* Are we browsing an archive? */ + bool browsingzip = false; /* Are we browsing an archive? */ zip_dir *zipfiles = NULL; SDL_Event sdlEvent; - struct stat filestat; ypos = 0; - refreshentries = TRUE; + refreshentries = true; entries = 0; /* Allocate memory for the file and path name strings: */ @@ -356,6 +355,8 @@ char* SDLGui_FileSelect(const char *path zipdir = pStringMem + 2 * FILENAME_MAX; zipfilename = pStringMem + 3 * FILENAME_MAX; zipfilename[0] = 0; + fname[0] = 0; + path[0] = 0; SDLGui_CenterDlg(fsdlg); if (bAllowNew) @@ -375,21 +376,16 @@ char* SDLGui_FileSelect(const char *path strncpy(path, path_and_name, FILENAME_MAX); path[FILENAME_MAX-1] = '\0'; } - else + if (!File_DirExists(path)) { - if (!getcwd(path, FILENAME_MAX)) + File_SplitPath(path, path, fname, NULL); + if (!(File_DirExists(path) || getcwd(path, FILENAME_MAX))) { - perror("SDLGui_FileSelect"); + perror("SDLGui_FileSelect: non-existing path and CWD failed"); return NULL; } } - if (stat(path, &filestat) == 0 && S_ISDIR(filestat.st_mode)) - { - File_AddSlashToEndFileName(path); - fname[0] = 0; - } - else - File_SplitPath(path, path, fname, NULL); + File_MakeAbsoluteName(path); File_MakeValidPathName(path); File_ShrinkName(dlgpath, path, DLGPATH_SIZE); @@ -426,12 +422,12 @@ char* SDLGui_FileSelect(const char *path { fprintf(stderr, "SDLGui_FileSelect: Path not found.\n"); free(pStringMem); - return FALSE; + return NULL; } /* reload always implies refresh */ - reloaddir = FALSE; - refreshentries = TRUE; + reloaddir = false; + refreshentries = true; }/* reloaddir */ /* Update the file name strings in the dialog? */ @@ -440,9 +436,9 @@ char* SDLGui_FileSelect(const char *path if (!DlgFileSelect_RefreshEntries(files, path, browsingzip)) { free(pStringMem); - return FALSE; + return NULL; } - refreshentries = FALSE; + refreshentries = false; } /* Show dialog: */ @@ -458,17 +454,17 @@ char* SDLGui_FileSelect(const char *path { perror("Error while allocating temporary memory in SDLGui_FileSelect()"); free(pStringMem); - return FALSE; + return NULL; } - if (browsingzip == TRUE) + if (browsingzip == true) { if (!strcat_maxlen(tempstr, FILENAME_MAX, zipdir, files[retbut-SGFSDLG_ENTRY1+ypos]->d_name)) { fprintf(stderr, "SDLGui_FileSelect: Path name too long!\n"); free(pStringMem); - return FALSE; + return NULL; } /* directory? */ if (File_DoesFileNameEndWithSlash(tempstr)) @@ -484,7 +480,7 @@ char* SDLGui_FileSelect(const char *path zipfiles = NULL; /* Copy the path name to the dialog */ File_ShrinkName(dlgpath, path, DLGPATH_SIZE); - browsingzip = FALSE; + browsingzip = false; } else { @@ -500,7 +496,7 @@ char* SDLGui_FileSelect(const char *path strcpy(zipdir, tempstr); File_ShrinkName(dlgpath, zipdir, DLGPATH_SIZE); } - reloaddir = TRUE; + reloaddir = true; /* Copy the path name to the dialog */ selection = -1; /* Remove old selection */ zipfilename[0] = '\0'; @@ -523,16 +519,16 @@ char* SDLGui_FileSelect(const char *path { fprintf(stderr, "SDLGui_FileSelect: Path name too long!\n"); free(pStringMem); - return FALSE; + return NULL; } - if (stat(tempstr, &filestat) == 0 && S_ISDIR(filestat.st_mode)) + if (File_DirExists(tempstr)) { File_HandleDotDirs(tempstr); File_AddSlashToEndFileName(tempstr); /* Copy the path name to the dialog */ File_ShrinkName(dlgpath, tempstr, DLGPATH_SIZE); strcpy(path, tempstr); - reloaddir = TRUE; + reloaddir = true; selection = -1; /* Remove old selection */ dlgfname[0] = 0; ypos = 0; @@ -541,15 +537,15 @@ char* SDLGui_FileSelect(const char *path { /* open a zip file */ zipfiles = ZIP_GetFiles(tempstr); - if (zipfiles != NULL && browsingzip == FALSE) + if (zipfiles != NULL && browsingzip == false) { selection = retbut-SGFSDLG_ENTRY1+ypos; strcpy(fname, files[selection]->d_name); File_ShrinkName(dlgfname, fname, DLGFNAME_SIZE); - browsingzip = TRUE; + browsingzip = true; zipdir[0] = '\0'; /* zip root */ File_ShrinkName(dlgpath, zipdir, DLGPATH_SIZE); - reloaddir = TRUE; + reloaddir = true; ypos = 0; } @@ -579,7 +575,7 @@ char* SDLGui_FileSelect(const char *path { /* free zip file entries */ ZIP_FreeZipDir(zipfiles); - browsingzip = FALSE; + browsingzip = false; zipfiles = NULL; File_ShrinkName(dlgpath, path, DLGPATH_SIZE); } @@ -597,7 +593,7 @@ char* SDLGui_FileSelect(const char *path File_PathShorten(path, 1); File_ShrinkName(dlgpath, path, DLGPATH_SIZE); } - reloaddir = TRUE; + reloaddir = true; break; case SGFSDLG_HOMEDIR: /* Change to home directory */ @@ -609,12 +605,12 @@ char* SDLGui_FileSelect(const char *path /* free zip file entries */ ZIP_FreeZipDir(zipfiles); zipfiles = NULL; - browsingzip = FALSE; + browsingzip = false; } strcpy(path, home); File_AddSlashToEndFileName(path); File_ShrinkName(dlgpath, path, DLGPATH_SIZE); - reloaddir = TRUE; + reloaddir = true; break; case SGFSDLG_ROOTDIR: /* Change to root directory */ @@ -623,11 +619,11 @@ char* SDLGui_FileSelect(const char *path /* free zip file entries */ ZIP_FreeZipDir(zipfiles); zipfiles = NULL; - browsingzip = FALSE; + browsingzip = false; } - strcpy(path, "/"); + path[0] = PATHSEP; path[1] = '\0'; strcpy(dlgpath, path); - reloaddir = TRUE; + reloaddir = true; break; case SGFSDLG_UP: /* Scroll up */ DlgFileSelect_ScrollUp(); @@ -641,7 +637,7 @@ char* SDLGui_FileSelect(const char *path strcpy(fname, dlgfname); break; case SGFSDLG_SHOWHIDDEN: /* Show/hide hidden files */ - reloaddir = TRUE; + reloaddir = true; ypos = 0; break; case SDLGUI_UNKNOWNEVENT: @@ -694,12 +690,12 @@ char* SDLGui_FileSelect(const char *path * If bAllowNew is true, user can select new files also. * * If no file is selected, or there's some problem with the file, - * return FALSE and clear dlgname & confname. - * Otherwise return TRUE, set dlgname & confname to the new file name + * return false and clear dlgname & confname. + * Otherwise return true, set dlgname & confname to the new file name * (dlgname is shrinked & limited to maxlen and confname is assumed * to have FILENAME_MAX amount of space). */ -BOOL SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, BOOL bAllowNew) +bool SDLGui_FileConfSelect(char *dlgname, char *confname, int maxlen, bool bAllowNew) { char *selname; @@ -718,7 +714,7 @@ BOOL SDLGui_FileConfSelect(char *dlgname dlgname[0] = confname[0] = 0; } free(selname); - return TRUE; + return true; } - return FALSE; + return false; }