home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / HILFEN / MODEM / COMAND28 / XLATE.CMD < prev   
OS/2 REXX Batch file  |  1993-12-01  |  15KB  |  638 lines

  1. ; ----- COM-AND Edit transation tables
  2. ;
  3. ;    This script opens a window and allows the editing of translation
  4. ;    tables.  COM-AND supports two transations: incoming and outgoing.
  5. ;    The first 128 bytes of the incoming table are displayed on entry.
  6. ;
  7. ;    The incoming table is 256 entries.  The outgoing table is the same
  8. ;    size.  The 'n'th position represents the translation value for the
  9. ;    character with value 'n'.
  10. ;
  11. ;    Translation may be enabled here in this script - and in COM-AND's
  12. ;    Alt-V emulations.
  13. ;
  14. ;    R.McG, commenced 1/89
  15. ; ----- Usages -----------------
  16. ;    S19 -----> COM-AND.XLT file name to be used
  17. ;    S10-S17 -> The file loaded into memory
  18. ;    N99 -----> Display page (0,1,2,3)
  19. ;    FLAG(9) -> Hex/decimal switch
  20. ;    FLAG(8) -> Modification to file
  21. ; ------------------------------
  22. ;    Initialization
  23. ;
  24. ;* TRACE ON
  25.    ON ESCAPE GOSUB Exit         ; SAVE is performed in Window
  26.    LEGEND " Edit translations"
  27.    SET TTHRU OFF            ; Disallow typeahead
  28.    N99 = 0                ; Base of current window
  29.    SET FLAG(9) OFF            ; Hex/decimal flag (true = hex)
  30.    SET FLAG(8) OFF            ; Modification flag
  31. ;
  32. ;    Initialize, and paint an initial window
  33. ;
  34.    GOSUB Set_Fname            ; S19 -> target file
  35.    UPPER S19                ; .. make nice
  36.    GOSUB Load                ; Load values
  37.    GOSUB Window             ; Open the window
  38. ;
  39. ;    Main-loop - look for keyentry
  40. ;
  41. Main_Loop:
  42.    ATSAY  22,11 (default) "          "
  43.    LOCATE 22,11
  44.    KEYGET S0                ; Get a keystroke
  45. ;
  46. ;    Act upon the keystroke
  47. ;
  48.    SWITCH S0
  49.       CASE "4900"                       ; Pgup
  50.      GOTO PgUp
  51.       ENDCASE
  52.       CASE "5100"                       ; PgDn
  53.      GOTO PgDn
  54.       ENDCASE
  55.       CASE "4700"                       ; Home
  56.      GOTO Home
  57.       ENDCASE
  58.       CASE "4F00"                       ; End
  59.      GOTO End
  60.       ENDCASE
  61.       CASE "H"                          ; H)ex
  62.      SET FLAG(9) ON
  63.      GOSUB DISPPAGE
  64.      GOTO Main_Loop
  65.       ENDCASE
  66.       CASE "D"                          ; D)ecimal
  67.      SET FLAG(9) OFF
  68.      GOSUB DISPPAGE
  69.      GOTO Main_Loop
  70.       ENDCASE
  71.       CASE "S"                          ; S)ave
  72.      GOSUB Store
  73.      GOTO Main_Loop
  74.       ENDCASE
  75.       CASE "N"                          ; S)ave
  76.      IF FLAG(8)
  77.         GOSUB Store         ; Save on disk
  78.         SET FLAG(8) OFF
  79.         ENDIF
  80.      SET TRAN ON
  81.      GOTO Main_Loop
  82.       ENDCASE
  83.       CASE "F"                          ; S)ave
  84.      SET TRAN OFF
  85.      GOTO Main_Loop
  86.       ENDCASE
  87.    ENDSWITCH
  88. ;
  89. ;     Begin numeric entry
  90. ;
  91.    IF NOT NULL S0(1:3)            ; Disallow other special keys
  92.       SOUND 100,100
  93.       GOTO Main_Loop
  94.       ENDIF
  95.    GOSUB Enter                ; Enter #
  96.    GOTO Main_Loop            ; And continue
  97. ;
  98. ; ----- Page up (cycle backwards through possible values)
  99. ;
  100. PgUp:
  101.    DEC N99
  102.    IF LT N99 0
  103.       N99 = 3
  104.       ENDIF
  105.    GOSUB DispPage
  106.    GOTO Main_Loop
  107. ;
  108. ; ----- Page down (cycle forwards through possible values)
  109. ;
  110. PgDn:
  111.    INC N99
  112.    IF GT N99 3
  113.       N99 = 0
  114.       ENDIF
  115.    GOSUB DispPage
  116.    GOTO Main_Loop
  117. ;
  118. ; ----- Home (move to first line)
  119. ;
  120. Home:
  121.    N99 = 0
  122.    GOSUB DispPage
  123.    GOTO Main_Loop
  124. ;
  125. ; ----- End (Move to last line)
  126. ;
  127. End:
  128.    N99 = 3
  129.    GOSUB DispPage
  130.    GOTO Main_Loop
  131. ;
  132. ; ----- Subroutine Exit - terminate the process
  133. ;
  134. Exit:
  135.    IF FLAG(8)                ; If table modified
  136.       GOSUB Ask_Save            ; Ask if to save
  137.       ENDIF
  138.    DO                    ; CLose any open windows
  139.      WCLOSE
  140.      UNTIL FAILURE
  141.    EXIT
  142. ;
  143. ; ----- Subroutine: Enter a value
  144. ;    .. on entry S0 -> The first keystroke
  145. ;    .. S9 within this subroutine the field being constructed
  146. ;    .. N6 within this subroutine is an index to field being constructed
  147. ;
  148. Enter:
  149.    N6 = 0                ; Index to field being built
  150.    S9 = ""                              ; Clear field
  151.    UPPER S0                ; Make upper case
  152.    CTOI S0 N0                ; Easier comparison
  153.    IF NOT ((GE N0 48 and LE N0 57) or EQ N0 88) ; Allow 0-9 and 'x'
  154.       SOUND 100,100
  155.       RETURN
  156.       ENDIF
  157.    CURSOR N0,N1
  158.    INC N1
  159.    LOCATE N0,N1
  160.    GOTO Keyin
  161. ;
  162. ;    Accept another keypress
  163. ;
  164. Keypress:
  165.    KEYGET S0                ; Get more from keybd
  166. ;
  167. ;    Catch backspace (and equivalent cursor left) here
  168. ;
  169. Keyin:
  170.    IF STRCMP S0 "08" or STRCMP S0 "4B00"; Backspace or cursor left
  171.       IF GT N6 0
  172.      CURSOR N0,N1
  173.      ATSAY N0,N1 (default) "^H"
  174.      DEC N6
  175.      ENDIF
  176.       IF EQ N6 0
  177.      RETURN             ; Nop at this pt
  178.      ENDIF
  179.       GOTO Keypress
  180.       ENDIF
  181. ;
  182. ;    Catch carriage return (and equivalent space/tab) here
  183. ;
  184.    IF STRCMP S0 "0D" or STRCMP S0 " " or STRCMP S0 "09" ; cr, space, tab
  185.       IF EQ N6 0            ; Look for nothing done
  186.      RETURN             ; Empty field
  187.      ENDIF
  188.       GOTO End_Entry            ; Done - try to convert it
  189.       ENDIF
  190. ;
  191. ;    Other control keys abort entry
  192. ;
  193.    IF NOT NULL S0(1:3)            ; If a special key
  194.       GOTO Abort_Entry            ; Exit on special key
  195.       ENDIF
  196. ;
  197. ;    Filter only 0-9, a-f, and 'x' here
  198. ;
  199.    UPPER S0                ; Make upper case
  200.    CTOI S0 N0                ; Easier comparison
  201.    IF NOT ((GE N0 48 and LE N0 57) or (GE N0 65 and LE N0 70) or EQ N0 88)
  202.       SOUND 100,100
  203.       GOTO Keypress
  204.       ENDIF
  205. ;
  206. ;    Add the character to the string being constructed
  207. ;
  208.    CURSOR N0,N1
  209.    ATSAY N0,N1 (default) S0
  210.    INC N1
  211.    LOCATE N0,N1
  212.    S9(N6:N6) = S0            ; Add the key
  213.    INC N6                ; Add to index
  214.    GOTO Keypress            ; And continue
  215. ;
  216. ;    Abort entry and return to main
  217. ;
  218. Abort_Entry:
  219.    RETURN
  220. ;
  221. ;    Error in entry
  222. ;
  223. Entry_Error:
  224.    SOUND 400,100
  225.    RETURN
  226. ;
  227. ;    End of entry - catch empty field
  228. ;
  229. End_Entry:
  230.       IF EQ N6 0            ; EMpty field
  231.      RETURN
  232.      ENDIF
  233. ;
  234. ;    Convert a leading 'x' into '0x'
  235. ;
  236.       IF STRCMP S9(0:0) "X"             ; 'x' in col 0
  237.      S9 = "0"&S9                    ; Add an initial 0
  238.      ENDIF
  239. ;
  240. ;    Try to convert the char
  241. ;
  242.       ATOI S9 N0            ; Convert
  243.       IF ERROR or (LT N0 0 or GT N0 255)
  244.      GOTO Entry_Error        ; .. indicate error
  245.      ENDIF
  246. ;
  247. ;    Lookup the value obtained
  248. ;
  249.    GOSUB Get_Value            ; Using N0, get its translation into N1
  250.    S0 = "Char %03d (x%02x) currently translates to %03d (x%02x)"
  251.    STRFMT S1 S0 N0,N0 N1,N1        ; Construct prompt
  252. ;
  253. ;    Open a window for the entry of the translation
  254. ;
  255.    WOPEN 19,0, 22,78 (default) TenterXIT
  256.    ATSAY 20,2, (default) S1        ; D
  257.    ATSAY 21,2  (default) "New translation: "
  258.    ATSAY 22,28 (default) " Press ESC to cancel "
  259. ;
  260. ;    Ask for the translation
  261. ;
  262. Tenter:
  263.    ATGET 21,19 (default) 4 S0        ; Get new translation
  264. ;
  265. ;    Catch empty response (Tenter_ESC also clears S0)
  266. ;
  267.    IF NULL S0                ; EMpty field
  268.       WCLOSE                ; Drop window
  269.       RETURN
  270.       ENDIF
  271. ;
  272. ;    Convert a leading 'x' into '0x'
  273. ;
  274.    IF STRCMP S0(0:0) "X"                ; 'x' in col 0
  275.       S0 = "0"&S0                       ; Add an initial 0
  276.       ENDIF
  277. ;
  278. ;    Try to convert the char
  279. ;
  280.    ATOI S0 N1                ; Convert
  281.    IF ERROR or (LT N1 0 or GT N1 255)
  282.       SOUND 400,100
  283.       GOTO Tenter            ; .. Try again
  284.       ENDIF
  285. ;
  286. ;    We have a value (N0 translating into N1)
  287. ;
  288.    WCLOSE
  289.    SET FLAG(8) ON            ; Mark updated
  290.    GOSUB Set_Value
  291. ;
  292. ;    Redisplay the line or page modified
  293. ;
  294.    N3 = N0/128                ; N3  -> page #
  295.    IF GE N99 2                ; N99 -> incoming/outgoing
  296.       N3 = N3+2
  297.       ENDIF
  298.    IF NE N3 N99
  299.       N99 = N3                ; Set new page no
  300.       GOSUB DispPage            ; Display the new page
  301.    ELSE
  302.       N98 = N0 & 15            ; Make N98 = 0-15
  303.       GOSUB DispLine            ; Just redo the line (n98 = lineno)
  304.       ENDIF
  305.    RETURN
  306. ;
  307. ; ----- Escape during entry routine
  308. ;
  309. TenterXit:
  310.       S0 = ""                           ; Null input field
  311.       RETURN
  312. ;
  313. ; ----- Get a translation value
  314. ;    On entry N0 -> the char being translated
  315. ;    On exit  N1 <- the translation
  316. ;
  317. Get_Value:
  318.     N3 = N0/64        ; Mask string # (0-3)
  319.     IF GE N99 2        ; Decide incoming/outgoing
  320.        N3 = N3+4        ; Sel within incoming/outgoing tables
  321.        ENDIF
  322.     SWITCH N3        ; Switch on string # (0-7)
  323.       CASE 0
  324.         S0 = S10
  325.       ENDCASE
  326.       CASE 1
  327.         S0 = S11
  328.       ENDCASE
  329.       CASE 2
  330.         S0 = S12
  331.       ENDCASE
  332.       CASE 3
  333.         S0 = S13
  334.       ENDCASE
  335.       CASE 4
  336.         S0 = S14
  337.       ENDCASE
  338.       CASE 5
  339.         S0 = S15
  340.       ENDCASE
  341.       CASE 6
  342.         S0 = S16
  343.       ENDCASE
  344.       CASE 7
  345.         S0 = S17
  346.       ENDCASE
  347.     ENDSWITCH
  348.     CTOI S0(N0&63) N1
  349.     RETURN
  350. ;
  351. ; ----- Store a translation value
  352. ;    On entry N0 -> the char being translated
  353. ;         N1 -> the translation
  354. ;
  355. Set_Value:
  356.     N3 = N0/64        ; Mask string # (0-3)
  357.     IF GE N99 2        ; Decide incoming/outgoing
  358.        N3 = N3+4        ; Sel within incoming/outgoing tables
  359.        ENDIF
  360.     SWITCH N3        ; Switch on string # (0-7)
  361.       CASE 0
  362.         ITOC N1 S10(N0&63)
  363.       ENDCASE
  364.       CASE 1
  365.         ITOC N1 S11(N0&63)
  366.       ENDCASE
  367.       CASE 2
  368.         ITOC N1 S12(N0&63)
  369.       ENDCASE
  370.       CASE 3
  371.         ITOC N1 S13(N0&63)
  372.       ENDCASE
  373.       CASE 4
  374.         ITOC N1 S14(N0&63)
  375.       ENDCASE
  376.       CASE 5
  377.         ITOC N1 S15(N0&63)
  378.       ENDCASE
  379.       CASE 6
  380.         ITOC N1 S16(N0&63)
  381.       ENDCASE
  382.       CASE 7
  383.         ITOC N1 S17(N0&63)
  384.       ENDCASE
  385.     ENDSWITCH
  386.     RETURN
  387. ;
  388. ; ----- Construct the file name we'll use for COM-AND.XLT
  389. ;
  390. Set_Fname:
  391.     S19 = "COM-AND.XLT"     ; Default to current subdir
  392.     IF ISFILE S19        ; Look for file on default subdir
  393.        RETURN        ; Exit here
  394.        ENDIF
  395. ;
  396. ; ----- Construct the file with the COM-AND= pathing (if provided)
  397. ;
  398.     ENVIRON S1 "COM-AND="   ; Look for COM-AND= environment var
  399.     IF FOUND        ; If environment variable found
  400.        LENGTH S1 N0     ; Get its length
  401.        N0 = N0-1        ; Point to last char in string
  402.        IF not STRCMP S1(n0:n0) "\"
  403.           N0 = N0+1
  404.           CONCAT S1(n0) "\"
  405.           ENDIF
  406.        ENDIF
  407.     S19 = S1&"COM-AND.XLT"  ; Concatenate path and name
  408.     RETURN
  409. ;
  410. ; ----- Subroutine: error
  411. ;    .. Open a window, display, and and await keypress
  412. ;    S0,S1 pass the message(s) to display
  413. ;
  414. Error:
  415.     WOPEN 10,1, 13,77 (contrast) ErrEsc
  416.     ATSAY 11, 3 (contrast) S0(0:73)
  417.     ATSAY 12, 3 (contrast) S1(0:73)
  418.     ATSAY 13,26 (contrast) " Press any key to continue "
  419.     SOUND 880,100
  420.  
  421.     KEYGET S0        ; Wait for any key
  422.     WCLOSE            ; Restore screen under
  423.     RETURN            ; And return to caller
  424. ;
  425. ;    Escape during "Error" window
  426. ;
  427. ErrEsc:
  428.     RETURN            ; And return to KEYGET above
  429. ;
  430. ; ----- Load the current table
  431. ;    .. first, dummy values
  432. ;
  433. Load:
  434.     FOR N0=0,31
  435.         ITOC  N0      S10(N0:N0)
  436.         ITOC (N0+64)  S11(N0:N0)
  437.         ITOC (N0+128) S12(N0:N0)
  438.         ITOC (N0+192) S13(N0:N0)
  439.         ITOC  N0+32   S10(N0+32)
  440.         ITOC (N0+96)  S11(N0+32)
  441.         ITOC (N0+160) S12(N0+32)
  442.         ITOC (N0+224) S13(N0+32)
  443.         ENDFOR
  444.     S14 = S10
  445.     S15 = S11
  446.     S16 = S12
  447.     S17 = S13
  448. ;
  449. ;    If the file doesn't exist, no error
  450. ;
  451.     IF NOT ISFILE S19
  452.        GOTO LOADXIT
  453.        ENDIF
  454. ;
  455. ;    Open the file
  456. ;
  457.     FOPENI S19 BINARY    ; Open as a binary file
  458.     IF FAILED        ; If error openeing it...
  459.        S0 = "Error opening file for loading"
  460.        S1 = S19
  461.        GOSUB Error         ; Display error message
  462.        RETURN
  463.        ENDIF
  464. ;
  465. ;    Read the file into 8 string variables
  466. ;    .. File is opened binary!
  467. ;
  468.     READ S10 64 N0        ; Read 64 bytes
  469.     READ S11 64 N0        ; Read 64 bytes
  470.     READ S12 64 N0        ; Read 64 bytes
  471.     READ S13 64 N0        ; Read 64 bytes
  472.     READ S14 64 N0        ; Read 64 bytes
  473.     READ S15 64 N0        ; Read 64 bytes
  474.     READ S16 64 N0        ; Read 64 bytes
  475.     READ S17 64 N0        ; Read 64 bytes
  476.     FCLOSEI         ; Close the file
  477. LoadXit:
  478.     RETURN            ; And we're done
  479. ;
  480. ; ----- Subroutine: Ask if modifications are to be saved
  481. ;    .. Open a window, display, and and await keypress
  482. ;    S0,S1 pass the message(s) to display
  483. ;
  484. Ask_Save:
  485.     WOPEN 10,1, 12,77 (contrast) AskEsc
  486.     ATSAY 11, 3 (contrast) "Do you wish to save changes? (y/n): "
  487.     ATSAY 12,29 (contrast) " Press ESC to exit "
  488.     SOUND 880,100
  489. Ask_Again:
  490.     ATGET 11,40 (contrast) 1 S0
  491.     SWITCH S0
  492.       CASE "Y"
  493.         GOSUB Store     ; Save current values
  494.       ENDCASE
  495.       CASE "N"
  496.       ENDCASE
  497.       DEFAULT
  498.         SOUND 100,100
  499.         GOTO Ask_Again    ; None of the above
  500.       ENDCASE
  501.     ENDSWITCH
  502.  
  503.     WCLOSE            ; Restore screen under
  504.     RETURN            ; And return to caller
  505. ;
  506. ;    Escape during "Ask" window
  507. ;
  508. AskEsc:
  509.     S0 = "N"                ; Fake a 'n'
  510.     RETURN            ; And return to KEYGET above
  511. ;
  512. ; ----- Store the table as composed.
  513. ;    .. First, Open the file
  514. ;
  515. Store:
  516.     FOPENO S19 BINARY    ; Open the file name so constructed
  517.     IF FAILED        ; If error openeing it...
  518.        S0 = "Error opening file for update"
  519.        S1 = S19
  520.        GOSUB Error         ; Display error message
  521.        RETURN
  522.        ENDIF
  523. ;
  524. ;    Write the file from the 8 string variables
  525. ;    .. File is opened binary!
  526. ;
  527.     WRITE S10 64
  528.     WRITE S11 64
  529.     WRITE S12 64
  530.     WRITE S13 64
  531.     WRITE S14 64
  532.     WRITE S15 64
  533.     WRITE S16 64
  534.     WRITE S17 64
  535.     FCLOSEO         ; Close the file
  536.     RETURN            ; And we're done
  537. ;
  538. ; ----- Format the current page for display
  539. ;    .. First, Display the Incoming/outgoing legend
  540. ;
  541. DispPage:
  542.     SWITCH N99        ; Switch on current page
  543.       CASE 0
  544.         S0 = "Incoming translations"
  545.       ENDCASE
  546.       CASE 1
  547.         S0 = "Incoming translations"
  548.       ENDCASE
  549.       CASE 2
  550.         S0 = "Outgoing translations"
  551.       ENDCASE
  552.       CASE 3
  553.         S0 = "Outgoing translations"
  554.       ENDCASE
  555.       DEFAULT        ; N99 buggerred
  556.         RETURN        ; Leave display blank
  557.       ENDCASE
  558.     ENDSWITCH
  559.     ATSAY 1,2 (default) S0 & ", from file "*S19
  560. ;
  561. ;    Now, build lines and display 'em
  562. ;
  563.     FOR N98 = 0,15        ; 16 rows of 8 columns
  564.         GOSUB  DispLine
  565.         ENDFOR
  566.     RETURN            ; And we're done
  567. ;
  568. ; ----- Display a single line
  569. ;    N99 -> 0,1,2,3 display page
  570. ;    N98 -> The line number (0-15)
  571. ;
  572. DispLine:
  573.     SWITCH N99        ; Switch on current page
  574.       CASE 0
  575.         S0 = S10
  576.         S1 = S11
  577.       ENDCASE
  578.       CASE 1
  579.         S0 = S12
  580.         S1 = S13
  581.       ENDCASE
  582.       CASE 2
  583.         S0 = S14
  584.         S1 = S15
  585.       ENDCASE
  586.       CASE 3
  587.         S0 = S16
  588.         S1 = S17
  589.       ENDCASE
  590.       DEFAULT        ; N99 buggerred
  591.         RETURN        ; Leave display blank
  592.       ENDCASE
  593.     ENDSWITCH
  594. ;
  595. ;    Now, build a line and display it
  596. ;
  597.     N10 = N98        ; Even page # 1st lnno
  598.     IF NOT ZERO (N99&1)    ; Odd/even base page #
  599.        N10 = N98+128    ; Odd page # 1st line #
  600.        ENDIF
  601.     FOR N9=1,8
  602.         N10[N9] = N10[N9-1]+16 ; N11-N17
  603.         ENDFOR
  604.     CTOI S0(N98)    N0
  605.     CTOI S0(N98+16) N1
  606.     CTOI S0(N98+32) N2
  607.     CTOI S0(N98+48) N3
  608.     CTOI S1(N98)    N4
  609.     CTOI S1(N98+16) N5
  610.     CTOI S1(N98+32) N6
  611.     CTOI S1(N98+48) N7
  612.     IF FLAG(9)        ; T -> Hex
  613.        S2 = "x%02x:x%02x  x%02x:x%02x  x%02x:x%02x  x%02x:x%02x"
  614.     ELSE
  615.        S2 = "%03d:%03d  %03d:%03d  %03d:%03d  %03d:%03d"
  616.        ENDIF
  617.     STRFMT S3 S2 N10,N0, N11,N1, N12,N2, N13,N3
  618.     ATSAY N98+2,3 (default) S3
  619.     STRFMT S3 S2 N14,N4, N15,N5, N16,N6, N17,N7
  620.     ATSAY N98+2,3+37 (default) S3
  621.     RETURN            ; And we're done
  622. ;
  623. ; ----- Open a window with blank fields
  624. ;
  625. Window:
  626.    WOPEN  0,0  23,78 (Default)
  627.    ATSAY  0,2  (default)   " COM-AND Translates "
  628.  
  629.    ATSAY 18,0  (default) "├─────────────────────────────────────────────────────────────────────────────┤"
  630.    ATSAY 19,3  (default)    "PgUp, PgDn, Home, End through table(s);  H)ex, D)ecimal, S)ave, oN), oF)f;"
  631.    ATSAY 20,3  (default)    "Or enter a value (decimal or hex) to modify."
  632.    ATSAY 21,0  (default) "├─────────────────────────────────────────────────────────────────────────────┤"
  633.    ATSAY 22,3  (default) "Select: "
  634.    ATSAY 23,30 (default)            " Press ESC to exit "
  635.  
  636.    GOSUB  DispPage
  637.    RETURN
  638.