# HG changeset patch # User markus schnalke # Date 1428867934 -7200 # Node ID ac52712b2b5e4a2f3aeea734fa4c17245b05adad # Parent a09d0630f05b2b4d78205d4d10b4e12ac689d5d8 Remove the fspec(5) tabulator support We don't want such bloat in ed(1)! diff -r a09d0630f05b -r ac52712b2b5e ed.1 --- a/ed.1 Tue Aug 12 18:08:24 2014 +0200 +++ b/ed.1 Sun Apr 12 21:45:34 2015 +0200 @@ -74,31 +74,6 @@ in a temporary file called the .IR buffer . .PP -The editor supports format specifications as defined in -.IR fspec (5). -If the terminal is configured to expand tabulators -(as enabled with -.I stty tab3 -or -.IR "stty \-tabs"), -and the first line of the file being edited -contains a format specification, -the -.I t -and -.I s -are interpreted, -that is, tabulators are expanded and lines are truncated -when printing to the terminal. For example, -.RS -<:t\-f s72:> -.sp -.RE -selects FORTRAN format and truncates lines at 72 characters. -No expansion or truncation is performed by -.I ed -when input is typed to the terminal. -.PP Commands to .I ed have a simple and regular structure: zero or diff -r a09d0630f05b -r ac52712b2b5e ed.c --- a/ed.c Tue Aug 12 18:08:24 2014 +0200 +++ b/ed.c Sun Apr 12 21:45:34 2015 +0200 @@ -68,7 +68,6 @@ #include #include #include "sigset.h" -#include #include #include #include @@ -77,7 +76,6 @@ #include #include #include -#include static int FNSIZE; static int LBSIZE; static int RHSIZE; @@ -99,13 +97,6 @@ #define WRITE 1 #define EXIST 2 -struct tabulator { - struct tabulator *t_nxt; /* next list element */ - const char *t_str; /* tabulator string */ - int t_tab; /* tab stop position */ - int t_rep; /* repetitive tab count */ -}; - static int peekc; static int lastc; static char *savedfile; @@ -166,7 +157,6 @@ static int mb_cur_max; static int needsub; static int insub; -static struct tabulator *tabstops; static int maxlength; static int rspec; static int Nflag; @@ -235,11 +225,6 @@ static int creatf(const char *); static int sopen(const char *, int); static void sclose(int); -static void fspec(const char *); -static const char *ftok(const char **); -static struct tabulator *tabstring(const char *); -static void freetabs(void); -static void expand(const char *); static void growlb(const char *); static void growrhs(const char *); static void growfn(const char *); @@ -1127,8 +1112,6 @@ } while (c != '\n'); linebuf[--i] = 0; nextj = j; - if (rspec && dot == zero) - fspec(linebuf); if (maxlength && i > maxlength) { putstr("line too long: lno = "); putd((dot - zero+1)&MAXCNT); @@ -1969,8 +1952,6 @@ { if (listf) list(sp); - else if (tabstops) - expand(sp); else puts(sp); } @@ -2234,247 +2215,6 @@ readop = 0; } -static void -fspec(const char *lp) -{ - struct termios ts; - const char *cp; - - freetabs(); - maxlength = 0; - if (tcgetattr(1, &ts) < 0 -#ifdef TAB3 - || (ts.c_oflag&TAB3) == 0 -#endif - ) - return; - while (lp[0]) { - if (lp[0] == '<' && lp[1] == ':') - break; - lp++; - } - if (lp[0]) { - lp += 2; - while ((cp = ftok(&lp)) != NULL) { - switch (*cp) { - case 't': - freetabs(); - if ((tabstops = tabstring(&cp[1])) == NULL) - goto err; - break; - case 's': - maxlength = atoi(&cp[1]); - break; - case 'm': - case 'd': - case 'e': - break; - case ':': - if (cp[1] == '>') { - if (tabstops == NULL) - if ((tabstops = tabstring("0")) - == NULL) - goto err; - return; - } - /*FALLTHRU*/ - default: - err: freetabs(); - maxlength = 0; - errput("PWB spec problem", NULL); - return; - } - } - } -} - -static const char * -ftok(const char **lp) -{ - const char *cp; - - while (**lp && **lp != ':' && (**lp == ' ' || **lp == '\t')) - (*lp)++; - cp = *lp; - while (**lp && **lp != ':' && **lp != ' ' && **lp != '\t') - (*lp)++; - return cp; -} - -static struct tabulator * -repetitive(int repetition) -{ - struct tabulator *tp, *tabspec; - int col, i; - - if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL) - return NULL; - tp->t_rep = repetition; - if (repetition > 0) { - for (col = 1+repetition, i = 0; i < 22; col += repetition) { - if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL) - return NULL; - tp = tp->t_nxt; - tp->t_tab = col; - } - } - return tabspec; -} - -#define blank(c) ((c) == ' ' || (c) == '\t') - -static struct tabulator * -tablist(const char *s) -{ - struct tabulator *tp, *tabspec; - char *x; - int prev = 0, val; - - if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL) - return NULL; - for (;;) { - while (*s == ',') - s++; - if (*s == '\0' || blank(*s) || *s == ':') - break; - val = strtol(s, &x, 10); - if (*s == '+') - val += prev; - prev = val; - if (*s == '-' || (*x != ',' && !blank(*x) && *x != ':' && - *x != '\0')) - return NULL; - s = x; - if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL) - return NULL; - tp = tp->t_nxt; - tp->t_tab = val; - } - return tabspec; -} - -static struct tabulator * -tabstring(const char *s) -{ - const struct { - const char *c_nam; - const char *c_str; - } canned[] = { - { "a", "1,10,16,36,72" }, - { "a2", "1,10,16,40,72" }, - { "c", "1,8,12,16,20,55" }, - { "c2", "1,6,10,14,49" }, - { "c3", "1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67" }, - { "f", "1,7,11,15,19,23" }, - { "p", "1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61" }, - { "s", "1,10,55" }, - { "u", "1,12,20,44" }, - { 0, 0 } - }; - - int i, j; - - if (s[0] == '-') { - if (s[1] >= '0' && s[1] <= '9' && ((i = atoi(&s[1])) != 0)) - return repetitive(i); - for (i = 0; canned[i].c_nam; i++) { - for (j = 0; canned[i].c_nam[j]; j++) - if (s[j+1] != canned[i].c_nam[j]) - break; - if ((s[j+1]=='\0' || s[j+1]==':' || blank(s[j+1])) && - canned[i].c_nam[j] == '\0') - return tablist(canned[i].c_str); - } - return NULL; - } else - return tablist(s); -} - -static void -freetabs(void) -{ - struct tabulator *tp; - - tp = tabstops; - while (tp) { - tabstops = tp->t_nxt; - free(tp); - tp = tabstops; - } -} - -static void -expand(const char *s) -{ - struct tabulator *tp = tabstops; - int col = 0, n = 1, m, tabcnt = 0, nspc; - wchar_t wc; - - while (*s) { - nspc = 0; - switch (*s) { - case '\n': - putchr('\0'); - s++; - continue; - case '\t': - if (tp) { - if (tp->t_rep) { - if (col % tp->t_rep == 0) { - nspc++; - col++; - } - while (col % tp->t_rep) { - nspc++; - col++; - } - break; - } - while (tp && (col>tp->t_tab || tp->t_tab == 0)) - tp = tp->t_nxt; - if (tp && col == tp->t_tab) { - nspc++; - col++; - tp = tp->t_nxt; - } - if (tp) { - while (col < tp->t_tab) { - nspc++; - col++; - } - tp = tp->t_nxt; - break; - } - } - tabcnt = 1; - nspc++; - break; - default: - if (mb_cur_max>1 && (n=mbtowc(&wc, s, mb_cur_max))>0) { - if ((m = wcwidth(wc)) > 0) - col += m; - } else { - col++; - n = 1; - } - } - if (maxlength && col > maxlength) { - putstr("\ntoo long"); - break; - } - if (nspc) { - while (nspc--) - putchr(' '); - s++; - } else - while (n--) - putchr(*s++); - } - if (tabcnt) - putstr("\ntab count"); - putchr('\n'); -} - static wint_t GETWC(char *mb) {