Fossil SCM

Minor refactoring. Move the definition of <code>BLOB_APPEND_BLOB()</code> macro from <code>markdown_html.c</code> to <code>blob.c</code> so that it could be used outside of <code>markdown_html.c</code>. Also rename it to <code>blob_appendb</code> for consistency with <code>blob_appendf()</code> and other API. Within <code>markdown.c</code> use that newly available macro where appropriate. Within <code>markdown_html.c</code> use it for footnotes-relevant code. Other invocations of <code>BLOB_APPEND_BLOB()</code within <code>markdown_html.c</code are left intact (they use an alias) in order to simplify the potential merge with the trunk.

george 2022-02-23 08:21 markdown-footnotes
Commit 33a681ebee054f3d0346fbf992f19823120ce23f64ba5fb4b58e12e262803144
+6
--- src/blob.c
+++ src/blob.c
@@ -53,10 +53,16 @@
5353
/*
5454
** The buffer holding the blob data
5555
*/
5656
#define blob_buffer(X) ((X)->aData)
5757
58
+/*
59
+** Append blob contents to another
60
+*/
61
+#define blob_appendb(dest, src) \
62
+ blob_append((dest), blob_buffer(src), blob_size(src))
63
+
5864
/*
5965
** Seek whence parameter values
6066
*/
6167
#define BLOB_SEEK_SET 1
6268
#define BLOB_SEEK_CUR 2
6369
--- src/blob.c
+++ src/blob.c
@@ -53,10 +53,16 @@
53 /*
54 ** The buffer holding the blob data
55 */
56 #define blob_buffer(X) ((X)->aData)
57
 
 
 
 
 
 
58 /*
59 ** Seek whence parameter values
60 */
61 #define BLOB_SEEK_SET 1
62 #define BLOB_SEEK_CUR 2
63
--- src/blob.c
+++ src/blob.c
@@ -53,10 +53,16 @@
53 /*
54 ** The buffer holding the blob data
55 */
56 #define blob_buffer(X) ((X)->aData)
57
58 /*
59 ** Append blob contents to another
60 */
61 #define blob_appendb(dest, src) \
62 blob_append((dest), blob_buffer(src), blob_size(src))
63
64 /*
65 ** Seek whence parameter values
66 */
67 #define BLOB_SEEK_SET 1
68 #define BLOB_SEEK_CUR 2
69
+6 -6
--- src/markdown.c
+++ src/markdown.c
@@ -1071,12 +1071,12 @@
10711071
if( !lr ) return -1;
10721072
10731073
/* fill the output buffers */
10741074
blob_reset(link);
10751075
blob_reset(title);
1076
- blob_append(link, blob_buffer(&lr->link), blob_size(&lr->link));
1077
- blob_append(title, blob_buffer(&lr->title), blob_size(&lr->title));
1076
+ blob_appendb(link, &lr->link);
1077
+ blob_appendb(title, &lr->title);
10781078
return 0;
10791079
}
10801080
10811081
/* get_footnote() -- find a footnote by label, invoked during the 2nd pass.
10821082
* On success returns a footnote (after incrementing its nUsed field),
@@ -2692,14 +2692,14 @@
26922692
blob_append_string(&list, "<ul class='fn-joined'>\n");
26932693
for(k=i; k<j; k++){
26942694
struct footnote *y = fn + k;
26952695
blob_append_string(&list, "<li>");
26962696
if( blob_size(&y->upc) ){
2697
- blob_append(&list, blob_buffer(&y->upc), blob_size(&y->upc));
2697
+ blob_appendb(&list, &y->upc);
26982698
blob_reset(&y->upc);
26992699
}
2700
- blob_append(&list, blob_buffer(&y->text), blob_size(&y->text));
2700
+ blob_appendb(&list, &y->text);
27012701
blob_append_string(&list, "</li>\n");
27022702
27032703
/* free memory buffer */
27042704
blob_reset(&y->text);
27052705
if( k!=i ) blob_reset(&y->id);
@@ -2747,11 +2747,11 @@
27472747
struct footnote *aNotes;
27482748
const int N = COUNT_FOOTNOTES( allNotes );
27492749
27502750
/* make a shallow copy of `origin` */
27512751
blob_truncate(notes,0);
2752
- blob_append(notes, blob_buffer(allNotes), blob_size(allNotes));
2752
+ blob_appendb(notes, allNotes);
27532753
aNotes = CAST_AS_FOOTNOTES(notes);
27542754
qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
27552755
27562756
if( --maxDepth < 0 || nMarks == rndr.notes.nMarks ) break;
27572757
nMarks = rndr.notes.nMarks;
@@ -2767,11 +2767,11 @@
27672767
27682768
/* `origin` may be altered and extended through this call */
27692769
parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
27702770
27712771
blob_truncate(&x->text,0);
2772
- blob_append(&x->text, blob_buffer(tmp), blob_size(tmp));
2772
+ blob_appendb(&x->text, tmp);
27732773
x->bRndred = 1;
27742774
}
27752775
}
27762776
release_work_buffer(&rndr,tmp);
27772777
27782778
--- src/markdown.c
+++ src/markdown.c
@@ -1071,12 +1071,12 @@
1071 if( !lr ) return -1;
1072
1073 /* fill the output buffers */
1074 blob_reset(link);
1075 blob_reset(title);
1076 blob_append(link, blob_buffer(&lr->link), blob_size(&lr->link));
1077 blob_append(title, blob_buffer(&lr->title), blob_size(&lr->title));
1078 return 0;
1079 }
1080
1081 /* get_footnote() -- find a footnote by label, invoked during the 2nd pass.
1082 * On success returns a footnote (after incrementing its nUsed field),
@@ -2692,14 +2692,14 @@
2692 blob_append_string(&list, "<ul class='fn-joined'>\n");
2693 for(k=i; k<j; k++){
2694 struct footnote *y = fn + k;
2695 blob_append_string(&list, "<li>");
2696 if( blob_size(&y->upc) ){
2697 blob_append(&list, blob_buffer(&y->upc), blob_size(&y->upc));
2698 blob_reset(&y->upc);
2699 }
2700 blob_append(&list, blob_buffer(&y->text), blob_size(&y->text));
2701 blob_append_string(&list, "</li>\n");
2702
2703 /* free memory buffer */
2704 blob_reset(&y->text);
2705 if( k!=i ) blob_reset(&y->id);
@@ -2747,11 +2747,11 @@
2747 struct footnote *aNotes;
2748 const int N = COUNT_FOOTNOTES( allNotes );
2749
2750 /* make a shallow copy of `origin` */
2751 blob_truncate(notes,0);
2752 blob_append(notes, blob_buffer(allNotes), blob_size(allNotes));
2753 aNotes = CAST_AS_FOOTNOTES(notes);
2754 qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
2755
2756 if( --maxDepth < 0 || nMarks == rndr.notes.nMarks ) break;
2757 nMarks = rndr.notes.nMarks;
@@ -2767,11 +2767,11 @@
2767
2768 /* `origin` may be altered and extended through this call */
2769 parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
2770
2771 blob_truncate(&x->text,0);
2772 blob_append(&x->text, blob_buffer(tmp), blob_size(tmp));
2773 x->bRndred = 1;
2774 }
2775 }
2776 release_work_buffer(&rndr,tmp);
2777
2778
--- src/markdown.c
+++ src/markdown.c
@@ -1071,12 +1071,12 @@
1071 if( !lr ) return -1;
1072
1073 /* fill the output buffers */
1074 blob_reset(link);
1075 blob_reset(title);
1076 blob_appendb(link, &lr->link);
1077 blob_appendb(title, &lr->title);
1078 return 0;
1079 }
1080
1081 /* get_footnote() -- find a footnote by label, invoked during the 2nd pass.
1082 * On success returns a footnote (after incrementing its nUsed field),
@@ -2692,14 +2692,14 @@
2692 blob_append_string(&list, "<ul class='fn-joined'>\n");
2693 for(k=i; k<j; k++){
2694 struct footnote *y = fn + k;
2695 blob_append_string(&list, "<li>");
2696 if( blob_size(&y->upc) ){
2697 blob_appendb(&list, &y->upc);
2698 blob_reset(&y->upc);
2699 }
2700 blob_appendb(&list, &y->text);
2701 blob_append_string(&list, "</li>\n");
2702
2703 /* free memory buffer */
2704 blob_reset(&y->text);
2705 if( k!=i ) blob_reset(&y->id);
@@ -2747,11 +2747,11 @@
2747 struct footnote *aNotes;
2748 const int N = COUNT_FOOTNOTES( allNotes );
2749
2750 /* make a shallow copy of `origin` */
2751 blob_truncate(notes,0);
2752 blob_appendb(notes, allNotes);
2753 aNotes = CAST_AS_FOOTNOTES(notes);
2754 qsort(aNotes, N, sizeof(struct footnote), cmp_footnote_sort);
2755
2756 if( --maxDepth < 0 || nMarks == rndr.notes.nMarks ) break;
2757 nMarks = rndr.notes.nMarks;
@@ -2767,11 +2767,11 @@
2767
2768 /* `origin` may be altered and extended through this call */
2769 parse_inline(tmp, &rndr, blob_buffer(&x->text), blob_size(&x->text));
2770
2771 blob_truncate(&x->text,0);
2772 blob_appendb(&x->text, tmp);
2773 x->bRndred = 1;
2774 }
2775 }
2776 release_work_buffer(&rndr,tmp);
2777
2778
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -59,16 +59,17 @@
5959
* The empty string in the second argument leads to a syntax error
6060
* when the macro is not used with a string literal. Unfortunately
6161
* the error is not overly explicit.
6262
*/
6363
64
-/* BLOB_APPEND_BLOB -- append blob contents to another */
65
-#define BLOB_APPEND_BLOB(dest, src) \
66
- blob_append((dest), blob_buffer(src), blob_size(src))
64
+/* BLOB_APPEND_BLOB -- append blob contents to another
65
+** TODO: Refactor all invocations to use globall macro blob_appendb()
66
+*/
67
+#define BLOB_APPEND_BLOB(dest, src) blob_appendb((dest), (src))
6768
6869
#ifndef FOOTNOTES_WITHOUT_URI
69
- #define BLOB_APPEND_URI(dest,ctx) BLOB_APPEND_BLOB(dest,&((ctx)->reqURI))
70
+ #define BLOB_APPEND_URI(dest,ctx) blob_appendb(dest,&((ctx)->reqURI))
7071
#else
7172
#define BLOB_APPEND_URI(dest,ctx)
7273
#endif
7374
7475
/* Converts an integer to a null-terminated base26 representation
@@ -404,11 +405,11 @@
404405
if(span && blob_size(span)) {
405406
BLOB_APPEND_LITERAL(ob,"<span class='");
406407
append_footnote_upc(ob, upc, 0);
407408
BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
408409
blob_appendf(ob,"%s'>",pos);
409
- BLOB_APPEND_BLOB(ob, span);
410
+ blob_appendb(ob, span);
410411
blob_trim(ob);
411412
BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
412413
BLOB_APPEND_URI(ob, ctx);
413414
blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
414415
}else{
@@ -424,11 +425,11 @@
424425
assert( iMark == -1 );
425426
426427
sprintf(pos, "%s-%s", ctx->unique.c, l.c);
427428
if(span && blob_size(span)) {
428429
blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
429
- BLOB_APPEND_BLOB(ob, span);
430
+ blob_appendb(ob, span);
430431
blob_trim(ob);
431432
BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
432433
BLOB_APPEND_URI(ob, ctx);
433434
blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
434435
}else{
@@ -526,16 +527,16 @@
526527
if( bJoin ){
527528
BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
528529
blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
529530
}else if( nUsed ){
530531
append_footnote_upc(ob, upc, 1);
531
- BLOB_APPEND_BLOB(ob, text);
532
+ blob_appendb(ob, text);
532533
}else{
533534
BLOB_APPEND_LITERAL(ob,"<i></i>\n"
534535
"<pre><code class='language-markdown'>");
535536
if( blob_size(upc) ){
536
- BLOB_APPEND_BLOB(ob, upc);
537
+ blob_appendb(ob, upc);
537538
}
538539
html_escape(ob, blob_buffer(text), blob_size(text));
539540
BLOB_APPEND_LITERAL(ob,"</code></pre>");
540541
}
541542
#undef _joined_footnote_indicator
@@ -550,11 +551,11 @@
550551
BLOB_APPEND_LITERAL(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
551552
html_escape(ob, blob_buffer(id), blob_size(id));
552553
BLOB_APPEND_LITERAL(ob, "</code>&nbsp;]<i></i>\n"
553554
"<pre><code class='language-markdown'>");
554555
if( blob_size(upc) ){
555
- BLOB_APPEND_BLOB(ob, upc);
556
+ blob_appendb(ob, upc);
556557
}
557558
html_escape(ob, blob_buffer(text), blob_size(text));
558559
BLOB_APPEND_LITERAL(ob,"</code></pre>");
559560
}
560561
BLOB_APPEND_LITERAL(ob, "\n</li>\n");
@@ -563,11 +564,11 @@
563564
struct Blob *ob, const struct Blob *items, void *opaque
564565
){
565566
if( items && blob_size(items) ){
566567
BLOB_APPEND_LITERAL(ob,
567568
"\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
568
- BLOB_APPEND_BLOB(ob, items);
569
+ blob_appendb(ob, items);
569570
BLOB_APPEND_LITERAL(ob, "</ol>\n");
570571
}
571572
}
572573
573574
/* HTML span tags */
574575
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -59,16 +59,17 @@
59 * The empty string in the second argument leads to a syntax error
60 * when the macro is not used with a string literal. Unfortunately
61 * the error is not overly explicit.
62 */
63
64 /* BLOB_APPEND_BLOB -- append blob contents to another */
65 #define BLOB_APPEND_BLOB(dest, src) \
66 blob_append((dest), blob_buffer(src), blob_size(src))
 
67
68 #ifndef FOOTNOTES_WITHOUT_URI
69 #define BLOB_APPEND_URI(dest,ctx) BLOB_APPEND_BLOB(dest,&((ctx)->reqURI))
70 #else
71 #define BLOB_APPEND_URI(dest,ctx)
72 #endif
73
74 /* Converts an integer to a null-terminated base26 representation
@@ -404,11 +405,11 @@
404 if(span && blob_size(span)) {
405 BLOB_APPEND_LITERAL(ob,"<span class='");
406 append_footnote_upc(ob, upc, 0);
407 BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
408 blob_appendf(ob,"%s'>",pos);
409 BLOB_APPEND_BLOB(ob, span);
410 blob_trim(ob);
411 BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
412 BLOB_APPEND_URI(ob, ctx);
413 blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
414 }else{
@@ -424,11 +425,11 @@
424 assert( iMark == -1 );
425
426 sprintf(pos, "%s-%s", ctx->unique.c, l.c);
427 if(span && blob_size(span)) {
428 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
429 BLOB_APPEND_BLOB(ob, span);
430 blob_trim(ob);
431 BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
432 BLOB_APPEND_URI(ob, ctx);
433 blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
434 }else{
@@ -526,16 +527,16 @@
526 if( bJoin ){
527 BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
528 blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
529 }else if( nUsed ){
530 append_footnote_upc(ob, upc, 1);
531 BLOB_APPEND_BLOB(ob, text);
532 }else{
533 BLOB_APPEND_LITERAL(ob,"<i></i>\n"
534 "<pre><code class='language-markdown'>");
535 if( blob_size(upc) ){
536 BLOB_APPEND_BLOB(ob, upc);
537 }
538 html_escape(ob, blob_buffer(text), blob_size(text));
539 BLOB_APPEND_LITERAL(ob,"</code></pre>");
540 }
541 #undef _joined_footnote_indicator
@@ -550,11 +551,11 @@
550 BLOB_APPEND_LITERAL(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
551 html_escape(ob, blob_buffer(id), blob_size(id));
552 BLOB_APPEND_LITERAL(ob, "</code>&nbsp;]<i></i>\n"
553 "<pre><code class='language-markdown'>");
554 if( blob_size(upc) ){
555 BLOB_APPEND_BLOB(ob, upc);
556 }
557 html_escape(ob, blob_buffer(text), blob_size(text));
558 BLOB_APPEND_LITERAL(ob,"</code></pre>");
559 }
560 BLOB_APPEND_LITERAL(ob, "\n</li>\n");
@@ -563,11 +564,11 @@
563 struct Blob *ob, const struct Blob *items, void *opaque
564 ){
565 if( items && blob_size(items) ){
566 BLOB_APPEND_LITERAL(ob,
567 "\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
568 BLOB_APPEND_BLOB(ob, items);
569 BLOB_APPEND_LITERAL(ob, "</ol>\n");
570 }
571 }
572
573 /* HTML span tags */
574
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -59,16 +59,17 @@
59 * The empty string in the second argument leads to a syntax error
60 * when the macro is not used with a string literal. Unfortunately
61 * the error is not overly explicit.
62 */
63
64 /* BLOB_APPEND_BLOB -- append blob contents to another
65 ** TODO: Refactor all invocations to use globall macro blob_appendb()
66 */
67 #define BLOB_APPEND_BLOB(dest, src) blob_appendb((dest), (src))
68
69 #ifndef FOOTNOTES_WITHOUT_URI
70 #define BLOB_APPEND_URI(dest,ctx) blob_appendb(dest,&((ctx)->reqURI))
71 #else
72 #define BLOB_APPEND_URI(dest,ctx)
73 #endif
74
75 /* Converts an integer to a null-terminated base26 representation
@@ -404,11 +405,11 @@
405 if(span && blob_size(span)) {
406 BLOB_APPEND_LITERAL(ob,"<span class='");
407 append_footnote_upc(ob, upc, 0);
408 BLOB_APPEND_LITERAL(ob,"notescope' id='noteref");
409 blob_appendf(ob,"%s'>",pos);
410 blob_appendb(ob, span);
411 blob_trim(ob);
412 BLOB_APPEND_LITERAL(ob,"<sup class='noteref'><a href='");
413 BLOB_APPEND_URI(ob, ctx);
414 blob_appendf(ob,"#footnote%s'>%i</a></sup></span>", pos, iMark);
415 }else{
@@ -424,11 +425,11 @@
425 assert( iMark == -1 );
426
427 sprintf(pos, "%s-%s", ctx->unique.c, l.c);
428 if(span && blob_size(span)) {
429 blob_appendf(ob, "<span class='notescope' id='misref%s'>", pos);
430 blob_appendb(ob, span);
431 blob_trim(ob);
432 BLOB_APPEND_LITERAL(ob, "<sup class='noteref misref'><a href='");
433 BLOB_APPEND_URI(ob, ctx);
434 blob_appendf(ob, "#misreference%s'>misref</a></sup></span>", pos);
435 }else{
@@ -526,16 +527,16 @@
527 if( bJoin ){
528 BLOB_APPEND_LITERAL(ob,"<sup class='fn-joined'></sup><ul>");
529 blob_append(ob,blob_buffer(text)+_jfi_sz,blob_size(text)-_jfi_sz);
530 }else if( nUsed ){
531 append_footnote_upc(ob, upc, 1);
532 blob_appendb(ob, text);
533 }else{
534 BLOB_APPEND_LITERAL(ob,"<i></i>\n"
535 "<pre><code class='language-markdown'>");
536 if( blob_size(upc) ){
537 blob_appendb(ob, upc);
538 }
539 html_escape(ob, blob_buffer(text), blob_size(text));
540 BLOB_APPEND_LITERAL(ob,"</code></pre>");
541 }
542 #undef _joined_footnote_indicator
@@ -550,11 +551,11 @@
551 BLOB_APPEND_LITERAL(ob,"<li class='fn-unreferenced'>\n[^&nbsp;<code>");
552 html_escape(ob, blob_buffer(id), blob_size(id));
553 BLOB_APPEND_LITERAL(ob, "</code>&nbsp;]<i></i>\n"
554 "<pre><code class='language-markdown'>");
555 if( blob_size(upc) ){
556 blob_appendb(ob, upc);
557 }
558 html_escape(ob, blob_buffer(text), blob_size(text));
559 BLOB_APPEND_LITERAL(ob,"</code></pre>");
560 }
561 BLOB_APPEND_LITERAL(ob, "\n</li>\n");
@@ -563,11 +564,11 @@
564 struct Blob *ob, const struct Blob *items, void *opaque
565 ){
566 if( items && blob_size(items) ){
567 BLOB_APPEND_LITERAL(ob,
568 "\n<hr class='footnotes-separator'/>\n<ol class='footnotes'>\n");
569 blob_appendb(ob, items);
570 BLOB_APPEND_LITERAL(ob, "</ol>\n");
571 }
572 }
573
574 /* HTML span tags */
575

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button