bc.y (259785) | bc.y (265533) |
---|---|
1%{ | 1%{ |
2/* $OpenBSD: bc.y,v 1.33 2009/10/27 23:59:36 deraadt Exp $ */ | 2/* $OpenBSD: bc.y,v 1.44 2013/11/20 21:33:54 deraadt Exp $ */ |
3 4/* 5 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * --- 15 unchanged lines hidden (view full) --- 26 * completely rewritten lexical analyzer using lex(1). 27 * 28 * Some effort has been made to make sure that the generated code is 29 * the same as the code generated by the older version, to provide 30 * easy regression testing. 31 */ 32 33#include <sys/cdefs.h> | 3 4/* 5 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * --- 15 unchanged lines hidden (view full) --- 26 * completely rewritten lexical analyzer using lex(1). 27 * 28 * Some effort has been made to make sure that the generated code is 29 * the same as the code generated by the older version, to provide 30 * easy regression testing. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: stable/10/usr.bin/bc/bc.y 259785 2013-12-23 20:20:46Z delphij $"); | 34__FBSDID("$FreeBSD: stable/10/usr.bin/bc/bc.y 265533 2014-05-07 08:06:54Z delphij $"); |
35 36#include <sys/types.h> 37#include <sys/wait.h> 38 39#include <ctype.h> 40#include <err.h> 41#include <errno.h> 42#include <getopt.h> 43#include <histedit.h> 44#include <limits.h> 45#include <search.h> 46#include <signal.h> 47#include <stdarg.h> | 35 36#include <sys/types.h> 37#include <sys/wait.h> 38 39#include <ctype.h> 40#include <err.h> 41#include <errno.h> 42#include <getopt.h> 43#include <histedit.h> 44#include <limits.h> 45#include <search.h> 46#include <signal.h> 47#include <stdarg.h> |
48#include <stdbool.h> | |
49#include <string.h> 50#include <unistd.h> 51#include <stdlib.h> 52 53#include "extern.h" 54#include "pathnames.h" 55 | 48#include <string.h> 49#include <unistd.h> 50#include <stdlib.h> 51 52#include "extern.h" 53#include "pathnames.h" 54 |
56#define BC_VER "1.0-FreeBSD" | 55#define BC_VER "1.1-FreeBSD" |
57#define END_NODE ((ssize_t) -1) 58#define CONST_STRING ((ssize_t) -2) 59#define ALLOC_STRING ((ssize_t) -3) 60 61extern char *yytext; 62extern FILE *yyin; 63 64struct tree { --- 901 unchanged lines hidden (view full) --- 966yyerror(const char *s) 967{ 968 char *p, *str; 969 int n; 970 971 if (yyin != NULL && feof(yyin)) 972 n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF", 973 __progname, filename, lineno, s); | 56#define END_NODE ((ssize_t) -1) 57#define CONST_STRING ((ssize_t) -2) 58#define ALLOC_STRING ((ssize_t) -3) 59 60extern char *yytext; 61extern FILE *yyin; 62 63struct tree { --- 901 unchanged lines hidden (view full) --- 965yyerror(const char *s) 966{ 967 char *p, *str; 968 int n; 969 970 if (yyin != NULL && feof(yyin)) 971 n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF", 972 __progname, filename, lineno, s); |
974 else if (isspace(yytext[0]) || !isprint(yytext[0])) | 973 else if (yytext[0] == '\n') |
975 n = asprintf(&str, | 974 n = asprintf(&str, |
975 "%s: %s:%d: %s: newline unexpected", 976 __progname, filename, lineno, s); 977 else if (isspace((unsigned char)yytext[0]) || 978 !isprint((unsigned char)yytext[0])) 979 n = asprintf(&str, |
|
976 "%s: %s:%d: %s: ascii char 0x%02x unexpected", 977 __progname, filename, lineno, s, yytext[0]); 978 else 979 n = asprintf(&str, "%s: %s:%d: %s: %s unexpected", 980 __progname, filename, lineno, s, yytext); 981 if (n == -1) 982 err(1, NULL); 983 --- 96 unchanged lines hidden (view full) --- 1080 *p++ = *str++; 1081 } 1082 *p = '\0'; 1083 return (ret); 1084} 1085 1086/* ARGSUSED */ 1087static void | 980 "%s: %s:%d: %s: ascii char 0x%02x unexpected", 981 __progname, filename, lineno, s, yytext[0]); 982 else 983 n = asprintf(&str, "%s: %s:%d: %s: %s unexpected", 984 __progname, filename, lineno, s, yytext); 985 if (n == -1) 986 err(1, NULL); 987 --- 96 unchanged lines hidden (view full) --- 1084 *p++ = *str++; 1085 } 1086 *p = '\0'; 1087 return (ret); 1088} 1089 1090/* ARGSUSED */ 1091static void |
1088sigchld(int signo) | 1092sigchld(int signo __unused) |
1089{ 1090 pid_t pid; | 1093{ 1094 pid_t pid; |
1091 int status; | 1095 int status, save_errno = errno; |
1092 | 1096 |
1093 switch (signo) { 1094 default: 1095 for (;;) { 1096 pid = waitpid(dc, &status, WUNTRACED); 1097 if (pid == -1) { 1098 if (errno == EINTR) 1099 continue; 1100 _exit(0); 1101 } 1102 if (WIFEXITED(status) || WIFSIGNALED(status)) 1103 _exit(0); 1104 else 1105 break; 1106 } | 1097 for (;;) { 1098 pid = waitpid(dc, &status, WCONTINUED | WNOHANG); 1099 if (pid == -1) { 1100 if (errno == EINTR) 1101 continue; 1102 _exit(0); 1103 } else if (pid == 0) 1104 break; 1105 if (WIFEXITED(status) || WIFSIGNALED(status)) 1106 _exit(0); 1107 else 1108 break; |
1107 } | 1109 } |
1110 errno = save_errno; |
|
1108} 1109 1110static const char * 1111dummy_prompt(void) 1112{ 1113 1114 return (""); 1115} --- 70 unchanged lines hidden (view full) --- 1186 dup(p[0]); 1187 close(p[0]); 1188 close(p[1]); 1189 execl(_PATH_DC, "dc", "-x", (char *)NULL); 1190 err(1, "cannot find dc"); 1191 } 1192 } 1193 if (interactive) { | 1111} 1112 1113static const char * 1114dummy_prompt(void) 1115{ 1116 1117 return (""); 1118} --- 70 unchanged lines hidden (view full) --- 1189 dup(p[0]); 1190 close(p[0]); 1191 close(p[1]); 1192 execl(_PATH_DC, "dc", "-x", (char *)NULL); 1193 err(1, "cannot find dc"); 1194 } 1195 } 1196 if (interactive) { |
1197 gettty(&ttysaved); |
|
1194 el = el_init("bc", stdin, stderr, stderr); 1195 hist = history_init(); 1196 history(hist, &he, H_SETSIZE, 100); 1197 el_set(el, EL_HIST, history, hist); 1198 el_set(el, EL_EDITOR, "emacs"); 1199 el_set(el, EL_SIGNAL, 1); 1200 el_set(el, EL_PROMPT, dummy_prompt); | 1198 el = el_init("bc", stdin, stderr, stderr); 1199 hist = history_init(); 1200 history(hist, &he, H_SETSIZE, 100); 1201 el_set(el, EL_HIST, history, hist); 1202 el_set(el, EL_EDITOR, "emacs"); 1203 el_set(el, EL_SIGNAL, 1); 1204 el_set(el, EL_PROMPT, dummy_prompt); |
1205 el_set(el, EL_ADDFN, "bc_eof", "", bc_eof); 1206 el_set(el, EL_BIND, "^D", "bc_eof", NULL); |
|
1201 el_source(el, NULL); 1202 } 1203 yywrap(); 1204 return (yyparse()); 1205} | 1207 el_source(el, NULL); 1208 } 1209 yywrap(); 1210 return (yyparse()); 1211} |