nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] proposal to add support for the XDG base directory spec


From: Benno Schulenberg
Subject: Re: [Nano-devel] proposal to add support for the XDG base directory spec
Date: Tue, 24 Oct 2017 20:00:35 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0


Op 21-10-2017 om 13:29 schreef Simon Ochsenreither:
Please have a look at the updated patch and tell me what you think!

The functions histfilename() and poshistfilename() are identical,
apart from the basename of the file.  So it's obvious what that
should become: a single function with a parameter.

+    retval = create_xdgdata_nano_directory_if_not_existing(nanodatadir);

This function is called just once, and is right after where it is
called.  Just remove the free(), the return, and the closing brace
and let the code run on.

        get_homedir();
-       if (homedir == NULL || !have_dotnano()) {
+       if (homedir == NULL || (!have_dotnano() &&
                                !have_or_created_xdgdata_nano())) {

If the user doesn't have an actual home directory, but XDG_DATA_HOME
does point to a place where the user has write access, then that place
should be used.  So those two lines should become a single line:

        if (!have_statedir()) {

The same argument goes for XDG_CONFIG_HOME.  So the "Wah!" message
should only be given when none of the three possible config dirs is
available.

+    stat(file, &rcinfo);
+
+    if (access(file, R_OK) != 0) {
+       /* file does not exist or is not readable */
+       return FALSE;
+    } else if (stat(file, &rcinfo) != -1 && (S_ISDIR(rcinfo.st_mode) ||

There is no need to stat() a file before calling access() on it.  Nor
is there any need for an 'else' keyword if the 'then' part returns.
Which means that you can leave more code untouched.

+       nanorc = charealloc(nanorc, strlen(homedir) + strlen(RCFILE_NAME) + 3);
+       sprintf(nanorc, "%s/.%s", homedir, RCFILE_NAME);
+       if (is_good_file(nanorc)) {
+           parse_one_nanorc();

Something similar happens three times in a row.  Better press it into
a small function.

+           if (xdgconfdir != NULL) {

You only try the fallback config dir when XDG_CONFIG_HOME is *set*.
That is not right.

Benno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]