1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2001 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 ------------------------------------------------------------------------------
27 with Ada.Characters.Handling; use Ada.Characters.Handling;
28 with Ada.Command_Line; use Ada.Command_Line;
30 with System.IO; use System.IO;
36 Exit_Program : exception;
38 function Get_Maximum_File_Name_Length return Integer;
39 pragma Import (C, Get_Maximum_File_Name_Length,
40 "__gnat_get_maximum_file_name_length");
43 Count := Argument_Count;
45 if Count < 1 or else Count > 2 then
46 Put_Line ("Usage: gnatkr filename[.extension] [krunch-count]");
50 -- If the length (krunch-count) argument is omitted use the system
51 -- default if there is one, otherwise use 8.
54 Maxlen := Get_Maximum_File_Name_Length;
63 for J in Argument (2)'Range loop
64 if Argument (2) (J) /= ' ' then
65 if Argument (2) (J) not in '0' .. '9' then
66 Put_Line ("Illegal argument for krunch-count");
69 Maxlen := Maxlen * 10 +
70 Character'Pos (Argument (2) (J)) - Character'Pos ('0');
75 -- Zero means crunch only system files
78 Maxlen := Natural'Last;
84 Fname : String := Argument (1);
85 Klen : Natural := Fname'Length;
87 Extp : Boolean := False;
88 -- True if extension is present
91 -- If extension is present, points to it (init to prevent warning)
94 -- Remove .adb or .ads extension if present (recognized only if the
95 -- name is all lower case and contains no other instances of dots)
98 and then Fname (Klen - 3 .. Klen - 1) = ".ad"
99 and then (Fname (Klen) = 's' or else Fname (Klen) = 'b')
103 for J in 1 .. Klen - 4 loop
104 if Is_Upper (Fname (J)) or else Fname (J) = '.' then
118 -- Fold to lower case and replace dots by dashes
120 for J in 1 .. Klen loop
121 Fname (J) := To_Lower (Fname (J));
123 if Fname (J) = '.' then
128 Krunch (Fname, Klen, Maxlen, False);
130 Put (Fname (1 .. Klen));
133 Put (Fname (Ext .. Fname'Length));
140 Set_Exit_Status (Success);
144 Set_Exit_Status (Failure);