From patchwork Fri Jun 13 10:08:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 359483 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A5429140093 for ; Fri, 13 Jun 2014 20:08:37 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=dpVCLrAURoqdnlpm3qdeenUHmJAxyYI4E+43xlCZ1pXUvmA7+P 2K9KsaJmq3vRPSUrdkGjJnjfMaBB7+xNXw4BIhVDeNGmNUT9TjLQwARODJCQbZkM Xd1sfv9TmLnrPFPDYg83MfgnCHN7FjtzEhZmZL/Z4ov9S57wDGCAv0bzY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=v0ws9jp1xf29TpjKxJ64SVDz/QE=; b=bGd6EEYh3B3ng4g8KfF/ /+dm8Pr/FU0VCFCQe8RXeJ1+CE9P8OyfrPWUtpno+4Sg8mBgfVHf79UUD4XB3mvX MPI+kSOy59G4IAnj8ekM1T6Uu6uQsynFC6AP0mlS2dmjGzngqmP+kN3JLP7roTmz AjCo4U0KN9sdkdyOY0ZlEpo= Received: (qmail 5519 invoked by alias); 13 Jun 2014 10:08:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5506 invoked by uid 89); 13 Jun 2014 10:08:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 13 Jun 2014 10:08:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 38EDF1160CE; Fri, 13 Jun 2014 06:08:25 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 01fe+4PA62gu; Fri, 13 Jun 2014 06:08:25 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [IPv6:2620:20:4000:0:a6ba:dbff:fe26:1f63]) by rock.gnat.com (Postfix) with ESMTP id 2702E1160AA; Fri, 13 Jun 2014 06:08:25 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 2587591976; Fri, 13 Jun 2014 06:08:25 -0400 (EDT) Date: Fri, 13 Jun 2014 06:08:25 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Emmanuel Briot Subject: [Ada] GNAT.Command_Line.Get_Argument does't expand correctly with custom parser Message-ID: <20140613100825.GA2268@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This patches fixes the use of custom parsers when trying to expand command line arguments like "*.adb". When run from the test directory, the following program should output "next source >>> test_cmd_line1.adb". with Ada.Text_IO; use Ada.Text_IO; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; procedure Test_Cmd_Line1 is Arg_Parser : Opt_Parser := Command_Line_Parser; Switches : String_List_Access := new String_List'(1 => new String'("*.adb")); begin Initialize_Option_Scan (Parser => Arg_Parser, Command_Line => Switches, Stop_At_First_Non_Switch => True, Section_Delimiters => "cargs"); Parse_Params : loop case GNAT.Command_Line.Getopt ("", Parser => Arg_Parser) is when ASCII.NUL => loop Put_Line ("next source >>>" & Get_Argument (Do_Expansion => True, Parser => Arg_Parser)); exit Parse_Params when Next_Source.all = ""; end loop; when others => Put_Line (Full_Switch (Arg_Parser)); end case; end loop Parse_Params; end Test_Cmd_Line1; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-06-13 Emmanuel Briot * g-comlin.adb (Get_Argument): fix expansion of command line arguments (e.g. "*.adb") when using a custom parser. The parser was not passed to the recursive call, and thus we were trying to do the expansion on the default command line parser. Index: g-comlin.adb =================================================================== --- g-comlin.adb (revision 211615) +++ g-comlin.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1999-2013, Free Software Foundation, Inc. -- +-- Copyright (C) 1999-2014, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -402,7 +402,6 @@ end if; if Parser.Current_Argument > Parser.Arg_Count then - -- If this is the first time this function is called if Parser.Current_Index = 1 then @@ -449,21 +448,16 @@ declare Arg : constant String := Argument (Parser, Parser.Current_Argument - 1); - Index : Positive; - begin - Index := Arg'First; - while Index <= Arg'Last loop + for Index in Arg'Range loop if Arg (Index) = '*' or else Arg (Index) = '?' or else Arg (Index) = '[' then Parser.In_Expansion := True; Start_Expansion (Parser.Expansion_It, Arg); - return Get_Argument (Do_Expansion); + return Get_Argument (Do_Expansion, Parser); end if; - - Index := Index + 1; end loop; end; end if;