lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev Re: [PATCH 2.8.4dev.18] NEXT_DOC


From: Ilya Zakharevich
Subject: lynx-dev Re: [PATCH 2.8.4dev.18] NEXT_DOC
Date: Sun, 18 Feb 2001 04:09:40 -0500
User-agent: Mutt/1.2.5i

This patch implements an action NEXT_DOC, which undoes what PREV_DOC
(usually on the Left key) does.

Enjoy,
Ilya

P.S.  Possible enhancements:

  a) make HISTORY show the position on the (no more!) "stack".

  b) several places in the source use the value of nhist (they scan
     history?).  Make nhist_extra public, and check whether these
     places want nhist + nhist_extra instead.

  c) Currently LYpop() and (some) LYpush() erases "the tail" of the
     stack.  Maybe some callers would prefer a different semantic...

--- ./src/LYHistory.c-pre-pop   Wed Oct 25 11:35:28 2000
+++ ./src/LYHistory.c   Sun Feb 18 01:33:50 2001
@@ -38,6 +38,8 @@ PRIVATE VisitedLink *Latest_tree;
 PRIVATE VisitedLink *First_tree;
 PRIVATE VisitedLink *Last_by_first;
 
+PRIVATE int nhist_extra;
+
 #ifdef LY_FIND_LEAKS
 /*
  *  Utility for freeing the list of visited links. - FM
@@ -254,6 +256,34 @@ PUBLIC BOOLEAN LYwouldPush ARGS2(
 }
 
 /*
+ *  Free the information in the last history entry.
+ */
+PRIVATE void clean_extra NOARGS
+{
+    nhist += nhist_extra;
+    while (nhist_extra > 0) {
+       nhist--;
+       FREE(history[nhist].title);
+       FREE(history[nhist].address);
+       FREE(history[nhist].post_data);
+       FREE(history[nhist].post_content_type);
+       FREE(history[nhist].bookmark);
+       nhist_extra--;
+    }
+}
+
+/* What is the relationship to are_different() from the mainloop?! */
+PRIVATE int are_identical ARGS2(histstruct *,  doc, document *,        doc1)
+{
+     return (  STREQ(doc1->address, doc->address)
+               && !strcmp(doc1->post_data ? doc1->post_data : "",
+                          doc->post_data ?  doc->post_data : "")
+               && !strcmp(doc1->bookmark ? doc1->bookmark : "",
+                          doc->bookmark ?  doc->bookmark : "")
+               && doc1->isHEAD == doc->isHEAD );
+}
+
+/*
  *  Push the current filename, link and line number onto the history list.
  */
 PUBLIC void LYpush ARGS2(
@@ -284,17 +314,7 @@ PUBLIC void LYpush ARGS2(
     /*
      * If file is identical to one before it, don't push it.
      */
-    if (nhist> 1 &&
-       STREQ(history[nhist-1].address, doc->address) &&
-       !strcmp(history[nhist-1].post_data ?
-               history[nhist-1].post_data : "",
-               doc->post_data ?
-               doc->post_data : "") &&
-       !strcmp(history[nhist-1].bookmark ?
-               history[nhist-1].bookmark : "",
-               doc->bookmark ?
-               doc->bookmark : "") &&
-       history[nhist-1].isHEAD == doc->isHEAD) {
+    if ( nhist > 1 && are_identical(&(history[nhist-1]), doc)) {
        if (history[nhist-1].internal_link == doc->internal_link) {
            /* But it is nice to have the last position remembered!
               - kw */
@@ -303,6 +323,20 @@ PUBLIC void LYpush ARGS2(
            return;
        }
     }
+
+    /*
+     * If file is identical to the current document, just move the pointer.
+     */
+    if ( nhist_extra >= 1 && are_identical(&(history[nhist]), doc)) {
+       history[nhist].link = doc->link;
+       history[nhist].line = doc->line;
+       nhist_extra--;
+       nhist++;
+       return;
+    }
+
+    clean_extra();
+
     /*
      * OK, push it if we have stack space.
      */
@@ -426,6 +460,7 @@ PUBLIC void LYpop ARGS1(
        document *,     doc)
 {
     if (nhist > 0) {
+       clean_extra();
        nhist--;
        doc->link = history[nhist].link;
        doc->line = history[nhist].line;
@@ -452,6 +487,57 @@ PUBLIC void LYpop ARGS1(
 }
 
 /*
+ *  Move to the previous filename, link and line number from the history list.
+ */
+PUBLIC void LYhist_prev ARGS1(
+       document *,     doc)
+{
+    if (nhist <= 0 || (!nhist_extra && nhist >= MAXHIST))
+       return;
+    nhist--;
+    nhist_extra++;
+    LYpop_num(nhist, doc);
+}
+
+/*
+ *  Called before calling LYhist_prev().
+ */
+PUBLIC void LYhist_prev_register ARGS1(
+       document *,     doc)
+{
+    if (nhist <= 0)
+       return;
+    if (nhist_extra) {         /* Make something to return back */
+       /* Store the new position */
+       history[nhist].link = doc->link;
+       history[nhist].line = doc->line;
+    } else {
+       if (nhist >= MAXHIST) /* push will fail */
+           return;
+       LYpush(doc, 0);
+       nhist--;
+       nhist_extra++;
+    }
+}
+
+/*
+ *  Move to the next filename, link and line number from the history list.
+ */
+PUBLIC int LYhist_next ARGS2(
+       document *,     doc, document *,        newdoc)
+{
+    if (nhist_extra <= 1)              /* == 1 when we are the last one */
+       return 0;
+    /* Store the new position */
+    history[nhist].link = doc->link;
+    history[nhist].line = doc->line;
+    nhist++;
+    nhist_extra--;
+    LYpop_num(nhist, newdoc);
+    return 1;
+}
+
+/*
  *  Pop the specified hist entry, link and line number from the history
  *  list but don't actually remove the entry, just return it.
  *  (This procedure is badly named :)
@@ -460,7 +546,7 @@ PUBLIC void LYpop_num ARGS2(
        int,            number,
        document *,     doc)
 {
-    if (number >= 0 && nhist > number) {
+    if (number >= 0 && nhist + nhist_extra > number) {
        doc->link = history[number].link;
        doc->line = history[number].line;
        StrAllocCopy(doc->title, history[number].title);
@@ -513,7 +599,7 @@ PUBLIC int showhistory ARGS1(
     fprintf(fp0, "<pre>\n");
 
     fprintf(fp0, "<em>%s</em>\n", gettext("You selected:"));
-    for (x = nhist-1; x >= 0; x--) {
+    for (x = nhist + nhist_extra - 1; x >= 0; x--) {
        /*
         *  The number of the document in the hist stack,
         *  its title in a link, and its address. - FM
@@ -573,7 +659,7 @@ PUBLIC BOOLEAN historytarget ARGS1(
        strlen(newdoc->address) < 10 || !isdigit(UCH(*(newdoc->address+9))))
        return(FALSE);
 
-    if ((number = atoi(newdoc->address+9)) > nhist || number < 0)
+    if ((number = atoi(newdoc->address+9)) > nhist + nhist_extra || number < 0)
        return(FALSE);
 
     /*
--- ./src/LYHistory.h-pre-pop   Thu Oct 21 09:56:48 1999
+++ ./src/LYHistory.h   Sat Feb 17 17:12:40 2001
@@ -11,6 +11,9 @@ extern int LYShowVisitedLinks PARAMS((ch
 extern int showhistory PARAMS((char **newfile));
 extern void LYAddVisitedLink PARAMS((document *doc));
 extern void LYpop PARAMS((document *doc));
+extern void LYhist_prev PARAMS((document *doc));
+extern void LYhist_prev_register PARAMS((document *doc));
+extern int LYhist_next PARAMS((document *doc, document *newdoc));
 extern void LYpop_num PARAMS((int number, document *doc));
 extern void LYpush PARAMS((document *doc, BOOLEAN force_push));
 
--- ./src/LYMainLoop.c-pre-pop  Mon Feb 12 22:57:44 2001
+++ ./src/LYMainLoop.c  Sun Feb 18 01:10:48 2001
@@ -3845,6 +3845,15 @@ PRIVATE BOOLEAN handle_LYK_OPTIONS ARGS2
     return FALSE;
 }
 
+PRIVATE void handle_NEXT_DOC NOARGS
+{
+    if (LYhist_next(&curdoc, &newdoc)) {
+       FREE(curdoc.address);           /* avoid push */
+       return;
+    }
+    HTUserMsg(gettext("No next document present"));
+}
+
 PRIVATE void handle_LYK_NEXT_LINK ARGS3(
     int,       c,
     int *,     old_c,
@@ -4034,8 +4043,8 @@ PRIVATE int handle_PREV_DOC ARGS3(
                    return 2;
                } else {
                    HTUserMsg2(WWW_SKIP_MESSAGE, WWWDoc.address);
-                   do {
-                       LYpop(&curdoc);
+                   do {        /* Should be LYhist_prev when _next supports */
+                       LYpop(&curdoc);         /* skipping of forms */
                    } while (nhist > 1 && !are_different(
                        (document *)&history[(nhist - 1)],
                        &curdoc));
@@ -4061,6 +4070,7 @@ PRIVATE int handle_PREV_DOC ARGS3(
        /*
         *  Set newdoc.address to empty to pop a file.
         */
+       LYhist_prev_register(&curdoc);  /* Why not call _prev instead of 
zeroing address?  */
        FREE(newdoc.address);
 #ifdef DIRED_SUPPORT
        if (lynx_edit_mode) {
@@ -5339,7 +5349,7 @@ try_again:
                     *  If newdoc.address is empty then pop a file
                     *  and load it.  - FM
                     */
-                   LYpop(&newdoc);
+                   LYhist_prev(&newdoc);
                    popped_doc = TRUE;
 
 
@@ -7027,6 +7037,10 @@ new_cmd:  /*
            case 2:
                goto new_cmd;
            }
+           break;
+
+       case LYK_NEXT_DOC:      /* undo back up a level */
+           handle_NEXT_DOC();
            break;
 
        case LYK_NOCACHE: /* Force submission of form or link with no-cache */

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

reply via email to

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