summaryrefslogtreecommitdiff
path: root/usr.bin/yacc/main.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-11-05 09:36:23 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-11-05 09:36:23 +0000
commit64d7c58621387164e66efac991e7f8c6dda7bba9 (patch)
treefd56178ce53ffacf0aa4d06f65617641f614c793 /usr.bin/yacc/main.c
parent21ff7274cfc683669ff3601a2a20d5a56501bf6d (diff)
handle c++ and other languages; buffer underrun; netbsd pr#4392;
fixes from jfw@jfwhome.funhouse.com
Diffstat (limited to 'usr.bin/yacc/main.c')
-rw-r--r--usr.bin/yacc/main.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/usr.bin/yacc/main.c b/usr.bin/yacc/main.c
index 3ced574d390..5f0b65d107e 100644
--- a/usr.bin/yacc/main.c
+++ b/usr.bin/yacc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.7 1997/04/04 18:41:38 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.8 1997/11/05 09:36:22 deraadt Exp $ */
/* $NetBSD: main.c,v 1.5 1996/03/19 03:21:38 jtc Exp $ */
/*
@@ -47,7 +47,7 @@ char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.7 1997/04/04 18:41:38 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.8 1997/11/05 09:36:22 deraadt Exp $";
#endif
#endif /* not lint */
@@ -358,12 +358,33 @@ create_file_names()
{
if (explicit_file_name)
{
- defines_file_name = MALLOC(strlen(output_file_name));
+ char *suffix;
+
+ defines_file_name = MALLOC(strlen(output_file_name)+1);
if (defines_file_name == 0)
no_space();
strcpy(defines_file_name, output_file_name);
- if (!strcmp(output_file_name + (strlen(output_file_name)-2), ".c"))
- defines_file_name [strlen(output_file_name)-1] = 'h';
+
+ /* does the output_file_name have a known suffix */
+ if ((suffix = strrchr(output_file_name, '.')) != 0 &&
+ (!strcmp(suffix, ".c") || /* good, old-fashioned C */
+ !strcmp(suffix, ".C") || /* C++, or C on Windows */
+ !strcmp(suffix, ".cc") || /* C++ */
+ !strcmp(suffix, ".cxx") || /* C++ */
+ !strcmp(suffix, ".cpp"))) /* C++ (Windows) */
+ {
+ strncpy(defines_file_name, output_file_name,
+ suffix - output_file_name + 1);
+ defines_file_name[suffix - output_file_name + 1] = 'h';
+ defines_file_name[suffix - output_file_name + 2] = '\0';
+ } else {
+ fprintf(stderr,"%s: suffix of output file name %s"
+ " not recognized, no -d file generated.\n",
+ myname, output_file_name);
+ dflag = 0;
+ free(defines_file_name);
+ defines_file_name = 0;
+ }
}
else
{