UNIX Free Pascal


.


13.28. ls -l.

uses linux,strings,sysutils; (* Linux PChar*)

function ctime(var time_t:longint):pchar;cdecl;external 'c';

 

 

function gettype(t:word):char;forward; (* .. ls*)

 

(* .. ls*)

function gettype(t:word):char;

begin

if S_ISDIR(t) then (* *)

gettype:='d'

else

if S_ISREG(t) then (* *)

gettype:='-'

else

if S_ISBLK(t) then (* *)

gettype:='b'

else

if S_ISCHR(t) then (* *)

gettype:='c'

else

if S_ISFIFO(t) then (* *)

gettype:='p'

else

if S_ISLNK(t) then (* *)

gettype:='l'

else

gettype:='?';

end;

 

 

function getrights(r:word):string;

var

u, (* *)

g, (* *)

o, (* *)

s, (* *)

i:integer;

res:string; (* *)

const

o7777=(1 shl 12)-1; (* = 12 *)

o10 =8; (*010 *)

o100 =64; (*0100 *)

o1000=512; (*01000*)

symrights:array [0..7] of string=( (* *)

'---', (*0 = 000*)

'--x', (*1 = 001*)

'-w-', (*2 = 010*)

'-wx', (*3 = 011*)

'r--', (*4 = 100*)

'r-x', (*5 = 101*)

'rw-', (*6 = 110*)

'rwx' (*7 = 111*)

);

spec='tss'; (* *)

begin

(* , ( ..)*)

r:=r and o7777;(* 10000-1==1*8^4-1==1*(2^3)^4-1==2^12-1 *)




- -  - -  - -