1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Gnatvsn
; use Gnatvsn
;
29 with Osint
; use Osint
;
30 with Targparm
; use Targparm
;
32 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
33 with Ada
.Command_Line
; use Ada
.Command_Line
;
34 with Ada
.Text_IO
; use Ada
.Text_IO
;
36 package body VMS_Conv
is
38 -------------------------
39 -- Internal Structures --
40 -------------------------
42 -- The switches and commands are defined by strings in the previous
43 -- section so that they are easy to modify, but internally, they are
44 -- kept in a more conveniently accessible form described in this
47 -- Commands, command qualifiers and options have a similar common format
48 -- so that searching for matching names can be done in a common manner.
50 type Item_Id
is (Id_Command
, Id_Switch
, Id_Option
);
52 type Translation_Type
is
55 -- A qualifier with no options.
56 -- Example: GNAT MAKE /VERBOSE
59 -- A qualifier followed by a list of directories
60 -- Example: GNAT COMPILE /SEARCH=([], [.FOO], [.BAR])
63 -- A qualifier followed by one directory
64 -- Example: GNAT LIBRARY /SET=[.VAXFLOATLIB]
67 -- A qualifier followed by a filename
68 -- Example: GNAT LINK /EXECUTABLE=FOO.EXE
71 -- A qualifier followed by a filename
72 -- Example: GNAT MAKE /PROJECT_FILE=PRJ.GPR
75 -- A qualifier followed by a numeric value.
76 -- Example: GNAT CHOP /FILE_NAME_MAX_LENGTH=39
79 -- A qualifier followed by a quoted string. Only used by
80 -- /IDENTIFICATION qualifier.
81 -- Example: GNAT LINK /IDENTIFICATION="3.14a1 version"
84 -- A qualifier followed by a list of options.
85 -- Example: GNAT COMPILE /REPRESENTATION_INFO=(ARRAYS,OBJECTS)
88 -- A qualifier followed by a list. Only used for
89 -- MAKE /COMPILER_QUALIFIERS /BINDER_QUALIFIERS /LINKER_QUALIFIERS
90 -- (gnatmake -cargs -bargs -largs )
91 -- Example: GNAT MAKE ... /LINKER_QUALIFIERS /VERBOSE FOOBAR.OBJ
94 -- A qualifier passed directly to the linker. Only used
95 -- for LINK and SHARED if no other match is found.
96 -- Example: GNAT LINK FOO.ALI /SYSSHR
99 -- A qualifier followed by a legal linker symbol prefix. Only used
100 -- for BIND /BUILD_LIBRARY (gnatbind -Lxyz).
101 -- Example: GNAT BIND /BUILD_LIBRARY=foobar
104 type Item
(Id
: Item_Id
);
105 type Item_Ptr
is access all Item
;
107 type Item
(Id
: Item_Id
) is record
109 -- Name of the command, switch (with slash) or option
112 -- Pointer to next item on list, always has the same Id value
114 Command
: Command_Type
:= Undefined
;
116 Unix_String
: String_Ptr
:= null;
117 -- Corresponding Unix string. For a command, this is the unix command
118 -- name and possible default switches. For a switch or option it is
119 -- the unix switch string.
126 -- Pointer to list of switch items for the command, linked
127 -- through the Next fields with null terminating the list.
130 -- Usage information, used only for errors and the default
131 -- list of commands output.
133 Params
: Parameter_Ref
;
134 -- Array of parameters
136 Defext
: String (1 .. 3);
137 -- Default extension. If non-blank, then this extension is
138 -- supplied by default as the extension for any file parameter
139 -- which does not have an extension already.
143 Translation
: Translation_Type
;
144 -- Type of switch translation. For all cases, except Options,
145 -- this is the only field needed, since the Unix translation
146 -- is found in Unix_String.
149 -- For the Options case, this field is set to point to a list
150 -- of options item (for this case Unix_String is null in the
151 -- main switch item). The end of the list is marked by null.
156 -- No special fields needed, since Name and Unix_String are
157 -- sufficient to completely described an option.
162 subtype Command_Item
is Item
(Id_Command
);
163 subtype Switch_Item
is Item
(Id_Switch
);
164 subtype Option_Item
is Item
(Id_Option
);
166 Keep_Temps_Option
: constant Item_Ptr
:=
170 new String'("/KEEP_TEMPORARY_FILES"),
172 Command
=> Undefined
,
173 Unix_String
=> null);
175 Param_Count
: Natural := 0;
176 -- Number of parameter arguments so far
181 Arg_File
: Ada
.Text_IO
.File_Type
;
182 -- A file where arguments are read from
185 -- Pointer to head of list of command items, one for each command, with
186 -- the end of the list marked by a null pointer.
188 Last_Command
: Item_Ptr
;
189 -- Pointer to last item in Commands list
192 -- Pointer to command item for current command
194 Make_Commands_Active
: Item_Ptr
:= null;
195 -- Set to point to Command entry for COMPILE, BIND, or LINK as appropriate
196 -- if a COMMANDS_TRANSLATION switch has been encountered while processing
199 Output_File_Expected
: Boolean := False;
200 -- True for GNAT LINK after -o switch, so that the ".ali" extension is
201 -- not added to the executable file name.
203 package Buffer
is new Table
.Table
204 (Table_Component_Type
=> Character,
205 Table_Index_Type
=> Integer,
206 Table_Low_Bound
=> 1,
207 Table_Initial
=> 4096,
208 Table_Increment
=> 100,
209 Table_Name
=> "Buffer");
210 -- Table to store the command to be used
212 package Cargs_Buffer
is new Table
.Table
213 (Table_Component_Type
=> Character,
214 Table_Index_Type
=> Integer,
215 Table_Low_Bound
=> 1,
216 Table_Initial
=> 4096,
217 Table_Increment
=> 100,
218 Table_Name
=> "Cargs_Buffer");
219 -- Table to store the compiler switches for GNAT COMPILE
221 Cargs
: Boolean := False;
222 -- When True, commands should go to Cargs_Buffer instead of Buffer table
224 function Init_Object_Dirs
return Argument_List
;
225 -- Get the list of the object directories
227 function Invert_Sense
(S
: String) return VMS_Data
.String_Ptr
;
228 -- Given a unix switch string S, computes the inverse (adding or
229 -- removing ! characters as required), and returns a pointer to
230 -- the allocated result on the heap.
232 function Is_Extensionless
(F
: String) return Boolean;
233 -- Returns true if the filename has no extension
235 function Match
(S1
, S2
: String) return Boolean;
236 -- Determines whether S1 and S2 match (this is a case insensitive match)
238 function Match_Prefix
(S1
, S2
: String) return Boolean;
239 -- Determines whether S1 matches a prefix of S2. This is also a case
240 -- insensitive match (for example Match ("AB","abc") is True).
242 function Matching_Name
245 Quiet
: Boolean := False) return Item_Ptr
;
246 -- Determines if the item list headed by Itm and threaded through the
247 -- Next fields (with null marking the end of the list), contains an
248 -- entry that uniquely matches the given string. The match is case
249 -- insensitive and permits unique abbreviation. If the match succeeds,
250 -- then a pointer to the matching item is returned. Otherwise, an
251 -- appropriate error message is written. Note that the discriminant
252 -- of Itm is used to determine the appropriate form of this message.
253 -- Quiet is normally False as shown, if it is set to True, then no
254 -- error message is generated in a not found situation (null is still
255 -- returned to indicate the not-found situation).
257 function OK_Alphanumerplus
(S
: String) return Boolean;
258 -- Checks that S is a string of alphanumeric characters,
259 -- returning True if all alphanumeric characters,
260 -- False if empty or a non-alphanumeric character is present.
262 function OK_Integer
(S
: String) return Boolean;
263 -- Checks that S is a string of digits, returning True if all digits,
264 -- False if empty or a non-digit is present.
266 procedure Place
(C
: Character);
267 -- Place a single character in the buffer, updating Ptr
269 procedure Place
(S
: String);
270 -- Place a string character in the buffer, updating Ptr
272 procedure Place_Lower
(S
: String);
273 -- Place string in buffer, forcing letters to lower case, updating Ptr
275 procedure Place_Unix_Switches
(S
: VMS_Data
.String_Ptr
);
276 -- Given a unix switch string, place corresponding switches in Buffer,
277 -- updating Ptr appropriately. Note that in the case of use of ! the
278 -- result may be to remove a previously placed switch.
280 procedure Preprocess_Command_Data
;
281 -- Preprocess the string form of the command and options list into the
284 procedure Process_Argument
(The_Command
: in out Command_Type
);
285 -- Process one argument from the command line, or one line from
286 -- from a command line file. For the first call, set The_Command.
288 procedure Process_Buffer
(S
: String);
289 -- Process the characters in the Buffer table or the Cargs_Buffer table
290 -- to convert these into arguments.
292 procedure Validate_Command_Or_Option
(N
: VMS_Data
.String_Ptr
);
293 -- Check that N is a valid command or option name, i.e. that it is of the
294 -- form of an Ada identifier with upper case letters and underscores.
296 procedure Validate_Unix_Switch
(S
: VMS_Data
.String_Ptr
);
297 -- Check that S is a valid switch string as described in the syntax for
298 -- the switch table item UNIX_SWITCH or else begins with a backquote.
300 ----------------------
301 -- Init_Object_Dirs --
302 ----------------------
304 function Init_Object_Dirs
return Argument_List
is
305 Object_Dirs
: Integer;
306 Object_Dir
: Argument_List
(1 .. 256);
307 Object_Dir_Name
: String_Access
;
311 Object_Dir_Name
:= new String'(Object_Dir_Default_Prefix);
312 Get_Next_Dir_In_Path_Init (Object_Dir_Name);
316 Dir : constant String_Access :=
317 String_Access (Get_Next_Dir_In_Path (Object_Dir_Name));
319 exit when Dir = null;
320 Object_Dirs := Object_Dirs + 1;
321 Object_Dir (Object_Dirs) :=
323 To_Canonical_Dir_Spec
325 (Normalize_Directory_Name
(Dir
.all).all,
326 True).all, True).all);
330 Object_Dirs
:= Object_Dirs
+ 1;
331 Object_Dir
(Object_Dirs
) := new String'("-lgnat");
333 if OpenVMS_On_Target then
334 Object_Dirs := Object_Dirs + 1;
335 Object_Dir (Object_Dirs) := new String'("-ldecgnat");
338 return Object_Dir
(1 .. Object_Dirs
);
339 end Init_Object_Dirs
;
345 procedure Initialize
is
349 (Cname
=> new S
'("BIND"),
350 Usage => new S'("GNAT BIND file[.ali] /qualifiers"),
352 Unixcmd
=> new S
'("gnatbind"),
354 Switches => Bind_Switches'Access,
355 Params => new Parameter_Array'(1 => Unlimited_Files
),
359 (Cname
=> new S
'("CHOP"),
360 Usage => new S'("GNAT CHOP file [directory] /qualifiers"),
362 Unixcmd
=> new S
'("gnatchop"),
364 Switches => Chop_Switches'Access,
365 Params => new Parameter_Array'(1 => File
, 2 => Optional_File
),
369 (Cname
=> new S
'("CLEAN"),
370 Usage => new S'("GNAT CLEAN /qualifiers files"),
372 Unixcmd
=> new S
'("gnatclean"),
374 Switches => Clean_Switches'Access,
375 Params => new Parameter_Array'(1 => File
),
379 (Cname
=> new S
'("COMPILE"),
380 Usage => new S'("GNAT COMPILE filespec[,...] /qualifiers"),
382 Unixcmd
=> new S
'("gnatmake"),
383 Unixsws => new Argument_List'(1 => new String'("-f"),
384 2 => new String'("-u"),
385 3 => new String'("-c")),
386 Switches => GCC_Switches'Access,
387 Params => new Parameter_Array'(1 => Files_Or_Wildcard
),
391 (Cname
=> new S
'("CHECK"),
392 Usage => new S'("GNAT CHECK name /qualifiers"),
394 Unixcmd
=> new S
'("gnatcheck"),
396 Switches => Check_Switches'Access,
397 Params => new Parameter_Array'(1 => Unlimited_Files
),
401 (Cname
=> new S
'("SYNC"),
402 Usage => new S'("GNAT SYNC name /qualifiers"),
404 Unixcmd
=> new S
'("gnatsync"),
406 Switches => Sync_Switches'Access,
407 Params => new Parameter_Array'(1 => Unlimited_Files
),
411 (Cname
=> new S
'("ELIM"),
412 Usage => new S'("GNAT ELIM name /qualifiers"),
414 Unixcmd
=> new S
'("gnatelim"),
416 Switches => Elim_Switches'Access,
417 Params => new Parameter_Array'(1 => Other_As_Is
),
421 (Cname
=> new S
'("FIND"),
422 Usage => new S'("GNAT FIND pattern[:sourcefile[:line"
423 & "[:column]]] filespec[,...] /qualifiers"),
425 Unixcmd
=> new S
'("gnatfind"),
427 Switches => Find_Switches'Access,
428 Params => new Parameter_Array'(1 => Other_As_Is
,
429 2 => Files_Or_Wildcard
),
433 (Cname
=> new S
'("KRUNCH"),
434 Usage => new S'("GNAT KRUNCH file [/COUNT=nnn]"),
436 Unixcmd
=> new S
'("gnatkr"),
438 Switches => Krunch_Switches'Access,
439 Params => new Parameter_Array'(1 => File
),
443 (Cname
=> new S
'("LINK"),
444 Usage => new S'("GNAT LINK file[.ali]"
445 & " [extra obj_&_lib_&_exe_&_opt files]"
448 Unixcmd
=> new S
'("gnatlink"),
450 Switches => Link_Switches'Access,
451 Params => new Parameter_Array'(1 => Unlimited_Files
),
455 (Cname
=> new S
'("LIST"),
456 Usage => new S'("GNAT LIST /qualifiers object_or_ali_file"),
458 Unixcmd
=> new S
'("gnatls"),
460 Switches => List_Switches'Access,
461 Params => new Parameter_Array'(1 => Unlimited_Files
),
465 (Cname
=> new S
'("MAKE"),
466 Usage => new S'("GNAT MAKE file(s) /qualifiers (includes "
467 & "COMPILE /qualifiers)"),
469 Unixcmd
=> new S
'("gnatmake"),
471 Switches => Make_Switches'Access,
472 Params => new Parameter_Array'(1 => Unlimited_Files
),
476 (Cname
=> new S
'("METRIC"),
477 Usage => new S'("GNAT METRIC /qualifiers source_file"),
479 Unixcmd
=> new S
'("gnatmetric"),
481 Switches => Metric_Switches'Access,
482 Params => new Parameter_Array'(1 => Unlimited_Files
),
486 (Cname
=> new S
'("NAME"),
487 Usage => new S'("GNAT NAME /qualifiers naming-pattern "
488 & "[naming-patterns]"),
490 Unixcmd
=> new S
'("gnatname"),
492 Switches => Name_Switches'Access,
493 Params => new Parameter_Array'(1 => Unlimited_As_Is
),
497 (Cname
=> new S
'("PREPROCESS"),
499 new S'("GNAT PREPROCESS ifile ofile dfile /qualifiers"),
501 Unixcmd
=> new S
'("gnatprep"),
503 Switches => Prep_Switches'Access,
504 Params => new Parameter_Array'(1 .. 3 => File
),
508 (Cname
=> new S
'("PRETTY"),
509 Usage => new S'("GNAT PRETTY /qualifiers source_file"),
511 Unixcmd
=> new S
'("gnatpp"),
513 Switches => Pretty_Switches'Access,
514 Params => new Parameter_Array'(1 => Unlimited_Files
),
518 (Cname
=> new S
'("SHARED"),
519 Usage => new S'("GNAT SHARED [obj_&_lib_&_exe_&_opt"
520 & "files] /qualifiers"),
522 Unixcmd
=> new S
'("gcc"),
524 new Argument_List'(new String'("-shared") & Init_Object_Dirs),
525 Switches => Shared_Switches'Access,
526 Params => new Parameter_Array'(1 => Unlimited_Files
),
530 (Cname
=> new S
'("STACK"),
531 Usage => new S'("GNAT STACK /qualifiers ci_files"),
533 Unixcmd
=> new S
'("gnatstack"),
535 Switches => Stack_Switches'Access,
536 Params => new Parameter_Array'(1 => Unlimited_Files
),
537 Defext
=> "ci" & ASCII
.NUL
),
540 (Cname
=> new S
'("STUB"),
541 Usage => new S'("GNAT STUB file [directory]/qualifiers"),
543 Unixcmd
=> new S
'("gnatstub"),
545 Switches => Stub_Switches'Access,
546 Params => new Parameter_Array'(1 => File
, 2 => Optional_File
),
550 (Cname
=> new S
'("XREF"),
551 Usage => new S'("GNAT XREF filespec[,...] /qualifiers"),
553 Unixcmd
=> new S
'("gnatxref"),
555 Switches => Xref_Switches'Access,
556 Params => new Parameter_Array'(1 => Files_Or_Wildcard
),
565 function Invert_Sense
(S
: String) return VMS_Data
.String_Ptr
is
566 Sinv
: String (1 .. S
'Length * 2);
567 -- Result (for sure long enough)
569 Sinvp
: Natural := 0;
570 -- Pointer to output string
573 for Sp
in S
'Range loop
574 if Sp
= S
'First or else S
(Sp
- 1) = ',' then
578 Sinv
(Sinvp
+ 1) := '!';
579 Sinv
(Sinvp
+ 2) := S
(Sp
);
584 Sinv
(Sinvp
+ 1) := S
(Sp
);
589 return new String'(Sinv (1 .. Sinvp));
592 ----------------------
593 -- Is_Extensionless --
594 ----------------------
596 function Is_Extensionless (F : String) return Boolean is
598 for J in reverse F'Range loop
601 elsif F (J) = '/' or else F (J) = ']' or else F (J) = ':' then
607 end Is_Extensionless;
613 function Match (S1, S2 : String) return Boolean is
614 Dif : constant Integer := S2'First - S1'First;
618 if S1'Length /= S2'Length then
622 for J in S1'Range loop
623 if To_Lower (S1 (J)) /= To_Lower (S2 (J + Dif)) then
636 function Match_Prefix (S1, S2 : String) return Boolean is
638 if S1'Length > S2'Length then
641 return Match (S1, S2 (S2'First .. S2'First + S1'Length - 1));
649 function Matching_Name
652 Quiet : Boolean := False) return Item_Ptr
657 -- Little procedure to output command/qualifier/option as appropriate
658 -- and bump error count.
670 Errors := Errors + 1;
675 Put (Standard_Error, "command");
678 if Hostparm.OpenVMS then
679 Put (Standard_Error, "qualifier");
681 Put (Standard_Error, "switch");
685 Put (Standard_Error, "option");
689 Put (Standard_Error, "input");
693 Put (Standard_Error, ": ");
694 Put (Standard_Error, S);
697 -- Start of processing for Matching_Name
700 -- If exact match, that's the one we want
703 while P1 /= null loop
704 if Match (S, P1.Name.all) then
711 -- Now check for prefix matches
714 while P1 /= null loop
715 if P1.Name.all = "/<other>" then
718 elsif not Match_Prefix (S, P1.Name.all) then
722 -- Here we have found one matching prefix, so see if there is
723 -- another one (which is an ambiguity)
726 while P2 /= null loop
727 if Match_Prefix (S, P2.Name.all) then
729 Put (Standard_Error, "ambiguous ");
731 Put (Standard_Error, " (matches ");
732 Put (Standard_Error, P1.Name.all);
734 while P2 /= null loop
735 if Match_Prefix (S, P2.Name.all) then
736 Put (Standard_Error, ',');
737 Put (Standard_Error, P2.Name.all);
743 Put_Line (Standard_Error, ")");
752 -- If we fall through that loop, then there was only one match
758 -- If we fall through outer loop, there was no match
761 Put (Standard_Error, "unrecognized ");
763 New_Line (Standard_Error);
769 -----------------------
770 -- OK_Alphanumerplus --
771 -----------------------
773 function OK_Alphanumerplus (S : String) return Boolean is
779 for J in S'Range loop
780 if not (Is_Alphanumeric (S (J)) or else
781 S (J) = '_
' or else S (J) = '$
')
789 end OK_Alphanumerplus;
795 function OK_Integer (S : String) return Boolean is
801 for J in S'Range loop
802 if not Is_Digit (S (J)) then
815 procedure Output_Version is
817 if AAMP_On_Target then
823 Put_Line (Gnatvsn.Gnat_Version_String);
824 Put_Line ("Copyright 1996-" &
826 ", Free Software Foundation, Inc.");
833 procedure Place (C : Character) is
836 Cargs_Buffer.Append (C);
842 procedure Place (S : String) is
844 for J in S'Range loop
853 procedure Place_Lower (S : String) is
855 for J in S'Range loop
856 Place (To_Lower (S (J)));
860 -------------------------
861 -- Place_Unix_Switches --
862 -------------------------
864 procedure Place_Unix_Switches (S : VMS_Data.String_Ptr) is
865 P1, P2, P3 : Natural;
867 Slen, Sln2 : Natural;
868 Wild_Card : Boolean := False;
872 while P1 <= S'Last loop
881 pragma Assert (S (P1) = '-' or else S (P1) = '`
');
883 while P2 < S'Last and then S (P2 + 1) /= ',' loop
887 -- Switch is now in S (P1 .. P2)
892 Wild_Card := S (P2) = '*';
900 while P3 <= Buffer.Last - Slen loop
901 if Buffer.Table (P3) = ' '
902 and then String (Buffer.Table (P3 + 1 .. P3 + Slen)) =
906 P3 + Slen = Buffer.Last
908 Buffer.Table (P3 + Slen + 1) = ' ')
913 while P3 + Sln2 /= Buffer.Last
914 and then Buffer.Table (P3 + Sln2 + 1) /= ' '
920 Buffer.Table (P3 .. Buffer.Last - Sln2 - 1) :=
921 Buffer.Table (P3 + Sln2 + 1 .. Buffer.Last);
922 Buffer.Set_Last (Buffer.Last - Sln2 - 1);
934 pragma Assert (S (P2) /= '*');
941 Place (S (P1 .. P2));
946 end Place_Unix_Switches;
948 -----------------------------
949 -- Preprocess_Command_Data --
950 -----------------------------
952 procedure Preprocess_Command_Data is
954 for C in Real_Command_Type loop
956 Command : constant Item_Ptr := new Command_Item;
958 Last_Switch : Item_Ptr;
959 -- Last switch in list
962 -- Link new command item into list of commands
964 if Last_Command = null then
967 Last_Command.Next := Command;
970 Last_Command := Command;
972 -- Fill in fields of new command item
974 Command.Name := Command_List (C).Cname;
975 Command.Usage := Command_List (C).Usage;
976 Command.Command := C;
978 if Command_List (C).Unixsws = null then
979 Command.Unix_String := Command_List (C).Unixcmd;
982 Cmd : String (1 .. 5_000);
984 Sws : constant Argument_List_Access :=
985 Command_List (C).Unixsws;
988 Cmd (1 .. Command_List (C).Unixcmd'Length) :=
989 Command_List (C).Unixcmd.all;
990 Last := Command_List (C).Unixcmd'Length;
992 for J in Sws'Range loop
995 Cmd (Last + 1 .. Last + Sws (J)'Length) :=
997 Last := Last + Sws (J)'Length;
1000 Command.Unix_String := new String'(Cmd
(1 .. Last
));
1004 Command
.Params
:= Command_List
(C
).Params
;
1005 Command
.Defext
:= Command_List
(C
).Defext
;
1007 Validate_Command_Or_Option
(Command
.Name
);
1009 -- Process the switch list
1011 for S
in Command_List
(C
).Switches
'Range loop
1013 SS
: constant VMS_Data
.String_Ptr
:=
1014 Command_List
(C
).Switches
(S
);
1015 P
: Natural := SS
'First;
1016 Sw
: Item_Ptr
:= new Switch_Item
;
1018 Last_Opt
: Item_Ptr
;
1019 -- Pointer to last option
1022 -- Link new switch item into list of switches
1024 if Last_Switch
= null then
1025 Command
.Switches
:= Sw
;
1027 Last_Switch
.Next
:= Sw
;
1032 -- Process switch string, first get name
1034 while SS
(P
) /= ' ' and then SS
(P
) /= '=' loop
1038 Sw
.Name
:= new String'(SS (SS'First .. P - 1));
1040 -- Direct translation case
1042 if SS (P) = ' ' then
1043 Sw.Translation := T_Direct;
1044 Sw.Unix_String := new String'(SS
(P
+ 1 .. SS
'Last));
1045 Validate_Unix_Switch
(Sw
.Unix_String
);
1047 if SS
(P
- 1) = '>' then
1048 Sw
.Translation
:= T_Other
;
1050 elsif SS
(P
+ 1) = '`' then
1053 -- Create the inverted case (/NO ..)
1055 elsif SS
(SS
'First + 1 .. SS
'First + 2) /= "NO" then
1056 Sw
:= new Switch_Item
;
1057 Last_Switch
.Next
:= Sw
;
1061 new String'("/NO" & SS (SS'First + 1 .. P - 1));
1062 Sw.Translation := T_Direct;
1063 Sw.Unix_String := Invert_Sense (SS (P + 1 .. SS'Last));
1064 Validate_Unix_Switch (Sw.Unix_String);
1067 -- Directories translation case
1069 elsif SS (P + 1) = '*' then
1070 pragma Assert (SS (SS'Last) = '*');
1071 Sw.Translation := T_Directories;
1072 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
1073 Validate_Unix_Switch
(Sw
.Unix_String
);
1075 -- Directory translation case
1077 elsif SS
(P
+ 1) = '%' then
1078 pragma Assert
(SS
(SS
'Last) = '%');
1079 Sw
.Translation
:= T_Directory
;
1080 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
1081 Validate_Unix_Switch (Sw.Unix_String);
1083 -- File translation case
1085 elsif SS (P + 1) = '@
' then
1086 pragma Assert (SS (SS'Last) = '@
');
1087 Sw.Translation := T_File;
1088 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
1089 Validate_Unix_Switch
(Sw
.Unix_String
);
1091 -- No space file translation case
1093 elsif SS
(P
+ 1) = '<' then
1094 pragma Assert
(SS
(SS
'Last) = '>');
1095 Sw
.Translation
:= T_No_Space_File
;
1096 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
1097 Validate_Unix_Switch (Sw.Unix_String);
1099 -- Numeric translation case
1101 elsif SS (P + 1) = '#
' then
1102 pragma Assert (SS (SS'Last) = '#
');
1103 Sw.Translation := T_Numeric;
1104 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
1105 Validate_Unix_Switch
(Sw
.Unix_String
);
1107 -- Alphanumerplus translation case
1109 elsif SS
(P
+ 1) = '|' then
1110 pragma Assert
(SS
(SS
'Last) = '|');
1111 Sw
.Translation
:= T_Alphanumplus
;
1112 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
1113 Validate_Unix_Switch (Sw.Unix_String);
1115 -- String translation case
1117 elsif SS (P + 1) = '"' then
1118 pragma Assert (SS (SS'Last) = '"');
1119 Sw.Translation := T_String;
1120 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
1121 Validate_Unix_Switch
(Sw
.Unix_String
);
1123 -- Commands translation case
1125 elsif SS
(P
+ 1) = '?' then
1126 Sw
.Translation
:= T_Commands
;
1127 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last));
1129 -- Options translation case
1132 Sw.Translation := T_Options;
1133 Sw.Unix_String := new String'("");
1135 P
:= P
+ 1; -- bump past =
1136 while P
<= SS
'Last loop
1138 Opt
: constant Item_Ptr
:= new Option_Item
;
1142 -- Link new option item into options list
1144 if Last_Opt
= null then
1147 Last_Opt
.Next
:= Opt
;
1152 -- Fill in fields of new option item
1155 while SS
(Q
) /= ' ' loop
1159 Opt
.Name
:= new String'(SS (P .. Q - 1));
1160 Validate_Command_Or_Option (Opt.Name);
1165 while Q <= SS'Last and then SS (Q) /= ' ' loop
1169 Opt.Unix_String := new String'(SS
(P
.. Q
- 1));
1170 Validate_Unix_Switch
(Opt
.Unix_String
);
1179 end Preprocess_Command_Data
;
1181 ----------------------
1182 -- Process_Argument --
1183 ----------------------
1185 procedure Process_Argument
(The_Command
: in out Command_Type
) is
1186 Argv
: String_Access
;
1189 function Get_Arg_End
1191 Arg_Idx
: Integer) return Integer;
1192 -- Begins looking at Arg_Idx + 1 and returns the index of the
1193 -- last character before a slash or else the index of the last
1194 -- character in the string Argv.
1200 function Get_Arg_End
1202 Arg_Idx
: Integer) return Integer
1205 for J
in Arg_Idx
+ 1 .. Argv
'Last loop
1206 if Argv
(J
) = '/' then
1214 -- Start of processing for Process_Argument
1219 -- If an argument file is open, read the next non empty line
1221 if Is_Open
(Arg_File
) then
1223 Line
: String (1 .. 256);
1227 Get_Line
(Arg_File
, Line
, Last
);
1228 exit when Last
/= 0 or else End_Of_File
(Arg_File
);
1231 -- If the end of the argument file has been reached, close it
1233 if End_Of_File
(Arg_File
) then
1236 -- If the last line was empty, return after increasing Arg_Num
1237 -- to go to the next argument on the comment line.
1240 Arg_Num
:= Arg_Num
+ 1;
1245 Argv
:= new String'(Line (1 .. Last));
1248 if Argv (1) = '@
' then
1249 Put_Line (Standard_Error, "argument file cannot contain @cmd");
1255 -- No argument file is open, get the argument on the command line
1257 Argv := new String'(Argument
(Arg_Num
));
1258 Arg_Idx
:= Argv
'First;
1260 -- Check if this is the specification of an argument file
1262 if Argv
(Arg_Idx
) = '@' then
1263 -- The first argument on the command line cannot be an argument
1269 "Cannot specify argument line before command");
1273 -- Open the file, after conversion of the name to canonical form.
1274 -- Fail if file is not found.
1277 Canonical_File_Name
: String_Access
:=
1278 To_Canonical_File_Spec
(Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1280 Open
(Arg_File
, In_File
, Canonical_File_Name
.all);
1281 Free
(Canonical_File_Name
);
1286 Put
(Standard_Error
, "Cannot open argument file """);
1287 Put
(Standard_Error
, Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1288 Put_Line
(Standard_Error
, """");
1294 <<Tryagain_After_Coalesce
>>
1297 Next_Arg_Idx
: Integer;
1298 Arg
: String_Access
;
1301 Next_Arg_Idx
:= Get_Arg_End
(Argv
.all, Arg_Idx
);
1302 Arg
:= new String'(Argv (Arg_Idx .. Next_Arg_Idx));
1304 -- The first one must be a command name
1306 if Arg_Num = 1 and then Arg_Idx = Argv'First then
1307 Command := Matching_Name (Arg.all, Commands);
1309 if Command = null then
1313 The_Command := Command.Command;
1314 Output_File_Expected := False;
1316 -- Give usage information if only command given
1318 if Argument_Count = 1
1319 and then Next_Arg_Idx = Argv'Last
1324 ("List of available qualifiers and options");
1327 Put (Command.Usage.all);
1329 Put_Line (Command.Unix_String.all);
1332 Sw : Item_Ptr := Command.Switches;
1335 while Sw /= null loop
1339 case Sw.Translation is
1343 Put_Line (Sw.Unix_String.all &
1348 Put_Line (Sw.Unix_String.all);
1350 when T_Directories =>
1351 Put ("=(direc,direc,..direc)");
1353 Put (Sw.Unix_String.all);
1355 Put (Sw.Unix_String.all);
1356 Put_Line (" direc ...");
1361 Put (Sw.Unix_String.all);
1363 if Sw.Unix_String (Sw.Unix_String'Last)
1369 Put_Line ("directory ");
1371 when T_File | T_No_Space_File =>
1374 Put (Sw.Unix_String.all);
1376 if Sw.Translation = T_File
1377 and then Sw.Unix_String
1378 (Sw.Unix_String'Last) /= '='
1390 (Sw.Unix_String'First) = '`
'
1393 (Sw.Unix_String'First + 1
1394 .. Sw.Unix_String'Last));
1396 Put (Sw.Unix_String.all);
1401 when T_Alphanumplus =>
1406 (Sw.Unix_String'First) = '`
'
1409 (Sw.Unix_String'First + 1
1410 .. Sw.Unix_String'Last));
1412 Put (Sw.Unix_String.all);
1424 Put (Sw.Unix_String.all);
1427 (Sw.Unix_String'Last) /= '='
1436 Put (" (switches for ");
1438 (Sw.Unix_String'First + 7
1439 .. Sw.Unix_String'Last));
1443 (Sw.Unix_String'First
1444 .. Sw.Unix_String'First + 5));
1445 Put_Line (" switches");
1449 Opt : Item_Ptr := Sw.Options;
1452 Put_Line ("=(option,option..)");
1454 while Opt /= null loop
1458 if Opt = Sw.Options then
1463 Put_Line (Opt.Unix_String.all);
1477 -- Special handling for internal debugging switch /?
1479 elsif Arg.all = "/?" then
1480 Display_Command := True;
1481 Output_File_Expected := False;
1483 -- Special handling of internal option /KEEP_TEMPORARY_FILES
1485 elsif Arg'Length >= 7
1486 and then Matching_Name
1487 (Arg.all, Keep_Temps_Option, True) /= null
1489 Opt.Keep_Temporary_Files := True;
1491 -- Copy -switch unchanged, as well as +rule
1493 elsif Arg (Arg'First) = '-' or else Arg (Arg'First) = '+' then
1497 -- Set Output_File_Expected for the next argument
1499 Output_File_Expected :=
1500 Arg.all = "-o" and then The_Command = Link;
1502 -- Copy quoted switch with quotes stripped
1504 elsif Arg (Arg'First) = '"' then
1505 if Arg (Arg'Last) /= '"' then
1506 Put (Standard_Error, "misquoted argument: ");
1507 Put_Line (Standard_Error, Arg.all);
1508 Errors := Errors + 1;
1512 Place (Arg (Arg'First + 1 .. Arg'Last - 1));
1515 Output_File_Expected := False;
1517 -- Parameter Argument
1519 elsif Arg (Arg'First) /= '/'
1520 and then Make_Commands_Active = null
1522 Param_Count := Param_Count + 1;
1524 if Param_Count <= Command.Params'Length then
1526 case Command.Params (Param_Count) is
1528 when File | Optional_File =>
1530 Normal_File : constant String_Access :=
1531 To_Canonical_File_Spec
1536 Place_Lower (Normal_File.all);
1538 if Is_Extensionless (Normal_File.all)
1539 and then Command.Defext /= " "
1542 Place (Command.Defext);
1546 when Unlimited_Files =>
1548 Normal_File : constant String_Access :=
1549 To_Canonical_File_Spec
1552 File_Is_Wild : Boolean := False;
1553 File_List : String_Access_List_Access;
1556 for J in Arg'Range loop
1558 or else Arg (J) = '%'
1560 File_Is_Wild := True;
1564 if File_Is_Wild then
1565 File_List := To_Canonical_File_List
1568 for J in File_List.all'Range loop
1570 Place_Lower (File_List.all (J).all);
1575 Place_Lower (Normal_File.all);
1577 -- Add extension if not present, except after
1580 if Is_Extensionless (Normal_File.all)
1581 and then Command.Defext /= " "
1582 and then not Output_File_Expected
1585 Place (Command.Defext);
1589 Param_Count := Param_Count - 1;
1596 when Unlimited_As_Is =>
1599 Param_Count := Param_Count - 1;
1601 when Files_Or_Wildcard =>
1603 -- Remove spaces from a comma separated list
1604 -- of file names and adjust control variables
1607 while Arg_Num < Argument_Count and then
1608 (Argv (Argv'Last) = ',' xor
1609 Argument (Arg_Num + 1)
1610 (Argument (Arg_Num + 1)'First) = ',')
1613 (Argv
.all & Argument
(Arg_Num
+ 1));
1614 Arg_Num
:= Arg_Num
+ 1;
1615 Arg_Idx
:= Argv
'First;
1617 Get_Arg_End
(Argv
.all, Arg_Idx
);
1619 (Argv (Arg_Idx .. Next_Arg_Idx));
1622 -- Parse the comma separated list of VMS
1623 -- filenames and place them on the command
1624 -- line as space separated Unix style
1625 -- filenames. Lower case and add default
1626 -- extension as appropriate.
1629 Arg1_Idx : Integer := Arg'First;
1631 function Get_Arg1_End
1633 Arg_Idx : Integer) return Integer;
1634 -- Begins looking at Arg_Idx + 1 and
1635 -- returns the index of the last character
1636 -- before a comma or else the index of the
1637 -- last character in the string Arg.
1643 function Get_Arg1_End
1645 Arg_Idx : Integer) return Integer
1648 for J in Arg_Idx + 1 .. Arg'Last loop
1649 if Arg (J) = ',' then
1662 Get_Arg1_End (Arg.all, Arg1_Idx);
1666 Arg (Arg1_Idx .. Next_Arg1_Idx);
1669 constant String_Access :=
1670 To_Canonical_File_Spec (Arg1);
1674 Place_Lower (Normal_File.all);
1676 if Is_Extensionless (Normal_File.all)
1677 and then Command.Defext /= " "
1680 Place (Command.Defext);
1683 Arg1_Idx := Next_Arg1_Idx + 1;
1686 exit when Arg1_Idx > Arg'Last;
1688 -- Don't allow two or more commas in
1691 if Arg (Arg1_Idx) = ',' then
1692 Arg1_Idx := Arg1_Idx + 1;
1693 if Arg1_Idx > Arg'Last or else
1694 Arg (Arg1_Idx) = ','
1698 "Malformed Parameter: " &
1700 Put (Standard_Error, "usage: ");
1701 Put_Line (Standard_Error,
1712 -- Reset Output_File_Expected, in case it was True
1714 Output_File_Expected := False;
1716 -- Qualifier argument
1719 Output_File_Expected := False;
1721 Cargs := Command.Name.all = "COMPILE";
1723 -- This code is too heavily nested, should be
1724 -- separated out as separate subprogram ???
1730 Endp : Natural := 0; -- avoid warning!
1735 while SwP < Arg'Last
1736 and then Arg (SwP + 1) /= '='
1741 -- At this point, the switch name is in
1742 -- Arg (Arg'First..SwP) and if that is not the
1743 -- whole switch, then there is an equal sign at
1744 -- Arg (SwP + 1) and the rest of Arg is what comes
1745 -- after the equal sign.
1747 -- If make commands are active, see if we have
1748 -- another COMMANDS_TRANSLATION switch belonging
1751 if Make_Commands_Active /= null then
1754 (Arg (Arg'First .. SwP),
1759 and then Sw.Translation = T_Commands
1766 (Arg (Arg'First .. SwP),
1767 Make_Commands_Active.Switches,
1771 -- For case of GNAT MAKE or CHOP, if we cannot
1772 -- find the switch, then see if it is a
1773 -- recognized compiler switch instead, and if
1774 -- so process the compiler switch.
1776 elsif Command.Name.all = "MAKE"
1777 or else Command.Name.all = "CHOP" then
1780 (Arg (Arg'First .. SwP),
1787 (Arg (Arg'First .. SwP),
1789 ("COMPILE", Commands).Switches,
1793 -- For all other cases, just search the relevant
1799 (Arg (Arg'First .. SwP),
1806 and then Sw.Name /= null
1808 (Sw.Name.all = "/PROJECT_FILE" or else
1809 Sw.Name.all = "/MESSAGES_PROJECT_FILE" or else
1810 Sw.Name.all = "/EXTERNAL_REFERENCE")
1815 case Sw.Translation is
1817 Place_Unix_Switches (Sw.Unix_String);
1819 and then Arg (SwP + 1) = '='
1821 Put (Standard_Error,
1822 "qualifier options ignored: ");
1823 Put_Line (Standard_Error, Arg.all);
1826 when T_Directories =>
1827 if SwP + 1 > Arg'Last then
1828 Put (Standard_Error,
1829 "missing directories for: ");
1830 Put_Line (Standard_Error, Arg.all);
1831 Errors := Errors + 1;
1833 elsif Arg (SwP + 2) /= '(' then
1837 elsif Arg (Arg'Last) /= ')' then
1839 -- Remove spaces from a comma separated
1840 -- list of file names and adjust
1841 -- control variables accordingly.
1843 if Arg_Num < Argument_Count and then
1844 (Argv (Argv'Last) = ',' xor
1845 Argument (Arg_Num + 1)
1846 (Argument (Arg_Num + 1)'First) = ',')
1849 new String'(Argv
.all
1852 Arg_Num
:= Arg_Num
+ 1;
1853 Arg_Idx
:= Argv
'First;
1855 Get_Arg_End
(Argv
.all, Arg_Idx
);
1857 (Argv (Arg_Idx .. Next_Arg_Idx));
1858 goto Tryagain_After_Coalesce;
1861 Put (Standard_Error,
1862 "incorrectly parenthesized " &
1863 "or malformed argument: ");
1864 Put_Line (Standard_Error, Arg.all);
1865 Errors := Errors + 1;
1869 Endp := Arg'Last - 1;
1872 while SwP <= Endp loop
1874 Dir_Is_Wild : Boolean := False;
1875 Dir_Maybe_Is_Wild : Boolean := False;
1877 Dir_List : String_Access_List_Access;
1883 and then Arg (P2 + 1) /= ','
1885 -- A wildcard directory spec on
1886 -- VMS will contain either * or
1889 if Arg (P2) = '*' then
1890 Dir_Is_Wild := True;
1892 elsif Arg (P2) = '%' then
1893 Dir_Is_Wild := True;
1895 elsif Dir_Maybe_Is_Wild
1896 and then Arg (P2) = '.'
1897 and then Arg (P2 + 1) = '.'
1899 Dir_Is_Wild := True;
1900 Dir_Maybe_Is_Wild := False;
1902 elsif Dir_Maybe_Is_Wild then
1903 Dir_Maybe_Is_Wild := False;
1905 elsif Arg (P2) = '.'
1906 and then Arg (P2 + 1) = '.'
1908 Dir_Maybe_Is_Wild := True;
1917 To_Canonical_File_List
1918 (Arg (SwP .. P2), True);
1920 for J in Dir_List.all'Range loop
1924 (Dir_List.all (J).all);
1931 (To_Canonical_Dir_Spec
1932 (Arg (SwP .. P2), False).all);
1940 if SwP + 1 > Arg'Last then
1941 Put (Standard_Error,
1942 "missing directory for: ");
1943 Put_Line (Standard_Error, Arg.all);
1944 Errors := Errors + 1;
1947 Place_Unix_Switches (Sw.Unix_String);
1949 -- Some switches end in "=". No space
1953 (Sw.Unix_String'Last) /= '='
1959 (To_Canonical_Dir_Spec
1960 (Arg (SwP + 2 .. Arg'Last),
1964 when T_File | T_No_Space_File =>
1965 if SwP + 1 > Arg'Last then
1966 Put (Standard_Error,
1967 "missing file for: ");
1968 Put_Line (Standard_Error, Arg.all);
1969 Errors := Errors + 1;
1972 Place_Unix_Switches (Sw.Unix_String);
1974 -- Some switches end in "=". No space
1977 if Sw.Translation = T_File
1978 and then Sw.Unix_String
1979 (Sw.Unix_String'Last) /= '='
1985 (To_Canonical_File_Spec
1986 (Arg (SwP + 2 .. Arg'Last)).all);
1990 if OK_Integer (Arg (SwP + 2 .. Arg'Last)) then
1991 Place_Unix_Switches (Sw.Unix_String);
1992 Place (Arg (SwP + 2 .. Arg'Last));
1995 Put (Standard_Error, "argument for ");
1996 Put (Standard_Error, Sw.Name.all);
1998 (Standard_Error, " must be numeric");
1999 Errors := Errors + 1;
2002 when T_Alphanumplus =>
2003 if OK_Alphanumerplus
2004 (Arg (SwP + 2 .. Arg'Last))
2006 Place_Unix_Switches (Sw.Unix_String);
2007 Place (Arg (SwP + 2 .. Arg'Last));
2010 Put (Standard_Error, "argument for ");
2011 Put (Standard_Error, Sw.Name.all);
2012 Put_Line (Standard_Error,
2013 " must be alphanumeric");
2014 Errors := Errors + 1;
2019 -- A String value must be extended to the
2020 -- end of the Argv, otherwise strings like
2021 -- "foo/bar" get split at the slash.
2023 -- The beginning and ending of the string
2024 -- are flagged with embedded nulls which
2025 -- are removed when building the Spawn
2026 -- call. Nulls are use because they won't
2027 -- show up in a /? output. Quotes aren't
2028 -- used because that would make it
2029 -- difficult to embed them.
2031 Place_Unix_Switches (Sw.Unix_String);
2033 if Next_Arg_Idx /= Argv'Last then
2034 Next_Arg_Idx := Argv'Last;
2036 (Argv
(Arg_Idx
.. Next_Arg_Idx
));
2039 while SwP
< Arg
'Last and then
2040 Arg
(SwP
+ 1) /= '=' loop
2046 Place
(Arg
(SwP
+ 2 .. Arg
'Last));
2051 -- Output -largs/-bargs/-cargs
2054 Place
(Sw
.Unix_String
2055 (Sw
.Unix_String
'First ..
2056 Sw
.Unix_String
'First + 5));
2059 (Sw
.Unix_String
'First + 7 ..
2060 Sw
.Unix_String
'Last) = "MAKE"
2062 Make_Commands_Active
:= null;
2065 -- Set source of new commands, also
2066 -- setting this non-null indicates that
2067 -- we are in the special commands mode
2068 -- for processing the -xargs case.
2070 Make_Commands_Active
:=
2073 (Sw
.Unix_String
'First + 7 ..
2074 Sw
.Unix_String
'Last),
2079 if SwP
+ 1 > Arg
'Last then
2081 (Sw
.Options
.Unix_String
);
2084 elsif Arg
(SwP
+ 2) /= '(' then
2088 elsif Arg
(Arg
'Last) /= ')' then
2089 Put
(Standard_Error
,
2090 "incorrectly parenthesized argument: ");
2091 Put_Line
(Standard_Error
, Arg
.all);
2092 Errors
:= Errors
+ 1;
2097 Endp
:= Arg
'Last - 1;
2100 while SwP
<= Endp
loop
2104 and then Arg
(P2
+ 1) /= ','
2109 -- Option name is in Arg (SwP .. P2)
2111 Opt
:= Matching_Name
(Arg
(SwP
.. P2
),
2124 (new String'(Sw.Unix_String.all &
2132 Arg_Idx := Next_Arg_Idx + 1;
2135 exit when Arg_Idx > Argv'Last;
2139 if not Is_Open (Arg_File) then
2140 Arg_Num := Arg_Num + 1;
2142 end Process_Argument;
2144 --------------------
2145 -- Process_Buffer --
2146 --------------------
2148 procedure Process_Buffer (S : String) is
2150 Inside_Nul : Boolean := False;
2151 Arg : String (1 .. 1024);
2156 while P1 <= S'Last and then S (P1) = ' ' loop
2161 Arg (Arg_Ctr) := S (P1);
2163 while P1 <= S'Last loop
2164 if S (P1) = ASCII.NUL then
2166 Inside_Nul := False;
2172 if S (P1) = ' ' and then not Inside_Nul then
2174 Arg_Ctr := Arg_Ctr + 1;
2175 Arg (Arg_Ctr) := S (P1);
2178 Last_Switches.Increment_Last;
2182 and then (S (P2 + 1) /= ' ' or else
2186 Arg_Ctr := Arg_Ctr + 1;
2187 Arg (Arg_Ctr) := S (P2);
2188 if S (P2) = ASCII.NUL then
2189 Arg_Ctr := Arg_Ctr - 1;
2192 Inside_Nul := False;
2199 Last_Switches.Table (Last_Switches.Last) :=
2200 new String'(String (Arg
(1 .. Arg_Ctr
)));
2203 exit when P1
> S
'Last;
2206 Arg
(Arg_Ctr
) := S
(P1
);
2211 --------------------------------
2212 -- Validate_Command_Or_Option --
2213 --------------------------------
2215 procedure Validate_Command_Or_Option
(N
: VMS_Data
.String_Ptr
) is
2217 pragma Assert
(N
'Length > 0);
2219 for J
in N
'Range loop
2221 pragma Assert
(N
(J
- 1) /= '_');
2224 pragma Assert
(Is_Upper
(N
(J
)) or else Is_Digit
(N
(J
)));
2228 end Validate_Command_Or_Option
;
2230 --------------------------
2231 -- Validate_Unix_Switch --
2232 --------------------------
2234 procedure Validate_Unix_Switch
(S
: VMS_Data
.String_Ptr
) is
2236 if S
(S
'First) = '`' then
2240 pragma Assert
(S
(S
'First) = '-' or else S
(S
'First) = '!');
2242 for J
in S
'First + 1 .. S
'Last loop
2243 pragma Assert
(S
(J
) /= ' ');
2246 pragma Assert
(S
(J
- 1) = ',' and then S
(J
+ 1) = '-');
2250 end Validate_Unix_Switch
;
2252 --------------------
2253 -- VMS_Conversion --
2254 --------------------
2256 procedure VMS_Conversion
(The_Command
: out Command_Type
) is
2257 Result
: Command_Type
:= Undefined
;
2258 Result_Set
: Boolean := False;
2263 -- First we must preprocess the string form of the command and options
2264 -- list into the internal form that we use.
2266 Preprocess_Command_Data
;
2268 -- If no parameters, give complete list of commands
2270 if Argument_Count
= 0 then
2273 Put_Line
("List of available commands");
2276 while Commands
/= null loop
2278 -- No usage for GNAT SYNC
2280 if Commands
.Command
/= Sync
then
2281 Put
(Commands
.Usage
.all);
2283 Put_Line
(Commands
.Unix_String
.all);
2286 Commands
:= Commands
.Next
;
2292 -- Loop through arguments
2295 while Arg_Num
<= Argument_Count
loop
2296 Process_Argument
(Result
);
2298 if not Result_Set
then
2299 The_Command
:= Result
;
2304 -- Gross error checking that the number of parameters is correct.
2305 -- Not applicable to Unlimited_Files parameters.
2307 if (Param_Count
= Command
.Params
'Length - 1
2308 and then Command
.Params
(Param_Count
+ 1) = Unlimited_Files
)
2309 or else Param_Count
<= Command
.Params
'Length
2314 Put_Line
(Standard_Error
,
2315 "Parameter count of "
2316 & Integer'Image (Param_Count
)
2317 & " not equal to expected "
2318 & Integer'Image (Command
.Params
'Length));
2319 Put
(Standard_Error
, "usage: ");
2320 Put_Line
(Standard_Error
, Command
.Usage
.all);
2321 Errors
:= Errors
+ 1;
2327 -- Prepare arguments for a call to spawn, filtering out
2328 -- embedded nulls place there to delineate strings.
2330 Process_Buffer
(String (Buffer
.Table
(1 .. Buffer
.Last
)));
2332 if Cargs_Buffer
.Last
> 1 then
2333 Last_Switches
.Append
(new String'("-cargs"));
2335 (String (Cargs_Buffer.Table (1 .. Cargs_Buffer.Last)));