lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev HText_startAnchor/HText_endAnchor patch


From: Klaus Weide
Subject: lynx-dev HText_startAnchor/HText_endAnchor patch
Date: Mon, 30 Nov 1998 19:10:14 -0600 (CST)

Suggested changes to HText_startAnchor 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_startAnchor 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.


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/GridText.c        Mon Nov 30 18:47:04 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;
  
***************
*** 2851,2857 ****
         *  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) {
                /*
--- 2856,2868 ----
         *  immediately preceding line also has only
         *  white and special characters. - FM
         */
!       while (i == 0 &&
!              (a->extent > CurBlankExtent ||
!               (a->extent == CurBlankExtent &&
!                prev != text->last_line &&
!                (prev->size == 0 ||
!                 prev->data[prev->size - 1] == ']')))) {
!           start = prev;
            j = prev->size - a->extent + CurBlankExtent;
            if (j < 0) {
                /*
***************
*** 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
--- 2887,2897 ----
                j++;
            }
            if (i == 0) {
!               if (a->extent > (CurBlankExtent + prev->size) ||
!                   (a->extent == CurBlankExtent + prev->size &&
!                    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 ****
--- 2920,2930 ----
             */
            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;
  
--- 2938,2943 ----
***************
*** 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)
--- 2946,2961 ----
                 *  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 ****
--- 2988,2999 ----
                         *  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 ****
--- 3001,3010 ----
                            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;
--- 3034,3040 ----
                            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)
--- 3042,3054 ----
                            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';
--- 3057,3066 ----
                                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--;
--- 3087,3093 ----
                    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
--- 3119,3125 ----
                            prev->size = j;
                            prev->data[j++] = '\0';
                            while (j < k)
!                               prev->data[j++] = '\0';
                        } else {
                            /*
                             *  Shucks!  We didn't find the
***************
*** 3114,3119 ****
--- 3149,3160 ----
             *  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 ****
--- 3179,3191 ----
             */
            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]