qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs dired.c qe.c qe.h shell.c util.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs dired.c qe.c qe.h shell.c util.c
Date: Sun, 26 Jun 2016 08:35:26 +0000 (UTC)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        16/06/26 08:35:26

Modified files:
        .              : dired.c qe.c qe.h shell.c util.c 

Log message:
        dired: improve current directory support
        
        - pass EditPane to canonicalize_absolute_path() to make current 
directory 
          context based.
        - use shell buffer context based directory for next-error.  Should 
actually
          use more context such as current position to compute current 
directory.
        - move canonicalize_absolute_path() and is_abs_path() from util.c to 
qe.c

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.67&r2=1.68
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.226&r2=1.227
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.219&r2=1.220
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.110&r2=1.111
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.72&r2=1.73

Patches:
Index: dired.c
===================================================================
RCS file: /sources/qemacs/qemacs/dired.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- dired.c     13 Jun 2016 17:12:35 -0000      1.67
+++ dired.c     26 Jun 2016 08:35:25 -0000      1.68
@@ -1263,7 +1263,7 @@
     pstrcpy(target, sizeof(target), s->b->filename);
 
     /* Set the filename to the directory of the current file */
-    canonicalize_absolute_path(filename, sizeof(filename), target);
+    canonicalize_absolute_path(s, filename, sizeof(filename), target);
     if (!is_directory(filename) && !is_filepattern(filename)) {
         p = strrchr(filename, '/');
         if (p)

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -b -r1.226 -r1.227
--- qe.c        13 Jun 2016 17:12:35 -0000      1.226
+++ qe.c        26 Jun 2016 08:35:25 -0000      1.227
@@ -447,7 +447,7 @@
 {
     char buf[MAX_FILENAME_SIZE];
 
-    canonicalize_absolute_path(buf, sizeof(buf), path);
+    canonicalize_absolute_path(s, buf, sizeof(buf), path);
 
     if (chdir(buf)) {
         put_status(s, "Cannot change directory to '%s'", buf);
@@ -5353,7 +5353,7 @@
 
     current = cp->current;
     if (*current == '~') {
-        canonicalize_absolute_path(filename, sizeof(filename), cp->current);
+        canonicalize_absolute_path(cp->s, filename, sizeof(filename), 
cp->current);
         current = filename;
     }
 
@@ -6125,6 +6125,70 @@
     do_refresh(qs->first_window);
 }
 
+/* return TRUE if absolute path. works for files and URLs */
+static int is_abs_path(const char *path)
+{
+    size_t prefix;
+
+    if (*path == '/')
+        return 1;
+
+    /* Accept as absolute a drive or protocol followed by `/` */
+    prefix = strcspn(path, "/:");
+    if (path[prefix] == ':' && path[prefix + 1] == '/')
+        return 1;
+    
+    return 0;
+}
+
+/* canonicalize the path for a given window and make it absolute */
+void canonicalize_absolute_path(EditState *s, char *buf, int buf_size, const 
char *path1)
+{
+    char cwd[MAX_FILENAME_SIZE];
+    char path[MAX_FILENAME_SIZE];
+    char *homedir;
+
+    if (!is_abs_path(path1)) {
+        if (*path1 == '~') {
+            if (path1[1] == '\0' || path1[1] == '/') {
+                homedir = getenv("HOME");
+                if (homedir) {
+                    pstrcpy(path, sizeof(path), homedir);
+#ifdef CONFIG_WIN32
+                    path_win_to_unix(path);
+#endif
+                    remove_slash(path);
+                    pstrcat(path, sizeof(path), path1 + 1);
+                    path1 = path;
+                }
+            } else {
+                /* CG: should get info from getpwnam */
+#ifdef CONFIG_DARWIN
+                pstrcpy(path, sizeof(path), "/Users/");
+#else
+                pstrcpy(path, sizeof(path), "/home/");
+#endif
+                pstrcat(path, sizeof(path), path1 + 1);
+                path1 = path;
+            }
+        } else {
+            /* CG: not sufficient for windows drives */
+            /* CG: should test result */
+            if (s) {
+                get_default_path(s, cwd, sizeof(cwd));
+            } else {
+                getcwd(cwd, sizeof(cwd));
+#ifdef CONFIG_WIN32
+                path_win_to_unix(cwd);
+#endif
+            }
+            makepath(path, sizeof(path), cwd, path1);
+            path1 = path;
+        }
+    }
+    canonicalize_path(buf, buf_size, path1);
+}
+
 /* compute default path for find/save buffer */
 char *get_default_path(EditState *s, char *buf, int buf_size)
 {
@@ -6144,7 +6208,8 @@
     } else {
         filename = s->b->filename;
     }
-    canonicalize_absolute_path(buf1, sizeof(buf1), filename);
+    /* XXX: should just retrieve the current directory */
+    canonicalize_absolute_path(NULL, buf1, sizeof(buf1), filename);
     splitpath(buf, buf_size, NULL, 0, buf1);
     return buf;
 }
@@ -6327,7 +6392,7 @@
         }
     } else {
         /* compute full name */
-        canonicalize_absolute_path(filename, sizeof(filename), filename1);
+        canonicalize_absolute_path(s, filename, sizeof(filename), filename1);
     }
 
 #ifndef CONFIG_TINY
@@ -6561,7 +6626,7 @@
 {
     char path[MAX_FILENAME_SIZE];
 
-    canonicalize_absolute_path(path, sizeof(path), filename);
+    canonicalize_absolute_path(s, path, sizeof(path), filename);
     if (*renamefile == 'y' && *s->b->filename) {
         if (rename(s->b->filename, path))
             put_status(s, "Cannot rename file to %s", path);
@@ -6603,7 +6668,7 @@
     /* deactivate region hilite */
     s->region_style = 0;
 
-    canonicalize_absolute_path(absname, sizeof(absname), filename);
+    canonicalize_absolute_path(s, absname, sizeof(absname), filename);
     put_save_message(s, filename,
                      eb_write_buffer(s->b, s->b->mark, s->offset, filename));
 }

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.219
retrieving revision 1.220
diff -u -b -r1.219 -r1.220
--- qe.h        13 Jun 2016 17:12:35 -0000      1.219
+++ qe.h        26 Jun 2016 08:35:26 -0000      1.220
@@ -214,7 +214,7 @@
 int is_directory(const char *path);
 int is_filepattern(const char *filespec);
 void canonicalize_path(char *buf, int buf_size, const char *path);
-void canonicalize_absolute_path(char *buf, int buf_size, const char *path1);
+void canonicalize_absolute_path(EditState *s, char *buf, int buf_size, const 
char *path1);
 char *make_user_path(char *buf, int buf_size, const char *path);
 char *reduce_filename(char *dest, int size, const char *filename);
 int match_extension(const char *filename, const char *extlist);

Index: shell.c
===================================================================
RCS file: /sources/qemacs/qemacs/shell.c,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -b -r1.110 -r1.111
--- shell.c     7 Jun 2016 08:56:40 -0000       1.110
+++ shell.c     26 Jun 2016 08:35:26 -0000      1.111
@@ -2041,7 +2041,8 @@
 
     line[stop] = '\0';
 
-    canonicalize_absolute_path(buf, buf_size, line + start);
+    /* XXX: should use a lower level function to avoid potential recursion */
+    canonicalize_absolute_path(NULL, buf, buf_size, line + start);
     append_slash(buf, buf_size);
     return buf;
 }
@@ -2100,6 +2101,7 @@
     EditBuffer *b;
     int offset, found_offset;
     char filename[MAX_FILENAME_SIZE];
+    char fullpath[MAX_FILENAME_SIZE];
     buf_t fnamebuf, *fname;
     int c, line_num, col_num;
     char error_message[128];
@@ -2153,6 +2155,9 @@
             buf_putc_utf8(fname, c);
         }
 
+        /* XXX: default directory should depend on current position in `s` */
+        canonicalize_absolute_path(s, fullpath, sizeof(fullpath), filename);
+
         /* extract line number */
         for (line_num = col_num = 0;;) {
             c = eb_nextc(b, offset, &offset);
@@ -2178,10 +2183,10 @@
         }
         eb_get_strline(b, error_message, sizeof(error_message), &offset);
         if (line_num >= 1) {
-            if (line_num != error_line_num ||
-                !strequal(filename, error_filename)) {
+            if (line_num != error_line_num
+            ||  !strequal(fullpath, error_filename)) {
                 error_line_num = line_num;
-                pstrcpy(error_filename, sizeof(error_filename), filename);
+                pstrcpy(error_filename, sizeof(error_filename), fullpath);
                 break;
             }
         }
@@ -2199,7 +2204,7 @@
     /* CG: Should remove popups, sidepanes, helppanes... */
 
     /* go to the error */
-    do_find_file(s, filename, 0);
+    do_find_file(s, fullpath, 0);
     do_goto_line(qs->active_window, line_num, col_num);
 
     put_status(s, "=> %s", error_message);

Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- util.c      13 Jun 2016 17:12:35 -0000      1.72
+++ util.c      26 Jun 2016 08:35:26 -0000      1.73
@@ -236,64 +236,6 @@
     }
 }
 
-/* return TRUE if absolute path. works for files and URLs */
-static int is_abs_path(const char *path)
-{
-    const char *p;
-
-    /* XXX: should only accept 'drive:' and 'proto:' */
-    p = strchr(path, ':');
-    if (p)
-        p++;
-    else
-        p = path;
-    return *p == '/';
-}
-
-/* canonicalize the path and make it absolute */
-void canonicalize_absolute_path(char *buf, int buf_size, const char *path1)
-{
-    char cwd[MAX_FILENAME_SIZE];
-    char path[MAX_FILENAME_SIZE];
-    char *homedir;
-
-    if (!is_abs_path(path1)) {
-        if (*path1 == '~') {
-            if (path1[1] == '\0' || path1[1] == '/') {
-                homedir = getenv("HOME");
-                if (homedir) {
-                    pstrcpy(path, sizeof(path), homedir);
-#ifdef CONFIG_WIN32
-                    path_win_to_unix(path);
-#endif
-                    remove_slash(path);
-                    pstrcat(path, sizeof(path), path1 + 1);
-                    path1 = path;
-                }
-            } else {
-                /* CG: should get info from getpwnam */
-#ifdef CONFIG_DARWIN
-                pstrcpy(path, sizeof(path), "/Users/");
-#else
-                pstrcpy(path, sizeof(path), "/home/");
-#endif
-                pstrcat(path, sizeof(path), path1 + 1);
-                path1 = path;
-            }
-        } else {
-            /* CG: not sufficient for windows drives */
-            /* CG: should test result */
-            getcwd(cwd, sizeof(cwd));
-#ifdef CONFIG_WIN32
-            path_win_to_unix(cwd);
-#endif
-            makepath(path, sizeof(path), cwd, path1);
-            path1 = path;
-        }
-    }
-    canonicalize_path(buf, buf_size, path1);
-}
-
 /* reduce path relative to homedir */
 char *make_user_path(char *buf, int buf_size, const char *path)
 {



reply via email to

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