Re: [hatari-devel] SDL GUI file and directory selection |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] SDL GUI file and directory selection
- From: Andreas Grabher <andreas_g86@xxxxxxxxxx>
- Date: Tue, 18 Oct 2022 21:55:36 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1666122953; bh=ZCtyFB487omkJqG7cMllajvoytHdpRSanyImw09VRl0=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=kmUwKmV/jAQqG9NEZz6hkZ0TmGjkqo6BxOafWG0+xhbJibDLVi95YNjnU5/pA099n tOeODG84RKNyzvAC3hni7IT40kSoAVZFKIbBtZxwDFeKwH1Sk0rJjW+2llJQ6JMRMz 476dB0/Wiuoy6P0yWY8icZ2BsvCzdsqhTMZw4p/3flFPYSW2pPcgHUBdl9rd9zyeY5 IlcWAHmfPlZH1J4OljY06u1vxRXg2OO0icO4+9CZ/hPGmlp74VmN3IKXUvAC1Y+CLf +PdA+k50t1zxAsTg8e84WOtWaJ9jcZLqInpm3wA4pMQK9E/rC3f3yzN0dQhMhIsb7c 1jxwnoKUvQJwA==
Hello Eero,
thank you very much for the changes. Using Str_Copy() makes sense. May I suggest to change SdlGui_DirConfSelect() to SDLGui_DirConfSelect() for naming consistency?
I got one last question:
I noticed that File_MakeValidPathName() outputs just '\0‘ if the input is "/somefile" (some file selected in root directory). I think it should return "/" instead. It seems that the if-statement "if (pPathName[0])“ is causing that issue. I tried removing it and didn’t see any regression yet. Does anyone have an idea why this if-statement exists? The explanation of the function tells that empty strings should be left as-is. What does this mean? At least it does not seem to work properly.
Best wishes,
Andreas
> Am 18.10.2022 um 01:36 schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:
>
> Hi Andreas,
>
> I added the changes you suggested.
>
> On 15.10.2022 16.21, Andreas Grabher wrote:
>> Path is always valid (or '\0' in case of /somefile) after File_MakeValidPathName(). So SDLGui_DirSelect() can be further simplified like this:
>> bool SDLGui_DirSelect(char *dlgname, char *confname, int maxlen)
>> {
>> char *selname;
>> selname = SDLGui_FileSelect("Choose a folder", confname, NULL, NULL, false);
>> if (selname)
>> {
>> File_MakeValidPathName(selname);
>> strncpy(confname, selname, FILENAME_MAX);
>
> Either you:
> 1. trust selname to fit into confname, and use use strcpy(), but on all OSes FILENAME_MAX might not be enough for that
> * use strncpy() *and* zero terminate the string, or
> * use Str_Copy()
>
>
> => I opted for last, for consistency with the other fsel function.
>
>
>> File_ShrinkName(dlgname, selname, maxlen);
>> free(selname);
>> return true;
>> }
>> return false;
>> }
> ...
>>> I also suggest to rename SdlGui_DirSelect() to SDLGui_DirSelect() for matching the naming scheme of the other functions.
>
> Added "Conf" to function name for consistency.
>
>
> - Eero
>
>
>