lynx-dev
[Top][All Lists]
Advanced

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

LYNX-DEV [patch] New feature: 'G' goes to a parent document


From: Tomasz J. Cholewo
Subject: LYNX-DEV [patch] New feature: 'G' goes to a parent document
Date: Sat, 8 Feb 1997 18:46:46 -0500

Hi,

The following patch causes that pressing 'G' (uppercase) key goes to a
``parent'' of the current document.  The parent is determined in this
case by removing a segment of URL's path after the last slash.
Repetitive applying of 'G' goes to the ``root'' document which URL has
no path part.  It works also in an obvious way in DIRED mode.

I found it very useful for browsing results of web searches when lots of
documents have changed names, don't exist or don't include links to
their parents.

This patch also fixes a minor memory leak in LYMainLoop.c caused by not
freeing a string returned by |HTParse|.

Tom

=================== CUT HERE ===================
diff -dbur lynx2-7/LYMessages_en.h lynx2-7-work/LYMessages_en.h
--- lynx2-7/LYMessages_en.h     Sat Jan 25 13:17:56 1997
+++ lynx2-7-work/LYMessages_en.h        Sat Feb  8 15:20:51 1997
@@ -249,6 +249,7 @@
 #define ALREADY_AT_END "You are already at the end of this document."
 #define ALREADY_AT_BEGIN "You are already at the beginning of this document."
 #define ALREADY_AT_FIRST "You are already at the first document"
+#define ALREADY_AT_ROOT "You are already at the root document"
 #define NO_LINKS_ABOVE "There are no links above this line of the document."
 #define NO_LINKS_BELOW "There are no links below this line of the document."
 #define MAXLEN_REACHED_DEL_OR_MOV \
diff -dbur lynx2-7/lynx.cfg lynx2-7-work/lynx.cfg
--- lynx2-7/lynx.cfg    Tue Feb  4 18:21:24 1997
+++ lynx2-7-work/lynx.cfg       Sat Feb  8 18:11:51 1997
@@ -1242,6 +1242,7 @@
 #KEYMAP:*:IMAGE_TOGGLE # Toggle inclusion of links for all images
 #KEYMAP:[:INLINE_TOGGLE        # Toggle pseudo-ALTs for inlines with no ALT 
string
 #KEYMAP:0x00:DO_NOTHING        # Does nothing (ignore this key)
+#KEYMAP:G:GOTO_PARENT  # Goto a parent URL

 # If TOGGLE_HELP is mapped, in novice mode the second help menu line
 # can be toggled among NOVICE_LINE_TWO_A, _B, and _C, as defined in
diff -dbur lynx2-7/src/LYKeymap.c lynx2-7-work/src/LYKeymap.c
--- lynx2-7/src/LYKeymap.c      Tue Feb  4 17:07:18 1997
+++ lynx2-7-work/src/LYKeymap.c Sat Feb  8 18:16:43 1997
@@ -89,7 +89,7 @@
 #endif /* DIRED_SUPPORT || VMS */
 /* F */

-LYK_GOTO,
+LYK_GOTO_PARENT,
 /* G */

 LYK_HELP,            LYK_INDEX,      LYK_JUMP,      LYK_KEYMAP,
@@ -453,7 +453,8 @@
 { "MINIMAL",           "toggle minimal vs. valid comment parsing" },
 { "SOFT_DQUOTES",      "toggle valid vs. soft double-quote parsing" },
 { "RAW_TOGGLE",                "toggle raw 8-bit translations or CJK mode ON 
or OFF" },
-{ "COOKIE_JAR",                "Examine the Cookie Jar" },
+{ "COOKIE_JAR",                "examine the Cookie Jar" },
+{ "GOTO_PARENT",       "go to a document being a parent of current URL" },
 #ifdef VMS
 { "DIRED_MENU",                "invoke File/Directory Manager, if available" },
 #else
diff -dbur lynx2-7/src/LYKeymap.h lynx2-7-work/src/LYKeymap.h
--- lynx2-7/src/LYKeymap.h      Thu Jan 16 18:25:26 1997
+++ lynx2-7-work/src/LYKeymap.h Sat Feb  8 18:15:32 1997
@@ -89,23 +89,27 @@
 #define       LYK_SOFT_DQUOTES 65
 #define       LYK_RAW_TOGGLE   66
 #define       LYK_COOKIE_JAR    67
+#define       LYK_GOTO_PARENT   68

 #ifdef VMS
-#define       LYK_DIRED_MENU    68
+#define       LYK_DIRED_MENU    69
 #endif /* VMS */
+
 #ifdef DIRED_SUPPORT
-#define       LYK_DIRED_MENU    68
-#define       LYK_CREATE        69
-#define       LYK_REMOVE        70
-#define       LYK_MODIFY        71
-#define       LYK_TAG_LINK      72
-#define       LYK_UPLOAD        73
-#define       LYK_INSTALL       74
+#define       LYK_DIRED_MENU    69
+#define       LYK_CREATE        70
+#define       LYK_REMOVE        71
+#define       LYK_MODIFY        72
+#define       LYK_TAG_LINK      73
+#define       LYK_UPLOAD        74
+#define       LYK_INSTALL       75
 #endif /* DIRED_SUPPORT */
+
+
 #ifdef NOT_USED
-#define       LYK_VERSION      75
-#define       LYK_FORM_UP       76
-#define       LYK_FORM_DOWN     77
+#define       LYK_VERSION      76
+#define       LYK_FORM_UP       77
+#define       LYK_FORM_DOWN     78
 #endif /* NOT_USED */

 #endif /* LYKEYMAP_H */
diff -dbur lynx2-7/src/LYMainLoop.c lynx2-7-work/src/LYMainLoop.c
--- lynx2-7/src/LYMainLoop.c    Thu Feb  6 16:34:00 1997
+++ lynx2-7-work/src/LYMainLoop.c       Sat Feb  8 18:09:59 1997
@@ -2449,6 +2449,67 @@
            }
            break;

+        case LYK_GOTO_PARENT:                  /* 'G' to go to a ``higher 
level'' URL (tjc) */
+           if (!strcmp((curdoc.title ? curdoc.title : ""), SHOWINFO_TITLE)) {
+               /*
+                *  If in info page, get out.
+                */
+               cmd = LYK_PREV_DOC;
+               goto new_cmd;
+           }
+
+           if (no_goto && !LYValidate) {
+               if (old_c != real_c) {
+                   old_c = real_c;
+                   _statusline(GOTO_DISALLOWED);
+                   sleep(MessageSecs);
+               }
+           } else {
+                char *address = HTParse(curdoc.address, "", PARSE_ACCESS |
+                                        PARSE_HOST | PARSE_PUNCTUATION);
+                char *path = HTParse(curdoc.address, "", PARSE_PATH | 
PARSE_PUNCTUATION); /* ignore anchor */
+
+                if (path != NULL) {
+                    if (strlen(path) > 1) {
+                        if (path[strlen(path)-1] == '/')
+                            path[strlen(path)-1] = '\0'; /* remove trailing 
slash */
+                        if ((cp = strrchr(path, '/')) != NULL)
+                            *(cp + 1) = '\0';   /* leave slash */
+                        else
+                            path[0] = '\0';     /* at root */
+                        StrAllocCat(address, path);
+                        FREE(path);
+                    } else {                    /* we are at the root already 
*/
+                        _statusline(ALREADY_AT_ROOT);
+                        sleep(MessageSecs);
+                        FREE(path);
+                        break;
+                    }
+                }
+                StrAllocCopy(newdoc.address, address);
+                FREE(address);
+
+                newdoc.isHEAD = FALSE;
+                if (are_different(&curdoc, &newdoc)) {
+                    /*
+                    *  Make a name for this new URL.
+                    */
+                    StrAllocCopy(newdoc.title, "A URL specified by the user");
+                    FREE(newdoc.post_data);
+                    FREE(newdoc.post_content_type);
+                    FREE(newdoc.bookmark);
+                    newdoc.safe = FALSE;
+                    force_load = TRUE;
+                    LYUserSpecifiedURL = TRUE;
+#ifdef DIRED_SUPPORT
+                    if (lynx_edit_mode)
+                        HTuncache_current_document();
+#endif /* DIRED_SUPPORT */
+                    HTAddGotoURL(newdoc.address);
+                }
+            }
+            break;
+
        case LYK_HELP:                  /* show help file */
            if (!STREQ(curdoc.address, helpfile)) {
                /*
@@ -2795,8 +2856,9 @@
                             *  Wasn't a ~user URL so guess address@hidden - FM
                             */
                            StrAllocCopy(address, "mailto:WebMaster@";);
-                       StrAllocCat(address,
-                                   HTParse(curdoc.address, "", PARSE_HOST));
+                        cp = HTParse(curdoc.address, "", PARSE_HOST);
+                       StrAllocCat(address, cp);
+                        FREE(cp);
                        _user_message(NO_OWNER_USE, address);
                        c = LYgetch();
                        if (TOUPPER(c) == 'Y') {
;
; To UNSUBSCRIBE:  Send a mail message to address@hidden
;                  with "unsubscribe lynx-dev" (without the
;                  quotation marks) on a line by itself.
;

reply via email to

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