process.c (80286) | process.c (87766) |
---|---|
1/*- 2 * Copyright (c) 1992 Diomidis Spinellis. 3 * Copyright (c) 1992, 1993, 1994 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Diomidis Spinellis of Imperial College, University of London. 8 * --- 21 unchanged lines hidden (view full) --- 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 | 1/*- 2 * Copyright (c) 1992 Diomidis Spinellis. 3 * Copyright (c) 1992, 1993, 1994 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Diomidis Spinellis of Imperial College, University of London. 8 * --- 21 unchanged lines hidden (view full) --- 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 */ 37 |
38#include <sys/cdefs.h> 39__FBSDID("$FreeBSD: head/usr.bin/sed/process.c 87766 2001-12-12 23:20:16Z markm $"); 40 |
|
38#ifndef lint | 41#ifndef lint |
39#if 0 40static char sccsid[] = "@(#)process.c 8.6 (Berkeley) 4/20/94"; | 42static const char sccsid[] = "@(#)process.c 8.6 (Berkeley) 4/20/94"; |
41#endif | 43#endif |
42static const char rcsid[] = 43 "$FreeBSD: head/usr.bin/sed/process.c 80286 2001-07-24 14:05:21Z obrien $"; 44#endif /* not lint */ | |
45 46#include <sys/types.h> 47#include <sys/stat.h> 48#include <sys/ioctl.h> 49#include <sys/uio.h> 50 51#include <ctype.h> 52#include <err.h> --- 401 unchanged lines hidden (view full) --- 454 } 455 if (ferror(stdout)) 456 errx(1, "stdout: %s", strerror(errno ? errno : EIO)); 457 appendx = sdone = 0; 458} 459 460static void 461lputs(s) | 44 45#include <sys/types.h> 46#include <sys/stat.h> 47#include <sys/ioctl.h> 48#include <sys/uio.h> 49 50#include <ctype.h> 51#include <err.h> --- 401 unchanged lines hidden (view full) --- 453 } 454 if (ferror(stdout)) 455 errx(1, "stdout: %s", strerror(errno ? errno : EIO)); 456 appendx = sdone = 0; 457} 458 459static void 460lputs(s) |
462 register char *s; | 461 char *s; |
463{ | 462{ |
464 register int count; 465 register char *escapes, *p; | 463 int count; 464 char *escapes, *p; |
466 struct winsize win; 467 static int termwidth = -1; 468 469 if (termwidth == -1) { 470 if ((p = getenv("COLUMNS"))) 471 termwidth = atoi(p); 472 else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && 473 win.ws_col > 0) --- 65 unchanged lines hidden (view full) --- 539 * regsub - perform substitutions after a regexp match 540 * Based on a routine by Henry Spencer 541 */ 542static void 543regsub(sp, string, src) 544 SPACE *sp; 545 char *string, *src; 546{ | 465 struct winsize win; 466 static int termwidth = -1; 467 468 if (termwidth == -1) { 469 if ((p = getenv("COLUMNS"))) 470 termwidth = atoi(p); 471 else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && 472 win.ws_col > 0) --- 65 unchanged lines hidden (view full) --- 538 * regsub - perform substitutions after a regexp match 539 * Based on a routine by Henry Spencer 540 */ 541static void 542regsub(sp, string, src) 543 SPACE *sp; 544 char *string, *src; 545{ |
547 register int len, no; 548 register char c, *dst; | 546 int len, no; 547 char c, *dst; |
549 550#define NEEDSP(reqlen) \ 551 if (sp->len >= sp->blen - (reqlen) - 1) { \ 552 sp->blen += (reqlen) + 1024; \ 553 if ((sp->space = sp->back = realloc(sp->back, sp->blen)) \ 554 == NULL) \ 555 err(1, "realloc"); \ 556 dst = sp->space + sp->len; \ --- 56 unchanged lines hidden (view full) --- 613 sp->space[sp->len += len] = '\0'; 614} 615 616/* 617 * Close all cached opened files and report any errors 618 */ 619void 620cfclose(cp, end) | 548 549#define NEEDSP(reqlen) \ 550 if (sp->len >= sp->blen - (reqlen) - 1) { \ 551 sp->blen += (reqlen) + 1024; \ 552 if ((sp->space = sp->back = realloc(sp->back, sp->blen)) \ 553 == NULL) \ 554 err(1, "realloc"); \ 555 dst = sp->space + sp->len; \ --- 56 unchanged lines hidden (view full) --- 612 sp->space[sp->len += len] = '\0'; 613} 614 615/* 616 * Close all cached opened files and report any errors 617 */ 618void 619cfclose(cp, end) |
621 register struct s_command *cp, *end; | 620 struct s_command *cp, *end; |
622{ 623 624 for (; cp != end; cp = cp->next) 625 switch(cp->code) { 626 case 's': 627 if (cp->u.s->wfd != -1 && close(cp->u.s->wfd)) 628 err(1, "%s", cp->u.s->wfile); 629 cp->u.s->wfd = -1; 630 break; 631 case 'w': 632 if (cp->u.fd != -1 && close(cp->u.fd)) 633 err(1, "%s", cp->t); 634 cp->u.fd = -1; 635 break; 636 case '{': 637 cfclose(cp->u.c, cp->next); 638 break; 639 } 640} | 621{ 622 623 for (; cp != end; cp = cp->next) 624 switch(cp->code) { 625 case 's': 626 if (cp->u.s->wfd != -1 && close(cp->u.s->wfd)) 627 err(1, "%s", cp->u.s->wfile); 628 cp->u.s->wfd = -1; 629 break; 630 case 'w': 631 if (cp->u.fd != -1 && close(cp->u.fd)) 632 err(1, "%s", cp->t); 633 cp->u.fd = -1; 634 break; 635 case '{': 636 cfclose(cp->u.c, cp->next); 637 break; 638 } 639} |