1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Gnatvsn
; use Gnatvsn
;
30 with Osint
; use Osint
;
31 with Targparm
; use Targparm
;
33 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
34 with Ada
.Command_Line
; use Ada
.Command_Line
;
35 with Ada
.Text_IO
; use Ada
.Text_IO
;
37 package body VMS_Conv
is
39 Keep_Temps_Option
: constant Item_Ptr
:=
43 new String'("/KEEP_TEMPORARY_FILES"),
48 Param_Count
: Natural := 0;
49 -- Number of parameter arguments so far
54 Arg_File
: Ada
.Text_IO
.File_Type
;
55 -- A file where arguments are read from
58 -- Pointer to head of list of command items, one for each command, with
59 -- the end of the list marked by a null pointer.
61 Last_Command
: Item_Ptr
;
62 -- Pointer to last item in Commands list
65 -- Pointer to command item for current command
67 Make_Commands_Active
: Item_Ptr
:= null;
68 -- Set to point to Command entry for COMPILE, BIND, or LINK as appropriate
69 -- if a COMMANDS_TRANSLATION switch has been encountered while processing
72 Output_File_Expected
: Boolean := False;
73 -- True for GNAT LINK after -o switch, so that the ".ali" extension is
74 -- not added to the executable file name.
76 package Buffer
is new Table
.Table
77 (Table_Component_Type
=> Character,
78 Table_Index_Type
=> Integer,
80 Table_Initial
=> 4096,
81 Table_Increment
=> 100,
82 Table_Name
=> "Buffer");
84 function Init_Object_Dirs
return Argument_List
;
85 -- Get the list of the object directories
87 function Invert_Sense
(S
: String) return VMS_Data
.String_Ptr
;
88 -- Given a unix switch string S, computes the inverse (adding or
89 -- removing ! characters as required), and returns a pointer to
90 -- the allocated result on the heap.
92 function Is_Extensionless
(F
: String) return Boolean;
93 -- Returns true if the filename has no extension
95 function Match
(S1
, S2
: String) return Boolean;
96 -- Determines whether S1 and S2 match (this is a case insensitive match)
98 function Match_Prefix
(S1
, S2
: String) return Boolean;
99 -- Determines whether S1 matches a prefix of S2. This is also a case
100 -- insensitive match (for example Match ("AB","abc") is True).
102 function Matching_Name
105 Quiet
: Boolean := False) return Item_Ptr
;
106 -- Determines if the item list headed by Itm and threaded through the
107 -- Next fields (with null marking the end of the list), contains an
108 -- entry that uniquely matches the given string. The match is case
109 -- insensitive and permits unique abbreviation. If the match succeeds,
110 -- then a pointer to the matching item is returned. Otherwise, an
111 -- appropriate error message is written. Note that the discriminant
112 -- of Itm is used to determine the appropriate form of this message.
113 -- Quiet is normally False as shown, if it is set to True, then no
114 -- error message is generated in a not found situation (null is still
115 -- returned to indicate the not-found situation).
117 function OK_Alphanumerplus
(S
: String) return Boolean;
118 -- Checks that S is a string of alphanumeric characters,
119 -- returning True if all alphanumeric characters,
120 -- False if empty or a non-alphanumeric character is present.
122 function OK_Integer
(S
: String) return Boolean;
123 -- Checks that S is a string of digits, returning True if all digits,
124 -- False if empty or a non-digit is present.
126 procedure Place
(C
: Character);
127 -- Place a single character in the buffer, updating Ptr
129 procedure Place
(S
: String);
130 -- Place a string character in the buffer, updating Ptr
132 procedure Place_Lower
(S
: String);
133 -- Place string in buffer, forcing letters to lower case, updating Ptr
135 procedure Place_Unix_Switches
(S
: VMS_Data
.String_Ptr
);
136 -- Given a unix switch string, place corresponding switches in Buffer,
137 -- updating Ptr appropriatelly. Note that in the case of use of ! the
138 -- result may be to remove a previously placed switch.
140 procedure Preprocess_Command_Data
;
141 -- Preprocess the string form of the command and options list into the
144 procedure Process_Argument
(The_Command
: in out Command_Type
);
145 -- Process one argument from the command line, or one line from
146 -- from a command line file. For the first call, set The_Command.
148 procedure Validate_Command_Or_Option
(N
: VMS_Data
.String_Ptr
);
149 -- Check that N is a valid command or option name, i.e. that it is of the
150 -- form of an Ada identifier with upper case letters and underscores.
152 procedure Validate_Unix_Switch
(S
: VMS_Data
.String_Ptr
);
153 -- Check that S is a valid switch string as described in the syntax for
154 -- the switch table item UNIX_SWITCH or else begins with a backquote.
156 ----------------------
157 -- Init_Object_Dirs --
158 ----------------------
160 function Init_Object_Dirs
return Argument_List
is
161 Object_Dirs
: Integer;
162 Object_Dir
: Argument_List
(1 .. 256);
163 Object_Dir_Name
: String_Access
;
167 Object_Dir_Name
:= new String'(Object_Dir_Default_Prefix);
168 Get_Next_Dir_In_Path_Init (Object_Dir_Name);
172 Dir : constant String_Access :=
173 String_Access (Get_Next_Dir_In_Path (Object_Dir_Name));
175 exit when Dir = null;
176 Object_Dirs := Object_Dirs + 1;
177 Object_Dir (Object_Dirs) :=
179 To_Canonical_Dir_Spec
181 (Normalize_Directory_Name
(Dir
.all).all,
182 True).all, True).all);
186 Object_Dirs
:= Object_Dirs
+ 1;
187 Object_Dir
(Object_Dirs
) := new String'("-lgnat");
189 if OpenVMS_On_Target then
190 Object_Dirs := Object_Dirs + 1;
191 Object_Dir (Object_Dirs) := new String'("-ldecgnat");
194 return Object_Dir
(1 .. Object_Dirs
);
195 end Init_Object_Dirs
;
201 procedure Initialize
is
205 (Cname
=> new S
'("BIND"),
206 Usage => new S'("GNAT BIND file[.ali] /qualifiers"),
208 Unixcmd
=> new S
'("gnatbind"),
210 Switches => Bind_Switches'Access,
211 Params => new Parameter_Array'(1 => Unlimited_Files
),
215 (Cname
=> new S
'("CHOP"),
216 Usage => new S'("GNAT CHOP file [directory] /qualifiers"),
218 Unixcmd
=> new S
'("gnatchop"),
220 Switches => Chop_Switches'Access,
221 Params => new Parameter_Array'(1 => File
, 2 => Optional_File
),
225 (Cname
=> new S
'("CLEAN"),
226 Usage => new S'("GNAT CLEAN /qualifiers files"),
228 Unixcmd
=> new S
'("gnatclean"),
230 Switches => Clean_Switches'Access,
231 Params => new Parameter_Array'(1 => File
),
235 (Cname
=> new S
'("COMPILE"),
236 Usage => new S'("GNAT COMPILE filespec[,...] /qualifiers"),
238 Unixcmd
=> new S
'("gnatmake"),
239 Unixsws => new Argument_List'(1 => new String'("-f"),
240 2 => new String'("-u"),
241 3 => new String'("-c")),
242 Switches => GCC_Switches'Access,
243 Params => new Parameter_Array'(1 => Files_Or_Wildcard
),
247 (Cname
=> new S
'("CHECK"),
248 Usage => new S'("GNAT CHECK name /qualifiers"),
250 Unixcmd
=> new S
'("gnatcheck"),
252 Switches => Check_Switches'Access,
253 Params => new Parameter_Array'(1 => Unlimited_Files
),
257 (Cname
=> new S
'("ELIM"),
258 Usage => new S'("GNAT ELIM name /qualifiers"),
260 Unixcmd
=> new S
'("gnatelim"),
262 Switches => Elim_Switches'Access,
263 Params => new Parameter_Array'(1 => Other_As_Is
),
267 (Cname
=> new S
'("FIND"),
268 Usage => new S'("GNAT FIND pattern[:sourcefile[:line"
269 & "[:column]]] filespec[,...] /qualifiers"),
271 Unixcmd
=> new S
'("gnatfind"),
273 Switches => Find_Switches'Access,
274 Params => new Parameter_Array'(1 => Other_As_Is
,
275 2 => Files_Or_Wildcard
),
279 (Cname
=> new S
'("KRUNCH"),
280 Usage => new S'("GNAT KRUNCH file [/COUNT=nnn]"),
282 Unixcmd
=> new S
'("gnatkr"),
284 Switches => Krunch_Switches'Access,
285 Params => new Parameter_Array'(1 => File
),
289 (Cname
=> new S
'("LINK"),
290 Usage => new S'("GNAT LINK file[.ali]"
291 & " [extra obj_&_lib_&_exe_&_opt files]"
294 Unixcmd
=> new S
'("gnatlink"),
296 Switches => Link_Switches'Access,
297 Params => new Parameter_Array'(1 => Unlimited_Files
),
301 (Cname
=> new S
'("LIST"),
302 Usage => new S'("GNAT LIST /qualifiers object_or_ali_file"),
304 Unixcmd
=> new S
'("gnatls"),
306 Switches => List_Switches'Access,
307 Params => new Parameter_Array'(1 => Unlimited_Files
),
311 (Cname
=> new S
'("MAKE"),
312 Usage => new S'("GNAT MAKE file(s) /qualifiers (includes "
313 & "COMPILE /qualifiers)"),
315 Unixcmd
=> new S
'("gnatmake"),
317 Switches => Make_Switches'Access,
318 Params => new Parameter_Array'(1 => Unlimited_Files
),
322 (Cname
=> new S
'("METRIC"),
323 Usage => new S'("GNAT METRIC /qualifiers source_file"),
325 Unixcmd
=> new S
'("gnatmetric"),
327 Switches => Metric_Switches'Access,
328 Params => new Parameter_Array'(1 => Unlimited_Files
),
332 (Cname
=> new S
'("NAME"),
333 Usage => new S'("GNAT NAME /qualifiers naming-pattern "
334 & "[naming-patterns]"),
336 Unixcmd
=> new S
'("gnatname"),
338 Switches => Name_Switches'Access,
339 Params => new Parameter_Array'(1 => Unlimited_As_Is
),
343 (Cname
=> new S
'("PREPROCESS"),
345 new S'("GNAT PREPROCESS ifile ofile dfile /qualifiers"),
347 Unixcmd
=> new S
'("gnatprep"),
349 Switches => Prep_Switches'Access,
350 Params => new Parameter_Array'(1 .. 3 => File
),
354 (Cname
=> new S
'("PRETTY"),
355 Usage => new S'("GNAT PRETTY /qualifiers source_file"),
357 Unixcmd
=> new S
'("gnatpp"),
359 Switches => Pretty_Switches'Access,
360 Params => new Parameter_Array'(1 => Unlimited_Files
),
364 (Cname
=> new S
'("SETUP"),
365 Usage => new S'("GNAT SETUP /qualifiers"),
367 Unixcmd
=> new S
'(""),
369 Switches => Setup_Switches'Access,
370 Params => new Parameter_Array'(1 => Unlimited_Files
),
374 (Cname
=> new S
'("SHARED"),
375 Usage => new S'("GNAT SHARED [obj_&_lib_&_exe_&_opt"
376 & "files] /qualifiers"),
378 Unixcmd
=> new S
'("gcc"),
380 new Argument_List'(new String'("-shared") & Init_Object_Dirs),
381 Switches => Shared_Switches'Access,
382 Params => new Parameter_Array'(1 => Unlimited_Files
),
386 (Cname
=> new S
'("STUB"),
387 Usage => new S'("GNAT STUB file [directory]/qualifiers"),
389 Unixcmd
=> new S
'("gnatstub"),
391 Switches => Stub_Switches'Access,
392 Params => new Parameter_Array'(1 => File
, 2 => Optional_File
),
396 (Cname
=> new S
'("XREF"),
397 Usage => new S'("GNAT XREF filespec[,...] /qualifiers"),
399 Unixcmd
=> new S
'("gnatxref"),
401 Switches => Xref_Switches'Access,
402 Params => new Parameter_Array'(1 => Files_Or_Wildcard
),
411 function Invert_Sense
(S
: String) return VMS_Data
.String_Ptr
is
412 Sinv
: String (1 .. S
'Length * 2);
413 -- Result (for sure long enough)
415 Sinvp
: Natural := 0;
416 -- Pointer to output string
419 for Sp
in S
'Range loop
420 if Sp
= S
'First or else S
(Sp
- 1) = ',' then
424 Sinv
(Sinvp
+ 1) := '!';
425 Sinv
(Sinvp
+ 2) := S
(Sp
);
430 Sinv
(Sinvp
+ 1) := S
(Sp
);
435 return new String'(Sinv (1 .. Sinvp));
438 ----------------------
439 -- Is_Extensionless --
440 ----------------------
442 function Is_Extensionless (F : String) return Boolean is
444 for J in reverse F'Range loop
447 elsif F (J) = '/' or else F (J) = ']' or else F (J) = ':' then
453 end Is_Extensionless;
459 function Match (S1, S2 : String) return Boolean is
460 Dif : constant Integer := S2'First - S1'First;
464 if S1'Length /= S2'Length then
468 for J in S1'Range loop
469 if To_Lower (S1 (J)) /= To_Lower (S2 (J + Dif)) then
482 function Match_Prefix (S1, S2 : String) return Boolean is
484 if S1'Length > S2'Length then
487 return Match (S1, S2 (S2'First .. S2'First + S1'Length - 1));
495 function Matching_Name
498 Quiet : Boolean := False) return Item_Ptr
503 -- Little procedure to output command/qualifier/option as appropriate
504 -- and bump error count.
516 Errors := Errors + 1;
521 Put (Standard_Error, "command");
524 if Hostparm.OpenVMS then
525 Put (Standard_Error, "qualifier");
527 Put (Standard_Error, "switch");
531 Put (Standard_Error, "option");
535 Put (Standard_Error, "input");
539 Put (Standard_Error, ": ");
540 Put (Standard_Error, S);
543 -- Start of processing for Matching_Name
546 -- If exact match, that's the one we want
549 while P1 /= null loop
550 if Match (S, P1.Name.all) then
557 -- Now check for prefix matches
560 while P1 /= null loop
561 if P1.Name.all = "/<other>" then
564 elsif not Match_Prefix (S, P1.Name.all) then
568 -- Here we have found one matching prefix, so see if there is
569 -- another one (which is an ambiguity)
572 while P2 /= null loop
573 if Match_Prefix (S, P2.Name.all) then
575 Put (Standard_Error, "ambiguous ");
577 Put (Standard_Error, " (matches ");
578 Put (Standard_Error, P1.Name.all);
580 while P2 /= null loop
581 if Match_Prefix (S, P2.Name.all) then
582 Put (Standard_Error, ',');
583 Put (Standard_Error, P2.Name.all);
589 Put_Line (Standard_Error, ")");
598 -- If we fall through that loop, then there was only one match
604 -- If we fall through outer loop, there was no match
607 Put (Standard_Error, "unrecognized ");
609 New_Line (Standard_Error);
615 -----------------------
616 -- OK_Alphanumerplus --
617 -----------------------
619 function OK_Alphanumerplus (S : String) return Boolean is
625 for J in S'Range loop
626 if not (Is_Alphanumeric (S (J)) or else
627 S (J) = '_
' or else S (J) = '$
')
635 end OK_Alphanumerplus;
641 function OK_Integer (S : String) return Boolean is
647 for J in S'Range loop
648 if not Is_Digit (S (J)) then
661 procedure Output_Version is
664 Put_Line (Gnatvsn.Gnat_Version_String);
665 Put_Line ("Copyright 1996-" &
667 ", Free Software Foundation, Inc.");
674 procedure Place (C : Character) is
676 Buffer.Increment_Last;
677 Buffer.Table (Buffer.Last) := C;
680 procedure Place (S : String) is
682 for J in S'Range loop
691 procedure Place_Lower (S : String) is
693 for J in S'Range loop
694 Place (To_Lower (S (J)));
698 -------------------------
699 -- Place_Unix_Switches --
700 -------------------------
702 procedure Place_Unix_Switches (S : VMS_Data.String_Ptr) is
703 P1, P2, P3 : Natural;
705 Slen, Sln2 : Natural;
706 Wild_Card : Boolean := False;
710 while P1 <= S'Last loop
719 pragma Assert (S (P1) = '-' or else S (P1) = '`
');
721 while P2 < S'Last and then S (P2 + 1) /= ',' loop
725 -- Switch is now in S (P1 .. P2)
730 Wild_Card := S (P2) = '*';
738 while P3 <= Buffer.Last - Slen loop
739 if Buffer.Table (P3) = ' '
740 and then String (Buffer.Table (P3 + 1 .. P3 + Slen)) =
744 P3 + Slen = Buffer.Last
746 Buffer.Table (P3 + Slen + 1) = ' ')
751 while P3 + Sln2 /= Buffer.Last
752 and then Buffer.Table (P3 + Sln2 + 1) /= ' '
758 Buffer.Table (P3 .. Buffer.Last - Sln2 - 1) :=
759 Buffer.Table (P3 + Sln2 + 1 .. Buffer.Last);
760 Buffer.Set_Last (Buffer.Last - Sln2 - 1);
772 pragma Assert (S (P2) /= '*');
779 Place (S (P1 .. P2));
784 end Place_Unix_Switches;
786 -----------------------------
787 -- Preprocess_Command_Data --
788 -----------------------------
790 procedure Preprocess_Command_Data is
792 for C in Real_Command_Type loop
794 Command : constant Item_Ptr := new Command_Item;
796 Last_Switch : Item_Ptr;
797 -- Last switch in list
800 -- Link new command item into list of commands
802 if Last_Command = null then
805 Last_Command.Next := Command;
808 Last_Command := Command;
810 -- Fill in fields of new command item
812 Command.Name := Command_List (C).Cname;
813 Command.Usage := Command_List (C).Usage;
814 Command.Command := C;
816 if Command_List (C).Unixsws = null then
817 Command.Unix_String := Command_List (C).Unixcmd;
820 Cmd : String (1 .. 5_000);
822 Sws : constant Argument_List_Access :=
823 Command_List (C).Unixsws;
826 Cmd (1 .. Command_List (C).Unixcmd'Length) :=
827 Command_List (C).Unixcmd.all;
828 Last := Command_List (C).Unixcmd'Length;
830 for J in Sws'Range loop
833 Cmd (Last + 1 .. Last + Sws (J)'Length) :=
835 Last := Last + Sws (J)'Length;
838 Command.Unix_String := new String'(Cmd
(1 .. Last
));
842 Command
.Params
:= Command_List
(C
).Params
;
843 Command
.Defext
:= Command_List
(C
).Defext
;
845 Validate_Command_Or_Option
(Command
.Name
);
847 -- Process the switch list
849 for S
in Command_List
(C
).Switches
'Range loop
851 SS
: constant VMS_Data
.String_Ptr
:=
852 Command_List
(C
).Switches
(S
);
853 P
: Natural := SS
'First;
854 Sw
: Item_Ptr
:= new Switch_Item
;
857 -- Pointer to last option
860 -- Link new switch item into list of switches
862 if Last_Switch
= null then
863 Command
.Switches
:= Sw
;
865 Last_Switch
.Next
:= Sw
;
870 -- Process switch string, first get name
872 while SS
(P
) /= ' ' and SS
(P
) /= '=' loop
876 Sw
.Name
:= new String'(SS (SS'First .. P - 1));
878 -- Direct translation case
881 Sw.Translation := T_Direct;
882 Sw.Unix_String := new String'(SS
(P
+ 1 .. SS
'Last));
883 Validate_Unix_Switch
(Sw
.Unix_String
);
885 if SS
(P
- 1) = '>' then
886 Sw
.Translation
:= T_Other
;
888 elsif SS
(P
+ 1) = '`' then
891 -- Create the inverted case (/NO ..)
893 elsif SS
(SS
'First + 1 .. SS
'First + 2) /= "NO" then
894 Sw
:= new Switch_Item
;
895 Last_Switch
.Next
:= Sw
;
899 new String'("/NO" & SS (SS'First + 1 .. P - 1));
900 Sw.Translation := T_Direct;
901 Sw.Unix_String := Invert_Sense (SS (P + 1 .. SS'Last));
902 Validate_Unix_Switch (Sw.Unix_String);
905 -- Directories translation case
907 elsif SS (P + 1) = '*' then
908 pragma Assert (SS (SS'Last) = '*');
909 Sw.Translation := T_Directories;
910 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
911 Validate_Unix_Switch
(Sw
.Unix_String
);
913 -- Directory translation case
915 elsif SS
(P
+ 1) = '%' then
916 pragma Assert
(SS
(SS
'Last) = '%');
917 Sw
.Translation
:= T_Directory
;
918 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
919 Validate_Unix_Switch (Sw.Unix_String);
921 -- File translation case
923 elsif SS (P + 1) = '@
' then
924 pragma Assert (SS (SS'Last) = '@
');
925 Sw.Translation := T_File;
926 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
927 Validate_Unix_Switch
(Sw
.Unix_String
);
929 -- No space file translation case
931 elsif SS
(P
+ 1) = '<' then
932 pragma Assert
(SS
(SS
'Last) = '>');
933 Sw
.Translation
:= T_No_Space_File
;
934 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
935 Validate_Unix_Switch (Sw.Unix_String);
937 -- Numeric translation case
939 elsif SS (P + 1) = '#
' then
940 pragma Assert (SS (SS'Last) = '#
');
941 Sw.Translation := T_Numeric;
942 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
943 Validate_Unix_Switch
(Sw
.Unix_String
);
945 -- Alphanumerplus translation case
947 elsif SS
(P
+ 1) = '|' then
948 pragma Assert
(SS
(SS
'Last) = '|');
949 Sw
.Translation
:= T_Alphanumplus
;
950 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
951 Validate_Unix_Switch (Sw.Unix_String);
953 -- String translation case
955 elsif SS (P + 1) = '"' then
956 pragma Assert (SS (SS'Last) = '"');
957 Sw.Translation := T_String;
958 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
959 Validate_Unix_Switch
(Sw
.Unix_String
);
961 -- Commands translation case
963 elsif SS
(P
+ 1) = '?' then
964 Sw
.Translation
:= T_Commands
;
965 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last));
967 -- Options translation case
970 Sw.Translation := T_Options;
971 Sw.Unix_String := new String'("");
973 P
:= P
+ 1; -- bump past =
974 while P
<= SS
'Last loop
976 Opt
: constant Item_Ptr
:= new Option_Item
;
980 -- Link new option item into options list
982 if Last_Opt
= null then
985 Last_Opt
.Next
:= Opt
;
990 -- Fill in fields of new option item
993 while SS
(Q
) /= ' ' loop
997 Opt
.Name
:= new String'(SS (P .. Q - 1));
998 Validate_Command_Or_Option (Opt.Name);
1003 while Q <= SS'Last and then SS (Q) /= ' ' loop
1007 Opt.Unix_String := new String'(SS
(P
.. Q
- 1));
1008 Validate_Unix_Switch
(Opt
.Unix_String
);
1017 end Preprocess_Command_Data
;
1019 ----------------------
1020 -- Process_Argument --
1021 ----------------------
1023 procedure Process_Argument
(The_Command
: in out Command_Type
) is
1024 Argv
: String_Access
;
1027 function Get_Arg_End
1029 Arg_Idx
: Integer) return Integer;
1030 -- Begins looking at Arg_Idx + 1 and returns the index of the
1031 -- last character before a slash or else the index of the last
1032 -- character in the string Argv.
1038 function Get_Arg_End
1040 Arg_Idx
: Integer) return Integer
1043 for J
in Arg_Idx
+ 1 .. Argv
'Last loop
1044 if Argv
(J
) = '/' then
1052 -- Start of processing for Process_Argument
1055 -- If an argument file is open, read the next non empty line
1057 if Is_Open
(Arg_File
) then
1059 Line
: String (1 .. 256);
1063 Get_Line
(Arg_File
, Line
, Last
);
1064 exit when Last
/= 0 or else End_Of_File
(Arg_File
);
1067 -- If the end of the argument file has been reached, close it
1069 if End_Of_File
(Arg_File
) then
1072 -- If the last line was empty, return after increasing Arg_Num
1073 -- to go to the next argument on the comment line.
1076 Arg_Num
:= Arg_Num
+ 1;
1081 Argv
:= new String'(Line (1 .. Last));
1084 if Argv (1) = '@
' then
1085 Put_Line (Standard_Error, "argument file cannot contain @cmd");
1091 -- No argument file is open, get the argument on the command line
1093 Argv := new String'(Argument
(Arg_Num
));
1094 Arg_Idx
:= Argv
'First;
1096 -- Check if this is the specification of an argument file
1098 if Argv
(Arg_Idx
) = '@' then
1099 -- The first argument on the command line cannot be an argument
1105 "Cannot specify argument line before command");
1109 -- Open the file, after conversion of the name to canonical form.
1110 -- Fail if file is not found.
1113 Canonical_File_Name
: String_Access
:=
1114 To_Canonical_File_Spec
(Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1116 Open
(Arg_File
, In_File
, Canonical_File_Name
.all);
1117 Free
(Canonical_File_Name
);
1122 Put
(Standard_Error
, "Cannot open argument file """);
1123 Put
(Standard_Error
, Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1124 Put_Line
(Standard_Error
, """");
1130 <<Tryagain_After_Coalesce
>>
1133 Next_Arg_Idx
: Integer;
1134 Arg
: String_Access
;
1137 Next_Arg_Idx
:= Get_Arg_End
(Argv
.all, Arg_Idx
);
1138 Arg
:= new String'(Argv (Arg_Idx .. Next_Arg_Idx));
1140 -- The first one must be a command name
1142 if Arg_Num = 1 and then Arg_Idx = Argv'First then
1143 Command := Matching_Name (Arg.all, Commands);
1145 if Command = null then
1149 The_Command := Command.Command;
1150 Output_File_Expected := False;
1152 -- Give usage information if only command given
1154 if Argument_Count = 1
1155 and then Next_Arg_Idx = Argv'Last
1160 ("List of available qualifiers and options");
1163 Put (Command.Usage.all);
1165 Put_Line (Command.Unix_String.all);
1168 Sw : Item_Ptr := Command.Switches;
1171 while Sw /= null loop
1175 case Sw.Translation is
1179 Put_Line (Sw.Unix_String.all &
1184 Put_Line (Sw.Unix_String.all);
1186 when T_Directories =>
1187 Put ("=(direc,direc,..direc)");
1189 Put (Sw.Unix_String.all);
1191 Put (Sw.Unix_String.all);
1192 Put_Line (" direc ...");
1197 Put (Sw.Unix_String.all);
1199 if Sw.Unix_String (Sw.Unix_String'Last)
1205 Put_Line ("directory ");
1207 when T_File | T_No_Space_File =>
1210 Put (Sw.Unix_String.all);
1212 if Sw.Translation = T_File
1213 and then Sw.Unix_String
1214 (Sw.Unix_String'Last) /= '='
1226 (Sw.Unix_String'First) = '`
'
1229 (Sw.Unix_String'First + 1
1230 .. Sw.Unix_String'Last));
1232 Put (Sw.Unix_String.all);
1237 when T_Alphanumplus =>
1242 (Sw.Unix_String'First) = '`
'
1245 (Sw.Unix_String'First + 1
1246 .. Sw.Unix_String'Last));
1248 Put (Sw.Unix_String.all);
1260 Put (Sw.Unix_String.all);
1263 (Sw.Unix_String'Last) /= '='
1272 Put (" (switches for ");
1274 (Sw.Unix_String'First + 7
1275 .. Sw.Unix_String'Last));
1279 (Sw.Unix_String'First
1280 .. Sw.Unix_String'First + 5));
1281 Put_Line (" switches");
1285 Opt : Item_Ptr := Sw.Options;
1288 Put_Line ("=(option,option..)");
1290 while Opt /= null loop
1294 if Opt = Sw.Options then
1299 Put_Line (Opt.Unix_String.all);
1313 -- Special handling for internal debugging switch /?
1315 elsif Arg.all = "/?" then
1316 Display_Command := True;
1317 Output_File_Expected := False;
1319 -- Special handling of internal option /KEEP_TEMPORARY_FILES
1321 elsif Arg'Length >= 7
1322 and then Matching_Name
1323 (Arg.all, Keep_Temps_Option, True) /= null
1325 Opt.Keep_Temporary_Files := True;
1327 -- Copy -switch unchanged
1329 elsif Arg (Arg'First) = '-' then
1333 -- Set Output_File_Expected for the next argument
1335 Output_File_Expected :=
1336 Arg.all = "-o" and then The_Command = Link;
1338 -- Copy quoted switch with quotes stripped
1340 elsif Arg (Arg'First) = '"' then
1341 if Arg (Arg'Last) /= '"' then
1342 Put (Standard_Error, "misquoted argument: ");
1343 Put_Line (Standard_Error, Arg.all);
1344 Errors := Errors + 1;
1348 Place (Arg (Arg'First + 1 .. Arg'Last - 1));
1351 Output_File_Expected := False;
1353 -- Parameter Argument
1355 elsif Arg (Arg'First) /= '/'
1356 and then Make_Commands_Active = null
1358 Param_Count := Param_Count + 1;
1360 if Param_Count <= Command.Params'Length then
1362 case Command.Params (Param_Count) is
1364 when File | Optional_File =>
1366 Normal_File : constant String_Access :=
1367 To_Canonical_File_Spec
1372 Place_Lower (Normal_File.all);
1374 if Is_Extensionless (Normal_File.all)
1375 and then Command.Defext /= " "
1378 Place (Command.Defext);
1382 when Unlimited_Files =>
1384 Normal_File : constant String_Access :=
1385 To_Canonical_File_Spec
1388 File_Is_Wild : Boolean := False;
1389 File_List : String_Access_List_Access;
1392 for J in Arg'Range loop
1394 or else Arg (J) = '%'
1396 File_Is_Wild := True;
1400 if File_Is_Wild then
1401 File_List := To_Canonical_File_List
1404 for J in File_List.all'Range loop
1406 Place_Lower (File_List.all (J).all);
1411 Place_Lower (Normal_File.all);
1413 -- Add extension if not present, except after
1416 if Is_Extensionless (Normal_File.all)
1417 and then Command.Defext /= " "
1418 and then not Output_File_Expected
1421 Place (Command.Defext);
1425 Param_Count := Param_Count - 1;
1432 when Unlimited_As_Is =>
1435 Param_Count := Param_Count - 1;
1437 when Files_Or_Wildcard =>
1439 -- Remove spaces from a comma separated list
1440 -- of file names and adjust control variables
1443 while Arg_Num < Argument_Count and then
1444 (Argv (Argv'Last) = ',' xor
1445 Argument (Arg_Num + 1)
1446 (Argument (Arg_Num + 1)'First) = ',')
1449 (Argv
.all & Argument
(Arg_Num
+ 1));
1450 Arg_Num
:= Arg_Num
+ 1;
1451 Arg_Idx
:= Argv
'First;
1453 Get_Arg_End
(Argv
.all, Arg_Idx
);
1455 (Argv (Arg_Idx .. Next_Arg_Idx));
1458 -- Parse the comma separated list of VMS
1459 -- filenames and place them on the command
1460 -- line as space separated Unix style
1461 -- filenames. Lower case and add default
1462 -- extension as appropriate.
1465 Arg1_Idx : Integer := Arg'First;
1467 function Get_Arg1_End
1469 Arg_Idx : Integer) return Integer;
1470 -- Begins looking at Arg_Idx + 1 and
1471 -- returns the index of the last character
1472 -- before a comma or else the index of the
1473 -- last character in the string Arg.
1479 function Get_Arg1_End
1481 Arg_Idx : Integer) return Integer
1484 for J in Arg_Idx + 1 .. Arg'Last loop
1485 if Arg (J) = ',' then
1498 Get_Arg1_End (Arg.all, Arg1_Idx);
1502 Arg (Arg1_Idx .. Next_Arg1_Idx);
1505 constant String_Access :=
1506 To_Canonical_File_Spec (Arg1);
1510 Place_Lower (Normal_File.all);
1512 if Is_Extensionless (Normal_File.all)
1513 and then Command.Defext /= " "
1516 Place (Command.Defext);
1519 Arg1_Idx := Next_Arg1_Idx + 1;
1522 exit when Arg1_Idx > Arg'Last;
1524 -- Don't allow two or more commas in
1527 if Arg (Arg1_Idx) = ',' then
1528 Arg1_Idx := Arg1_Idx + 1;
1529 if Arg1_Idx > Arg'Last or else
1530 Arg (Arg1_Idx) = ','
1534 "Malformed Parameter: " &
1536 Put (Standard_Error, "usage: ");
1537 Put_Line (Standard_Error,
1548 -- Reset Output_File_Expected, in case it was True
1550 Output_File_Expected := False;
1552 -- Qualifier argument
1555 Output_File_Expected := False;
1557 -- This code is too heavily nested, should be
1558 -- separated out as separate subprogram ???
1564 Endp : Natural := 0; -- avoid warning!
1569 while SwP < Arg'Last
1570 and then Arg (SwP + 1) /= '='
1575 -- At this point, the switch name is in
1576 -- Arg (Arg'First..SwP) and if that is not the
1577 -- whole switch, then there is an equal sign at
1578 -- Arg (SwP + 1) and the rest of Arg is what comes
1579 -- after the equal sign.
1581 -- If make commands are active, see if we have
1582 -- another COMMANDS_TRANSLATION switch belonging
1585 if Make_Commands_Active /= null then
1588 (Arg (Arg'First .. SwP),
1593 and then Sw.Translation = T_Commands
1600 (Arg (Arg'First .. SwP),
1601 Make_Commands_Active.Switches,
1605 -- For case of GNAT MAKE or CHOP, if we cannot
1606 -- find the switch, then see if it is a
1607 -- recognized compiler switch instead, and if
1608 -- so process the compiler switch.
1610 elsif Command.Name.all = "MAKE"
1611 or else Command.Name.all = "CHOP" then
1614 (Arg (Arg'First .. SwP),
1621 (Arg (Arg'First .. SwP),
1623 ("COMPILE", Commands).Switches,
1627 -- For all other cases, just search the relevant
1633 (Arg (Arg'First .. SwP),
1639 case Sw.Translation is
1642 Place_Unix_Switches (Sw.Unix_String);
1644 and then Arg (SwP + 1) = '='
1646 Put (Standard_Error,
1647 "qualifier options ignored: ");
1648 Put_Line (Standard_Error, Arg.all);
1651 when T_Directories =>
1652 if SwP + 1 > Arg'Last then
1653 Put (Standard_Error,
1654 "missing directories for: ");
1655 Put_Line (Standard_Error, Arg.all);
1656 Errors := Errors + 1;
1658 elsif Arg (SwP + 2) /= '(' then
1662 elsif Arg (Arg'Last) /= ')' then
1664 -- Remove spaces from a comma separated
1665 -- list of file names and adjust
1666 -- control variables accordingly.
1668 if Arg_Num < Argument_Count and then
1669 (Argv (Argv'Last) = ',' xor
1670 Argument (Arg_Num + 1)
1671 (Argument (Arg_Num + 1)'First) = ',')
1674 new String'(Argv
.all
1677 Arg_Num
:= Arg_Num
+ 1;
1678 Arg_Idx
:= Argv
'First;
1680 Get_Arg_End
(Argv
.all, Arg_Idx
);
1682 (Argv (Arg_Idx .. Next_Arg_Idx));
1683 goto Tryagain_After_Coalesce;
1686 Put (Standard_Error,
1687 "incorrectly parenthesized " &
1688 "or malformed argument: ");
1689 Put_Line (Standard_Error, Arg.all);
1690 Errors := Errors + 1;
1694 Endp := Arg'Last - 1;
1697 while SwP <= Endp loop
1699 Dir_Is_Wild : Boolean := False;
1700 Dir_Maybe_Is_Wild : Boolean := False;
1702 Dir_List : String_Access_List_Access;
1708 and then Arg (P2 + 1) /= ','
1710 -- A wildcard directory spec on
1711 -- VMS will contain either * or
1714 if Arg (P2) = '*' then
1715 Dir_Is_Wild := True;
1717 elsif Arg (P2) = '%' then
1718 Dir_Is_Wild := True;
1720 elsif Dir_Maybe_Is_Wild
1721 and then Arg (P2) = '.'
1722 and then Arg (P2 + 1) = '.'
1724 Dir_Is_Wild := True;
1725 Dir_Maybe_Is_Wild := False;
1727 elsif Dir_Maybe_Is_Wild then
1728 Dir_Maybe_Is_Wild := False;
1730 elsif Arg (P2) = '.'
1731 and then Arg (P2 + 1) = '.'
1733 Dir_Maybe_Is_Wild := True;
1742 To_Canonical_File_List
1743 (Arg (SwP .. P2), True);
1745 for J in Dir_List.all'Range loop
1749 (Dir_List.all (J).all);
1756 (To_Canonical_Dir_Spec
1757 (Arg (SwP .. P2), False).all);
1765 if SwP + 1 > Arg'Last then
1766 Put (Standard_Error,
1767 "missing directory for: ");
1768 Put_Line (Standard_Error, Arg.all);
1769 Errors := Errors + 1;
1772 Place_Unix_Switches (Sw.Unix_String);
1774 -- Some switches end in "=". No space
1778 (Sw.Unix_String'Last) /= '='
1784 (To_Canonical_Dir_Spec
1785 (Arg (SwP + 2 .. Arg'Last),
1789 when T_File | T_No_Space_File =>
1790 if SwP + 1 > Arg'Last then
1791 Put (Standard_Error,
1792 "missing file for: ");
1793 Put_Line (Standard_Error, Arg.all);
1794 Errors := Errors + 1;
1797 Place_Unix_Switches (Sw.Unix_String);
1799 -- Some switches end in "=". No space
1802 if Sw.Translation = T_File
1803 and then Sw.Unix_String
1804 (Sw.Unix_String'Last) /= '='
1810 (To_Canonical_File_Spec
1811 (Arg (SwP + 2 .. Arg'Last)).all);
1815 if OK_Integer (Arg (SwP + 2 .. Arg'Last)) then
1816 Place_Unix_Switches (Sw.Unix_String);
1817 Place (Arg (SwP + 2 .. Arg'Last));
1820 Put (Standard_Error, "argument for ");
1821 Put (Standard_Error, Sw.Name.all);
1823 (Standard_Error, " must be numeric");
1824 Errors := Errors + 1;
1827 when T_Alphanumplus =>
1828 if OK_Alphanumerplus
1829 (Arg (SwP + 2 .. Arg'Last))
1831 Place_Unix_Switches (Sw.Unix_String);
1832 Place (Arg (SwP + 2 .. Arg'Last));
1835 Put (Standard_Error, "argument for ");
1836 Put (Standard_Error, Sw.Name.all);
1837 Put_Line (Standard_Error,
1838 " must be alphanumeric");
1839 Errors := Errors + 1;
1844 -- A String value must be extended to the
1845 -- end of the Argv, otherwise strings like
1846 -- "foo/bar" get split at the slash.
1848 -- The begining and ending of the string
1849 -- are flagged with embedded nulls which
1850 -- are removed when building the Spawn
1851 -- call. Nulls are use because they won't
1852 -- show up in a /? output. Quotes aren't
1853 -- used because that would make it
1854 -- difficult to embed them.
1856 Place_Unix_Switches (Sw.Unix_String);
1858 if Next_Arg_Idx /= Argv'Last then
1859 Next_Arg_Idx := Argv'Last;
1861 (Argv
(Arg_Idx
.. Next_Arg_Idx
));
1864 while SwP
< Arg
'Last and then
1865 Arg
(SwP
+ 1) /= '=' loop
1871 Place
(Arg
(SwP
+ 2 .. Arg
'Last));
1876 -- Output -largs/-bargs/-cargs
1879 Place
(Sw
.Unix_String
1880 (Sw
.Unix_String
'First ..
1881 Sw
.Unix_String
'First + 5));
1884 (Sw
.Unix_String
'First + 7 ..
1885 Sw
.Unix_String
'Last) = "MAKE"
1887 Make_Commands_Active
:= null;
1890 -- Set source of new commands, also
1891 -- setting this non-null indicates that
1892 -- we are in the special commands mode
1893 -- for processing the -xargs case.
1895 Make_Commands_Active
:=
1898 (Sw
.Unix_String
'First + 7 ..
1899 Sw
.Unix_String
'Last),
1904 if SwP
+ 1 > Arg
'Last then
1906 (Sw
.Options
.Unix_String
);
1909 elsif Arg
(SwP
+ 2) /= '(' then
1913 elsif Arg
(Arg
'Last) /= ')' then
1914 Put
(Standard_Error
,
1915 "incorrectly parenthesized argument: ");
1916 Put_Line
(Standard_Error
, Arg
.all);
1917 Errors
:= Errors
+ 1;
1922 Endp
:= Arg
'Last - 1;
1925 while SwP
<= Endp
loop
1929 and then Arg
(P2
+ 1) /= ','
1934 -- Option name is in Arg (SwP .. P2)
1936 Opt
:= Matching_Name
(Arg
(SwP
.. P2
),
1949 (new String'(Sw.Unix_String.all &
1957 Arg_Idx := Next_Arg_Idx + 1;
1960 exit when Arg_Idx > Argv'Last;
1964 if not Is_Open (Arg_File) then
1965 Arg_Num := Arg_Num + 1;
1967 end Process_Argument;
1969 --------------------------------
1970 -- Validate_Command_Or_Option --
1971 --------------------------------
1973 procedure Validate_Command_Or_Option (N : VMS_Data.String_Ptr) is
1975 pragma Assert (N'Length > 0);
1977 for J in N'Range loop
1979 pragma Assert (N (J - 1) /= '_
');
1982 pragma Assert (Is_Upper (N (J)) or else Is_Digit (N (J)));
1986 end Validate_Command_Or_Option;
1988 --------------------------
1989 -- Validate_Unix_Switch --
1990 --------------------------
1992 procedure Validate_Unix_Switch (S : VMS_Data.String_Ptr) is
1994 if S (S'First) = '`
' then
1998 pragma Assert (S (S'First) = '-' or else S (S'First) = '!');
2000 for J in S'First + 1 .. S'Last loop
2001 pragma Assert (S (J) /= ' ');
2004 pragma Assert (S (J - 1) = ',' and then S (J + 1) = '-');
2008 end Validate_Unix_Switch;
2010 --------------------
2011 -- VMS_Conversion --
2012 --------------------
2014 procedure VMS_Conversion (The_Command : out Command_Type) is
2015 Result : Command_Type := Undefined;
2016 Result_Set : Boolean := False;
2020 -- First we must preprocess the string form of the command and options
2021 -- list into the internal form that we use.
2023 Preprocess_Command_Data;
2025 -- If no parameters, give complete list of commands
2027 if Argument_Count = 0 then
2030 Put_Line ("List of available commands");
2033 while Commands /= null loop
2034 Put (Commands.Usage.all);
2036 Put_Line (Commands.Unix_String.all);
2037 Commands := Commands.Next;
2045 -- Loop through arguments
2047 while Arg_Num <= Argument_Count loop
2048 Process_Argument (Result);
2050 if not Result_Set then
2051 The_Command := Result;
2056 -- Gross error checking that the number of parameters is correct.
2057 -- Not applicable to Unlimited_Files parameters.
2059 if (Param_Count = Command.Params'Length - 1
2060 and then Command.Params (Param_Count + 1) = Unlimited_Files)
2061 or else Param_Count <= Command.Params'Length
2066 Put_Line (Standard_Error,
2067 "Parameter count of "
2068 & Integer'Image (Param_Count)
2069 & " not equal to expected "
2070 & Integer'Image (Command.Params'Length));
2071 Put (Standard_Error, "usage: ");
2072 Put_Line (Standard_Error, Command.Usage.all);
2073 Errors := Errors + 1;
2079 -- Prepare arguments for a call to spawn, filtering out
2080 -- embedded nulls place there to delineate strings.
2084 Inside_Nul : Boolean := False;
2085 Arg : String (1 .. 1024);
2091 while P1 <= Buffer.Last and then Buffer.Table (P1) = ' ' loop
2096 Arg (Arg_Ctr) := Buffer.Table (P1);
2098 while P1 <= Buffer.Last loop
2100 if Buffer.Table (P1) = ASCII.NUL then
2102 Inside_Nul := False;
2108 if Buffer.Table (P1) = ' ' and then not Inside_Nul then
2110 Arg_Ctr := Arg_Ctr + 1;
2111 Arg (Arg_Ctr) := Buffer.Table (P1);
2114 Last_Switches.Increment_Last;
2117 while P2 < Buffer.Last
2118 and then (Buffer.Table (P2 + 1) /= ' ' or else
2122 Arg_Ctr := Arg_Ctr + 1;
2123 Arg (Arg_Ctr) := Buffer.Table (P2);
2124 if Buffer.Table (P2) = ASCII.NUL then
2125 Arg_Ctr := Arg_Ctr - 1;
2127 Inside_Nul := False;
2134 Last_Switches.Table (Last_Switches.Last) :=
2135 new String'(String (Arg
(1 .. Arg_Ctr
)));
2138 Arg
(Arg_Ctr
) := Buffer
.Table
(P1
);