lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev fixed 123+p bug


From: Laura Eaves
Subject: lynx-dev fixed 123+p bug
Date: Sun, 28 Feb 1999 13:48:56 -0500 (EST)

(was this a typo or a thinko?... I'm afraid it was the latter...:)
Anyway, here's the entire patch, sans the update to follow_help.html
which I posted earlier and which hasn't changed).
I did have to touch mainloop(), but the line I added
was much more careful than the first time...
I haven't changed the syntax.  Taking votes: does anyone want it
changed to 123p+ or 0+123p? (similar for g and -)
Thanks for any feedback.
--le

Patch against dev17:
Index: GridText.c
--- old/GridText.c      Fri Feb 26 23:00:08 1999
+++ src/GridText.c      Sat Feb 27 03:13:18 1999
@@ -3947,6 +3947,70 @@
     }
 }
 
+/* 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;
+    int curpos = links[cur].lx;
+    int on_screen = ( curline >= scrtop && curline < (scrtop + display_lines) 
);
+    /* 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, %s\n",
+       scrtop,curline,curanchor,display_lines,on_screen?"on_screen":"0");
+    if (!HTMainText) return 0;
+    if ( rel==0 ) return num;
+
+    /* if cur numbered link is on current page, use it */
+    if ( on_screen && 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 ( on_screen ) { /* on screen but not a numbered link */
+       for ( ;  a;  a = a->next ) {
+           if ( a->number ) { l = a; curanchor = l->number; }
+           if ( curline == a->line_num && curpos == a->line_pos ) break;
+       }
+    }
+    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: LYForms.c
--- old/LYForms.c       Wed Feb 17 07:29:34 1999
+++ src/LYForms.c       Sat Feb 27 15:06:16 1999
@@ -515,10 +515,12 @@
 **  If a 'g' or 'p' suffix is included, that will be
 **  loaded into c.  Otherwise, c is zeroed. - FM & LE
 */
-PRIVATE int get_popup_option_number ARGS1(
-       int *,          c)
+PRIVATE int get_popup_option_number ARGS2(
+       int *,          c,
+       int *,          rel)
 {
     char temp[120];
+    char *p = temp;
 
     /*
      *  Load the c argument into the prompt buffer.
@@ -533,16 +535,25 @@
     if (LYgetstr(temp, VISIBLE, sizeof(temp), NORECALL) < 0 || *temp == 0) {
        HTInfoMsg(CANCELLED);
        *c = '\0';
+       *rel = '\0';
        return(0);
     }
 
+    while ( isdigit(*p) ) ++p;
+
+    /* if we have a + or - suffix, save it */
+    if ( *p == '+' || *p == '-' )
+       *rel = *p++;
+    else
+       *rel = '\0';
+
     /*
      *  If we had a 'g' or 'p' suffix, load it into c.
      *  Otherwise, zero c.  Then return the number.
      */
-    if (strchr(temp, 'g') != NULL || strchr(temp, 'G') != NULL) {
+    if ( *p == 'g' || *p == 'G' ) {
        *c = 'g';
-    } else if (strchr(temp, 'p') != NULL || strchr(temp, 'P') != NULL) {
+    } else if (*p == 'p' || *p == 'P' ) {
        *c = 'p';
     } else {
        *c = '\0';
@@ -585,7 +596,7 @@
      *  and to position the popup window appropriately,
      *  taking the user_mode setting into account. -- FM
      */
-    int c = 0, cmd = 0, i = 0, j = 0;
+    int c = 0, cmd = 0, i = 0, j = 0, rel = 0;
     int orig_selection = cur_selection;
 #ifndef USE_SLANG
     WINDOW * form_window;
@@ -887,8 +898,26 @@
                 *  a 'g' or 'p' suffix (which will be loaded
                 *  into c). - FM & LE
                 */
-               number = get_popup_option_number((int *)&c);
+               number = get_popup_option_number((int *)&c,(int *)&rel);
 
+               /* handle + or - suffix */
+               CTRACE(tfp,"got popup option number %d, ",number);
+               CTRACE(tfp,"rel='%c', c='%c', cur_selection=%d\n",
+                               rel,c,cur_selection);
+               if ( c == 'p' ) {
+                   int curpage = ((cur_selection + 1) > length) ?
+                       (((cur_selection + 1) + (length - 1))/(length))
+                                         : 1;
+                   CTRACE(tfp,"  curpage=%d\n",curpage);
+                   if ( rel == '+' )
+                       number = curpage + number;
+                   else if ( rel == '-' )
+                       number = curpage - number;
+               } else if ( rel == '+' )
+                   number = cur_selection + number + 1;
+               else if ( rel == '-' )
+                   number = cur_selection - number + 1;
+               if ( rel ) CTRACE(tfp,"new number=%d\n",number);
                /*
                 *  Check for a 'p' suffix. - FM
                 */
Index: LYGetFile.c
--- old/LYGetFile.c     Fri Feb 26 23:00:07 1999
+++ src/LYGetFile.c     Sun Feb 28 13:33:01 1999
@@ -944,9 +944,12 @@
        int *,          num)
 {
     char temp[120];
+    char *p = temp;
+    int rel = 0;
     int new_top, new_link;
     BOOL want_go;
 
+    CTRACE(tfp,"follow_link_number(%d,%d,...)\n",c,cur);
     temp[0] = c;
     temp[1] = '\0';
     *num = -1;
@@ -959,18 +962,32 @@
        return(DO_NOTHING);
     }
     *num = atoi(temp);
+    while ( isdigit(*p) ) ++p;
+    if ( *p == '+' || *p == '-' )
+       rel = *p++;
 
+    CTRACE(tfp,"  temp=%s, *num=%d, rel='%c'\n",temp,*num,rel);
     /*
      * 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 = doc->line; /* passed from mainloop() */
+       int curpage = ((curline + 1) > display_lines) ?
+               (((curline + 1) + (display_lines - 1))/(display_lines))
+                                                   : 1;
+       CTRACE(tfp," nlines=%d, npages=%d, curline=%d, curpage=%d\n",
+               nlines,npages,curline,curpage);
        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 +999,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.
     */
Index: LYMainLoop.c
--- old/LYMainLoop.c    Fri Feb 26 23:00:07 1999
+++ src/LYMainLoop.c    Sun Feb 28 13:29:55 1999
@@ -1766,6 +1766,10 @@
            int lindx = ((nlinks > 0) ? curdoc.link : 0);
            int number;
 
+           /* pass cur line num for use in follow_link_number()
+            * Note: Current line may not equal links[cur].line
+            */
+           newdoc.line = curdoc.line;
            switch (follow_link_number(c, lindx, &newdoc, &number)) {
            case DO_LINK_STUFF:
                /*

reply via email to

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