PR c++/3637
[official-gcc.git] / gcc / ada / krunch.ads
blob54877bce5a708a4c0dbceaa2ca8f7dafc4be03eb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- K R U N C H --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.13 $ --
10 -- --
11 -- Copyright (C) 1992-1997 Free Software Foundation, Inc. --
12 -- --
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. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This procedure implements file name crunching
38 -- First, the name is divided into segments separated by minus signs and
39 -- underscores, then all minus signs and underscores are eliminated. If
40 -- this leaves the name short enough, we are done.
42 -- If not, then the longest segment is located (left-most if there are
43 -- two of equal length), and shortened by dropping its last character.
44 -- This is repeated until the name is short enough.
46 -- As an example, consider the krunch of our-strings-wide_fixed.adb
47 -- to fit the name into 8 characters as required by DOS:
49 -- our-strings-wide_fixed 22
50 -- our strings wide fixed 19
51 -- our string wide fixed 18
52 -- our strin wide fixed 17
53 -- our stri wide fixed 16
54 -- our stri wide fixe 15
55 -- our str wide fixe 14
56 -- our str wid fixe 13
57 -- our str wid fix 12
58 -- ou str wid fix 11
59 -- ou st wid fix 10
60 -- ou st wi fix 9
61 -- ou st wi fi 8
63 -- Final file name: OUSTWIFX.ADB
65 -- A special rule applies for children of System, Ada, Gnat, and Interfaces.
66 -- In these cases, the following special prefix replacements occur:
68 -- ada- replaced by a-
69 -- gnat- replaced by g-
70 -- interfaces- replaced by i-
71 -- system- replaced by s-
73 -- The rest of the name is krunched in the usual manner described above.
74 -- In addition, these names, as well as the names of the renamed packages
75 -- from the obsolescent features annex, are always krunched to 8 characters
76 -- regardless of the setting of Maxlen.
78 -- As an example of this special rule, consider ada-strings-wide_fixed.adb
79 -- which gets krunched as follows:
81 -- ada-strings-wide_fixed 22
82 -- a- strings wide fixed 18
83 -- a- string wide fixed 17
84 -- a- strin wide fixed 16
85 -- a- stri wide fixed 15
86 -- a- stri wide fixe 14
87 -- a- str wide fixe 13
88 -- a- str wid fixe 12
89 -- a- str wid fix 11
90 -- a- st wid fix 10
91 -- a- st wi fix 9
92 -- a- st wi fi 8
94 -- Final file name: A-STWIFX.ADB
96 -- Since children of units named A, G, I or S might conflict with the names
97 -- of predefined units, the naming rule in that case is that the first hyphen
98 -- is replaced by a tilde sign.
100 -- Note: as described below, this special treatment of predefined library
101 -- unit file names can be inhibited by setting the No_Predef flag.
103 -- Of course there is no guarantee that this algorithm results in uniquely
104 -- crunched names (nor, obviously, is there any algorithm which would do so)
105 -- In fact we run into such a case in the standard library routines with
106 -- children of Wide_Text_IO, so a special rule is applied to deal with this
107 -- clash, namely the prefix ada-wide_text_io- is replaced by a-wt- and then
108 -- the normal crunching rules are applied, so that for example, the unit:
110 -- Ada.Wide_Text_IO.Float_IO
112 -- has the file name
114 -- a-wtflio
116 -- This is the only irregularity required (so far!) to keep the file names
117 -- unique in the standard predefined libraries.
119 procedure Krunch
120 (Buffer : in out String;
121 Len : in out Natural;
122 Maxlen : Natural;
123 No_Predef : Boolean);
124 pragma Elaborate_Body (Krunch);
125 -- The full file name is stored in Buffer (1 .. Len) on entry. The file
126 -- name is crunched in place and on return Len is updated, so that the
127 -- resulting krunched name is in Buffer (1 .. Len) where Len <= Maxlen.
128 -- Note that Len may be less than or equal to Maxlen on entry, in which
129 -- case it may be possible that Krunch does not modify Buffer. The fourth
130 -- parameter, No_Predef, is a switch which, if set to True, disables the
131 -- normal special treatment of predefined library unit file names.
133 -- Note: the string Buffer must have a lower bound of 1, and may not
134 -- contain any blanks (in particular, it must not have leading blanks).