PATCH: uicmd.cc prefs.save_dir cleanup

Jeremy Henty <onepoint-YprzHiG/[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
uicmd.cc exports a get()/set() interface to the default save directory
that is never used elsewhere,  and used only trivially internally.  It
also rereads  prefs.save_dir at  every save,  which is  redundant.  It
would be  simpler to  have an  init() interface  that is  called once.
There would be no change to the user.

Patch attached.  Thoughts?

Regards,

Jeremy Henty

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
uicmd_cleanup (text/plain, 2.8 KB)
# HG changeset patch
# Parent a2c7eb50a7e7d56479d0bbda155b12eb52a1cc21
uicmd.{hh,cc}: simplify by replacing a_UIcmd_{get,set}_save_dir() with a_UIcmd_init().

diff -r a2c7eb50a7e7 src/dillo.cc
--- a/src/dillo.cc	Thu Dec 27 09:13:34 2012 +0000
+++ b/src/dillo.cc	Thu Dec 27 09:38:34 2012 +0000
@@ -367,6 +367,7 @@
    a_Bw_init();
    a_Cookies_init();
    a_Auth_init();
+   a_UIcmd_init();
 
    dw::Textblock::setPenaltyHyphen (prefs.penalty_hyphen);
    dw::Textblock::setPenaltyHyphen2 (prefs.penalty_hyphen_2);
diff -r a2c7eb50a7e7 src/uicmd.cc
--- a/src/uicmd.cc	Thu Dec 27 09:13:34 2012 +0000
+++ b/src/uicmd.cc	Thu Dec 27 09:38:34 2012 +0000
@@ -61,7 +61,7 @@
 /*
  * Local data
  */
-static char *save_dir = NULL;
+static const char *save_dir = "";
 
 /*
  * Forward declarations
@@ -826,7 +826,7 @@
 {
    size_t MaxLen = 64;
    char *FileName, *newname, *o, *n;
-   const char *name, *dir = a_UIcmd_get_save_dir();
+   const char *name, *dir = save_dir;
 
    if ((name = strrchr(pathstr, '/'))) {
       if (strlen(++name) > MaxLen) {
@@ -840,31 +840,22 @@
                 i+=2, '_' : o[i];
       }
       *n = 0;
-      FileName = dStrconcat(dir ? dir : "", newname, NULL);
+      FileName = dStrconcat(dir, newname, NULL);
       dFree(newname);
    } else {
-      FileName = dStrconcat(dir ? dir : "", pathstr, NULL);
+      FileName = dStrconcat(dir, pathstr, NULL);
    }
    return FileName;
 }
 
 /*
- * Get the default directory for saving files.
- */
-const char *a_UIcmd_get_save_dir()
-{
-   return save_dir;
-}
-
-/*
  * Set the default directory for saving files.
  */
-void a_UIcmd_set_save_dir(const char *dir)
+void a_UIcmd_init(void)
 {
-   const char *p;
+   const char *p, *dir = prefs.save_dir;
 
    if (dir && (p = strrchr(dir, '/'))) {
-      dFree(save_dir);
       // assert a trailing '/'
       save_dir = dStrconcat(dir, (p[1] != 0) ? "/" : "", NULL);
    }
@@ -881,7 +872,6 @@
    const DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw));
 
    if (url) {
-      a_UIcmd_set_save_dir(prefs.save_dir);
       SuggestedName = UIcmd_make_save_filename(URL_PATH(url));
       name = a_Dialog_save_file("Save Page as File", NULL, SuggestedName);
       MSG("a_UIcmd_save: %s\n", name);
@@ -1013,8 +1003,6 @@
    const char *name;
    char *SuggestedName;
 
-   a_UIcmd_set_save_dir(prefs.save_dir);
-
    SuggestedName = UIcmd_make_save_filename(URL_STR(url));
    name = a_Dialog_save_file("Dillo: Save Link as File", NULL, SuggestedName);
    if (name) {
diff -r a2c7eb50a7e7 src/uicmd.hh
--- a/src/uicmd.hh	Thu Dec 27 09:13:34 2012 +0000
+++ b/src/uicmd.hh	Thu Dec 27 09:38:34 2012 +0000
@@ -59,8 +59,7 @@
 void a_UIcmd_close_bw(void *vbw);
 void a_UIcmd_close_all_bw(void *p);
 
-const char *a_UIcmd_get_save_dir();
-void a_UIcmd_set_save_dir(const char *dir);
+void a_UIcmd_init(void);
 
 
 // UI binding functions -------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.