summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-11-06 01:05:13 +0100
committerGravatar Tom Willemsen2012-11-06 01:05:13 +0100
commit4faee6984ff621b8bd314992694cae6dcac66978 (patch)
tree8584827b4faccf14efae96d24cde2e5b48cf8eda
parent350d3466256450b12341f4a7131ed76800790a53 (diff)
downloadsite-4faee6984ff621b8bd314992694cae6dcac66978.tar.gz
site-4faee6984ff621b8bd314992694cae6dcac66978.zip
Add "HI" archive post
-rw-r--r--posts/HI.mdwn68
1 files changed, 68 insertions, 0 deletions
diff --git a/posts/HI.mdwn b/posts/HI.mdwn
new file mode 100644
index 0000000..bbe4e31
--- /dev/null
+++ b/posts/HI.mdwn
@@ -0,0 +1,68 @@
+
+<p>Since I have nothing better to say and still want to say something,
+here is some nonsense:
+</p>
+<p>
+I've been having an issue with loading configuration and data files.
+The problem is that I like the <a href="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG Base Directory Specification</a> and am
+trying to write my software in such a way that it supports both this
+and the usual(/old) folder in <code>$HOME</code> approach.
+</p>
+<p>
+This doesn't sound all that difficult, nor is it, but still I was
+making a lot of mistakes with it, because I don't just want to support
+something, I don't want to force whomever (nobody but me, really) uses
+my software to be forced in to anything. So first I need to check if
+the XDG environment variables exist, if they do then I have to see if
+the file I want to load exists in that directory, if it doesn't and
+one does exist in <code>$HOME</code> I want that one, but if the one in home
+doesn't exist either, I want the one in the XDG folder again. It gets
+messy.
+</p>
+<p>
+I feel that I may have it now, though&hellip;
+</p>
+
+
+[[!format el """
+(define (stored-file xdg-env file)
+ "Try to get FILE stored either in XDG-ENV or the home directory."
+ (let ((xdg (getenv xdg-env))
+ (stored-file (string-append
+ (getenv "HOME") "/.project/" file)))
+ (unless (or (file-exists? stored-file) (not xdg))
+ (set! stored-file (string-append xdg "/project/" file)))
+ stored-file))
+
+(define (config-file file)
+ (stored-file "XDG_CONFIG_HOME"))
+
+(define (data-file file)
+ (stored-file "XDG_DATA_HOME"))
+
+(define (rc-file)
+ (config-file "rc.scm"))
+
+(define (list-file)
+ (data-file "list.scm"))
+"""]]
+
+<p>
+The <code>stored-file</code> function first assumes that we will want to grab it
+from the directory in <code>$HOME</code>, when it can't verify that <i>that</i> particular
+file exists and knows that the XDG variable isn't empty it will
+instead return a reference to the file in that directory.
+</p>
+<p>
+All the other functions are just there to make it clear and convenient
+to load these files and not specifically necessary. The good part of
+this function, in my opinion, is that is separates configuration and
+data files from each other in code, but will just grab it all from the
+same directory when working with the <code>$HOME</code> directory. This, of
+course, can create naming conflicts, but if you have naming conflicts
+this way you might get confused by what you're doing here or there
+anyway.
+</p>
+
+[[!meta date="2012-10-03 02:35:41"]]
+[[!tag scheme xdg coding]]