From owner-freebsd-bugs Sat Feb 15 10:10:24 2003 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 90EB437B401 for ; Sat, 15 Feb 2003 10:10:19 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3A47943F93 for ; Sat, 15 Feb 2003 10:10:14 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id h1FIAENS003438 for ; Sat, 15 Feb 2003 10:10:14 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id h1FIADEb003437; Sat, 15 Feb 2003 10:10:13 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9DB0F37B401 for ; 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 ; 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 Reply-To: Stefan Farfeleder To: FreeBSD-gnats-submit@FreeBSD.org Cc: stefan@fafoe.dyndns.org X-Send-Pr-Version: 3.113 Subject: bin/48313: [patch] make yacc(1) use getopt(3) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 48313 >Category: bin >Synopsis: [patch] make yacc(1) use getopt(3) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Feb 15 10:10:13 PST 2003 >Closed-Date: >Last-Modified: >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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message