OSDN Git Service

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