' Bitmask Constants for flags and permissions
#COMPILE EXE
#DIM ALL

%FLAG_NONE = 0
%FLAG_READ = 1
%FLAG_WRITE = 2
%FLAG_EXECUTE = 4
%FLAG_DELETE = 8
%FLAG_SHARE = 16
%FLAG_COPY = 32
%FLAG_MOVE = 64
%FLAG_RENAME = 128
%FLAG_COMPRESS = 256
%FLAG_ENCRYPT = 512
%FLAG_BACKUP = 1024
%FLAG_ARCHIVE = 2048
%FLAG_HIDDEN = 4096
%FLAG_SYSTEM = 8192
%FLAG_TEMPORARY = 16384

%PERM_USER_NONE = 0
%PERM_USER_READ = 256
%PERM_USER_WRITE = 512
%PERM_USER_EXEC = 1024
%PERM_USER_ALL = %PERM_USER_READ OR %PERM_USER_WRITE OR %PERM_USER_EXEC
%PERM_GROUP_READ = 32
%PERM_GROUP_WRITE = 64
%PERM_GROUP_EXEC = 128
%PERM_GROUP_ALL = %PERM_GROUP_READ OR %PERM_GROUP_WRITE OR %PERM_GROUP_EXEC
%PERM_OTHER_READ = 4
%PERM_OTHER_WRITE = 8
%PERM_OTHER_EXEC = 16
%PERM_OTHER_ALL = %PERM_OTHER_READ OR %PERM_OTHER_WRITE OR %PERM_OTHER_EXEC
%PERM_ALL = %PERM_USER_ALL OR %PERM_GROUP_ALL OR %PERM_OTHER_ALL

%STATUS_IDLE = 0
%STATUS_RUNNING = 1
%STATUS_PAUSED = 2
%STATUS_ERROR = 4
%STATUS_COMPLETE = 8
%STATUS_CANCELLED = 16
%STATUS_RETRY = 32
%STATUS_FAILED = 64

%TYPE_FILE = 0
%TYPE_DIRECTORY = 1
%TYPE_SYMLINK = 2
%TYPE_DEVICE = 3
%TYPE_PIPE = 4
%TYPE_SOCKET = 5

%PROT_NONE = 0
%PROT_READ = 1
%PROT_WRITE = 2
%PROT_EXEC = 4
%PROT_READWRITE = %PROT_READ OR %PROT_WRITE
%PROT_READEXEC = %PROT_READ OR %PROT_EXEC
%PROT_READWRITEEXEC = %PROT_READ OR %PROT_WRITE OR %PROT_EXEC

%ACCESS_NONE = 0
%ACCESS_LIST = 1
%ACCESS_READ = 2
%ACCESS_WRITE = 4
%ACCESS_CREATE = 8
%ACCESS_MODIFY = 16
%ACCESS_DELETE = 32
%ACCESS_ADMIN = 64
%ACCESS_FULL = %ACCESS_LIST OR %ACCESS_READ OR %ACCESS_WRITE OR %ACCESS_CREATE OR %ACCESS_MODIFY OR %ACCESS_DELETE OR %ACCESS_ADMIN

FUNCTION PBMAIN() AS LONG
    LOCAL flags AS LONG
    LOCAL perms AS LONG

    PRINT "Bitmask Constants Demo"
    PRINT "====================="
    PRINT ""

    PRINT "File attribute flags:"
    PRINT "  FLAG_NONE = "; %FLAG_NONE
    PRINT "  FLAG_READ = "; %FLAG_READ
    PRINT "  FLAG_WRITE = "; %FLAG_WRITE
    PRINT "  FLAG_EXECUTE = "; %FLAG_EXECUTE
    PRINT ""
    PRINT "  Combination example (READ + WRITE + EXECUTE):"
    flags = %FLAG_READ OR %FLAG_WRITE OR %FLAG_EXECUTE
    PRINT "  Flags = "; flags; " (binary: "; BIN$(flags); ")"

    flags = %FLAG_READ OR %FLAG_WRITE OR %FLAG_SHARE OR %FLAG_COPY
    PRINT ""
    PRINT "  User file permissions (READ + WRITE + SHARE + COPY):"
    PRINT "  Flags = "; flags; " (binary: "; BIN$(flags); ")"
    IF flags AND %FLAG_READ THEN PRINT "  Has READ permission: Yes"
    IF flags AND %FLAG_WRITE THEN PRINT "  Has WRITE permission: Yes"
    IF flags AND %FLAG_EXECUTE THEN PRINT "  Has EXECUTE permission: Yes"
    IF flags AND %FLAG_SHARE THEN PRINT "  Has SHARE permission: Yes"

    PRINT ""
    PRINT "POSIX permission constants:"
    PRINT "  PERM_USER_ALL = "; %PERM_USER_ALL
    PRINT "  PERM_GROUP_ALL = "; %PERM_GROUP_ALL
    PRINT "  PERM_OTHER_ALL = "; %PERM_OTHER_ALL
    PRINT "  PERM_ALL = "; %PERM_ALL

    PRINT ""
    PRINT "Access control:"
    PRINT "  ACCESS_FULL = "; %ACCESS_FULL
    PRINT "  PROT_READWRITE = "; %PROT_READWRITE
    PRINT "  PROT_READWRITEEXEC = "; %PROT_READWRITEEXEC

    perms = %PERM_USER_READ OR %PERM_USER_WRITE OR %PERM_GROUP_READ OR %PERM_OTHER_READ
    PRINT ""
    PRINT "  File permissions (rw-r--r--): binary "; BIN$(perms)
    PRINT "  Decimal: "; perms

    PRINT ""
    PRINT "Status flags test:"
    LOCAL status AS LONG
    status = %STATUS_RUNNING OR %STATUS_COMPLETE
    PRINT "  Status mask: "; status

    PRINT ""
    PRINT "All bitmask constants loaded."

    FUNCTION = 0
END FUNCTION
