| expr.c (9d14cf08bcba73bac30314cd22629a0fec28f929) | expr.c (cc22b130832529204c03214239a57aaadd05101f) |
|---|---|
| 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the |
| 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. | 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. |
| 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23/* All Rights Reserved */ 24 25 26/* | 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 22/* All Rights Reserved */ 23 24 25/* |
| 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. | 26 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. |
| 29 */ 30 | 27 */ 28 |
| 31#pragma ident "%Z%%M% %I% %E% SMI" 32 | |
| 33#include <stdlib.h> 34#include <regexpr.h> 35#include <locale.h> 36#include <string.h> 37#include <unistd.h> 38#include <regex.h> 39#include <limits.h> 40#include <stdio.h> --- 12 unchanged lines hidden (view full) --- 53#define NEQ 267 54#define ADD 268 55#define SUBT 269 56#define MULT 270 57#define DIV 271 58#define REM 272 59#define MCH 273 60#define MATCH 274 | 29#include <stdlib.h> 30#include <regexpr.h> 31#include <locale.h> 32#include <string.h> 33#include <unistd.h> 34#include <regex.h> 35#include <limits.h> 36#include <stdio.h> --- 12 unchanged lines hidden (view full) --- 49#define NEQ 267 50#define ADD 268 51#define SUBT 269 52#define MULT 270 53#define DIV 271 54#define REM 272 55#define MCH 273 56#define MATCH 274 |
| 61#ifdef _iBCS2 62#define SUBSTR 276 63#define LENGTH 277 64#define INDEX 278 65#endif /* _iBCS2 */ | 57#define SUBSTR 275 58#define LENGTH 276 59#define INDEX 277 |
| 66 67/* size of subexpression array */ 68#define MSIZE LINE_MAX 69#define error(c) errxx() 70#define EQL(x, y) (strcmp(x, y) == 0) 71 72#define ERROR(c) errxx() 73#define MAX_MATCH 20 --- 9 unchanged lines hidden (view full) --- 83static char *ltoa(); 84static char *lltoa(); 85static char **Av; 86static char *buf; 87static int Ac; 88static int Argi; 89static int noarg; 90static int paren; | 60 61/* size of subexpression array */ 62#define MSIZE LINE_MAX 63#define error(c) errxx() 64#define EQL(x, y) (strcmp(x, y) == 0) 65 66#define ERROR(c) errxx() 67#define MAX_MATCH 20 --- 9 unchanged lines hidden (view full) --- 77static char *ltoa(); 78static char *lltoa(); 79static char **Av; 80static char *buf; 81static int Ac; 82static int Argi; 83static int noarg; 84static int paren; |
| 91#ifdef _iBCS2 92char *sysv3_set; 93#endif /* _iBCS2 */ | |
| 94/* 95 * Array used to store subexpressions in regular expressions 96 * Only one subexpression allowed per regular expression currently 97 */ 98static char Mstring[1][MSIZE]; 99 100 101static char *operator[] = { 102 "|", "&", "+", "-", "*", "/", "%", ":", 103 "=", "==", "<", "<=", ">", ">=", "!=", 104 "match", | 85/* 86 * Array used to store subexpressions in regular expressions 87 * Only one subexpression allowed per regular expression currently 88 */ 89static char Mstring[1][MSIZE]; 90 91 92static char *operator[] = { 93 "|", "&", "+", "-", "*", "/", "%", ":", 94 "=", "==", "<", "<=", ">", ">=", "!=", 95 "match", |
| 105#ifdef _iBCS2 | |
| 106 "substr", "length", "index", | 96 "substr", "length", "index", |
| 107#endif /* _iBCS2 */ | |
| 108 "\0" }; 109static int op[] = { 110 OR, AND, ADD, SUBT, MULT, DIV, REM, MCH, 111 EQ, EQ, LT, LEQ, GT, GEQ, NEQ, | 97 "\0" }; 98static int op[] = { 99 OR, AND, ADD, SUBT, MULT, DIV, REM, MCH, 100 EQ, EQ, LT, LEQ, GT, GEQ, NEQ, |
| 112 MATCH 113#ifdef _iBCS2 114, SUBSTR, LENGTH, INDEX 115#endif /* _iBCS2 */ | 101 MATCH, 102 SUBSTR, LENGTH, INDEX |
| 116 }; 117static int pri[] = { | 103 }; 104static int pri[] = { |
| 118 1, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7 119#ifdef _iBCS2 120, 7, 7, 7 121#endif /* _iBCS2 */ | 105 1, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 106 7, 7, 7 |
| 122 }; 123 124 125/* 126 * clean_buf - XCU4 mod to remove leading zeros from negative signed 127 * numeric output, e.g., -00001 becomes -1 128 */ 129static void --- 204 unchanged lines hidden (view full) --- 334 rv = "0"; 335 else 336 rv = r1; 337 break; 338 } 339 return (rv); 340} 341 | 107 }; 108 109 110/* 111 * clean_buf - XCU4 mod to remove leading zeros from negative signed 112 * numeric output, e.g., -00001 becomes -1 113 */ 114static void --- 204 unchanged lines hidden (view full) --- 319 rv = "0"; 320 else 321 rv = r1; 322 break; 323 } 324 return (rv); 325} 326 |
| 342#ifdef _iBCS2 | |
| 343char * 344substr(char *v, char *s, char *w) 345{ 346 int si, wi; 347 char *res; 348 349 si = atol(s); 350 wi = atol(w); --- 31 unchanged lines hidden (view full) --- 382 char *rv; 383 384 while (*s++) ++i; 385 386 rv = exprmalloc(8); 387 (void) strcpy(rv, ltoa(i)); 388 return (rv); 389} | 327char * 328substr(char *v, char *s, char *w) 329{ 330 int si, wi; 331 char *res; 332 333 si = atol(s); 334 wi = atol(w); --- 31 unchanged lines hidden (view full) --- 366 char *rv; 367 368 while (*s++) ++i; 369 370 rv = exprmalloc(8); 371 (void) strcpy(rv, ltoa(i)); 372 return (rv); 373} |
| 390#endif /* _iBCS2 */ | |
| 391 392static char * 393match(char *s, char *p) 394{ 395 char *rv; 396 long val; /* XCU4 */ 397 398 (void) strcpy(rv = exprmalloc(8), ltoa(val = (long)ematch(s, p))); --- 208 unchanged lines hidden (view full) --- 607 if (par != 0) { 608 paren--; 609 Argi++; 610 } 611 Argi++; 612 return (r1); 613 } 614 ylex = yylex(); | 374 375static char * 376match(char *s, char *p) 377{ 378 char *rv; 379 long val; /* XCU4 */ 380 381 (void) strcpy(rv = exprmalloc(8), ltoa(val = (long)ematch(s, p))); --- 208 unchanged lines hidden (view full) --- 590 if (par != 0) { 591 paren--; 592 Argi++; 593 } 594 Argi++; 595 return (r1); 596 } 597 ylex = yylex(); |
| 615#ifdef _iBCS2 616 if (ylex > MCH && ((sysv3_set && ylex <= INDEX) || ylex <= MATCH)) { 617#else 618 if (ylex > MCH && ylex <= MATCH) { 619#endif /* _iBCS2 */ | 598 if (ylex > MCH && ylex <= INDEX) { |
| 620 if (Argi == temp) { 621 return (r1); 622 } 623 op1 = ylex; 624 Argi++; 625 switch (op1) { 626 case MATCH: 627 rb = expres(pri[op1-OR], 0); 628 ra = expres(pri[op1-OR], 0); 629 break; | 599 if (Argi == temp) { 600 return (r1); 601 } 602 op1 = ylex; 603 Argi++; 604 switch (op1) { 605 case MATCH: 606 rb = expres(pri[op1-OR], 0); 607 ra = expres(pri[op1-OR], 0); 608 break; |
| 630#ifdef _iBCS2 | |
| 631 case SUBSTR: 632 rc = expres(pri[op1-OR], 0); 633 rb = expres(pri[op1-OR], 0); 634 ra = expres(pri[op1-OR], 0); 635 break; 636 case LENGTH: 637 ra = expres(pri[op1-OR], 0); 638 break; 639 case INDEX: 640 rb = expres(pri[op1-OR], 0); 641 ra = expres(pri[op1-OR], 0); 642 break; | 609 case SUBSTR: 610 rc = expres(pri[op1-OR], 0); 611 rb = expres(pri[op1-OR], 0); 612 ra = expres(pri[op1-OR], 0); 613 break; 614 case LENGTH: 615 ra = expres(pri[op1-OR], 0); 616 break; 617 case INDEX: 618 rb = expres(pri[op1-OR], 0); 619 ra = expres(pri[op1-OR], 0); 620 break; |
| 643#endif /* _iBCS2 */ | |
| 644 } 645 switch (op1) { 646 case MATCH: 647 r1 = match(rb, ra); 648 break; | 621 } 622 switch (op1) { 623 case MATCH: 624 r1 = match(rb, ra); 625 break; |
| 649#ifdef _iBCS2 | |
| 650 case SUBSTR: 651 r1 = substr(rc, rb, ra); 652 break; 653 case LENGTH: 654 r1 = length(ra); 655 break; 656 case INDEX: 657 r1 = index(rb, ra); 658 break; | 626 case SUBSTR: 627 r1 = substr(rc, rb, ra); 628 break; 629 case LENGTH: 630 r1 = length(ra); 631 break; 632 case INDEX: 633 r1 = index(rb, ra); 634 break; |
| 659#endif /* _iBCS2 */ | |
| 660 } 661 if (noarg == 1) { 662 return (r1); 663 } 664 Argi--; 665 goto lop; 666 } 667 ylex = yylex(); --- 38 unchanged lines hidden (view full) --- 706 (void) fprintf(stderr, gettext("Usage: expr expression\n")); 707 exit(3); 708 } 709 Ac = argc; 710 Argi = 1; 711 noarg = 0; 712 paren = 0; 713 Av = argv; | 635 } 636 if (noarg == 1) { 637 return (r1); 638 } 639 Argi--; 640 goto lop; 641 } 642 ylex = yylex(); --- 38 unchanged lines hidden (view full) --- 681 (void) fprintf(stderr, gettext("Usage: expr expression\n")); 682 exit(3); 683 } 684 Ac = argc; 685 Argi = 1; 686 noarg = 0; 687 paren = 0; 688 Av = argv; |
| 714#ifdef _iBCS2 715 sysv3_set = getenv("SYSV3"); 716#endif /* _iBCS2 */ | |
| 717 718 (void) setlocale(LC_ALL, ""); 719#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 720#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 721#endif 722 (void) textdomain(TEXT_DOMAIN); 723 buf = expres(0, 1); 724 if (Ac != Argi || paren != 0) { 725 yyerror("syntax error"); 726 } 727 /* 728 * XCU4 - strip leading zeros from numeric output 729 */ 730 clean_buf(buf); 731 (void) write(1, buf, (unsigned)strlen(buf)); 732 (void) write(1, "\n", 1); 733 return ((strcmp(buf, "0") == 0 || buf[0] == 0) ? 1 : 0); 734} | 689 690 (void) setlocale(LC_ALL, ""); 691#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 692#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 693#endif 694 (void) textdomain(TEXT_DOMAIN); 695 buf = expres(0, 1); 696 if (Ac != Argi || paren != 0) { 697 yyerror("syntax error"); 698 } 699 /* 700 * XCU4 - strip leading zeros from numeric output 701 */ 702 clean_buf(buf); 703 (void) write(1, buf, (unsigned)strlen(buf)); 704 (void) write(1, "\n", 1); 705 return ((strcmp(buf, "0") == 0 || buf[0] == 0) ? 1 : 0); 706} |