text
stringlengths
0
234
for J in reverse 1 .. Name.Len loop
if Name.Name (J) = '.' then
if J = Name.Len then
-- Take care of names ending with a '.' (e.g. no extension,
-- the final '.' is part of the basename)
Last := J;
Ext := (others => ' ');
else
Last := J - 1;
S_Idx := Ext'First;
for K in J + 1 .. Name.Len loop
Ext (S_Idx) := To_Upper (Name.Name (K));
S_Idx := S_Idx + 1;
-- In case the extension is more than 3 characters, we
-- keep the first 3 ones.
exit when S_Idx > Ext'Last;
end loop;
end if;
exit;
end if;
end loop;
S_Idx := 0;
SName := (others => ' ');
for J in 1 .. Last loop
exit when Add_Tilde and then S_Idx >= 6;
exit when not Add_Tilde and then S_Idx = 8;
if Name.Name (J) in 'a' .. 'z' then
S_Idx := S_Idx + 1;
SName (S_Idx) := To_Upper (Name.Name (J));
elsif Is_Legal_Character (Name.Name (J)) then
S_Idx := S_Idx + 1;
SName (S_Idx) := Name.Name (J);
elsif Name.Name (J) = '.'
or else Name.Name (J) = ' '
then
-- dots that are not used as extension delimiters are invalid
-- in FAT short names and ignored in long names to short names
-- translation
Add_Tilde := True;
else
-- Any other character is translated as '_'
Add_Tilde := True;
S_Idx := S_Idx + 1;
SName (S_Idx) := '_';
end if;
end loop;
if Add_Tilde then
if S_Idx >= 6 then
SName (7 .. 8) := "~1";
else
SName (S_Idx + 1 .. S_Idx + 2) := "~1";
end if;
end if;
end To_Short_Name;
---------------
-- Inc_SName --
---------------
procedure Inc_SName (SName : in out String)
is
Idx : Natural := 0;
Num : Natural := 0;
begin
for J in reverse SName'Range loop
if Idx = 0 then
if SName (J) = ' ' then
null;
elsif SName (J) in '0' .. '9' then
Idx := J;
else
SName (SName'Last - 1 .. SName'Last) := "~1";
return;
end if;
elsif SName (J) in '0' .. '9' then
Idx := J;
elsif SName (J) = '~' then
Num := Value (SName (Idx .. SName'Last)) + 1;
-- make Idx point to '~'
Idx := J;
declare
N_Suffix : String := Natural'Image (Num);
begin
N_Suffix (N_Suffix'First) := '~';
if Idx + N_Suffix'Length - 1 > SName'Last then