1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Ada.Characters.Handling; use Ada.Characters.Handling;
30 with Ada.Command_Line; use Ada.Command_Line;
33 with System.IO; use System.IO;
36 pragma Ident (Gnatvsn.Gnat_Version_String);
40 Exit_Program : exception;
42 function Get_Maximum_File_Name_Length return Integer;
43 pragma Import (C, Get_Maximum_File_Name_Length,
44 "__gnat_get_maximum_file_name_length");
47 Count := Argument_Count;
49 if Count < 1 or else Count > 2 then
50 Put_Line ("Usage: gnatkr filename[.extension] [krunch-count]");
54 -- If the length (krunch-count) argument is omitted use the system
55 -- default if there is one, otherwise use 8.
58 Maxlen := Get_Maximum_File_Name_Length;
67 for J in Argument (2)'Range loop
68 if Argument (2) (J) /= ' ' then
69 if Argument (2) (J) not in '0' .. '9' then
70 Put_Line ("Illegal argument for krunch-count");
73 Maxlen := Maxlen * 10 +
74 Character'Pos (Argument (2) (J)) - Character'Pos ('0');
79 -- Zero means crunch only system files
82 Maxlen := Natural'Last;
88 Fname : String := Argument (1);
89 Klen : Natural := Fname'Length;
91 Extp : Boolean := False;
92 -- True if extension is present
95 -- If extension is present, points to it (init to prevent warning)
98 -- Remove .adb or .ads extension if present (recognized only if the
99 -- name is all lower case and contains no other instances of dots)
102 and then Fname (Klen - 3 .. Klen - 1) = ".ad"
103 and then (Fname (Klen) = 's' or else Fname (Klen) = 'b')
107 for J in 1 .. Klen - 4 loop
108 if Is_Upper (Fname (J)) or else Fname (J) = '.' then
122 -- Fold to lower case and replace dots by dashes
124 for J in 1 .. Klen loop
125 Fname (J) := To_Lower (Fname (J));
127 if Fname (J) = '.' then
132 Krunch (Fname, Klen, Maxlen, False);
134 Put (Fname (1 .. Klen));
137 Put (Fname (Ext .. Fname'Length));
144 Set_Exit_Status (Success);
148 Set_Exit_Status (Failure);