/* ASCLRL() -- Clear to end of line from current position */ static void asclrl(int pos, int width) { int i; if (t_cl) { t_send(t_cl); /* use clear to eol function */ return; } if (pos==1 && linsdel_ok) { t_delete_line(); /* delete line */ t_insert_line(); /* reinsert it */ return; } for (i=1; i<=width-pos+1; i++) t_char(' '); /* last resort, blank it out */ for (i=1; i<=width-pos+1; i++) /* backspace to original position */ t_char(0x8); return; }
/* Backup cursor keeping characters under it */ static void backup(char *str) { if (cp == 0) { return; } while ((str[cp] & 0xC0) == 0x80) { cp--; } t_char('\010'); cp--; }
/* Move cursor forward keeping characters under it */ static void forward(char *str, int str_len) { if (cp > str_len) { return; } if (cp >= cl) { t_char(' '); str[cp+1] = ' '; str[cp+2] = 0; } else { t_char(str[cp]); if ((str[cp] & 0xC0) == 0xC0) { cp++; while ((str[cp] & 0xC0) == 0x80) { t_char(str[cp]); cp++; } cp--; } } cp++; }
// caller consumed '&' t_char scanner::scan_entity() { t_char buf[32]; int i = 0; t_char t; for(; i < 31 ; ++i ) { t = get_t_char(); if(t == 0) return TT_EOF; if( !isalnum(t) ) { push_back(t); break; // appears a erroneous entity token. // but we try to use it. } buf[i] = t_char(t); if(t == ';') break; } buf[i] = 0; if(i == 2) { if(equal(buf,"gt",2)) return '>'; if(equal(buf,"lt",2)) return '<'; } else if(i == 3 && equal(buf,"amp",3)) return '&'; else if(i == 4) { if(equal(buf,"apos",4)) return '\''; if(equal(buf,"quot",4)) return '\"'; } t = resolve_entity(buf,i); if(t) return t; // no luck ... append_value('&'); for(int n = 0; n < i; ++n) append_value(buf[n]); return ';'; }
int input_line(char *string, int length) { char curline[2000]; /* edit buffer */ int noline; unsigned c; int more; int i; if (first) { poolinit(); /* build line pool */ first = 0; } noline = 1; /* no line fetched yet */ for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) { if (usrbrk()) { clrbrk(); break; } switch (c=input_char()) { case F_RETURN: /* CR */ t_sendl("\r\n", 2); /* yes, print it and */ goto done; /* get out */ case F_CLRSCRN: /* clear screen */ asclrs(); t_sendl(curline, cl); ascurs(0, cp); break; case F_CSRUP: if (noline) { /* no line fetched yet */ getnext(); /* getnext so getprev gets current */ noline = 0; /* we now have line */ } bstrncpy(curline, getprev(), sizeof(curline)); prtcur(curline); break; case F_CSRDWN: noline = 0; /* mark line fetched */ bstrncpy(curline, getnext(), sizeof(curline)); prtcur(curline); break; case F_INSCHR: insert_space(curline, sizeof(curline)); break; case F_DELCHR: delchr(1, curline, sizeof(curline)); /* delete one character */ break; case F_CSRLFT: /* Backspace */ backup(curline); break; case F_CSRRGT: forward(curline, sizeof(curline)); break; case F_ERSCHR: /* Rubout */ backup(curline); delchr(1, curline, sizeof(curline)); if (cp == 0) { t_char(' '); t_char(0x8); } break; case F_DELEOL: t_clrline(0, t_width); if (cl > cp) cl = cp; break; case F_NXTWRD: i = next_word(curline); while (i--) { forward(curline, sizeof(curline)); } break; case F_PRVWRD: i = prev_word(curline); while (i--) { backup(curline); } break; case F_DELWRD: delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ break; case F_NXTMCH: /* Ctl-X */ if (cl==0) { *string = EOS; /* terminate string */ return(c); /* give it to him */ } /* Note fall through */ case F_DELLIN: case F_ERSLIN: while (cp > 0) { backup(curline); /* backup to beginning of line */ } t_clrline(0, t_width); /* erase line */ cp = 0; cl = 0; /* reset cursor counter */ t_char(' '); t_char(0x8); break; case F_SOL: while (cp > 0) { backup(curline); } break; case F_EOL: while (cp < cl) { forward(curline, sizeof(curline)); } while (cp > cl) { backup(curline); } break; case F_TINS: /* toggle insert mode */ mode_insert = !mode_insert; /* flip bit */ break; default: if (c > 255) { /* function key hit */ if (cl==0) { /* if first character then */ *string = EOS; /* terminate string */ return c; /* return it */ } t_honk_horn(); /* complain */ } else { if ((c & 0xC0) == 0xC0) { if ((c & 0xFC) == 0xFC) { more = 5; } else if ((c & 0xF8) == 0xF8) { more = 4; } else if ((c & 0xF0) == 0xF0) { more = 3; } else if ((c & 0xE0) == 0xE0) { more = 2; } else { more = 1; } } else { more = 0; } if (mode_insert) { insert_space(curline, sizeof(curline)); } curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ while (more--) { c= input_char(); insert_hole(curline, sizeof(curline)); curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ } if (cp > cl) { cl = cp; /* keep current length */ curline[cp] = 0; } } break; } /* end switch */ } /* If we fall through here rather than goto done, the line is too long simply return what we have now. */ done: curline[cl++] = EOS; /* terminate */ bstrncpy(string,curline,length); /* return line to caller */ /* Save non-blank lines. Note, put line zaps curline */ if (curline[0] != EOS) { putline(curline,cl); /* save line for posterity */ } return 0; /* give it to him/her */ }
void scanner::append_tag_name(t_char c) { if(tag_name_length < (MAX_NAME_SIZE - 1)) tag_name[tag_name_length++] = t_char(c); }
void scanner::append_attr_name(t_char c) { if(attr_name_length < (MAX_NAME_SIZE - 1)) attr_name[attr_name_length++] = t_char(c); }