home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Gadgets 1
/
ADE-1.bin
/
ade-dist
/
gnat-2.06-src.tgz
/
tar.out
/
fsf
/
gnat
/
ada
/
krunch.adb
< prev
next >
Wrap
Text File
|
1996-09-28
|
7KB
|
198 lines
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- K R U N C H --
-- --
-- B o d y --
-- --
-- $Revision: 1.10 $ --
-- --
-- Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved --
-- --
-- The GNAT library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU Library General Public License as published by --
-- the Free Software Foundation; either version 2, or (at your option) any --
-- later version. The GNAT library is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Library General Public License for more details. You should have --
-- received a copy of the GNU Library General Public License along with --
-- the GNAT library; see the file COPYING.LIB. If not, write to the Free --
-- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
procedure Krunch
(Buffer : in out String;
Len : in out Natural;
Maxlen : Natural;
No_Predef : Boolean)
is
Curlen : Natural;
Krlen : Natural;
Num_Seps : Natural;
Startloc : Natural;
begin
-- Deal with special predefined children cases. Startloc is the first
-- location for the krunch, set to 1, except for the predefined children
-- case, where it is set to 3, to start after the standard prefix.
if No_Predef then
Startloc := 1;
Curlen := Len;
Krlen := Maxlen;
elsif Len >= 26
and then Buffer (1 .. 25) = "ada-text_io-wide_text_io-"
then
Startloc := 3;
Buffer (2 .. 5) := "-wt-";
Buffer (6 .. Len - 20) := Buffer (26 .. Len);
Curlen := Len - 20;
Krlen := 8;
elsif Len >= 4 and then Buffer (1 .. 4) = "ada-" then
Startloc := 3;
Buffer (2 .. Len - 2) := Buffer (4 .. Len);
Curlen := Len - 2;
Krlen := 8;
elsif Len >= 5 and then Buffer (1 .. 5) = "gnat-" then
Startloc := 3;
Buffer (2 .. Len - 3) := Buffer (5 .. Len);
Curlen := Len - 3;
Krlen := 8;
elsif Len >= 7 and then Buffer (1 .. 7) = "system-" then
Startloc := 3;
Buffer (2 .. Len - 5) := Buffer (7 .. Len);
Curlen := Len - 5;
Krlen := 8;
elsif Len >= 11 and then Buffer (1 .. 11) = "interfaces-" then
Startloc := 3;
Buffer (2 .. Len - 9) := Buffer (11 .. Len);
Curlen := Len - 9;
Krlen := 8;
-- For the renamings in the obsolescent section, we also force krunching
-- to 8 characters, but no other special processing is required here.
-- Note that text_io and calendar are already short enough anyway.
elsif (Len = 9 and then Buffer (1 .. 9) = "direct_io")
or else (Len = 10 and then Buffer (1 .. 10) = "interfaces")
or else (Len = 13 and then Buffer (1 .. 13) = "io_exceptions")
or else (Len = 12 and then Buffer (1 .. 12) = "machine_code")
or else (Len = 13 and then Buffer (1 .. 13) = "sequential_io")
or else (Len = 20 and then Buffer (1 .. 20) = "unchecked_conversion")
or else (Len = 22 and then Buffer (1 .. 22) = "unchecked_deallocation")
then
Startloc := 1;
Krlen := 8;
Curlen := Len;
-- Special case of a child unit whose parent unit is a single letter. In
-- order to prevent confusion with krunched names of predefined units use
-- a plus rather than a minus as the second character of the file name.
elsif Len > 1 and then Buffer (2) = '-' and then Len <= Maxlen then
Buffer (2) := '+';
return;
-- Normal case, not a predefined file
else
Startloc := 1;
Curlen := Len;
Krlen := Maxlen;
end if;
-- Immediate return if file name is short enough now
if Curlen <= Krlen then
Len := Curlen;
return;
end if;
-- For now, refuse to krunch a name that contains an ESC character (wide
-- character sequence) since it's too much trouble to do this right ???
for J in 1 .. Curlen loop
if Buffer (J) = Ascii.ESC then
return;
end if;
end loop;
-- Count number of separators (minus signs and underscores) and for now
-- replace them by spaces. We keep them around till the end to control
-- the krunching process, and then we eliminate them as the last step
Num_Seps := 0;
for J in Startloc .. Curlen loop
if Buffer (J) = '-' or else Buffer (J) = '_' then
Buffer (J) := ' ';
Num_Seps := Num_Seps + 1;
end if;
end loop;
-- Now we do the one character at a time krunch till we are short enough
while Curlen - Num_Seps > Krlen loop
declare
Long_Length : Natural := 0;
Long_Last : Natural := 0;
Piece_Start : Natural;
Ptr : Natural;
begin
Ptr := Startloc;
-- Loop through pieces to find longest piece
while Ptr <= Curlen loop
Piece_Start := Ptr;
-- Loop through characters in one piece of name
while Ptr <= Curlen and then Buffer (Ptr) /= ' ' loop
Ptr := Ptr + 1;
end loop;
if Ptr - Piece_Start > Long_Length then
Long_Length := Ptr - Piece_Start;
Long_Last := Ptr - 1;
end if;
Ptr := Ptr + 1;
end loop;
-- Remove last character of longest piece
if Long_Last < Curlen then
Buffer (Long_Last .. Curlen - 1) :=
Buffer (Long_Last + 1 .. Curlen);
end if;
Curlen := Curlen - 1;
end;
end loop;
-- Final step, remove the spaces
Len := 0;
for J in 1 .. Curlen loop
if Buffer (J) /= ' ' then
Len := Len + 1;
Buffer (Len) := Buffer (J);
end if;
end loop;
return;
end Krunch;