From stefan@fafoe.dyndns.org  Sat Feb 15 10:04:13 2003
Return-Path: <stefan@fafoe.dyndns.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9DB0F37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 15 Feb 2003 10:04:13 -0800 (PST)
Received: from fafoe.dyndns.org (chello212186121237.14.vie.surfer.at [212.186.121.237])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BE81D43F85
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 15 Feb 2003 10:04:12 -0800 (PST)
	(envelope-from stefan@fafoe.dyndns.org)
Received: from frog.fafoe (frog.fafoe [192.168.2.101])
	by fafoe.dyndns.org (Postfix) with ESMTP
	id C4B224050; Sat, 15 Feb 2003 19:04:10 +0100 (CET)
Received: by frog.fafoe (Postfix, from userid 1001)
	id 12C386C0; Sat, 15 Feb 2003 19:04:09 +0100 (CET)
Message-Id: <20030215180409.12C386C0@frog.fafoe>
Date: Sat, 15 Feb 2003 19:04:09 +0100 (CET)
From: Stefan Farfeleder <stefan@fafoe.dyndns.org>
Reply-To: Stefan Farfeleder <stefan@fafoe.dyndns.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: stefan@fafoe.dyndns.org
Subject: [patch] make yacc(1) use getopt(3)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         48313
>Category:       bin
>Synopsis:       [patch] make yacc(1) use getopt(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 15 10:10:13 PST 2003
>Closed-Date:    Thu Mar 04 18:02:36 PST 2004
>Last-Modified:  Thu Mar 04 18:03:37 PST 2004
>Originator:     Stefan Farfeleder
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD frog.fafoe 5.0-CURRENT FreeBSD 5.0-CURRENT #16: Thu Feb 13 22:23:09 CET 2003 freebsd@frog.fafoe:/freebsd/current/obj/freebsd/current/src/sys/FROG i386


	
>Description:
Instead of using getopt(3) yacc parses the command lines options on its
own.  By using getopt(3) code duplication in the for loop can be
eliminated leading to cleaner and shorter code.
	
>How-To-Repeat:
n/a
	
>Fix:

	

--- yacc.diff begins here ---
Index: main.c
===================================================================
RCS file: /usr/home/ncvs/src/usr.bin/yacc/main.c,v
retrieving revision 1.20
diff -c -u -r1.20 main.c
--- main.c	9 Apr 2002 11:39:05 -0000	1.20
+++ main.c	15 Feb 2003 16:17:55 -0000
@@ -168,32 +168,15 @@
 int argc;
 char *argv[];
 {
-    int i;
-    char *s;
+    int ch;
 
-    for (i = 1; i < argc; ++i)
+    while ((ch = getopt(argc, argv, "b:dlo:p:rtv")) != -1)
     {
-	s = argv[i];
-	if (*s != '-') break;
-	switch (*++s)
+	switch (ch)
 	{
-	case '\0':
-	    input_file = stdin;
-	    if (i + 1 < argc) usage();
-	    return;
-
-	case '-':
-	    ++i;
-	    goto no_more_options;
-
 	case 'b':
-	    if (*++s)
-		 file_prefix = s;
-	    else if (++i < argc)
-		file_prefix = argv[i];
-	    else
-		usage();
-	    continue;
+	    file_prefix = optarg;
+	    break;
 
 	case 'd':
 	    dflag = 1;
@@ -204,22 +187,12 @@
 	    break;
 
 	case 'o':
-	    if (*++s)
-		output_file_name = s;
-	    else if (++i < argc)
-		output_file_name = argv[i];
-	    else
-		usage();
-	    continue;
+	    output_file_name = optarg;
+	    break;
 
 	case 'p':
-	    if (*++s)
-		symbol_prefix = s;
-	    else if (++i < argc)
-		symbol_prefix = argv[i];
-	    else
-		usage();
-	    continue;
+	    symbol_prefix = optarg;
+	    break;
 
 	case 'r':
 	    rflag = 1;
@@ -236,44 +209,14 @@
 	default:
 	    usage();
 	}
-
-	for (;;)
-	{
-	    switch (*++s)
-	    {
-	    case '\0':
-		goto end_of_option;
-
-	    case 'd':
-		dflag = 1;
-		break;
-
-	    case 'l':
-		lflag = 1;
-		break;
-
-	    case 'r':
-		rflag = 1;
-		break;
-
-	    case 't':
-		tflag = 1;
-		break;
-
-	    case 'v':
-		vflag = 1;
-		break;
-
-	    default:
-		usage();
-	    }
-	}
-end_of_option:;
     }
 
-no_more_options:;
-    if (i + 1 != argc) usage();
-    input_file_name = argv[i];
+    if (optind + 1 != argc)
+	usage();
+    if (strcmp(argv[optind], "-") == 0)
+	input_file = stdin;
+    else
+	input_file_name = argv[optind];
 }
 
 
--- yacc.diff ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: wes 
State-Changed-When: Thu Mar 4 18:01:08 PST 2004 
State-Changed-Why:  
Committed, with review/prodding from joe@. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=48313 
>Unformatted:

Make that review/prodding by josef@.
