/* emmatch() -- match emphasis for a single emphasis token. */ static void emmatch(MMIOT *f, int first, int last) { block *start = &T(f->Q)[first]; int e, e2, match; switch (start->b_count) { case 2: if ( e = empair(f,first,last,match=2) ) break; case 1: e = empair(f,first,last,match=1); break; case 0: return; default: e = empair(f,first,last,1); e2= empair(f,first,last,2); if ( e2 >= e ) { e = e2; match = 2; } else match = 1; break; } if ( e ) { /* if we found emphasis to match, match it, recursively call * emblock to match emphasis inside the new html block, add * the emphasis markers for the block, then (tail) recursively * call ourself to match any remaining emphasis on this token. */ block *end = &T(f->Q)[e]; end->b_count -= match; start->b_count -= match; emblock(f, first, e); PREFIX(start->b_text, emtags[match-1].open, emtags[match-1].size-1); SUFFIX(end->b_post, emtags[match-1].close, emtags[match-1].size); emmatch(f, first, last); } } /* emmatch */
/* emmatch() */ static void emmatch(MMIOT *f, int go) { block *start = &T(f->Q)[go], *end; int e, e2, i, match; while ( start->b_count ) { switch (start->b_count) { case 2: e = empair(f,go,match=2); if ( e != EOF ) break; case 1: e = empair(f,go,match=1); break; default: e = empair(f,go,1); e2= empair(f,go,2); if ( e == EOF || ((e2 != EOF) && (e2 >= e)) ) { e = e2; match = 2; } else match = 1; } if ( e != EOF ) { end = &T(f->Q)[go+e]; emclose(&end->b_post, match); emopen(&start->b_text, match); end->b_count -= match; } else { for (i=0; i < match; i++) EXPAND(start->b_text) = start->b_char; } start->b_count -= match; } }