Do not give client to util functions.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 14 Apr 2018 20:42:56 +0000 (22:42 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 14 Apr 2018 20:44:04 +0000 (22:44 +0200)
Give only those information the util functions need to work.

src/ex.c
src/main.c
src/main.h
src/util.c
src/util.h

index 4ffd10d..3520b20 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -749,7 +749,7 @@ static gboolean parse_rhs(Client *c, const char **input, ExArg *arg)
      * EX_FLAG_CMD is not set also on | */
     while (**input && **input != '\n' && (cmdlist || **input != '|')) {
         /* check for expansion placeholder */
-        util_parse_expansion(c, input, arg->rhs, flags, "|\\");
+        util_parse_expansion(c->state, input, arg->rhs, flags, "|\\");
 
         if (VB_IS_SEPARATOR(**input)) {
             /* add tilde expansion for next loop needs to be first char or to
@@ -1245,7 +1245,7 @@ static gboolean complete(Client *c, short direction)
 
                 case EX_SAVE: /* Fallthrough */
                 case EX_SOURCE:
-                    found = util_filename_fill_completion(c, store, token);
+                    found = util_filename_fill_completion(c->state, store, token);
                     break;
 
 #ifdef FEATURE_AUTOCMD
index c12f648..aaddbef 100644 (file)
@@ -131,7 +131,7 @@ gboolean vb_download_set_destination(Client *c, WebKitDownload *download,
 
     /* Prepare the path to save the download. */
     if (path && *path) {
-        file = util_build_path(c, path, download_path);
+        file = util_build_path(c->state, path, download_path);
 
         /* if file is an directory append a file name */
         if (g_file_test(file, (G_FILE_TEST_IS_DIR))) {
@@ -140,7 +140,7 @@ gboolean vb_download_set_destination(Client *c, WebKitDownload *download,
             g_free(dir);
         }
     } else {
-        file = util_build_path(c, suggested_filename, download_path);
+        file = util_build_path(c->state, suggested_filename, download_path);
     }
 
     g_free(basename);
index b7a3402..ac23d0d 100644 (file)
@@ -119,6 +119,7 @@ enum {
 };
 
 typedef struct Client Client;
+typedef struct State State;
 typedef struct Map Map;
 typedef struct Mode Mode;
 typedef struct Arg Arg;
index 3ba4377..bef3800 100644 (file)
@@ -46,13 +46,13 @@ static gboolean match_list(const char *pattern, int patlen, const char *subject)
  *
  * Returned path must be freed.
  */
-char *util_build_path(Client *c, const char *path, const char *dir)
+char *util_build_path(State state, const char *path, const char *dir)
 {
     char *fullPath = NULL, *fexp, *dexp, *p;
     int expflags   = UTIL_EXP_TILDE|UTIL_EXP_DOLLAR;
 
     /* if the path could be expanded */
-    if ((fexp = util_expand(c, path, expflags))) {
+    if ((fexp = util_expand(state, path, expflags))) {
         if (*fexp == '/') {
             /* path is already absolute, no need to use given dir - there is
              * no need to free fexp, because this should be done by the caller
@@ -60,7 +60,7 @@ char *util_build_path(Client *c, const char *path, const char *dir)
             fullPath = fexp;
         } else if (dir && *dir) {
             /* try to expand also the dir given - this may be ~/path */
-            if ((dexp = util_expand(c, dir, expflags))) {
+            if ((dexp = util_expand(state, dir, expflags))) {
                 /* use expanded dir and append expanded path */
                 fullPath = g_build_filename(dexp, fexp, NULL);
                 g_free(dexp);
@@ -154,7 +154,7 @@ gboolean util_create_tmp_file(const char *content, char **file)
  *
  * Returned path must be g_freed.
  */
-char *util_expand(Client *c, const char *src, int expflags)
+char *util_expand(State state, const char *src, int expflags)
 {
     const char **input = &src;
     char *result;
@@ -162,7 +162,7 @@ char *util_expand(Client *c, const char *src, int expflags)
     int flags    = expflags;
 
     while (**input) {
-        util_parse_expansion(c, input, dst, flags, "\\");
+        util_parse_expansion(state, input, dst, flags, "\\");
         if (VB_IS_SEPARATOR(**input)) {
             /* after space the tilde expansion is allowed */
             flags = expflags;
@@ -513,7 +513,7 @@ gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src
  * Fills file path completion entries into given list store for also given
  * input.
  */
-gboolean util_filename_fill_completion(Client *c, GtkListStore *store, const char *input)
+gboolean util_filename_fill_completion(State state, GtkListStore *store, const char *input)
 {
     gboolean found = FALSE;
     GError *error  = NULL;
@@ -525,7 +525,7 @@ gboolean util_filename_fill_completion(Client *c, GtkListStore *store, const cha
     input_basename = last_slash ? last_slash + 1 : input;
     input_dirname  = g_strndup(input, input_basename - input);
     real_dirname   = util_expand(
-        c,
+        state,
         *input_dirname ? input_dirname : ".",
         UTIL_EXP_TILDE|UTIL_EXP_DOLLAR|UTIL_EXP_SPECIAL
     );
@@ -608,7 +608,7 @@ double util_js_result_as_number(WebKitJavascriptResult *result)
  * @quoteable: String of chars that are additionally escapable by \.
  * Returns TRUE if input started with expandable pattern.
  */
-gboolean util_parse_expansion(Client *c, const char **input, GString *str,
+gboolean util_parse_expansion(State state, const char **input, GString *str,
         int flags, const char *quoteable)
 {
     GString *name;
@@ -683,9 +683,9 @@ gboolean util_parse_expansion(Client *c, const char **input, GString *str,
         expanded = TRUE;
         g_string_free(name, TRUE);
     } else if (flags & UTIL_EXP_SPECIAL && **input == '%') {
-        if (*c->state.uri) {
+        if (state.uri) {
             /* TODO check for modifiers like :h:t:r:e */
-            g_string_append(str, c->state.uri);
+            g_string_append(str, state.uri);
             expanded = TRUE;
         }
     }
index ad27a12..14dc3bb 100644 (file)
@@ -30,11 +30,11 @@ enum {
 };
 typedef void *(*Util_Content_Func)(const char*, const char*);
 
-char *util_build_path(Client *c, const char *path, const char *dir);
+char *util_build_path(State state, const char *path, const char *dir);
 void util_cleanup(void);
 gboolean util_create_dir_if_not_exists(const char *dirpath);
 gboolean util_create_tmp_file(const char *content, char **file);
-char *util_expand(Client *c, const char *src, int expflags);
+char *util_expand(State state, const char *src, int expflags);
 gboolean util_file_append(const char *file, const char *format, ...);
 gboolean util_file_prepend(const char *file, const char *format, ...);
 void util_file_prepend_line(const char *file, const char *line,
@@ -47,10 +47,10 @@ char **util_get_lines(const char *filename);
 GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
         guint max_items);
 gboolean util_fill_completion(GtkListStore *store, const char *input, GList *src);
-gboolean util_filename_fill_completion(Client *c, GtkListStore *store, const char *input);
+gboolean util_filename_fill_completion(State state, GtkListStore *store, const char *input);
 char *util_js_result_as_string(WebKitJavascriptResult *result);
 double util_js_result_as_number(WebKitJavascriptResult *result);
-gboolean util_parse_expansion(Client *c, const char **input, GString *str,
+gboolean util_parse_expansion(State state, const char **input, GString *str,
         int flags, const char *quoteable);
 char *util_sanitize_filename(char *filename);
 char *util_sanitize_uri(const char *uri_str);