int main(int argc, const char *argv[]) { char tab[MAXLINE+1]; settab(argc, argv, tab); detab(tab); return 0; }
/*replace strings of blanks with tabs*/ int main(int argc, char *argv[]){ int i; char tab[MAXLINE + 1]; settab(argc, argv, tab); entab(tab); return 0; }
/* replace strings of blanks with tabs */ int main(int argc, char *argv[]) { char tab[MAXLINE+1]; settab(argc, argv, tab); /* initialize tab stops */ entab(tab); /* replace blanks with tabs */ detab(tab); /* replace tab with blanks */ return 0; }
/* &表示\t,*表示空格 */ int main(int argc,char *argv[]) { char *tab; tab=(char *)malloc(100*sizeof(char)); settab(argc,argv,tab); char *sss="1df 567\ta"; char * ss=(char *)malloc(100*sizeof(char)); printf("%s\n",sss); entab(sss,ss,tab); printf("%s\n",ss); return 0; }
int main(int argc, char *argv[]) { int len; char line[MAXLINE]; char final[MAXLINE]; while((len = getLine(line, MAXLINE)) > 0) { settab(line, len, argc, argv); detab(final, line); printf("%s : %s", line, final); } return 0; }
void ttyout(unsigned char c) { switch(mode) { /* Print mode */ case 5: if(c==6) break; pp(c); return; /* No prefix characters */ case 0: switch(c) { case 6: mode=5; return; /* Pass-thru printing */ case 7: bell(); break; case 8: dowrap=0; bs(); break; case 9: tab(); break; case 10: case 11: case 12: dowrap=0; if(mnl) cr(); lf(); break; case 13: dowrap=0; cr(); break; case 27: mode=1; return; case 0x84: dowrap=0; lf(); break; case 0x85: dowrap=0; cr(); lf(); break; case 0x88: settab(); break; case 0x8d: dowrap=0; ups(); break; case 0x9b: begin(); mode=2; return; default: if(minsert) insc(c); else type(c); } break; /* ESC has been received */ case 1: switch(c) { case 27: return; case '[': begin(); mode=2; return; case 'D': dowrap=0; lf(); break; case 'E': dowrap=0; cr(); lf(); break; case 'H': settab(); break; case 'M': dowrap=0; ups(); break; case '#': mode=3; return; } break; /* ESC [ or 0x9B has been received */ case 2: /* Enter numbers */ switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': parry[nptr]=parry[nptr]*10+c-'0'; return; case ';': if(MAXPARMS== ++nptr) break; else return; case 27: mode=1; return; case '[': begin(); return; case 'c': ttyinit(); break; case 'p': dowrap=0; break; /* Reset what? */ case 'r': dowrap=0; setregn(); break; case 'm': setattrib(); break; case 'J': clrs(); break; case 'K': clrl(); break; case 'X': clrc(); break; case 'H': dowrap=0; pos(); break; case 'C': dowrap=0; right(); break; case 'D': dowrap=0; left(); break; case 'A': dowrap=0; up(); break; case 'B': dowrap=0; down(); break; case 'g': clrt(); break; case 'M': dell(); break; case 'L': insl(); break; case 'P': delc(); break; case '@': inss(); break; case 'h': hmode(); break; case 'l': lmode(); break; case '!': case '?': return; } break; /* ESC # has been received */ case 3: switch(c) { case 27: mode=1; return; case '[': begin(); mode=2; return; } break; } mode=0; }
/* * mainloop() - * основной цикл работы редактора */ mainloop() { int i,m,first=1; register int j; int clsave,ccsave; int k; /* Хитрости с экономией памяти */ register int *lre1= &lread1; #define lread1 (*lre1) int thiscol, thisrow; char ich[8], *cp; /* Для команд с тремя вариантами аргументов */ int (*lnfun)(),(*spfun)(); int openlines(), openspaces(), closelines(),closespaces(),picklines(), pickspaces(); /* === */ extern int templ[4]; struct viewport *oport; /* * Обработка одного символа или команды * ==================================== */ if (cursorline== 0) oldcline = 1; if (cursorcol == 0) oldccol = 1; #ifndef lint goto funcdone; #endif FOREVER { csrsw = clrsw = 0; read1(); if (errsw) { errsw = 0; clrsw = 1; goto errclear; } /* * Редактирование в строке */ if ((! CTRLCHAR) || lread1 == CCCTRLQUOTE || lread1 == CCBACKSPACE || lread1 == CCDELCH) { /* Отмена в 1 колонке */ if (lread1 == CCBACKSPACE && cursorcol == 0) { lread1 = -1; goto contin; } if (openwrite[curfile] == 0) goto nowriterr; /* Строки у нас нет? Дай! */ if (clineno != (i = curwksp->ulhclno+cursorline)) getlin(i); /* исключение символа */ if (lread1==CCDELCH || (imodesw && lread1==CCBACKSPACE) ) { thiscol = cursorcol + curwksp->ulhccno; thisrow = cursorline; if (lread1 == CCBACKSPACE) thiscol--; if (ncline < thiscol + 2) { if (lread1 == CCBACKSPACE) movecursor(LT); lread1 = -1; goto contin; } for (i=thiscol;i<ncline-2;i++) cline[i] = cline[i+1]; ncline--; thiscol -= curwksp->ulhccno; putup(-(1+thiscol),cursorline); poscursor(thiscol,thisrow); fcline = 1; lread1 = -1; goto contin; } /* Проверка на границу окна */ if (cursorcol > curport->rtext) { if (fcline) { putline(0); movep(defrport); goto contin; } else goto margerr; } fcline = 1; if (j = (lread1 == CCBACKSPACE)) { movecursor(LT); lread1 = ' '; } if ((i = cursorcol + curwksp->ulhccno) >= (lcline - 2)) excline(i+2); if (i >= ncline-1) { for (k=ncline-1; k<=i; k++) cline[k] = ' '; cline[i+1] = NEWLINE; ncline = i+2; } else if (imodesw) { thiscol = cursorcol + curwksp->ulhccno; thisrow = cursorline; if (ncline >= lcline) excline(ncline+1); for (i=ncline;i>thiscol;i--) cline[i] = cline[i-1]; ncline++; thiscol -= curwksp->ulhccno; putup(-(1+thiscol),cursorline); poscursor(thiscol,thisrow); } /* Выставим границу */ if (cursorcol >= curport->rtext) curport->redit = curport->rtext + 1; /* Замена символа */ if(lread1==CCCTRLQUOTE) lread1 = esc0; if (cursorcol == curport->rtext - 10) putcha(COBELL); cline[i] = lread1; putch(lread1,1); /* Если переехали границу */ curport->redit = curport->rtext; if (j) movecursor(LT); lread1 = -1; goto contin; } /* Сдвиг вниз, если последняя строка */ if (lread1 == CCRETURN ) { putline(0); if ( cursorline == curport->btext) movew(defplline); if((i=curwksp->ulhccno) !=0) movep(-i); movecursor(lread1); lread1= -1; goto errclear; } /* * Если команда перемещения */ if (lread1<=BT) { movecursor(lread1); if (lread1 <= VMOTCODE ) { putline(0); if(curspos) goto newnumber; } lread1 = -1; goto contin; } /* Если граница поля */ if (cursorcol > curport->rtext) poscursor(curport->rtext,cursorline); putline(0); if (lread1 == CCQUIT) { if (endit() == 0) goto funcdone; gosw = 0; return; } switch (lread1) { case CCENTER: goto gotarg; case CCLPORT: movep(- deflport); goto funcdone; case CCSETFILE: switchfile(); goto funcdone; case CCCHPORT: chgport(-1); goto funcdone; case CCOPEN: if (openwrite[curfile]==0) goto nowriterr; openlines(curwksp->ulhclno + cursorline,definsert); goto funcdone; case CCMISRCH: search(-1); goto funcdone; case CCCLOSE: if (openwrite[curfile]==0) goto nowriterr; closelines(curwksp->ulhclno + cursorline, defdelete); goto funcdone; case CCPUT: if (openwrite[curfile]==0) goto nowriterr; if (pickbuf->nrows == 0) goto nopickerr; put(pickbuf,curwksp->ulhclno+cursorline, curwksp->ulhccno+cursorcol); goto funcdone; case CCPICK: picklines(curwksp->ulhclno + cursorline, defpick); goto funcdone; case CCINSMODE: imodesw = 1 - imodesw; /* change it */ goto funcdone; case CCGOTO: gtfcn(0); goto funcdone; case CCMIPAGE: movew(- defmipage * (1+curport->btext)); goto funcdone; case CCPLSRCH: search(1); goto funcdone; case CCRPORT: movep(defrport); goto funcdone; case CCPLLINE: movew(defplline); goto funcdone; case CCDELCH: goto notimperr; case CCSAVEFILE: savefile(NULL,curfile); goto funcdone; case CCMILINE: movew(-defmiline); goto funcdone; case CCDOCMD: goto notstrerr; case CCPLPAGE: movew(defplpage * (1+curport->btext)); goto funcdone; case CCMAKEPORT: makeport(deffile); goto funcdone; case CCTABS: settab(curwksp->ulhccno + cursorcol); goto funcdone; /* case CCMOVELEFT: */ /* case CCTAB: */ /* case CCMOVEDOWN: */ /* case CCHOME: */ /* case CCRETURN: */ /* case CCMOVEUP: */ default: goto badkeyerr; } /* Повтор ввода аргумента */ reparg: read1(); if(CTRLCHAR) goto yesarg; else goto noargerr; /* * Дай аргумент! */ gotarg: param(0); yesarg: if (lread1 == CCQUIT ) { if (paraml>0 && (dechars(paramv,paraml),*paramv) == 'a') { gosw = 0; if (*(paramv+1) != 'd') return; cleanup(); inputfile = -1; /* to force a dump */ fatal("ABORTED"); } if (endit() == 0) goto funcdone; gosw = 1; return; } switch (lread1) { case CCENTER: goto funcdone; case CCLPORT: if (paramtype <= 0) goto notstrerr; if (s2i(paramv,&i)) goto notinterr; movep(-i); goto funcdone; case CCSETFILE: if (paramtype <= 0) goto notstrerr; if (paramv == 0) goto noargerr; if ( use0flg || !inputfile) dechars(paramv,paraml); use0flg=1; editfile(paramv,0,0,1,1); goto funcdone; case CCCHPORT: if (paramtype <= 0) goto notstrerr; if (s2i(paramv,&i)) goto notinterr; if (i <= 0) goto notposerr; chgport(i-1); goto funcdone; case CCOPEN: if (openwrite[curfile]==0) goto nowriterr; if (paramtype == 0) { splitline(curwksp->ulhclno + paramr0, paramc0 + curwksp->ulhccno); goto funcdone; } else { lnfun = openlines; spfun = openspaces; goto spdir; }; case CCMISRCH: case CCPLSRCH: if (paramtype <= 0) goto notstrerr; if (paramv == 0) goto noargerr; if (searchkey) free(searchkey); searchkey = paramv; paraml = 0; search(lread1==CCPLSRCH?1:-1); goto funcdone; case CCCLOSE: if (openwrite[curfile]==0) goto nowriterr; if (paramtype == 0) combineline(curwksp->ulhclno + paramr0, paramc0 + curwksp->ulhccno); else { if(paramtype > 0 && paramv && paramv[0]=='>') { msrbuf(deletebuf,paramv+1,0); goto funcdone; } lnfun = closelines; spfun = closespaces; goto spdir; } goto funcdone; case CCPUT: if (paramtype > 0 && paramv && paramv[0]=='$' ) { if (msrbuf(pickbuf,paramv+1,1))goto errclear; goto funcdone; } if (paramtype != 0) goto notstrerr; if (openwrite[curfile]==0) goto nowriterr; if (deletebuf->nrows == 0) goto nodelerr; put(deletebuf,curwksp->ulhclno+cursorline, curwksp->ulhccno+cursorcol); goto funcdone; case CCMOVELEFT: case CCTAB: case CCMOVEDOWN: case CCHOME: case CCMOVEUP: case CCMOVERIGHT: case CCBACKTAB: if (s2i(paramv,&i)) goto notinterr; if (i <= 0) goto notposerr; m = ((lread1<=BT) ? lread1:0); while (--i >= 0) movecursor(m); goto funcdone; case CCRETURN: if(paramtype <=0|| !paramv) goto notimperr; dechars(paramv,paraml); switch (paramv[0]) { case '>': msvtag(paramv+1); goto funcdone; case '$': if(mdeftag(paramv+1)){ lread1= -1; goto reparg; } else goto funcdone; case 'w': if(paramv[1]==' ' && paramv[2]=='+') openwrite[curwksp->wfile]=1; else openwrite[curwksp->wfile]=0; goto funcdone; case 'k': defkey(); goto funcdone; case 'r': rescreen(-1); goto funcdone; /* Восттановить экран */ case 'd': if(paramv[1]==' ') defmac(¶mv[2]); goto funcdone; case 'q': lread1=CCQUIT; if(paramv[1]=='a') { gosw=0; return; } goto contin; default: goto noargerr; } case CCPICK: if (paramtype == 0) goto notimperr; if (paramtype > 0 && paramv && paramv[0]=='>') { msrbuf(pickbuf,paramv+1,0); goto funcdone; } lnfun = picklines; spfun = pickspaces; goto spdir; case CCINSMODE: imodesw = 1 - imodesw; /* Щелкнем!! */ goto funcdone; case CCGOTO: if (paramtype == 0) gtfcn(nlines[curfile]); else if (paramtype > 0) { if(paramv && paramv[0]=='$') { mgotag(paramv+1); goto funcdone; } if (s2i(paramv,&i)) goto notinterr; gtfcn(i-1); } else goto noargerr; goto funcdone; case CCMIPAGE: if (paramtype <= 0) goto notstrerr; if (s2i(paramv,&i)) goto notinterr; movew(- i * (1 + curport->btext)); goto funcdone; case CCRPORT: if (paramtype <= 0) goto notstrerr; if (s2i(paramv,&i)) goto notinterr; movep(i); goto funcdone; case CCPLLINE: if (paramtype < 0) goto notstrerr; else if (paramtype == 0) movew(cursorline); else if (paramtype > 0) { if (s2i(paramv,&i)) goto notinterr; movew(i); } goto funcdone; case CCDELCH: goto notimperr; case CCSAVEFILE: if (paramtype <= 0) goto notstrerr; if (paramv == 0) goto noargerr; dechars(paramv,paraml); savefile(paramv,curfile); goto funcdone; case CCMILINE: if (paramtype < 0) goto notstrerr; else if (paramtype == 0) movew(cursorline - curport->btext); else if (paramtype > 0) { if (s2i(paramv,&i)) goto notinterr; movew(-i); } goto funcdone; case CCDOCMD: if(paramtype<=0) goto notstrerr; dechars(paramv,paraml); if (openwrite[curfile] == 0) goto nowriterr; callexec(); goto funcdone; case CCPLPAGE: if (paramtype <= 0) goto notstrerr; if (s2i(paramv,&i)) goto notinterr; movew(i * (1 + curport->btext)); goto funcdone; case CCMAKEPORT: if (paramtype == 0) removeport(); else if (paramtype < 0) goto notstrerr; else { dechars(paramv,paraml); makeport(paramv); } goto funcdone; case CCTABS: clrtab(curwksp->ulhccno + cursorcol); goto funcdone; default: goto badkeyerr; } spdir: if (paramtype > 0) { if(paramv[0] == '$') { if(mdeftag(paramv+1)) goto spdir; else goto funcdone; } if (s2i(paramv,&i)) goto notinterr; if (i <= 0) goto notposerr; (*lnfun)(curwksp->ulhclno + cursorline, i); } else { if (paramc1 == paramc0) { (*lnfun)(curwksp->ulhclno+paramr0, (paramr1-paramr0)+1); } else (*spfun)(curwksp->ulhclno + paramr0, curwksp->ulhccno + paramc0, (paramc1-paramc0), (paramr1-paramr0) + 1); } goto funcdone; badkeyerr: error(DIAG("Illegal key or unnown macro","Неизвестная клавиша или макро")); goto funcdone; notstrerr: error(DIAG("Argument must be a string.","Аргумент должен быть строкой")); goto funcdone; noargerr: error(DIAG("Invalid argument.","Плохой аргумент")); goto funcdone; notinterr: error(DIAG("Argument must be numerik.","Аргумент должен быть числом")); goto funcdone; notposerr: error(DIAG("Argument must be positive.","Аргумент должен быть положительным")); goto funcdone; nopickerr: error(DIAG("Nothing in the pick buffer.","Буфер вставок пуст")); goto funcdone; nodelerr: error (DIAG("Nothing in the close buffer.","Буфер убранных строк пуст")); goto funcdone; notimperr: error(DIAG("Feature not implemented yet.","Еще не определено.")); goto funcdone; margerr: error("Margin stusk; move cursor to free."); goto funcdone; nowriterr: error(DIAG("You cannot modify this file!","Вы не можете изменить этот файл.")); goto funcdone; funcdone: clrsw = 1; newnumber: lread1 = -1; /* signify char read was used */ errclear: oport = curport; k = cursorline; j = cursorcol; switchport(¶mport); paramport.redit = PARAMRINFO; if (clrsw) { if (!errsw && !first) { poscursor(0,0); info(blanks,PARAMRINFO); } poscursor(PARAMREDIT+2,0); if (oport->wksp->wfile) { info(DIAG("file ","файл "),PARAMRINFO); info(openfnames[oport->wksp->wfile],PARAMRINFO); } info(DIAG(" line "," строка: "),PARAMRINFO); clsave = cursorline; first=0; ccsave = cursorcol; } poscursor(ccsave,clsave); i = oport->wksp->ulhclno + k + 1; /* Рисуем номер строки */ cp = ich + 8; *--cp = '\0'; do (*--cp = '0' + (i % 10)); while (i = i/10); info(cp,PARAMRINFO); *cp = '\0'; while (cp != ich) *--cp = ' '; info(ich,PARAMRINFO); switchport(oport); paramport.redit = PARAMREDIT; poscursor(j,k); if (csrsw) { putch(COCURS,1); poscursor(j,k); dumpcbuf(); sleep(1); putup(k,k); poscursor(j,k); } if (imodesw && clrsw && !errsw) telluser(DIAG(" ***** i n s e r t m o d e *****"," * * * * режим вставки * * * * "),0); contin: ; } #undef lread1 }
output(){ /* print the output for the states */ int i, j, k, c; settab(); arrset("yyact"); for( i=0; i<nstate; ++i ){ /* output the stuff for state i */ nolook = (tystate[i]==0); closure(i); /* output actions */ aryfil( temp1, nterms+1, 0 ); for( j=0; j<cwset; ++j ){ /* look at the items */ c = *( wsets[j].pitem ); if( c>0 && c<NTBASE && temp1[c]==0 ) temp1[c] = go2(i,c); } if( i == 1 ) temp1[1] = ACCEPTCODE; /* now, we have the shifts; look at the reductions */ lastred = 0; for( j=0; j<cwset; ++j ){ c = *( wsets[j].pitem ); if( c<=0 ){ /* reduction */ lastred = -c; for( k=1; k<=nterms; ++k ){ if( ((wsets[j].ws[k>>4])&(1<<(k&017))) != 0 ) { if( temp1[k] == 0 ) temp1[k] = c; else if( temp1[k]<0 ){ /* reduce/reduce conflict */ settty(); printf("\n%d: reduce/reduce conflict (red'ns %d and %d ) on %s", i, -temp1[k], lastred, symnam(k) ); if( -temp1[k] > lastred ) temp1[k] = -lastred; ++zzrrconf; settab(); } else { /* potential shift/reduce conflict */ switch( precftn( lastred, k ) ) { case 0: /* precedence does not apply */ settty(); printf("\n%d: shift/reduce conflict (shift %d, red'n %d) on %s", i, temp1[k], lastred, symnam(k) ); ++zzsrconf; settab(); break; case 1: /* reduce */ temp1[k] = -lastred; break; case 2: /* error, binary operator */ temp1[k] = ERRCODE; break; case 3: /* shift ... leave the entry alone */ break; } } } } } } wract(i); }