lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev HText_beginAnchor/HText_endAnchor patch - revised


From: Klaus Weide
Subject: lynx-dev HText_beginAnchor/HText_endAnchor patch - revised
Date: Tue, 1 Dec 1998 16:54:05 -0600 (CST)

The patch I sent previously under the Subject 
"HText_startAnchor/HText_endAnchor patch" introduced a new problem.
For the curious, try it on <http://lwn.net/>.  Here is a fixed
version.

I was also erroneously referring to "HText_startAnchor"; there is no
such function, I meant "HText_beginAnchor".


    Klaus


Suggested changes to HText_beginAnchor and HText_endAnchor.
They should also make line number removal work better for color styles
(and other cases when there are no embedded special chars).

* Fixed line number removal code in HText_endAnchor in several places,
  it was modifying the wrong line which could lead to memory
  corruption.
* Tweaks in HText_beginAnchor and HText_endAnchor for handling link numbers:
  don't swallow space after number if line was split, find link number on
  previous line even it it is at the very end, adjust line split position
  after number removal.  Generate TRACE output in interesting cases.
  (This is a revised patch, the first attempt had problems.)

Patch against 2.8.1rel.2, should work with current devel.

*** lynx2-8-1.orig/src/GridText.c       Wed Oct 14 07:23:56 1998
--- lynx2-8-1/src/GridText.c    Tue Dec  1 16:38:48 1998
***************
*** 2722,2729 ****
--- 2722,2733 ----
      if ((a->number > 0) &&
        (keypad_mode == LINKS_ARE_NUMBERED ||
         keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED)) {
+       char saved_lastchar = text->LastChar;
+       int saved_linenum = text->Lines;
        sprintf(marker,"[%d]", a->number);
        HText_appendText(text, marker);
+       if (saved_linenum && text->Lines && saved_lastchar != ' ')
+           text->LastChar = ']'; /* if marker not after space caused split */
        a->start = text->chars + text->last_line->size;
        a->line_num = text->Lines;
        a->line_pos = text->last_line->size;
***************
*** 2792,2797 ****
--- 2796,2802 ----
                   HTAnchor_followMainLink((HTAnchor *)a->anchor)))));
        HTLine *last = text->last_line;
        HTLine *prev = text->last_line->prev;
+       HTLine *start = last;
        int CurBlankExtent = 0;
        int BlankExtent = 0;
  
***************
*** 2815,2821 ****
             */
            i = a->extent;
        }
!       j = (last->size - i);
        while (j < last->size) {
            if (!IsSpecialAttrChar(last->data[j]) &&
                !isspace((unsigned char)last->data[j]) &&
--- 2820,2826 ----
             */
            i = a->extent;
        }
!       k = j = (last->size - i);
        while (j < last->size) {
            if (!IsSpecialAttrChar(last->data[j]) &&
                !isspace((unsigned char)last->data[j]) &&
***************
*** 2851,2858 ****
         *  immediately preceding line also has only
         *  white and special characters. - FM
         */
!       while (i == 0 && a->extent > CurBlankExtent) {
!           j = prev->size - a->extent + CurBlankExtent;
            if (j < 0) {
                /*
                 *  The anchor starts on a preceding line,
--- 2856,2870 ----
         *  immediately preceding line also has only
         *  white and special characters. - FM
         */
!       while (i == 0 &&
!              (a->extent > CurBlankExtent ||
!               (a->extent == CurBlankExtent &&
!                k == 0 && 
!                prev != text->last_line &&
!                (prev->size == 0 ||
!                 prev->data[prev->size - 1] == ']')))) {
!           start = prev;
!           k = j = prev->size - a->extent + CurBlankExtent;
            if (j < 0) {
                /*
                 *  The anchor starts on a preceding line,
***************
*** 2876,2882 ****
                j++;
            }
            if (i == 0) {
!               if (a->extent > (CurBlankExtent + prev->size)) {
                    /*
                     *  This line has only white and special
                     *  characters, so treat its entire extent
--- 2888,2899 ----
                j++;
            }
            if (i == 0) {
!               if (a->extent > (CurBlankExtent + prev->size) ||
!                   (a->extent == CurBlankExtent + (int)prev->size &&
!                    k == 0 &&
!                    prev->prev != text->last_line &&
!                    (prev->prev->size == 0 ||
!                     prev->prev->data[prev->prev->size - 1] == ']'))) {
                    /*
                     *  This line has only white and special
                     *  characters, so treat its entire extent
***************
*** 2905,2910 ****
--- 2922,2932 ----
             */
            a->show_anchor = NO;
  
+           CTRACE(tfp,
+                  "HText_endAnchor: hidden 
(line,start,pos,ext,BlankExtent):(%d,%d,%d,%d,%d)",
+                  a->line_num,a->start,a->line_pos,a->extent,
+                  BlankExtent);
+ 
            /*
             *  If links are numbered, then try to get rid of the
             *  numbered bracket and adjust the anchor count. - FM
***************
*** 2918,2924 ****
             * possibly caused by HTML errors. - kw
             */
            if (remove_numbers_on_empty) {
-               HTLine *start;
                int NumSize = 0;
                TextAnchor *anc;
  
--- 2940,2945 ----
***************
*** 2927,2944 ****
                 *  or to the beginning of the line on which the
                 *  anchor start. - FM
                 */
!               if (prev == last->prev) {
                    /*
                     *  The anchor starts on the last line. - FM
                     */
-                   start = last;
                    j = (last->size - a->extent - 1);
                } else {
                    /*
                     *  The anchor starts on a previous line. - FM
                     */
!                   start = prev;
!                   prev = prev->prev;
                    j = (start->size - a->extent + CurBlankExtent - 1);
                }
                if (j < 0)
--- 2948,2963 ----
                 *  or to the beginning of the line on which the
                 *  anchor start. - FM
                 */
!               if (start == last) {
                    /*
                     *  The anchor starts on the last line. - FM
                     */
                    j = (last->size - a->extent - 1);
                } else {
                    /*
                     *  The anchor starts on a previous line. - FM
                     */
!                   prev = start->prev;
                    j = (start->size - a->extent + CurBlankExtent - 1);
                }
                if (j < 0)
***************
*** 2971,2976 ****
--- 2990,3001 ----
                         *  on this line. - FM
                         */
                        NumSize++;
+                       if (start==last && (int)text->permissible_split > j) {
+                           if ((int)text->permissible_split - NumSize < j)
+                               text->permissible_split = j;
+                           else
+                               text->permissible_split -= NumSize;
+                       }
                        k = j + NumSize;
                        while (k < start->size)
                            start->data[j++] = start->data[k++];
***************
*** 2978,2984 ****
--- 3003,3012 ----
                            text->chars -= NumSize;
                        for (anc = a; anc; anc = anc->next) {
                            anc->start -= NumSize;
+                           if (anc->line_num == a->line_num &&
+                               anc->line_pos >= NumSize) {
                            anc->line_pos -= NumSize;
+                           }
                        }
                        start->size = j;
                        start->data[j++] = '\0';
***************
*** 3008,3014 ****
                            NumSize++;
                            l = (i - j);
                            while (i < prev->size)
!                               start->data[j++] = start->data[i++];
                            text->chars -= l;
                            for (anc = a; anc; anc = anc->next) {
                                anc->start -= l;
--- 3036,3042 ----
                            NumSize++;
                            l = (i - j);
                            while (i < prev->size)
!                               prev->data[j++] = prev->data[i++];
                            text->chars -= l;
                            for (anc = a; anc; anc = anc->next) {
                                anc->start -= l;
***************
*** 3016,3022 ****
                            prev->size = j;
                            prev->data[j] = '\0';
                            while (j < i)
!                               start->data[j++] = '\0';
                            j = 0;
                            i = k;
                            while (k < start->size)
--- 3044,3056 ----
                            prev->size = j;
                            prev->data[j] = '\0';
                            while (j < i)
!                               prev->data[j++] = '\0';
!                           if (start == last && text->permissible_split > 0) {
!                               if ((int)text->permissible_split < k)
!                                   text->permissible_split = 0;
!                               else
!                                   text->permissible_split -= k;
!                           }
                            j = 0;
                            i = k;
                            while (k < start->size)
***************
*** 3025,3031 ****
                                text->chars -= i;
                            for (anc = a; anc; anc = anc->next) {
                                anc->start -= i;
!                               anc->line_pos -= i;
                            }
                            start->size = j;
                            start->data[j++] = '\0';
--- 3059,3068 ----
                                text->chars -= i;
                            for (anc = a; anc; anc = anc->next) {
                                anc->start -= i;
!                               if (anc->line_num == a->line_num &&
!                                   anc->line_pos >= i) {
!                                   anc->line_pos -= i;
!                               }
                            }
                            start->size = j;
                            start->data[j++] = '\0';
***************
*** 3052,3058 ****
                    if (j < 0)
                        j = 0;
                    i = (j + 1);
!                   if ((j > 2) &&
                        (prev->data[j] == ']' &&
                         isdigit((unsigned char)prev->data[j - 1]))) {
                        j--;
--- 3089,3095 ----
                    if (j < 0)
                        j = 0;
                    i = (j + 1);
!                   if ((j >= 2) &&
                        (prev->data[j] == ']' &&
                         isdigit((unsigned char)prev->data[j - 1]))) {
                        j--;
***************
*** 3084,3090 ****
                            prev->size = j;
                            prev->data[j++] = '\0';
                            while (j < k)
!                               start->data[j++] = '\0';
                        } else {
                            /*
                             *  Shucks!  We didn't find the
--- 3121,3127 ----
                            prev->size = j;
                            prev->data[j++] = '\0';
                            while (j < k)
!                               prev->data[j++] = '\0';
                        } else {
                            /*
                             *  Shucks!  We didn't find the
***************
*** 3114,3119 ****
--- 3151,3162 ----
             *  as a link. - FM
             */
            a->show_anchor = YES;
+           if (BlankExtent) {
+               CTRACE(tfp,
+                  "HText_endAnchor: blanks 
(line,start,pos,ext,BlankExtent):(%d,%d,%d,%d,%d)",
+                  a->line_num,a->start,a->line_pos,a->extent,
+                  BlankExtent);
+           }
        }
        if (a->show_anchor == NO) {
            /*
***************
*** 3138,3143 ****
--- 3181,3193 ----
             */
            a->extent -= ((BlankExtent < a->extent) ?
                                        BlankExtent : 0);
+       }
+       if (BlankExtent || a->extent <= 0 || a->number <= 0) {
+           CTRACE(tfp,
+                  "->[%d](%d,%d,%d,%d,%d)\n",
+                  a->number,
+                  a->line_num,a->start,a->line_pos,a->extent,
+                  BlankExtent);
        }
      } else {
        /*

reply via email to

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