home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / VSnap / startsnap.rexx < prev    next >
OS/2 REXX Batch file  |  1990-04-10  |  10KB  |  396 lines

  1. /* Arexx script to help people with Snap arguments */
  2.  
  3. signal on error
  4.  
  5. if ~show('l', "rexxarplib.library") then do
  6.     check = addlib('rexxsupport.library',0,-30,0)
  7.     check = addlib('rexxmathlib.library',0,-30,0)
  8.     check = addlib('rexxarplib.library',0,-30,0)
  9. end
  10.  
  11. if ~exists("fonts:helvetica/15") then do
  12.     say "I need font 'Helvetica 15'."
  13.     exit 10
  14. end
  15.  
  16. bool.0 = 'OFF'; bool.1 = 'ON'
  17.  
  18. /* Fix window dimensions */
  19.  
  20. screen.width = ScreenCols()
  21. screen.height = ScreenRows()
  22.  
  23. window.width = 400
  24. window.height = 200
  25. window.leftedge = (screen.width-window.width)/2
  26. window.topedge = (screen.height-window.height)/2
  27.  
  28. /* Set up a host */
  29. parse version 'V' vers .
  30. signal on syntax
  31. call stop(SNAPHOST)
  32. syntax:
  33. if vers > 1.06 then
  34.     address AREXX  "'call CreateHost(SNAPHOST, SNAPPORT)'"
  35. else
  36.     "runwsh >nil:" "'call CreateHost(SNAPHOST, SNAPPORT)'"
  37.  
  38. /*
  39. *   Wait for a while until host is ready.
  40. */
  41. do for 50 while ~show('Ports','SNAPHOST')
  42.    call delay 10  /* 200 ms */
  43. end
  44.  
  45. call SetReqColor(SNAPHOST, BLOCKPEN, 1)
  46. call SetReqColor(SNAPHOST, DETAILPEN, 0)
  47.  
  48. /*
  49. *   Open the window
  50. */
  51. window.idcmp = 'CLOSEWINDOW+GADGETUP+RAWKEY'
  52. window.flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
  53.  
  54. title = "Setup tool for Snap"
  55. snap = show('P','Snap.port')
  56. if snap then
  57.     title = title "(Snap is installed)"
  58. else
  59.     title = title "(Snap is not installed)"
  60.  
  61. call OpenWindow(SNAPHOST, window.leftedge, window.topedge, window.width, ,
  62.                 window.height, window.idcmp, window.flags, title)
  63.  
  64. call ModifyHost(SNAPHOST, RAWKEY, "RAWKEY %c")
  65.  
  66. call SetFont(SNAPHOST, "Helvetica.font", 15)
  67.  
  68. signal dotext
  69. /* --- Start of texts ---
  70. 10
  71. "      Please hold on..."    5  20 45 ""
  72. "Priority:"                  5  40  6 "Input handler priority."
  73. "Insert key:"              215  60  9 "Key used with Left Amiga to insert."
  74. "Char delay:"              215  80  9 "Delay after each inserted character"
  75. "Line delay:"              215 100  9 "Delay after each inserted newline."
  76. "Bit mask:"                215 120  9 "Bit planes to draw selection frame into."
  77. "Starting unit:"           215 140  9 "Unit in which to start snapping."
  78. "Selection frame pattern:" 215  40 19 "Pattern used for crawling dots in selection frame."
  79. "Text qualifier:"            5  60 11 "Qualifier used when snapping characters."
  80. "Gfx qualifier:"           110  60 11 "Qualifier used when snapping graphics."
  81. --- End of texts --- */
  82.  
  83. dotext:
  84. textlines = sigl+2
  85. parse value sourceline(textlines) with num .
  86.  
  87. call SetReqColor(SNAPHOST, 'BOXPEN', 0)
  88. call SetReqColor(SNAPHOST, 'SHADOWPEN', 0)
  89. call SetAPen(SNAPHOST, 1)
  90. do i=1 for num
  91.     parse value sourceline(textlines+i) with '"'text'"' x y w . '"'help'"'
  92.     call AddGadget(SNAPHOST, x, y, 'HLP'i, copies(' ',w), "HELP "help)
  93. end
  94.  
  95. call SetReqColor(SNAPHOST, 'BOXPEN', 2)
  96. call SetReqColor(SNAPHOST, 'SHADOWPEN', 3)
  97. do i=1 for num
  98.     parse value sourceline(textlines+i) with '"'text'"' x y w . '"'help'"'
  99.     call Move(SNAPHOST, x, y+10); call Text(SNAPHOST, text)
  100. end
  101.  
  102. /* Set up some nice gadgets */
  103. x = 65
  104. do i=51 for 5
  105.     call AddGadget(SNAPHOST,  x, 40, 'PR'i, ''i'', 'PRIORITY 'i); x = x+27
  106. end
  107.  
  108. ins.1 = 23;  ins.2 = 15;  ins.3 = 34
  109. key.1 = 'I'; key.2 = 'Y'; key.3 = 'V'
  110. x = 300
  111. do i=1 for 3
  112.     call AddGadget(SNAPHOST, x, 60, 'INS'i, key.i, 'INSKEY 'i); x = x+20
  113. end
  114.  
  115. x = 300
  116. do i=0 for 3
  117.     call AddGadget(SNAPHOST, x, 80, 'CDL'i, i, 'CDELAY 'i); x = x+20
  118. end
  119.  
  120. x = 300
  121. do i=0 for 3
  122.     call AddGadget(SNAPHOST, x, 100, 'LDL'i, i, 'LDELAY 'i); x = x+20
  123. end
  124.  
  125. x = 300
  126. do i=0 for 3
  127.     call AddGadget(SNAPHOST, x, 120, 'MSK'i, i, 'MASK 'i); x = x+20
  128. end
  129.  
  130. call AddGadget(SNAPHOST, 300, 140, 'UNT'0, "Frame", 'UNIT 0')
  131. call AddGadget(SNAPHOST, 300, 155, 'UNT'1, "Char ", 'UNIT 1')
  132.  
  133. call SetReqColor(SNAPHOST, 'SHADOWPEN', 0L)
  134. y = 18
  135. do i=0 for 16
  136.     call AddGadget(SNAPHOST, 380,  y, 'PAT'i, ' ', 'PATTERN 'i); y = y+11
  137. end
  138. call SetReqColor(SNAPHOST, 'SHADOWPEN', 3L)
  139.  
  140. bit.1 = 0; desc.1 = 'Left Shift '
  141. bit.2 = 1; desc.2 = 'Right Shift'
  142. bit.3 = 3; desc.3 = 'Control    '
  143. bit.4 = 4; desc.4 = 'Left Alt   '
  144. bit.5 = 5; desc.5 = 'Right Alt  '
  145. bit.6 = 6; desc.6 = 'Left Amiga '
  146. bit.7 = 7; desc.7 = 'Right Amiga'
  147.  
  148. y = 75
  149. do i=1 for 7
  150.     call AddGadget(SNAPHOST,   5, y,  'TQ'i, desc.i, 'TEXTQUAL 'i)
  151.     call AddGadget(SNAPHOST, 110, y,  'GQ'i, desc.i, 'GFXQUAL 'i)
  152.     y = y+15
  153. end
  154.  
  155. call AddGadget(SNAPHOST, 35, 180, 'XERX', 'Immediate insert', 'XEROX')
  156.  
  157. call AddGadget(SNAPHOST, 235, 180, 'APPLY', 'Apply settings', 'APPLY')
  158.  
  159. /* Open our host port */
  160. call openport(SNAPPORT)
  161.  
  162. start:
  163.  
  164. call ShowText("     Setting defaults...")
  165. pri = 51;           call SetGadget(SNAPHOST, 'PR51', 'ON')
  166. textqual = '0040'x; call SetGadget(SNAPHOST,  'TQ6', 'ON')
  167. gfxqual  = '0080'x; call SetGadget(SNAPHOST,  'GQ7', 'ON')
  168. inskey = 1;         call SetGadget(SNAPHOST, 'INS1', 'ON')
  169. cdelay = 0;         call SetGadget(SNAPHOST, 'CDL0', 'ON')
  170. ldelay = 0;         call SetGadget(SNAPHOST, 'LDL0', 'ON')
  171. pattern = '7777'x;
  172. do i=0 for 16
  173.     if bittst(pattern,i) then call SetGadget(SNAPHOST, 'PAT'i, 'ON')
  174. end
  175. xerox = 0
  176. unit = 0;           call SetGadget(SNAPHOST, 'UNT0', 'ON')
  177. planes = '00'x
  178.  
  179. call ShowText("     Select options. Click here for help.")
  180.  
  181. help.1 = "Click text (eg 'Priority') for help. Click here for more help."
  182. help.2 = "Close window for correct command line. Click for more."
  183. help.3 = "Click 'Apply settings' to reconfigure Snap."
  184. maxhelp = 3
  185.  
  186. keycmd. = ""
  187. keycmd.95 = "HELP";    keycmd.25 = "PRIORITY";  keycmd.16 = "CLOSEWINDOW"
  188. keycmd.23 = "INSKEY";  keycmd.51 = "CDELAY";    keycmd.40 = "LDELAY"
  189. keycmd.33 = "UNIT";    keycmd.32 = "APPLY"
  190.  
  191. main:
  192. quitflag = 0
  193. helpnum = 1
  194.  
  195. loop:
  196. if quitflag~=0 then signal done
  197.  
  198. call waitpkt(SNAPPORT)
  199. p = getpkt(SNAPPORT)
  200. if p == NULL() then signal loop
  201.  
  202. cmd = getarg(p)
  203. call reply(p, 0)
  204.  
  205. docmd:
  206. parse var cmd item val .
  207. signal value item
  208.  
  209. closewindow:
  210.     quitflag = 1
  211.     signal loop
  212.  
  213. rawkey:
  214.     cmd = keycmd.val
  215.     if cmd ~= "" then do
  216.         signal docmd
  217.     end
  218.     signal loop
  219.  
  220. help:
  221.     parse var cmd item help
  222.     if help="" then do
  223.         call showtext(help.helpnum)
  224.         helpnum = helpnum+1
  225.         if helpnum>maxhelp then helpnum = 1
  226.     end
  227.     else do
  228.         call showtext(help)
  229.     end
  230.     signal loop
  231.  
  232. priority:
  233.     if val="" then do
  234.         val = pri+1
  235.         if val>55 then val = 51
  236.     end
  237.     pri = val
  238.     do i=51 for 5
  239.         call setgadget(SNAPHOST, 'PR'i, 'OFF')
  240.     end
  241.     call setgadget(SNAPHOST, 'PR'pri, 'ON')
  242.     signal loop
  243.  
  244. inskey:
  245.     if val="" then do
  246.         val = inskey+1
  247.         if val>3 then val = 1
  248.     end
  249.     inskey = val
  250.     do i=1 for 3
  251.         call setgadget(SNAPHOST, 'INS'i, 'OFF')
  252.     end
  253.     call setgadget(SNAPHOST, 'INS'val, 'ON')
  254.     signal loop
  255.  
  256. cdelay:
  257.     if val="" then do
  258.         val = cdelay+1
  259.         if val>2 then val = 0
  260.     end
  261.     cdelay = val
  262.     do i=0 for 3
  263.         call setgadget(SNAPHOST, 'CDL'i, 'OFF')
  264.     end
  265.     call setgadget(SNAPHOST, 'CDL'val, 'ON')
  266.     signal loop
  267.  
  268. ldelay:
  269.     if val="" then do
  270.         val = ldelay+1
  271.         if val>2 then val = 0
  272.     end
  273.     ldelay = val
  274.     do i=0 for 3
  275.         call setgadget(SNAPHOST, 'LDL'i, 'OFF')
  276.     end
  277.     call setgadget(SNAPHOST, 'LDL'val, 'ON')
  278.     signal loop
  279.  
  280. unit:
  281.     if val="" then do
  282.         val = 1-unit
  283.     end
  284.     unit = val
  285.     call setgadget(SNAPHOST, 'UNT0', 'OFF')
  286.     call setgadget(SNAPHOST, 'UNT1', 'OFF')
  287.     call setgadget(SNAPHOST, 'UNT'unit, 'ON')
  288.     signal loop
  289.  
  290. pattern:
  291.     pattern = bitchg(pattern,val)
  292.     temp = bittst(pattern,val)
  293.     call setgadget(SNAPHOST, 'PAT'val, bool.temp)
  294.     signal loop
  295.  
  296. mask:
  297.     planes = bitchg(planes,val)
  298.     temp = bittst(planes,val)
  299.     call setgadget(SNAPHOST, 'MSK'val, bool.temp)
  300.     signal loop
  301.  
  302. textqual:
  303.     if bittst(textqual,bit.val) then do
  304.         textqual = bitclr(textqual,bit.val)
  305.         call setgadget(SNAPHOST, 'TQ'val, 'OFF')
  306.     end
  307.     else do
  308.         call setgadget(SNAPHOST, 'GQ'val, 'OFF')
  309.         gfxqual = bitclr(gfxqual,bit.val)
  310.         textqual = bitset(textqual,bit.val)
  311.         call setgadget(SNAPHOST, 'TQ'val, 'ON')
  312.     end
  313.     signal loop
  314.  
  315. gfxqual:
  316.     if bittst(gfxqual,bit.val) then do
  317.         gfxqual = bitclr(gfxqual,bit.val)
  318.         call setgadget(SNAPHOST, 'GQ'val, 'OFF')
  319.     end
  320.     else do
  321.         call setgadget(SNAPHOST, 'TQ'val, 'OFF')
  322.         textqual = bitclr(textqual,bit.val)
  323.         gfxqual = bitset(gfxqual,bit.val)
  324.         call setgadget(SNAPHOST, 'GQ'val, 'ON')
  325.     end
  326.     signal loop
  327.  
  328. xerox:
  329.     xerox = 1-xerox
  330.     call setgadget(SNAPHOST, 'XERX', bool.xerox)
  331.     signal loop
  332.  
  333. apply:
  334.     quitflag = 2
  335.     signal loop
  336.  
  337.  
  338. done:
  339. if c2d(textqual)=0 then do
  340.     call ShowText("No text qualifier specified!")
  341.     signal main
  342. end
  343. else if c2d(gfxqual)=0 then do
  344.     call ShowText("No graphics qualifier specified!")
  345.     signal main
  346. end
  347.  
  348. cmd = ""
  349. if pri~=51           then cmd = cmd "-p"pri
  350. if textqual~='0040'x then cmd = cmd "-t"c2x(textqual)
  351. if gfxqual~='0080'x  then cmd = cmd "-g"c2x(gfxqual)
  352. if key.inskey~='I'   then cmd = cmd "-i"ins.inskey
  353. if cdelay~=0         then cmd = cmd "-c"cdelay
  354. if ldelay~=0         then cmd = cmd "-l"ldelay
  355. if pattern~='7777'x  then cmd = cmd "-a"c2x(pattern)
  356. if xerox             then cmd = cmd "-x"
  357. if unit~=0           then cmd = cmd "-u"unit
  358. if planes~='00'x     then cmd = cmd "-b"c2x(planes)
  359.  
  360. snapcmd = "snap"
  361.  
  362. if quitflag=1 then do
  363.     say snapcmd || cmd
  364. end
  365. else do
  366.     if ~exists("snap") & ~exists("c:snap") then do
  367.         snapcmd = GetFile(50, 50, "sys:", "", "Find Snap for me")
  368.         if word(statef(snapcmd),1) ~= 'FILE' then do
  369.             snapcmd = snapcmd'snap'
  370.         end
  371.     end
  372.     if exists(snapcmd) then do
  373.         if snap then address command snapcmd cmd
  374.         address command snapcmd cmd
  375.     end
  376.     else do
  377.         call ShowText("Snap not found.")
  378.         signal main
  379.     end
  380. end
  381.  
  382. error:
  383. call Stop(SNAPHOST)
  384. exit
  385.  
  386. showtext: procedure expose SNAPHOST
  387.  
  388. parse arg text
  389.  
  390. call SetAPen(SNAPHOST, 0)
  391. call RectFill(SNAPHOST, 5, 15, 370, 35)
  392. call SetAPen(SNAPHOST, 1)
  393. call Move(SNAPHOST, 5, 30)
  394. call Text(SNAPHOST, text)
  395. return
  396.