Assign CLI argument to a string variable in Ada -


i having issues when attempting assign command line argument ada program string variable.

here main procedure:

with ada.command_line; use ada.command_line;  procedure proc     cli_exception : exception;     filename : string (1..argument(1)'length);     usage : string (1..31); begin     usage := "usage: ./proc [filename]";     if argument_count /= 1        raise cli_exception;    end if;     arg in 1..argument_count loop        case arg            when 1 =>                filename := argument(arg);            when others =>                null;        end case;    end loop;     put_line("filename is: " & filename); exception     when e: cli_exception =>         put_line(usage); end proc; 

the problem here in declarative part of procedure upper bound string "filename" set. if no cli arguments given, argument(1) throw exception before procedure begins because there no argument #1.

the output is:

raised constraint_error : a-comlin.adb:65 explicit raise 

is there other way of defining size of string variable without using unbounded string, , without picking arbitrary number (as qualified filenames can quite large)?

-thanks

use declare block inside procedure , initialize filename argument value:

-- ... if argument_count /= 1    raise cli_exception; end if;  declare    filename : string := argument (1); begin    -- want filename here. end; 

by way, same usage:

usage : string := "usage: ./proc [filename]"; 

that way, not have count characters each time alter string.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -