📄 uedit.c
字号:
len=0; doit: while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || (c>='0' && c<='9')) { if(len!=MAX_WORD_SIZE) buf[len++]=c; c=pgetc(p); } if (c!=NO_MORE_DATA) prgetc(p); buf[len]=0; if (is_in_group(set,buf)) { ++cnt; } else if (cnt==1) { if (is_in_any_group(group,buf)) { if (!((buf[0]>='a' && buf[0]<='z') || (buf[0]>='A' && buf[0]<='Z'))) pgoto(p,p->byte-len+1); else pgoto(p,p->byte-len); pset(bw->cursor,p); prm(p); return 0; } } else if(is_in_group(last_of_set,buf)) { /* VHDL hack */ if (bw->o.vhdl_comment && (!zcmp(buf,USTR "end") || !zcmp(buf,USTR "END"))) while((c=pgetc(p))!=NO_MORE_DATA) if (c==';' || c=='\n') break; --cnt; } } } prm(p); return -1; }}/* Return true if <foo /> */int xml_startend(P *p){ int c, d=0; p=pdup(p, USTR "xml_startend"); while((c=pgetc(p)) != NO_MORE_DATA) { if(d=='/' && c=='>') { prm(p); return 1; } else if(c=='>') break; d=c; } prm(p); return 0;}int tomatch_xml(BW *bw,unsigned char *word,int dir){ if (dir== -1) { /* Backward search */ P *p=pdup(bw->cursor, USTR "tomatch_xml"); int c; unsigned char buf[MAX_WORD_SIZE+1]; int len; int cnt = 1; p_goto_next(p); p_goto_prev(p); while ((c=prgetc(p)) != NO_MORE_DATA) { if ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='.' || c==':' || c=='-' || c=='_') { int x; len=0; while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || (c>='0' && c<='9') || c=='.' || c == '-' || c == ':') { if(len!=MAX_WORD_SIZE) buf[len++]=c; c=prgetc(p); } if(c!=NO_MORE_DATA) c = pgetc(p); buf[len]=0; for(x=0;x!=len/2;++x) { int d = buf[x]; buf[x] = buf[len-x-1]; buf[len-x-1] = d; } if (!zcmp(word,buf) && !xml_startend(p)) { if (c=='<') { if (!--cnt) { pset(bw->cursor,p); prm(p); return 0; } } else if (c=='/') { ++cnt; } } } } prm(p); return -1; } else { /* Forward search */ P *p=pdup(bw->cursor, USTR "tomatch_xml"); int c; unsigned char buf[MAX_WORD_SIZE+1]; int len; int cnt = 1; while ((c=pgetc(p)) != NO_MORE_DATA) { if (c == '<') { int e = 1; c = pgetc(p); if (c=='/') { e = 0; c = pgetc(p); } if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c=='_' || c==':' || c=='-' || c=='.') { len=0; while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || c==':' || c=='-' || c=='.' || (c >= '0' && c <= '9')) { if(len!=MAX_WORD_SIZE) buf[len++]=c; c=pgetc(p); } if (c!=NO_MORE_DATA) prgetc(p); buf[len]=0; if (!zcmp(word,buf) && !xml_startend(p)) { if (e) { ++cnt; } else if (!--cnt) { pgoto(p,p->byte-len); pset(bw->cursor,p); prm(p); return 0; } } } else if (c!=NO_MORE_DATA) { prgetc(p); } } } prm(p); return -1; }}void get_xml_name(P *p,unsigned char *buf){ int c; int len=0; p=pdup(p, USTR "get_xml_name"); c=pgetc(p); while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || c==':' || c=='-' || c=='.' || (c >= '0' && c <= '9')) { if(len!=MAX_WORD_SIZE) buf[len++]=c; c=pgetc(p); } buf[len]=0; prm(p);}void get_delim_name(P *q,unsigned char *buf){ int c; int len=0; P *p=pdup(q, USTR "get_delim_name"); while ((c=prgetc(p))!=NO_MORE_DATA) if (c!=' ' && c!='\t') break; prm(p); /* preprocessor directive hack */ if (c=='#' || c=='`') buf[len++]=c; p=pdup(q, USTR "get_delim_name"); c=pgetc(p); while ((c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || c=='_' || (c >= '0' && c <= '9')) { if(len!=MAX_WORD_SIZE) buf[len++]=c; c=pgetc(p); } buf[len]=0; prm(p);}int utomatch(BW *bw){ int d; int c, /* Character under cursor */ f, /* Character to find */ dir; /* 1 to search forward, -1 to search backward */ c = brch(bw->cursor); /* Check for word delimiters */ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_') { P *p; unsigned char buf[MAX_WORD_SIZE+1]; unsigned char buf1[MAX_WORD_SIZE+1]; unsigned char *list = bw->b->o.text_delimiters; unsigned char *set; unsigned char *group; unsigned char *word; int flg=0; p=pdup(bw->cursor, USTR "utomatch"); p_goto_next(p); p_goto_prev(p); get_delim_name(p,buf); get_xml_name(p,buf1); c=prgetc(p); if (c=='<') flg = 1; else if (c=='/') { c=prgetc(p); if (c=='<') flg = -1; } prm(p); if (flg) { return tomatch_xml(bw, buf1, flg); } for (set = list; set && *set; set = next_set(set)) { for (group = set; *group && *group!='=' && *group!=':'; group=next_group(group)) { for (word = group; *word && *word!='|' && *word!='=' && *word!=':'; word=next_word(word)) { if (match_word(word, buf)) { return tomatch_word(bw, set, next_group(word)); } } } } /* We don't know the word, so start a search */ return dofirst(bw, 0, 0, buf); } switch (c) { case '/': dir = 1; pgetc(bw->cursor); f = brch(bw->cursor); prgetc(bw->cursor); if(f=='*') f = '/'; else { dir = -1; f = prgetc(bw->cursor); if (f!=NO_MORE_DATA) pgetc(bw->cursor); if(f=='*') f = '/'; else return -1; } break; case '(': f = ')'; dir = 1; break; case '[': f = ']'; dir = 1; break; case '{': f = '}'; dir = 1; break; case '`': f = '\''; dir = 1; break; case '<': f = '>'; dir = 1; break; case ')': f = '('; dir = -1; break; case ']': f = '['; dir = -1; break; case '}': f = '{'; dir = -1; break; case '\'': f = '`'; dir = -1; break; case '>': f = '<'; dir = -1; break; default: return -1; } /* Search for matching C comment */ if (f == '/') { P *p = pdup(bw->cursor, USTR "utomatch"); if (dir == 1) { d = pgetc(p); do { do { if (d == '*') break; } while ((d = pgetc(p)) != NO_MORE_DATA); d = pgetc(p); } while (d != NO_MORE_DATA && d != '/'); if (d == '/') { pset(bw->cursor,p); prgetc(bw->cursor); } } else { d = prgetc(p); do { do { if (d == '*') break; } while ((d = prgetc(p)) != NO_MORE_DATA); d = prgetc(p); } while (d != NO_MORE_DATA && d != '/'); if (d == '/') { pset(bw->cursor,p); } } prm(p); if (d == NO_MORE_DATA) return -1; else return 0; } /* Search for matching delimiter: ignore things in comments or strings */ /* This really should be language dependent */ if (dir == 1) { P *p = pdup(bw->cursor, USTR "utomatch"); int cnt = 0; /* No. levels of delimiters we're in */ while ((d = pgetc(p)) != NO_MORE_DATA) { if (d == '\\') { pgetc(p); } else if (d == '$' && brch(p)=='#' && bw->o.pound_comment) { pgetc(p); } else if (d == '"') { while ((d = pgetc(p)) != NO_MORE_DATA) if (d == '"') break; else if (d == '\\') pgetc(p); } else if (bw->o.single_quoted && d == '\'' && c!='\'' && c!='`') { while((d = pgetc(p)) != NO_MORE_DATA) if (d == '\'') break; else if (d == '\\') pgetc(p); } else if ((bw->o.pound_comment && d == '#') || (bw->o.semi_comment && d == ';') || (bw->o.vhdl_comment && d == '-' && brch(p) == '-')) { while ((d = pgetc(p)) != NO_MORE_DATA) if (d == '\n') break; } else if ((bw->o.c_comment || bw->o.cpp_comment) && d == '/') { d = pgetc(p); if (bw->o.c_comment && d == '*') { d = pgetc(p); do { do { if (d == '*') break; } while ((d = pgetc(p)) != NO_MORE_DATA); d = pgetc(p); } while (d != NO_MORE_DATA && d != '/'); } else if (d == '/') { while ((d = pgetc(p)) != NO_MORE_DATA) if (d == '\n') break; } else if (d != NO_MORE_DATA) prgetc(p); } else if (d == c) ++cnt; else if (d == f && !--cnt) { prgetc(p); pset(bw->cursor, p); break; } } prm(p); } else { P *p = pdup(bw->cursor, USTR "utomatch"); int cnt = 0; /* No. levels of delimiters we're in */ while ((d = prgetc(p)) != NO_MORE_DATA) { int peek = prgetc(p); int peek1 = 0; if(peek != NO_MORE_DATA) { peek1 = prgetc(p); if (peek1 != NO_MORE_DATA) pgetc(p); pgetc(p); } if (peek == '\\' && peek1!='\\') { } else if (d == '"') { while((d = prgetc(p)) != NO_MORE_DATA) { if (d == '"') { d = prgetc(p); if (d != '\\') { if (d != NO_MORE_DATA) pgetc(p); break; } } } } else if (bw->o.c_comment && d =='/') { d = prgetc(p); if (d == '*') { d = prgetc(p); do { do { if (d == '*') break; } while ((d = prgetc(p)) != NO_MORE_DATA); d = prgetc(p); } while (d != NO_MORE_DATA && d != '/'); } else if (d != NO_MORE_DATA) pgetc(p); } else if ((bw->o.cpp_comment || bw->o.pound_comment || bw->o.semi_comment || bw->o.vhdl_comment) && d == '\n') { P *q = pdup(p, USTR "utomatch"); int cc; p_goto_bol(q); while((cc = pgetc(q)) != '\n') { if (bw->o.pound_comment && cc == '$' && brch(q)=='#') { pgetc(q); } else if(cc=='"') { while ((cc = pgetc(q)) != '\n') if (cc == '"') break; else if (cc == '\\') pgetc(q); } else if (bw->o.cpp_comment && cc == '/') { if (brch(q)=='/') { prgetc(q); pset(p,q); break; } } else if (bw->o.single_quoted && cc == '\'') { while((cc = pgetc(q)) != '\n') if (cc == '\'') break; else if (cc == '\\') pgetc(q); } else if (bw->o.vhdl_comment && cc == '-') { if (brch(q)=='-') { prgetc(q); pset(p,q); break; } } else if (bw->o.pound_comment && cc == '#') { pset(p,q); break; } else if (bw->o.semi_comment && cc == ';') { pset(p,q); break; } } prm(q); } else if (bw->o.single_quoted && d =='\'' && c!='\'' && c!='`') { while((d = prgetc(p)) != NO_MORE_DATA) if (d == '\'') { d = prgetc(p); if (d != '\\') { if (d != NO_MORE_DATA) pgetc(p); break; } } } else if (d == c) ++cnt; else if (d == f) if (!cnt--) { pset(bw->cursor, p); break; } } prm(p); } if (d == NO_MORE_DATA) return -1; else return 0;}/* Move cursor up */int uuparw(BW *bw){ if (bw->o.hex) { if (bw->cursor->byte<16) return -1; else { pbkwd(bw->cursor, 16); return 0; } } if (bw->cursor->line) { pprevl(bw->cursor); pcol(bw->cursor, bw->cursor->xcol); return 0; } else return -1;}/* Move cursor down */int udnarw(BW *bw){ if (bw->o.hex) { if (bw->cursor->byte+16 <= bw->b->eof->byte) { pfwrd(bw->cursor, 16); return 0; } else if (bw->cursor->byte != bw->b->eof->byte) { pset(bw->cursor, bw->b->eof); return 0; } else { return -1; } } if (bw->cursor->line != bw->b->eof->line) { pnextl(bw->cursor); pcol(bw->cursor, bw->cursor->xcol); return 0; } else if(bw->o.picture) { p_goto_eol(bw->cursor); binsc(bw->cursor,'\n'); pgetc(bw->cursor); pcol(bw->cursor, bw->cursor->xcol); return 0; } else return -1;}/* Move cursor to top of window */int utos(BW *bw){ long col = bw->cursor->xcol; pset(bw->cursor, bw->top); pcol(bw->cursor, col); bw->cursor->xcol = col; return 0;}/* Move cursor to bottom of window */int ubos(BW *bw){ long col = bw->cursor->xcol; pline(bw->cursor, bw->top->line + bw->h - 1); pcol(bw->cursor, col); bw->cursor->xcol = col; return 0;}/* Scroll buffer window up n lines * If beginning of file is close, scrolls as much as it can * If beginning of file is on-screen, cursor jumps to beginning of file * * If flg is set: cursor stays fixed relative to screen edge * If flg is clr: cursor stays fixed on the buffer line */void scrup(BW *bw, int n, int flg){ int scrollamnt = 0; int cursoramnt = 0; int x; /* Decide number of lines we're really going to scroll */ if (bw->o.hex) { if (bw->top->byte/16 >= n) scrollamnt = cursoramnt = n; else if (bw->top->byte/16) scrollamnt = cursoramnt = bw->top->byte/16; else if (flg) cursoramnt = bw->cursor->byte/16; else if (bw->cursor->byte/16 >= n) cursoramnt = n; } else { if (bw->top->line >= n) scrollamnt = cursoramnt = n; else if (bw->top->line) scrollamnt = cursoramnt = bw->top->line; else if (flg) cursoramnt = bw->cursor->line; else if (bw->cursor->line >= n) cursoramnt = n; } if (bw->o.hex) { /* Move top-of-window pointer */ pbkwd(bw->top,scrollamnt*16); /* Move cursor */ pbkwd(bw->cursor,cursoramnt*16); /* If window is on the screen, give (buffered) scrolling command */ if (bw->parent->y != -1) nscrldn(bw->parent->t->t, bw->y, bw->y + bw->h, scrollamnt); } else { /* Move top-of-window pointer */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -