18 #define DEFAULT_ANCHOR_FORMAT "id%03d"
23 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
33 char *buff =
S_ALLOC_N(
char, len * 4 / 3 + 6);
37 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
38 buff[i++] =
b64_table[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
45 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
46 buff[i++] =
b64_table[077 & (((s[1] << 2) & 074) | ((
'\0' >> 6) & 03))];
51 buff[i++] =
b64_table[077 & (((*s << 4) & 060) | (('\0' >> 4) & 017))];
62 int a = -1,b = -1,c = 0,d;
64 static int b64_xtable[256];
73 for (i = 0; i < 256; i++) {
76 for (i = 0; i < 64; i++) {
81 while (s[0] ==
'\r' || s[0] ==
'\n') { s++; }
82 if ((a = b64_xtable[(
int)s[0]]) == -1)
break;
83 if ((b = b64_xtable[(
int)s[1]]) == -1)
break;
84 if ((c = b64_xtable[(
int)s[2]]) == -1)
break;
85 if ((d = b64_xtable[(
int)s[3]]) == -1)
break;
86 *end++ = a << 2 | b >> 4;
87 *end++ = b << 4 | c >> 2;
91 if (a != -1 && b != -1) {
92 if (s + 2 < send && s[2] ==
'=')
93 *end++ = a << 2 | b >> 4;
94 if (c != -1 && s + 3 < send && s[3] ==
'=') {
95 *end++ = a << 2 | b >> 4;
96 *end++ = b << 4 | c >> 2;
297 if ( len + at >= (
long)e->
bufsize )
302 if (len <= rest)
break;
327 if ( check_room > 0 )
359 char *anchor_name =
NULL;
404 sprintf( an,
"&%s ", anchor_name );
415 sprintf( an,
"*%s", anchor_name );
443 if ( tag ==
NULL )
return;
448 if (
strlen( tag ) == 0 ) {
452 }
else if ( strncmp( tag,
"tag:", 4 ) == 0 ) {
453 int taglen = (int)
strlen( tag );
459 const char *subd = tag + 4;
460 while ( *subd !=
':' && *subd !=
'\0' ) subd++;
461 if ( *subd ==
':' ) {
480 }
else if ( strncmp( tag,
"x-private:", 10 ) == 0 ) {
499 spcs[0] =
'\n'; spcs[lvl->
spaces + 1] =
'\0';
500 for ( i = 0; i < lvl->
spaces; i++ ) spcs[i+1] =
' ';
509 #define SCAN_NONPRINT 1
511 #define SCAN_INDENTED 2
515 #define SCAN_WHITEEDGE 8
517 #define SCAN_NEWLINE 16
519 #define SCAN_SINGLEQ 32
521 #define SCAN_DOUBLEQ 64
523 #define SCAN_INDIC_S 128
525 #define SCAN_INDIC_C 256
527 #define SCAN_NONL_E 512
529 #define SCAN_MANYNL_E 1024
531 #define SCAN_FLOWMAP 2048
533 #define SCAN_FLOWSEQ 4096
535 #define SCAN_DOCSEP 8192
543 long i = 0, start = 0;
546 if ( len < 1 )
return flags;
549 if ( cursor[0] ==
'[' || cursor[0] ==
']' ||
550 cursor[0] ==
'{' || cursor[0] ==
'}' ||
551 cursor[0] ==
'!' || cursor[0] ==
'*' ||
552 cursor[0] ==
'&' || cursor[0] ==
'|' ||
553 cursor[0] ==
'>' || cursor[0] ==
'\'' ||
554 cursor[0] ==
'"' || cursor[0] ==
'#' ||
555 cursor[0] ==
'%' || cursor[0] ==
'@' ||
559 if ( ( cursor[0] ==
'-' || cursor[0] ==
':' ||
560 cursor[0] ==
'?' || cursor[0] ==
',' ) &&
561 ( len == 1 || cursor[1] ==
' ' || cursor[1] ==
'\n' ) )
567 if ( cursor[len-1] !=
'\n' ) {
569 }
else if ( len > 1 && cursor[len-2] ==
'\n' ) {
573 ( len > 0 && ( cursor[0] ==
' ' || cursor[0] ==
'\t' || cursor[0] ==
'\n' || cursor[0] ==
'\r' ) ) ||
574 ( len > 1 && ( cursor[len-1] ==
' ' || cursor[len-1] ==
'\t' ) )
580 if ( len >= 3 && strncmp( cursor,
"---", 3 ) == 0 )
584 for ( i = 0; i <
len; i++ ) {
586 if ( ! ( cursor[i] == 0x9 ||
589 ( cursor[i] >= 0x20 && cursor[i] <= 0x7E ) )
593 else if ( cursor[i] ==
'\n' ) {
595 if ( len - i >= 3 && strncmp( &cursor[i+1],
"---", 3 ) == 0 )
597 if ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\t' )
599 if ( req_width > 0 && i - start > req_width )
603 else if ( cursor[i] ==
'\'' )
607 else if ( cursor[i] ==
'"' )
611 else if ( cursor[i] ==
']' )
615 else if ( cursor[i] ==
'}' )
620 else if ( ( cursor[i] ==
' ' && cursor[i+1] ==
'#' ) ||
621 ( cursor[i] ==
':' &&
622 ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\n' || i == len - 1 ) ) )
626 else if ( cursor[i] ==
',' &&
627 ( cursor[i+1] ==
' ' || cursor[i+1] ==
'\n' || i == len - 1 ) )
642 char keep_nl,
const char *str,
long len )
648 const char *match_implicit;
651 if ( str ==
NULL ) str =
"";
702 force_style = favor_style;
710 if ( scan & SCAN_NEWLINE ) {
711 force_style = favor_style;
717 if ( force_indent > 0 ) {
745 switch ( force_style )
779 for( i = 0; i <
len; i++ )
781 if( (src[i] < 0x20) || (0x7E < src[i]) )
809 const char *
mark = str;
810 const char *start = str;
811 const char *end = str;
813 while ( mark < str + len ) {
823 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) {
833 if ( width > 0 && *start !=
' ' && mark - end > width ) {
857 const char *
mark = str;
858 const char *start = str;
859 const char *end = str;
861 while ( mark < str + len ) {
862 if ( do_indent > 0 ) {
863 if ( do_indent == 2 ) {
888 if ( start < str + len && ( *start ==
' ' || *start ==
'\n' ) ) {
894 if ( width > 0 && *start !=
' ' && mark - end > width ) {
917 const char *
mark = str;
918 const char *start = str;
919 const char *end = str;
923 }
else if ( keep_nl ==
NL_KEEP ) {
927 while ( mark < str + len ) {
928 if ( *mark ==
'\n' ) {
930 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) end += 1;
932 if ( mark + 1 == str + len ) {
953 const char *
mark = str;
954 const char *start = str;
955 const char *end = str;
959 }
else if ( keep_nl ==
NL_KEEP ) {
964 while ( mark < str + len ) {
969 if ( *start !=
' ' && *start !=
'\n' && *end !=
'\n' && *end !=
' ' ) {
972 if ( mark + 1 == str + len ) {
981 if ( *start !=
' ' ) {
982 if ( mark - end > width ) {
1065 for ( i = 0; i < spcs; i++ ) {
1095 for ( i = 0; i < spcs; i++ ) {
1102 if ( lvl->
ncount % 2 == 0 ) {
1112 if ( lvl->
ncount % 2 == 0 ) {
1120 spcs[lvl->
spaces] =
'\0';
1121 for ( i = 0; i < lvl->
spaces; i++ ) spcs[i] =
' ';
1133 if ( lvl->
ncount % 2 == 0 ) {
1159 if ( lvl->
ncount == 0 ) {
1171 if ( lvl->
ncount == 0 ) {
1173 }
else if ( lvl->
ncount % 2 == 1 ) {
1196 char *anchor_name =
NULL;
1237 sprintf( anchor_name, anc, idx );