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

CONST FLAG_NONE = 0
CONST FLAG_READ = 1
CONST FLAG_WRITE = 2
CONST FLAG_EXECUTE = 4
CONST FLAG_DELETE = 8
CONST FLAG_SHARE = 16
CONST FLAG_COPY = 32
CONST FLAG_MOVE = 64
CONST FLAG_RENAME = 128
CONST FLAG_COMPRESS = 256
CONST FLAG_ENCRYPT = 512
CONST FLAG_BACKUP = 1024
CONST FLAG_ARCHIVE = 2048
CONST FLAG_HIDDEN = 4096
CONST FLAG_SYSTEM = 8192
CONST FLAG_TEMPORARY = 16384
CONST PERM_USER_NONE = 0
CONST PERM_USER_READ = 256
CONST PERM_USER_WRITE = 512
CONST PERM_USER_EXEC = 1024
CONST PERM_USER_ALL = PERM_USER_READ OR PERM_USER_WRITE OR PERM_USER_EXEC
CONST PERM_GROUP_READ = 32
CONST PERM_GROUP_WRITE = 64
CONST PERM_GROUP_EXEC = 128
CONST PERM_GROUP_ALL = PERM_GROUP_READ OR PERM_GROUP_WRITE OR PERM_GROUP_EXEC
CONST PERM_OTHER_READ = 4
CONST PERM_OTHER_WRITE = 8
CONST PERM_OTHER_EXEC = 16
CONST PERM_OTHER_ALL = PERM_OTHER_READ OR PERM_OTHER_WRITE OR PERM_OTHER_EXEC
CONST PERM_ALL = PERM_USER_ALL OR PERM_GROUP_ALL OR PERM_OTHER_ALL
CONST STATUS_IDLE = 0
CONST STATUS_RUNNING = 1
CONST STATUS_PAUSED = 2
CONST STATUS_ERROR = 4
CONST STATUS_COMPLETE = 8
CONST STATUS_CANCELLED = 16
CONST STATUS_RETRY = 32
CONST STATUS_FAILED = 64
CONST TYPE_FILE = 0
CONST TYPE_DIRECTORY = 1
CONST TYPE_SYMLINK = 2
CONST TYPE_DEVICE = 3
CONST TYPE_PIPE = 4
CONST TYPE_SOCKET = 5
CONST PROT_NONE = 0
CONST PROT_READ = 1
CONST PROT_WRITE = 2
CONST PROT_EXEC = 4
CONST PROT_READWRITE = PROT_READ OR PROT_WRITE
CONST PROT_READEXEC = PROT_READ OR PROT_EXEC
CONST PROT_READWRITEEXEC = PROT_READ OR PROT_WRITE OR PROT_EXEC
CONST ACCESS_NONE = 0
CONST ACCESS_LIST = 1
CONST ACCESS_READ = 2
CONST ACCESS_WRITE = 4
CONST ACCESS_CREATE = 8
CONST ACCESS_MODIFY = 16
CONST ACCESS_DELETE = 32
CONST ACCESS_ADMIN = 64
CONST 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
