@@ -116,7 +116,7 @@ typedef struct /**** Named link position structure */
116
116
{
117
117
short page, /* Page # */
118
118
top; /* Top position */
119
- uchar name[124 ]; /* Reference name */
119
+ uchar name[252 ]; /* Reference name */
120
120
} link_t ;
121
121
122
122
typedef struct // // Page information
@@ -320,7 +320,7 @@ static void parse_comment(tree_t *t, float *left, float *width, float *bottom,
320
320
321
321
static void check_pages (int page);
322
322
323
- static void add_link (uchar *name, int page, int top);
323
+ static void add_link (tree_t *html, uchar *name, int page, int top);
324
324
static link_t *find_link (uchar *name);
325
325
static int compare_links (link_t *n1, link_t *n2);
326
326
@@ -3835,7 +3835,8 @@ render_contents(tree_t *t, /* I - Tree to parse */
3835
3835
* Add a target link...
3836
3836
*/
3837
3837
3838
- add_link (link, *page, (int )(*y + height));
3838
+ add_link (NULL , link, *page, (int )(*y + height));
3839
+ add_link (temp, link, *page, (int )(*y + height));
3839
3840
}
3840
3841
3841
3842
switch (temp->markup )
@@ -3847,7 +3848,8 @@ render_contents(tree_t *t, /* I - Tree to parse */
3847
3848
* Add a target link...
3848
3849
*/
3849
3850
3850
- add_link (link, *page, (int )(*y + height));
3851
+ add_link (NULL , link, *page, (int )(*y + height));
3852
+ add_link (temp, link, *page, (int )(*y + height));
3851
3853
}
3852
3854
break ;
3853
3855
@@ -4156,7 +4158,8 @@ parse_doc(tree_t *t, /* I - Tree to parse */
4156
4158
* Add a link target using the ID=name variable...
4157
4159
*/
4158
4160
4159
- add_link (name, *page, (int )*y);
4161
+ add_link (NULL , name, *page, (int )*y);
4162
+ add_link (t, name, *page, (int )*y);
4160
4163
}
4161
4164
else if (t->markup == MARKUP_FILE)
4162
4165
{
@@ -4176,7 +4179,7 @@ parse_doc(tree_t *t, /* I - Tree to parse */
4176
4179
*sep = ' \0 ' ;
4177
4180
4178
4181
// Add the link
4179
- add_link (newname, *page, (int )*y);
4182
+ add_link (NULL , newname, *page, (int )*y);
4180
4183
}
4181
4184
4182
4185
if (chapter == 0 && !title_page)
@@ -5345,7 +5348,8 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
5345
5348
* Add a target link...
5346
5349
*/
5347
5350
5348
- add_link (link, *page, (int )(*y + height));
5351
+ add_link (NULL , link, *page, (int )(*y + height));
5352
+ add_link (temp, link, *page, (int )(*y + height));
5349
5353
}
5350
5354
5351
5355
switch (temp->markup )
@@ -5357,7 +5361,8 @@ parse_paragraph(tree_t *t, /* I - Tree to parse */
5357
5361
* Add a target link...
5358
5362
*/
5359
5363
5360
- add_link (link, *page, (int )(*y + height));
5364
+ add_link (NULL , link, *page, (int )(*y + height));
5365
+ add_link (temp, link, *page, (int )(*y + height));
5361
5366
}
5362
5367
5363
5368
default :
@@ -5673,7 +5678,8 @@ parse_pre(tree_t *t, /* I - Tree to parse */
5673
5678
* Add a target link...
5674
5679
*/
5675
5680
5676
- add_link (link, *page, (int )(*y + height));
5681
+ add_link (NULL , link, *page, (int )(*y + height));
5682
+ add_link (start, link, *page, (int )(*y + height));
5677
5683
}
5678
5684
5679
5685
switch (start->markup )
@@ -5689,7 +5695,8 @@ parse_pre(tree_t *t, /* I - Tree to parse */
5689
5695
* Add a target link...
5690
5696
*/
5691
5697
5692
- add_link (link, *page, (int )(*y + height));
5698
+ add_link (NULL , link, *page, (int )(*y + height));
5699
+ add_link (start, link, *page, (int )(*y + height));
5693
5700
}
5694
5701
break ;
5695
5702
@@ -9035,9 +9042,10 @@ check_pages(int page) // I - Current page
9035
9042
*/
9036
9043
9037
9044
static void
9038
- add_link (uchar *name, /* I - Name of link */
9039
- int page, /* I - Page # */
9040
- int top) /* I - Y position */
9045
+ add_link (tree_t *html, /* I - HTML node */
9046
+ uchar *name, /* I - Name of link */
9047
+ int page, /* I - Page # */
9048
+ int top) /* I - Y position */
9041
9049
{
9042
9050
link_t *temp; /* New name */
9043
9051
@@ -9047,48 +9055,57 @@ add_link(uchar *name, /* I - Name of link */
9047
9055
9048
9056
DEBUG_printf ((" add_link(name=\" %s\" , page=%d, top=%d)\n " , name, page, top));
9049
9057
9050
- if ((temp = find_link (name)) != NULL )
9058
+ if (!html && (temp = find_link (name)) != NULL )
9051
9059
{
9052
9060
temp->page = (short )page;
9053
9061
temp->top = (short )top;
9062
+ return ;
9054
9063
}
9055
- else
9056
- {
9057
- // See if we need to allocate memory for links...
9058
- if (num_links >= alloc_links)
9059
- {
9060
- // Allocate more links...
9061
- alloc_links += ALLOC_LINKS;
9062
9064
9063
- if (num_links == 0 )
9064
- temp = (link_t *)malloc (sizeof (link_t ) * alloc_links);
9065
- else
9066
- temp = (link_t *)realloc (links, sizeof (link_t ) * alloc_links);
9065
+ // See if we need to allocate memory for links...
9066
+ if (num_links >= alloc_links)
9067
+ {
9068
+ // Allocate more links...
9069
+ alloc_links += ALLOC_LINKS;
9067
9070
9068
- if (temp == NULL )
9069
- {
9070
- progress_error (HD_ERROR_OUT_OF_MEMORY,
9071
- " Unable to allocate memory for %d links - %s" ,
9072
- (int )alloc_links, strerror (errno));
9073
- alloc_links -= ALLOC_LINKS;
9074
- return ;
9075
- }
9071
+ if (num_links == 0 )
9072
+ temp = (link_t *)malloc (sizeof (link_t ) * alloc_links);
9073
+ else
9074
+ temp = (link_t *)realloc (links, sizeof (link_t ) * alloc_links);
9076
9075
9077
- links = temp;
9076
+ if (temp == NULL )
9077
+ {
9078
+ progress_error (HD_ERROR_OUT_OF_MEMORY, " Unable to allocate memory for %d links - %s" , (int )alloc_links, strerror (errno));
9079
+ alloc_links -= ALLOC_LINKS;
9080
+ return ;
9078
9081
}
9079
9082
9080
- // Add a new link...
9081
- temp = links + num_links;
9082
- num_links ++;
9083
+ links = temp;
9084
+ }
9083
9085
9084
- strlcpy (( char *)temp-> name , ( char *)name, sizeof (temp-> name ));
9085
- temp-> page = ( short )page ;
9086
- temp-> top = ( short )top ;
9086
+ // Add a new link...
9087
+ temp = links + num_links ;
9088
+ num_links ++ ;
9087
9089
9088
- if (num_links > 1 )
9089
- qsort (links, num_links, sizeof (link_t ),
9090
- (compare_func_t )compare_links);
9090
+ if (html)
9091
+ {
9092
+ uchar *filename; /* Filename */
9093
+
9094
+ if ((filename = htmlGetVariable (html->parent , (uchar *)" _HD_FILENAME" )) != NULL )
9095
+ snprintf ((char *)temp->name , sizeof (temp->name ), " %s#%s" , (char *)filename, (char *)name);
9096
+ else
9097
+ strlcpy ((char *)temp->name , (char *)name, sizeof (temp->name ));
9098
+ }
9099
+ else
9100
+ {
9101
+ strlcpy ((char *)temp->name , (char *)name, sizeof (temp->name ));
9091
9102
}
9103
+
9104
+ temp->page = (short )page;
9105
+ temp->top = (short )top;
9106
+
9107
+ if (num_links > 1 )
9108
+ qsort (links, num_links, sizeof (link_t ), (compare_func_t )compare_links);
9092
9109
}
9093
9110
9094
9111
@@ -9662,10 +9679,20 @@ static tree_t * /* O - Flattened markup tree */
9662
9679
flatten_tree (tree_t *t) /* I - Markup tree to flatten */
9663
9680
{
9664
9681
tree_t *temp, /* New tree node */
9682
+ *parent, /* Parent node (for file info) */
9665
9683
*flat; /* Flattened tree */
9666
9684
9667
9685
9668
- flat = NULL ;
9686
+ flat = NULL ;
9687
+ parent = NULL ;
9688
+ for (temp = t; temp != NULL ; temp = temp->parent )
9689
+ {
9690
+ if (temp->markup == MARKUP_FILE)
9691
+ {
9692
+ parent = temp;
9693
+ break ;
9694
+ }
9695
+ }
9669
9696
9670
9697
while (t != NULL )
9671
9698
{
@@ -9680,7 +9707,7 @@ flatten_tree(tree_t *t) /* I - Markup tree to flatten */
9680
9707
case MARKUP_IMG :
9681
9708
temp = (tree_t *)calloc (sizeof (tree_t ), 1 );
9682
9709
memcpy (temp, t, sizeof (tree_t ));
9683
- temp->parent = NULL ;
9710
+ temp->parent = parent ;
9684
9711
temp->child = NULL ;
9685
9712
temp->prev = flat;
9686
9713
temp->next = NULL ;
@@ -9697,7 +9724,7 @@ flatten_tree(tree_t *t) /* I - Markup tree to flatten */
9697
9724
{
9698
9725
temp = (tree_t *)calloc (sizeof (tree_t ), 1 );
9699
9726
memcpy (temp, t, sizeof (tree_t ));
9700
- temp->parent = NULL ;
9727
+ temp->parent = parent ;
9701
9728
temp->child = NULL ;
9702
9729
temp->prev = flat;
9703
9730
temp->next = NULL ;
@@ -9736,7 +9763,7 @@ flatten_tree(tree_t *t) /* I - Markup tree to flatten */
9736
9763
case MARKUP_CAPTION :
9737
9764
temp = (tree_t *)calloc (sizeof (tree_t ), 1 );
9738
9765
temp->markup = MARKUP_BR;
9739
- temp->parent = NULL ;
9766
+ temp->parent = parent ;
9740
9767
temp->child = NULL ;
9741
9768
temp->prev = flat;
9742
9769
temp->next = NULL ;
0 commit comments