lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH] "change directory" command


From: Vlad Harchev
Subject: lynx-dev [PATCH] "change directory" command
Date: Mon, 12 Jun 2000 15:35:12 +0500 (SAMST)

 Here is a first version of implementation of "change directory" command. I
 tested it only on linux. It's bound to 'C' in both modes (before this in
 normal modem COMMENT command was bound to 'c' and 'C' in normal mode, and
 CREATE was bound to 'c' and 'C' in dired mode). The main purpose of this
 command is not to type the name of the directory when 'p'rinting to files and
 'd'ownloading. If this command is invoked in dired mode, the listing of
 destination directory will be automatically loaded. Dired file ops menu lists
 this command too as the first item.
   To disable it, comment the line 
#define SUPPORT_CHDIR 
 in userdefs.h
   Seems 'configure' option would be handy for this (but IMO it should be
 enabled by default).
 
 I will update documentation to reflect this command if this implementation is
 accepted.

 Best regards,
  -Vlad

diff -ru lynx2.8.4dev3~/lynx.cfg lynx2.8.4dev3/lynx.cfg
--- lynx2.8.4dev3~/lynx.cfg     Sat Jun  3 19:54:48 2000
+++ lynx2.8.4dev3/lynx.cfg      Mon Jun 12 15:15:42 2000
@@ -2314,6 +2314,7 @@
 #KEYMAP:/:WHEREIS              # Find a string within the current document
 #KEYMAP:n:NEXT                 # Find next occurrence of string within document
 #KEYMAP:c:COMMENT              # Comment to the author of the current document
+#KEYMAP:C:CHDIR                        # Change current directory
 #KEYMAP:e:EDIT                 # Edit current document or form's textarea 
(call: ^Ve)
 #KEYMAP:E:ELGOTO               # Edit the current link's URL or ACTION and go 
to it
 #KEYMAP:=:INFO                 # Show info about current document
@@ -2380,6 +2381,7 @@
 #KEYMAP:^U:PREV_DOC:DIRED      # Return to the previous document
 #KEYMAP:.:TAG_LINK:DIRED       # Tag a file or directory for later action
 #KEYMAP:c:CREATE:DIRED         # Create a new file or directory
+#KEYMAP:C:CHDIR:DIRED          # change current directory
 #KEYMAP:f:DIRED_MENU:DIRED     # Display a menu of file operations
 #KEYMAP:m:MODIFY:DIRED         # Modify name or location of a file or directory
 #KEYMAP:r:REMOVE:DIRED         # Remove files or directories
diff -ru lynx2.8.4dev3~/src/LYKeymap.c lynx2.8.4dev3/src/LYKeymap.c
--- lynx2.8.4dev3~/src/LYKeymap.c       Mon Mar 13 04:38:38 2000
+++ lynx2.8.4dev3/src/LYKeymap.c        Mon Jun 12 15:18:21 2000
@@ -120,8 +120,13 @@
 LYK_UP_LINK,         LYK_INFO,     LYK_DOWN_LINK,   LYK_HELP,
 /* < */              /* = */         /* > */        /* ? */
 
+#ifndef SUPPORT_CHDIR
 LYK_RAW_TOGGLE,      LYK_ADDRLIST, LYK_PREV_PAGE,   LYK_COMMENT,
 /* @ */              /* A */         /* B */        /* C */
+#else
+LYK_RAW_TOGGLE,      LYK_ADDRLIST, LYK_PREV_PAGE,   LYK_CHDIR,
+/* @ */              /* A */         /* B */        /* C */
+#endif
 
 LYK_DOWNLOAD,        LYK_ELGOTO,  LYK_DIRED_MENU,   LYK_ECGOTO,
 /* D */              /* E */         /* F */        /* G */
@@ -411,9 +416,13 @@
 
    0,                  0,              0,             0,
 /* < */             /* = */         /* > */        /* ? */
-
+#ifndef SUPPORT_CHDIR
    0,                  0,              0,         LYK_CREATE,
 /* @ */             /* A */         /* B */        /* C */
+#else
+   0,                  0,              0,         LYK_CHDIR,
+/* @ */             /* A */         /* B */        /* C */
+#endif
 
    0,                  0,        LYK_DIRED_MENU,       0,
 /* D */             /* E */         /* F */        /* G */
@@ -734,6 +743,9 @@
 { "CHANGE_KCODE",      "Change Kanji code" },
 #endif
 #endif /* VMS */
+#ifdef SUPPORT_CHDIR
+ { "CHDIR",            "change current directory" },
+#endif
 { NULL,                        "" }
 };
 
diff -ru lynx2.8.4dev3~/src/LYKeymap.h lynx2.8.4dev3/src/LYKeymap.h
--- lynx2.8.4dev3~/src/LYKeymap.h       Fri Feb 25 16:38:35 2000
+++ lynx2.8.4dev3/src/LYKeymap.h        Sun Jun 11 12:30:44 2000
@@ -236,6 +236,9 @@
 #ifdef KANJI_CODE_OVERRIDE
   , LYK_CHG_KCODE
 #endif
+#ifdef SUPPORT_CHDIR
+  , LYK_CHDIR
+#endif
 } LYKeymapCode;
 
 
diff -ru lynx2.8.4dev3~/src/LYLocal.c lynx2.8.4dev3/src/LYLocal.c
--- lynx2.8.4dev3~/src/LYLocal.c        Sun May  7 11:49:40 2000
+++ lynx2.8.4dev3/src/LYLocal.c Mon Jun 12 15:09:02 2000
@@ -140,6 +140,10 @@
  *  configuration file via DIRED_MENU lines, then these default entries
  *  are discarded entirely.
  */
+#ifdef SUPPORT_CHDIR
+{ 0,                 "", "Change directory",
+                     "", "LYNXDIRED://CHDIR",          NULL },
+#endif
 { 0,                 "", "New File",
 "(in current directory)", "LYNXDIRED://NEW_FILE%d",            NULL },
 
@@ -1485,6 +1489,7 @@
     char *tmpbuf = NULL;
     char *buffer = NULL;
     char *dirname = NULL;
+    BOOL do_pop_doc = TRUE;
 
     line_url = doc->address;
     CTRACE((tfp, "local_dired: called for <%s>.\n",
@@ -1495,8 +1500,13 @@
     StrAllocCopy(line, line_url);
     HTUnEscape(line);  /* _file_ (not URL) syntax, for those functions
                           that need it.  Don't forget to FREE it. */
-
-    if ((arg = match_op("NEW_FILE", line)) != 0) {
+    if ((arg = match_op("CHDIR", line)) != 0) {    
+#ifdef SUPPORT_CHDIR
+       handle_LYK_CHDIR();
+       do_pop_doc = FALSE;
+#endif
+       arg = "blah";/*do something to avoid cc's complaints*/
+    } else if ((arg = match_op("NEW_FILE", line)) != 0) {
        if (create_file(arg) > 0)
            LYforce_no_cache = TRUE;
     } else if ((arg = match_op("NEW_FOLDER", line)) != 0) {
@@ -1713,7 +1723,8 @@
     FREE(buffer);
     FREE(line);
     FREE(tp);
-    LYpop(doc);
+    if (do_pop_doc)
+       LYpop(doc);
     return 0;
 }
 
diff -ru lynx2.8.4dev3~/src/LYMainLoop.c lynx2.8.4dev3/src/LYMainLoop.c
--- lynx2.8.4dev3~/src/LYMainLoop.c     Sat Jun  3 19:54:48 2000
+++ lynx2.8.4dev3/src/LYMainLoop.c      Mon Jun 12 15:26:41 2000
@@ -5045,6 +5045,84 @@
     return;
 }
 
+#ifdef SUPPORT_CHDIR
+#ifdef DOSPATH
+#define PATHSEP_STR "\\"
+#else
+#define PATHSEP_STR "/"
+#endif
+
+/*original implementation by VH*/
+PUBLIC void handle_LYK_CHDIR NOARGS
+{
+    static char buf[512];
+    char* p = NULL;
+    
+    _statusline(gettext("cd to:"));
+    /* some people may prefer automatic clearing of the previous user input,
+    here, to do this, just uncomment next line - VH*/
+    /* buf[0]='\0'; */
+    if (LYgetstr(buf,VISIBLE,sizeof(buf)-1,0)<0 || !*buf) {
+       HTInfoMsg(CANCELLED);
+       return;
+    };
+    
+    if (*buf=='~' && !buf[1]) {
+       StrAllocCopy(p,Home_Dir());
+    } else if (*buf=='~') {
+       HTSprintf0(&p,"%s%s",Home_Dir(),buf+1);
+    } else {
+       StrAllocCopy(p,buf);
+    };
+    
+    if (chdir(p)) {
+       switch (errno) {
+           case EACCES:
+               HTInfoMsg(COULD_NOT_ACCESS_DIR);
+               break;
+           case ENOENT:
+               HTInfoMsg(gettext("No such directory"));
+               break;
+           case ENOTDIR:
+               HTInfoMsg(gettext("A component of path is not a directory"));
+               break;
+           default:
+               HTInfoMsg(gettext("failed to change directory"));
+       };      
+    } else {
+#ifdef DIRED_SUPPORT
+       /*if in dired, load content of other directory*/
+       if (!no_dired_support && 
+           (lynx_edit_mode || (LYIsUIPage(curdoc.address, UIP_DIRED_MENU)))) {
+           char* tmp = wwwName(p);
+           char* addr = NULL;
+           StrAllocCopy(addr,"file://localhost");
+           StrAllocCat(addr,tmp);
+           if (tmp!=p) 
+           /*since wwwName is nop on unix and allocates something on VMS and 
DOS*/
+               FREE(tmp); 
+           
+           newdoc.address = addr;
+           newdoc.isHEAD = FALSE;
+            StrAllocCopy(newdoc.title, gettext("A URL specified by the user"));
+           FREE(newdoc.post_data);
+           FREE(newdoc.post_content_type);
+           FREE(newdoc.bookmark);
+           newdoc.safe = FALSE;
+           newdoc.internal_link = FALSE;
+           /**force_load = TRUE;*/
+           if (lynx_edit_mode) {
+               DIRED_UNCACHE_2;
+           }
+       } else
+#endif    
+           HTInfoMsg(OPERATION_DONE);
+    };
+    FREE(p);
+};
+#undef PATHSEP_STR 
+#endif
+
 /*
  *  Here's where we do all the work.
  *  mainloop is basically just a big switch dependent on the users input.
@@ -7168,7 +7246,11 @@
 
        case LYK_DO_NOTHING:    /* pretty self explanatory */
            break;
-
+#ifdef SUPPORT_CHDIR
+       case LYK_CHDIR:
+           handle_LYK_CHDIR();
+           break;
+#endif
        } /* end of BIG switch */
     }
 }
diff -ru lynx2.8.4dev3~/src/LYMainLoop.h lynx2.8.4dev3/src/LYMainLoop.h
--- lynx2.8.4dev3~/src/LYMainLoop.h     Wed Dec  1 07:33:02 1999
+++ lynx2.8.4dev3/src/LYMainLoop.h      Mon Jun 12 13:37:26 2000
@@ -14,6 +14,9 @@
 extern void LYSetNewline PARAMS((int value));
 extern void handle_LYK_TRACE_TOGGLE NOPARAMS;
 extern void handle_LYK_WHEREIS PARAMS((int cmd, BOOLEAN *refresh_screen));
+#ifdef SUPPORT_CHDIR
+extern void handle_LYK_CHDIR NOPARAMS; 
+#endif
 extern void repaint_main_statusline PARAMS((int for_what));
 
 #endif /* LYMAINLOOP_H */
diff -ru lynx2.8.4dev3~/src/LYUtils.c lynx2.8.4dev3/src/LYUtils.c
--- lynx2.8.4dev3~/src/LYUtils.c        Sat Jun  3 19:54:48 2000
+++ lynx2.8.4dev3/src/LYUtils.c Mon Jun 12 13:20:39 2000
@@ -7088,9 +7088,16 @@
 #if defined(__DJGPP__) || defined(_WINDOWS)
     if (strchr(result, ':') != NULL)
        cp = NULL;
-    else
+    else 
 #endif /*  __DJGPP__ || _WINDOWS */
-       cp = original_dir;
+       {
+#ifdef SUPPORT_CHDIR
+           static char buf[LY_MAXPATH];
+           cp = Current_Dir(buf);          
+#else
+           cp = original_dir;
+#endif
+       }
     }
     else
 #endif /* __EMX__*/
diff -ru lynx2.8.4dev3~/userdefs.h lynx2.8.4dev3/userdefs.h
--- lynx2.8.4dev3~/userdefs.h   Sat Jun  3 19:54:48 2000
+++ lynx2.8.4dev3/userdefs.h    Mon Jun 12 15:13:13 2000
@@ -1459,6 +1459,14 @@
  */
 #define SUPPORT_MULTIBYTE_EDIT
 
+/***************************** 
+ * SUPPORT_CHDIR provides CD command (bound to 'C' by default). It allows
+ * changing directory to arbitrary location (if OS allows them). If dired is
+ * enabled, user will be able to visit any directory and view any file allowed 
+ * accroding to file permissions or ACLs.
+*/
+#define SUPPORT_CHDIR
+
 /*****************************
  * USE_TH_JP_AUTO_DETECT, CONV_JISX0201KANA_JISX0208KANA,  
  * and KANJI_CODE_OVERRIDE are the macros for Japanese. - TH 


; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

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