heirloom-ed

diff ed.c @ 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
line diff
     1.1 --- a/ed.c	Tue Aug 12 18:08:24 2014 +0200
     1.2 +++ b/ed.c	Sun Apr 12 21:45:34 2015 +0200
     1.3 @@ -68,7 +68,6 @@
     1.4  #include <stdlib.h>
     1.5  #include <signal.h>
     1.6  #include "sigset.h"
     1.7 -#include <termios.h>
     1.8  #include <setjmp.h>
     1.9  #include <libgen.h>
    1.10  #include <inttypes.h>
    1.11 @@ -77,7 +76,6 @@
    1.12  #include <ctype.h>
    1.13  #include <wctype.h>
    1.14  #include <limits.h>
    1.15 -#include <termios.h>
    1.16  static int	FNSIZE;
    1.17  static int	LBSIZE;
    1.18  static int	RHSIZE;
    1.19 @@ -99,13 +97,6 @@
    1.20  #define	WRITE	1
    1.21  #define	EXIST	2
    1.22  
    1.23 -struct	tabulator {
    1.24 -	struct tabulator	*t_nxt;	/* next list element */
    1.25 -	const char	*t_str;		/* tabulator string */
    1.26 -	int	t_tab;			/* tab stop position */
    1.27 -	int	t_rep;			/* repetitive tab count */
    1.28 -};
    1.29 -
    1.30  static int	peekc;
    1.31  static int	lastc;
    1.32  static char	*savedfile;
    1.33 @@ -166,7 +157,6 @@
    1.34  static int	mb_cur_max;
    1.35  static int	needsub;
    1.36  static int	insub;
    1.37 -static struct tabulator	*tabstops;
    1.38  static int	maxlength;
    1.39  static int	rspec;
    1.40  static int	Nflag;
    1.41 @@ -235,11 +225,6 @@
    1.42  static int	creatf(const char *);
    1.43  static int	sopen(const char *, int);
    1.44  static void	sclose(int);
    1.45 -static void	fspec(const char *);
    1.46 -static const char	*ftok(const char **);
    1.47 -static struct tabulator	*tabstring(const char *);
    1.48 -static void	freetabs(void);
    1.49 -static void	expand(const char *);
    1.50  static void	growlb(const char *);
    1.51  static void	growrhs(const char *);
    1.52  static void	growfn(const char *);
    1.53 @@ -1127,8 +1112,6 @@
    1.54  	} while (c != '\n');
    1.55  	linebuf[--i] = 0;
    1.56  	nextj = j;
    1.57 -	if (rspec && dot == zero)
    1.58 -		fspec(linebuf);
    1.59  	if (maxlength && i > maxlength) {
    1.60  		putstr("line too long: lno = ");
    1.61  		putd((dot - zero+1)&MAXCNT);
    1.62 @@ -1969,8 +1952,6 @@
    1.63  {
    1.64  	if (listf)
    1.65  		list(sp);
    1.66 -	else if (tabstops)
    1.67 -		expand(sp);
    1.68  	else
    1.69  		puts(sp);
    1.70  }
    1.71 @@ -2234,247 +2215,6 @@
    1.72  	readop = 0;
    1.73  }
    1.74  
    1.75 -static void
    1.76 -fspec(const char *lp)
    1.77 -{
    1.78 -	struct termios	ts;
    1.79 -	const char	*cp;
    1.80 -
    1.81 -	freetabs();
    1.82 -	maxlength = 0;
    1.83 -	if (tcgetattr(1, &ts) < 0
    1.84 -#ifdef	TAB3
    1.85 -			|| (ts.c_oflag&TAB3) == 0
    1.86 -#endif
    1.87 -			)
    1.88 -		return;
    1.89 -	while (lp[0]) {
    1.90 -		if (lp[0] == '<' && lp[1] == ':')
    1.91 -			break;
    1.92 -		lp++;
    1.93 -	}
    1.94 -	if (lp[0]) {
    1.95 -		lp += 2;
    1.96 -		while ((cp = ftok(&lp)) != NULL) {
    1.97 -			switch (*cp) {
    1.98 -			case 't':
    1.99 -				freetabs();
   1.100 -				if ((tabstops = tabstring(&cp[1])) == NULL)
   1.101 -					goto err;
   1.102 -				break;
   1.103 -			case 's':
   1.104 -				maxlength = atoi(&cp[1]);
   1.105 -				break;
   1.106 -			case 'm':
   1.107 -			case 'd':
   1.108 -			case 'e':
   1.109 -				break;
   1.110 -			case ':':
   1.111 -				if (cp[1] == '>') {
   1.112 -					if (tabstops == NULL)
   1.113 -						if ((tabstops = tabstring("0"))
   1.114 -								== NULL)
   1.115 -							goto err;
   1.116 -					return;
   1.117 -				}
   1.118 -				/*FALLTHRU*/
   1.119 -			default:
   1.120 -			err:	freetabs();
   1.121 -				maxlength = 0;
   1.122 -				errput("PWB spec problem", NULL);
   1.123 -				return;
   1.124 -			}
   1.125 -		}
   1.126 -	}
   1.127 -}
   1.128 -
   1.129 -static const char *
   1.130 -ftok(const char **lp)
   1.131 -{
   1.132 -	const char	*cp;
   1.133 -
   1.134 -	while (**lp && **lp != ':' && (**lp == ' ' || **lp == '\t'))
   1.135 -		(*lp)++;
   1.136 -	cp = *lp;
   1.137 -	while (**lp && **lp != ':' && **lp != ' ' && **lp != '\t')
   1.138 -		(*lp)++;
   1.139 -	return cp;
   1.140 -}
   1.141 -
   1.142 -static struct tabulator *
   1.143 -repetitive(int repetition)
   1.144 -{
   1.145 -	struct tabulator	*tp, *tabspec;
   1.146 -	int	col, i;
   1.147 -
   1.148 -	if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL)
   1.149 -		return NULL;
   1.150 -	tp->t_rep = repetition;
   1.151 -	if (repetition > 0) {
   1.152 -		 for (col = 1+repetition, i = 0; i < 22; col += repetition) {
   1.153 -			if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL)
   1.154 -				return NULL;
   1.155 -			tp = tp->t_nxt;
   1.156 -			tp->t_tab = col;
   1.157 -		}
   1.158 -	}
   1.159 -	return tabspec;
   1.160 -}
   1.161 -
   1.162 -#define	blank(c)	((c) == ' ' || (c) == '\t')
   1.163 -
   1.164 -static struct tabulator *
   1.165 -tablist(const char *s)
   1.166 -{
   1.167 -	struct tabulator	*tp, *tabspec;
   1.168 -	char	*x;
   1.169 -	int	prev = 0, val;
   1.170 -
   1.171 -	if ((tp = tabspec = calloc(1, sizeof *tp)) == NULL)
   1.172 -		return NULL;
   1.173 -	for (;;) {
   1.174 -		while (*s == ',')
   1.175 -			s++;
   1.176 -		if (*s == '\0' || blank(*s) || *s == ':')
   1.177 -			break;
   1.178 -		val = strtol(s, &x, 10);
   1.179 -		if (*s == '+')
   1.180 -			val += prev;
   1.181 -		prev = val;
   1.182 -		if (*s == '-' || (*x != ',' && !blank(*x) && *x != ':' &&
   1.183 -					*x != '\0'))
   1.184 -			return NULL;
   1.185 -		s = x;
   1.186 -		if ((tp->t_nxt = calloc(1, sizeof *tp)) == NULL)
   1.187 -			return NULL;
   1.188 -		tp = tp->t_nxt;
   1.189 -		tp->t_tab = val;
   1.190 -	}
   1.191 -	return tabspec;
   1.192 -}
   1.193 -
   1.194 -static struct tabulator *
   1.195 -tabstring(const char *s)
   1.196 -{
   1.197 -	const struct {
   1.198 -		const char	*c_nam;
   1.199 -		const char	*c_str;
   1.200 -	} canned[] = {
   1.201 -		{ "a",	"1,10,16,36,72" },
   1.202 -		{ "a2",	"1,10,16,40,72" },
   1.203 -		{ "c",	"1,8,12,16,20,55" },
   1.204 -		{ "c2",	"1,6,10,14,49" },
   1.205 -		{ "c3",	"1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67" },
   1.206 -		{ "f",	"1,7,11,15,19,23" },
   1.207 -		{ "p",	"1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61" },
   1.208 -		{ "s",	"1,10,55" },
   1.209 -		{ "u",	"1,12,20,44" },
   1.210 -		{ 0,	0 }
   1.211 -	};
   1.212 -
   1.213 -	int	i, j;
   1.214 -
   1.215 -	if (s[0] == '-') {
   1.216 -		if (s[1] >= '0' && s[1] <= '9' && ((i = atoi(&s[1])) != 0))
   1.217 -			return repetitive(i);
   1.218 -		for (i = 0; canned[i].c_nam; i++) {
   1.219 -			for (j = 0; canned[i].c_nam[j]; j++)
   1.220 -				if (s[j+1] != canned[i].c_nam[j])
   1.221 -					break;
   1.222 -			if ((s[j+1]=='\0' || s[j+1]==':' || blank(s[j+1])) &&
   1.223 -					canned[i].c_nam[j] == '\0')
   1.224 -				return tablist(canned[i].c_str);
   1.225 -		}
   1.226 -		return NULL;
   1.227 -	} else
   1.228 -		return tablist(s);
   1.229 -}
   1.230 -
   1.231 -static void
   1.232 -freetabs(void)
   1.233 -{
   1.234 -	struct tabulator	*tp;
   1.235 -
   1.236 -	tp = tabstops;
   1.237 -	while (tp) {
   1.238 -		tabstops = tp->t_nxt;
   1.239 -		free(tp);
   1.240 -		tp = tabstops;
   1.241 -	}
   1.242 -}
   1.243 -
   1.244 -static void
   1.245 -expand(const char *s)
   1.246 -{
   1.247 -	struct tabulator	*tp = tabstops;
   1.248 -	int	col = 0, n = 1, m, tabcnt = 0, nspc;
   1.249 -	wchar_t	wc;
   1.250 -
   1.251 -	while (*s) {
   1.252 -		nspc = 0;
   1.253 -		switch (*s) {
   1.254 -		case '\n':
   1.255 -			putchr('\0');
   1.256 -			s++;
   1.257 -			continue;
   1.258 -		case '\t':
   1.259 -			if (tp) {
   1.260 -				if (tp->t_rep) {
   1.261 -					if (col % tp->t_rep == 0) {
   1.262 -						nspc++;
   1.263 -						col++;
   1.264 -					}
   1.265 -					while (col % tp->t_rep) {
   1.266 -						nspc++;
   1.267 -						col++;
   1.268 -					}
   1.269 -					break;
   1.270 -				}
   1.271 -				while (tp && (col>tp->t_tab || tp->t_tab == 0))
   1.272 -					tp = tp->t_nxt;
   1.273 -				if (tp && col == tp->t_tab) {
   1.274 -					nspc++;
   1.275 -					col++;
   1.276 -					tp = tp->t_nxt;
   1.277 -				}
   1.278 -				if (tp) {
   1.279 -					while (col < tp->t_tab) {
   1.280 -						nspc++;
   1.281 -						col++;
   1.282 -					}
   1.283 -					tp = tp->t_nxt;
   1.284 -					break;
   1.285 -				}
   1.286 -			}
   1.287 -			tabcnt = 1;
   1.288 -			nspc++;
   1.289 -			break;
   1.290 -		default:
   1.291 -			if (mb_cur_max>1 && (n=mbtowc(&wc, s, mb_cur_max))>0) {
   1.292 -				if ((m = wcwidth(wc)) > 0)
   1.293 -					col += m;
   1.294 -			} else {
   1.295 -				col++;
   1.296 -				n = 1;
   1.297 -			}
   1.298 -		}
   1.299 -		if (maxlength && col > maxlength) {
   1.300 -			putstr("\ntoo long");
   1.301 -			break;
   1.302 -		}
   1.303 -		if (nspc) {
   1.304 -			while (nspc--)
   1.305 -				putchr(' ');
   1.306 -			s++;
   1.307 -		} else
   1.308 -			while (n--)
   1.309 -				putchr(*s++);
   1.310 -	}
   1.311 -	if (tabcnt)
   1.312 -		putstr("\ntab count");
   1.313 -	putchr('\n');
   1.314 -}
   1.315 -
   1.316  static wint_t
   1.317  GETWC(char *mb)
   1.318  {