program x;

const drives : set of char = ['A','B','P'];

label exit;
var buf : string [80];
    i,j : integer;
    name : array [1..8] of char;
    ext  : array [1..3] of char;
    lf   : integer;
    dp,pkt :integer;

begin
for i := 1 to 8 do name [i] := '?';
for i := 1 to 3 do ext [i] := '?';
write ( 'dir mask : ' );
read ( buf );
dp  := 0;
pkt := length ( buf ) + 1;
if length ( buf ) = 0
then begin
     lf := bdos ( 25 ) + 97;
     write ( chr ( lf ) , ':*.*' );
     end
else begin
{ grossbuchstaben }
     for i := 1 to length ( buf ) do
         buf [i] := upcase ( buf [i] );

{ laufwerk }
     for i := length ( buf ) downto 1 do
         if buf [i] = ':' then dp := i;
     case dp of
     0  : lf := bdos ( 25 ) + 97;
     1  : begin
          write ( 'FALSCHES FORMAT' );
          {falschein;}
          goto exit;
          end;
     else if buf [dp-1] in drives
          then begin
               lf := ord ( buf [dp-1] ) - 65;
               bdos ( 14 , lf );
               end
          else begin
               write ( 'KEIN LAUFWERK' );
               goto exit;
               end;
          end;
{ ext oder nicht }
     for i := length ( buf ) downto dp + 1 do
         if buf [i] = '.' then pkt := i;

{ name }
     if dp <> length ( buf )
     then begin
          i := 0;
          repeat i := i + 1;
                 name [i] := buf [i+dp];
          until ( i = 8 ) or ( i + dp = pkt - 1 ) or ( name [i] = '*' );
          if name [i] <> '*'
          then for i := i + 1 to 8 do
                   name [i] := ' ';
          if name [i] = '*'
          then name [i] := '?';
          end
     else write ( '*' );
{ ext }
     if pkt < length ( buf )
     then begin
          i := 0;
          repeat i := i + 1;
                 ext [i] := buf [i+pkt];
          until ( i = 3 ) or ( i + pkt = length ( buf )) or ( ext [i] = '*' );
          if ext [i] <> '*'
          then for i := i + 1 to 3 do
                   ext [i] := ' ';
          if ext [i] = '*'
          then ext [i] := '?';
          end
     else begin
          if pkt = length ( buf )
          then write ('*')
          else write ( '.*');
          end;
     end;
exit:
writeln;
writeln('len  = ',length(buf));
writeln('dp   = ',dp);
writeln('pkt  = ',pkt);
writeln('name : "',name,'"');
writeln('ext  : "',ext ,'"');
end.