heirloom-ed
changeset 3:ac52712b2b5e
Remove the fspec(5) tabulator support
We don't want such bloat in ed(1)!
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sun, 12 Apr 2015 21:45:34 +0200 |
parents | a09d0630f05b |
children | 4165f1b57d18 |
files | ed.1 ed.c |
diffstat | 2 files changed, 0 insertions(+), 285 deletions(-) [+] |
line diff
1.1 --- a/ed.1 Tue Aug 12 18:08:24 2014 +0200 1.2 +++ b/ed.1 Sun Apr 12 21:45:34 2015 +0200 1.3 @@ -74,31 +74,6 @@ 1.4 in a temporary file called the 1.5 .IR buffer . 1.6 .PP 1.7 -The editor supports format specifications as defined in 1.8 -.IR fspec (5). 1.9 -If the terminal is configured to expand tabulators 1.10 -(as enabled with 1.11 -.I stty tab3 1.12 -or 1.13 -.IR "stty \-tabs"), 1.14 -and the first line of the file being edited 1.15 -contains a format specification, 1.16 -the 1.17 -.I t 1.18 -and 1.19 -.I s 1.20 -are interpreted, 1.21 -that is, tabulators are expanded and lines are truncated 1.22 -when printing to the terminal. For example, 1.23 -.RS 1.24 -<:t\-f s72:> 1.25 -.sp 1.26 -.RE 1.27 -selects FORTRAN format and truncates lines at 72 characters. 1.28 -No expansion or truncation is performed by 1.29 -.I ed 1.30 -when input is typed to the terminal. 1.31 -.PP 1.32 Commands to 1.33 .I ed 1.34 have a simple and regular structure: zero or
2.1 --- a/ed.c Tue Aug 12 18:08:24 2014 +0200 2.2 +++ b/ed.c Sun Apr 12 21:45:34 2015 +0200 2.3 @@ -68,7 +68,6 @@ 2.4 #include <stdlib.h> 2.5 #include <signal.h> 2.6 #include "sigset.h" 2.7 -#include <termios.h> 2.8 #include <setjmp.h> 2.9 #include <libgen.h> 2.10 #include <inttypes.h> 2.11 @@ -77,7 +76,6 @@ 2.12 #include <ctype.h> 2.13 #include <wctype.h> 2.14 #include <limits.h> 2.15 -#include <termios.h> 2.16 static int FNSIZE; 2.17 static int LBSIZE; 2.18 static int RHSIZE; 2.19 @@ -99,13 +97,6 @@ 2.20 #define WRITE 1 2.21 #define EXIST 2 2.22 2.23 -struct tabulator { 2.24 - struct tabulator *t_nxt; /* next list element */ 2.25 - const char *t_str; /* tabulator string */ 2.26 - int t_tab; /* tab stop position */ 2.27 - int t_rep; /* repetitive tab count */ 2.28 -}; 2.29 - 2.30 static int peekc; 2.31 static int lastc; 2.32 static char *savedfile; 2.33 @@ -166,7 +157,6 @@ 2.34 static int mb_cur_max; 2.35 static int needsub; 2.36 static int insub; 2.37 -static struct tabulator *tabstops; 2.38 static int maxlength; 2.39 static int rspec; 2.40 static int Nflag; 2.41 @@ -235,11 +225,6 @@ 2.42 static int creatf(const char *); 2.43 static int sopen(const char *, int); 2.44 static void sclose(int); 2.45 -static void fspec(const char *); 2.46 -static const char *ftok(const char **); 2.47 -static struct tabulator *tabstring(const char *); 2.48 -static void freetabs(void); 2.49 -static void expand(const char *); 2.50 static void growlb(const char *); 2.51 static void growrhs(const char *); 2.52 static void growfn(const char *); 2.53 @@ -1127,8 +1112,6 @@ 2.54 } while (c != '\n'); 2.55 linebuf[--i] = 0; 2.56 nextj = j; 2.57 - if (rspec && dot == zero) 2.58 - fspec(linebuf); 2.59 if (maxlength && i > maxlength) { 2.60 putstr("line too long: lno = "); 2.61 putd((dot - zero+1)&MAXCNT); 2.62 @@ -1969,8 +1952,6 @@ 2.63 { 2.64 if (listf) 2.65 list(sp); 2.66 - else if (tabstops) 2.67 - expand(sp); 2.68 else 2.69 puts(sp); 2.70 } 2.71 @@ -2234,247 +2215,6 @@ 2.72 readop = 0; 2.73 } 2.74 2.75 -static void 2.76 -fspec(const char *lp) 2.77 -{ 2.78 - struct termios ts; 2.79 - const char *cp; 2.80 - 2.81 - freetabs(); 2.82 - maxlength = 0; 2.83 - if (tcgetattr(1, &ts) < 0 2.84 -#ifdef TAB3 2.85 - || (ts.c_oflag&TAB3) == 0 2.86 -#endif 2.87 - ) 2.88 - return; 2.89 - while (lp[0]) { 2.90 - if (lp[0] == '<' && lp[1] == ':') 2.91 - break; 2.92 - lp++; 2.93 - } 2.94 - if (lp[0]) { 2.95 - lp += 2; 2.96 - while ((cp = ftok(&lp)) != NULL) { 2.97 - switch (*cp) { 2.98 - case 't': 2.99 - freetabs(); 2.100 - if ((tabstops = tabstring(&cp[1])) == NULL) 2.101 - goto err; 2.102 - break; 2.103 - case 's': 2.104 - maxlength = atoi(&cp[1]); 2.105 - break; 2.106 - case 'm': 2.107 - case 'd': 2.108 - case 'e': 2.109 - break; 2.110 - case ':': 2.111 - if (cp[1] == '>') { 2.112 - if (tabstops == NULL) 2.113 - if ((tabstops = tabstring("0")) 2.114 - == NULL) 2.115 - goto err; 2.116 - return; 2.117 - } 2.118 - /*FALLTHRU*/ 2.119 - default: 2.120 - err: freetabs(); 2.121 - maxlength = 0; 2.122 - errput("PWB spec problem", NULL); 2.123 - return; 2.124 - } 2.125 - } 2.126 - } 2.127 -} 2.128 - 2.129 -static const char * 2.130 -ftok(const char **lp) 2.131 -{ 2.132 - const char *cp; 2.133 - 2.134 - while (**lp && **lp != ':' && (**lp == ' ' || **lp == '\t')) 2.135 - (*lp)++; 2.136 - cp = *lp; 2.137 - while (**lp && **lp != ':' && **lp != ' ' && **lp != '\t') 2.138 - (*lp)++; 2.139 - return cp; 2.140 -} 2.141 - 2.142 -static struct tabulator * 2.143 -repetitive(int repetition) 2.144 -{ 2.145 - struct tabulator *tp, *tabspec; 2.146 - int col, i; 2.147 - 2.148 - if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL) 2.149 - return NULL; 2.150 - tp->t_rep = repetition; 2.151 - if (repetition > 0) { 2.152 - for (col = 1+repetition, i = 0; i < 22; col += repetition) { 2.153 - if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL) 2.154 - return NULL; 2.155 - tp = tp->t_nxt; 2.156 - tp->t_tab = col; 2.157 - } 2.158 - } 2.159 - return tabspec; 2.160 -} 2.161 - 2.162 -#define blank(c) ((c) == ' ' || (c) == '\t') 2.163 - 2.164 -static struct tabulator * 2.165 -tablist(const char *s) 2.166 -{ 2.167 - struct tabulator *tp, *tabspec; 2.168 - char *x; 2.169 - int prev = 0, val; 2.170 - 2.171 - if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL) 2.172 - return NULL; 2.173 - for (;;) { 2.174 - while (*s == ',') 2.175 - s++; 2.176 - if (*s == '\0' || blank(*s) || *s == ':') 2.177 - break; 2.178 - val = strtol(s, &x, 10); 2.179 - if (*s == '+') 2.180 - val += prev; 2.181 - prev = val; 2.182 - if (*s == '-' || (*x != ',' && !blank(*x) && *x != ':' && 2.183 - *x != '\0')) 2.184 - return NULL; 2.185 - s = x; 2.186 - if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL) 2.187 - return NULL; 2.188 - tp = tp->t_nxt; 2.189 - tp->t_tab = val; 2.190 - } 2.191 - return tabspec; 2.192 -} 2.193 - 2.194 -static struct tabulator * 2.195 -tabstring(const char *s) 2.196 -{ 2.197 - const struct { 2.198 - const char *c_nam; 2.199 - const char *c_str; 2.200 - } canned[] = { 2.201 - { "a", "1,10,16,36,72" }, 2.202 - { "a2", "1,10,16,40,72" }, 2.203 - { "c", "1,8,12,16,20,55" }, 2.204 - { "c2", "1,6,10,14,49" }, 2.205 - { "c3", "1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67" }, 2.206 - { "f", "1,7,11,15,19,23" }, 2.207 - { "p", "1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61" }, 2.208 - { "s", "1,10,55" }, 2.209 - { "u", "1,12,20,44" }, 2.210 - { 0, 0 } 2.211 - }; 2.212 - 2.213 - int i, j; 2.214 - 2.215 - if (s[0] == '-') { 2.216 - if (s[1] >= '0' && s[1] <= '9' && ((i = atoi(&s[1])) != 0)) 2.217 - return repetitive(i); 2.218 - for (i = 0; canned[i].c_nam; i++) { 2.219 - for (j = 0; canned[i].c_nam[j]; j++) 2.220 - if (s[j+1] != canned[i].c_nam[j]) 2.221 - break; 2.222 - if ((s[j+1]=='\0' || s[j+1]==':' || blank(s[j+1])) && 2.223 - canned[i].c_nam[j] == '\0') 2.224 - return tablist(canned[i].c_str); 2.225 - } 2.226 - return NULL; 2.227 - } else 2.228 - return tablist(s); 2.229 -} 2.230 - 2.231 -static void 2.232 -freetabs(void) 2.233 -{ 2.234 - struct tabulator *tp; 2.235 - 2.236 - tp = tabstops; 2.237 - while (tp) { 2.238 - tabstops = tp->t_nxt; 2.239 - free(tp); 2.240 - tp = tabstops; 2.241 - } 2.242 -} 2.243 - 2.244 -static void 2.245 -expand(const char *s) 2.246 -{ 2.247 - struct tabulator *tp = tabstops; 2.248 - int col = 0, n = 1, m, tabcnt = 0, nspc; 2.249 - wchar_t wc; 2.250 - 2.251 - while (*s) { 2.252 - nspc = 0; 2.253 - switch (*s) { 2.254 - case '\n': 2.255 - putchr('\0'); 2.256 - s++; 2.257 - continue; 2.258 - case '\t': 2.259 - if (tp) { 2.260 - if (tp->t_rep) { 2.261 - if (col % tp->t_rep == 0) { 2.262 - nspc++; 2.263 - col++; 2.264 - } 2.265 - while (col % tp->t_rep) { 2.266 - nspc++; 2.267 - col++; 2.268 - } 2.269 - break; 2.270 - } 2.271 - while (tp && (col>tp->t_tab || tp->t_tab == 0)) 2.272 - tp = tp->t_nxt; 2.273 - if (tp && col == tp->t_tab) { 2.274 - nspc++; 2.275 - col++; 2.276 - tp = tp->t_nxt; 2.277 - } 2.278 - if (tp) { 2.279 - while (col < tp->t_tab) { 2.280 - nspc++; 2.281 - col++; 2.282 - } 2.283 - tp = tp->t_nxt; 2.284 - break; 2.285 - } 2.286 - } 2.287 - tabcnt = 1; 2.288 - nspc++; 2.289 - break; 2.290 - default: 2.291 - if (mb_cur_max>1 && (n=mbtowc(&wc, s, mb_cur_max))>0) { 2.292 - if ((m = wcwidth(wc)) > 0) 2.293 - col += m; 2.294 - } else { 2.295 - col++; 2.296 - n = 1; 2.297 - } 2.298 - } 2.299 - if (maxlength && col > maxlength) { 2.300 - putstr("\ntoo long"); 2.301 - break; 2.302 - } 2.303 - if (nspc) { 2.304 - while (nspc--) 2.305 - putchr(' '); 2.306 - s++; 2.307 - } else 2.308 - while (n--) 2.309 - putchr(*s++); 2.310 - } 2.311 - if (tabcnt) 2.312 - putstr("\ntab count"); 2.313 - putchr('\n'); 2.314 -} 2.315 - 2.316 static wint_t 2.317 GETWC(char *mb) 2.318 {