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