Implement -mmemcpy-strategy= and -mmemset-strategy= options
[official-gcc.git] / gcc / ada / gnatkr.adb
blob1df692e7b4d6049857bf1b87f1d8a168dfda683e
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T K R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Ada.Characters.Handling; use Ada.Characters.Handling;
27 with Ada.Command_Line; use Ada.Command_Line;
28 with Gnatvsn;
29 with Krunch;
30 with System.IO; use System.IO;
32 procedure Gnatkr is
33 pragma Ident (Gnatvsn.Gnat_Static_Version_String);
35 Count : Natural;
36 Maxlen : Integer;
37 Exit_Program : exception;
39 function Get_Maximum_File_Name_Length return Integer;
40 pragma Import (C, Get_Maximum_File_Name_Length,
41 "__gnat_get_maximum_file_name_length");
43 begin
44 Count := Argument_Count;
46 if Count < 1 or else Count > 2 then
47 Put_Line ("Usage: gnatkr filename[.extension] [krunch-count]");
48 raise Exit_Program;
50 else
51 -- If the length (krunch-count) argument is omitted use the system
52 -- default if there is one, otherwise use 8.
54 if Count = 1 then
55 Maxlen := Get_Maximum_File_Name_Length;
57 if Maxlen = -1 then
58 Maxlen := 8;
59 end if;
61 else
62 Maxlen := 0;
64 for J in Argument (2)'Range loop
65 if Argument (2) (J) /= ' ' then
66 if Argument (2) (J) not in '0' .. '9' then
67 Put_Line ("Illegal argument for krunch-count");
68 raise Exit_Program;
69 else
70 Maxlen := Maxlen * 10 +
71 Character'Pos (Argument (2) (J)) - Character'Pos ('0');
72 end if;
73 end if;
74 end loop;
76 -- Zero means crunch only system files
78 if Maxlen = 0 then
79 Maxlen := Natural'Last;
80 end if;
82 end if;
84 declare
85 Fname : String := Argument (1);
86 Klen : Natural := Fname'Length;
88 Extp : Boolean := False;
89 -- True if extension is present
91 Ext : Natural := 0;
92 -- If extension is present, points to it (init to prevent warning)
94 begin
95 -- Remove extension if present (an extension is defined as the
96 -- section of the file name after the last dot in the name. If
97 -- there is no dot in the name, then
98 -- name is all lower case and contains no other instances of dots)
100 for J in reverse 1 .. Klen loop
101 if Fname (J) = '.' then
102 Extp := True;
103 Ext := J;
104 Klen := J - 1;
105 exit;
106 end if;
107 end loop;
109 -- Fold to lower case and replace dots by dashes
111 for J in 1 .. Klen loop
112 Fname (J) := To_Lower (Fname (J));
114 if Fname (J) = '.' then
115 Fname (J) := '-';
116 end if;
117 end loop;
119 Krunch (Fname, Klen, Maxlen, False);
121 Put (Fname (1 .. Klen));
123 if Extp then
124 Put (Fname (Ext .. Fname'Length));
125 end if;
127 New_Line;
128 end;
129 end if;
131 Set_Exit_Status (Success);
133 exception
134 when Exit_Program =>
135 Set_Exit_Status (Failure);
137 end Gnatkr;