OSDN Git Service

Fix copyright problems reported by Doug Evans.
[pf3gnuchains/gcc-fork.git] / gcc / ada / gnatkr.adb
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-2001 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 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.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Ada.Characters.Handling; use Ada.Characters.Handling;
28 with Ada.Command_Line;        use Ada.Command_Line;
29 with Krunch;
30 with System.IO; use System.IO;
31
32 procedure Gnatkr is
33
34    Count        : Natural;
35    Maxlen       : Integer;
36    Exit_Program : exception;
37
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");
41
42 begin
43    Count := Argument_Count;
44
45    if Count < 1 or else Count > 2 then
46       Put_Line ("Usage: gnatkr  filename[.extension]  [krunch-count]");
47       raise Exit_Program;
48
49    else
50       --  If the length (krunch-count) argument is omitted use the system
51       --  default if there is one, otherwise use 8.
52
53       if Count = 1 then
54          Maxlen := Get_Maximum_File_Name_Length;
55
56          if Maxlen = -1 then
57             Maxlen := 8;
58          end if;
59
60       else
61          Maxlen := 0;
62
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");
67                   raise Exit_Program;
68                else
69                   Maxlen := Maxlen * 10 +
70                     Character'Pos (Argument (2) (J)) - Character'Pos ('0');
71                end if;
72             end if;
73          end loop;
74
75          --  Zero means crunch only system files
76
77          if Maxlen = 0 then
78             Maxlen := Natural'Last;
79          end if;
80
81       end if;
82
83       declare
84          Fname : String  := Argument (1);
85          Klen  : Natural := Fname'Length;
86
87          Extp : Boolean := False;
88          --  True if extension is present
89
90          Ext : Natural := 0;
91          --  If extension is present, points to it (init to prevent warning)
92
93       begin
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)
96
97          if Klen > 4
98            and then Fname (Klen - 3 .. Klen - 1) = ".ad"
99            and then (Fname (Klen) = 's' or else Fname (Klen) = 'b')
100          then
101             Extp := True;
102
103             for J in 1 .. Klen - 4 loop
104                if Is_Upper (Fname (J)) or else Fname (J) = '.' then
105                   Extp := False;
106                end if;
107             end loop;
108
109             if Extp then
110                Klen := Klen - 4;
111                Ext := Klen + 1;
112             end if;
113
114          else
115             Extp := False;
116          end if;
117
118          --  Fold to lower case and replace dots by dashes
119
120          for J in 1 .. Klen loop
121             Fname (J) := To_Lower (Fname (J));
122
123             if Fname (J) = '.' then
124                Fname (J) := '-';
125             end if;
126          end loop;
127
128          Krunch (Fname, Klen, Maxlen, False);
129
130          Put (Fname (1 .. Klen));
131
132          if Extp then
133             Put (Fname (Ext .. Fname'Length));
134          end if;
135
136          New_Line;
137       end;
138    end if;
139
140    Set_Exit_Status (Success);
141
142 exception
143    when Exit_Program =>
144       Set_Exit_Status (Failure);
145
146 end Gnatkr;