parse.y (127807) | parse.y (178846) |
---|---|
1%{ 2/* 3 * Copyright (c) 1998 - 2000 Kungliga Tekniska H�gskolan 4 * (Royal Institute of Technology, Stockholm, Sweden). 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ | 1%{ 2/* 3 * Copyright (c) 1998 - 2000 Kungliga Tekniska H�gskolan 4 * (Royal Institute of Technology, Stockholm, Sweden). 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ |
34/* $FreeBSD: head/contrib/com_err/parse.y 127807 2004-04-03 21:17:01Z nectar $ */ | 34/* $FreeBSD: head/contrib/com_err/parse.y 178846 2008-05-08 11:01:46Z dfr $ */ |
35 36#include "compile_et.h" 37#include "lex.h" 38#if 0 | 35 36#include "compile_et.h" 37#include "lex.h" 38#if 0 |
39RCSID("$Id: parse.y,v 1.11 2000/06/22 00:42:52 assar Exp $"); | 39RCSID("$Id: parse.y 15426 2005-06-16 19:21:42Z lha $"); |
40#endif 41 42void yyerror (char *s); 43static long name2number(const char *str); 44 45extern char *yytext; 46 47/* This is for bison */ --- 26 unchanged lines hidden (view full) --- 74id : ID STRING 75 { 76 id_str = $2; 77 } 78 ; 79 80et : ET STRING 81 { | 40#endif 41 42void yyerror (char *s); 43static long name2number(const char *str); 44 45extern char *yytext; 46 47/* This is for bison */ --- 26 unchanged lines hidden (view full) --- 74id : ID STRING 75 { 76 id_str = $2; 77 } 78 ; 79 80et : ET STRING 81 { |
82 base = name2number($2); 83 strncpy(name, $2, sizeof(name)); 84 name[sizeof(name) - 1] = '\0'; | 82 base_id = name2number($2); 83 strlcpy(name, $2, sizeof(name)); |
85 free($2); 86 } 87 | ET STRING STRING 88 { | 84 free($2); 85 } 86 | ET STRING STRING 87 { |
89 base = name2number($2); 90 strncpy(name, $3, sizeof(name)); 91 name[sizeof(name) - 1] = '\0'; | 88 base_id = name2number($2); 89 strlcpy(name, $3, sizeof(name)); |
92 free($2); 93 free($3); 94 } 95 ; 96 97statements : statement 98 | statements statement 99 ; 100 101statement : INDEX NUMBER 102 { 103 number = $2; 104 } 105 | PREFIX STRING 106 { | 90 free($2); 91 free($3); 92 } 93 ; 94 95statements : statement 96 | statements statement 97 ; 98 99statement : INDEX NUMBER 100 { 101 number = $2; 102 } 103 | PREFIX STRING 104 { |
107 prefix = realloc(prefix, strlen($2) + 2); 108 strcpy(prefix, $2); 109 strcat(prefix, "_"); | 105 free(prefix); 106 asprintf (&prefix, "%s_", $2); 107 if (prefix == NULL) 108 errx(1, "malloc"); |
110 free($2); 111 } 112 | PREFIX 113 { 114 prefix = realloc(prefix, 1); | 109 free($2); 110 } 111 | PREFIX 112 { 113 prefix = realloc(prefix, 1); |
114 if (prefix == NULL) 115 errx(1, "malloc"); |
|
115 *prefix = '\0'; 116 } 117 | EC STRING ',' STRING 118 { 119 struct error_code *ec = malloc(sizeof(*ec)); | 116 *prefix = '\0'; 117 } 118 | EC STRING ',' STRING 119 { 120 struct error_code *ec = malloc(sizeof(*ec)); |
121 122 if (ec == NULL) 123 errx(1, "malloc"); |
|
120 121 ec->next = NULL; 122 ec->number = number; 123 if(prefix && *prefix != '\0') { 124 asprintf (&ec->name, "%s%s", prefix, $2); | 124 125 ec->next = NULL; 126 ec->number = number; 127 if(prefix && *prefix != '\0') { 128 asprintf (&ec->name, "%s%s", prefix, $2); |
129 if (ec->name == NULL) 130 errx(1, "malloc"); |
|
125 free($2); 126 } else 127 ec->name = $2; 128 ec->string = $4; 129 APPEND(codes, ec); 130 number++; 131 } 132 | END 133 { 134 YYACCEPT; 135 } 136 ; 137 138%% 139 140static long 141name2number(const char *str) 142{ 143 const char *p; | 131 free($2); 132 } else 133 ec->name = $2; 134 ec->string = $4; 135 APPEND(codes, ec); 136 number++; 137 } 138 | END 139 { 140 YYACCEPT; 141 } 142 ; 143 144%% 145 146static long 147name2number(const char *str) 148{ 149 const char *p; |
144 long base = 0; | 150 long num = 0; |
145 const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 146 "abcdefghijklmnopqrstuvwxyz0123456789_"; 147 if(strlen(str) > 4) { 148 yyerror("table name too long"); 149 return 0; 150 } 151 for(p = str; *p; p++){ 152 char *q = strchr(x, *p); 153 if(q == NULL) { 154 yyerror("invalid character in table name"); 155 return 0; 156 } | 151 const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 152 "abcdefghijklmnopqrstuvwxyz0123456789_"; 153 if(strlen(str) > 4) { 154 yyerror("table name too long"); 155 return 0; 156 } 157 for(p = str; *p; p++){ 158 char *q = strchr(x, *p); 159 if(q == NULL) { 160 yyerror("invalid character in table name"); 161 return 0; 162 } |
157 base = (base << 6) + (q - x) + 1; | 163 num = (num << 6) + (q - x) + 1; |
158 } | 164 } |
159 base <<= 8; 160 if(base > 0x7fffffff) 161 base = -(0xffffffff - base + 1); 162 return base; | 165 num <<= 8; 166 if(num > 0x7fffffff) 167 num = -(0xffffffff - num + 1); 168 return num; |
163} 164 165void 166yyerror (char *s) 167{ 168 error_message ("%s\n", s); 169} | 169} 170 171void 172yyerror (char *s) 173{ 174 error_message ("%s\n", s); 175} |