prepared code to add a way to change the notes directory
[ptask.git] / src / note.c
index c5b225a..77f98cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2012-2013 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <log.h>
 #include <note.h>
 
-static char *get_path(const char *uuid)
+static char *get_default_path(const char *uuid)
 {
        char *home, *dir, *path;
 
        home = getenv("HOME");
 
        if (!home) {
-               fprintf(stderr, "HOME environment variable not defined\n");
+               log_err("HOME environment variable not defined");
                return NULL;
        }
 
@@ -48,6 +49,11 @@ static char *get_path(const char *uuid)
        return path;
 }
 
+static char *get_path(const char *uuid)
+{
+       return get_default_path(uuid);
+}
+
 void note_put(const char *uuid, const char *note)
 {
        char *path;
@@ -58,7 +64,7 @@ void note_put(const char *uuid, const char *note)
        if (!path)
                return ;
 
-       printf("note_put %s %s %s\n", path, uuid, note);
+       log_debug("note_put %s %s %s", path, uuid, note);
 
        f = fopen(path, "w");
 
@@ -66,7 +72,7 @@ void note_put(const char *uuid, const char *note)
                fwrite(note, 1, strlen(note), f);
                fclose(f);
        } else {
-               fprintf(stderr, "Failed to open %s\n", path);
+               log_err("Failed to open %s", path);
        }
 
        free(path);
@@ -99,7 +105,7 @@ char *note_get(const char *uuid)
                }
                fclose(f);
        } else {
-               fprintf(stderr, "Failed to open %s\n", path);
+               log_debug("%s does not exist or cannot be opened", path);
        }
 
        return str;