[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev next/prev relative number command suffixes
From: |
Laura Eaves |
Subject: |
lynx-dev next/prev relative number command suffixes |
Date: |
Fri, 26 Feb 1999 19:21:26 -0500 (EST) |
Ok, here's a patch that implements the following:
n[+|-][p|P|g|G]
where n is a decimal number.
(Note: the old 123g/123p/123 behavior is unchanged.)
Example: 1+g takes you to the next numbered link, skipping intermediate pages
and/or unnumbered anchors.
5-p or 5+p takes you 5 pages back or forward from where you are.
123+ activates the link 123 ahead of the current numbered link -- probably
not very useful in practice, but the implementation does it.
I've tried to check for all the boundary conditions and think I
got them all -- but feel free to test and report any abnormalities.
Let me know if you think this is a good/bad idea.
--le
Index: GridText.c
--- old/GridText.c Wed Feb 17 07:29:34 1999
+++ src/GridText.c Fri Feb 26 18:58:55 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 12:53:03 1999
+++ src/GridText.h Fri Feb 26 12:51:14 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 Wed Feb 17 07:29:34 1999
+++ src/LYGetFile.c Fri Feb 26 16:56:35 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,28 @@
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 curpage = ((doc->line + 1) > display_lines) ?
+ (((doc->line + 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 +994,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 11:10:28 1999
+++ src/LYMainLoop.c Fri Feb 26 17:01:54 1999
@@ -1766,6 +1766,8 @@
int lindx = ((nlinks > 0) ? curdoc.link : 0);
int number;
+ /* save cur line in newdoc for use in follow_link_number() */
+ newdoc = curdoc;
switch (follow_link_number(c, lindx, &newdoc, &number)) {
case DO_LINK_STUFF:
/*
- lynx-dev next/prev relative number command suffixes,
Laura Eaves <=