1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2005 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
30 with Osint
; use Osint
;
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 Keep_Temps_Option
: constant Item_Ptr
:=
42 new String'("/KEEP_TEMPORARY_FILES"),
47 Param_Count
: Natural := 0;
48 -- Number of parameter arguments so far
53 Arg_File
: Ada
.Text_IO
.File_Type
;
54 -- A file where arguments are read from
57 -- Pointer to head of list of command items, one for each command, with
58 -- the end of the list marked by a null pointer.
60 Last_Command
: Item_Ptr
;
61 -- Pointer to last item in Commands list
64 -- Pointer to command item for current command
66 Make_Commands_Active
: Item_Ptr
:= null;
67 -- Set to point to Command entry for COMPILE, BIND, or LINK as appropriate
68 -- if a COMMANDS_TRANSLATION switch has been encountered while processing
71 Output_File_Expected
: Boolean := False;
72 -- True for GNAT LINK after -o switch, so that the ".ali" extension is
73 -- not added to the executable file name.
75 package Buffer
is new Table
.Table
76 (Table_Component_Type
=> Character,
77 Table_Index_Type
=> Integer,
79 Table_Initial
=> 4096,
81 Table_Name
=> "Buffer");
83 function Init_Object_Dirs
return Argument_List
;
84 -- Get the list of the object directories
86 function Invert_Sense
(S
: String) return VMS_Data
.String_Ptr
;
87 -- Given a unix switch string S, computes the inverse (adding or
88 -- removing ! characters as required), and returns a pointer to
89 -- the allocated result on the heap.
91 function Is_Extensionless
(F
: String) return Boolean;
92 -- Returns true if the filename has no extension
94 function Match
(S1
, S2
: String) return Boolean;
95 -- Determines whether S1 and S2 match (this is a case insensitive match)
97 function Match_Prefix
(S1
, S2
: String) return Boolean;
98 -- Determines whether S1 matches a prefix of S2. This is also a case
99 -- insensitive match (for example Match ("AB","abc") is True).
101 function Matching_Name
104 Quiet
: Boolean := False) return Item_Ptr
;
105 -- Determines if the item list headed by Itm and threaded through the
106 -- Next fields (with null marking the end of the list), contains an
107 -- entry that uniquely matches the given string. The match is case
108 -- insensitive and permits unique abbreviation. If the match succeeds,
109 -- then a pointer to the matching item is returned. Otherwise, an
110 -- appropriate error message is written. Note that the discriminant
111 -- of Itm is used to determine the appropriate form of this message.
112 -- Quiet is normally False as shown, if it is set to True, then no
113 -- error message is generated in a not found situation (null is still
114 -- returned to indicate the not-found situation).
116 function OK_Alphanumerplus
(S
: String) return Boolean;
117 -- Checks that S is a string of alphanumeric characters,
118 -- returning True if all alphanumeric characters,
119 -- False if empty or a non-alphanumeric character is present.
121 function OK_Integer
(S
: String) return Boolean;
122 -- Checks that S is a string of digits, returning True if all digits,
123 -- False if empty or a non-digit is present.
125 procedure Place
(C
: Character);
126 -- Place a single character in the buffer, updating Ptr
128 procedure Place
(S
: String);
129 -- Place a string character in the buffer, updating Ptr
131 procedure Place_Lower
(S
: String);
132 -- Place string in buffer, forcing letters to lower case, updating Ptr
134 procedure Place_Unix_Switches
(S
: VMS_Data
.String_Ptr
);
135 -- Given a unix switch string, place corresponding switches in Buffer,
136 -- updating Ptr appropriatelly. Note that in the case of use of ! the
137 -- result may be to remove a previously placed switch.
139 procedure Preprocess_Command_Data
;
140 -- Preprocess the string form of the command and options list into the
143 procedure Process_Argument
(The_Command
: in out Command_Type
);
144 -- Process one argument from the command line, or one line from
145 -- from a command line file. For the first call, set The_Command.
147 procedure Validate_Command_Or_Option
(N
: VMS_Data
.String_Ptr
);
148 -- Check that N is a valid command or option name, i.e. that it is of the
149 -- form of an Ada identifier with upper case letters and underscores.
151 procedure Validate_Unix_Switch
(S
: VMS_Data
.String_Ptr
);
152 -- Check that S is a valid switch string as described in the syntax for
153 -- the switch table item UNIX_SWITCH or else begins with a backquote.
155 ----------------------
156 -- Init_Object_Dirs --
157 ----------------------
159 function Init_Object_Dirs
return Argument_List
is
160 Object_Dirs
: Integer;
161 Object_Dir
: Argument_List
(1 .. 256);
162 Object_Dir_Name
: String_Access
;
166 Object_Dir_Name
:= new String'(Object_Dir_Default_Prefix);
167 Get_Next_Dir_In_Path_Init (Object_Dir_Name);
171 Dir : constant String_Access :=
172 String_Access (Get_Next_Dir_In_Path (Object_Dir_Name));
174 exit when Dir = null;
175 Object_Dirs := Object_Dirs + 1;
176 Object_Dir (Object_Dirs) :=
178 To_Canonical_Dir_Spec
180 (Normalize_Directory_Name
(Dir
.all).all,
181 True).all, True).all);
185 Object_Dirs
:= Object_Dirs
+ 1;
186 Object_Dir
(Object_Dirs
) := new String'("-lgnat");
188 if Hostparm.OpenVMS then
189 Object_Dirs := Object_Dirs + 1;
190 Object_Dir (Object_Dirs) := new String'("-ldecgnat");
193 return Object_Dir
(1 .. Object_Dirs
);
194 end Init_Object_Dirs
;
200 procedure Initialize
is
204 (Cname
=> new S
'("BIND"),
205 Usage => new S'("GNAT BIND file[.ali] /qualifiers"),
207 Unixcmd
=> new S
'("gnatbind"),
209 Switches => Bind_Switches'Access,
210 Params => new Parameter_Array'(1 => File
),
214 (Cname
=> new S
'("CHOP"),
215 Usage => new S'("GNAT CHOP file [directory] /qualifiers"),
217 Unixcmd
=> new S
'("gnatchop"),
219 Switches => Chop_Switches'Access,
220 Params => new Parameter_Array'(1 => File
, 2 => Optional_File
),
224 (Cname
=> new S
'("CLEAN"),
225 Usage => new S'("GNAT CLEAN /qualifiers files"),
227 Unixcmd
=> new S
'("gnatclean"),
229 Switches => Clean_Switches'Access,
230 Params => new Parameter_Array'(1 => File
),
234 (Cname
=> new S
'("COMPILE"),
235 Usage => new S'("GNAT COMPILE filespec[,...] /qualifiers"),
237 Unixcmd
=> new S
'("gnatmake"),
238 Unixsws => new Argument_List'(1 => new String'("-f"),
239 2 => new String'("-u"),
240 3 => new String'("-c")),
241 Switches => GCC_Switches'Access,
242 Params => new Parameter_Array'(1 => Files_Or_Wildcard
),
246 (Cname
=> new S
'("ELIM"),
247 Usage => new S'("GNAT ELIM name /qualifiers"),
249 Unixcmd
=> new S
'("gnatelim"),
251 Switches => Elim_Switches'Access,
252 Params => new Parameter_Array'(1 => Other_As_Is
),
256 (Cname
=> new S
'("FIND"),
257 Usage => new S'("GNAT FIND pattern[:sourcefile[:line"
258 & "[:column]]] filespec[,...] /qualifiers"),
260 Unixcmd
=> new S
'("gnatfind"),
262 Switches => Find_Switches'Access,
263 Params => new Parameter_Array'(1 => Other_As_Is
,
264 2 => Files_Or_Wildcard
),
268 (Cname
=> new S
'("KRUNCH"),
269 Usage => new S'("GNAT KRUNCH file [/COUNT=nnn]"),
271 Unixcmd
=> new S
'("gnatkr"),
273 Switches => Krunch_Switches'Access,
274 Params => new Parameter_Array'(1 => File
),
278 (Cname
=> new S
'("LIBRARY"),
279 Usage => new S'("GNAT LIBRARY /[CREATE | SET | DELETE]"
280 & "=directory [/CONFIG=file]"),
282 Unixcmd
=> new S
'("gnatlbr"),
284 Switches => Lbr_Switches'Access,
285 Params => new Parameter_Array'(1 .. 0 => 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-2005 Free Software Foundation, Inc.");
672 procedure Place (C : Character) is
674 Buffer.Increment_Last;
675 Buffer.Table (Buffer.Last) := C;
678 procedure Place (S : String) is
680 for J in S'Range loop
689 procedure Place_Lower (S : String) is
691 for J in S'Range loop
692 Place (To_Lower (S (J)));
696 -------------------------
697 -- Place_Unix_Switches --
698 -------------------------
700 procedure Place_Unix_Switches (S : VMS_Data.String_Ptr) is
701 P1, P2, P3 : Natural;
703 Slen, Sln2 : Natural;
704 Wild_Card : Boolean := False;
708 while P1 <= S'Last loop
717 pragma Assert (S (P1) = '-' or else S (P1) = '`
');
719 while P2 < S'Last and then S (P2 + 1) /= ',' loop
723 -- Switch is now in S (P1 .. P2)
728 Wild_Card := S (P2) = '*';
736 while P3 <= Buffer.Last - Slen loop
737 if Buffer.Table (P3) = ' '
738 and then String (Buffer.Table (P3 + 1 .. P3 + Slen)) =
742 P3 + Slen = Buffer.Last
744 Buffer.Table (P3 + Slen + 1) = ' ')
749 while P3 + Sln2 /= Buffer.Last
750 and then Buffer.Table (P3 + Sln2 + 1) /= ' '
756 Buffer.Table (P3 .. Buffer.Last - Sln2 - 1) :=
757 Buffer.Table (P3 + Sln2 + 1 .. Buffer.Last);
758 Buffer.Set_Last (Buffer.Last - Sln2 - 1);
770 pragma Assert (S (P2) /= '*');
777 Place (S (P1 .. P2));
782 end Place_Unix_Switches;
784 -----------------------------
785 -- Preprocess_Command_Data --
786 -----------------------------
788 procedure Preprocess_Command_Data is
790 for C in Real_Command_Type loop
792 Command : constant Item_Ptr := new Command_Item;
794 Last_Switch : Item_Ptr;
795 -- Last switch in list
798 -- Link new command item into list of commands
800 if Last_Command = null then
803 Last_Command.Next := Command;
806 Last_Command := Command;
808 -- Fill in fields of new command item
810 Command.Name := Command_List (C).Cname;
811 Command.Usage := Command_List (C).Usage;
812 Command.Command := C;
814 if Command_List (C).Unixsws = null then
815 Command.Unix_String := Command_List (C).Unixcmd;
818 Cmd : String (1 .. 5_000);
820 Sws : constant Argument_List_Access :=
821 Command_List (C).Unixsws;
824 Cmd (1 .. Command_List (C).Unixcmd'Length) :=
825 Command_List (C).Unixcmd.all;
826 Last := Command_List (C).Unixcmd'Length;
828 for J in Sws'Range loop
831 Cmd (Last + 1 .. Last + Sws (J)'Length) :=
833 Last := Last + Sws (J)'Length;
836 Command.Unix_String := new String'(Cmd
(1 .. Last
));
840 Command
.Params
:= Command_List
(C
).Params
;
841 Command
.Defext
:= Command_List
(C
).Defext
;
843 Validate_Command_Or_Option
(Command
.Name
);
845 -- Process the switch list
847 for S
in Command_List
(C
).Switches
'Range loop
849 SS
: constant VMS_Data
.String_Ptr
:=
850 Command_List
(C
).Switches
(S
);
851 P
: Natural := SS
'First;
852 Sw
: Item_Ptr
:= new Switch_Item
;
855 -- Pointer to last option
858 -- Link new switch item into list of switches
860 if Last_Switch
= null then
861 Command
.Switches
:= Sw
;
863 Last_Switch
.Next
:= Sw
;
868 -- Process switch string, first get name
870 while SS
(P
) /= ' ' and SS
(P
) /= '=' loop
874 Sw
.Name
:= new String'(SS (SS'First .. P - 1));
876 -- Direct translation case
879 Sw.Translation := T_Direct;
880 Sw.Unix_String := new String'(SS
(P
+ 1 .. SS
'Last));
881 Validate_Unix_Switch
(Sw
.Unix_String
);
883 if SS
(P
- 1) = '>' then
884 Sw
.Translation
:= T_Other
;
886 elsif SS
(P
+ 1) = '`' then
889 -- Create the inverted case (/NO ..)
891 elsif SS
(SS
'First + 1 .. SS
'First + 2) /= "NO" then
892 Sw
:= new Switch_Item
;
893 Last_Switch
.Next
:= Sw
;
897 new String'("/NO" & SS (SS'First + 1 .. P - 1));
898 Sw.Translation := T_Direct;
899 Sw.Unix_String := Invert_Sense (SS (P + 1 .. SS'Last));
900 Validate_Unix_Switch (Sw.Unix_String);
903 -- Directories translation case
905 elsif SS (P + 1) = '*' then
906 pragma Assert (SS (SS'Last) = '*');
907 Sw.Translation := T_Directories;
908 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
909 Validate_Unix_Switch
(Sw
.Unix_String
);
911 -- Directory translation case
913 elsif SS
(P
+ 1) = '%' then
914 pragma Assert
(SS
(SS
'Last) = '%');
915 Sw
.Translation
:= T_Directory
;
916 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
917 Validate_Unix_Switch (Sw.Unix_String);
919 -- File translation case
921 elsif SS (P + 1) = '@
' then
922 pragma Assert (SS (SS'Last) = '@
');
923 Sw.Translation := T_File;
924 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
925 Validate_Unix_Switch
(Sw
.Unix_String
);
927 -- No space file translation case
929 elsif SS
(P
+ 1) = '<' then
930 pragma Assert
(SS
(SS
'Last) = '>');
931 Sw
.Translation
:= T_No_Space_File
;
932 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
933 Validate_Unix_Switch (Sw.Unix_String);
935 -- Numeric translation case
937 elsif SS (P + 1) = '#
' then
938 pragma Assert (SS (SS'Last) = '#
');
939 Sw.Translation := T_Numeric;
940 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
941 Validate_Unix_Switch
(Sw
.Unix_String
);
943 -- Alphanumerplus translation case
945 elsif SS
(P
+ 1) = '|' then
946 pragma Assert
(SS
(SS
'Last) = '|');
947 Sw
.Translation
:= T_Alphanumplus
;
948 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last - 1));
949 Validate_Unix_Switch (Sw.Unix_String);
951 -- String translation case
953 elsif SS (P + 1) = '"' then
954 pragma Assert (SS (SS'Last) = '"');
955 Sw.Translation := T_String;
956 Sw.Unix_String := new String'(SS
(P
+ 2 .. SS
'Last - 1));
957 Validate_Unix_Switch
(Sw
.Unix_String
);
959 -- Commands translation case
961 elsif SS
(P
+ 1) = '?' then
962 Sw
.Translation
:= T_Commands
;
963 Sw
.Unix_String
:= new String'(SS (P + 2 .. SS'Last));
965 -- Options translation case
968 Sw.Translation := T_Options;
969 Sw.Unix_String := new String'("");
971 P
:= P
+ 1; -- bump past =
972 while P
<= SS
'Last loop
974 Opt
: constant Item_Ptr
:= new Option_Item
;
978 -- Link new option item into options list
980 if Last_Opt
= null then
983 Last_Opt
.Next
:= Opt
;
988 -- Fill in fields of new option item
991 while SS
(Q
) /= ' ' loop
995 Opt
.Name
:= new String'(SS (P .. Q - 1));
996 Validate_Command_Or_Option (Opt.Name);
1001 while Q <= SS'Last and then SS (Q) /= ' ' loop
1005 Opt.Unix_String := new String'(SS
(P
.. Q
- 1));
1006 Validate_Unix_Switch
(Opt
.Unix_String
);
1015 end Preprocess_Command_Data
;
1017 ----------------------
1018 -- Process_Argument --
1019 ----------------------
1021 procedure Process_Argument
(The_Command
: in out Command_Type
) is
1022 Argv
: String_Access
;
1025 function Get_Arg_End
1027 Arg_Idx
: Integer) return Integer;
1028 -- Begins looking at Arg_Idx + 1 and returns the index of the
1029 -- last character before a slash or else the index of the last
1030 -- character in the string Argv.
1036 function Get_Arg_End
1038 Arg_Idx
: Integer) return Integer
1041 for J
in Arg_Idx
+ 1 .. Argv
'Last loop
1042 if Argv
(J
) = '/' then
1050 -- Start of processing for Process_Argument
1053 -- If an argument file is open, read the next non empty line
1055 if Is_Open
(Arg_File
) then
1057 Line
: String (1 .. 256);
1061 Get_Line
(Arg_File
, Line
, Last
);
1062 exit when Last
/= 0 or else End_Of_File
(Arg_File
);
1065 -- If the end of the argument file has been reached, close it
1067 if End_Of_File
(Arg_File
) then
1070 -- If the last line was empty, return after increasing Arg_Num
1071 -- to go to the next argument on the comment line.
1074 Arg_Num
:= Arg_Num
+ 1;
1079 Argv
:= new String'(Line (1 .. Last));
1082 if Argv (1) = '@
' then
1083 Put_Line (Standard_Error, "argument file cannot contain @cmd");
1089 -- No argument file is open, get the argument on the command line
1091 Argv := new String'(Argument
(Arg_Num
));
1092 Arg_Idx
:= Argv
'First;
1094 -- Check if this is the specification of an argument file
1096 if Argv
(Arg_Idx
) = '@' then
1097 -- The first argument on the command line cannot be an argument
1103 "Cannot specify argument line before command");
1107 -- Open the file, after conversion of the name to canonical form.
1108 -- Fail if file is not found.
1111 Canonical_File_Name
: String_Access
:=
1112 To_Canonical_File_Spec
(Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1114 Open
(Arg_File
, In_File
, Canonical_File_Name
.all);
1115 Free
(Canonical_File_Name
);
1120 Put
(Standard_Error
, "Cannot open argument file """);
1121 Put
(Standard_Error
, Argv
(Arg_Idx
+ 1 .. Argv
'Last));
1122 Put_Line
(Standard_Error
, """");
1128 <<Tryagain_After_Coalesce
>>
1131 Next_Arg_Idx
: Integer;
1132 Arg
: String_Access
;
1135 Next_Arg_Idx
:= Get_Arg_End
(Argv
.all, Arg_Idx
);
1136 Arg
:= new String'(Argv (Arg_Idx .. Next_Arg_Idx));
1138 -- The first one must be a command name
1140 if Arg_Num = 1 and then Arg_Idx = Argv'First then
1141 Command := Matching_Name (Arg.all, Commands);
1143 if Command = null then
1147 The_Command := Command.Command;
1148 Output_File_Expected := False;
1150 -- Give usage information if only command given
1152 if Argument_Count = 1
1153 and then Next_Arg_Idx = Argv'Last
1158 ("List of available qualifiers and options");
1161 Put (Command.Usage.all);
1163 Put_Line (Command.Unix_String.all);
1166 Sw : Item_Ptr := Command.Switches;
1169 while Sw /= null loop
1173 case Sw.Translation is
1177 Put_Line (Sw.Unix_String.all &
1182 Put_Line (Sw.Unix_String.all);
1184 when T_Directories =>
1185 Put ("=(direc,direc,..direc)");
1187 Put (Sw.Unix_String.all);
1189 Put (Sw.Unix_String.all);
1190 Put_Line (" direc ...");
1195 Put (Sw.Unix_String.all);
1197 if Sw.Unix_String (Sw.Unix_String'Last)
1203 Put_Line ("directory ");
1205 when T_File | T_No_Space_File =>
1208 Put (Sw.Unix_String.all);
1210 if Sw.Translation = T_File
1211 and then Sw.Unix_String
1212 (Sw.Unix_String'Last) /= '='
1224 (Sw.Unix_String'First) = '`
'
1227 (Sw.Unix_String'First + 1
1228 .. Sw.Unix_String'Last));
1230 Put (Sw.Unix_String.all);
1235 when T_Alphanumplus =>
1240 (Sw.Unix_String'First) = '`
'
1243 (Sw.Unix_String'First + 1
1244 .. Sw.Unix_String'Last));
1246 Put (Sw.Unix_String.all);
1258 Put (Sw.Unix_String.all);
1261 (Sw.Unix_String'Last) /= '='
1270 Put (" (switches for ");
1272 (Sw.Unix_String'First + 7
1273 .. Sw.Unix_String'Last));
1277 (Sw.Unix_String'First
1278 .. Sw.Unix_String'First + 5));
1279 Put_Line (" switches");
1283 Opt : Item_Ptr := Sw.Options;
1286 Put_Line ("=(option,option..)");
1288 while Opt /= null loop
1292 if Opt = Sw.Options then
1297 Put_Line (Opt.Unix_String.all);
1311 -- Special handling for internal debugging switch /?
1313 elsif Arg.all = "/?" then
1314 Display_Command := True;
1315 Output_File_Expected := False;
1317 -- Special handling of internal option /KEEP_TEMPORARY_FILES
1319 elsif Arg'Length >= 7
1320 and then Matching_Name
1321 (Arg.all, Keep_Temps_Option, True) /= null
1323 Opt.Keep_Temporary_Files := True;
1325 -- Copy -switch unchanged
1327 elsif Arg (Arg'First) = '-' then
1331 -- Set Output_File_Expected for the next argument
1333 Output_File_Expected :=
1334 Arg.all = "-o" and then The_Command = Link;
1336 -- Copy quoted switch with quotes stripped
1338 elsif Arg (Arg'First) = '"' then
1339 if Arg (Arg'Last) /= '"' then
1340 Put (Standard_Error, "misquoted argument: ");
1341 Put_Line (Standard_Error, Arg.all);
1342 Errors := Errors + 1;
1346 Place (Arg (Arg'First + 1 .. Arg'Last - 1));
1349 Output_File_Expected := False;
1351 -- Parameter Argument
1353 elsif Arg (Arg'First) /= '/'
1354 and then Make_Commands_Active = null
1356 Param_Count := Param_Count + 1;
1358 if Param_Count <= Command.Params'Length then
1360 case Command.Params (Param_Count) is
1362 when File | Optional_File =>
1364 Normal_File : constant String_Access :=
1365 To_Canonical_File_Spec
1370 Place_Lower (Normal_File.all);
1372 if Is_Extensionless (Normal_File.all)
1373 and then Command.Defext /= " "
1376 Place (Command.Defext);
1380 when Unlimited_Files =>
1382 Normal_File : constant String_Access :=
1383 To_Canonical_File_Spec
1386 File_Is_Wild : Boolean := False;
1387 File_List : String_Access_List_Access;
1390 for J in Arg'Range loop
1392 or else Arg (J) = '%'
1394 File_Is_Wild := True;
1398 if File_Is_Wild then
1399 File_List := To_Canonical_File_List
1402 for J in File_List.all'Range loop
1404 Place_Lower (File_List.all (J).all);
1409 Place_Lower (Normal_File.all);
1411 -- Add extension if not present, except after
1414 if Is_Extensionless (Normal_File.all)
1415 and then Command.Defext /= " "
1416 and then not Output_File_Expected
1419 Place (Command.Defext);
1423 Param_Count := Param_Count - 1;
1430 when Unlimited_As_Is =>
1433 Param_Count := Param_Count - 1;
1435 when Files_Or_Wildcard =>
1437 -- Remove spaces from a comma separated list
1438 -- of file names and adjust control variables
1441 while Arg_Num < Argument_Count and then
1442 (Argv (Argv'Last) = ',' xor
1443 Argument (Arg_Num + 1)
1444 (Argument (Arg_Num + 1)'First) = ',')
1447 (Argv
.all & Argument
(Arg_Num
+ 1));
1448 Arg_Num
:= Arg_Num
+ 1;
1449 Arg_Idx
:= Argv
'First;
1451 Get_Arg_End
(Argv
.all, Arg_Idx
);
1453 (Argv (Arg_Idx .. Next_Arg_Idx));
1456 -- Parse the comma separated list of VMS
1457 -- filenames and place them on the command
1458 -- line as space separated Unix style
1459 -- filenames. Lower case and add default
1460 -- extension as appropriate.
1463 Arg1_Idx : Integer := Arg'First;
1465 function Get_Arg1_End
1467 Arg_Idx : Integer) return Integer;
1468 -- Begins looking at Arg_Idx + 1 and
1469 -- returns the index of the last character
1470 -- before a comma or else the index of the
1471 -- last character in the string Arg.
1477 function Get_Arg1_End
1479 Arg_Idx : Integer) return Integer
1482 for J in Arg_Idx + 1 .. Arg'Last loop
1483 if Arg (J) = ',' then
1496 Get_Arg1_End (Arg.all, Arg1_Idx);
1500 Arg (Arg1_Idx .. Next_Arg1_Idx);
1503 constant String_Access :=
1504 To_Canonical_File_Spec (Arg1);
1508 Place_Lower (Normal_File.all);
1510 if Is_Extensionless (Normal_File.all)
1511 and then Command.Defext /= " "
1514 Place (Command.Defext);
1517 Arg1_Idx := Next_Arg1_Idx + 1;
1520 exit when Arg1_Idx > Arg'Last;
1522 -- Don't allow two or more commas in
1525 if Arg (Arg1_Idx) = ',' then
1526 Arg1_Idx := Arg1_Idx + 1;
1527 if Arg1_Idx > Arg'Last or else
1528 Arg (Arg1_Idx) = ','
1532 "Malformed Parameter: " &
1534 Put (Standard_Error, "usage: ");
1535 Put_Line (Standard_Error,
1546 -- Reset Output_File_Expected, in case it was True
1548 Output_File_Expected := False;
1550 -- Qualifier argument
1553 Output_File_Expected := False;
1555 -- This code is too heavily nested, should be
1556 -- separated out as separate subprogram ???
1562 Endp : Natural := 0; -- avoid warning!
1567 while SwP < Arg'Last
1568 and then Arg (SwP + 1) /= '='
1573 -- At this point, the switch name is in
1574 -- Arg (Arg'First..SwP) and if that is not the
1575 -- whole switch, then there is an equal sign at
1576 -- Arg (SwP + 1) and the rest of Arg is what comes
1577 -- after the equal sign.
1579 -- If make commands are active, see if we have
1580 -- another COMMANDS_TRANSLATION switch belonging
1583 if Make_Commands_Active /= null then
1586 (Arg (Arg'First .. SwP),
1591 and then Sw.Translation = T_Commands
1598 (Arg (Arg'First .. SwP),
1599 Make_Commands_Active.Switches,
1603 -- For case of GNAT MAKE or CHOP, if we cannot
1604 -- find the switch, then see if it is a
1605 -- recognized compiler switch instead, and if
1606 -- so process the compiler switch.
1608 elsif Command.Name.all = "MAKE"
1609 or else Command.Name.all = "CHOP" then
1612 (Arg (Arg'First .. SwP),
1619 (Arg (Arg'First .. SwP),
1621 ("COMPILE", Commands).Switches,
1625 -- For all other cases, just search the relevant
1631 (Arg (Arg'First .. SwP),
1637 case Sw.Translation is
1640 Place_Unix_Switches (Sw.Unix_String);
1642 and then Arg (SwP + 1) = '='
1644 Put (Standard_Error,
1645 "qualifier options ignored: ");
1646 Put_Line (Standard_Error, Arg.all);
1649 when T_Directories =>
1650 if SwP + 1 > Arg'Last then
1651 Put (Standard_Error,
1652 "missing directories for: ");
1653 Put_Line (Standard_Error, Arg.all);
1654 Errors := Errors + 1;
1656 elsif Arg (SwP + 2) /= '(' then
1660 elsif Arg (Arg'Last) /= ')' then
1662 -- Remove spaces from a comma separated
1663 -- list of file names and adjust
1664 -- control variables accordingly.
1666 if Arg_Num < Argument_Count and then
1667 (Argv (Argv'Last) = ',' xor
1668 Argument (Arg_Num + 1)
1669 (Argument (Arg_Num + 1)'First) = ',')
1672 new String'(Argv
.all
1675 Arg_Num
:= Arg_Num
+ 1;
1676 Arg_Idx
:= Argv
'First;
1678 Get_Arg_End
(Argv
.all, Arg_Idx
);
1680 (Argv (Arg_Idx .. Next_Arg_Idx));
1681 goto Tryagain_After_Coalesce;
1684 Put (Standard_Error,
1685 "incorrectly parenthesized " &
1686 "or malformed argument: ");
1687 Put_Line (Standard_Error, Arg.all);
1688 Errors := Errors + 1;
1692 Endp := Arg'Last - 1;
1695 while SwP <= Endp loop
1697 Dir_Is_Wild : Boolean := False;
1698 Dir_Maybe_Is_Wild : Boolean := False;
1700 Dir_List : String_Access_List_Access;
1706 and then Arg (P2 + 1) /= ','
1708 -- A wildcard directory spec on
1709 -- VMS will contain either * or
1712 if Arg (P2) = '*' then
1713 Dir_Is_Wild := True;
1715 elsif Arg (P2) = '%' then
1716 Dir_Is_Wild := True;
1718 elsif Dir_Maybe_Is_Wild
1719 and then Arg (P2) = '.'
1720 and then Arg (P2 + 1) = '.'
1722 Dir_Is_Wild := True;
1723 Dir_Maybe_Is_Wild := False;
1725 elsif Dir_Maybe_Is_Wild then
1726 Dir_Maybe_Is_Wild := False;
1728 elsif Arg (P2) = '.'
1729 and then Arg (P2 + 1) = '.'
1731 Dir_Maybe_Is_Wild := True;
1740 To_Canonical_File_List
1741 (Arg (SwP .. P2), True);
1743 for J in Dir_List.all'Range loop
1747 (Dir_List.all (J).all);
1754 (To_Canonical_Dir_Spec
1755 (Arg (SwP .. P2), False).all);
1763 if SwP + 1 > Arg'Last then
1764 Put (Standard_Error,
1765 "missing directory for: ");
1766 Put_Line (Standard_Error, Arg.all);
1767 Errors := Errors + 1;
1770 Place_Unix_Switches (Sw.Unix_String);
1772 -- Some switches end in "=". No space
1776 (Sw.Unix_String'Last) /= '='
1782 (To_Canonical_Dir_Spec
1783 (Arg (SwP + 2 .. Arg'Last),
1787 when T_File | T_No_Space_File =>
1788 if SwP + 1 > Arg'Last then
1789 Put (Standard_Error,
1790 "missing file for: ");
1791 Put_Line (Standard_Error, Arg.all);
1792 Errors := Errors + 1;
1795 Place_Unix_Switches (Sw.Unix_String);
1797 -- Some switches end in "=". No space
1800 if Sw.Translation = T_File
1801 and then Sw.Unix_String
1802 (Sw.Unix_String'Last) /= '='
1808 (To_Canonical_File_Spec
1809 (Arg (SwP + 2 .. Arg'Last)).all);
1813 if OK_Integer (Arg (SwP + 2 .. Arg'Last)) then
1814 Place_Unix_Switches (Sw.Unix_String);
1815 Place (Arg (SwP + 2 .. Arg'Last));
1818 Put (Standard_Error, "argument for ");
1819 Put (Standard_Error, Sw.Name.all);
1821 (Standard_Error, " must be numeric");
1822 Errors := Errors + 1;
1825 when T_Alphanumplus =>
1826 if OK_Alphanumerplus
1827 (Arg (SwP + 2 .. Arg'Last))
1829 Place_Unix_Switches (Sw.Unix_String);
1830 Place (Arg (SwP + 2 .. Arg'Last));
1833 Put (Standard_Error, "argument for ");
1834 Put (Standard_Error, Sw.Name.all);
1835 Put_Line (Standard_Error,
1836 " must be alphanumeric");
1837 Errors := Errors + 1;
1842 -- A String value must be extended to the
1843 -- end of the Argv, otherwise strings like
1844 -- "foo/bar" get split at the slash.
1846 -- The begining and ending of the string
1847 -- are flagged with embedded nulls which
1848 -- are removed when building the Spawn
1849 -- call. Nulls are use because they won't
1850 -- show up in a /? output. Quotes aren't
1851 -- used because that would make it
1852 -- difficult to embed them.
1854 Place_Unix_Switches (Sw.Unix_String);
1856 if Next_Arg_Idx /= Argv'Last then
1857 Next_Arg_Idx := Argv'Last;
1859 (Argv
(Arg_Idx
.. Next_Arg_Idx
));
1862 while SwP
< Arg
'Last and then
1863 Arg
(SwP
+ 1) /= '=' loop
1869 Place
(Arg
(SwP
+ 2 .. Arg
'Last));
1874 -- Output -largs/-bargs/-cargs
1877 Place
(Sw
.Unix_String
1878 (Sw
.Unix_String
'First ..
1879 Sw
.Unix_String
'First + 5));
1882 (Sw
.Unix_String
'First + 7 ..
1883 Sw
.Unix_String
'Last) = "MAKE"
1885 Make_Commands_Active
:= null;
1888 -- Set source of new commands, also
1889 -- setting this non-null indicates that
1890 -- we are in the special commands mode
1891 -- for processing the -xargs case.
1893 Make_Commands_Active
:=
1896 (Sw
.Unix_String
'First + 7 ..
1897 Sw
.Unix_String
'Last),
1902 if SwP
+ 1 > Arg
'Last then
1904 (Sw
.Options
.Unix_String
);
1907 elsif Arg
(SwP
+ 2) /= '(' then
1911 elsif Arg
(Arg
'Last) /= ')' then
1912 Put
(Standard_Error
,
1913 "incorrectly parenthesized argument: ");
1914 Put_Line
(Standard_Error
, Arg
.all);
1915 Errors
:= Errors
+ 1;
1920 Endp
:= Arg
'Last - 1;
1923 while SwP
<= Endp
loop
1927 and then Arg
(P2
+ 1) /= ','
1932 -- Option name is in Arg (SwP .. P2)
1934 Opt
:= Matching_Name
(Arg
(SwP
.. P2
),
1947 (new String'(Sw.Unix_String.all &
1955 Arg_Idx := Next_Arg_Idx + 1;
1958 exit when Arg_Idx > Argv'Last;
1962 if not Is_Open (Arg_File) then
1963 Arg_Num := Arg_Num + 1;
1965 end Process_Argument;
1967 --------------------------------
1968 -- Validate_Command_Or_Option --
1969 --------------------------------
1971 procedure Validate_Command_Or_Option (N : VMS_Data.String_Ptr) is
1973 pragma Assert (N'Length > 0);
1975 for J in N'Range loop
1977 pragma Assert (N (J - 1) /= '_
');
1980 pragma Assert (Is_Upper (N (J)) or else Is_Digit (N (J)));
1984 end Validate_Command_Or_Option;
1986 --------------------------
1987 -- Validate_Unix_Switch --
1988 --------------------------
1990 procedure Validate_Unix_Switch (S : VMS_Data.String_Ptr) is
1992 if S (S'First) = '`
' then
1996 pragma Assert (S (S'First) = '-' or else S (S'First) = '!');
1998 for J in S'First + 1 .. S'Last loop
1999 pragma Assert (S (J) /= ' ');
2002 pragma Assert (S (J - 1) = ',' and then S (J + 1) = '-');
2006 end Validate_Unix_Switch;
2008 --------------------
2009 -- VMS_Conversion --
2010 --------------------
2012 procedure VMS_Conversion (The_Command : out Command_Type) is
2013 Result : Command_Type := Undefined;
2014 Result_Set : Boolean := False;
2018 -- First we must preprocess the string form of the command and options
2019 -- list into the internal form that we use.
2021 Preprocess_Command_Data;
2023 -- If no parameters, give complete list of commands
2025 if Argument_Count = 0 then
2028 Put_Line ("List of available commands");
2031 while Commands /= null loop
2032 Put (Commands.Usage.all);
2034 Put_Line (Commands.Unix_String.all);
2035 Commands := Commands.Next;
2043 -- Loop through arguments
2045 while Arg_Num <= Argument_Count loop
2046 Process_Argument (Result);
2048 if not Result_Set then
2049 The_Command := Result;
2054 -- Gross error checking that the number of parameters is correct.
2055 -- Not applicable to Unlimited_Files parameters.
2057 if (Param_Count = Command.Params'Length - 1
2058 and then Command.Params (Param_Count + 1) = Unlimited_Files)
2059 or else Param_Count <= Command.Params'Length
2064 Put_Line (Standard_Error,
2065 "Parameter count of "
2066 & Integer'Image (Param_Count)
2067 & " not equal to expected "
2068 & Integer'Image (Command.Params'Length));
2069 Put (Standard_Error, "usage: ");
2070 Put_Line (Standard_Error, Command.Usage.all);
2071 Errors := Errors + 1;
2077 -- Prepare arguments for a call to spawn, filtering out
2078 -- embedded nulls place there to delineate strings.
2082 Inside_Nul : Boolean := False;
2083 Arg : String (1 .. 1024);
2089 while P1 <= Buffer.Last and then Buffer.Table (P1) = ' ' loop
2094 Arg (Arg_Ctr) := Buffer.Table (P1);
2096 while P1 <= Buffer.Last loop
2098 if Buffer.Table (P1) = ASCII.NUL then
2100 Inside_Nul := False;
2106 if Buffer.Table (P1) = ' ' and then not Inside_Nul then
2108 Arg_Ctr := Arg_Ctr + 1;
2109 Arg (Arg_Ctr) := Buffer.Table (P1);
2112 Last_Switches.Increment_Last;
2115 while P2 < Buffer.Last
2116 and then (Buffer.Table (P2 + 1) /= ' ' or else
2120 Arg_Ctr := Arg_Ctr + 1;
2121 Arg (Arg_Ctr) := Buffer.Table (P2);
2122 if Buffer.Table (P2) = ASCII.NUL then
2123 Arg_Ctr := Arg_Ctr - 1;
2125 Inside_Nul := False;
2132 Last_Switches.Table (Last_Switches.Last) :=
2133 new String'(String (Arg
(1 .. Arg_Ctr
)));
2136 Arg
(Arg_Ctr
) := Buffer
.Table
(P1
);