?? cb.c
字號:
case '[': putch(c,NO); ct = 0; while((c = getch()) != ']' || ct > 0){ if(c == Beof)error("]"); putch(c,NO); if(c == '[')ct++; if(c == ']')ct--; } putch(c,NO); continue; case '#': putch(c,NO); while ((cc = getch()) != '\n'){ if(cc == Beof)error("newline"); if (cc == '\\'){ putch(cc,NO); cc = getch(); } putch(cc,NO); } putch(cc,NO); lbegin = 0; outs(clev->tabs); lbegin = 1; count = 0; continue; default: if (c == ','){ opflag = 1; putch(c,YES); if (strict){ if ((cc = getch()) != ' ')unget(cc); if(cc != '\n')putch(' ',YES); } } else if(isop(c))gotop(c); else { if(isalnum(c) && lastlook == 0)lastlook = p; if(isdigit(c)){ putch(c,NO); while(isdigit(c=Bgetc(input))||c == '.')putch(c,NO); if(c == 'e'){ putch(c,NO); c = Bgetc(input); putch(c, NO); while(isdigit(c=Bgetc(input)))putch(c,NO); } Bungetc(input); } else putch(c,NO); if(keyflag != DATADEF)opflag = 0; } } }}voidgotif(void){ outs(clev->tabs); if(++clev->iflev >= IFLEVEL-1){ fprint(2,"too many levels of if %d\n",clev->iflev ); clev->iflev = IFLEVEL-1; } clev->ifc[clev->iflev] = clev->tabs; clev->spdepth[clev->iflev] = clev->pdepth;}voidgotelse(void){ clev->tabs = clev->ifc[clev->iflev]; clev->pdepth = clev->spdepth[clev->iflev]; if(--(clev->iflev) < 0)clev->iflev = 0;}intcheckif(char *pt){ struct keyw *lptr; int cc; if((lptr=lookup(pt,lastplace+1))!= 0){ if(lptr->type == IF){ if(strict)putch(' ',YES); copy(lptr->name); *pt='\0'; lastplace = pt; if(strict){ putch(lptr->punc,NO); eatallsp(); } clev->tabs = clev->ifc[clev->iflev]; clev->pdepth = clev->spdepth[clev->iflev]; keyflag = KEYWORD; return(1); } } return(0);}voidgotdo(void){ if(++dolevel >= DOLEVEL-1){ fprint(2,"too many levels of do %d\n",dolevel); dolevel = DOLEVEL-1; } dotabs[dolevel] = clev->tabs; docurly[dolevel] = YES;}voidresetdo(void){ if(docurly[dolevel] == NO) clev->pdepth = dopdepth[dolevel]; if(--dolevel < 0)dolevel = 0;}voidgottype(struct keyw *lptr){ char *pt; struct keyw *tlptr; int c; while(1){ pt = getnext(1); if((tlptr=lookup(pt,lastplace+1))!=0){ putch(' ',YES); copy(tlptr->name); *pt='\0'; lastplace = pt; if(tlptr->type == STRUCT){ putch(tlptr->punc,YES); gotstruct(); break; } lptr=tlptr; continue; } else{ putch(lptr->punc,NO); while((c=getch())== ' ' || c == '\t'); unget(c); break; } }}voidgotstruct(void){ int c; int cc; char *pt; while((c=getch()) == ' ' || c == '\t') if(!strict)putch(c,NO); if(c == '{'){ structlev++; unget(c); return; } if(isalpha(c)){ putch(c,NO); while(isalnum(c=getch()))putch(c,NO); } unget(c); pt = getnext(1); if(*pt == '{')structlev++; if(strict){ eatallsp(); putch(' ',NO); }}voidgotop(int c){ char optmp[OPLENGTH]; char *op_ptr; struct op *s_op; char *a, *b; op_ptr = optmp; *op_ptr++ = c; while (isop(( *op_ptr = getch())))op_ptr++; if(!strict)unget(*op_ptr); else if (*op_ptr != ' ')unget( *op_ptr); *op_ptr = '\0'; s_op = op; b = optmp; while ((a = s_op->name) != 0){ op_ptr = b; while ((*op_ptr == *a) && (*op_ptr != '\0')){ a++; op_ptr++; } if (*a == '\0'){ keep(s_op); opflag = s_op->setop; if (*op_ptr != '\0'){ b = op_ptr; s_op = op; continue; } else break; } else s_op++; }}voidkeep(struct op *o){ char *s; int ok; if(o->blanks == NEVER)ok = NO; else ok = YES; if (strict && ((o->blanks & ALWAYS) || ((opflag == 0 && o->blanks & SOMETIMES) && clev->tabs != 0))) putspace(' ',YES); for(s=o->name; *s != '\0'; s++){ if(*(s+1) == '\0')putch(*s,ok); else putch(*s,NO); } if (strict && ((o->blanks & ALWAYS) || ((opflag == 0 && o->blanks & SOMETIMES) && clev->tabs != 0))) putch(' ',YES);}intgetnl(void){ int ch; char *savp; int gotcmt; gotcmt = 0; savp = p; while ((ch = getch()) == '\t' || ch == ' ')putch(ch,NO); if (ch == '/'){ if ((ch = getch()) == '*'){ putch('/',NO); putch('*',NO); comment(NO); ch = getch(); gotcmt=1; } else if (ch == '/') { putch('/',NO); putch('/',NO); cpp_comment(NO); ch = getch(); gotcmt = 1; } else { if(inswitch)*(++lastplace) = ch; else { inswitch = 1; *lastplace = ch; } unget('/'); return(0); } } if(ch == '\n'){ if(gotcmt == 0)p=savp; return(1); } unget(ch); return(0);}voidptabs(int n){ int i; int num; if(n > maxtabs){ if(!folded){ Bprint(output, "/* code folded from here */\n"); folded = 1; } num = n-maxtabs; } else { num = n; if(folded){ folded = 0; Bprint(output, "/* unfolding */\n"); } } for (i = 0; i < num; i++)Bputc(output, '\t');}voidouts(int n){ if (p > string){ if (lbegin){ ptabs(n); lbegin = 0; if (split == 1){ split = 0; if (clev->tabs > 0)Bprint(output, "\t"); } } *p = '\0'; Bprint(output, "%s", string); lastlook = p = string; } else { if (lbegin != 0){ lbegin = 0; split = 0; } }}voidputch(char c,int ok){ int cc; if(p < &string[LINE-1]){ if(count+TABLENG*clev->tabs >= maxleng && ok && !folded){ if(c != ' ')*p++ = c; OUT; split = 1; if((cc=getch()) != '\n')unget(cc); } else { *p++ = c; count++; } } else { outs(clev->tabs); *p++ = c; count = 0; }}struct keyw *lookup(char *first, char *last){ struct keyw *ptr; char *cptr, *ckey, *k; if(first == last || first == 0)return(0); cptr = first; while (*cptr == ' ' || *cptr == '\t')cptr++; if(cptr >= last)return(0); ptr = key; while ((ckey = ptr->name) != 0){ for (k = cptr; (*ckey == *k && *ckey != '\0'); k++, ckey++); if(*ckey=='\0' && (k==last|| (k<last && !isalnum(*k)))){ opflag = 1; lastlook = 0; return(ptr); } ptr++; } return(0);}intcomment(int ok){ int ch; int hitnl; hitnl = 0; while ((ch = getch()) != Beof){ putch(ch, NO); if (ch == '*'){gotstar: if ((ch = getch()) == '/'){ putch(ch,NO); return(hitnl); } putch(ch,NO); if (ch == '*')goto gotstar; } if (ch == '\n'){ if(ok && !hitnl){ outs(clev->tabs); } else { outs(0); } lbegin = 1; count = 0; hitnl = 1; } } return(hitnl);}intcpp_comment(int ok){ int ch; int hitnl; hitnl = 0; while ((ch = getch()) != -1) { if (ch == '\n') { if (ok && !hitnl) outs(clev->tabs); else outs(0); lbegin = 1; count = 0; hitnl = 1; break; } putch(ch, NO); } return hitnl;}voidputspace(char ch, int ok){ if(p == string)putch(ch,ok); else if (*(p - 1) != ch) putch(ch,ok);}intgetch(void){ char c; if(inswitch){ if(next != '\0'){ c=next; next = '\0'; return(c); } if(tptr <= lastplace){ if(*tptr != '\0')return(*tptr++); else if(++tptr <= lastplace)return(*tptr++); } inswitch=0; lastplace = tptr = temp; } return(Bgetc(input));}voidunget(char c){ if(inswitch){ if(tptr != temp) *(--tptr) = c; else next = c; } else Bungetc(input);}char *getnext(int must){ int c; char *beg; int prect,nlct; prect = nlct = 0; if(tptr > lastplace){ tptr = lastplace = temp; err = 0; inswitch = 0; } tp = lastplace; if(inswitch && tptr <= lastplace) if (isalnum(*lastplace)||ispunct(*lastplace)||isop(*lastplace))return(lastplace);space: while(isspace(c=Bgetc(input)))puttmp(c,1); beg = tp; puttmp(c,1); if(c == '/'){ if(puttmp(Bgetc(input),1) == '*'){cont: while((c=Bgetc(input)) != '*'){ puttmp(c,0); if(must == 0 && c == '\n') if(nlct++ > 2)goto done; } puttmp(c,1); star: if(puttmp((c=Bgetc(input)),1) == '/'){ beg = tp; puttmp((c=Bgetc(input)),1); } else if(c == '*')goto star; else goto cont; } else goto done; } if(isspace(c))goto space; if(c == '#' && tp > temp+1 && *(tp-2) == '\n'){ if(prect++ > 2)goto done; while(puttmp((c=Bgetc(input)),1) != '\n') if(c == '\\')puttmp(Bgetc(input),1); goto space; } if(isalnum(c)){ while(isalnum(c = Bgetc(input)))puttmp(c,1); Bungetc(input); }done: puttmp('\0',1); lastplace = tp-1; inswitch = 1; return(beg);}voidcopy(char *s){ while(*s != '\0')putch(*s++,NO);}voidclearif(struct indent *cl){ int i; for(i=0;i<IFLEVEL-1;i++)cl->ifc[i] = 0;}char puttmp(char c, int keep){ if(tp < &temp[TEMP-120]) *tp++ = c; else { if(keep){ if(tp >= &temp[TEMP-1]){ fprint(2,"can't look past huge comment - quiting\n"); exits("boom"); } *tp++ = c; } else if(err == 0){ err++; fprint(2,"truncating long comment\n"); } } return(c);}voiderror(char *s){ fprint(2,"saw EOF while looking for %s\n",s); exits("boom");}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -