home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / convtmplt / !ConvTmplt / ConvTmplt (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1993-06-08  |  23.1 KB  |  832 lines

  1.  >ConvTmplt
  2. Usage$ = "ConvTmplt <in> <out> [-Hourglass] [-Title] [-TFont <name>] [-TSize <points>] [-Icon] [-IFont <name>] [-ISize <points>] [-CheckColours] [-BValidation] [-Extent] [-IndSize <n>] [-Sort] [-Debug]"
  3.  v5.00 - CJB 08.06.1993 added -Sort ordering
  4.  v4.00 - CJB 27.01.1993 add scroll bars if old style-window & extent
  5.  v3.01 - CJB 18.01.1993 Interface v2.00 has validation strings b5, b6, and b7
  6.                         convert validation strings z0-z7
  7.  v3.00 - CJB 30.12.1992 -IndSize + wimp > 2.87 template handling uses less memory
  8.                         much better error messages
  9.                         extent => force bounded + title bar/quit icon
  10.                         only opens a font once
  11.  v2.10 - CJB 22.11.1992 changed so length of indirected buffer is 32K now
  12.      This program filters Wimp Template files (including those with fonts)
  13.      [requires CAssembler module to be resident]
  14.      It optionally converts text icons to an anti-aliased font, handling
  15.      colour correctly
  16.      would like to resize icon bbox if new anti-aliased text ends up being clipped
  17.  MACHINE:  Archimedes, RiscOS3.10 (wimp >= 2.87 better memory)
  18.  LANGUAGE: BBC BASIC V (v1.05)
  19.  AUTHOR:   Cy Booker,
  20.            86 Church View, Main Road, Crockenhill, Swanley, Kent.
  21.            BR8 8JW
  22.   Debug% = 
  23. initmemory
  24.   sizeof_q% = 512
  25. malloc(q%, sizeof_q%)
  26. _define_constants
  27. calloc(Fonts%, 256)
  28. malloc(messages%, 4)
  29.  window%(300)                      :
  30.   a reasonable upper bound
  31. malloc(windowid%, 4*
  32. (window%(), 1)):
  33.  pointer to nul-terminated window id$
  34.  FontName$(2), FontSize%(2), FontHandle%(2) : NFonts% = 0
  35.   n_windows% = 0
  36. _Lose_Fonts:
  37. (M    
  38.  we may not have to actually start a wimp task to Wimp_OpenTemplate,
  39. ))    
  40.  but it does no harm to, anyway!
  41.     $q%="TASK"
  42.     messages%!0 = 0
  43. ,`    
  44.  "Wimp_Initialise", 300, !q%, "Convert Templates", messages% 
  45.  WimpVersion%, taskhand%
  46. .7    
  47.  "XWimp_CloseDown",taskhand%,!q%:
  48. /'      
  49. _Load_Templates(input_file$)
  50.       
  51. 1&        
  52.  "Wimp_Poll",0,q%+4 
  53.       
  54.  A%=0
  55. 3(      
  56. _Save_Templates(output_file$)
  57. 4-    
  58.  "Wimp_CloseDown",taskhand%,!q%
  59. _Lose_Fonts
  60. _Lose_Fonts
  61.  i%= 0 
  62.  Fonts%?i%
  63. <!      
  64.  "XFont_LoseFont", i%
  65.       Fonts%?i% -= 1
  66. >        
  67.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. D'        creates each window in turn
  69.         sets
  70.              n_windows%
  71. G)             window%(0..n_windows%-1)
  72. HF             windowid%[0..n_windows%-1] = ptr to nul-terminate id$
  73. I%             templates_file_size%
  74. _Load_Templates(file$)
  75.  idrove%, id%, length%, r0%, c%, t%
  76.  template%, t_name%
  77.  "OS_File", 17, file$ 
  78.  r0%,,,, length%
  79.  r0%<>1 
  80.  1, "Can't open `"+ file$+ "'"
  81. Q$  templates_file_size% = length%
  82. malloc(template%, length%)
  83.  WimpVersion% < 287 
  84. malloc(id%, IndSize%)
  85. malloc(t_name%, 16)
  86.  "Wimp_OpenTemplate",, file$
  87.  "XWimp_CloseTemplate":
  88.     next% = 0
  89.     n_windows% = 0
  90.     idrove% = id%
  91. [        
  92.       t_name%!0 = 
  93. ("*")
  94.       $t_name% = "*"
  95. ^!      
  96.  WimpVersion% >= 287 
  97. _Y        
  98.  "Wimp_LoadTemplate", 0, 0, 0, 0, 0, t_name%, next% 
  99.  ,, IndSize%,,,, next%
  100.         
  101.  next% 
  102.           t_name%?12 = 13
  103.           
  104. cI          
  105. $+ " [loading window `"+ $t_name%+ "']"+ 
  106. d>            
  107.  IndSize% < 0 
  108.  1, "Negative indirect size"
  109. eS            IndSize% += 1                           :
  110.   +1 handles size == zero
  111. f&            
  112. malloc(id%, IndSize%)
  113. gY            
  114.  "Wimp_LoadTemplate",, template%, id%, id%+IndSize%, Fonts%, t_name%, 0
  115.           
  116.         
  117.       
  118. kt        
  119.  "Wimp_LoadTemplate",, template%, idrove%, id%+IndSize%, Fonts%, t_name%, next% 
  120.  ,, idrove%,,,, next%
  121.       
  122.       
  123.  next% 
  124.         t_name%?12 = 13
  125.         
  126. pH        
  127. $+ " [creating window `"+ $t_name%+ "']"+ 
  128. q>          
  129. malloc(windowid%!(n_windows%*4), 
  130. ($t_name%)+1)
  131. r7          
  132. putz(windowid%!(n_windows%*4), $t_name%)
  133. sF          
  134.  "Wimp_CreateWindow",, template% 
  135.  window%(n_windows%)
  136.           n_windows% += 1
  137.         
  138.       
  139.  next%=0
  140.  "Wimp_CloseTemplate"
  141. free(template%)
  142. free(t_name%)
  143.  n_windows%=0 
  144.  1, "No windows in template file"
  145.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146. /        Needs external templates_file_size%
  147. O        This is so can allocate a big enough buffer to guarantee no need to
  148. %        check for buffer overflow
  149. T        builds entire template in memory and then blits the lot to a file at end
  150. U        this has the side-effect of maybe increasing the file size by a couple of
  151. Z        bytes per template, because need each template to start on a word-aligned word
  152. W        If an error occurs you lose some memory, but who cares - it gets given back
  153.         when the app dies.
  154. _Save_Templates(file$)
  155.  FontH%, sizeof_hdr%, sizeof_whdr%, sizeof_font%
  156.  newfonts%, buffer%, ind%, temp%, win%, rove%, i%, j%
  157.  n_icons%, icons%, icon%
  158.  window$, icon$
  159.  array%, a%, P%, L%, O%, code%, lr, sp, pass%
  160.  Hourglass% 
  161.  "XHourglass_On"
  162. _Hourglass_Off:
  163.     FontH% = 1
  164.     sizeof_hdr%  = 16
  165.     sizeof_whdr% = 24
  166.     sizeof_font% = 48
  167. calloc(newfonts%, 256)
  168. A    
  169. malloc(buffer%, templates_file_size%*2 + 2*sizeof_font%)
  170. F    
  171. malloc(ind%, 256)        :
  172.  scratch space for indirected text
  173. J    
  174. malloc(temp%, 16)        :
  175.  scratch space for non-indirected text
  176. $    win% = buffer% + sizeof_hdr%
  177. 6    rove% = win% + (n_windows% * sizeof_whdr%) + 4
  178. %    
  179. malloc(array%, n_windows%*4)
  180.  i%= 0 
  181.  n_windows%-1
  182. +      array%!(i%*4) = n_windows%-1 - i%
  183.  Sort% 
  184.       L% = 18*4
  185. &      
  186. malloc(code%, L%):L%+=code%
  187.       lr = 14
  188.       sp = 13
  189. $      
  190.  pass%= %1100 
  191.  %1110 
  192.         P% = 0:O% = code%
  193.         [OPT pass%
  194.         STMFD   (sp)!, {lr}
  195. G        LDR     R2, [R12, R0, LSL #2]           ; pointer to string
  196. G        LDR     R3, [R12, R1, LSL #2]           ; pointer to string
  197.         MVN     R0, #0
  198. .        SWI     "Territory_LowerCaseTable"
  199.         .loop
  200.          LDRB    R1, [R2], #1
  201.          LDRB    lr, [R3], #1
  202.          LDRB    R1, [R0, R1]
  203.          LDRB    lr, [R0, lr]
  204.         TEQ     R1, #0
  205. !        Beq     end_of_string
  206.         CMP     R1, lr
  207.         Beq     loop
  208.         LDMFD   (sp)!, {pc}
  209.         .end_of_string
  210.         CMP     lr, #0
  211.         LDMFD   (sp)!, {pc}
  212.         ]
  213.       
  214.  pass%
  215. @      
  216.  "OS_HeapSort", n_windows%, array%, code%, windowid%
  217.         
  218. &    
  219.   process each window in turn
  220.  a%= 0 
  221.  n_windows%-1
  222.       i% = array%!(a%*4)
  223. +      window$ = 
  224. getz(windowid%!(i%*4))
  225.       
  226. <      
  227. $+ " [window `"+ window$+ "']"+ 
  228. U        
  229.  Hourglass% 
  230.  "XHourglass_Percentage", (n_windows%-i%)*100/n_windows%
  231. :        
  232.  may extend file length a bit, but who cares!
  233. %        rove% = (rove% + 3) 
  234.         
  235.  department of...
  236. $        
  237.  rove%!-4, window%(i%)
  238. -        
  239.  "Wimp_GetWindowInfo",, rove%-4
  240. $        
  241.  rove%!-4, window%(i%)
  242.         
  243.  ... dirty tricks
  244. D        win%!0 = rove% - buffer%                  :
  245.  file offset
  246. O        win%!4 = rove%                            :
  247.  so can calc total size
  248. K        rove%!24 = &C0B00639                      :
  249.  window open behind
  250. G        rove%!64 = 1                              :
  251.  System sprites
  252.         xmin% = rove%!40
  253.         ymin% = rove%!44
  254.         xmax% = rove%!48
  255.         ymax% = rove%!52
  256.         n_icons% = rove%!84
  257.         icons% = rove% + 88
  258. ,        rove% = icons% + (32 * n_icons%)
  259.         
  260. 0        
  261. $+ " [titlebar]"+ 
  262. w          
  263. _Relocate_Icon_Data(win%!4, rove%, win%!4 + 56, win%!4 + 72, AlterTitle%, TitleFont$, TitleFontSize%, 
  264.         
  265.         icon% = 0
  266.         
  267.  icon% < n_icons%
  268.           icon$ = 
  269. (icon%)
  270.           
  271. :          
  272. $+ " [icon "+ icon$+ "]"+ 
  273. ~            
  274. _Relocate_Icon_Data(win%!4, rove%, icons%+16, icons%+20, AlterIcon%, IconFont$, IconFontSize%, CheckColours%)
  275. 1            
  276.  xmin%>icons%!0 
  277.  xmin%=icons%!0
  278. 1            
  279.  ymin%>icons%!4 
  280.  ymin%=icons%!4
  281. 1            
  282.  xmax%<icons%!8 
  283.  xmax%=icons%!8
  284. 3            
  285.  ymax%<icons%!12 
  286.  ymax%=icons%!12
  287.             icons% += 32
  288.             icon% += 1
  289.           
  290.         
  291.         
  292.  Extent% 
  293.           icons% = win%!4
  294.            flags% = icons%!28
  295. L          flags% = flags% 
  296.  (1 << 6)              :
  297.  window is bounded
  298. N          flags% = flags% 
  299.  (1 << 26)                  :
  300.  title bar exists
  301. O          flags% = flags% 
  302.  (1 << 25)                  :
  303.  close window icon
  304.           
  305.  flags% >= 0 
  306. N            flags% = flags% 
  307.  &0000008D                :
  308.  old-style window
  309.           
  310. M          
  311.  ((xmax%+0.0 - xmin%) > 900.0) 
  312.  (ymax%+0.0 - ymin%) > 900.0 
  313. I            flags% = flags% 
  314.  &70000000                :
  315.  scroll bars
  316.           
  317.            icons%!28 = flags%
  318.           icons%!40 = xmin%
  319.           icons%!44 = ymin%
  320.           icons%!48 = xmax%
  321.           icons%!52 = ymax%
  322.           icons%!0 = 0
  323.           icons%!4 = 0
  324. &          icons%!8 = xmax% - xmin%
  325. '          icons%!12 = ymax% - ymin%
  326.         
  327. M        win%!4 = rove% - win%!4                   :
  328.  total size of window
  329. @        win%!8 = 1                                :
  330.  sprites
  331. C        $buffer% = 
  332. window$+ 
  333. (13)+ "Cy Booker", sizeof_hdr%-1)
  334.         win%!12 = buffer%!0
  335.         win%!16 = buffer%!4
  336.         win%!20 = buffer%!8
  337.          win% += sizeof_whdr%
  338.       
  339.     H    !win% = 0                                   :
  340.   flag last window
  341.  FontH% = 1 
  342. @      !buffer% = -1                             :
  343.   no fonts
  344.         
  345. K      !buffer% = rove% - buffer%                :
  346.   offset to font info
  347. &      
  348.  i%= 0 
  349.  sizeof_font%-1 
  350.         rove%!i% = 0
  351.       
  352.       
  353.  i%= 1 
  354.  FontH%-1
  355.         j% = 0
  356.         
  357.           j% += 1
  358.         
  359.  newfonts%?j% = i%
  360. A        
  361.  "Font_ReadDefn", j%, rove%+8 
  362.  ,, rove%!0, rove%!4
  363. !        rove% += sizeof_font%
  364.       
  365.         
  366. #    
  367.  i%= 4 
  368.  sizeof_hdr%-1 
  369.       buffer%!i% = 0
  370. 6    
  371.  "OS_File", 10, file$, &FEC,, buffer%, rove%
  372. free(newfonts%)
  373. free(buffer%)
  374. free(ind%)
  375. free(temp%)
  376. _Hourglass_Off
  377.         simply turn it off
  378. _Hourglass_Off
  379.  Hourglass% 
  380.  "XHourglass_Off"
  381. +M        base% is for offset calculations, so 'rove% - base%' is an offset
  382. ,Z               (actually, uses fact this points to window base. for background colour)
  383. -Q        rove% points to memory buffer that gets filled with icons' extra data
  384. .1        flags% points to the icons' flag word
  385. /1        data% points to the icons' data words
  386. 0;        alter% is 
  387.  if change text icon to anti-aliased
  388. 1=        font$ is the name of the anti-aliased font to use
  389. 2C        size% is the point size of the anti-aliased font to use
  390. 38        colours% is 
  391.  if check the validation string
  392. 4:        uses the external 'UpdateBValidation%' boolean
  393. 5U        Note: if UpdateBValidation% and alter% and indirected text and validation
  394. 6B        string, then assume icons' bbox is stored at flags%-16
  395. _Relocate_Icon_Data(base%, 
  396.  rove%, flags%, data%, alter%, font$, size%, colours%)
  397.  fore%, back%, do_it%, i%
  398.  !flags% 
  399.  &040 
  400.  is anti-aliased
  401. <@    
  402.  (!flags% 
  403.  1) = 0 
  404.  1, "Anti-aliased font, no text!"
  405. _handle_font(flags%)
  406. >C    
  407.  alter% 
  408.  colours% 
  409.  ((!flags% 
  410.  &0000F000) < &0000E000) 
  411. ?A      
  412. _Alter_Font_Colours(flags%, base%?34, base%?35, data%)
  413. @        
  414.  not anti-aliased
  415. C.    
  416.  alter% 
  417.  ((!flags% 
  418.  &001) = &001) 
  419. D-      
  420.  text, force it to be anti-aliased
  421. E%      
  422.  ((!flags% 
  423.  &100) <> 0) 
  424. FQ        
  425.  is indirected, need to check if multi-line (can't be anti-aliased!)
  426. G#        do_it% = (data%!4 <= 0)
  427.         
  428.  do_it% 
  429. IG          do_it% = 
  430. _find_validation_string($(data%!4), "Ll", i%)
  431.         
  432.       
  433.         
  434.  not indirected
  435. M-        
  436.   but ignore "empty" text fields
  437. N!        do_it% = ?data% <> 13
  438.       
  439.       
  440.  do_it% 
  441. Q)        fore% = (!flags% >> 24) 
  442. R         
  443.  (!flags% 
  444.  &020) 
  445. S,          
  446.  filled background, so use it
  447. T+          back% = (!flags% >> 28) 
  448.         
  449. V/          
  450.  unfilled, use window background
  451.           back% = base%?35
  452.         
  453. Y0        flags%?3 = 
  454. _Find_Font(font$, size%)
  455. Z!        
  456. _handle_font(flags%)
  457. [/        
  458.  fore%=back% 
  459.  back% = fore% 
  460. \$        !flags% = !flags% 
  461.  &040
  462.         
  463.  colours% 
  464. ^?          
  465. _Alter_Font_Colours(flags%, fore%, back%, data%)
  466.         
  467.       
  468. a        
  469.  (!flags% 
  470.  &103) > &100 
  471. d     
  472.  indirected data exists
  473. e.    
  474. _Relocate_Data(base%, rove%, data%!0)
  475. f0    
  476.  (data%!4 > 0) 
  477.  ((!flags% 
  478.  1) <> 0) 
  479.       
  480.  validation string
  481. h5      
  482.  UpdateBValidation% 
  483.  (flags% = data%-4) 
  484. i9        
  485. _Massage_Validation_String(base%, flags%-16)
  486.       
  487. k0      
  488. _Relocate_Data(base%, rove%, data%!4)
  489. l        
  490. m        
  491.  (!flags% 
  492.  3) = 2 
  493. o>      data%!4 = 1                       :
  494.   sprite pointer
  495. p        
  496. t)        icon% points to an icon block
  497. uS        assume it is an indirected icon, with a valid validation string pointer
  498. vU        this converts any "B"order validations to "R"iscOS3.10 border validations
  499. wU        note that the validation string could be shortened, and the bbox updated!
  500. _Massage_Validation_String(base%, icon%)
  501.  dx%, dy%, i%, j%, ind$, n$
  502.   ind$ = $(icon%!24)
  503. _find_validation_string(ind$, "BbzZ", i%) 
  504. ind$, i%+1, 1) 
  505. ~)    
  506.  "0":dx% = 4 :dy% =  4:n$ = "R5"
  507. )    
  508.  "1":dx% = 8 :dy% =  8:n$ = "R3"
  509. )    
  510.  "2":dx% = 16:dy% = 16:n$ = "R6"
  511. +      
  512.  ((icon%!16 
  513.  &F000) >= &E000) 
  514.         
  515.   writable icon
  516. ,             dx% =  8:dy% =  8:n$ = "R7"
  517.       
  518. ,             dx% =  8:dy% =  8:n$ = "R2"
  519.       
  520. )    
  521.  "4":dx% =  4:dy% =  4:n$ = "R2"
  522. )    
  523.  "5":dx% = 16:dy% = 16:n$ = "R7"
  524. )    
  525.  "6":dx% =  8:dy% =  8:n$ = "R7"
  526. )    
  527.  "7":dx% =  2:dy% =  4:n$ = "R1"
  528. )    
  529.  "8":dx% =  4:dy% =  4:n$ = "R1"
  530. B    
  531.  1, "Unknown validation string (`"+ 
  532. ind$, i%, 2)+ "')"
  533.         
  534.     j% = 
  535. ind$, ";", i%)
  536.  j% = 0 
  537. !      ind$ = 
  538. ind$, i%-1)+ n$
  539.         
  540. -      ind$ = 
  541. ind$, i%-1)+ n$+ 
  542. ind$, j%)
  543.         
  544.     $(icon%!24) = ind$
  545.     icon%!0 -= dx%
  546.     icon%!4 -= dy%
  547.     icon%!8 += dx%
  548.     icon%!12 += dy%
  549.     icon%!16 = icon%!16 
  550.      base%!28 = base%!28 
  551. e        This routine maps the current (displayed) font handle to the external (saved) font handle
  552. ]        flags% points to the icon flags word, so flags%?3 is the font handle that changes
  553. '        updates the global 'FontH%'
  554. _handle_font(flags%)
  555.  external_FontH%, internal_FontH%
  556.    external_FontH% = flags%?3
  557. 1  internal_FontH% = newfonts%?external_FontH%
  558.  internal_FontH%=0 
  559.      internal_FontH% = FontH%
  560.     FontH% += 1
  561. 3    newfonts%?external_FontH% = internal_FontH%
  562.    flags%?3 = internal_FontH%
  563. 1        flags% points to the icons' flag word
  564. 1        data% points to the icons' data words
  565. 8         fore% is the desired foreground wimp colour
  566. 8         back% is the desired background wimp colour
  567. @        This is used to ensure fonts are displayed correctly
  568. P        Ie we want to make sure that the icon has a "F"ont validation string
  569. 2        If one already exists, then do nothing
  570.         Otherwise add one.
  571. K        If not indirected then use two scratchspaces and alter the data
  572. )        uses temp% points to 13 bytes
  573. )        uses ind% points to 256 bytes
  574. 5        Note, may alter data%!0, data%!4, data%!8
  575. 9        Note, may alter !flags% (
  576.  &100 = indirected)
  577. _Alter_Font_Colours(flags%, fore%, back%, data%)
  578.  i%, found%
  579.  ind$
  580.  (!flags% 
  581.  &041)<>&041 
  582.  1, "Attempt to change colour of non-anti-aliased text"
  583.   ind$ = ""
  584.  (!flags% 
  585.  &100) 
  586.  data%!4 > 0 
  587.       ind$ = $(data%!4)
  588. ;      found% = 
  589. _find_validation_string(ind$, "Ff", i%)
  590.         
  591. P    
  592.   have to force icon to be indirected so can create a validation string
  593.     found% = 
  594.      !flags% = !flags% 
  595.  &100
  596. F    temp%!0 = data%!0                   :
  597.  copy text to safe place
  598.     temp%!4 = data%!4
  599.     temp%!8 = data%!8
  600.     temp%?12 = 13
  601. 6    data%!0 = temp%                   :
  602.  fake text
  603. G    data%!4 = -1                                :
  604.  dummy validation
  605. @    data%!8 = 
  606. ($temp%)+1           :
  607.  size of buffer needed
  608.  found% 
  609.  ind$ <> "" 
  610.       
  611. ind$, 1)<> ";" 
  612.         ind$ += ";"
  613.       
  614.         
  615. 9    $ind% = ind$+ "F"+ 
  616. colour(back%)+ 
  617. colour(fore%)
  618.     data%!4 = ind%
  619. J        returns a single-character string for the given wimp colour n%
  620. B        this character is used in the "F"ont validation string
  621. colour(n%)
  622. "0123456789ABCDEF", (n% 
  623.  &0F) + 1, 1)
  624. C        massages !data% to contain offsets rather than pointers
  625. *        and places the data at rove%++
  626. _Relocate_Data(base%, 
  627.  rove%, 
  628.  data%)
  629.   $rove% = $data%
  630.   data% = rove% - base%
  631.   rove% += 
  632. ($rove%)+1
  633.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634.      dynamic memory routines
  635.      this manages a heap above the workspace of basic
  636.      automatically growing/shrinking as needed
  637. initmemory
  638.  heap% 16
  639.   heap%!0 = 0
  640.  "CAssembler_Heap", 0, heap%, 32*1024
  641. calloc(
  642.  p%, size%)
  643.  "CAssembler_Heap", 5, heap%, size% 
  644. malloc(
  645.  p%, size%)
  646.  "CAssembler_Heap", 1, heap%, size% 
  647. free(
  648.  "CAssembler_Heap", 2, heap%, p%
  649.   p% = 0
  650.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  651.  Debug% 
  652.     e$ = ", ["+ 
  653. )+ "]"
  654.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  655. ,        Used to add a font to any window
  656. Y        Ie it updates the global font count array (as used when loaded the templates)
  657.         returns the handle
  658. ?        Uses global `cache' of which fonts have been opened
  659. J        Since we only ever have, at most, 2 fonts (title/icon) then no
  660. ;        point using anything other than a linear search
  661. Q        If don't use this cache, then if a template file has > 255 text icons
  662. 6        then we end up opening this too many times
  663. _Find_Font(name$, point_size%)
  664.  handle%, found%, i%
  665.   i% = 0
  666.   found% = 
  667.  (i% < NFonts%) 
  668.  found%
  669. #J    found% = ((name$ = FontName$(i%)) 
  670.  (point_size% = FontSize%(i%)))
  671.  found% 
  672.       i% += 1
  673. &        
  674.  found% 
  675. )!    handle% = FontHandle%(i%)
  676. +R    
  677.  "Font_FindFont",, name$, point_size%*16, point_size%*16, 0, 0 
  678.  handle%
  679. ,6    
  680.  Fonts%?handle% = 255 
  681.  1, "Too many fonts"
  682.     Fonts%?handle% += 1
  683. ."    FontName$(NFonts%) = name$
  684. /(    FontSize%(NFonts%) = point_size%
  685. 0&    FontHandle%(NFonts%) = handle%
  686.     NFonts% += 1
  687. = handle%
  688.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  689. 7@        validations$ is the possibly empty validation string
  690. 8>        find$ is a string of single characters (eg "FfRr")
  691. 9S        This routine returns 
  692.  if any of the semi-colon separated fields of the
  693. :V        validation string start (after any space) with a letter of the find string
  694. ;N        If success then i% is the index (from 1) of the matching character
  695. _find_validation_string(validation$, find$, 
  696.  found%
  697.   i% = 1
  698. A#    
  699. validation$, i%, 1)=" "
  700.       i% += 1
  701. C        
  702. D'    found% = (i% <= 
  703. (validation$))
  704.  found% 
  705. F6      found% = (
  706. find$, 
  707. validation$, i%, 1)) > 0)
  708. G        
  709.  found% 
  710. I+      i% = 
  711. validation$, ";", i%+1) + 1
  712. J        
  713.  found% 
  714.  (i% = 1)
  715. = found%
  716.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717.      This scans the command line for parameters
  718.      If none found then prompt user to edit program/use command line
  719. _define_constants
  720.  b%, p%, C%, V$
  721. U!  input_file$ = "$.Templates"
  722. V#  output_file$ = "$.Templates1"
  723. W;  Hourglass% = 
  724.              :
  725.  boolean, show hourglass
  726. XP  AlterTitle%   = 
  727.                   :
  728.   force title font to be anti-aliased
  729. Y$  TitleFont$ = "Homerton.Medium"
  730. Z-  TitleFontSize% = 12        :
  731.  in points
  732. [O  AlterIcon%   = 
  733.                   :
  734.   force text icons to be anti-aliased
  735. \#  IconFont$ = "Homerton.Medium"
  736. ],  IconFontSize% = 13        :
  737.  in points
  738. ^K  CheckColours% = 
  739.               :
  740.   ensure "F" validation string is ok
  741. _K  UpdateBValidation% = 
  742.      :
  743.  "b" translates to "r" validation string
  744.   Extent% = 
  745.   IndSize% = 32 * 1024
  746.   Sort% = 
  747.  "OS_GetEnv" 
  748.  "XOS_ReadVarVal", "ConvTmplt$Parameters", q%, -1, 0, 0 
  749.  ,, b%
  750.  b% < 0 
  751. fB    
  752. _get_var_value(p$, "ConvTmplt$Parameters", q%, sizeof_q%)
  753.     V$ = "Debug/s,Hourglass/s,Title/s,TFont/k,TSize/e,Icon/s,IFont/k,ISize/e,CheckColours/s,BValidation/s,Extent/s,IndSize/e,Sort/s"
  754. hA    
  755.  "XOS_ReadVarVal", "ConvTmplt$In", q%, -1, 0, 0 
  756.  ,, b%
  757.  b% < 0 
  758. jE      
  759. _get_var_value(input_file$, "ConvTmplt$In", q%, sizeof_q%)
  760. kG      
  761. _get_var_value(output_file$, "ConvTmplt$Out", q%, sizeof_q%)
  762. l8      
  763.  "XOS_ReadArgs", V$, p$, q%, sizeof_q% 
  764.       b% = q% - 20
  765. n        
  766. oG      
  767.  "XOS_ReadArgs", "In/a,Out/a,"+ V$, p$, q%, sizeof_q% 
  768.       b% = q% - 12
  769. q#      
  770. getz(input_file$, b%!12)
  771. r$      
  772. getz(output_file$, b%!16)
  773. s        
  774. t/    
  775.  (C% 
  776.  1, p$:
  777. "Usage: "+ Usage$
  778. u(    
  779. getb(Debug%,             b%!20)
  780. v(    
  781. getb(Hourglass%,         b%!24)
  782. w(    
  783. getb(AlterTitle%,        b%!28)
  784. x(    
  785. getz(TitleFont$,         b%!32)
  786. y(    
  787. geti(TitleFontSize%,     b%!36)
  788. z(    
  789. getb(AlterIcon%,         b%!40)
  790. {(    
  791. getz(IconFont$,          b%!44)
  792. |(    
  793. geti(IconFontSize%,      b%!48)
  794. }(    
  795. getb(CheckColours%,      b%!52)
  796. ~(    
  797. getb(UpdateBValidation%, b%!56)
  798. (    
  799. getb(Extent%,            b%!60)
  800. (    
  801. geti(IndSize%,           b%!64)
  802. (    
  803. getb(Sort%,              b%!68)
  804. _get_var_value(
  805.  val$, var$, q%, sizeof_q%)
  806.  len%
  807.  "OS_ReadVarVal", var$, q%, sizeof_q%, 0, 0 
  808.  ,, len%
  809. )  q%?len% = 13    :
  810.  terminate string
  811.   val$ = $q%
  812.  "OS_SetVarVal", var$, q%, -1, 0, 0
  813. geti(
  814.  var, p%)
  815.     var = 
  816. geti(p%)
  817. geti(q%)
  818.  q%=q%!1
  819. getb(
  820.  var, p%)
  821.     var = (var = 0)
  822. getz(
  823.  var$, p%)
  824.     var$ = 
  825. getz(p%)
  826. getz(q%)
  827. ?q%>=32:V$+=
  828. (?q%):q%+=1:
  829. putz(A%,A$)
  830.   $A%=A$:A%?
  831. (A$)=0
  832.