lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev 123p+ final(?) patch


From: Laura Eaves
Subject: lynx-dev 123p+ final(?) patch
Date: Mon, 1 Mar 1999 10:43:06 -0500 (EST)

below is the whole patch applied to pure dev17, including documentation.
It implements Phillip's 123p+ syntax.
I tested it on various combinations and it seems to work.
(It doesn't go to great lengths to report syntax errors typing in the
number commands -- but then it didn't before either...:)
--le
--- old/GridText.c      Mon Mar  1 09:51:45 1999
+++ src/GridText.c      Sun Feb 28 14:42:01 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.
  *
--- old/GridText.h      Mon Mar  1 09:51:44 1999
+++ src/GridText.h      Sun Feb 28 14:42:01 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,
--- old/LYForms.c       Mon Mar  1 09:51:44 1999
+++ src/LYForms.c       Mon Mar  1 10:21:37 1999
@@ -515,10 +515,13 @@
 **  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;
+    int num;
 
     /*
      *  Load the c argument into the prompt buffer.
@@ -533,21 +536,37 @@
     if (LYgetstr(temp, VISIBLE, sizeof(temp), NORECALL) < 0 || *temp == 0) {
        HTInfoMsg(CANCELLED);
        *c = '\0';
+       *rel = '\0';
        return(0);
     }
 
+    *rel = '\0';
+    num = atoi(p);
+    while ( isdigit(*p) ) ++p;
+    switch ( *p ) {
+    case '+': case '-':
+       /* 123+ or 123- */
+       *rel = *p++; *c = 0;
+       break;
+    default:
+       *c = *p++;
+       *rel = *p;
+    }
+
     /*
      *  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';
     }
-    return(atoi(temp));
+    if ( *rel != '+' && *rel != '-' )
+       *rel = 0;
+    return num;
 }
 
 /* Use this rather than the 'wprintw()' function to write a blank-padded
@@ -585,7 +604,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 +906,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
                 */
--- old/LYGetFile.c     Mon Mar  1 09:51:44 1999
+++ src/LYGetFile.c     Mon Mar  1 10:08:02 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;
@@ -958,19 +961,41 @@
        HTInfoMsg(CANCELLED);
        return(DO_NOTHING);
     }
-    *num = atoi(temp);
+    *num = atoi(p);
+    while ( isdigit(*p) ) ++p;
+    c = *p; /* reuse c; 0 or g or p or + or - */
+    switch ( c ) {
+    case '+': case '-':
+       /* 123+ or 123- */
+       rel = c; c = 0; ++p;
+       break;
+    default:
+       rel = *++p;
+    }
+    /* don't currently check for errors typing suffix */
 
+    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 ( c == 'p' || c == '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 +1007,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 = ( c == 'g' || c == '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.
     */
--- old/LYMainLoop.c    Mon Mar  1 09:51:44 1999
+++ src/LYMainLoop.c    Sun Feb 28 14:42:00 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:
                /*
--- old/follow_help.html        Mon Mar  1 09:51:44 1999
+++ lynx_help/keystrokes/follow_help.html       Mon Mar  1 10:19:28 1999
@@ -43,6 +43,23 @@
 <em>Follow link (or goto link or page) number:</em> feature to an advanced
 navigation aid.
 
+<p>Finally, a user may add a <em>+</em> or <em>-</em> suffix to a number
+command to indicate jumping forward or back relative to the current link or
+page.
+For example,
+typing
+<em>1g+</em> followed by RETURN will move the current
+link to the next numbered link, skipping any intervening
+pages or unnumbered links.  <em>1g-</em> goes to the preceeding
+numbered link.  <em>5p+</em> skips ahead 5 pages, and so on.
+Note that typing <em>1g+</em> is different from typing a down arrow
+in that <em>1g+</em> may skip pages containing no links, or
+intervening non-numbered links, such as form fields when
+form fields are not numbered.  It also differs from
+the <em>&lt;tab&gt;</em> command in that <em>1g+</em>
+does not skip over whole textareas, unless form fields
+are not numbered..
+
 <p>If the user has set <em>Keypad mode</em> to <em>Numbers act as arrows</em>,
 then only '<em>0</em>', rather than every number, will be treated as an
 <em>F_LINK_NUM</em> command for invoking the <em>Follow link (or goto link or 
page)
@@ -74,6 +91,19 @@
 conjunction with the '<em>p</em>' suffix), a <em>page</em> is defined as
 the number of OPTIONs displayed within the vertical dimension of the popup
 window.
+Finally, the <em>+</em> and <em>-</em> suffixes can be used
+to move forward or back from the current option or page in
+a popup menu,
+similarly to the way they are used for links   For example,
+while viewing a popup window, the user can type
+<em>3p+</em> and RETURN
+to skip ahead 3 pages, and <em>50g-</em> will move the
+current selection back 50 options.
+This will work whether or not <em>keypad mode</em> is
+<Links and form fields are numbered</em> since options
+are numbered internally.  If form field numbering is
+turned off, the option numbers won't appear on screen,
+but the user can still navigate using these commands.
 
 <p>Note that HTML can be structured so that it includes <em>hidden
 links</em>, i.e., without a visible link name intended for ACTIVATE-ing
@@ -113,7 +143,7 @@
 ACTIVATE-ed via that menu.  Also, if a link was hidden due to an ALT
 attribute in an IMG element, it will be converted to a <em>visible link</em>
 whenever the IMAGE_TOGGLE ('<em>*</em>') command is used to create links
-for SRC attritute values of IMG elements, because this indicates that the
+for SRC attribute values of IMG elements, because this indicates that the
 user does have some form of image handling enabled via a helper application, 
 or wishes to download files for subsequent use with a graphic browsers or
 other suitable software.

reply via email to

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