1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This procedure implements file name crunching
36 -- First, the name is divided into segments separated by minus signs and
37 -- underscores, then all minus signs and underscores are eliminated. If
38 -- this leaves the name short enough, we are done.
40 -- If not, then the longest segment is located (left-most if there are
41 -- two of equal length), and shortened by dropping its last character.
42 -- This is repeated until the name is short enough.
44 -- As an example, consider the krunch of our-strings-wide_fixed.adb
45 -- to fit the name into 8 characters as required by DOS:
47 -- our-strings-wide_fixed 22
48 -- our strings wide fixed 19
49 -- our string wide fixed 18
50 -- our strin wide fixed 17
51 -- our stri wide fixed 16
52 -- our stri wide fixe 15
53 -- our str wide fixe 14
54 -- our str wid fixe 13
61 -- Final file name: OUSTWIFX.ADB
63 -- A special rule applies for children of System, Ada, Gnat, and Interfaces.
64 -- In these cases, the following special prefix replacements occur:
66 -- ada- replaced by a-
67 -- gnat- replaced by g-
68 -- interfaces- replaced by i-
69 -- system- replaced by s-
71 -- The rest of the name is krunched in the usual manner described above.
72 -- In addition, these names, as well as the names of the renamed packages
73 -- from the obsolescent features annex, are always krunched to 8 characters
74 -- regardless of the setting of Maxlen.
76 -- As an example of this special rule, consider ada-strings-wide_fixed.adb
77 -- which gets krunched as follows:
79 -- ada-strings-wide_fixed 22
80 -- a- strings wide fixed 18
81 -- a- string wide fixed 17
82 -- a- strin wide fixed 16
83 -- a- stri wide fixed 15
84 -- a- stri wide fixe 14
85 -- a- str wide fixe 13
92 -- Final file name: A-STWIFX.ADB
94 -- Since children of units named A, G, I or S might conflict with the names
95 -- of predefined units, the naming rule in that case is that the first hyphen
96 -- is replaced by a tilde sign.
98 -- Note: as described below, this special treatment of predefined library
99 -- unit file names can be inhibited by setting the No_Predef flag.
101 -- Of course there is no guarantee that this algorithm results in uniquely
102 -- crunched names (nor, obviously, is there any algorithm which would do so)
103 -- In fact we run into such a case in the standard library routines with
104 -- children of Wide_Text_IO, so a special rule is applied to deal with this
105 -- clash, namely the prefix ada-wide_text_io- is replaced by a-wt- and then
106 -- the normal crunching rules are applied, so that for example, the unit:
108 -- Ada.Wide_Text_IO.Float_IO
114 -- More problems arise with Wide_Wide, so we replace this sequence by
115 -- a z (which is not used much) and also (as in the Wide_Text_IO case),
116 -- we replace the prefix ada.wide_wide_text_io- by a-zt- and then
117 -- the normal crunching rules are applied.
119 -- These are the only irregularity required (so far!) to keep the file names
120 -- unique in the standard predefined libraries.
123 (Buffer
: in out String;
124 Len
: in out Natural;
126 No_Predef
: Boolean);
127 pragma Elaborate_Body
(Krunch
);
128 -- The full file name is stored in Buffer (1 .. Len) on entry. The file
129 -- name is crunched in place and on return Len is updated, so that the
130 -- resulting krunched name is in Buffer (1 .. Len) where Len <= Maxlen.
131 -- Note that Len may be less than or equal to Maxlen on entry, in which
132 -- case it may be possible that Krunch does not modify Buffer. The fourth
133 -- parameter, No_Predef, is a switch which, if set to True, disables the
134 -- normal special treatment of predefined library unit file names.
136 -- Note: the string Buffer must have a lower bound of 1, and may not
137 -- contain any blanks (in particular, it must not have leading blanks).