REM > TestTerr

ON ERROR ON ERROR OFF: REPORT: PRINT ERL: END

DIM b% 1000, DATE$(6), FMT$(3), PROP$(10)

DATE$(0) = "%cs %se %mi %12 %24 %am %pm %we %w3 %wn"
DATE$(1) = "%CS %SE %MI %12 %24 %AM %PM %WE %W3 %WN"
DATE$(2) = "%dy %st %mo %m3 %mn %ce %yr %wk %dn %tz"
DATE$(3) = "%DY %ST %MO %M3 %MN %CE %YR %WK %DN %TZ"
DATE$(4) = "%zcs %zse %zmi %z12 %z24 %zam %zpm %zwe %zw3 %zwn"
DATE$(5) = "%zdy %zst %zmo %zm3 %zmn %zce %zyr %zwk %zdn %ztz"
DATE$(6) = "%% abc 123 cs se zmi"

FMT$(1) = "%24:%MI:%SE"
FMT$(2) = "%W3, %DY-%M3-%CE%YR"
FMT$(3) = "%W3, %DY-%M3-%CE%YR.%24:%MI:%SE"

PROP$() = "control", "uppercase", "lowercase", "alphabetic", "punctuation", "white space", "digit", "hex digit", "has accent", "same direction", "opposite direction"

REM------------------------------------------------------------
PRINT "Territory manager SWIs"
REM------------------------------------------------------------
PRINT "  Territory_Number"

SYS"Territory_Number" TO test%
PRINT "    Current territory's number: "; STR$test%

REM------------------------------------------------------------
PRINT "  Territory_NumberToName"

FOR terr% = 1 TO 50
  SYS"XTerritory_NumberToName", terr%, b%, 1000 TO err%, name$; flags%
  IF flags% AND 1 THEN
REM    PRINT "    "; STR$terr%; ": Error: "; STR$(!err%); ": "; FNstr(err% + 4)
  ELSE
    PRINT "    "; STR$terr%; ": "; name$
  ENDIF
NEXT

REM------------------------------------------------------------
PRINT "  Territory_Exists"'"    ";

FOR terr% = 1 TO 50
  SYS"Territory_Exists", terr% TO ; flags%
  IF flags% AND 2 THEN PRINT STR$terr%; " ";
NEXT

REM------------------------------------------------------------
PRINT '"  Territory_AlphabetNumberToName"

FOR alph% = 100 TO 120
  SYS"XTerritory_AlphabetNumberToName", alph%, b%, 1000 TO err%, name$; flags%
  IF flags% AND 1 THEN
REM    PRINT "    "; STR$alph%; ": Error: "; STR$(!err%); ": "; FNstr(err% + 4)
  ELSE
    PRINT "    "; STR$alph%; ": "; name$
  ENDIF
NEXT

REM------------------------------------------------------------
PRINT "  Territory_SelectAlphabet"

SYS"Territory_Alphabet", -1

REM------------------------------------------------------------
PRINT "  Territory_SetTime"

PROCprinttime

b%?0 = 3
SYS"OS_Word", 14, b%

b%?10 = 0
b%?11 = 0
b%?12 = &ef
b%?13 = &cd
b%?14 = &ab
PRINT "    Setting time to: "; FNtime(b%+10)
SYS"Territory_SetTime", b%+10

PROCprinttime

PRINT "    Setting time back"
SYS"Territory_SetTime", b%

PROCprinttime

REM------------------------------------------------------------
PRINT "  Territory_ReadCurrentTimeZone"

SYS"Territory_ReadCurrentTimeZone" TO name$, offset%
PRINT "    name: '"; name$; "', offset/cs: "; STR$offset%

REM------------------------------------------------------------
PRINT "  Territory_ConvertTimeToUTCOrdinals"

SYS"Territory_ConvertTimeToUTCOrdinals",, b%, b%+100
PRINT "    centiseconds: "; STR$b%!100
PRINT "         seconds: "; STR$b%!104
PRINT "         minutes: "; STR$b%!108
PRINT "           hours: "; STR$b%!112
PRINT "             day: "; STR$b%!116
PRINT "           month: "; STR$b%!120
PRINT "            year: "; STR$b%!124
PRINT "     day of week: "; STR$b%!128
PRINT "     day of year: "; STR$b%!132

REM------------------------------------------------------------
PRINT "Territory module SWIs"
REM------------------------------------------------------------
PRINT "  Territory_ReadTimeZones"

SYS"Territory_ReadTimeZones", -1 TO zone$, dst$, zone%, dst%
PRINT "    standard: '"; zone$; "', offset/cs: "; STR$zone%
PRINT "    dst: '"; dst$; "', offset/cs: "; STR$dst%

REM------------------------------------------------------------
PRINT "  Territory_ConvertDateAndTime"

b%?0 = 3
SYS"OS_Word", 14, b%
FOR i% = 0 TO 6
  SYS"Territory_ConvertDateAndTime", -1, b%, b%+10, 990, DATE$(i%) TO date$
  PRINT "    '"; DATE$(i%) "' -> '"; date$; "'"
NEXT

REM------------------------------------------------------------
PRINT "  Territory_ConvertStandardDateAndTime"

SYS"Territory_ConvertStandardDateAndTime", -1, b%, b%+10, 990 TO date$
PRINT "    '"; date$; "'"

REM------------------------------------------------------------
PRINT "  Territory_ConvertStandardDate"

SYS"Territory_ConvertStandardDate", -1, b%, b%+10, 990 TO date$
PRINT "    '"; date$; "'"

REM------------------------------------------------------------
PRINT "  Territory_ConvertStandardTime"

SYS"Territory_ConvertStandardTime", -1, b%, b%+10, 990 TO date$
PRINT "    '"; date$; "'"

REM------------------------------------------------------------
PRINT "  Territory_ConvertTimeToOrdinals"

SYS"Territory_ConvertTimeToOrdinals", -1, b%, b%+100
PRINT "    centiseconds: "; STR$b%!100
PRINT "         seconds: "; STR$b%!104
PRINT "         minutes: "; STR$b%!108
PRINT "           hours: "; STR$b%!112
PRINT "             day: "; STR$b%!116
PRINT "           month: "; STR$b%!120
PRINT "            year: "; STR$b%!124
PRINT "     day of week: "; STR$b%!128
PRINT "     day of year: "; STR$b%!132

REM------------------------------------------------------------
PRINT "  Territory_ConvertTimeStringToOrdinals"

FOR i% = 1 TO 3
  SYS"Territory_ConvertDateAndTime", -1, b%, b%+10, 990, FMT$(i%) TO date$
  PRINT "    "; STR$i%; " '"; FMT$(i%); "' -> '"; date$; "'"
  SYS"Territory_ConvertTimeStringToOrdinals", -1, i%, date$, b%+100
  PRINT "    centiseconds: "; STR$b%!100
  PRINT "         seconds: "; STR$b%!104
  PRINT "         minutes: "; STR$b%!108
  PRINT "           hours: "; STR$b%!112
  PRINT "             day: "; STR$b%!116
  PRINT "           month: "; STR$b%!120
  PRINT "            year: "; STR$b%!124
NEXT

REM------------------------------------------------------------
PRINT "  Territory_ConvertOrdinalsToTime"

SYS"Territory_ConvertTimeToOrdinals", -1, b%, b%+100
SYS"Territory_ConvertOrdinalsToTime", -1, b%+10, b%+100
PRINT "    Original time : "; FNtime(b%)
PRINT "    Converted to ordinals and back"
PRINT "    Converted time: "; FNtime(b%+10)

REM------------------------------------------------------------
PRINT "  Territory_Alphabet"

SYS"Territory_Alphabet", -1 TO alph%
PRINT "    Alphabet number: "; STR$alph%

REM------------------------------------------------------------
PRINT "  Territory_AlphabetIdentifier"

SYS"Territory_AlphabetIdentifier", -1 TO alph$
PRINT "    Alphabet name: "; alph$

REM------------------------------------------------------------
PRINT "  Territory_SelectKeyboardHandler"

SYS"Territory_SelectKeyboardHandler", -1

REM------------------------------------------------------------
PRINT "  Territory_WriteDirection"

SYS"Territory_WriteDirection", -1 TO dir%
PRINT "    &"; STR$~dir%; ": ";
IF dir% AND 1 THEN PRINT "right to left, "; ELSE PRINT "left to right, ";
IF dir% AND 2 THEN PRINT "bottom to top, "; ELSE PRINT "top to bottom, ";
IF dir% AND 4 THEN PRINT "vertical" ELSE PRINT "horizontal"

REM------------------------------------------------------------
PRINT "  Territory_CharacterPropertyTable"

FOR i% = 0 TO 10
  PRINT "    "; STR$i%; " "; PROP$(i%); ": ";
  SYS"Territory_CharacterPropertyTable", -1, i% TO table%
  FOR c% = 0 TO 255
    IF table%?(c% >> 3) AND (1 << (c% AND 7)) THEN PRINT FNchar(c%);
  NEXT
  PRINT
NEXT

REM------------------------------------------------------------
PRINT "  Territory_LowerCaseTable"

SYS"Territory_LowerCaseTable", -1 TO table%
PROCtable(table%)

REM------------------------------------------------------------
PRINT "  Territory_UpperCaseTable"

SYS"Territory_UpperCaseTable", -1 TO table%
PROCtable(table%)

REM------------------------------------------------------------
PRINT "  Territory_ControlTable"

SYS"Territory_ControlTable", -1 TO table%
PROCtable(table%)

REM------------------------------------------------------------
PRINT "  Territory_PlainTable"

SYS"Territory_PlainTable", -1 TO table%
PROCtable(table%)

REM------------------------------------------------------------
PRINT "  Territory_ValueTable"

SYS"Territory_ValueTable", -1 TO table%
PROCtable(table%)

REM------------------------------------------------------------
PRINT "  Territory_RepresentationTable"

SYS"Territory_RepresentationTable", -1 TO table%
PRINT "    ";
FOR i% = 0 TO 15
  PRINT FNchar(table%?i%);
NEXT
PRINT

REM------------------------------------------------------------

END

REM------------------------------------------------------------

DEF FNstr(addr%)
LOCAL s$
WHILE ?addr% > 31
  s$ += CHR$(?addr%)
  addr% += 1
ENDWHILE
=s$

REM------------------------------------------------------------

DEF FNtime(z%)
LOCAL i%, s$
FOR i% = 4 TO 0 STEP -1
  s$ += RIGHT$("0" + STR$~z%?i%, 2)
NEXT
=s$

REM------------------------------------------------------------

DEF PROCprinttime
b%?100 = 3
SYS"OS_Word", 14, b%+100
PRINT "    5-byte UTC time now: "; FNtime(b%+100)
ENDPROC

REM------------------------------------------------------------

DEF FNchar(c%)
IF c% < 33 OR c% = 127 THEN
  ="[" + STR$~c% + "]"
ENDIF
=CHR$c%

REM------------------------------------------------------------

DEF PROCtable(table%)
LOCAL from$, to$, c%
FOR c% = 0 TO 255
  IF table%?c% <> c% THEN
    from$ += FNchar(c%)
    to$ += FNchar(table%?c%)
  ENDIF
  IF LENto$ > 60 THEN
    PRINT "    "; from$
    PRINT "    "; to$
    from$ = ""
    to$ = ""
  ENDIF
NEXT
PRINT "    "; from$
PRINT "    "; to$
ENDPROC
