[UP]


Manual Reference Pages  - path (3)

NAME

path(3f) - [M_path] OOP interface for a GNU Linux or Unix pathname (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

type path

      ! COMPONENTS:
      character(len=:),allocatable :: name
contains

      ! METHODS:
      procedure    :: branch
      procedure    :: leaf
      procedure    :: stem
      procedure    :: bud
      procedure    :: init
      procedure    :: is_dir
      procedure    :: stat
      procedure    :: readable
      procedure    :: writable
      procedure    :: executable
      procedure    :: exists
      procedure    :: realpath
      procedure    :: splitup
      procedure    :: joinup

! OVERLOADED OPERATORS FOR TYPE(path) procedure,private :: eq generic :: operator(==) => eq

end type path

DESCRIPTION

Given a pathname, resolve or expand it into branch/stem.bud and/or branch/leaf, test for file type and access privileges if file exists, and return system statistics.

Assumes directory separator is a slash (’/’) and that filename does not contain trailing spaces.

      /branch/leaf
      /branch/stem.bud

OPTIONS

FILENAME
  pathname

RETURNS

%name name of file
%branch()
  Output FILENAME with its last non-slash component and trailing slashes removed. if FILENAME contains no ’/’ character, output "." (meaning the current directory).
%leaf() Output FILENAME with anything up to and including the right-most slashes removed.
%stem() Output FILENAME leaf with any right-most suffix removed. A suffix is anything from the rightmost period in the filename leaf to the end of the pathname.
%bud() Output FILENAME right-most suffix.
%is_dir()
  a logical specifying if path is currently a directory pathname.
%exists()
  determine if file exists
%readable()
  determine if file is readable
%writable()
  determine if file is writable
%executable()
  determine if file is executable
%stat() an array of integers describing the current status of the file. returns the same data array as the SYSTEM_STAT(3f) function with the difference that the status of the call is element 14.
%realpath()
  resolve the pathname using the Posix C routine realpath(3c)

EXAMPLE

Sample program:

   program demo_path
   use M_path, only   : path
   use M_system, only : system_getpwuid, system_getgrgid
   use M_time,   only : fmtdate, u2d
   use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64, real32, real64, real128
   character(len=*),parameter               :: fmt_date=’year-month-day hour:minute:second’
   type(path)                               :: file
   character(len=:),allocatable             :: filename
   integer(kind=int64)                      :: buff(14)
   integer                                  :: i
      do i = 1 , max(1,command_argument_count())
       if(command_argument_count().eq.0)then
          filename=’.’
       else
          call getname(i,filename)
       endif

file%name=filename ! or call file%init(filename)

write(*,*)’name........ ’,file%name write(*,*)’branch...... ’,file%branch() write(*,*)’leaf........ ’,file%leaf() write(*,*)’stem........ ’,file%stem() write(*,*)’bud......... ’,file%bud() write(*,*)’is_dir...... ’,file%is_dir() write(*,*)’readable.... ’,file%readable() write(*,*)’writable.... ’,file%writable() write(*,*)’executable.. ’,file%executable() write(*,*)’exists...... ’,file%exists() write(*,*)’realpath.... ’,file%realpath() write(*,*)’stat........ ’ buff=file%stat() if(buff(14) == 0) then write (*,"(9x,’Device ID(hex/decimal):’, T40,Z0,’h/’,I0,’d’)")& & buff(1),buff(1) write (*,"(9x,’Inode number:’, T40, I0)")& & buff(2) write (*,"(9x,’File mode (octal):’, T40, O19)")& & buff(3) write (*,"(9x,’Number of links:’, T40, I0)")& & buff(4) write (*,"(9x,’Owner’’s uid/username:’, T40, I0,1x, A)")& & buff(5), system_getpwuid(buff(5)) write (*,"(9x,’Owner’’s gid/group:’, T40, I0,1x, A)")& & buff(6), system_getgrgid(buff(6)) write (*,"(9x,’Device where located:’, T40, I0)")& & buff(7) write (*,"(9x,’File size(bytes):’, T40, I0)")& & buff(8) write (*,"(9x,’Last access time:’, T40, I0,1x, A)")& & buff(9), fmtdate(u2d(int(buff(9))),fmt_date) write (*,"(9x,’Last modification time:’, T40, I0,1x, A)")& & buff(10),fmtdate(u2d(int(buff(10))),fmt_date) write (*,"(9x,’Last status change time:’, T40, I0,1x, A)")& & buff(11),fmtdate(u2d(int(buff(11))),fmt_date) write (*,"(9x,’Preferred block size(bytes):’, T40, I0)")& & buff(12) write (*,"(9x,’No. of blocks allocated:’, T40, I0)")& & buff(13) else write (*,*) ’*path%stat* error: ’,file%name,’ status= ’,status endif write(*,*) enddo

contains subroutine getname(i,fn) integer,intent(in) :: i character(len=:),allocatable,intent(out) :: fn integer :: fn_length ! get pathname from command line arguments call get_command_argument (i , length=fn_length) if(allocated(filename))deallocate(filename) allocate(character(len=fn_length) :: fn) call get_command_argument (i , value=fn) end subroutine getname end program demo_path

Results:

Sample program executions:

    demo_path $HOME $HOME/.bashrc

name........ /home/urbanjs/V600 branch...... /home/urbanjs leaf........ V600 stem........ V600 bud......... is_dir...... T readable.... T writable... T executable.. T exists...... T realpath.... /home/urbanjs/V600 stat........ Device ID(hex/decimal): 3E6BE045h/1047257157d Inode number: 281474977443215 File mode (octal): 40700 Number of links: 1 Owner’s uid/username: 197609 JSU Owner’s gid/group: 197121 None Device where located: 0 File size(bytes): 0 Last access time: 1559495702 2019-06-02 13:15:02 Last modification time: 1559495702 2019-06-02 13:15:02 Last status change time: 1559495702 2019-06-02 13:15:02 Preferred block size(bytes): 65536 No. of blocks allocated: 92

name........ /home/urbanjs/V600/.bashrc branch...... /home/urbanjs/V600 leaf........ .bashrc stem........ .bashrc bud......... is_dir...... F readable.... T writable... T executable.. T exists...... T realpath.... /home/urbanjs/V600/.bashrc stat........ Device ID(hex/decimal): 3E6BE045h/1047257157d Inode number: 59672695062674129 File mode (octal): 100744 Number of links: 1 Owner’s uid/username: 197609 JSU Owner’s gid/group: 4294967295 Unknown+Group Device where located: 0 File size(bytes): 8744 Last access time: 1434310665 2015-06-14 15:37:45 Last modification time: 1533428694 2018-08-04 20:24:54 Last status change time: 1533428694 2018-08-04 20:24:54 Preferred block size(bytes): 65536 No. of blocks allocated: 12

AUTHOR

John S. Urban

LICENSE

Public Domain


path (3) March 11, 2021
Generated by manServer 1.08 from 066133fd-df08-4377-ab12-a1f7f4d766d9 using man macros.