Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran
program p
implicit none
character(len=:),allocatable :: s
integer                      :: stat,l,i,j,k
 call get_command_argument (0,length=l)
 allocate(character(len=l) :: s)
 call get_command_argument (0,s,status=stat)
 if (stat == 0) then
  i=index(s,'/',back=.true.)
  j=index(s,'\',back=.true.)
  k=max(i,j)
  if(k.ne.0)s=s(k+1:)
  print *, "The program's name is " // trim (s)
 endif
end program p

simplifying assumption is that both / and \ are not allowed in a filename but if present are assumed to delimit the leaf name
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Directories; use Ada.Directories;
S : String := (Simple_Name (Command_Name));

New implementation...
< >
programming-idioms.org