lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev OOPS -- fixed patch for number command suffixes (against dev17)


From: Laura Eaves
Subject: lynx-dev OOPS -- fixed patch for number command suffixes (against dev17)
Date: Fri, 26 Feb 1999 23:17:52 -0500 (EST)

Dangerous assignment I made in mainloop() turned out to break things
-- but fortunately wasn't necessary to begin with.

I've included the whole patch again, although only a few lines changed.
The fix actually makes the diff smaller, and LYMainLoop.c isn't effected..

I think this now works.
Let me know if otherwise.
--le

Index: GridText.c
--- old/GridText.c      Fri Feb 26 23:00:08 1999
+++ src/GridText.c      Fri Feb 26 23:04:50 1999
@@ -3947,6 +3947,65 @@
     }
 }
 
+/* HTGetRelLinkNum returns the anchor number to which follow_link_number()
+ *    is to jump (input was 123+ or 123- or 123+g or 123-g or 123 or 123g)
+ * num is the number specified
+ * rel is 0 or '+' or '-'
+ * cur is the current link
+ */
+PUBLIC int HTGetRelLinkNum ARGS3(
+       int,    num,
+       int,    rel,
+       int,    cur)
+{
+    TextAnchor *a, *l = 0;
+    int scrtop = HText_getTopOfScreen()+1;
+    int curline = links[cur].anchor_line_num;
+    /* curanchor may or may not be the "current link", depending whether it's
+     * on the current screen
+     */
+    int curanchor = links[cur].anchor_number;
+
+    CTRACE(tfp,"HTGetRelLinkNum(%d,%d,%d) -- HTMainText=%lx\n",
+       num,rel,cur,HTMainText);
+    CTRACE(tfp,"  scrtop=%d, curline=%d, curanchor=%d, display_lines=%d\n",
+       scrtop,curline,curanchor,display_lines);
+    if (!HTMainText) return 0;
+    if ( rel==0 ) return num;
+
+    if ( curline < scrtop || curline >= (scrtop + display_lines) )
+       curanchor = 0;
+
+    /* if cur numbered link is on current page, use it */
+    if ( curanchor ) {
+       CTRACE(tfp,"curanchor=%d at line %d on screen\n",curanchor,curline);
+       if ( rel == '+' ) return curanchor + num;
+       else if ( rel == '-' ) return curanchor - num;
+       else return num; /* shouldn't happen */
+    }
+
+    /* no current link on screen, or current link is not numbered
+     * -- find previous closest numbered link
+     */
+    for (a = HTMainText->first_anchor; a; a = a->next) {
+       CTRACE(tfp,"  a->line_num=%d, a->number=%d\n",a->line_num,a->number);
+       if ( a->line_num >= scrtop ) break;
+       if ( a->number == 0 ) continue;
+       l = a;
+       curanchor = l->number;
+    }
+    CTRACE(tfp,"  a=%lx, l=%lx, curanchor=%d\n",a,l,curanchor);
+    if ( rel == '+' )
+       return curanchor + num;
+    else if ( rel == '-' )
+       if ( l ) return curanchor + 1 - num;
+       else {
+           for ( ;  a && a->number==0;  a = a->next ) ;
+           return a ? a->number - num : 0;
+       }
+    else return num; /* shouldn't happen */
+}
+
 /*
  *  HTGetLinkInfo returns some link info based on the number.
  *
Index: GridText.h
--- old/GridText.h      Fri Feb 26 23:00:07 1999
+++ src/GridText.h      Fri Feb 26 23:04:49 1999
@@ -142,6 +142,7 @@
 extern BOOL HText_select PARAMS((HText *text));
 extern BOOL HText_POSTReplyLoaded PARAMS((document *doc));
 extern BOOL HTFindPoundSelector PARAMS((char *selector));
+extern int HTGetRelLinkNum PARAMS((int num, int rel, int cur));
 extern int HTGetLinkInfo PARAMS((
        int             number,
        int             want_go,
Index: LYGetFile.c
--- old/LYGetFile.c     Fri Feb 26 23:00:07 1999
+++ src/LYGetFile.c     Fri Feb 26 23:09:41 1999
@@ -944,6 +944,8 @@
        int *,          num)
 {
     char temp[120];
+    char *p = temp;
+    int rel = 0;
     int new_top, new_link;
     BOOL want_go;
 
@@ -959,18 +961,29 @@
        return(DO_NOTHING);
     }
     *num = atoi(temp);
+    while ( isdigit(*p) ) ++p;
+    if ( *p == '+' || *p == '-' )
+       rel = *p++;
 
     /*
      * Check if we had a 'p' or 'P' following the number as
      * a flag for displaying the page with that number. - FM
      */
-    if (strchr(temp, 'p') != NULL || strchr(temp, 'P') != NULL) {
+    if ( *p == 'p' || *p == 'P' ) {
        int nlines = HText_getNumOfLines();
        int npages = ((nlines + 1) > display_lines) ?
                (((nlines + 1) + (display_lines - 1))/(display_lines))
                                                    : 1;
+       int curline = links[cur].anchor_line_num;
+       int curpage = ((curline + 1) > display_lines) ?
+               (((curline + 1) + (display_lines - 1))/(display_lines))
+                                                   : 1;
        if (*num < 1)
-           *num = 1;
+           *num = rel ? 0 : 1;
+       if ( rel == '+' )
+           *num = curpage + *num;
+       else if ( rel == '-' )
+           *num = curpage - *num;
        doc->line = (npages <= 1) ?
                                1 :
                ((*num <= npages) ? (((*num - 1) * display_lines) + 1)
@@ -982,8 +995,13 @@
      * Check if we want to make the link corresponding to the
      * number the current link, rather than ACTIVATE-ing it.
      */
-    want_go = (strchr(temp, 'g') != NULL || strchr(temp, 'G') != NULL);
+    want_go = ( *p == 'g' || *p == 'G' );
 
+    /* If rel, add or subtract num from current link, or
+     * nearest previous/subsequent link if current link is not on screen.
+     */
+    if ( rel )
+       *num = HTGetRelLinkNum( *num, rel, cur );
    /*
     *  If we have a valid number, act on it.
     */

reply via email to

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