Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Oct 18, 2017 12:28 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: CHMOD calculator utility
PostPosted: Tue Aug 21, 2012 5:09 am 
Offline
User avatar

Joined: Wed Oct 06, 2010 10:25 am
Posts: 154
Location: ---
I write just for fun a little utility to help to translate from octal to string and vice versa
*nix file permissions.
With this utility you can also drop a file , change permissions and apply back to the file.
Full source+executable
You can learn the use of unix permission, extends, regex, and the permission object.
Feel free to download it from here: http://www.eudosia.com/downloads/download.php?download=53
Image

_________________
Massimiliano Fabbri
Freelance Senior Programmer
(Eudosia Systems)
Visual Basic 6 - RealStudio - Mobile Development
Php5/Mysql - Dot Net C# - Objective C
-------------------------------------------
http://www.eudosia-systems.it


Top
 Profile  
Reply with quote  
 Post subject: Re: CHMOD calculator utility
PostPosted: Tue Aug 21, 2012 9:40 am 
Offline

Joined: Tue Feb 14, 2012 5:39 am
Posts: 99
Location: Austria
Hey, nice project to start with!

It only has a few bugs with sticky bits
(e.g permissions rwSr--r-- )

You could also consider working with shift and bitwise and to get the bits. so you wont need a full array, only a "r","w","x" array.
The trick would be to loop over all bits (shift & bitwise and to get the bit's value).
If the bit is a 0, then the position is a "-", else set the char to array(position mod 3).
After that loop, search for sticky bits and set them accordingly.

EDIT: A small example with sticky bits and what i meant with the advice above. Converts a oct (766) to alpha (rwxr--r--) with support for sticky bits.

Function OctToAlpha(octal as string) As string
dim permissions as String = Bin(Val("&o"+octal))

dim ugoRights as String = permissions.Right(9)
dim stickyRights as String
if permissions.Len > 9 then
stickyRights = permissions.Left(3)
end

dim str as String
dim arr() as String = Array("r","w","x")
dim arrSticky() as String = Array("s","s","T")

for i as integer = 0 to 8
dim bit as String = ugoRights.Mid(i+1,1)

if i mod 3 = 2 and stickyRights.Len > 0 Then //x field, check for sticky bit
dim stickyPosition as integer = i / 3

if bit = "1" Then
str = str + Uppercase(arrSticky(stickyPosition))
else
str = str + Lowercase(arrSticky(stickyPosition))
end
else
if bit = "1" Then
str = str + arr(i mod 3)
else
str = str + "-"
end
end
next

return str
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: CHMOD calculator utility
PostPosted: Tue Aug 21, 2012 3:43 pm 
Offline
User avatar

Joined: Wed Oct 06, 2010 10:25 am
Posts: 154
Location: ---
Yes I know. I do not have considered the sticky bits
Your solution is surely more elegant then mine.
How do apply the s. bit with a file using my function?
I am just curious.

Max.

_________________
Massimiliano Fabbri
Freelance Senior Programmer
(Eudosia Systems)
Visual Basic 6 - RealStudio - Mobile Development
Php5/Mysql - Dot Net C# - Objective C
-------------------------------------------
http://www.eudosia-systems.it


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group