Mercurial > heirloom-ed
comparison ed.c @ 4:4165f1b57d18 default tip
Become SUSv3 compatible and thus remove own regexp code
The Heirloom tools can be compiled to comply to several standards.
This version does not need this flexibility. We can omit the
regexp code and use the system's, by using the SU3 variant of ed.
This is the latest of the supported standards.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 13 Apr 2015 17:26:51 +0200 |
parents | ac52712b2b5e |
children |
comparison
equal
deleted
inserted
replaced
3:ac52712b2b5e | 4:4165f1b57d18 |
---|---|
45 #elif defined __GNUC__ | 45 #elif defined __GNUC__ |
46 #define USED __attribute__ ((unused)) | 46 #define USED __attribute__ ((unused)) |
47 #else | 47 #else |
48 #define USED | 48 #define USED |
49 #endif | 49 #endif |
50 #if defined (SU3) | |
51 static const char sccsid[] USED = "@(#)ed_su3.sl 1.99 (gritter) 7/27/06"; | 50 static const char sccsid[] USED = "@(#)ed_su3.sl 1.99 (gritter) 7/27/06"; |
52 #elif defined (SUS) | |
53 static const char sccsid[] USED = "@(#)ed_sus.sl 1.99 (gritter) 7/27/06"; | |
54 #elif defined (S42) | |
55 static const char sccsid[] USED = "@(#)ed_s42.sl 1.99 (gritter) 7/27/06"; | |
56 #else /* !SU3, !SUS, !S42 */ | |
57 static const char sccsid[] USED = "@(#)ed.sl 1.99 (gritter) 7/27/06"; | |
58 #endif /* !SU3, !SUS, !S42 */ | |
59 | 51 |
60 #include <sys/types.h> | 52 #include <sys/types.h> |
61 #include <sys/stat.h> | 53 #include <sys/stat.h> |
62 #include <sys/wait.h> | 54 #include <sys/wait.h> |
63 #include <sys/stat.h> | 55 #include <sys/stat.h> |
236 #define PEEKC() (peekc = getchr()) | 228 #define PEEKC() (peekc = getchr()) |
237 #define RETURN(c) return c | 229 #define RETURN(c) return c |
238 #define ERROR(c) cmplerr(c) | 230 #define ERROR(c) cmplerr(c) |
239 static wint_t GETWC(char *); | 231 static wint_t GETWC(char *); |
240 | 232 |
241 #if defined (SUS) || defined (S42) || defined (SU3) | |
242 | |
243 #include <regex.h> | 233 #include <regex.h> |
244 | 234 |
245 #define NBRA 9 | 235 #define NBRA 9 |
246 | 236 |
247 static char *braslist[NBRA]; | 237 static char *braslist[NBRA]; |
252 static int nodelim; | 242 static int nodelim; |
253 | 243 |
254 static char *compile(char *, char *, const char *, int); | 244 static char *compile(char *, char *, const char *, int); |
255 static int step(const char *, const char *); | 245 static int step(const char *, const char *); |
256 | 246 |
257 #else /* !SUS, !S42, !SU3 */ | |
258 | |
259 #include <regexp.h> | |
260 | |
261 #endif /* !SUS, !S42, !SU3 */ | |
262 | |
263 int | 247 int |
264 main(int argc, char **argv) | 248 main(int argc, char **argv) |
265 { | 249 { |
266 register int i; | 250 register int i; |
267 void (*oldintr)(int); | 251 void (*oldintr)(int); |
268 | 252 |
269 progname = basename(argv[0]); | 253 progname = basename(argv[0]); |
270 #if defined (SUS) || defined (S42) || defined (SU3) | |
271 setlocale(LC_COLLATE, ""); | 254 setlocale(LC_COLLATE, ""); |
272 #endif | |
273 setlocale(LC_CTYPE, ""); | 255 setlocale(LC_CTYPE, ""); |
274 mb_cur_max = MB_CUR_MAX; | 256 mb_cur_max = MB_CUR_MAX; |
275 myuid = getuid(); | 257 myuid = getuid(); |
276 oldquit = sigset(SIGQUIT, SIG_IGN); | 258 oldquit = sigset(SIGQUIT, SIG_IGN); |
277 oldhup = sigset(SIGHUP, SIG_IGN); | 259 oldhup = sigset(SIGHUP, SIG_IGN); |
395 checkpoint(); | 377 checkpoint(); |
396 append(gettty, addr2); | 378 append(gettty, addr2); |
397 continue; | 379 continue; |
398 | 380 |
399 case 'c': | 381 case 'c': |
400 #if defined (SU3) | |
401 if (addr1 == zero && addr1+1 <= dol) { | 382 if (addr1 == zero && addr1+1 <= dol) { |
402 if (addr1 == addr2) | 383 if (addr1 == addr2) |
403 addr2++; | 384 addr2++; |
404 addr1++; | 385 addr1++; |
405 } | 386 } |
406 #endif /* SU3 */ | |
407 delete(); | 387 delete(); |
408 append(gettty, addr1-1); | 388 append(gettty, addr1-1); |
409 #if defined (SUS) || defined (SU3) | |
410 if (dot == addr1-1 && addr1 <= dol) | 389 if (dot == addr1-1 && addr1 <= dol) |
411 dot = addr1; | 390 dot = addr1; |
412 #endif /* SUS || SU3 */ | |
413 continue; | 391 continue; |
414 | 392 |
415 case 'd': | 393 case 'd': |
416 delete(); | 394 delete(); |
417 continue; | 395 continue; |
464 puts(prvmsg); | 442 puts(prvmsg); |
465 continue; | 443 continue; |
466 | 444 |
467 case 'i': | 445 case 'i': |
468 setdot(); | 446 setdot(); |
469 #if defined (SU3) | |
470 if (addr1 == zero) { | 447 if (addr1 == zero) { |
471 if (addr1 == addr2) | 448 if (addr1 == addr2) |
472 addr2++; | 449 addr2++; |
473 addr1++; | 450 addr1++; |
474 if (dol != zero) | 451 if (dol != zero) |
475 nonzero(); | 452 nonzero(); |
476 } else | 453 } else |
477 #endif /* SU3 */ | |
478 nonzero(); | 454 nonzero(); |
479 newline(); | 455 newline(); |
480 checkpoint(); | 456 checkpoint(); |
481 append(gettty, addr2-1); | 457 append(gettty, addr2-1); |
482 if (dot == addr2-1) | 458 if (dot == addr2-1) |
1053 if (i >= LBSIZE-2) | 1029 if (i >= LBSIZE-2) |
1054 growlb("line too long"); | 1030 growlb("line too long"); |
1055 linebuf[i++] = 0; | 1031 linebuf[i++] = 0; |
1056 if (linebuf[0]=='.' && linebuf[1]==0) | 1032 if (linebuf[0]=='.' && linebuf[1]==0) |
1057 return(EOF); | 1033 return(EOF); |
1058 #if !defined (SUS) && !defined (SU3) | |
1059 if (linebuf[0]=='\\' && linebuf[1]=='.' && linebuf[2]==0) | |
1060 linebuf[0]='.', linebuf[1]=0; | |
1061 #endif | |
1062 return(0); | 1034 return(0); |
1063 } | 1035 } |
1064 | 1036 |
1065 static long | 1037 static long |
1066 getnum(void) | 1038 getnum(void) |
1728 growlb("line too long"); | 1700 growlb("line too long"); |
1729 genbuf[j++] = c; | 1701 genbuf[j++] = c; |
1730 } | 1702 } |
1731 i = loc2 - linebuf; | 1703 i = loc2 - linebuf; |
1732 loc2 = j + linebuf; | 1704 loc2 = j + linebuf; |
1733 #if defined (SUS) || defined (SU3) || defined (S42) | |
1734 if (loc1 == &linebuf[i]) { | 1705 if (loc1 == &linebuf[i]) { |
1735 int n; | 1706 int n; |
1736 wchar_t wc; | 1707 wchar_t wc; |
1737 if (mb_cur_max > 1 && (n = mbtowc(&wc, loc2, mb_cur_max)) > 0) | 1708 if (mb_cur_max > 1 && (n = mbtowc(&wc, loc2, mb_cur_max)) > 0) |
1738 loc2 += n; | 1709 loc2 += n; |
1739 else | 1710 else |
1740 loc2++; | 1711 loc2++; |
1741 } | 1712 } |
1742 #endif /* SUS || SU3 || S42 */ | |
1743 while (genbuf[j++] = linebuf[i++]) | 1713 while (genbuf[j++] = linebuf[i++]) |
1744 if (j >= LBSIZE) | 1714 if (j >= LBSIZE) |
1745 growlb("line too long"); | 1715 growlb("line too long"); |
1746 if (really) { | 1716 if (really) { |
1747 lp = linebuf; | 1717 lp = linebuf; |
1865 static void | 1835 static void |
1866 cmplerr(int c) | 1836 cmplerr(int c) |
1867 { | 1837 { |
1868 const char *msg; | 1838 const char *msg; |
1869 | 1839 |
1870 #if !defined (SUS) && !defined (S42) && !defined (SU3) | |
1871 expbuf[0] = 0; | |
1872 #endif | |
1873 switch (c) { | 1840 switch (c) { |
1874 case 11: | 1841 case 11: |
1875 msg = "Range endpoint too large"; | 1842 msg = "Range endpoint too large"; |
1876 break; | 1843 break; |
1877 case 16: | 1844 case 16: |
1985 if (col+1 >= 72) { | 1952 if (col+1 >= 72) { |
1986 col = 0; | 1953 col = 0; |
1987 putchr('\\'); | 1954 putchr('\\'); |
1988 putchr('\n'); | 1955 putchr('\n'); |
1989 } | 1956 } |
1990 if (n<0 || | 1957 if (n<0 || c == '\\' || |
1991 #if defined (SUS) || defined (S42) || defined (SU3) | |
1992 c == '\\' || | |
1993 #endif /* SUS || S42 || SU3 */ | |
1994 !(mb_cur_max>1 ? iswprint(c) : isprint(c))) { | 1958 !(mb_cur_max>1 ? iswprint(c) : isprint(c))) { |
1995 if (n<0) | 1959 if (n<0) |
1996 n = 1; | 1960 n = 1; |
1997 while (n--) | 1961 while (n--) |
1998 col += lstchr(*lp++&0377); | 1962 col += lstchr(*lp++&0377); |
2003 } else { | 1967 } else { |
2004 putchr(*lp++&0377); | 1968 putchr(*lp++&0377); |
2005 col++; | 1969 col++; |
2006 } | 1970 } |
2007 } | 1971 } |
2008 #if defined (SUS) || defined (S42) || defined (SU3) | |
2009 putchr('$'); | 1972 putchr('$'); |
2010 #endif | |
2011 putchr('\n'); | 1973 putchr('\n'); |
2012 } | 1974 } |
2013 | 1975 |
2014 static int | 1976 static int |
2015 lstchr(int c) | 1977 lstchr(int c) |
2016 { | 1978 { |
2017 int cad = 1, d; | 1979 int cad = 1, d; |
2018 | 1980 |
2019 #if !defined (SUS) && !defined (S42) && !defined (SU3) | |
2020 if (c=='\t') { | |
2021 c = '>'; | |
2022 goto esc; | |
2023 } | |
2024 if (c=='\b') { | |
2025 c = '<'; | |
2026 esc: | |
2027 putchr('-'); | |
2028 putchr('\b'); | |
2029 putchr(c); | |
2030 } else if (c == '\n') { | |
2031 putchr('\\'); | |
2032 putchr('0'); | |
2033 putchr('0'); | |
2034 putchr('0'); | |
2035 cad = 4; | |
2036 #else /* !SUS, !S42, !SU3 */ | |
2037 if (c == '\n') | 1981 if (c == '\n') |
2038 c = '\0'; | 1982 c = '\0'; |
2039 if (c == '\\') { | 1983 if (c == '\\') { |
2040 putchr('\\'); | 1984 putchr('\\'); |
2041 putchr('\\'); | 1985 putchr('\\'); |
2062 cad = 2; | 2006 cad = 2; |
2063 } else if (c == '\v') { | 2007 } else if (c == '\v') { |
2064 putchr('\\'); | 2008 putchr('\\'); |
2065 putchr('v'); | 2009 putchr('v'); |
2066 cad = 2; | 2010 cad = 2; |
2067 #endif /* !SUS, !S42, !SU3 */ | |
2068 } else { | 2011 } else { |
2069 putchr('\\'); | 2012 putchr('\\'); |
2070 putchr(((c&~077)>>6)+'0'); | 2013 putchr(((c&~077)>>6)+'0'); |
2071 c &= 077; | 2014 c &= 077; |
2072 d = c & 07; | 2015 d = c & 07; |
2279 error(msg); | 2222 error(msg); |
2280 if (FNSIZE == 64) | 2223 if (FNSIZE == 64) |
2281 file[0] = savedfile[0] = 0; | 2224 file[0] = savedfile[0] = 0; |
2282 } | 2225 } |
2283 | 2226 |
2284 #if defined (SUS) || defined (S42) || defined (SU3) | |
2285 union ptrstore { | 2227 union ptrstore { |
2286 void *vp; | 2228 void *vp; |
2287 char bp[sizeof (void *)]; | 2229 char bp[sizeof (void *)]; |
2288 }; | 2230 }; |
2289 | 2231 |
2383 int reflags = 0; | 2325 int reflags = 0; |
2384 | 2326 |
2385 #ifdef REG_ANGLES | 2327 #ifdef REG_ANGLES |
2386 reflags |= REG_ANGLES; | 2328 reflags |= REG_ANGLES; |
2387 #endif | 2329 #endif |
2388 #if defined (SU3) && defined (REG_AVOIDNULL) | 2330 #ifdef REG_AVOIDNULL |
2389 reflags |= REG_AVOIDNULL; | 2331 reflags |= REG_AVOIDNULL; |
2390 #endif | 2332 #endif |
2391 if (op[0]) | 2333 if (op[0]) |
2392 regfree(rp); | 2334 regfree(rp); |
2393 op[0] = 0; | 2335 op[0] = 0; |
2451 braslist[i-1] = braelist[i-1] = NULL; | 2393 braslist[i-1] = braelist[i-1] = NULL; |
2452 } | 2394 } |
2453 } | 2395 } |
2454 return res == 0; | 2396 return res == 0; |
2455 } | 2397 } |
2456 #endif /* SUS || S42 || SU3 */ | |
2457 | 2398 |
2458 static void | 2399 static void |
2459 help(void) | 2400 help(void) |
2460 { | 2401 { |
2461 const char *desc[] = { | 2402 const char *desc[] = { |