* MAINTAINERS: (Write After Approval): Add myself.
[official-gcc.git] / gcc / ada / gnatkr.adb
blob01ab98bd41409244d23223c0ecb11d1b6529fba7
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T K R --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 with Ada.Characters.Handling; use Ada.Characters.Handling;
29 with Ada.Command_Line; use Ada.Command_Line;
30 with Gnatvsn;
31 with Krunch;
32 with System.IO; use System.IO;
34 procedure Gnatkr is
35 pragma Ident (Gnatvsn.Gnat_Version_String);
37 Count : Natural;
38 Maxlen : Integer;
39 Exit_Program : exception;
41 function Get_Maximum_File_Name_Length return Integer;
42 pragma Import (C, Get_Maximum_File_Name_Length,
43 "__gnat_get_maximum_file_name_length");
45 begin
46 Count := Argument_Count;
48 if Count < 1 or else Count > 2 then
49 Put_Line ("Usage: gnatkr filename[.extension] [krunch-count]");
50 raise Exit_Program;
52 else
53 -- If the length (krunch-count) argument is omitted use the system
54 -- default if there is one, otherwise use 8.
56 if Count = 1 then
57 Maxlen := Get_Maximum_File_Name_Length;
59 if Maxlen = -1 then
60 Maxlen := 8;
61 end if;
63 else
64 Maxlen := 0;
66 for J in Argument (2)'Range loop
67 if Argument (2) (J) /= ' ' then
68 if Argument (2) (J) not in '0' .. '9' then
69 Put_Line ("Illegal argument for krunch-count");
70 raise Exit_Program;
71 else
72 Maxlen := Maxlen * 10 +
73 Character'Pos (Argument (2) (J)) - Character'Pos ('0');
74 end if;
75 end if;
76 end loop;
78 -- Zero means crunch only system files
80 if Maxlen = 0 then
81 Maxlen := Natural'Last;
82 end if;
84 end if;
86 declare
87 Fname : String := Argument (1);
88 Klen : Natural := Fname'Length;
90 Extp : Boolean := False;
91 -- True if extension is present
93 Ext : Natural := 0;
94 -- If extension is present, points to it (init to prevent warning)
96 begin
97 -- Remove .adb or .ads extension if present (recognized only if the
98 -- name is all lower case and contains no other instances of dots)
100 if Klen > 4
101 and then Fname (Klen - 3 .. Klen - 1) = ".ad"
102 and then (Fname (Klen) = 's' or else Fname (Klen) = 'b')
103 then
104 Extp := True;
106 for J in 1 .. Klen - 4 loop
107 if Is_Upper (Fname (J)) or else Fname (J) = '.' then
108 Extp := False;
109 end if;
110 end loop;
112 if Extp then
113 Klen := Klen - 4;
114 Ext := Klen + 1;
115 end if;
117 else
118 Extp := False;
119 end if;
121 -- Fold to lower case and replace dots by dashes
123 for J in 1 .. Klen loop
124 Fname (J) := To_Lower (Fname (J));
126 if Fname (J) = '.' then
127 Fname (J) := '-';
128 end if;
129 end loop;
131 Krunch (Fname, Klen, Maxlen, False);
133 Put (Fname (1 .. Klen));
135 if Extp then
136 Put (Fname (Ext .. Fname'Length));
137 end if;
139 New_Line;
140 end;
141 end if;
143 Set_Exit_Status (Success);
145 exception
146 when Exit_Program =>
147 Set_Exit_Status (Failure);
149 end Gnatkr;