/* a < may be just a regular character, the start of an embedded html * tag, or the start of an <automatic link>. If it's an automatic * link, we also need to know if it's an email address because if it * is we need to mangle it in our futile attempt to cut down on the * spaminess of the rendered page. */ static int maybe_tag_or_link(MMIOT *f) { int c, size; int maybetag = 1; if ( f->flags & INSIDE_TAG ) return 0; for ( size=0; (c = peek(f, size+1)) != '>'; size++) { if ( c == EOF ) return 0; else if ( c == '\\' ) { maybetag=0; if ( peek(f, size+2) != EOF ) size++; } else if ( isspace(c) ) break; else if ( ! (c == '/' || isalnum(c) ) ) maybetag=0; } if ( size ) { if ( maybetag || (size >= 3 && strncmp(cursor(f), "!--", 3) == 0) ) { /* It is not a html tag unless we find the closing '>' in * the same block. */ while ( (c = peek(f, size+1)) != '>' ) if ( c == EOF ) return 0; else size++; if ( forbidden_tag(f) ) return 0; Qchar('<', f); while ( ((c = peek(f, 1)) != EOF) && (c != '>') ) Qchar(pull(f), f); return 1; } else if ( !isspace(c) && process_possible_link(f, size) ) { shift(f, size+1); return 1; } } return 0; }
/* a < may be just a regular character, the start of an embedded html * tag, or the start of an <automatic link>. If it's an automatic * link, we also need to know if it's an email address because if it * is we need to mangle it in our futile attempt to cut down on the * spaminess of the rendered page. */ static int maybe_tag_or_link(MMIOT *f) { int c, size; int maybetag = 1; if ( f->flags & INSIDE_TAG ) return 0; for ( size=0; (c = peek(f, size+1)) != '>'; size++) { if ( c == EOF ) return 0; else if ( c == '\\' ) { maybetag=0; if ( peek(f, size+2) != EOF ) size++; } else if ( isspace(c) ) break; else if ( ! (c == '/' || isalnum(c) ) ) maybetag=0; } if ( size ) { if ( maybetag || (size >= 3 && strncmp(cursor(f), "!--", 3) == 0) ) { Qstring(forbidden_tag(f) ? "<" : "<", f); while ( ((c = peek(f, 1)) != EOF) && (c != '>') ) cputc(pull(f), f); return 1; } else if ( !isspace(c) && process_possible_link(f, size) ) { shift(f, size+1); return 1; } } return 0; }
/* a < may be just a regular character, the start of an embedded html * tag, or the start of an <automatic link>. If it's an automatic * link, we also need to know if it's an email address because if it * is we need to mangle it in our futile attempt to cut down on the * spaminess of the rendered page. */ static int maybe_tag_or_link(MMIOT *f) { char *text; int c, size, i; int maybetag=1, maybeaddress=0; int mailto; if ( f->flags & INSIDE_TAG ) return 0; for ( size=0; ((c = peek(f,size+1)) != '>') && !isspace(c); size++ ) { if ( ! (c == '/' || isalnum(c) || c == '~') ) maybetag=0; if ( c == '@' ) maybeaddress=1; else if ( c == EOF ) return 0; } if ( size == 0 ) return 0; if ( maybetag || (size >= 3 && strncmp(cursor(f), "!--", 3) == 0) ) { Qstring(forbidden_tag(f) ? "<" : "<", f); while ( ((c = peek(f, 1)) != EOF) && (c != '>') ) cputc(pull(f), f); return 1; } if ( f->flags & DENY_A ) return 0; text = cursor(f); shift(f, size+1); for ( i=0; i < SZAUTOPREFIX; i++ ) if ( strncasecmp(text, autoprefix[i], strlen(autoprefix[i])) == 0 ) { Qstring("<a href=\"", f); puturl(text,size,f); Qstring("\">", f); puturl(text,size,f); Qstring("</a>", f); return 1; } if ( maybeaddress ) { Qstring("<a href=\"", f); if ( (size > 7) && strncasecmp(text, "mailto:", 7) == 0 ) mailto = 7; else { mailto = 0; /* supply a mailto: protocol if one wasn't attached */ mangle("mailto:", 7, f); } mangle(text, size, f); Qstring("\">", f); mangle(text+mailto, size-mailto, f); Qstring("</a>", f); return 1; } shift(f, -(size+1)); return 0; } /* maybe_tag_or_link */