chmodCALC

Linux specific forum
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

chmodCALC

Post by TronDoc »

maybe someone will find this beginner's code useful.
I got the idea from the javascript version in another thread.
--jb

Code: Select all

; title: chmodCALC.pb
; language: PureBASIC v3.81 (Linux)
; date: 2004.01.10
; author: Joe Block
; 
; just a little calculator for determining
; the correct value for simple chmods in Linux.
;
; it doesn't call chmod (yet) and doesn't
; have all the options of the command line chmod
;
; it's just a good simple practice program for me
; with the benefit of providing some helpful info.
;
; this program code is free for any use
; copyright 2004 Joe Block a.k.a. TronDoc a.k.a the elecTRONics DOCtor
;
; info table:
;
; permission	user(owner)	group	all(other)
; read			4			4		4
; write			2			2		2
; execute		1			1		1
; code			total		total	total
;
;
;
; Open a window
;
#WindowWidth  = 360
#WindowHeight = 140

If OpenWindow(0, 100, 120, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "TronDoc's - chmod calculator")

	If CreateGadgetList(WindowID())
		GadgetHeight = 24
		Top = 10
		StringGadget(0,  20, Top, 200, GadgetHeight, "chmod=") : Top+30

		CheckBoxGadget(10, 15, Top, 110, GadgetHeight, "Owner Read") : Top+30
		CheckBoxGadget(11, 15, Top, 110, GadgetHeight, "Owner Write")  : Top+30
		CheckBoxGadget(12, 15, Top, 110, GadgetHeight, "Owner Execute")  : Top+30
		Top = 40

		CheckBoxGadget(13, 130, Top, 110, GadgetHeight, "Group Read") : Top+30
		CheckBoxGadget(14, 130, Top, 110, GadgetHeight, "Group Write")  : Top+30
		CheckBoxGadget(15, 130, Top, 110, GadgetHeight, "Group Execute")  : Top+30
		Top = 40
		CheckBoxGadget(16, 240, Top, 110, GadgetHeight, "All Read") : Top+30
		CheckBoxGadget(17, 240, Top, 110, GadgetHeight, "All Write")  : Top+30
		CheckBoxGadget(18, 240, Top, 110, GadgetHeight, "All Execute")  : Top+30
	EndIf


  Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_EventGadget
      Select EventGadgetID()
        Case 10 ;
			If GetGadgetState(10)
				user = user + 4
			Else
				user = user - 4
			Endif
        Case 11 ;
			If GetGadgetState(11)
				user = user + 2
			Else
				user = user - 2
			Endif
        Case 12 ;
			If GetGadgetState(12)
				user = user + 1
			Else
				user = user - 1
			Endif
        Case 13 ;
			If GetGadgetState(13)
				group = group + 4
			Else
				group = group - 4
			Endif
        Case 14 ;
			If GetGadgetState(14)
				group = group + 2
			Else
				group = group - 2
			Endif
        Case 15 ;
			If GetGadgetState(15)
				group = group + 1
			Else
				group = group - 1
			Endif
        Case 16 ;
			If GetGadgetState(16)
				all = all + 4
			Else
				all = all - 4
			Endif
        Case 17 ;
			If GetGadgetState(17)
				all = all + 2
			Else
				all = all - 2
			Endif
        Case 18 ;
			If GetGadgetState(18)
				all = all + 1
			Else
				all = all - 1
			Endif
      EndSelect
	  chmod$ = Str(user)+Str(group)+Str(all)
	  SetGadgetText(0, "chmod="+chmod$)
;	  MessageRequester("Info", "chmod="+chmod$)	

    EndIf
  Until EventID = #PB_EventCloseWindow

EndIf

End 
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Nice example! :)

regards,
Christian
DeeCee
User
User
Posts: 34
Joined: Wed Dec 31, 2003 11:14 pm

Post by DeeCee »

Good one Joe! 8)

-DeeCee-
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

thanks..
..you both are TOO kind :wink:
NOW to get that morphed into
a chmodGUI that actually does
a chmod...
--jb
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Post Reply