3 * Copyright (c) 1986 by University of Toronto.
4 * Written by Henry Spencer. Not derived from licensed software.
6 * Permission is granted to anyone to use this software for any
7 * purpose on any computer system, and to redistribute it freely,
8 * subject to the following restrictions:
10 * 1. The author is not responsible for the consequences of use of
11 * this software, no matter how awful, even if they arise
14 * 2. The origin of this software must not be misrepresented, either
15 * by explicit claim or by omission.
17 * 3. Altered versions must be plainly marked as such, and must not
18 * be misrepresented as being the original software.
23 #define const /* avoid "const poisoning" */
27 /* The first byte of the regexp internal "program" is actually this magic
28 * number; the start node begins in the second byte.
34 #define UCHARAT(p) ((int)*(unsigned char *)(p))
36 #define UCHARAT(p) ((int)*(p)&CHARBITS)
40 - regsub - perform substitutions after a regexp match
42 void regsub(prog
, source
, dest
)
53 if (prog
== (regexp
*)NULL
|| source
== (char *)NULL
|| dest
== (char *)NULL
) {
54 regerror("NULL parm to regsub");
57 if (UCHARAT(prog
->program
) != MAGIC
) {
58 regerror("damaged regexp fed to regsub");
63 while ((c
= *src
++) != '\0') {
66 else if (c
== '\\' && '0' <= *src
&& *src
<= '9')
71 if (no
< 0) { /* Ordinary character. */
72 if (c
== '\\' && (*src
== '\\' || *src
== '&')) c
= *src
++;
75 if (prog
->startp
[no
] != (char *)NULL
&& prog
->endp
[no
] != (char *)NULL
) {
76 len
= (int) (prog
->endp
[no
] - prog
->startp
[no
]);
77 strncpy(dst
, prog
->startp
[no
], len
);
79 if (len
!= 0 && *(dst
- 1) == '\0') { /* strncpy hit NUL. */
80 regerror("damaged match string");
89 * $PchId: regsub.c,v 1.3 1995/11/27 20:18:16 philip Exp $