home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / bascompress / bascompress_1 / Examples_LibHandler_LibHandler (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1994-11-27  |  3.4 KB  |  143 lines

  1.   >LibHandler
  2. H Example library file used to control the running of other libraries
  3.  And error handler
  4. K Note that error handler calls Wimp_CloseDown, and so non-wimp programs
  5. @ may have to include a dummy version of this routine to keep
  6.  bascompress happy
  7.  USAGE:
  8.     B  This should be the first library file to be loaded, and its'
  9. G  hard initialisation called.  From then on just use _load_library.
  10. _LibHandler_version  :  = 013
  11. _hard_initialise_LibHandler(max_libs%, need_version%)
  12. _LibHandler_version<need_version% 
  13. #      
  14.  0, "LibHandler too old"
  15.  max_libs%<1 
  16. 7      
  17.  0, "LibHandler: bad max librarys parameter"
  18. %   max_library_files% = max_libs%
  19.  library_names$(max_library_files%-1)
  20.  library_versions%(max_library_files%-1)
  21.    num_library_files% = 0
  22. =   : 
  23.   This is used so can indent nested error handlers.
  24. "   Num_Lib_Error_Levels%  = 40
  25. !   Lib_Error_Level%       = 0
  26. E   On_Lib_Error_MODE%     = 12          :  
  27.   A 16-colour screen.
  28.  !   On_Lib_Error_Continue% = 
  29. !-   
  30.  Lib_Errors$(Num_Lib_Error_Levels%-1)
  31.    Wimp_Active% = 
  32.    Debug_Wimp%  = 
  33.  *********************************************************************
  34.  * Load a library file, check it's a new enough version  and then, if
  35.  * it hasn't already been loaded, call its' hard initialisation.
  36.  * This procedure could well be recursive.
  37.  * IN:   library$ == file name of library.
  38.  *       version% == earliest possible version required.
  39.  * OUT:  ERROR 0 if bad versions / too many library files.
  40. _load_library(library$, version%)
  41.  load%, i%, leaf$, e$
  42.    i%    = 0
  43.    load% = 
  44. 2.   leaf$ = 
  45. library$, 1 + 
  46. library$, "."))
  47. 3'   
  48.  i%<num_library_files% 
  49.  load%
  50. 4-      load% = (leaf$<>library_names$(i%))
  51.       
  52.  load% 
  53.          i% += 1
  54.       
  55.  load% 
  56. :#      
  57.  i%=max_library_files% 
  58. ;9         
  59.  0,"LibHandler: Too many librarys to load!"
  60.       
  61. =$      library_names$(i%) = leaf$
  62.       
  63.  library$
  64. ?7      e$ = "'" + library$ + "' does not have a FN_"
  65. @?      library_versions%(i%) = 
  66. ("FN_" + leaf$ + "_version")
  67. A&      num_library_files%      += 1
  68. B%      
  69.   This could be recursive.
  70. C.      
  71. ("FN_hard_initialise_" + leaf$) 
  72. DI         
  73.  1, "Library file '" + library$ + "'s hard init'ion failed"
  74.       
  75. G)   
  76.  version%>library_versions%(i%) 
  77. H8      
  78.  1, "Library file '" + library$ + "' too old"
  79. _handle_library_error
  80.  iii%, eee$
  81.  Wimp_Active% 
  82.  Debug_Wimp% 
  83. P/      
  84. _Wimp_Error(
  85. $+ " ["+ 
  86. )+ "].")
  87.       
  88. _Wimp_CloseDown
  89.       
  90. S        
  91.       
  92. _Wimp_Error(
  93. U!      
  94. =Wimp_Error_Fatal% 
  95.         
  96. _Wimp_CloseDown
  97.         
  98.       
  99. Y        
  100. [!    
  101.  On_Lib_Error_MODE%=-2 
  102. \       
  103.  Lib_Error_Level%>0 
  104. ]!        
  105. , Lib_Errors$(0)
  106.       
  107.         
  108.       
  109.       
  110. b        
  111. c!    
  112.  On_Lib_Error_MODE%>=0 
  113. d3      
  114.  On_Lib_Error_MODE%  :  
  115.   Reset screen.
  116. e        
  117. f#    
  118.  "An error has occured..."
  119. g        
  120.  Lib_Error_Level% 
  121. i(      
  122.  iii%= 0 
  123.  Lib_Error_Level%-1
  124. j)        
  125.  ((7 - (iii% << 1)) 
  126.  6) + 1
  127. k         
  128.  Lib_Errors$(iii%);
  129. l)        
  130.  iii%<(Lib_Error_Level%-1) 
  131.           
  132.  " in ";
  133.         
  134.       
  135.  iii%
  136. p        
  137. q$      
  138. $; " (line "; 
  139. ); ")"
  140. r        
  141. s        
  142. u        
  143.