compile.c (197356) | compile.c (197361) |
---|---|
1/*- 2 * Copyright (c) 1992 Diomidis Spinellis. 3 * Copyright (c) 1992, 1993 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 * --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1992 Diomidis Spinellis. 3 * Copyright (c) 1992, 1993 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 * --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 197356 2009-09-20 14:11:33Z dds $"); | 35__FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 197361 2009-09-20 15:17:40Z dds $"); |
36 37#ifndef lint 38static const char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93"; 39#endif 40 41#include <sys/types.h> 42#include <sys/stat.h> 43 --- 17 unchanged lines hidden (view full) --- 61 struct labhash *lh_next; 62 u_int lh_hash; 63 struct s_command *lh_cmd; 64 int lh_ref; 65} *labels[LHSZ]; 66 67static char *compile_addr(char *, struct s_addr *); 68static char *compile_ccl(char **, char *); | 36 37#ifndef lint 38static const char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93"; 39#endif 40 41#include <sys/types.h> 42#include <sys/stat.h> 43 --- 17 unchanged lines hidden (view full) --- 61 struct labhash *lh_next; 62 u_int lh_hash; 63 struct s_command *lh_cmd; 64 int lh_ref; 65} *labels[LHSZ]; 66 67static char *compile_addr(char *, struct s_addr *); 68static char *compile_ccl(char **, char *); |
69static char *compile_delimited(char *, char *); | 69static char *compile_delimited(char *, char *, int); |
70static char *compile_flags(char *, struct s_subst *); 71static regex_t *compile_re(char *, int); 72static char *compile_subst(char *, struct s_subst *); 73static char *compile_text(void); 74static char *compile_tr(char *, struct s_tr **); 75static struct s_command 76 **compile_stream(struct s_command **); 77static char *duptoeol(char *, const char *); --- 237 unchanged lines hidden (view full) --- 315 case SUBST: /* s */ 316 p++; 317 if (*p == '\0' || *p == '\\') 318 errx(1, 319"%lu: %s: substitute pattern can not be delimited by newline or backslash", 320 linenum, fname); 321 if ((cmd->u.s = calloc(1, sizeof(struct s_subst))) == NULL) 322 err(1, "malloc"); | 70static char *compile_flags(char *, struct s_subst *); 71static regex_t *compile_re(char *, int); 72static char *compile_subst(char *, struct s_subst *); 73static char *compile_text(void); 74static char *compile_tr(char *, struct s_tr **); 75static struct s_command 76 **compile_stream(struct s_command **); 77static char *duptoeol(char *, const char *); --- 237 unchanged lines hidden (view full) --- 315 case SUBST: /* s */ 316 p++; 317 if (*p == '\0' || *p == '\\') 318 errx(1, 319"%lu: %s: substitute pattern can not be delimited by newline or backslash", 320 linenum, fname); 321 if ((cmd->u.s = calloc(1, sizeof(struct s_subst))) == NULL) 322 err(1, "malloc"); |
323 p = compile_delimited(p, re); | 323 p = compile_delimited(p, re, 0); |
324 if (p == NULL) 325 errx(1, 326 "%lu: %s: unterminated substitute pattern", linenum, fname); 327 328 /* Compile RE with no case sensitivity temporarily */ 329 if (*re == '\0') 330 cmd->u.s->re = NULL; 331 else --- 36 unchanged lines hidden (view full) --- 368 * to a buffer area. Newline and delimiter escapes are processed; other 369 * escapes are ignored. 370 * 371 * Returns a pointer to the first character after the final delimiter or NULL 372 * in the case of a non-terminated string. The character array d is filled 373 * with the processed string. 374 */ 375static char * | 324 if (p == NULL) 325 errx(1, 326 "%lu: %s: unterminated substitute pattern", linenum, fname); 327 328 /* Compile RE with no case sensitivity temporarily */ 329 if (*re == '\0') 330 cmd->u.s->re = NULL; 331 else --- 36 unchanged lines hidden (view full) --- 368 * to a buffer area. Newline and delimiter escapes are processed; other 369 * escapes are ignored. 370 * 371 * Returns a pointer to the first character after the final delimiter or NULL 372 * in the case of a non-terminated string. The character array d is filled 373 * with the processed string. 374 */ 375static char * |
376compile_delimited(char *p, char *d) | 376compile_delimited(char *p, char *d, int is_tr) |
377{ 378 char c; 379 380 c = *p++; 381 if (c == '\0') 382 return (NULL); 383 else if (c == '\\') 384 errx(1, "%lu: %s: \\ can not be used as a string delimiter", --- 9 unchanged lines hidden (view full) --- 394 } else if (*p == '\\' && p[1] == '[') { 395 *d++ = *p++; 396 } else if (*p == '\\' && p[1] == c) 397 p++; 398 else if (*p == '\\' && p[1] == 'n') { 399 *d++ = '\n'; 400 p += 2; 401 continue; | 377{ 378 char c; 379 380 c = *p++; 381 if (c == '\0') 382 return (NULL); 383 else if (c == '\\') 384 errx(1, "%lu: %s: \\ can not be used as a string delimiter", --- 9 unchanged lines hidden (view full) --- 394 } else if (*p == '\\' && p[1] == '[') { 395 *d++ = *p++; 396 } else if (*p == '\\' && p[1] == c) 397 p++; 398 else if (*p == '\\' && p[1] == 'n') { 399 *d++ = '\n'; 400 p += 2; 401 continue; |
402 } else if (*p == '\\' && p[1] == '\\') 403 *d++ = *p++; 404 else if (*p == c) { | 402 } else if (*p == '\\' && p[1] == '\\') { 403 if (is_tr) 404 p++; 405 else 406 *d++ = *p++; 407 } else if (*p == c) { |
405 *d = '\0'; 406 return (p + 1); 407 } 408 *d++ = *p++; 409 } 410 return (NULL); 411} 412 --- 236 unchanged lines hidden (view full) --- 649 err(1, NULL); 650 y->multis = NULL; 651 y->nmultis = 0; 652 653 if (*p == '\0' || *p == '\\') 654 errx(1, 655 "%lu: %s: transform pattern can not be delimited by newline or backslash", 656 linenum, fname); | 408 *d = '\0'; 409 return (p + 1); 410 } 411 *d++ = *p++; 412 } 413 return (NULL); 414} 415 --- 236 unchanged lines hidden (view full) --- 652 err(1, NULL); 653 y->multis = NULL; 654 y->nmultis = 0; 655 656 if (*p == '\0' || *p == '\\') 657 errx(1, 658 "%lu: %s: transform pattern can not be delimited by newline or backslash", 659 linenum, fname); |
657 p = compile_delimited(p, old); | 660 p = compile_delimited(p, old, 1); |
658 if (p == NULL) 659 errx(1, "%lu: %s: unterminated transform source string", 660 linenum, fname); | 661 if (p == NULL) 662 errx(1, "%lu: %s: unterminated transform source string", 663 linenum, fname); |
661 p = compile_delimited(p - 1, new); | 664 p = compile_delimited(p - 1, new, 1); |
662 if (p == NULL) 663 errx(1, "%lu: %s: unterminated transform target string", 664 linenum, fname); 665 EATSPACE(); 666 op = old; 667 oldlen = mbsrtowcs(NULL, &op, 0, NULL); 668 if (oldlen == (size_t)-1) 669 err(1, NULL); --- 106 unchanged lines hidden (view full) --- 776 icase = 0; 777 778 a->type = 0; 779 switch (*p) { 780 case '\\': /* Context address */ 781 ++p; 782 /* FALLTHROUGH */ 783 case '/': /* Context address */ | 665 if (p == NULL) 666 errx(1, "%lu: %s: unterminated transform target string", 667 linenum, fname); 668 EATSPACE(); 669 op = old; 670 oldlen = mbsrtowcs(NULL, &op, 0, NULL); 671 if (oldlen == (size_t)-1) 672 err(1, NULL); --- 106 unchanged lines hidden (view full) --- 779 icase = 0; 780 781 a->type = 0; 782 switch (*p) { 783 case '\\': /* Context address */ 784 ++p; 785 /* FALLTHROUGH */ 786 case '/': /* Context address */ |
784 p = compile_delimited(p, re); | 787 p = compile_delimited(p, re, 0); |
785 if (p == NULL) 786 errx(1, "%lu: %s: unterminated regular expression", linenum, fname); 787 /* Check for case insensitive regexp flag */ 788 if (*p == 'I') { 789 icase = 1; 790 p++; 791 } 792 if (*re == '\0') --- 152 unchanged lines hidden --- | 788 if (p == NULL) 789 errx(1, "%lu: %s: unterminated regular expression", linenum, fname); 790 /* Check for case insensitive regexp flag */ 791 if (*p == 'I') { 792 icase = 1; 793 p++; 794 } 795 if (*re == '\0') --- 152 unchanged lines hidden --- |