home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ebooke.zip / BKEYS.E < prev    next >
Text File  |  1994-07-27  |  129KB  |  3,596 lines

  1. /*         Tagged-file Support Main Macro; Version 2.2  */
  2. /*                                                      */
  3. /* This is the main processing macro for the tagged-    */
  4. /* file syntax support, part of EBOOKIE PACKAGE from    */
  5. /* PCTOOLS.                                             */
  6. /*                                                      */
  7. /* It intercepts the following keys:                    */
  8. /*   tab ....... tab word (variable)                    */
  9. /*   backtab ... backtab word (variable)                */
  10. /*   space ..... check for tag                          */
  11. /*   c_space ... check for tag                          */
  12. /*   c_enter ... check for tag                          */
  13. /*   enter ..... check for tag                          */
  14. /*   up ........ check for tag                          */
  15. /*   down ...... check for tag                          */
  16. /*   pgup ...... check for tag                          */
  17. /*   pgdn ...... check for tag                          */
  18. /*   tag_start . start of tag (configurable)            */
  19. /*   tag_end ... check for tag (configurable)           */
  20. /*   a_1 ....... edit imbed file                        */
  21. /*   a_2 ....... enter remembered tag                   */
  22. /*   a_h ....... get keyword help                       */
  23. /*   c_h ....... view tag reference                     */      /* temple */
  24. /*   a_i ....... index                                  */
  25. /*   and all other keys of the keyboard.                */
  26. /*                                                      */
  27. /* The following commands are supported:                */
  28. /*   bookie .... Force start/stop of tag support        */
  29. /*   bookief ... Define tag-definition files            */
  30. /*   bkmattr ... Insert attibutes (optional)            */
  31. /*   bkmsym .... Replace all chars with symbols (opt.)  */
  32. /*   bkmdebug .. Debugging support (optional)           */
  33. /*                                                      */
  34. /* For the change history refer to EBOOKIE SCRIPT.      */
  35. /*                                                      */
  36.  
  37. /* Check if we are in the main E.E compilation, or      */
  38. /* if the support is compiled separately.               */
  39. compile if not defined(BLACK)
  40.   const bkm_is_external=1
  41.   include 'stdconst.e'
  42.   include 'colors.e'
  43.   tryinclude 'mycnf.e'
  44. compile if not defined(EBOOKIE_ENH)
  45.   const EBOOKIE_ENH = 0
  46. compile endif
  47. compile if EBOOKIE_ENH = 1
  48. ;  include 'EPMGCNF.SMP'
  49. compile if not defined(NLS_LANGUAGE)
  50.   NLS_LANGUAGE = 'ENGLISH'
  51. compile endif
  52. include NLS_LANGUAGE'.e'
  53. compile endif
  54. compile if EPM & EVERSION < '5.16'
  55.   tryinclude 'econfig.e'
  56. compile endif
  57. ;  include 'stdcnf.e'
  58. compile else
  59.   const bkm_is_external=0
  60. compile if not defined(EBOOKIE_ENH)
  61.   const EBOOKIE_ENH = 0
  62. compile endif
  63. compile endif
  64.  
  65. /* First we check the version of the editor. The        */
  66. /* minimum version required are the .12 versions. If    */
  67. /* the user has a wrong version, compiling terminates   */
  68. /* with an error message.                               */
  69. compile if E3
  70.   compile if EVERSION < '3.12'
  71.     *** EBOOKIE: Error, incorrect version of E3, must be at least 3.12.
  72.   compile endif
  73. compile endif
  74.  
  75. compile if EOS2
  76.   compile if EVERSION < '4.12'
  77.     *** EBOOKIE: Error, incorrect version of EOS2, must be at least 4.12.
  78.   compile endif
  79. compile endif
  80.  
  81. compile if EPM
  82.   compile if EVERSION < '5.12'
  83.     *** EBOOKIE: Error, incorrect version of EPM, must be at least 5.12.
  84.   compile endif
  85. compile endif
  86.  
  87. /* First we have to define some constants.              */
  88. CONST
  89.   bkm_version='2.10'
  90.  
  91. /* LAM:  Define these as STDCNF.E would:                */
  92. compile if not defined(ENHANCED_ENTER_KEYS)
  93.    ENHANCED_ENTER_KEYS = 0
  94. compile endif
  95. compile if not defined(ENTER_ACTION)
  96.    ENTER_ACTION   = 'ADDLINE'
  97. compile endif
  98. compile if not defined(EPATH)
  99.  compile if EPM    -- EPM uses a different name, for easier coexistance
  100.    EPATH= 'epmpath'
  101.  compile else
  102.    EPATH= 'epath'
  103.  compile endif
  104. compile endif
  105.  
  106.    ANY_CLASS = 0
  107.    COLOR_CLASS = 1
  108.  
  109. /* Check whether the user wants to replace the colons   */
  110. /* of invalid tags with "&gml." or "&colon" If it is    */
  111. /* zero, the colons are not replaced.                   */
  112. compile if defined(my_bkm_repl_colon)
  113.   bkm_repl_colon=my_bkm_repl_colon
  114. compile else
  115.   bkm_repl_colon=1
  116. compile endif
  117.  
  118. /* The default tag-definition file.                     */
  119. compile if defined(my_bkm_def_file)
  120.   bkm_def_file=my_bkm_def_file
  121. compile else
  122.   bkm_def_file='BKMTAGS.DEF'
  123. compile endif
  124.  
  125. /* Change margins?                                      */
  126. compile if defined(my_bkm_margins)
  127.   bkm_margins=my_bkm_margins
  128. compile else
  129.   bkm_margins='1 70 1'
  130. compile endif
  131.  
  132. /* Define if EBOOKIE is allowed to change the margins when      */
  133. /* switching to a non-ebookie file. Note: this only has an      */
  134. /* effect in E3. '0' means that EBOOKIE is allowed to change    */
  135. /* the margins, '1' means that EBOOKIE will not change the      */
  136. /* margins.                                                     */
  137. compile if defined(my_bkm_dont_touch_margins)
  138.   compile if E3
  139.     bkm_dont_touch_margins=my_bkm_dont_touch_margins
  140.   compile else
  141.     bkm_dont_touch_margins=0
  142.   compile endif
  143. compile else
  144.   bkm_dont_touch_margins=0
  145. compile endif
  146.  
  147. /* Dynamic margins?                                     */
  148. compile if defined(my_bkm_tags_between)
  149.   bkm_tags_between=my_bkm_tags_between
  150. compile else
  151.   bkm_tags_between=''
  152. compile endif
  153. compile if bkm_tags_between <> ''
  154. compile if bkm_dont_touch_margins
  155.     *** EBOOKIE: Error, conflicting options 'my_bkm_tags_between' and 'my_bkm_dont_touch_margins'.
  156. compile endif
  157. compile endif
  158.  
  159. /* Debugging?                                           */
  160. compile if defined(my_bkm_debugging)
  161.   bkm_debugging=my_bkm_debugging
  162. compile else
  163. compile if bkm_is_external
  164.   bkm_debugging=1            -- include debugging if externally linked
  165. compile else
  166.   bkm_debugging=0            -- save space, don't include debugging
  167. compile endif
  168. compile endif
  169.  
  170. /* Define the page-up routine                           */
  171. compile if defined(my_bkm_page_up)
  172.   bkm_page_up=my_bkm_page_up
  173. compile else
  174.   bkm_page_up=0
  175. compile endif
  176.  
  177. /* Define the page-down routine                         */
  178. compile if defined(my_bkm_page_down)
  179.   bkm_page_down=my_bkm_page_down
  180. compile else
  181.   bkm_page_down=0
  182. compile endif
  183.  
  184. /* Define the line-up routine                           */
  185. compile if defined(my_bkm_line_up)
  186.   bkm_line_up=my_bkm_line_up
  187. compile else
  188.   bkm_line_up=0
  189. compile endif
  190.  
  191. /* Define the line-down routine                         */
  192. compile if defined(my_bkm_line_down)
  193.   bkm_line_down=my_bkm_line_down
  194. compile else
  195.   bkm_line_down=0
  196. compile endif
  197.  
  198. /* Define the enter-key routine                         */
  199. compile if defined(my_bkm_enter)
  200.   bkm_enter=my_bkm_enter
  201. compile else
  202.   bkm_enter=0
  203. compile endif
  204.  
  205. /* Define if we want to replace special keys with the   */
  206. /* appropriate BookMaster symbols.                      */
  207. compile if defined(my_bkm_want_symbols)
  208.   bkm_want_symbols=my_bkm_want_symbols
  209. compile else
  210.   bkm_want_symbols=1
  211. compile endif
  212.  
  213. compile if bkm_want_symbols
  214.   compile if defined(my_bkm_codepage)
  215.     bkm_cdpg=my_bkm_codepage
  216.   compile else
  217.     bkm_cdpg='437'
  218.   compile endif
  219. compile endif
  220.  
  221. /* Define the number of lines searched when no footprint*/
  222. /* is found, or the extension does not indicate a tagged*/
  223. /* file.                                                */
  224. compile if defined(my_bkm_search)
  225.   bkm_search=my_bkm_search
  226. compile else
  227.   bkm_search=0
  228. compile endif
  229.  
  230. /* Define the file extensions for which you want the support to */
  231. /* be started automatically. If you set this constant to blank  */
  232. /* the file extension is not used to determine the file type.   */
  233. compile if defined(my_bkm_files)
  234.   bkm_files=my_bkm_files
  235. compile else
  236.   bkm_files='SCR BKM SCT FOI IPF SCRIPT STYLE'
  237. compile endif
  238.  
  239. /* Define which definition is to be used with a specific extenstion */
  240. compile if defined(my_bkm_ext_def)
  241.   bkm_ext_def=my_bkm_ext_def
  242. compile else
  243.   bkm_ext_def=''
  244. compile endif
  245.  
  246. /* Define the parameter expansion. "ALL" means that the space   */
  247. /* key always expands all parameters, "USUAL" (which is the     */
  248. /* default) expands only the usual parameters (c-enter or       */
  249. /* c-space then expands all parameters).                        */
  250. compile if defined(my_bkm_space_key)
  251.   bkm_space_key=my_bkm_space_key
  252. compile else
  253.   bkm_space_key='USUAL'
  254. compile endif
  255.  
  256. /* Define the attribute support. This is only available in EPM  */
  257. compile if EVERSION > '5.15'
  258. compile if defined(my_bkm_attr)
  259.   bkm_attr=my_bkm_attr
  260. compile if defined(my_bkm_attr_colors)
  261.   bkm_attr_colors=my_bkm_attr_colors
  262. compile else
  263.   bkm_attr_colors=223  -- White + Light_MagentaB
  264. compile endif
  265. compile if defined(my_bkm_attr_init)
  266.   bkm_attr_init=my_bkm_attr_init
  267. compile else
  268.   bkm_attr_init=0
  269. compile endif
  270. compile else  -- else not defined(my_bkm_attr)
  271.   bkm_attr=0
  272. compile endif
  273. compile else  -- else EVERSION <= 5.15
  274.   bkm_attr=0
  275. compile endif
  276.  
  277. /* Define the index support. */
  278. compile if defined(my_bkm_idx_supp)
  279.   bkm_idx_supp=my_bkm_idx_supp
  280. compile else
  281.   bkm_idx_supp=1
  282. compile endif
  283.  
  284. compile if bkm_idx_supp
  285.   compile if defined(my_bkm_keep_index_cases)
  286.     bkm_keep_index_cases=my_bkm_keep_index_cases
  287.   compile else
  288.     bkm_keep_index_cases=0
  289.   compile endif
  290. compile endif
  291.  
  292. /* Define the help support. */
  293. compile if defined(my_bkm_help_support)
  294.   bkm_help_support=my_bkm_help_support
  295. compile else
  296.   bkm_help_support=1
  297. compile endif
  298.  
  299. /* Define the help support. */               /* temple */
  300. compile if defined(my_bkm_help_reference)
  301.   compile if EPM
  302.     bkm_help_reference=my_bkm_help_reference
  303.   compile else
  304.     bkm_help_reference=0                    /* NO in DOS mode */
  305.   compile endif
  306. compile else
  307.   compile if EPM
  308.     bkm_help_reference=1                    /* Only in EPM */
  309.   compile else
  310.     bkm_help_reference=0                    /* otherwise no */
  311.   compile endif
  312. compile endif
  313.  
  314. compile if not defined(KEEP_HELP_AT_RIGHT)
  315.    KEEP_HELP_AT_RIGHT = 1   -- Ensure that the Help menu is rightmost
  316. compile endif
  317.  
  318. compile if not defined(TILDE_CHAR)
  319.  compile if EVERSION < '5.21'
  320.    TILDE_CHAR = ''
  321.  compile else
  322.    TILDE_CHAR = '~'
  323.  compile endif
  324. compile endif
  325.  
  326. /* The DEFINIT routine is called when the editor is     */
  327. /* started. First we define some global variables.      */
  328. definit
  329. compile if EVERSION >= '6.00'
  330.   'postme bkminit'
  331. compile else
  332.   universal bkm_def
  333.   universal bkm_idx
  334.   universal bkm_avail
  335. compile if bkm_tags_between<>''
  336.   universal bkm_between
  337.   universal bkm_between_new
  338. compile endif
  339. compile if bkm_debugging
  340.   universal bkm_debug
  341. compile endif
  342.   universal bkm_nocheck
  343.   universal bkm_save_file
  344.   universal bkm_last_colon
  345.   universal bkm_last_colon_line
  346.   universal bkm_num
  347.   universal bkm_cur_num
  348.   universal bkm_rep_tag
  349.   universal bkm_config
  350. compile if bkm_want_symbols
  351.   universal bkm_symbols
  352.   universal bkm_symbols_active
  353.   universal bkm_sym_file
  354.   universal bkm_codepage
  355. compile endif
  356.   universal bkm_tag_start
  357.   universal bkm_tag_end
  358.   universal bkm_end_tag
  359.   universal bkm_inv_tag_rep
  360.   universal bkm_temp_path
  361.   universal bkm_keepspace
  362. compile if EPM
  363.   universal bkm_did_menu
  364.   universal defaultmenu
  365.   universal activemenu
  366.  compile if EVERSION >= 5.20
  367.    universal activeaccel
  368.  compile endif
  369.  
  370.   link_rc = rc
  371. compile endif
  372.  
  373. ; LAM:  Would be both shorter and faster to convert this to:
  374. ;  parse value '' with bkm_temp_path bkm_def bkm_config bkm_idx ...
  375.  
  376.   bkm_temp_path=''
  377.   bkm_def=''                    -- internal name of the definition file
  378.   bkm_config = ''
  379.   bkm_idx=''                    -- name of the index
  380.   bkm_avail=-1                  -- flag (-1=not init., 0=unavailable, 1=available)
  381. compile if bkm_tags_between<>''
  382.   bkm_between=''                -- starting tag of margin change construct
  383.   bkm_between_new=''            -- change required?
  384. compile endif
  385. compile if bkm_debugging
  386.   bkm_debug=0                   -- flag (0=no debug, 1=debug on)
  387. compile endif
  388. ; 'echo on'                     -- remove semicolon to get additional trace
  389.   bkm_nocheck=0                 -- flag (1=don't check files in bkm_init)
  390.   bkm_save_file=''              -- current tag definition files
  391.   bkm_last_colon=0              -- position of last colon
  392.   bkm_last_colon_line=0         -- line number of last colon
  393.   bkm_num=1                     -- number of the first/next index and tag-def. file
  394.   bkm_cur_num=0                 -- number of the current index
  395.   bkm_rep_tag=''                -- tag which should be inserted if a_2 is pressed
  396.   bkm_tag_start=''              -- first character of a tag
  397.   bkm_tag_end=''                -- last character of a tag
  398.   bkm_end_tag=''                -- character sequence of end-tags
  399.   bkm_inv_tag_rep=''            -- character sequence replacing the tag-start of invalid tags
  400.   bkm_keepspace = 0             -- initialize
  401. compile if bkm_want_symbols
  402.   bkm_symbols=''                -- symbol table
  403.   bkm_symbols_active = 0        -- symbol support activated for this file
  404.   bkm_sym_file=''               -- symbol file name
  405.   bkm_codepage=''               -- current codepage
  406. /* Now we try to get the number of the current codepage.*/
  407. compile if E3
  408.   if dos_version()>320 then
  409.     parse value int86x(DOS_INT, 26113, '') with erc acp . scp . . cflag ','
  410.     if not cflag then
  411.       bkm_codepage=strip(acp)
  412.     endif
  413.   else
  414.     bkm_codepage=bkm_cdpg
  415.   endif
  416. compile else
  417.   codepage = '??'; datalen = '??'
  418.   call dynalink('DOSCALLS',            -- dynamic link library name
  419.                 '#130',                -- ordinal value for DOSGetCP
  420.                 atoi(2)            ||  -- length of code page list
  421.                 selector(codepage) ||  -- string selector
  422.                 offset(codepage)   ||  -- string offset
  423.                 selector(datalen)  ||  -- string selector
  424.                 offset(datalen) )      -- string offset
  425.   bkm_codepage = strip(itoa(codepage,10))
  426. compile endif
  427. compile endif
  428.   call bkm_make_bkm()           -- create the ".BKM" hidden file
  429. compile if EPM
  430.   bkm_did_menu = 0
  431.   compile if bkm_is_external = 1
  432.     call bkm_build_menu()
  433.   compile endif
  434.   rc = link_rc  -- LAM:  Avoid link error message problem.
  435. compile if EVERSION > '5.49' & EBOOKIE_ENH = 1
  436.   include 'd:\epm551\load.e'
  437. defselect
  438.   call bkm_defselect()
  439. compile endif -- EVERSION > '5.49' & EBOOKIE_ENH = 1
  440. compile endif -- EPM
  441. compile endif
  442.  
  443. compile if EVERSION >= '6.00'
  444. defc bkminit=
  445.   universal bkm_def
  446.   universal bkm_idx
  447.   universal bkm_avail
  448. compile if bkm_tags_between<>''
  449.   universal bkm_between
  450.   universal bkm_between_new
  451. compile endif
  452. compile if bkm_debugging
  453.   universal bkm_debug
  454. compile endif
  455.   universal bkm_nocheck
  456.   universal bkm_save_file
  457.   universal bkm_last_colon
  458.   universal bkm_last_colon_line
  459.   universal bkm_num
  460.   universal bkm_cur_num
  461.   universal bkm_rep_tag
  462.   universal bkm_config
  463. compile if bkm_want_symbols
  464.   universal bkm_symbols
  465.   universal bkm_symbols_active
  466.   universal bkm_sym_file
  467.   universal bkm_codepage
  468. compile endif
  469.   universal bkm_tag_start
  470.   universal bkm_tag_end
  471.   universal bkm_end_tag
  472.   universal bkm_inv_tag_rep
  473.   universal bkm_temp_path
  474.   universal bkm_keepspace
  475. compile if EPM
  476.   universal bkm_did_menu
  477.   universal defaultmenu
  478.   universal activemenu
  479.  compile if EVERSION >= 5.20
  480.    universal activeaccel
  481.  compile endif
  482.  
  483.   link_rc = rc
  484. compile endif
  485.  
  486. ; LAM:  Would be both shorter and faster to convert this to:
  487. ;  parse value '' with bkm_temp_path bkm_def bkm_config bkm_idx ...
  488.  
  489.   bkm_temp_path=''
  490.   bkm_def=''                    -- internal name of the definition file
  491.   bkm_config = ''
  492.   bkm_idx=''                    -- name of the index
  493.   bkm_avail=-1                  -- flag (-1=not init., 0=unavailable, 1=available)
  494. compile if bkm_tags_between<>''
  495.   bkm_between=''                -- starting tag of margin change construct
  496.   bkm_between_new=''            -- change required?
  497. compile endif
  498. compile if bkm_debugging
  499.   bkm_debug=0                   -- flag (0=no debug, 1=debug on)
  500. compile endif
  501. ; 'echo on'                     -- remove semicolon to get additional trace
  502.   bkm_nocheck=0                 -- flag (1=don't check files in bkm_init)
  503.   bkm_save_file=''              -- current tag definition files
  504.   bkm_last_colon=0              -- position of last colon
  505.   bkm_last_colon_line=0         -- line number of last colon
  506.   bkm_num=1                     -- number of the first/next index and tag-def. file
  507.   bkm_cur_num=0                 -- number of the current index
  508.   bkm_rep_tag=''                -- tag which should be inserted if a_2 is pressed
  509.   bkm_tag_start=''              -- first character of a tag
  510.   bkm_tag_end=''                -- last character of a tag
  511.   bkm_end_tag=''                -- character sequence of end-tags
  512.   bkm_inv_tag_rep=''            -- character sequence replacing the tag-start of invalid tags
  513.   bkm_keepspace = 0             -- initialize
  514. compile if bkm_want_symbols
  515.   bkm_symbols=''                -- symbol table
  516.   bkm_symbols_active = 0        -- symbol support activated for this file
  517.   bkm_sym_file=''               -- symbol file name
  518.   bkm_codepage=''               -- current codepage
  519. /* Now we try to get the number of the current codepage.*/
  520.   codepage = '????'; datalen = '????'
  521.   call dynalink32('DOSCALLS',            -- dynamic link library name
  522.                 '#291',                -- ordinal value for DOS32QueryCP
  523.                 atol(4)            ||  -- length of code page list
  524.                 offset(codepage)   ||  -- string offset
  525.                 selector(codepage) ||  -- string selector
  526.                 offset(datalen)    ||  -- string offset
  527.                 selector(datalen),2)   -- string selector
  528.   bkm_codepage = strip(ltoa(codepage,10))
  529. compile endif
  530.   call bkm_make_bkm()           -- create the ".BKM" hidden file
  531.   bkm_did_menu = 0
  532.   compile if bkm_is_external = 1
  533.     call bkm_build_menu()
  534.   compile endif
  535.   rc = link_rc  -- LAM:  Avoid link error message problem.
  536. compile if EBOOKIE_ENH = 1
  537.   include 'd:\epm551\load.e'
  538. defselect
  539.   call bkm_defselect()
  540. compile endif -- EBOOKIE_ENH = 1
  541. compile endif
  542.  
  543. /* Define a new command. "bookie" turns the tag         */
  544. /* formatting on or off.                                */
  545. defc bookie=
  546.   universal bkm_avail
  547.   universal bkm_last_colon
  548.   universal bkm_cur_num
  549.   universal bkm_save_file
  550. compile if bkm_tags_between<>''
  551.   universal bkm_between
  552.   universal bkm_between_new
  553. compile endif
  554. compile if bkm_want_symbols
  555.   universal bkm_sym_file
  556. compile endif
  557.   if bkm_avail=0 then
  558.     call bkm_say("No tag-definition file active.",0)
  559.   else
  560.     parm=strip(lowcase(arg(1)))
  561.     if parm='' then parm='on' endif
  562.     if substr(parm,1,2)='of' then
  563. compile if bkm_tags_between<>''
  564.       bkm_between=''
  565.       bkm_between_new=''
  566. compile endif
  567.       bkm_last_colon=0
  568. compile if bkm_want_symbols
  569.       bkm_sym_file=''
  570. compile endif
  571.       call bkm_upd_files(0,' ')
  572.       call bkm_select()
  573.       keys edit_keys
  574.     elseif parm='on' then
  575.       if bkm_avail=-1 then call bkm_chg_def_file(bkm_def_file,0) endif
  576.       if bkm_avail=1 then
  577.         bkm_last_colon=0
  578. compile if E3
  579.         call bkm_chg_def_file(bkm_save_file,0)
  580.         call bkm_upd_files(bkm_cur_num,' ')
  581.         call bkm_upd_line_one()
  582.         call bkm_select()
  583. compile else
  584.         call bkm_upd_line_one()
  585.         call bkm_init()
  586.         keys bkm_keys
  587. compile endif
  588.       endif
  589.     else
  590.      call bkm_say("Invalid parameter" arg(1) "supplied, must be 'ON' or 'OFf'.",0)
  591.     endif
  592.   endif
  593.  
  594. /* Define the "bookief" command to switch to different  */
  595. /* tag-definition file(s)                               */
  596. defc bookief=
  597.   universal bkm_cur_num
  598.   universal bkm_rep_tag
  599.   if arg(1)='' then
  600.     call bkm_say("Required parameter 'filename' omitted.",0)
  601.   else
  602.     call bkm_chg_def_file(arg(1),0)
  603.     call bkm_upd_line_one()
  604.     call bkm_upd_files(bkm_cur_num,' ')
  605.     call bkm_select()
  606.   endif
  607.  
  608. compile if bkm_attr
  609. defc bkmattr=
  610.   call bkm_add_attr(arg(1))
  611. compile endif
  612.  
  613. compile if bkm_want_symbols
  614. defc bkmsym=
  615.   universal bkm_symbols
  616.   universal bkm_symbols_active
  617.   universal bkm_sym_file
  618.   universal bkm_codepage
  619.   universal bkm_tag_start
  620.   universal bkm_tag_end
  621.   universal bkm_inv_tag_rep
  622.   fline=0
  623.   if lowcase(arg(1))='on' then
  624.     parse value bkm_sym_file with bkm_sym_file '.' .
  625.     call bkm_get_sym()
  626.   else
  627.     if lowcase(arg(1))='off' then
  628.       bkm_symbols_active = 0
  629.       call bkm_upd_files(-1,' ')
  630.     else
  631.       if bkm_symbols='' then
  632.         call bkm_say("Symbol support not active.",0)
  633.       else
  634.         getfileid symid,bkm_sym_file    -- get id of symbol file
  635.         if symid='' then
  636.           call bkm_say("Symbol support not active.",0)
  637.         else
  638.           if marktype()=='' then
  639.             if lowcase(arg(1))='all' then
  640.               fline=1
  641.               lline=.last
  642.               type='LINE'
  643.             else
  644.               call bkm_say("No marked line(s), and 'all' parameter not specified.",0)
  645.             endif
  646.           else
  647.             getmark fline, lline, fcol, lcol
  648.             type=marktype()
  649.           endif
  650.           if fline then
  651.             lines_changed=0
  652.             dont_doit=0
  653.             tag_started=0
  654.             for i=fline to lline
  655.               line_changed=0
  656.               sayerror "BKMSYM: Processing line" i"."
  657.               getline line,i
  658.               if type='LINE' then
  659.                 fcol=1
  660.                 lcol=length(strip(line,'T'))
  661.               endif
  662.               j=fcol-1
  663.               loop
  664.                 j=j+1
  665.                 if j>lcol then leave endif
  666.                 k=substr(line,j,1)
  667.                 if bkm_tag_start==k then           -- start of a tag?
  668.                   parse value substr(line,j) with tag .
  669.                   parse value tag with tag (bkm_tag_end) .
  670.                   if length(tag)>1 then
  671.                     tag_line=bkm_find_tag(tag)      -- try again
  672.                     if tag_line=0 then
  673.                       line=substr(line,1,j-1) || bkm_inv_tag_rep || substr(line,j+1)
  674.                       lcol=lcol+length(bkm_inv_tag_rep)-1
  675.                       j=j+length(bkm_inv_tag_rep)-1
  676.                       line_changed=1
  677.                     else
  678.                       tag_started=1
  679.                       if lowcase(tag)=':cgraphic' then
  680.                         dont_doit=1
  681.                       endif
  682.                       if lowcase(tag)=':ecgraphic' then
  683.                         dont_doit=0
  684.                       endif
  685.                     endif
  686.                   endif
  687.                 elseif bkm_tag_end==k then         -- end of a tag?
  688.                   tag_started=0
  689.                 else                               -- else check for replacement
  690.                   if not dont_doit then
  691.                     if not tag_started then
  692.                       if pos(k,bkm_symbols) then   -- if found continue
  693.                         getline xline,asc(k),symid  -- get the line from the symbol file
  694.                         parse value xline with . k .       -- get the replacement string
  695. ;;                      k=strip(k)                 -- remove leading & trailing blanks (LAM: Parse did that.)
  696.                         line=substr(line,1,j-1) || k || substr(line,j+1)
  697.                         lcol=lcol+length(k)-1
  698.                         j=j+length(k)-1
  699.                         line_changed=1
  700.                       endif
  701.                     endif
  702.                   endif
  703.                 endif
  704.               endloop
  705.               if line_changed then
  706.                 replaceline line,i
  707.                 lines_changed=lines_changed+1
  708.               endif
  709.             endfor
  710.             call bkm_say("Processing ended, "lines_changed" lines changed.",0)
  711.           endif
  712.         endif
  713.       endif
  714.     endif
  715.   endif
  716. compile endif
  717.  
  718. compile if bkm_debugging
  719. /* Define the "bkmdebug" command to ease the debugging  */
  720. defc bkmdebug=
  721.   universal bkm_def
  722.   universal bkm_idx
  723.   universal bkm_avail
  724. compile if bkm_tags_between<>''
  725.   universal bkm_between
  726. compile endif
  727.   universal bkm_debug
  728.   universal bkm_save_file
  729.   universal bkm_num
  730.   universal bkm_cur_num
  731.   universal bkm_rep_tag
  732.   universal bkm_tag_start
  733.   universal bkm_tag_end
  734.   universal bkm_end_tag
  735.   universal bkm_inv_tag_rep
  736.   universal bkm_temp_path
  737.   universal vTEMP_PATH
  738.   universal vAUTOSAVE_PATH
  739. compile if bkm_want_symbols
  740.   universal bkm_symbols
  741.   universal bkm_symbols_active
  742.   universal bkm_sym_file
  743.   universal bkm_codepage
  744. compile endif
  745. compile if bkm_attr
  746.   universal bkm_did_bkmattr
  747. compile endif
  748.   xdebug=strip(lowcase(arg(1)))
  749.   if xdebug='on' then
  750.     bkm_debug=1
  751.   elseif substr(xdebug,1,2)='of' then
  752.     bkm_debug=0
  753.     'echo off'
  754.   elseif substr(xdebug,1,1)='t' then
  755.     'echo on'
  756.     bkm_debug=1
  757.   elseif substr(xdebug,1,1)='e' then
  758.     'echo off'
  759.   elseif substr(xdebug,1,1)='d' then
  760.     insertline ".**EBOOKIE**DEBUGGING**INFO**START**",.line+1
  761.     insertline ".* version:" bkm_version", DOS (OS/2) version="dos_version(),.line+2
  762.     insertline ".* def:" bkm_def,.line+3
  763.     insertline ".* idx:" bkm_idx,.line+4
  764.     insertline ".* avail:" bkm_avail,.line+5
  765.     insertline ".* save_file:" bkm_save_file,.line+6
  766.     insertline ".* num:" bkm_num,.line+7
  767.     insertline ".* cur_num:" bkm_cur_num,.line+8
  768.     insertline ".* rep_tag:" strip(bkm_rep_tag),.line+9
  769.     insertline ".* tag_start:" bkm_tag_start,.line+10
  770.     insertline ".* tag_end:" bkm_tag_end,.line+11
  771.     insertline ".* end_tag:" bkm_end_tag,.line+12
  772.     insertline ".* inv_tag_rep:" bkm_inv_tag_rep,.line+13
  773.     insertline ".* Files known to EBOOKIE:",.line+14
  774.     j=15
  775.     getfileid id,'.BKM'
  776.     if id<>'' then
  777.       last=id.last
  778.       for i=1 to last
  779.         getline line,i,id
  780.         if line='' then iterate endif
  781.         if not pos('==',line) then iterate endif
  782.         insertline ".*     "||line,.line+j
  783.         j=j+1
  784.       endfor
  785.     else
  786.       insertline ".*     file .BKM not in ring.",.line+j
  787.       j=j+1
  788.     endif
  789. compile if bkm_want_symbols
  790.     insertline ".* symbols:" bkm_symbols,.line+j
  791.     insertline ".* symbols_active:" bkm_symbols_active,.line+j+1
  792.     insertline ".* codepage=" bkm_codepage,.line+j+2
  793.     insertline ".* sym_file=" bkm_sym_file,.line+j+3
  794.     j=j+4
  795. compile endif
  796. compile if bkm_tags_between<>''
  797.     insertline ".* between:" bkm_between,.line+j
  798.     j=j+1
  799. compile endif
  800.     insertline ".* bkm_temp_path=" bkm_temp_path,.line+j
  801.     j=j+1
  802. compile if bkm_attr
  803.     insertline ".* bkm_did_bkmattr=" bkm_did_bkmattr,.line+j
  804.     j=j+1
  805. compile endif
  806.     insertline ".**EBOOKIE**DEBUGGING**INFO**END**",.line+j
  807.   else
  808.     call bkm_say("Invalid parameter" arg(1) "supplied, must be 'ON|OFf|Display|Trace|Etrace'.",0)
  809.   endif
  810. compile else
  811. defc bkmdebug=
  812.   call bkm_say("Debugging not configured.",0)
  813. compile endif
  814.  
  815. defc bkmimbed=
  816.   call bkm_imbed()
  817.  
  818. defc bkmrem=
  819.   call bkm_rem()
  820.  
  821. compile if bkm_help_support
  822. defc bkmhelp=
  823.   call bkm_help(arg(1))
  824. compile endif
  825.  
  826. compile if bkm_idx_supp
  827. defc bkmidx=
  828.   call bkm_idx_make()
  829. compile endif
  830.  
  831. /* Define the keyset. It redefines the following keys:  */
  832. /*   tab ....... tab word                               */
  833. /*   backtab ... backtab word                           */
  834. /*   space ..... check for bkm tag                      */
  835. /*   enter ..... check for bkm tag                      */
  836. /*   period .... check for bkm tag                      */
  837. /*   colon ..... start of bkm tag                       */
  838. /*   up ........ same as period                         */
  839. /*   down ...... same as period                         */
  840. /*   pgup ...... same as period                         */
  841. /*   pgdown .... same as period                         */
  842. /*   a_1 ....... edit imbed file                        */
  843. /*   a_2 ....... insert default tag                     */
  844. /*   a_h ....... help for tag or attribute              */
  845. /*   c_h ....... view reference for tag                 */    /* temple */
  846. /*   a_i ....... index                                  */
  847. compile if E3
  848. defkeys bkm_keys overlay
  849. compile else
  850. defkeys bkm_keys overlay clear
  851. compile endif
  852.  
  853. /* Define the tabulators to tab one word at the time,   */
  854. /* or use regular tabs.                                 */
  855. def tab=
  856. compile if bkm_tags_between<>''
  857.   universal bkm_between
  858.   if bkm_between='' then                -- if in regular text
  859. compile endif
  860.     getline line                        -- get the current line
  861.     line=strip(line,'T')                -- clean trailing spaces
  862.     line=Substr(line,.col+1)            -- get stuff right of the cursor
  863.     if line<>' ' then                   -- not empty?
  864.       tab_word                          -- jump to next word
  865.     else
  866.       tab                               -- go to next tabstop
  867.     endif
  868. compile if bkm_tags_between<>''
  869.   else                                  -- within example?
  870.     tab                                 -- use regular tabs
  871.   endif
  872. compile endif
  873.  
  874. def s_tab=
  875. compile if bkm_tags_between<>''
  876.   universal bkm_between
  877.   if bkm_between='' then                -- if in regular text
  878. compile endif
  879.     getline line                        -- get the current line
  880.     line=strip(line,'T')                -- clean trailing spaces
  881.     line=Substr(line,.col+1)            -- get stuff right of the cursor
  882.     if line<>' ' then                   -- not empty?
  883.       backtab_word                      -- jump back one word
  884.     else
  885.       backtab                           -- use regular tabstop
  886.     endif
  887. compile if bkm_tags_between<>''
  888.   else                                  -- within example?
  889.     backtab                             -- use regular tabs
  890.   endif
  891. compile endif
  892.  
  893. def pgup=
  894.   universal expand_on
  895.   universal bkm_last_colon
  896.   universal bkm_tag_end
  897.   if bkm_last_colon & expand_on then            -- anything to do?
  898.     if not bkm_expansion(bkm_tag_end) then      -- check for tag
  899. compile if bkm_tags_between<>''
  900.       call bkm_pgup()                           -- no tag, page up
  901. compile else
  902. compile if bkm_page_up=1
  903.       call my_page_up()                         -- call user exit
  904. compile else
  905.       page_up                                   -- do regular page up
  906. compile endif
  907. compile endif
  908.     endif
  909.   else                                          -- nothing to do
  910. compile if bkm_tags_between<>''
  911.     call bkm_pgup()                             -- page up
  912. compile else
  913. compile if bkm_page_up=1
  914.     call my_page_up()                           -- call user exit
  915. compile else
  916.     page_up                                     -- regular page up
  917. compile endif
  918. compile endif
  919.   endif
  920.   bkm_last_colon=0                              -- reset last colon position
  921.  
  922. def pgdn=
  923.   universal expand_on
  924.   universal bkm_last_colon
  925.   universal bkm_tag_end
  926.   if bkm_last_colon & expand_on then            -- anything to do?
  927.     if not bkm_expansion(bkm_tag_end) then      -- check for tag
  928. compile if bkm_tags_between<>''
  929.       call bkm_pgdn()                           -- no tag, page down
  930. compile else
  931. compile if bkm_page_down=1
  932.       call my_page_down()                       -- call user exit
  933. compile else
  934.       page_down                                 -- do regular page down
  935. compile endif
  936. compile endif
  937.     endif
  938.   else                                          -- nothing to do
  939. compile if bkm_tags_between<>''
  940.     call bkm_pgdn()                             -- page down
  941. compile else
  942. compile if bkm_page_down=1
  943.     call my_page_down()                         -- call user exit
  944. compile else
  945.     page_down                                   -- regular page down
  946. compile endif
  947. compile endif
  948.   endif
  949.   bkm_last_colon=0                              -- reset last colon position
  950.  
  951. def up=
  952.   universal expand_on
  953.   universal bkm_last_colon
  954.   universal bkm_tag_end
  955. compile if bkm_tags_between<>''
  956.   universal bkm_between_new
  957.   universal bkm_between
  958. compile endif
  959.   if bkm_last_colon & expand_on then            -- anything to do?
  960.     if not bkm_expansion(bkm_tag_end) then      -- check for tag
  961. compile if bkm_tags_between<>''
  962.       call bkm_up()                             -- no tag, line up
  963. compile endif
  964. compile if bkm_line_up=1
  965.       call my_up()                              -- call user exit
  966. compile else
  967.       up                                        -- do regular line up
  968. compile endif
  969.     endif
  970.   else                                          -- nothing to do
  971. compile if bkm_tags_between<>''
  972.     call bkm_up()                               -- line up
  973. compile endif
  974. compile if bkm_line_up=1
  975.     call my_up()                                -- call user exit
  976. compile else
  977.     up                                          -- regular line up
  978. compile endif
  979.   endif
  980. compile if bkm_tags_between<>''
  981.   if bkm_between<>bkm_between_new then call bkm_upd_files(-1,bkm_between_new) endif
  982. compile endif
  983.   bkm_last_colon=0                              -- reset last colon position
  984.  
  985. def down=
  986.   universal expand_on
  987.   universal bkm_last_colon
  988.   universal bkm_tag_end
  989. compile if bkm_tags_between<>''
  990.   universal bkm_between_new
  991.   universal bkm_between
  992. compile endif
  993.   if bkm_last_colon & expand_on then            -- anything to do?
  994.     if not bkm_expansion(bkm_tag_end) then      -- check for tag
  995. compile if bkm_tags_between<>''
  996.       call bkm_down()                           -- no tag, line down
  997. compile endif
  998. compile if bkm_line_down=1
  999.       call my_down()                            -- call user exit
  1000. compile else
  1001.       down                                      -- do regular line down
  1002. compile endif
  1003.     endif
  1004.   else                                          -- nothing to do
  1005. compile if bkm_tags_between<>''
  1006.     call bkm_down()                             -- line down
  1007. compile endif
  1008. compile if bkm_line_down=1
  1009.     call my_down()                              -- call user exit
  1010. compile else
  1011.     down                                        -- regular line down
  1012. compile endif
  1013.   endif
  1014. compile if bkm_tags_between<>''
  1015.   if bkm_between<>bkm_between_new then call bkm_upd_files(-1,bkm_between_new) endif
  1016. compile endif
  1017.   bkm_last_colon=0                              -- reset last colon position
  1018.  
  1019. /* Define the space bar. Is it the end of a tag?        */
  1020. compile if EVERSION >= 5
  1021. def space=
  1022. compile else
  1023. def ' '=
  1024. compile endif
  1025.   universal expand_on
  1026.   universal bkm_last_colon
  1027. compile if bkm_attr
  1028.   universal bkm_did_bkmattr
  1029. compile endif
  1030.   if bkm_last_colon & expand_on then    -- something to do?
  1031.     if not bkm_expansion(' ') then      -- check for tag
  1032. compile if bkm_attr & EVERSION = '5.19'
  1033.     if not insert_state() then delete_char endif
  1034. compile endif
  1035.       keyin ' '                         -- if none, type space
  1036.     endif
  1037.   else
  1038. compile if bkm_attr & EVERSION = '5.19'
  1039.     if not insert_state() then delete_char endif
  1040. compile endif
  1041. compile if bkm_attr & EVERSION >= '5.50'
  1042.     if insert_state() & bkm_did_bkmattr then
  1043.        offst = -1
  1044.        query_attribute class, val, IsPush, offst, .col, .line
  1045.        if class then
  1046.           oldlevel = .levelofattributesupport
  1047.           .levelofattributesupport = 3
  1048.           call to_offset_zero()
  1049.        endif
  1050.     else
  1051.        class = 0
  1052.     endif
  1053. compile endif
  1054.     keyin ' '                           -- type space
  1055. compile if bkm_attr & EVERSION >= '5.50'
  1056.     if insert_state() & bkm_did_bkmattr & class then
  1057.       .levelofattributesupport = oldlevel
  1058.     endif
  1059. compile endif
  1060.   endif
  1061.   bkm_last_colon=0                      -- reset last colon position
  1062.  
  1063. /* Define the c_space (or c_enter) key to display all   */
  1064. /* optional parameters.                                 */
  1065. compile if EPM
  1066. def c_space=
  1067. compile else
  1068. def c_enter=
  1069. compile endif
  1070.   universal expand_on
  1071.   universal bkm_last_colon
  1072.   if bkm_last_colon & expand_on then    -- something to do?
  1073.     if not bkm_expansion('a') then      -- check for tag
  1074. compile if EPM
  1075. compile if bkm_attr & EVERSION = '5.19'
  1076.     if not insert_state() then delete_char endif
  1077. compile endif
  1078.       keyin ' '                         -- type regular space
  1079. compile else
  1080.       call my_c_enter()                 -- call default routine
  1081. compile endif
  1082.     endif
  1083.   else
  1084. compile if EPM
  1085. compile if bkm_attr & EVERSION = '5.19'
  1086.     if not insert_state() then delete_char endif
  1087. compile endif
  1088.     keyin ' '                           -- type space
  1089. compile else
  1090.     call my_c_enter()                   -- call default routine
  1091. compile endif
  1092.   endif
  1093.   bkm_last_colon=0                      -- reset last colon position
  1094.  
  1095. /* Check the enter key. It might be a regular "enter"   */
  1096. /* but it might also be the end of a tag.               */
  1097. def enter=
  1098.   universal expand_on
  1099.   universal bkm_last_colon
  1100. compile if ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  1101.   universal enterkey
  1102. compile endif
  1103.   if bkm_last_colon & expand_on then            -- something to do?
  1104.     if not bkm_expansion(bkm_tag_end) then      -- check for tag
  1105. compile if bkm_enter
  1106.       call my_enter_key()               -- call user exit
  1107. compile elseif ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  1108.       call enter_common(enterkey)
  1109. compile else
  1110.       call my_enter()                   -- call default routine
  1111. compile endif
  1112. compile if E3
  1113.     else
  1114.       call maybe_autosave()             -- check for autosave
  1115. compile endif
  1116.     endif
  1117.   else
  1118. compile if bkm_enter
  1119.     call my_enter_key()                 -- call user exit
  1120. compile elseif ENHANCED_ENTER_KEYS & ENTER_ACTION <> ''
  1121.       call enter_common(enterkey)
  1122. compile else
  1123.     call my_enter()                     -- call default routine
  1124. compile endif
  1125.   endif
  1126.   bkm_last_colon=0                      -- reset last colon position
  1127.  
  1128. def a_1=
  1129.   call bkm_imbed()
  1130.  
  1131. def a_2=
  1132.   call bkm_rem()
  1133.  
  1134. compile if bkm_help_support
  1135. def a_h=
  1136.   call bkm_help('a')
  1137.  
  1138. def c_h=
  1139.   call bkm_help('c')
  1140. compile endif
  1141.  
  1142. compile if bkm_idx_supp
  1143.   def a_i=
  1144.   call bkm_idx_make()
  1145. compile endif
  1146.  
  1147. compile if E3
  1148. def '!' - '■' =
  1149. compile else
  1150. def otherkeys
  1151. compile endif
  1152. compile if bkm_want_symbols
  1153.   universal bkm_symbols
  1154.   universal bkm_symbols_active
  1155.   universal bkm_sym_file
  1156. compile endif
  1157.   universal bkm_last_colon
  1158.   universal bkm_last_colon_line
  1159.   universal expand_on
  1160.   universal bkm_tag_start
  1161.   universal bkm_tag_end
  1162.   universal bkm_end_tag
  1163.   universal bkm_keepspace
  1164. compile if bkm_attr
  1165.   universal bkm_did_bkmattr
  1166. compile endif
  1167.   k=lastkey()                           -- get the last typed character
  1168. compile if EVERSION > 4
  1169.   if length(k)=1 then                   -- regular key?
  1170. compile endif
  1171. compile if EVERSION < 5
  1172.     if not command_state() then         -- check for command line
  1173. compile endif
  1174.       if bkm_tag_start==k then           -- start of a tag?
  1175.         bkm_last_colon=.col             -- yes, save position
  1176.         bkm_last_colon_line=.line       -- and save the line number
  1177.       elseif bkm_tag_end==k then         -- end of a tag?
  1178.         if bkm_last_colon & expand_on then    -- do we have to do something?
  1179.           bkm_keepspace = 0
  1180.           if bkm_expansion(bkm_tag_end) then k='' endif -- expand it
  1181.         endif
  1182.         bkm_last_colon=0                -- reset last tag-start postition
  1183.       elseif k==',' then                -- end of a tag?
  1184.         if bkm_last_colon & expand_on then    -- do we have to do something?
  1185.           bkm_keepspace = 1
  1186.           if bkm_expansion(bkm_tag_end) then k='' endif -- expand it
  1187.         endif
  1188.         bkm_last_colon=0                -- reset last tag-start postition
  1189. compile if bkm_want_symbols
  1190.       else                              -- else check for replacement
  1191.         if bkm_symbols_active = 1 then  -- symbol support active?
  1192.           if pos(k,bkm_symbols) then    -- if found key in table continue
  1193.             getfileid id,bkm_sym_file   -- get id of symbol file
  1194.             if id<>'' then              -- if available
  1195.               getline line,asc(k),id    -- get the line from the symbol file
  1196.               parse value line with . k .       -- get the replacement string
  1197.             endif
  1198.           endif
  1199.         endif
  1200. compile endif
  1201.       endif
  1202. compile if EVERSION < 5
  1203.     endif
  1204. compile endif
  1205. compile if bkm_attr & EVERSION >= '5.16' & EVERSION <= '5.19'
  1206.     if not insert_state() then delete_char endif
  1207. compile endif
  1208. compile if bkm_attr & EVERSION >= '5.50'
  1209.     if insert_state() & bkm_did_bkmattr then
  1210.        offst = -1
  1211.        query_attribute class, val, IsPush, offst, .col, .line
  1212.        if class then
  1213.           oldlevel = .levelofattributesupport
  1214.           .levelofattributesupport = 3
  1215.           call to_offset_zero()
  1216.        endif
  1217.     else
  1218.        class = 0
  1219.     endif
  1220. compile endif
  1221.     keyin k
  1222. compile if bkm_attr & EVERSION >= '5.50'
  1223.     if insert_state() & bkm_did_bkmattr & class then
  1224.       .levelofattributesupport = oldlevel
  1225.     endif
  1226. compile endif
  1227. compile if EVERSION > 4
  1228.   endif
  1229. compile endif
  1230.  
  1231. compile if E3
  1232. tryinclude 'mykeys.bkm'
  1233. compile endif
  1234.  
  1235. compile if bkm_enter or bkm_page_up or bkm_page_down or bkm_line_up or bkm_line_down
  1236.   tryinclude 'mybkmkey.e'               -- include user exit routines
  1237. compile endif
  1238.  
  1239. /* The next routines are included only if the dynamic   */
  1240. /* margins feature is selected.                         */
  1241.  
  1242. compile if bkm_tags_between<>''
  1243. /* Process the page up key                              */
  1244. defproc bkm_pgup()
  1245.   universal bkm_between_new
  1246.   universal bkm_between
  1247.   fline=.line                           -- get the current line
  1248. compile if bkm_page_up=1
  1249.   call my_page_up()                     -- call user exit
  1250. compile else
  1251.   page_up                               -- do regular page up
  1252. compile endif
  1253.   lline=.line                           -- save new line number
  1254.   for i=fline to lline by -1            -- loop over all lines skipped
  1255.     i                                   -- set current line
  1256.     call bkm_up()                       -- do a line-up
  1257.   endfor
  1258.   if bkm_between<>bkm_between_new then call bkm_upd_files(-1,bkm_between_new) endif
  1259.  
  1260. /* Process the page down key                            */
  1261. defproc bkm_pgdn()
  1262.   universal bkm_between_new
  1263.   universal bkm_between
  1264.   fline=.line                           -- get the current line
  1265. compile if bkm_page_down=1
  1266.   call my_page_down()                   -- call user exit
  1267. compile else
  1268.   page_down                             -- do regular page down
  1269. compile endif
  1270.   lline=.line                           -- save new line number
  1271.   for i=fline to lline                  -- loop over all lines skipped
  1272.     i                                   -- set current line
  1273.     call bkm_down()                     -- do a line-down
  1274.   endfor
  1275.   if bkm_between<>bkm_between_new then call bkm_upd_files(-1,bkm_between_new) endif
  1276.  
  1277. /* Process the up key.                                  */
  1278. defproc bkm_up()
  1279.   universal bkm_between
  1280.   universal bkm_tag_start
  1281.   universal bkm_tag_end
  1282.   universal bkm_end_tag
  1283. compile if bkm_debugging
  1284.   universal bkm_debug
  1285. compile endif
  1286.   universal bkm_between_new
  1287.   getline line                          -- get the current line
  1288.   parse value line with tag .           -- get the first word of the line
  1289.   if substr(tag,1,1)=bkm_tag_start then -- is the first character a tag-start?
  1290.     parse value tag with tag (bkm_tag_end) .    -- remove the tag-end
  1291.     tag=lowcase(strip(tag))             -- cleanup
  1292.     if bkm_between<>'' then             -- are we between something=
  1293.       if tag=bkm_end_tag||substr(bkm_between,2) | tag=bkm_between then  -- is the current tag an end-tag?
  1294.         'ma' bkm_margins                -- yes, set margins to default
  1295. compile if bkm_debugging
  1296.         if bkm_debug then call bkm_say("Margins changed to" bkm_margins".",0) endif
  1297. compile endif
  1298.         bkm_between_new=''              -- clean flag
  1299.       endif
  1300.     else
  1301.       tag=bkm_tag_start||substr(tag,3)  -- not between something
  1302. compile if EVERSION >= '5.20'
  1303.       if wordpos(tag,bkm_tags_between) then             -- in the list of tags to watch?
  1304. compile else
  1305.       if pos(tag||' ',bkm_tags_between||' ') then       -- in the list of tags to watch?
  1306. compile endif
  1307.         'ma 1 254 1'                    -- yes, reset margins
  1308. compile if bkm_debugging
  1309.         if bkm_debug then call bkm_say("Margins changed to 1 254 1.",0) endif
  1310. compile endif
  1311.         bkm_between_new=tag             -- save current tag
  1312.       endif
  1313.     endif
  1314.   endif
  1315.  
  1316. /* Process the down key                                 */
  1317. defproc bkm_down()
  1318.   universal bkm_between
  1319.   universal bkm_between_new
  1320.   universal bkm_tag_start
  1321.   universal bkm_tag_end
  1322.   universal bkm_end_tag
  1323. compile if bkm_debugging
  1324.   universal bkm_debug
  1325. compile endif
  1326.   getline line                          -- get the current line
  1327.   parse value line with tag .           -- get the first word
  1328.   if substr(tag,1,1)=bkm_tag_start then -- check for tag-start character
  1329.     parse value tag with tag (bkm_tag_end) .    -- remove tag-end
  1330.     tag=lowcase(strip(tag))             -- cleanup
  1331.     if bkm_between<>'' then             -- are we between something?
  1332.       if tag=bkm_end_tag||substr(bkm_between,2) then    -- did we find a tag-end?
  1333.         'ma' bkm_margins                -- set margins to default
  1334. compile if bkm_debugging
  1335.         if bkm_debug then call bkm_say("Margins changed to" bkm_margins".",0) endif
  1336. compile endif
  1337.         bkm_between_new=''              -- set flag
  1338.       endif
  1339.     else                                -- not between something
  1340. compile if EVERSION >= '5.20'
  1341.       if wordpos(tag,bkm_tags_between) then             -- is it in the list?
  1342. compile else
  1343.       if pos(tag||' ',bkm_tags_between||' ') then       -- is it in the list?
  1344. compile endif
  1345.         'ma 1 254 1'                    -- set margins
  1346. compile if bkm_debugging
  1347.         if bkm_debug then call bkm_say("Margins changed to 1 254 1.",0) endif
  1348. compile endif
  1349.         bkm_between_new=tag             -- save tag in flag
  1350.       endif
  1351.     endif
  1352.   endif
  1353.  
  1354. compile endif
  1355.  
  1356. /* The following is the main routine of the macro.        */
  1357. /* We have found a tag. Or better, there was a colon,     */
  1358. /* followed by some undetermined number of other          */
  1359. /* characters, and then a space, a period, or an "enter". */
  1360. defproc bkm_expansion(char)
  1361.   universal bkm_last_colon
  1362.   universal bkm_last_colon_line
  1363.   universal linerest
  1364.   universal bkm_line_text
  1365. compile if bkm_tags_between<>''
  1366.   universal bkm_between
  1367.   universal bkm_between_new
  1368. compile endif
  1369. compile if bkm_debugging
  1370.   universal bkm_debug
  1371. compile endif
  1372.   universal bkm_avail
  1373.   universal bkm_nocheck
  1374.   universal bkm_save_file
  1375.   universal bkm_rep_tag
  1376.   universal bkm_tag_start
  1377.   universal bkm_tag_end
  1378.   universal bkm_end_tag
  1379.   universal bkm_inv_tag_rep
  1380. compile if bkm_want_symbols
  1381.   universal bkm_symbols
  1382.   universal bkm_symbols_active
  1383.   universal bkm_sym_file
  1384. compile endif
  1385. /* First we have to check if the file should be         */
  1386. /* processed by the macro. If not, we return as fast as */
  1387. /* we can.                                              */
  1388.   if bkm_avail<>1 then return 0 endif           -- If support is inactive, return
  1389.   if bkm_find_file(.filename)<1 then return 0 endif     -- shall we do something?
  1390. compile if bkm_debugging
  1391.   if bkm_debug then call bkm_say("bkm_expansion("char"), bkm="bkm_find_file(.filename)", colon="bkm_last_colon", line="bkm_last_colon_line".",0) endif
  1392. compile endif
  1393. /* It seems that there is work to do. First we get the  */
  1394. /* text of the current line to retrieve the tag.        */
  1395.   retc=1                                        -- set OK return code
  1396. compile if EPM
  1397.   if .line then                                 -- is there a line?
  1398. compile else
  1399.   if .line and (not command_state()) then       -- line? command state?
  1400. compile endif
  1401.     getline line                -- Get the entire line in the variable "line".
  1402.     line=strip(line,'T')        -- Clean up trailing garbage.
  1403.     tag=''                      -- clean current tag
  1404.     linerest=''                 -- clean stuff after tag
  1405.     caution=0                   -- reset flag
  1406. /* First we have to check for the automatic word wrap,  */
  1407. /* which could have moved the tag to the next line. In  */
  1408. /* this case the first word MUST contain a colon at the */
  1409. /* beginning of somewhere in the middle.                */
  1410.     if .line=bkm_last_colon_line+1 then         -- are we in the next line?
  1411.       parse value line with fword .             -- yes, get first word
  1412.       bkm_last_colon=pos(bkm_tag_start,fword)   -- find position of tag in word
  1413.       if not bkm_last_colon then return 0 endif   -- return if no tag-start found
  1414.     endif
  1415. /* When the current column is greater than the column   */
  1416. /* of the colon, it might be a tag.                     */
  1417.     if .col>bkm_last_colon then                 -- cursor right of tag-start?
  1418.       tag=substr(line,bkm_last_colon,.col-bkm_last_colon)       -- get the tag
  1419.       if substr(tag,1,1)<>bkm_tag_start then return 0 endif     -- no tag-start?
  1420.       linerest=substr(line,.col)                -- get stuff to the right
  1421. /* If the tag already contains a colon there must be    */
  1422. /* something wrong. We get the tag, but we have to be   */
  1423. /* careful.                                             */
  1424.       if pos(bkm_tag_end,tag) then            -- tag contains tag-end?
  1425.         tag=substr(tag,1,pos(bkm_tag_end,tag)-1)        -- get tag
  1426.         linerest=substr(line,bkm_last_colon+length(strip(tag))+1) -- get rest
  1427.         caution=2                               -- set caution flag
  1428.       endif
  1429.     else
  1430. /* The cursor is before, or right on the colon. This    */
  1431. /* case has to be treated differently. Probably it is   */
  1432. /* not a tag anyhow, but then we might have to replace  */
  1433. /* the colon with "&gml." or "&colon.".                 */
  1434.       tag=substr(line,bkm_last_colon)           -- get rest of line
  1435.       if substr(tag,1,1)<>bkm_tag_start then return 0 endif     -- exit if no tag
  1436.       parse value tag with tag .                -- get first word of tag
  1437.       caution=1                                 -- set caution flag
  1438.       if pos(bkm_tag_end,tag) then            -- do we have a tag-end too?
  1439.         tag=substr(tag,1,pos(bkm_tag_end,tag)-1)        -- remove it
  1440.         linerest=substr(line,bkm_last_colon+length(strip(tag))+1) -- get new rest
  1441.         caution=2                               -- be careful
  1442.       else
  1443.         linerest=substr(line,bkm_last_colon+length(strip(tag))) -- get rest
  1444.       endif
  1445.     endif
  1446.     if bkm_last_colon>1 then                    -- tag-start not in first col?
  1447.       line=substr(line,1,bkm_last_colon-1)      -- get left stuff
  1448.     else
  1449.       line=''                                   -- no left stuff
  1450.     endif
  1451. /* Now we have got the tag. Put it into lower case and  */
  1452. /* remove the leading and trailing blanks.              */
  1453.     save_tag=strip(tag)                         -- save original cases
  1454.     tag=lowcase(save_tag)                       -- fold to lowercase
  1455. compile if bkm_debugging
  1456.     if bkm_debug then call bkm_say("bkm_expansion... tag="tag" caution="caution" line="line" linerest="linerest,0) endif
  1457. compile endif
  1458. /* If the length of the tag is 1, the user has just     */
  1459. /* typed a colon followed by a space. We leave this     */
  1460. /* as entered.                                          */
  1461.     if length(tag)>1 then                       --
  1462. /* Let's check if there is a valid tag. "tag_line" will */
  1463. /* contain "0" if it is not a valid tag, otherwise it   */
  1464. /* contains the number of the line with the tag. The    */
  1465. /* global variable "bkm_line_text" contains the text of */
  1466. /* the line, which contains the formatting intructions. */
  1467.       tag_line=bkm_find_tag(tag)        -- search tag in index
  1468. /* If the return code was -1 we have found an           */
  1469. /* inconsistency in the index. Now we have to create    */
  1470. /* the index again.                                     */
  1471.       if tag_line=-1 then               -- invalid index found?
  1472.         file=bkm_save_file              -- save all definition file names
  1473.         bkm_save_file=''                -- cleanup
  1474.         call bkm_chg_def_file(file,1)   -- force index generation
  1475.         call bkm_upd_line_one()         -- update line one
  1476.         call bkm_select()               -- activate support
  1477.         tag_line=bkm_find_tag(tag)      -- try again
  1478. /* If the return code again indicates an inconsistency, */
  1479. /* there is nothing left to do except to stop the       */
  1480. /* support. This should never happen.                   */
  1481.         if tag_line=-1 then             -- serious trouble
  1482.           call bkm_say("Unrecoverable error with definition file and index, support halted.",0)
  1483.           bkm_avail=0                   -- deactivate support
  1484.           bkm_nocheck=1                 -- deactivate initialization
  1485.           return 0                      -- exit
  1486.         endif
  1487.       endif
  1488.       if tag_line=0 then                -- did we find the tag?
  1489. /* No, either replace it with variable, or just return. */
  1490. compile if bkm_repl_colon=1
  1491. /* The caution flag is 2 when we found an invalid tag   */
  1492. /* including the tag-end character. The tag-start       */
  1493. /* character will be replaced.                          */
  1494.         if caution=2 then               -- replace it.
  1495.           replaceline line||bkm_inv_tag_rep||substr(save_tag,2)||bkm_tag_end||linerest
  1496.         else            -- otherwise just replace the tag-start character
  1497.           replaceline line||bkm_inv_tag_rep||substr(save_tag,2)||linerest
  1498.         endif
  1499.         if .col>=bkm_last_colon then .col=.col+length(bkm_inv_tag_rep)-1 endif -- set cursor
  1500. compile endif
  1501.         retc=0          -- set bad return code (this is necessary, because the
  1502. ;                       -- last key typed by the user has not been inserted in
  1503. ;                       -- the text yet.
  1504.       else
  1505.         if caution then
  1506.           if linerest<>'' then return 0 endif
  1507.           if caution=2 then return 0 endif
  1508.         endif
  1509. /* The tag has been found. The variable bkm_line_text   */
  1510. /* contains the formatting instructions. The format     */
  1511. /* of this line is:                                     */
  1512. /*                                                      */
  1513. /* :tag   the tag name (without the ending period)      */
  1514. /*                                                      */
  1515. /* flag   the flag. Refer to the routine "bkm_process"  */
  1516. /*        for a description of the flag.                */
  1517. /*                                                      */
  1518. /* text   the required parameters of the tag. The '#'   */
  1519. /*        sign can be used to position the cursor.      */
  1520. /*                                                      */
  1521. /* +      delimiter                                     */
  1522. /*                                                      */
  1523. /* text   the usual optional parameters                 */
  1524. /*                                                      */
  1525. /* +      delimiter                                     */
  1526. /*                                                      */
  1527. /* text   all optional parameters                       */
  1528. /*                                                      */
  1529. /* ||     delimiter                                     */
  1530. /*                                                      */
  1531. /* text   additional lines which should be inserted     */
  1532. /*        after the tag. A "\" is interpreted as "CR"   */
  1533. /*        the "#" can be used to position the cursor.   */
  1534. /*                                                      */
  1535. /* ||     delimiter                                     */
  1536. /*                                                      */
  1537. /* text   lines which should go BEFORE the tag.         */
  1538. /*                                                      */
  1539. /* ||     delimiter                                     */
  1540. /*                                                      */
  1541. /* tag    tag which will be assigned to the a_2 key     */
  1542. /*                                                      */
  1543.         parse value bkm_line_text with xtag flag sameline '||' otherlines '||' beforelines '||' rep_tag
  1544.         if rep_tag<>'' then             -- anything after the third delimiter?
  1545.           bkm_rep_tag=rep_tag           -- assign it to the a_2 key
  1546. compile if bkm_tags_between<>''
  1547.           call bkm_upd_files(-1,bkm_between)    -- save it in hidden file
  1548. compile else
  1549.           call bkm_upd_files(-1,' ')            -- save it in hidden file
  1550. compile endif
  1551.         endif
  1552.         parse value sameline with req '+' opt '+' all   -- get the parameters
  1553. compile if bkm_space_key='ALL'
  1554.         if char=' ' then char='a' endif
  1555. compile endif
  1556.         sameline=strip(req)             -- remove blanks
  1557.         opt=strip(opt)                  -- from optional too
  1558.         all=strip(all)                  -- and finally from optional optional.
  1559.         if char='a' then                -- shall we display everything?
  1560.           char=' '                      -- set to space
  1561.           opt=opt||' '||all             -- optional is all
  1562.         endif
  1563.         if char=' ' then                -- want parameters displayed
  1564. /* Now we have to remove the tag-end character (if any) */
  1565.           if pos(bkm_tag_end,sameline) then sameline=substr(sameline,1,pos(bkm_tag_end,sameline)-1) endif
  1566.           sameline=strip(sameline||' '||opt)    -- store all parms
  1567.         endif
  1568. /* Set the defaults.                                    */
  1569.         if flag='' then flag=1 endif    -- default flag is 1
  1570.         if sameline='' then             -- nothing there?
  1571.           sameline=bkm_tag_end||'#'     -- position cursor after end
  1572.         else
  1573. /* If the first character of the parameter is not an tag-end    */
  1574. /* the we must have a space inserted. (Otherwise the parameters */
  1575. /* would be glued to the tag, and we don't want that, do we?)   */
  1576.           if substr(sameline,1,1)<>bkm_tag_end then sameline=' '||sameline endif
  1577. /* Now we have to add a tag-end character at the end.           */
  1578.           if not pos(bkm_tag_end,sameline) then sameline=sameline||bkm_tag_end endif
  1579. /* If there is no cursor position defined, we put the cursor    */
  1580. /* after the end of the tag.                                    */
  1581.           if not pos('#',sameline) then sameline=sameline||'#' endif
  1582.         endif
  1583. /* Process the tag.                                     */
  1584.         retc=bkm_process(line,tag,flag,sameline,strip(otherlines),strip(beforelines))
  1585. /* Get the line which contains the cursor. If there is  */
  1586. /* something after the cursor we have to switch         */
  1587. /* inserting on.                                        */
  1588.         getline line                    -- get current line
  1589.         if substr(line,.col)<>'' then   -- something after the cursor?
  1590.           if not insert_state() then insert_toggle       -- insert on if yes
  1591. compile if EVERSION >= '5.50'
  1592.              call fixup_cursor()
  1593. compile endif
  1594.            endif
  1595.         endif
  1596. /* If the dynamic margins are configured, check it too. */
  1597. compile if bkm_tags_between<>''
  1598.         parse value line with xtag .                    -- get tag
  1599.         parse value xtag with xtag (bkm_tag_end) .      -- remove tag-end
  1600.         if xtag<>tag then -- not the same? (that means that the cursor is not in the line which contains the tag)
  1601.           if pos(tag||' ',bkm_tags_between||' ') then   -- tag in list?  [LAM: change to wordpos() for 5.20+?]
  1602.             'ma 1 254 1'                        -- reset margins
  1603. compile if bkm_debugging
  1604.             if bkm_debug then call bkm_say("Margins changed to 1 254 1.",0) endif
  1605. compile endif
  1606.             call bkm_upd_files(-1,tag)          -- store in hidden file
  1607.             bkm_between_new=tag                 -- set flag
  1608.           endif
  1609.         endif
  1610. compile endif
  1611.       endif
  1612. compile if bkm_want_symbols
  1613.     else                              -- else check for replacement
  1614.       retc=0                            -- set bad return code
  1615.       if bkm_symbols_active = 1 then    -- symbol support active?
  1616.         if pos(bkm_tag_start,bkm_symbols) then  -- if key found in table continue
  1617.           getfileid id,bkm_sym_file   -- get id of symbol file
  1618.           if id<>'' then              -- if available
  1619.             getline line,asc(bkm_tag_start),id  -- get the line from the symbol file
  1620.             parse value line with . k .       -- get the replacement string
  1621.             keyin k                     -- type the variable
  1622.             retc=1                      -- good return code
  1623.           endif
  1624.         endif
  1625.       endif
  1626. compile else
  1627.     else
  1628.       retc=0
  1629. compile endif
  1630.     endif
  1631.   else
  1632.     retc=0
  1633.   endif
  1634. return retc
  1635.  
  1636. /* Generic routine to insert the tag and optionally     */
  1637. /* the parameters into the same, or into multiple       */
  1638. /* lines. The input parameters are:                     */
  1639. /*  1 ... the part of the line to the left of the tag   */
  1640. /*  2 ... the tag (without the ending period)           */
  1641. /*  3 ... a switch. This switch can be:                 */
  1642. /*        1 ... force tag on new line, leave linerest   */
  1643. /*              on old line.                            */
  1644. /*        2 ... force tag on new line, move linerest    */
  1645. /*              after the tag.                          */
  1646. /*        3 ... leave tag where it is, if add. tag      */
  1647. /*              defines, put on end of line.            */
  1648. /*        4 ... additional tags contain file name which */
  1649. /*              should be inserted. Parameters are      */
  1650. /*              resolved as if flag=1.                  */
  1651. /*        5 ... same as 4, but tag is not inserted into */
  1652. /*              text.                                   */
  1653. /*  4 ... the parameters which should be inserted       */
  1654. /*  5 ... other tags which have to be inserted into     */
  1655. /*        new lines, or the same line (flag=3)          */
  1656. /*  6 ... other stuff which should be inserted before   */
  1657. /*        the line with the tag.                        */
  1658. defproc bkm_process(line,tag,force,parms,xother,beforelines)
  1659.   universal bkm_last_colon
  1660.   universal linerest
  1661.   universal bkm_save_file
  1662.   universal bkm_nocheck
  1663.   universal bkm_tag_end
  1664.   universal bkm_keepspace
  1665. compile if bkm_attr
  1666.   universal bkm_did_bkmattr
  1667. compile endif
  1668. compile if bkm_debugging
  1669.   universal bkm_debug
  1670.   if bkm_debug then call bkm_say("bkm_process("line","tag","force","parms","xother","beforelines")",0) endif
  1671. compile endif
  1672.   if force > 10 then
  1673.     force = force - 10
  1674.     bkm_keepspace = 1
  1675.   endif
  1676.   if line='' & linerest='' & not bkm_keepspace then bkm_last_colon=1 endif  -- move tag to position one
  1677.   savepos=pos('#',parms)                -- save new cursor postition
  1678.   cursor=savepos+length(tag)+bkm_last_colon-1   -- calculate new position
  1679. /* Remove the number (hash) sign from the parameters    */
  1680.   -- LAM:  If we know there's always a '#', could replace next two lines (if 5.20 or above):
  1681.   parse value parms with p1 '#' p2
  1682.   parms=p1||p2                  -- concatinate parameter
  1683.   -- with:  parms = delstr(parms, savepos, 1)
  1684. /* Save current line number, this is where the cursor   */
  1685. /* should go.                                           */
  1686.   new_line=.line
  1687.   if force=1 | force=4 then             -- tag must start in new line
  1688.     if bkm_last_colon=1 & linerest='' then      -- is alread there?
  1689.       replaceline tag||parms                    -- put tag and parms in line
  1690.     else
  1691. /* Remove the tag from the middle of the line, and      */
  1692. /* create a separate line for the tag.                  */
  1693.       replaceline line||linerest
  1694. compile if bkm_attr
  1695.       if bkm_did_bkmattr=1 then call bkm_upd_line_attr(.line) endif
  1696. compile endif
  1697. /* Now we have to redefine the cursor position          */
  1698.       cursor=cursor-bkm_last_colon+1
  1699.       if bkm_keepspace then
  1700.         if strip(line||linerest) = '' then
  1701.           replaceline substr(' ',1,length(line))||tag||parms
  1702.         else
  1703.           insertline substr(' ',1,length(line))||tag||parms,.line+1
  1704. /* The tag is on the next line, therefore we have to    */
  1705. /* position the cursor one line down.                   */
  1706.           new_line=new_line+1
  1707.           down
  1708.         endif
  1709.         cursor=cursor+length(line)
  1710.       else
  1711.         insertline tag||parms,.line+1
  1712. /* The tag is on the next line, therefore we have to    */
  1713. /* position the cursor one line down.                   */
  1714.         new_line=new_line+1
  1715.         down
  1716.       endif
  1717.     endif
  1718.     if force=4 then             -- get additional lines from file
  1719. /* xother contains file name                            */
  1720.       call bkm_get(strip(upcase(xother)))
  1721.       if rc<>0 then                             -- file not found, tell user
  1722.         call bkm_say("File" strip(upcase(xother)) "not found, repair" bkm_save_file".",0)
  1723. compile if EVERSION < 4
  1724.       else
  1725.         call bkm_init()                         -- initialize support
  1726. compile endif
  1727.       endif
  1728.       xother=''                                 -- cleanup
  1729.     endif
  1730.   elseif force=2 then
  1731. /* Remove the tag from the middle of the line, but      */
  1732. /* move the remainder of the line after the tag.        */
  1733.     if bkm_last_colon=1 then            -- tag-start in column 1?
  1734.       replaceline tag||parms||linerest  -- insert tag in position 1
  1735.     else
  1736.       replaceline line                  -- store stuff left of the tag
  1737. compile if bkm_attr
  1738.       if bkm_did_bkmattr=1 then call bkm_upd_line_attr(.line) endif
  1739. compile endif
  1740.       cursor=cursor-bkm_last_colon+1    -- position cursor
  1741.       if bkm_keepspace then
  1742.         if strip(line||linerest) = '' then
  1743.           replaceline substr(' ',1,length(line))||tag||parms||linerest   -- create a new line with the rest
  1744.         else
  1745.           insertline substr(' ',1,length(line))||tag||parms||linerest,.line+1   -- create a new line with the rest
  1746.           new_line=new_line+1               -- down one line
  1747.           down
  1748.         endif
  1749.         cursor=cursor+length(line)
  1750.       else
  1751.         insertline tag||parms||linerest,.line+1   -- create a new line with the rest
  1752.         new_line=new_line+1               -- down one line
  1753.         down
  1754.       endif
  1755.     endif
  1756.   elseif force=3 then                   -- tag may be anywhere in the line
  1757.     if bkm_last_colon=1 & linerest='' then      -- we are in position 1
  1758.       replaceline tag||parms            -- store tag and parameters
  1759.     else
  1760. /* This is a special case. The tag has been in the middle of a  */
  1761. /* line, we don't want to generate additional lines. So we      */
  1762. /* take the stuff which would otherwise go in new lines, and    */
  1763. /* put it in the line where the tag is.                         */
  1764.       parse value xother with p1 '#' p2 -- remove #
  1765.       xother=p1||p2                     -- concatenate
  1766.       parse value xother with p1 '\' p2 -- remove new line
  1767.       xother=p1||p2                     -- concatenate again
  1768.       replaceline line||tag||parms||linerest||xother -- replace line
  1769.       xother=''                         -- cleanup
  1770.     endif
  1771.   elseif force=5 then                   -- get data from file
  1772. /* xother contains file name                            */
  1773.     call bkm_get(strip(upcase(xother)))
  1774.     if rc then                             -- file not found, tell user
  1775.       call bkm_say("File" strip(upcase(xother)) "not found, repair" bkm_save_file".",0)
  1776. compile if EVERSION < 4
  1777.     else
  1778.       call bkm_init()                         -- initialize support
  1779. compile endif
  1780.     endif
  1781.     xother=''                                 -- cleanup
  1782.     if line||linerest='' then           -- tag was on empty line
  1783.       deleteline                        -- delete line
  1784.     else                                -- otherwise
  1785.       replaceline line||linerest        -- remove tag from line
  1786.       new_line=new_line+1               -- position cursor
  1787.       down
  1788.     endif
  1789.     getline xline,new_line              -- get new cursor position
  1790.     cursor=length(strip(xline))+1
  1791.   else
  1792.     call bkm_say('Flag' force 'for' tag 'invalid, repair' bkm_save_file".",0)
  1793.   endif
  1794. compile if bkm_attr
  1795.   if bkm_did_bkmattr=1 then call bkm_upd_line_attr(.line) endif
  1796. compile endif
  1797. /* Now generate additional lines, if any.               */
  1798.   if beforelines<>'' then               -- anything to add before the tag?
  1799.     loop                                -- loop over data
  1800.       parse value beforelines with iline '\' beforelines -- get CR
  1801.       if beforelines='' & iline='' then leave endif     -- any more data?
  1802.       if substr(iline,1,1)='%' then
  1803.         filename=upcase(strip(substr(iline,2)))
  1804.         savesize=.last                          -- save current size
  1805.         '-1'                                    -- back one line
  1806.         call bkm_get(filename)
  1807.         if rc then                             -- file not found, tell user
  1808.           call bkm_say("File" filename "not found, repair" bkm_save_file".",0)
  1809.           '+1'
  1810.         else
  1811.           new_line=new_line+.last-savesize        -- new line position
  1812. compile if EVERSION < 4
  1813.           call bkm_init()                         -- initialize support
  1814. compile endif
  1815.         endif
  1816.       else
  1817.         insertline iline,.line            -- yes, insert line, even if blank
  1818. compile if bkm_attr
  1819.         if bkm_did_bkmattr=1 then call bkm_upd_line_attr(.line) endif
  1820. compile endif
  1821.         new_line=new_line+1               -- remember new line position
  1822.       endif
  1823.       new_line                            -- set global
  1824.     endloop
  1825.   endif
  1826.   if xother<>'' then
  1827.     i=0
  1828.     loop                                  -- loop over stuff after the tag
  1829.       i=i+1
  1830.       parse value xother with iline '\' xother    -- get CR
  1831.       if xother='' & iline='' then leave endif    -- exit loop if nothing else
  1832.       if substr(iline,1,1)='%' then
  1833.         filename=upcase(strip(substr(iline,2)))
  1834.         savesize=.last                          -- save current size
  1835.         saveline=.line
  1836.         .line=.line+i-1                         -- calculate where it should go
  1837.         call bkm_get(filename)
  1838.         if rc then                             -- file not found, tell user
  1839.           call bkm_say("File" filename "not found, repair" bkm_save_file".",0)
  1840.           .line=.line+1-i
  1841.         else
  1842.           i=i+.last-savesize-1                    -- set new index
  1843.           saveline
  1844. compile if EVERSION < 4
  1845.           call bkm_init()                         -- initialize support
  1846. compile endif
  1847.         endif
  1848.       else
  1849.         insertline iline,.line+i            -- insert data
  1850.         x=pos('#',iline)                    -- cursor in this line?
  1851.         y=pos('@',iline)
  1852.         if x | y then                         -- yes, '#' found
  1853.           if x>1 then                       -- position at first column?
  1854. compile if EVERSION >= '5.20'
  1855.             iline = delstr(iline, x, 1)     -- no, delete that character
  1856. compile else
  1857.             parse value iline with p1 '#' p2  -- no, get before and after
  1858.             iline=p1||p2                    -- concatinate them
  1859. compile endif
  1860.           elseif y>1 then                   -- position at first column?
  1861. compile if EVERSION >= '5.20'
  1862.             iline = delstr(iline, y, 1)     -- no, delete that character
  1863. compile else
  1864.             parse value iline with p1 '@' p2  -- no, get before and after
  1865.             iline=p1||p2                    -- concatinate them
  1866. compile endif
  1867.           else
  1868.             iline=strip(substr(iline,2))    -- get rest of line
  1869.           endif
  1870.           replaceline iline,.line+i         -- replace the line
  1871. /* Now we have to check if the cursor is already positioned in  */
  1872. /* the line with the tag. If not, we can move it to this        */
  1873. /* position safely.                                             */
  1874.           if parms=bkm_tag_end | not savepos | y then  -- only default cursor?
  1875.             cursor=x+y                      -- yes, set cursor
  1876.             new_line=.line+i                -- set new line position
  1877.           endif
  1878.         endif
  1879. compile if bkm_attr
  1880.         if bkm_did_bkmattr=1 then call bkm_upd_line_attr(.line+i) endif
  1881. compile endif
  1882.       endif
  1883.     endloop
  1884.   endif
  1885. /* At the end we have to set the new cursor position.   */
  1886.   .col=cursor                           -- set cursor position
  1887.   new_line                              -- move cursor to correct line
  1888. return 1
  1889.  
  1890. /* The next routine checks the tag. If it is valid, the */
  1891. /* return code contains the line number of the tag in   */
  1892. /* the tag-definition file. If not, the return code is  */
  1893. /* zero. If an inconsistency is found, the return code  */
  1894. /* is set to -1.                                        */
  1895. defproc bkm_find_tag(tag)
  1896.   universal bkm_line_text
  1897.   universal bkm_def
  1898.   universal bkm_idx
  1899. compile if bkm_debugging
  1900.   universal bkm_debug
  1901.   if bkm_debug then call bkm_say('Searching for tag' tag".",0) endif
  1902. compile endif
  1903. /* Save the id of the current file.                     */
  1904. /* Get the id of the index file.                        */
  1905.   getfileid id,bkm_idx                  -- get id of index
  1906.   if id='' then return -1 endif         -- exit if index not found
  1907. /* A word to the index. The first line of the index     */
  1908. /* contains the names of the current tag-definition     */
  1909. /* files. This is checked somewhere else. At this point */
  1910. /* we can be sure that the index points to the right    */
  1911. /* tag-definition file.                                 */
  1912.   for i = 2 to 9999                     -- loop over index
  1913.     if i>id.last then leave endif       -- end of file?
  1914.     getline tagline,i,id                -- no, get line from index
  1915.     xpos=pos(tag||' ',tagline)          -- check for tag
  1916.     if xpos then                      -- tag found
  1917.       xtag=substr(tagline,xpos)         -- make tag first word
  1918.       parse value xtag with curtag curline .    -- get tag and line number
  1919.       getfileid id,bkm_def              -- get id of definition file
  1920.       if id='' then return -1 endif     -- exit if no definition file found
  1921.       getline bkm_line_text,curline,id  -- get the line with the number found in the index
  1922.       parse value bkm_line_text with istag flag . -- get tag and flag
  1923.       if istag<>tag then return -1 endif -- same tag? If not -> inconsistant
  1924.       if flag='-' then return 0 endif   -- tag "undefined" ?
  1925.       return curline                    -- return data to caller
  1926.     endif
  1927.   endfor
  1928. return 0                                -- no luck, no tag
  1929.  
  1930. /* Routine to display text on the status line. If debug */
  1931. /* is on, also wait for a key.                          */
  1932. defproc bkm_say(msg,flag)
  1933. compile if bkm_debugging
  1934.   universal bkm_debug
  1935.   if bkm_debug then flag=1 endif        -- wait for key in debug mode
  1936. compile endif
  1937.   if flag=1 then                        -- wait for key?
  1938. compile if EVERSION < 5
  1939.     msg=msg||' ...'                     -- yes, put ellipses after text
  1940. compile endif
  1941.     call messageNwait("EBOOKIE: "msg)   -- prefix message with "EBOOKIE"
  1942. compile if EVERSION < 5
  1943.     getfileid curfileid                 -- get current id
  1944.     sayerror 0                          -- clean message area
  1945.     activatefile curfileid              -- get back current file
  1946. compile endif
  1947.   else                                  -- don't wait for key
  1948.     call message("EBOOKIE: "msg)        -- call appropriate routine
  1949.   endif
  1950.  
  1951. /* The following routine is accessed at the time the    */
  1952. /* file is read from the disk. First we have to check   */
  1953. /* for the footprint ".* EBOOKIE". Then the extension   */
  1954. /* checked. Finally, if configured, we check a user-    */
  1955. /* defined number of lines for a valid tag. If the      */
  1956. /* tag we find is invalid, we don't start the support,  */
  1957. /* If it is OK; we start EBOOKIE.                       */
  1958. /*                                                      */
  1959. /* In E3 this routine is also accessed whenever the user*/
  1960. /* switches from one file to the other in the ring,     */
  1961. /* therefore we have to take care of that too.          */
  1962. /*                                                      */
  1963. defproc bkm_init()
  1964.   universal bkm_last_colon
  1965.   universal bkm_def
  1966.   universal bkm_idx
  1967.   universal bkm_avail
  1968.   universal bkm_message
  1969. compile if bkm_debugging
  1970.   universal bkm_debug
  1971. compile endif
  1972.   universal bkm_nocheck
  1973.   universal bkm_save_file
  1974.   universal bkm_cur_num
  1975.   universal bkm_rep_tag
  1976.   universal bkm_tag_start
  1977.   universal bkm_tag_end
  1978.   universal bkm_end_tag
  1979.   universal bkm_config
  1980. compile if bkm_tags_between<>''
  1981.   universal bkm_between_new
  1982. compile endif
  1983. compile if bkm_attr
  1984.   universal bkm_did_bkmattr
  1985. compile endif
  1986.   universal vTEMP_PATH
  1987.   universal vAUTOSAVE_PATH
  1988.   universal bkm_temp_path
  1989.  
  1990. compile if bkm_debugging
  1991.   if bkm_debug then call bkm_say("bkm_init()" .filename,0) endif
  1992. compile endif
  1993.  
  1994.   if bkm_temp_path='' then
  1995.     bkm_temp_path=strip(vAUTOSAVE_PATH)
  1996. compile if defined(AUTOSAVE_PATH)
  1997.     if bkm_temp_path='' then
  1998.       bkm_temp_path=strip(AUTOSAVE_PATH)
  1999.     endif
  2000. compile endif
  2001.     if bkm_temp_path='' then
  2002.       bkm_temp_path=strip(vTEMP_PATH)
  2003.     endif
  2004. compile if defined(TEMP_PATH)
  2005.     if bkm_temp_path='' then
  2006.       bkm_temp_path=strip(TEMP_PATH)
  2007.     endif
  2008. compile endif
  2009.     if bkm_temp_path<>'' then
  2010. compile if EVERSION >= '5.20'
  2011.       if rightstr(bkm_temp_path,1)<>'\' then
  2012. compile else
  2013.       if substr(bkm_temp_path,length(bkm_temp_path),1)<>'\' then
  2014. compile endif
  2015.         bkm_temp_path=bkm_temp_path||'\'
  2016.       endif
  2017.     endif
  2018.   endif
  2019. /* Skip files which we should not touch.                */
  2020.   if bkm_nocheck=1 then return 0 endif          -- internal files are not checked
  2021.   if substr(.filename,1,1)='.' then return 0 endif -- files which start with a period are not checked
  2022.   if .filename=bkm_def then return 0 endif      -- the definitions file is not checked
  2023.   if .filename=bkm_idx then return 0 endif      -- so is the index
  2024. /* Notify debugging user if we continue our work.       */
  2025. compile if bkm_debugging
  2026.   if bkm_debug then call bkm_say("bkm_init()" .filename "continues",0) endif
  2027. compile endif
  2028. compile if EVERSION < 4
  2029.   if bkm_find_file(.filename)>=0 then           -- look for file in hidden table
  2030.     call bkm_select()                           -- start the support
  2031.     return 0                                    -- return to caller
  2032.   endif
  2033. compile endif
  2034.   bkm=0                                 -- cleanup
  2035.   for i=1 to .last                      -- loop over beginning of file
  2036.     getline line,i                      -- get line
  2037.     parse value line with flag1 flag2 '(' def_file ')' . -- find footprint
  2038.     if flag1='.*' & flag2='EBOOKIE' then
  2039.       bkm=1                             -- footprint found
  2040.       leave                             -- exit loop
  2041.     endif
  2042.     if substr(flag1,1,2)<>'.*' then leave endif -- no comment, exit loop
  2043.   endfor
  2044.   if not bkm then
  2045.     def_file=bkm_def_file
  2046.     ext=filetype()
  2047. compile if EVERSION >= '5.20'
  2048.     if ext <> '' & wordpos(upcase(ext),upcase(bkm_files)) then
  2049. compile else
  2050.     x_files=bkm_files     -- LAM: assume this is because old versions of E uppercased the upcase() parm; doesn't happen with current versions.
  2051.     if pos(' '||strip(upcase(ext))||' ',' '||strip(upcase(x_files))||' ') then
  2052. compile endif
  2053.       bkm=1
  2054.       x_files=bkm_ext_def
  2055.       x=pos(strip(upcase(ext))||'=',upcase(x_files))
  2056.       if x then
  2057.         x_files=Substr(x_files,x)
  2058.         parse value x_files with . '=' def_file '=' .
  2059.         if pos('=',x_files) then
  2060.           x = lastpos(' ',def_file)
  2061.           def_file = substr(def_file,1,x)
  2062.         endif
  2063.         def_file=strip(def_file)
  2064.         If Substr(def_file,1,1) = '"' | substr(def_file,1,1) = "'" then
  2065.           def_file = Substr(def_file,2,Length(def_file)-2)
  2066.         endif
  2067.         if def_file = '' then def_file=bkm_def_file endif
  2068.       endif
  2069. compile if bkm_search > 0
  2070.     else
  2071.       search=max(bkm_search, 10)
  2072. /* Now search the first 100 lines of the file, or at    */
  2073. /* least the number of lines the user has specified.    */
  2074.       for i=1 to search
  2075.         if i=.last then leave endif
  2076.         getline line,i
  2077.         parse value line with tag .
  2078.         if substr(tag,1,1)<>bkm_tag_start then iterate endif
  2079.         parse value tag with tag (bkm_tag_end) .
  2080.         if length(tag)<2 then iterate endif
  2081.         if bkm_avail=-1 then
  2082.           call bkm_chg_def_file(def_file,0)
  2083.         endif
  2084.         if bkm_avail=0 then return 0 endif
  2085.         if bkm_find_tag(lowcase(tag))=0 then leave endif
  2086.         bkm=1
  2087.         leave
  2088.       endfor
  2089. compile endif
  2090.     endif
  2091.   endif
  2092.   bkm_rep_tag=''
  2093.   if bkm<>0 then
  2094.     call bkm_chg_def_file(def_file,0)
  2095.     if bkm_avail=0 then return 0 endif
  2096.     bkm=bkm_cur_num
  2097.     call bkm_upd_line_one()
  2098. compile if E3
  2099.     keys bkm_keys
  2100. compile endif
  2101. compile if bkm_dont_touch_margins=0
  2102.     'ma' bkm_margins
  2103. compile endif
  2104.     join_after_wrap=0
  2105.     bkm_last_colon=0
  2106. compile if EVERSION < 5
  2107.     c_state = command_state()
  2108.     if c_state then commandtoggle; endif
  2109. compile endif
  2110.     if bkm_config <> '' then
  2111.       'xcom L /.mod' bkm_config'/ca'
  2112.       bkm_config = ''
  2113.     else
  2114.       top
  2115.       down
  2116.     endif
  2117. compile if EVERSION < 5
  2118.     if c_state then commandtoggle; endif
  2119. compile endif
  2120. compile if bkm_attr
  2121.     bkm_did_bkmattr=1
  2122.     call attribute_on(1)  -- "Color attributes" flag
  2123.     call attribute_on(8)  -- "Save attributes" flag
  2124. compile if bkm_attr_init=1
  2125.     call bkm_add_attr('on')
  2126. compile endif
  2127. compile endif
  2128.   endif
  2129.   call bkm_upd_files(bkm,' ')
  2130. compile if bkm_tags_between<>''
  2131.   bkm_between_new=''
  2132. compile endif
  2133. compile if bkm_debugging
  2134.   if bkm_debug then call bkm_say("bkm_init()" .filename" ended, rc="bkm,0) endif
  2135. compile endif
  2136. return bkm
  2137.  
  2138. /* The following routine is called during the DEFSELECT */
  2139. /* processing in EOS2 or EPM, or during the             */
  2140. /* select_edit_keys() processing in E3.                 */
  2141. defproc bkm_select()
  2142.   universal bkm_last_colon
  2143. compile if bkm_tags_between<>''
  2144.   universal bkm_between
  2145.   universal bkm_between_new
  2146. compile endif
  2147. compile if bkm_debugging
  2148.   universal bkm_debug
  2149.   if bkm_debug then call bkm_say("bkm_select() called for ".filename,0) endif
  2150. compile endif
  2151.   bkm=bkm_find_file(.filename)
  2152.   if bkm>0 then
  2153. compile if E3
  2154.     keys bkm_keys
  2155. compile if bkm_dont_touch_margins=0
  2156.     'ma' bkm_margins
  2157. compile endif
  2158.     join_after_wrap=0
  2159. compile endif
  2160.     bkm_last_colon=0
  2161.     call bkm_switch(bkm)
  2162. compile if bkm_tags_between<>''
  2163.     bkm_between_new=bkm_between
  2164.     if bkm_between<>'' then
  2165.       'ma 1 254 1'
  2166.     endif
  2167. compile endif
  2168. compile if E3
  2169.   else
  2170.     ext=filetype()
  2171.     if ext='' then
  2172.       keys edit_keys
  2173. compile if bkm_dont_touch_margins=0
  2174.       'tabs' DEFAULT_TABS
  2175.       'ma' DEFAULT_MARGINS
  2176. compile endif
  2177. compile if E_SYNTAX_ASSIST and ALTERNATE_KEYSETS
  2178.     elseif ext='E' then
  2179.        keys e_keys
  2180. compile if bkm_dont_touch_margins=0
  2181.        'tabs' E_TABS
  2182.        'ma'   E_MARGINS
  2183. compile endif
  2184. compile endif
  2185. compile if C_SYNTAX_ASSIST and ALTERNATE_KEYSETS
  2186.     elseif ext='C' then
  2187.        keys c_keys
  2188. compile if bkm_dont_touch_margins=0
  2189.        'tabs' C_TABS
  2190.        'ma'   C_MARGINS
  2191. compile endif
  2192. compile endif
  2193. compile if P_SYNTAX_ASSIST and ALTERNATE_KEYSETS
  2194.     elseif ext='PAS' | ext='PASCAL' then
  2195.        keys pas_keys
  2196. compile if bkm_dont_touch_margins=0
  2197.        'tabs' P_TABS
  2198.        'ma'   P_MARGINS
  2199. compile endif
  2200. compile endif
  2201. compile if REXX_SYNTAX_ASSIST and ALTERNATE_KEYSETS
  2202.     elseif ext='BAT' | ext='CMD' | ext='EXC' | ext='EXEC' | ext='XEDIT' then
  2203.       getline line,1
  2204.       if substr(line,1,2)='/*' or (line='' & .last = 1) then
  2205.         keys rexx_keys
  2206. compile if bkm_dont_touch_margins=0
  2207.         'tabs' REXX_TABS
  2208.         'ma'   REXX_MARGINS
  2209. compile endif
  2210.       endif
  2211. compile endif
  2212.     else
  2213.       keys edit_keys
  2214. compile if bkm_dont_touch_margins=0
  2215.       'tabs' DEFAULT_TABS
  2216.       'ma' DEFAULT_MARGINS
  2217. compile endif
  2218.     endif
  2219. compile endif
  2220.   endif
  2221. return 0
  2222.  
  2223. /* Open or change the tag-definition files.             */
  2224. defproc bkm_chg_def_file(file,force)
  2225.   universal bkm_def
  2226.   universal bkm_idx
  2227.   universal bkm_avail
  2228.   universal bkm_nocheck
  2229.   universal bkm_save_file
  2230.   universal bkm_num
  2231.   universal bkm_cur_num
  2232. compile if bkm_want_symbols
  2233.   universal bkm_symbols
  2234.   universal bkm_symbols_active
  2235.   universal bkm_sym_file
  2236.   universal bkm_codepage
  2237. compile endif
  2238.   universal bkm_tag_start
  2239.   universal bkm_tag_end
  2240.   universal bkm_end_tag
  2241.   universal bkm_rep_tag
  2242.   universal bkm_inv_tag_rep
  2243.   universal bkm_temp_path
  2244. compile if bkm_debugging
  2245.   universal bkm_debug
  2246.   if bkm_debug then call bkm_say("bkm_chg_def_file("file","force")",0) endif
  2247. compile endif
  2248.   savefile=upcase(strip(file))
  2249.   save_def=bkm_def
  2250.   save_idx=bkm_idx
  2251.   save_avail=bkm_avail
  2252.   save_cur_num=bkm_cur_num
  2253. compile if bkm_want_symbols
  2254.   save_symbols=bkm_symbols
  2255.   save_symbols_active=bkm_symbols_active
  2256.   save_sym_file=bkm_sym_file
  2257. compile endif
  2258.   if not force then
  2259.     for i = 1 to 99
  2260.       xrc=bkm_switch(i)
  2261.       if xrc=1 then leave endif
  2262.       if savefile=bkm_save_file then
  2263.         getfileid id,'.BKM'
  2264. compile if EVERSION < '5.0'
  2265.         save_command_state=command_state()
  2266.         if save_command_state then commandtoggle endif
  2267. compile endif
  2268.         for j=1 to id.last
  2269.           getline line,j,id
  2270.           parse value line with fname '==' retc '||' .
  2271.           if retc=i then
  2272.             call bkm_find_file(fname)
  2273.             leave
  2274.           endif
  2275.         endfor
  2276. compile if EVERSION < '5.0'
  2277.         if save_command_state then commandtoggle endif
  2278. compile endif
  2279.         getfileid bkm_def_fileid,bkm_def
  2280.         getline tag_fline,1,bkm_def_fileid
  2281.         call bkm_get_parms(tag_fline,1)
  2282. compile if bkm_want_symbols
  2283.         if bkm_sym_file<>'' then
  2284.           bkm_sym_file=upcase(bkm_sym_file||'.'||bkm_codepage)
  2285.         endif
  2286. compile endif
  2287.         return 0
  2288.       endif
  2289.     endfor
  2290.   endif
  2291.   getfileid curfileid
  2292.   parse value upcase(file) with file .
  2293.   retc=0
  2294.   bkm_avail=1
  2295.   bkm_def=bkm_findfile(file)
  2296.   if bkm_def='' then bkm_avail=0 endif
  2297.   if bkm_avail=1 then
  2298.     bkm_path=''
  2299.     bkm_def=upcase(bkm_def)
  2300.     x=lastpos('\',bkm_def)
  2301.     if x then bkm_path=substr(bkm_def,1,x) endif
  2302.     bkm_nocheck=1
  2303.     if save_def<>'' & force=1 then
  2304.       getfileid id,save_def
  2305.       if id<>'' then
  2306.         activatefile id
  2307.         .modify=0
  2308.         'quit'
  2309.       endif
  2310.     endif
  2311.     if save_idx<>'' & force=1 then
  2312.       getfileid id,save_idx
  2313.       if id<>'' then
  2314.         activatefile id
  2315.         .modify=0
  2316.         'quit'
  2317.       endif
  2318.     endif
  2319.     activatefile curfileid
  2320. compile if bkm_debugging
  2321.     if bkm_debug then call bkm_say("Inititalizing tag support.",0) endif
  2322. compile endif
  2323. compile if EVERSION > 5
  2324.     'xcom edit' bkm_def
  2325.     .visible=0
  2326. compile else
  2327.     'xcom edit /h /q' bkm_def
  2328. compile endif
  2329.     bkm_save_file=substr(bkm_def,length(strip(bkm_path))+1)
  2330.     x=lastpos('.',bkm_save_file)
  2331.     if x then
  2332.       bkm_idx=substr(bkm_save_file,1,x)||'IDX'
  2333.     else
  2334.       bkm_idx=bkm_save_file||'.IDX'
  2335.     endif
  2336.     if force=1 then
  2337.       bkm_def='.D'||strip(save_cur_num)
  2338.       bkm_cur_num=save_cur_num
  2339.     else
  2340.       bkm_def='.D'||strip(bkm_num)
  2341.       bkm_cur_num=bkm_num
  2342.       bkm_num=bkm_num+1
  2343.     endif
  2344.     .filename=bkm_def
  2345.     getfileid bkm_def_fileid
  2346.     getline tag_fline,1,bkm_def_fileid
  2347.     call bkm_get_parms(tag_fline,1)
  2348.     msg=''
  2349.     parse value savefile with . savefile
  2350.     for i=1 to 9
  2351.       parse value savefile with file savefile
  2352.       if file=' ' then leave endif
  2353.       '0'
  2354.       call bkm_get(strip(upcase(file)))
  2355.       if rc then
  2356.         msg=msg||' '||strip(upcase(file))
  2357.       else
  2358.         activatefile bkm_def_fileid
  2359.         bkm_save_file=bkm_save_file||' '||strip(upcase(file))
  2360.         getline tag_fline,1,bkm_def_fileid
  2361.         call bkm_get_parms(tag_fline,0)
  2362. compile if bkm_want_symbols
  2363.         tag_fline='* EBOOKIE tag_start='||bkm_tag_start||' tag_end='||bkm_tag_end||' end_tag='||bkm_end_tag||' a_2='||bkm_rep_tag||' invalid='||bkm_inv_tag_rep||' symbols='||bkm_sym_file
  2364. compile else
  2365.         tag_fline='* EBOOKIE tag_start='||bkm_tag_start||' tag_end='||bkm_tag_end||' end_tag='||bkm_end_tag||' a_2='||bkm_rep_tag||' invalid='||bkm_inv_tag_rep
  2366. compile endif
  2367.         replaceline tag_fline,1,bkm_def_fileid
  2368.       endif
  2369.     endfor
  2370.     .modify=0
  2371.     if msg<>'' then
  2372.       activatefile curfileid
  2373.       call bkm_say("The file(s)"msg "could not be found.",1)
  2374.     endif
  2375.     line='.* EBOOKIE ('||Strip(bkm_save_file)||')'
  2376.     if bkm_temp_path='' then bkm_temp_path=bkm_path endif
  2377.     bkm_idx=bkm_temp_path||bkm_idx
  2378. compile if EVERSION > 5
  2379.     'xcom edit' bkm_idx
  2380.     .visible=0
  2381. compile else
  2382.     'xcom edit /h /q' bkm_idx
  2383. compile endif
  2384.     .filename=bkm_idx
  2385.     getfileid bkm_idx_fileid
  2386.     if not rc then
  2387.       maxlines=.last
  2388.       getline oline,1
  2389.       if oline<>line | force=1 then
  2390.         for i=1 to maxlines
  2391.           deleteline 1
  2392.           if rc then leave endif
  2393.         endfor
  2394.         rc=1
  2395.       endif
  2396.     endif
  2397.     if rc then
  2398.       activatefile curfileid
  2399.       call bkm_say("Inititalizing tag support, creating tag index, please wait...",0)
  2400.       activatefile bkm_def_fileid
  2401.       j=1
  2402.       bkm_tags=''
  2403.       for i=1 to 9999
  2404.         if i>.last then leave endif
  2405.         getline tline,i
  2406.         parse value tline with xtag rest
  2407.         if substr(xtag,1,1)<>bkm_tag_start then iterate endif
  2408.         bkm_tags=bkm_tags||' '||strip(xtag)||' '||i
  2409.         if length(bkm_tags)>240 then
  2410.           activatefile bkm_idx_fileid
  2411.           if j=1 then
  2412.             insertline line,j
  2413.             j=j+1
  2414.           endif
  2415.           insertline lowcase(strip(bkm_tags)),j
  2416.           j=j+1
  2417.           bkm_tags=''
  2418.           activatefile bkm_def_fileid
  2419.         endif
  2420.       endfor
  2421.       if length(bkm_tags) then
  2422.         activatefile bkm_idx_fileid
  2423.         if j=1 then
  2424.           insertline line,j
  2425.           j=j+1
  2426.         endif
  2427.         insertline lowcase(strip(bkm_tags)),j
  2428.       endif
  2429.       activatefile bkm_idx_fileid
  2430.       'xcom save' bkm_idx
  2431.     endif
  2432.     if force=1 then
  2433.       bkm_idx='.I'||strip(save_cur_num)
  2434.     else
  2435.       bkm_idx='.I'||strip(bkm_cur_num)
  2436.     endif
  2437.     .filename=bkm_idx
  2438.     .modify=0
  2439.     activatefile curfileid
  2440. compile if bkm_want_symbols
  2441.     call bkm_get_sym()
  2442. compile endif
  2443.     bkm_nocheck=0
  2444.   else
  2445.     bkm_def=save_def
  2446.     bkm_idx=save_idx
  2447.     bkm_avail=save_avail
  2448.     bkm_cur_num=save_cur_num
  2449. compile if bkm_want_symbols
  2450.     bkm_symbols=save_symbols
  2451.     bkm_symbols_active=save_symbols_active
  2452.     bkm_sym_file=save_sym_file
  2453. compile endif
  2454.     if bkm_avail=1 then
  2455.       call bkm_say("Could not find the file" file", support status unchanged.",0)
  2456.     else
  2457.       call bkm_say("Could not find the file" file", support not available.",0)
  2458.       bkm_avail=0
  2459.     endif
  2460.     retc=1
  2461.   endif
  2462.   activatefile curfileid
  2463. return retc
  2464.  
  2465. compile if bkm_want_symbols
  2466. defproc bkm_get_sym()
  2467.   universal bkm_symbols
  2468.   universal bkm_symbols_active
  2469.   universal bkm_sym_file
  2470.   universal bkm_codepage
  2471. compile if bkm_debugging
  2472.   universal bkm_debug
  2473.   if bkm_debug then call bkm_say("bkm_get_sym()",0) endif
  2474. compile endif
  2475.   getfileid curfileid
  2476. compile if bkm_debugging
  2477.   if bkm_debug then call bkm_say("Checking symbol support, file="upcase(bkm_sym_file||'.'||bkm_codepage),0) endif
  2478. compile endif
  2479.   if bkm_sym_file<>'' & bkm_codepage<>'' then
  2480.     bkm_sym_file=upcase(bkm_sym_file||'.'||bkm_codepage)
  2481.     getfileid id,bkm_sym_file
  2482.     if id='' | bkm_symbols = '' then
  2483. compile if bkm_debugging
  2484.       if bkm_debug then call bkm_say("Inititalizing symbol table.",0) endif
  2485. compile endif
  2486.       bkm_symbols=''
  2487.       bkm_symbols_active = 0
  2488.       xfile=bkm_findfile(bkm_sym_file)
  2489.       if xfile<>'' then
  2490. compile if EVERSION > 5
  2491.         'xcom edit' xfile
  2492.         .visible=0
  2493. compile else
  2494.         'xcom edit /h /q' xfile
  2495. compile endif
  2496.         if rc then
  2497.           call bkm_say("Error during load of" bkm_sym_file" rc=" rc", symbol support not active.",0)
  2498.           bkm_sym_file=''
  2499.           bkm_symbols=''
  2500.         else
  2501.           .filename=bkm_sym_file
  2502.           getline nosym,1
  2503.           deleteline 1
  2504.           .modify=0
  2505. compile if E3
  2506.           for i=33 to .last           -- skip x'00' to x'20' in E3
  2507. compile else
  2508.           for i=1 to .last
  2509. compile endif
  2510.             getline iline,i
  2511.             if asc(substr(iline,1,1))=i then
  2512.               parse value iline with char symbol '--' .
  2513.               if symbol<>'' then
  2514.                 if not pos(strip(char),nosym) then
  2515.                   bkm_symbols=bkm_symbols||strip(char)
  2516.                 endif
  2517.               endif
  2518.             endif
  2519.           endfor
  2520.           bkm_symbols=strip(bkm_symbols)
  2521.           bkm_symbols_active = 1
  2522.         endif
  2523.         activatefile curfileid
  2524.         call bkm_upd_files(-1,' ')
  2525.       else
  2526.         call bkm_say("Could not locate the file" bkm_sym_file", symbol support not active.",0)
  2527.         bkm_sym_file=''
  2528.         bkm_symbols=''
  2529.       endif
  2530.     else
  2531.       bkm_symbols_active = 1
  2532.       call bkm_upd_files(-1,' ')
  2533.     endif
  2534.   else
  2535.     bkm_sym_file=''
  2536.     bkm_symbols=''
  2537.   endif
  2538. compile endif
  2539.  
  2540. defproc bkm_upd_line_one()
  2541.   universal bkm_save_file
  2542. compile if bkm_debugging
  2543.   universal bkm_debug
  2544.   if bkm_debug then call bkm_say("bkm_upd_line_one()",0) endif
  2545. compile endif
  2546.   oldmod=.modify
  2547.   footprint='.* EBOOKIE ('||Strip(bkm_save_file)||')'
  2548.   if .last<1 then
  2549.     insertline footprint,1
  2550.   else
  2551.     for i=1 to .last
  2552.       getline oline,i
  2553.       parse value oline with flag1 flag2 .
  2554.       if flag1='.*' & flag2='EBOOKIE' then
  2555.         if oline<>footprint then
  2556.           replaceline footprint,i
  2557.         endif
  2558.         leave
  2559.       endif
  2560.       if substr(flag1,1,2)<>'.*' then
  2561.         insertline footprint,i
  2562.         if .last=2 & textline(2)='' then  -- A new file;
  2563.           .modify=oldmod                  -- allow quitting without prompt
  2564.         endif
  2565.         leave
  2566.       endif
  2567.     endfor
  2568.   endif
  2569. ; .modify=oldmod
  2570.  
  2571. defproc bkm_switch(num)
  2572.   universal bkm_save_file
  2573.   universal bkm_def
  2574.   universal bkm_idx
  2575.   universal bkm_cur_num
  2576. compile if bkm_debugging
  2577.   universal bkm_debug
  2578.   if bkm_debug then call bkm_say("bkm_switch("num")",0) endif
  2579. compile endif
  2580.   newidx='.I'||strip(num)
  2581.   if bkm_idx=newidx then return 0 endif
  2582.   retc=0
  2583.   getfileid id,newidx
  2584.   if id<>'' then
  2585.     getline oline,1,id
  2586.     parse value oline with flag1 flag2 '(' save_file ')' .
  2587.     if flag1='.*' & flag2='EBOOKIE' then
  2588.       bkm_idx=newidx
  2589.       bkm_def='.D'||strip(num)
  2590.       bkm_save_file=save_file
  2591.       bkm_cur_num=num
  2592.     else
  2593. compile if bkm_debugging
  2594.       if bkm_debug then call bkm_say("bkm_switch("num") file "newidx" no header",0) endif
  2595. compile endif
  2596.       retc=1
  2597.     endif
  2598.   else
  2599. compile if bkm_debugging
  2600.     if bkm_debug then call bkm_say("bkm_switch("num") file "newidx" not found",0) endif
  2601. compile endif
  2602.     retc=1
  2603.   endif
  2604. return retc
  2605.  
  2606. defproc bkm_findfile(file)
  2607. compile if bkm_debugging
  2608.   universal bkm_debug
  2609.   if bkm_debug then call bkm_say("bkm_findfile("file")",0) endif
  2610. compile endif
  2611.   if not pos('\',file) & not pos(':',file) then
  2612.     findfile xfile, file, EPATH
  2613. compile if E3
  2614.     if rc then findfile xfile, file, 'PATH' endif
  2615. compile else
  2616.     if rc then findfile xfile, file, '', 'D' endif  -- LAM: searches E(PM)PATH & DPATH
  2617. compile endif
  2618.   else
  2619.     findfile xfile, file, ''
  2620.   endif
  2621.   if not rc then return xfile endif
  2622. ; xfile=''
  2623. ; return xfile
  2624. ; LAM:  falling off the end automatically returns the null string.
  2625.  
  2626. defproc bkm_get(file)
  2627. compile if bkm_debugging
  2628.   universal bkm_debug
  2629.   if bkm_debug then call bkm_say("bkm_get("file")",0) endif
  2630. compile endif
  2631.   xfile=bkm_findfile(file)
  2632.   if xfile='' then return 1 endif
  2633.   file=xfile
  2634.   getfileid curfileid
  2635.   s_last=.last
  2636.   rc=0
  2637.   copy_rc=0
  2638.   bkm_nocheck=1
  2639. compile if EVERSION > 5
  2640. /* Note: This is a temporary fix for EPM. The "get"     */
  2641. /*       command doesn't work here. Don't ask me why... */  -- LAM:  why???
  2642.   'xcom edit' file
  2643.   .visible=0
  2644.   copy_rc=rc
  2645.   call psave_mark(save_mark)
  2646. compile if bkm_attr
  2647.   'bkmattr'
  2648. compile endif
  2649.   top
  2650.   mark_line
  2651.   bottom
  2652.   mark_line
  2653.   activatefile curfileid
  2654.   rc=0
  2655.   copy_mark
  2656.   copy_rc=copy_rc  -- LAM:  huh?
  2657.   getfileid fileid,file
  2658.   activatefile fileid
  2659.   'quit'
  2660.   activatefile curfileid
  2661.   parse value save_mark with s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt
  2662.   if fileid=s_mkfileid then
  2663.     diff=fileid.last-s_last
  2664.     if fileid.line<s_firstline then s_firstline=s_firstline+diff; endif
  2665.     if fileid.line<s_lastline then s_lastline=s_lastline+diff; endif
  2666.   endif
  2667.   call prestore_mark(s_firstline s_lastline s_firstcol s_lastcol s_mkfileid s_mt)
  2668. compile else
  2669.   'get' file
  2670.   copy_rc=rc
  2671. compile endif
  2672.   if copy_rc then
  2673.     call bkm_say("Error during 'get' of" file", cc="copy_rc".",1)
  2674.   endif
  2675.   activatefile curfileid
  2676.   bkm_nocheck=0
  2677. return copy_rc
  2678.  
  2679. defproc bkm_find_file(name)
  2680.   universal bkm_avail
  2681.   universal bkm_rep_tag
  2682. compile if bkm_tags_between<>''
  2683.   universal bkm_between
  2684. compile endif
  2685.   universal bkm_tag_start
  2686.   universal bkm_tag_end
  2687.   universal bkm_end_tag
  2688.   universal bkm_inv_tag_rep
  2689. compile if bkm_want_symbols
  2690.   universal bkm_symbols
  2691.   universal bkm_symbols_active
  2692.   universal bkm_sym_file
  2693. compile endif
  2694. compile if bkm_attr
  2695.   universal bkm_did_bkmattr
  2696. compile endif
  2697. compile if bkm_debugging
  2698.   universal bkm_debug
  2699.   if bkm_debug then call bkm_say("bkm_find_file("name")",0) endif
  2700. compile endif
  2701.   retc=-1
  2702.   getfileid id,'.BKM'
  2703.   if id='' then
  2704.     call bkm_make_bkm()
  2705.     getfileid id,'.BKM'
  2706.     if id='' then
  2707.       call bkm_say("Could not allocate the file '.BKM', support halted.",1)
  2708.       bkm_avail=0
  2709.       return retc
  2710.     endif
  2711.   endif
  2712. compile if EVERSION < '5.0'
  2713.   save_command_state=command_state()
  2714.   if save_command_state then commandtoggle endif
  2715. compile endif
  2716.   for i=1 to id.last
  2717.     getline line,i,id
  2718.     rep_tag=''
  2719.     between=''
  2720. compile if bkm_want_symbols
  2721. compile if bkm_attr
  2722.     parse value line with fname '==' retc '||' between '||' rep_tag '||' tag_start '||' tag_end '||' end_tag '||' inv_tag_rep '||' sym_file '||' bkm_symbols_active '||' bkm_did_bkmattr .
  2723. compile else
  2724.     parse value line with fname '==' retc '||' between '||' rep_tag '||' tag_start '||' tag_end '||' end_tag '||' inv_tag_rep '||' sym_file '||' bkm_symbols_active .
  2725. compile endif
  2726. compile else
  2727. compile if bkm_attr
  2728.     parse value line with fname '==' retc '||' between '||' rep_tag '||' tag_start '||' tag_end '||' end_tag '||' inv_tag_rep '||' bkm_did_bkmattr .
  2729. compile else
  2730.     parse value line with fname '==' retc '||' between '||' rep_tag '||' tag_start '||' tag_end '||' end_tag '||' inv_tag_rep .
  2731. compile endif
  2732. compile endif
  2733.     if fname=name then leave endif
  2734.   endfor
  2735.   if fname<>name then
  2736.     retc=-1
  2737.   else
  2738.     retc=strip(retc)
  2739. compile if bkm_tags_between<>''
  2740.     bkm_between=strip(between)
  2741. compile endif
  2742.     bkm_rep_tag=strip(rep_tag)
  2743.     bkm_tag_start=strip(tag_start)
  2744.     bkm_tag_end=strip(tag_end)
  2745.     bkm_end_tag=strip(end_tag)
  2746.     bkm_inv_tag_rep=strip(inv_tag_rep)
  2747. compile if bkm_want_symbols
  2748.     bkm_sym_file=strip(sym_file)
  2749.     getline bkm_symbols,i+1,id
  2750. compile endif
  2751.   endif
  2752. compile if EVERSION < '5.0'
  2753.   if save_command_state then commandtoggle endif
  2754. compile endif
  2755. return retc
  2756.  
  2757. defproc bkm_upd_files(bkm,tag)
  2758.   universal bkm_avail
  2759.   universal bkm_cur_num
  2760.   universal bkm_rep_tag
  2761. compile if bkm_tags_between<>''
  2762.   universal bkm_between
  2763. compile endif
  2764.   universal bkm_tag_start
  2765.   universal bkm_tag_end
  2766.   universal bkm_end_tag
  2767.   universal bkm_inv_tag_rep
  2768. compile if bkm_want_symbols
  2769.   universal bkm_symbols
  2770.   universal bkm_symbols_active
  2771.   universal bkm_sym_file
  2772. compile endif
  2773. compile if bkm_attr
  2774.   universal bkm_did_bkmattr
  2775. compile endif
  2776. compile if bkm_debugging
  2777.   universal bkm_debug
  2778.   if bkm_debug then call bkm_say("bkm_upd_files("bkm","tag")",0) endif
  2779. compile endif
  2780.   if bkm=-1 then bkm=bkm_cur_num endif
  2781.   getfileid id,'.BKM'
  2782.   if id='' then
  2783.     call bkm_make_bkm()
  2784.     getfileid id,'.BKM'
  2785.     if id='' then
  2786.       call bkm_say("Could not allocate the file '.BKM', support halted.",1)
  2787.       bkm_avail=0
  2788.       return 0
  2789.     endif
  2790.   endif
  2791. compile if EVERSION < '5.0'
  2792.   save_command_state=command_state()
  2793.   if save_command_state then commandtoggle endif
  2794. compile endif
  2795.   for i=1 to id.last
  2796.     getline line,i,id
  2797.     parse value line with fname '==' .
  2798.     if fname=.filename then leave endif
  2799.   endfor
  2800.   bkm_between=strip(tag)
  2801. compile if bkm_want_symbols
  2802.   line=.filename '==' strip(bkm) '||' bkm_between '||' strip(bkm_rep_tag) '||' bkm_tag_start '||' bkm_tag_end '||' bkm_end_tag '||' bkm_inv_tag_rep '||' bkm_sym_file '||' bkm_symbols_active
  2803. compile else
  2804.   line=.filename '==' strip(bkm) '||' bkm_between '||' strip(bkm_rep_tag) '||' bkm_tag_start '||' bkm_tag_end '||' bkm_end_tag '||' bkm_inv_tag_rep
  2805. compile endif
  2806. compile if bkm_attr
  2807.   line=line '||' bkm_did_bkmattr
  2808. compile endif
  2809.   if fname<>.filename then
  2810.     insertline line,1,id
  2811. compile if bkm_want_symbols
  2812.     insertline bkm_symbols,2,id
  2813. compile endif
  2814.   else
  2815.     replaceline line,i,id
  2816. compile if bkm_want_symbols
  2817.     replaceline bkm_symbols,i+1,id
  2818. compile endif
  2819.   endif
  2820.   id.modify=0
  2821. compile if EVERSION < '5.0'
  2822.   if save_command_state then commandtoggle endif
  2823. compile endif
  2824.  
  2825. defproc bkm_make_bkm()
  2826. compile if bkm_debugging
  2827.   universal bkm_debug
  2828.   if bkm_debug then call bkm_say("bkm_make_bkm() called. Current=".filename,0) endif
  2829. compile endif
  2830. /* Now we create the internal work file.                */
  2831.   getfileid curfileid           -- save the current file name
  2832. compile if EPM
  2833.   'xcom edit /n .BKM'           -- Create the file
  2834.   .visible=0
  2835. compile endif
  2836. compile if EOS2
  2837.   'xcom edit /h /q /c .BKM'     -- EOS2
  2838. compile endif
  2839. compile if E3
  2840.   'xcom edit /h /q /n .BKM'     -- E3
  2841. compile endif
  2842.   .filename='.BKM'              -- set the file name
  2843.   activatefile curfileid
  2844.  
  2845. defproc bkm_get_parms(line,flag)
  2846.   universal bkm_tag_start
  2847.   universal bkm_tag_end
  2848.   universal bkm_end_tag
  2849.   universal bkm_rep_tag
  2850.   universal bkm_inv_tag_rep
  2851.   universal bkm_tag_start
  2852.   universal bkm_save_file
  2853. compile if bkm_want_symbols
  2854.   universal bkm_sym_file
  2855. compile endif
  2856. compile if bkm_debugging
  2857.   universal bkm_debug
  2858.   if bkm_debug then call bkm_say("bkm_get_parms("line","flag") called.",0) endif
  2859. compile endif
  2860.   parse value line with delim1 delim2 .
  2861.   if strip(delim1)='*' & strip(delim2)='EBOOKIE' then
  2862.     if flag=1 then
  2863.       x=pos('tag_start=',line)
  2864.       if x then
  2865. ;;      tag_start=substr(line,x+length('tag_start='),1)
  2866. ;;      if strip(tag_start)<>'' then        -- LAM:  If it's not null,
  2867. ;;        bkm_tag_start=strip(tag_start)    -- use result
  2868. ;;      else                                -- but if result is null
  2869. ;;        bkm_tag_start=''                  -- use null ???
  2870. ;;      endif                               -- Then why bother checking if it's null?
  2871.         bkm_tag_start=strip(substr(line,x+length('tag_start='),1))  -- or x+10
  2872.       endif
  2873.       x=pos('tag_end=',line)
  2874.       if x then
  2875. ;;      tag_end=substr(line,x+length('tag_end='),1)
  2876. ;;      if strip(tag_end)<>'' then
  2877. ;;        bkm_tag_end=strip(tag_end)
  2878. ;;      else
  2879. ;;        bkm_tag_end=''
  2880. ;;      endif
  2881.         bkm_tag_end=strip(substr(line,x+length('tag_end='),1))  -- or x+8
  2882.       endif
  2883.       x=pos('end_tag=',line)
  2884.       if x then
  2885. compile if EVERSION >= '5.20'
  2886.         bkm_end_tag=word(substr(line,x+length('end_tag=')),1)  -- or x+8
  2887. compile else
  2888.         end_tag=substr(line,x+length('end_tag='))
  2889.         parse value end_tag with end_tag .
  2890. ;;      if strip(end_tag)<>'' then
  2891. ;;        bkm_end_tag=strip(end_tag)
  2892. ;;      else
  2893. ;;        bkm_end_tag=''
  2894. ;;      endif
  2895.         bkm_end_tag=strip(end_tag)
  2896. compile endif
  2897.       endif
  2898.     endif
  2899.     x=pos('a_2=',line)
  2900.     if x then
  2901.       rep_tag=substr(line,x+length('a_2='))
  2902.       if substr(rep_tag,1,1)<>' ' then
  2903.         parse value rep_tag with bkm_rep_tag .
  2904.       else
  2905.         bkm_rep_tag=''
  2906.       endif
  2907.     endif
  2908.     x=pos('invalid=',line)
  2909.     if x then
  2910.       inv_tag_rep=substr(line,x+length('invalid='))
  2911.       if substr(inv_tag_rep,1,1)<>' ' then
  2912.         parse value inv_tag_rep with bkm_inv_tag_rep .
  2913.       else
  2914.         bkm_inv_tag_rep=''
  2915.       endif
  2916.     endif
  2917. compile if bkm_want_symbols
  2918.     x=pos('symbols=',line)
  2919.     if x then
  2920.       sym_file=substr(line,x+length('symbols='))
  2921.       if substr(sym_file,1,1)<>' ' then
  2922.         parse value sym_file with bkm_sym_file .
  2923.       else
  2924.         bkm_sym_file=''
  2925.       endif
  2926.     endif
  2927. compile endif
  2928.   endif
  2929.   if flag=1 then
  2930.     if bkm_tag_start='' then bkm_tag_start=':' endif
  2931.     if bkm_tag_end='' then bkm_tag_end='.' endif
  2932.     if bkm_end_tag='' then bkm_end_tag=':e' endif
  2933.     if bkm_rep_tag='' then bkm_rep_tag=':p.' endif
  2934.     if bkm_inv_tag_rep='' then
  2935.       bkm_inv_tag_rep='&gml.'
  2936.       if substr(bkm_save_file,1,1)='B' then
  2937.         bkm_inv_tag_rep='&colon.'
  2938.       endif
  2939.     endif
  2940. compile if bkm_want_symbols
  2941.     if bkm_sym_file='' & substr(bkm_save_file,1,1)='B' then
  2942.       parse value bkm_save_file with bkm_sym_file '.' .
  2943.     endif
  2944. compile endif
  2945.   endif
  2946.   if bkm_inv_tag_rep='' then bkm_inv_tag_rep=bkm_tag_start endif
  2947.  
  2948. /* DEFLOAD is called when a new file is read into the   */
  2949. /* ring. In EOS2 and EPM this routine can be here, in   */
  2950. /* E3 it must be included in MYSELECT.E, which calls    */
  2951. /* the procedure bkm_init().                            */
  2952. compile if EVERSION >= '4.12'
  2953. defproc bkm_defload()
  2954.   universal bkm_did_menu
  2955. compile if bkm_debugging
  2956.   universal bkm_debug
  2957.   if bkm_debug then call bkm_say("DEFLOAD called for ".filename,0) endif
  2958. compile endif
  2959. compile if EVERSION > 5
  2960.   if bkm_did_menu <> 1 then call bkm_build_menu() endif
  2961. compile endif
  2962. return bkm_init()
  2963.  
  2964. /* DEFSELECT is called when the file is moved in the    */
  2965. /* topmost position of the ring. This is for EPM and    */
  2966. /* EOS2 only, in E3 this (and more) is done in bkm_init.*/
  2967. defproc bkm_defselect()
  2968. compile if bkm_debugging
  2969.   universal bkm_debug
  2970.   if bkm_debug then call bkm_say("DEFSELECT called for ".filename,0) endif
  2971. compile endif
  2972.   if bkm_find_file(.filename)>0 then
  2973.     call bkm_select()
  2974.   endif
  2975. compile endif
  2976.  
  2977. compile if bkm_attr
  2978. defproc bkm_upd_line_attr(linenum)
  2979.   universal bkm_tag_start
  2980.   universal bkm_tag_end
  2981. compile if EVERSION > '5.16' & EVERSION < '5.50'
  2982.   saveline = .line
  2983.   savecol = .col
  2984. compile endif
  2985.   xline=strip(textline(linenum),'T')
  2986.   first=pos(bkm_tag_start,xline)
  2987.   while first do
  2988.     last=pos(bkm_tag_end,xline,first)
  2989.     if last<first then last=length(xline) endif
  2990.     if last<>first then
  2991. compile if EVERSION >= '5.50'
  2992.       insert_attribute  COLOR_CLASS, 23, 0, -1, last+1, linenum
  2993. compile elseif EVERSION > '5.16'
  2994.       lastlength = length(xline)
  2995.       insert_attribute  COLOR_CLASS, 23, 0, -1, last+1, linenum
  2996.       .col = last+1
  2997.       linenum
  2998.       call shed_attributes()
  2999.       getline xline,linenum
  3000.       if lastlength <> length(xline) then
  3001.         .col = length(xline)
  3002.         oldlevel = .levelofattributesupport
  3003.         .levelofattributesupport = 3
  3004.         delete_char
  3005.         .levelofattributesupport = oldlevel
  3006.       endif
  3007. compile else
  3008.       insert_attribute  COLOR_CLASS, 23, 0, 1, last, linenum
  3009. compile endif
  3010.       insert_attribute  COLOR_CLASS, bkm_attr_colors, 1, -1, first, linenum
  3011.     endif
  3012.     first=pos(bkm_tag_start,xline,last+1)
  3013.   endwhile
  3014. compile if EVERSION > '5.16' & EVERSION < '5.50'
  3015.   saveline
  3016.   .col = savecol
  3017. compile endif
  3018.  
  3019. defproc bkm_add_attr(xcmd)
  3020.   universal bkm_tag_start
  3021.   universal bkm_tag_end
  3022.   universal bkm_did_bkmattr
  3023.   bkm_did_bkmattr=1
  3024.   call psave_pos(OldCursorPos)
  3025.   OldRC = RC
  3026.   display -3
  3027.   saveautosave=.autosave
  3028.   savemodify = .modify
  3029.   .autosave=0
  3030.   0; .col=1
  3031.   TheOffset = -300
  3032.   TheColumn = 1
  3033.   TheLine   = 0
  3034.   TheClass  = ANY_CLASS
  3035.   attribute_action FIND_NEXT_ATTR_SUBOP, TheClass, TheOffset, TheColumn, TheLine
  3036.   while TheClass do
  3037.     attribute_action DELETE_ATTR_SUBOP, TheClass, TheOffset, TheColumn, TheLine
  3038.     TheClass  = ANY_CLASS
  3039.     attribute_action FIND_NEXT_ATTR_SUBOP, TheClass, TheOffset, TheColumn, TheLine
  3040.   endwhile
  3041.   0; .col=1
  3042.   if lowcase(xcmd)<>'off' then
  3043.     "xcom l /"bkm_tag_start"/"
  3044.     while not rc do
  3045.       first=.col
  3046.       fline=.line
  3047.       getline line
  3048.       if pos(substr(line,first+1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') then
  3049.         "xcom l /"bkm_tag_end"/"
  3050.         last=.col
  3051.         lline=.line
  3052. compile if EVERSION >= '5.50'
  3053.         insert_attribute  COLOR_CLASS, 23, 0, -1, last+1, lline
  3054. compile elseif EVERSION > '5.16'
  3055.         getline xline,lline
  3056.         lastlength = length(xline)
  3057.         insert_attribute  COLOR_CLASS, 23, 0, -1, last+1, lline
  3058.         .col = last+1
  3059.         lline
  3060.         call shed_attributes()
  3061.         getline xline,lline
  3062.         if lastlength <> length(xline) then
  3063.           .col = length(xline)
  3064.           oldlevel = .levelofattributesupport
  3065.           .levelofattributesupport = 3
  3066.           delete_char
  3067.           .levelofattributesupport = oldlevel
  3068.         endif
  3069.         .col = last
  3070. compile else
  3071.         insert_attribute  COLOR_CLASS, 23, 0, 1, last, lline
  3072. compile endif
  3073.         insert_attribute  COLOR_CLASS, bkm_attr_colors, 1, -1, first, fline
  3074.       else
  3075.         .col=.col+1
  3076.       endif
  3077.       "xcom l /"bkm_tag_start"/"
  3078.     endwhile
  3079.   else
  3080.     bkm_did_bkmattr=0
  3081.   endif
  3082.   rc = OldRC
  3083.   .autosave=saveautosave
  3084.   .modify = savemodify
  3085.   display 3
  3086.   call prestore_pos(OldCursorPos)
  3087.   call bkm_upd_files(-1,' ')
  3088.  
  3089. ; Thanks to Jason Crawford for the following code
  3090. defproc to_offset_zero()
  3091.    oldline = .line;
  3092.    up; down;
  3093.    .line = oldline;
  3094.  
  3095. ---===shed_attributes===-----------------------------------------
  3096. --
  3097. -- To use shed_attributes(), move the cursor to the character that
  3098. --   is passing its attributes to neighboring characters.
  3099. --
  3100. -- This procedure is handy because it provides a method for
  3101. --  putting an attribute at a positive offset despite the
  3102. --  best efforts of EPM 5.18 to prevent this.
  3103. -- This code will move all the attributes at the beginning
  3104. --   of a character to the previous character, and all
  3105. --   attributes following the attribute to the next character.
  3106.  
  3107. -- This kludge is based on the enhanced behavior of delete_char
  3108. --   when levelofattributesupport has its second bit set.
  3109. --   This behavior moves attributes to adjacent characters
  3110. --   before removing the character.  The cursor must be at
  3111. --   offset 0 for this to happen, otherwise an attribute
  3112. --   will be removed instead.
  3113.  
  3114.  
  3115. defproc shed_attributes()
  3116.   oldcol  = .col;
  3117.   TheText = textline(.line)
  3118.   TheChar = substr(TheText, oldcol, 1);
  3119.   --
  3120.   call to_offset_zero(); -- just to be sure at offset 0
  3121.   oldlevel = .levelofattributesupport;
  3122.   .levelofattributesupport = 3
  3123.      delete_char;
  3124.      keyin TheChar;
  3125.   .levelofattributesupport = oldlevel
  3126.   left;
  3127.  
  3128. compile if EVERSION >= '5.50'
  3129. defc bkm_upd_line_attr =
  3130.   universal bkm_did_bkmattr
  3131.   if bkm_did_bkmattr=1 then
  3132.     oldmod = .modify
  3133.     replaceline textline(.line)
  3134.     call bkm_upd_line_attr(.line)
  3135.     .modify = oldmod
  3136.   endif
  3137. compile endif
  3138. compile endif
  3139.  
  3140. defproc bkm_imbed()
  3141.   universal bkm_config
  3142.   bkm_config = ''
  3143. compile if EVERSION < 5
  3144.  if not command_state() then         -- check for command line
  3145. compile endif
  3146.    line = upcase(textline(.line))
  3147.    parse value line with cmd file ';' .
  3148.    parse value file with file "'" .
  3149.    parse value file with file '"' .
  3150.    if cmd='.IM' | cmd='.SETUP' | cmd='.IM#XMP' | cmd = '.USING' | cmd='.IM$XMP' then
  3151.      If Pos('(',file) then
  3152.        parse value file with '(' file ')' .
  3153.      endif
  3154.      if cmd='.USING' then
  3155.        saveline = .line
  3156.        savecol = .col
  3157.        'xcom L /.config/ca-'
  3158.        if not rc then
  3159.          parse value textline(.line) with . bkm_config .
  3160.        endif
  3161.        saveline
  3162.        .col = savecol
  3163.      endif
  3164.      parse value .filename with fn ft fm
  3165.      if ft<>'' & fm<>'' then
  3166. /* Fix host session id problem, thanks to Pat Lockhart */
  3167.        hsid = ''
  3168.        if pos(':',fn) then
  3169.          parse value fn with hsid ':' fn
  3170.          if hsid <> '' then hsid = hsid||':' endif
  3171.        endif
  3172.        parse value file with ifn ift ifm .
  3173.        If ift='' then ift='SCRIPT' endif
  3174.        If ifm='' then ifm=fm endif
  3175.        ifn = hsid||ifn
  3176.        'edit' ifn ift ifm  -- edit host file
  3177.      else
  3178.        If not pos('.',file) then
  3179.          ext = 'SCR'
  3180.          fm = ''
  3181.          parse value file with file fm .
  3182.          if fm <> '' then ext = substr(fm,1,3) endif
  3183.          file=file||'.'||ext
  3184.        endif
  3185.        path=''
  3186.        If lastpos('\',.filename) then
  3187.          path=substr(.filename,1,lastpos('\',.filename))
  3188.        endif
  3189.        ifile=bkm_findfile(strip(path||file))
  3190.        if ifile='' then ifile=bkm_findfile(file) endif
  3191.        if ifile='' then ifile=strip(path||file) endif   -- new file
  3192.        'edit' ifile
  3193.      endif
  3194. compile if E3
  3195.      call bkm_init()
  3196. compile endif
  3197.    else
  3198.      call bkm_say("Line doesn't contain '.im', '.setup', or '.using'.",0)
  3199.    endif
  3200. compile if EVERSION < 5
  3201.  endif                               -- check for command line
  3202. compile endif
  3203.  
  3204. defproc bkm_rem()
  3205.   universal expand_on
  3206.   universal bkm_rep_tag
  3207.   universal bkm_last_colon
  3208.   universal bkm_last_colon_line
  3209.   universal bkm_tag_start
  3210.   universal bkm_tag_end
  3211.   universal bkm_end_tag
  3212.   if expand_on then                     -- shall we do something?
  3213.     if bkm_rep_tag<>'' then             -- anything defined?
  3214.       if pos(bkm_tag_end,bkm_rep_tag) then      -- find tag-end character
  3215.         char=bkm_tag_end                        -- save it
  3216.         parse value bkm_rep_tag with k (char) . -- remove it from tag
  3217.         k=strip(k)                      -- remove leading and trailing blanks
  3218.       else
  3219.         char=' '                        -- no tag-end character included
  3220.         k=strip(bkm_rep_tag)            -- get tag
  3221.       endif
  3222.       bkm_last_colon=.col               -- save position of tag-start
  3223.       bkm_last_colon_line=.line         -- save line number
  3224.       keyin k                           -- type characters
  3225.       call bkm_expansion(char)          -- expand it if a tag
  3226.       bkm_last_colon=0                  -- reset last colon position
  3227.     endif
  3228.   endif
  3229.  
  3230. compile if bkm_help_support
  3231. defproc bkm_help(aorc)
  3232.   universal bkm_save_file
  3233.   universal bkm_tag_start
  3234. compile if bkm_help_reference           /* temple */
  3235.   if aorc = 'a' then
  3236.     call bkm_ref()
  3237.     return 0
  3238.   endif
  3239. compile endif
  3240.   if bkm_find_file(.filename)=0 then
  3241.     call bkm_say("Support is not active for this file",0)
  3242.   else
  3243.     parse value bkm_save_file with help_file hrest
  3244.     Parse Value help_file with s_help_file '.' .
  3245.     s_help_file=s_help_file||'.HLP'
  3246.     loop
  3247.       Parse Value help_file with help_file '.' .
  3248.       help_file=help_file||'.HLP'
  3249.       getfileid curfile
  3250.       getfileid id,help_file
  3251.       if id='' then
  3252.         help_file=bkm_findfile(help_file)
  3253.         if help_file<>'' then
  3254. compile if EPM
  3255.           'xcom edit' help_file
  3256.           .visible=0
  3257. compile else
  3258.           'xcom edit /h /q' help_file
  3259. compile endif
  3260.           activatefile curfile
  3261.           if rc then
  3262.             call bkm_say("Unable to load the file" help_file", out of storage",0)
  3263.           endif
  3264.         endif
  3265.         getfileid id,help_file
  3266.       endif
  3267.       if id <> '' then leave endif
  3268.       if hrest = '' then leave endif
  3269.       parse value hrest with help_file hrest
  3270.     endloop
  3271.     if id='' then
  3272.       call bkm_say("Unable to find the file" s_help_file", support not available",0)
  3273.     else
  3274.       getline line,.line
  3275.       fcol=lastpos(' ',line,.col)+1
  3276.       lcol=pos(' ',line||' ',.col)-1
  3277.       xword=strip(substr(line,fcol,lcol-fcol+1))
  3278.       if Substr(xword,1,1) <> '.' then
  3279.         parse value xword with xword '.' .
  3280.       endif
  3281.       if Substr(xword,1,1) <> '=' then
  3282.         parse value xword with xword '=' .
  3283.       endif
  3284.       done=0
  3285.       for i = 1 to id.last                  -- loop over help file
  3286.         getline helpline,i,id               -- no, get line from index
  3287.         if substr(helpline,1,1)=' ' then iterate endif
  3288.         parse value helpline with attribute .
  3289.         parse value attribute with attribute '\' .
  3290.         parse value attribute with attribute '=' .
  3291.         if upcase(attribute)=upcase(xword) then
  3292.           done=1
  3293.           getfileid hlpfile,'.HLP'
  3294.           if hlpfile <> '' then
  3295.             activatefile hlpfile
  3296.             .modify=0
  3297.             'quit'
  3298.           endif
  3299.           'xcom edit /q /n .HLP'
  3300.           sayerror 0
  3301.           'ma 1 80 1'
  3302.           join_after_wrap=0
  3303.           for j=i to id.last
  3304.             getline helpline,j,id
  3305.             if substr(helpline,1,1)<>' ' then
  3306.               parse value helpline with attribute .
  3307.               parse value attribute with attribute '\' .
  3308.               parse value attribute with attribute '=' .
  3309.               if upcase(attribute)<>upcase(xword) then leave endif
  3310.               If j>i then
  3311.                 insert
  3312.                 insert
  3313.                 insert
  3314.                 down
  3315.                 down
  3316.                 down
  3317.                 begin_line
  3318.               endif
  3319.             endif
  3320.             helpline=strip(helpline)
  3321.             getline line
  3322.             if strip(line)<>'' then helpline=' 'helpline endif
  3323.             loop
  3324.               if not pos('\',helpline) then leave endif
  3325.               parse value helpline with xleft '\' helpline
  3326.               keyin xleft
  3327.               insert
  3328.               down
  3329.               begin_line
  3330.             endloop
  3331.             keyin helpline
  3332.           endfor
  3333.           .modify=0
  3334.           'top'
  3335.           leave
  3336.         endif
  3337.       endfor
  3338.       if not done then
  3339.         call bkm_say("No help for" xword "found.",0)
  3340.       endif
  3341.     endif
  3342.   endif
  3343. compile endif
  3344.  
  3345. compile if bkm_idx_supp
  3346. defproc bkm_idx_make()
  3347.   universal bkm_avail
  3348.   if bkm_avail=1 & bkm_find_file(.filename)>0 Then
  3349.     type=marktype()
  3350.     if type='' then
  3351.       fline=.line
  3352.       lline=.line
  3353.       fcol=.col
  3354.       lcol=.col
  3355.     else
  3356.       getmark fline, lline, fcol, lcol
  3357.     endif
  3358.     if type='LINE' then
  3359.       call bkm_say("Line mark invalid, must be block mark or not marked at all.",0)
  3360.     else
  3361.       if fline<>lline then
  3362.         call bkm_say("The marked block must not span lines.",0)
  3363.       else
  3364.         getline line,fline
  3365.         if fcol=lcol then
  3366.           fcol=lastpos(' ',' '||line,fcol)
  3367.           if substr(line,fcol,1)=' ' then fcol=fcol+1 endif
  3368.           lcol=pos(' ',line||' ',lcol)-1
  3369.         endif
  3370.         xblock=strip(substr(line,fcol,lcol-fcol+1))
  3371.         loop
  3372.           x=pos(':',xblock)
  3373.           if not x then leave endif
  3374.           y=pos('.',xblock,x)
  3375.           if not y then leave endif
  3376. compile if EVERSION >= '5.20'
  3377.           xblock=delstr(xblock,x,y-x+1)
  3378. compile else
  3379.           if x=1 then
  3380.             xblock=substr(xblock,y+1)
  3381.           else
  3382.             xblock=substr(xblock,1,x-1)||substr(xblock,y+1)
  3383.           endif
  3384. compile endif
  3385.         endloop
  3386.         loop
  3387.           x=verify(xblock, ',"''', 'M')  -- LAM:  Handles , " and ' in one loop.
  3388.           if not x then leave endif
  3389. compile if EVERSION >= '5.20'
  3390.           xblock=delstr(xblock,x,1)
  3391. compile else
  3392.           if x=1 then
  3393.             xblock=substr(xblock,2)
  3394.           else
  3395.             xblock=substr(xblock,1,x-1)||substr(xblock,x+1)
  3396.           endif
  3397. compile endif
  3398.         endloop
  3399.         if substr(xblock,1,1)='(' then  -- LAM: Could delete all parens by adding '()' to verify() string above...
  3400.           xblock=substr(xblock,2)
  3401. compile if EVERSION >= '5.20'
  3402.           if rightstr(xblock,1)=')' then xblock=leftstr(xblock,length(xblock)-1) endif
  3403. compile else
  3404.           if substr(xblock,length(xblock),1)=')' then xblock=substr(xblock,1,length(xblock)-1) endif
  3405. compile endif
  3406.         endif
  3407.         xblock=strip(xblock)
  3408. compile if EVERSION >= '5.20'
  3409.         if rightstr(xblock,1)='.' then
  3410. compile else
  3411.         if substr(xblock,length(xblock),1)='.' then
  3412. compile endif
  3413.           x=lastpos('&',xblock)
  3414.           if x then
  3415.             if pos(' ',xblock,x) then
  3416.               xblock=substr(xblock,1,length(xblock)-1)
  3417.             endif
  3418.           else
  3419.             xblock=substr(xblock,1,length(xblock)-1)
  3420.           endif
  3421.         endif
  3422.         x=pos('.',xblock)
  3423.         if x then
  3424.           if not lastpos('&',xblock,x) then
  3425.             if not lastpos(' ',xblock) then
  3426.               xblock=substr(xblock,x+1)
  3427.             endif
  3428.           endif
  3429.         endif
  3430. compile if bkm_keep_index_cases
  3431.         yblock=strip(xblock)
  3432.         xblock=''
  3433.         loop
  3434.           parse value yblock with xword yblock
  3435.           if xword='' then leave endif
  3436.           zword=lowcase(xword)
  3437.           if xword=upcase(xword) then
  3438.             xblock=xblock xword
  3439.           else
  3440.             xblock=xblock zword
  3441.           endif
  3442.         endloop
  3443. compile endif
  3444.         xblock=strip(xblock)
  3445.         insertline ".***",fline+1
  3446.         insertline ":i1."xblock,fline+2
  3447. compile if EVERSION >= '5.20'
  3448.         for i=2 to words(xblock)
  3449.           insertline ":i1." || subword(xblock,i) || ", " || subword(xblock,1,i-1),fline+i+1
  3450.         endfor
  3451.         insertline ".***",fline+i+1
  3452. compile else
  3453.         j=1
  3454.         for i=3 to 99
  3455.           x=0
  3456.           for k=1 to j
  3457.             x=pos(' ',xblock,x+1)
  3458.           endfor
  3459.           if not x then leave endif
  3460.           insertline ":i1." || substr(xblock,x+1) || ", " || substr(xblock,1,x),fline+i
  3461.           j=j+1
  3462.         endfor
  3463.         insertline ".***",fline+i
  3464. compile endif
  3465.         unmark
  3466.       endif
  3467.     endif
  3468.   endif
  3469. compile endif
  3470.  
  3471. compile if bkm_help_reference           /* temple */
  3472. defproc bkm_ref()
  3473.   universal bkm_tag_start
  3474.   universal bkm_tag_end
  3475.   universal bkm_save_file
  3476.   if bkm_find_file(.filename)=0 then
  3477.     call bkm_say("Support is not active for this file",0)
  3478.   else
  3479.     parse value bkm_save_file with help_file hrest
  3480.     parse value help_file with s_help_file '.' .
  3481.     s_help_file=s_help_file||'.INF'
  3482.     xfile = ''
  3483.     loop
  3484.       Parse Value help_file with help_file '.' .
  3485.       help_file=help_file||'.INF'
  3486.       findfile xfile, help_file, 'BOOKSHELF'
  3487. ;;    if rc then findfile xfile, help_file, 'EPATH' endif  -- LAM:  EPM uses EPMPATH, not EPATH, and
  3488.       if rc then findfile xfile, help_file, '', 'D' endif  -- this searches EPMPATH as well as DPATH
  3489.       if not rc then leave endif
  3490.       if hrest = '' then leave endif
  3491.       parse value hrest with help_file hrest
  3492.     endloop
  3493.     if xfile = '' then
  3494.        call bkm_say("Help file" s_help_file "not found.",0)
  3495.        return 0
  3496.     endif
  3497.     getline line,.line
  3498.     fcol=lastpos(' ',line,.col)+1
  3499.     lcol=pos(' ',line||' ',.col)-1
  3500.     xword=strip(substr(line,fcol,lcol-fcol+1))
  3501.     if Substr(xword,1,1) = bkm_tag_start then
  3502.       xword = substr(xword,2)
  3503.     endif
  3504.     if pos(bkm_tag_end,xword) then
  3505.        xword = substr(xword,1,pos(bkm_tag_end,xword)-1)
  3506.     endif
  3507.     if Substr(xword,1,1) <> '=' then
  3508.       parse value xword with xword '=' .
  3509.     endif
  3510.     'VIEW' xfile xword
  3511.   endif
  3512. compile endif
  3513.  
  3514. compile if EPM
  3515. defproc bkm_build_menu()
  3516.   universal defaultmenu
  3517.   universal activemenu
  3518.   universal bkm_did_menu
  3519.  compile if EVERSION >= 5.20
  3520.    universal activeaccel
  3521.  compile endif
  3522. compile if KEEP_HELP_AT_RIGHT
  3523.   deletemenu defaultmenu, 6, 0, 0  -- delete the existing Help menu (we want it to stay at the right)
  3524. compile endif
  3525.   grey = 16384
  3526.   buildsubmenu defaultmenu, 21,      'E'TILDE_CHAR'bookie',    ' ',           0,0
  3527.   buildmenuitem defaultmenu,21, 2101, '~Bookie on',            'bookie on',   0,0
  3528.   buildmenuitem defaultmenu,21, 2102, 'Bookie ~off',           'bookie off',  0,0
  3529.   buildmenuitem defaultmenu,21, 2103, \0,                      '',            4,0
  3530. compile if bkm_attr
  3531.   buildmenuitem defaultmenu,21, 2104, '~Attribute on',         'bkmattr on',  0,0
  3532.   buildmenuitem defaultmenu,21, 2105, 'A~ttribute off',        'bkmattr off', 0,0
  3533. compile if EVERSION >= '5.50'
  3534.   buildmenuitem defaultmenu,21, 2120, '~Fixup attributes',     'bkm_upd_line_attr', 0,0
  3535. compile endif
  3536. compile else
  3537.   buildmenuitem defaultmenu,21, 2104, '~Attribute on',         'bkmattr on',  0,grey
  3538.   buildmenuitem defaultmenu,21, 2105, 'A~ttribute off',        'bkmattr off', 0,grey
  3539. compile if EVERSION >= '5.50'
  3540.   buildmenuitem defaultmenu,21, 2120, '~Fixup attributes',     'bkm_upd_line_attr', 0,grey
  3541. compile endif
  3542. compile endif
  3543.   buildmenuitem defaultmenu,21, 2106, \0,                      '',            4,0
  3544. compile if bkm_want_symbols
  3545.   buildmenuitem defaultmenu,21, 2107, '~Symbols all/mark',     'bkmsym all',  0,0
  3546.   buildmenuitem defaultmenu,21, 2121, 'Symbols on',            'bkmsym on',   0,0
  3547.   buildmenuitem defaultmenu,21, 2122, 'Symbols off',           'bkmsym off',  0,0
  3548. compile else
  3549.   buildmenuitem defaultmenu,21, 2107, '~Symbols all/mark',     'bkmsym all',  0,grey
  3550.   buildmenuitem defaultmenu,21, 2121, 'Symbols on',            'bkmsym on',   0,grey
  3551.   buildmenuitem defaultmenu,21, 2122, 'Symbols off',           'bkmsym off',  0,grey
  3552. compile endif
  3553.   buildmenuitem defaultmenu,21, 2108, \0,                      '',            4,0
  3554. compile if bkm_debugging
  3555.   buildmenuitem defaultmenu,21, 2109, '~Debug on',             'bkmdebug on', 0,0
  3556.   buildmenuitem defaultmenu,21, 2110, 'D~ebug off',            'bkmdebug off',0,0
  3557.   buildmenuitem defaultmenu,21, 2111, 'De~bug on+echo',        'bkmdebug t'  ,0,0
  3558.   buildmenuitem defaultmenu,21, 2112, 'Debug dis~play',        'bkmdebug d'  ,0,0
  3559. compile else
  3560.   buildmenuitem defaultmenu,21, 2109, '~Debug on',             'bkmdebug on' ,0,grey
  3561.   buildmenuitem defaultmenu,21, 2110, 'D~ebug off',            'bkmdebug off',0,grey
  3562.   buildmenuitem defaultmenu,21, 2111, 'De~bug on+echo',        'bkmdebug t'  ,0,grey
  3563.   buildmenuitem defaultmenu,21, 2112, 'Debug dis~play',        'bkmdebug d'  ,0,grey
  3564. compile endif
  3565.   buildmenuitem defaultmenu,21, 2113, \0,                      '',            4,0
  3566.   buildmenuitem defaultmenu,21, 2114, 'Edit ~imbed'\9'a_1',    'bkmimbed',    0,0
  3567.   buildmenuitem defaultmenu,21, 2115, 'Insert default ~tag'\9'a_2', 'bkmrem', 0,0
  3568. compile if bkm_help_support
  3569.   buildmenuitem defaultmenu,21, 2116, '~Help for tag'\9'a_h',   'bkmhelp',    0,0
  3570. compile else
  3571.   buildmenuitem defaultmenu,21, 2116, '~Help for tag'\9'a_h',   'bkmhelp',    0,grey
  3572. compile endif
  3573. compile if bkm_idx_supp
  3574.   buildmenuitem defaultmenu,21, 2118, 'I~ndex word/mark'\9'a_i', 'bkmidx',    0,0
  3575. compile else
  3576.   buildmenuitem defaultmenu,21, 2118, 'I~ndex word/mark'\9'a_i', 'bkmidx',    0,grey
  3577. compile endif
  3578.   buildmenuitem defaultmenu,21, 2119, 'Vie~w documentation' ,   'view ebookie',    0,0
  3579. compile if KEEP_HELP_AT_RIGHT
  3580.  compile if EVERSION >= '5.20'  -- We know that OS/2 must be over 1.2
  3581.   call add_help_menu(defaultmenu, 1)  -- rebuild the help menu
  3582.  compile else
  3583.   call add_help_menu(defaultmenu, dos_version()>=1020)  -- rebuild the help menu
  3584.  compile endif
  3585. compile endif
  3586.   if activemenu = defaultmenu then     -- If this is the active menu, then
  3587.      showmenu defaultmenu              -- activate the above changes
  3588.   endif
  3589. compile if EVERSION >= 5.20 & TILDE_CHAR <> ''
  3590.    buildacceltable activeaccel, 'dokey a+B', AF_CHAR+AF_ALT,                  66, 2191  -- a+B
  3591.    buildacceltable activeaccel, 'dokey a+B', AF_CHAR+AF_ALT,                  98, 2192  -- a+b
  3592.    activateacceltable  activeaccel
  3593. compile endif
  3594.   bkm_did_menu = 1
  3595. compile endif  -- EPM
  3596.