home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsp / rink010 / Docs / Parent < prev    next >
Encoding:
Text File  |  1995-06-25  |  7.6 KB  |  229 lines

  1.  
  2. How to use rink in the parent program
  3. rink documentation, (c) Ben Summers 1995
  4.  
  5.  
  6.  
  7. The run time system
  8. ~~~~~~~~~~~~~~~~~~~
  9.  
  10. The rink run time system is supplied as an AOF file. This is currently bound
  11. to the C run time system, but can easily be modified to work with any
  12. lanuage using command line switches to rinkptr.
  13.  
  14. The parent must be linked with the run time system and the pointer block
  15. created by rinkptr.
  16.  
  17. A C header file, called rink.h is provided for use with C. It defines
  18. several functions used to control the run time system.
  19.  
  20.  
  21. ****************************************************************************
  22.  
  23. rink_load is used to load a segment.
  24.  
  25.    os_error *rink_load(char *segment_name, char *links_name,
  26.       rink_seghandle *sh, rink_check *ck)
  27.  
  28. It returns a handle to the segment for use with future calls to the system
  29. in *sh, and returns 0 to signify that no error occured.
  30.  
  31. The pointer to the error block is either an operting system error, or a rink
  32. internal error. These can be translated by the parent application by using
  33. rinkptr to create a sugar function to a translation function other than the
  34. default.
  35.  
  36. ck is a pointer to a structure. This must match the header of the file to be
  37. loaded as a check that the file is the right thing to be loading. The
  38. segment will be rejected if the main version number of the segment is
  39. greater than that given in this check block. The code version number is
  40. ignored, and is merely for information only.
  41.  
  42. Version numbers can be read with rink_readversion().
  43.  
  44.  
  45. ****************************************************************************
  46.  
  47. rink_fn returns a pointer to a function. It should be cast to a suitable
  48. function pointer. The demonstration program shows one possible method of use.
  49.  
  50.    typedef void *(*_rink_fn)(void);
  51.  
  52.    _rink_fn rink_fn(rink_seghandle ch, int entry);
  53.  
  54. It returns the address of the function, or zero if it does not exist in the
  55. header. ch is the handle of the segement as returned by rink_seghandle.
  56. entry is the entry number within the header, numbered from zero.
  57.  
  58.  
  59. As well as using it to find pointers which are then cached, you can also use
  60. it to call functions directly. For example, to call a function taking 6
  61. integer arguments which returns an integer, use something like
  62.  
  63.   typedef int (*fn6)(int, int, int, int, int, int);
  64.  
  65.   result = ((fn6)rink_fn(code, 6))(1, 2, 3, 4, 5, 6);
  66.  
  67.  
  68. ****************************************************************************
  69.  
  70. rink_enum_named is used to find the names of all named functions, and a
  71. pointer to that function.
  72.  
  73.    _rink_fn rink_enum_named(rink_seghandle cd, int *ref, char **name);
  74.  
  75. Set *ref to 0 before starting, and the call it repeatedly until *ref == -1.
  76. After each call, *ref is set to refer to the next function, *name contains a
  77. pointer to the name of the function, and a pointer to the function is
  78. returned.
  79.  
  80. For example, to print the names of all named functions within a segment, and
  81. call them assuming that they take no arguments, use something like
  82.  
  83.  
  84. typedef void (*fn0)(void);
  85.  
  86. void list_and_call(void)
  87. {
  88.   int l;
  89.   char *name;
  90.   _rink_fn fn;
  91.  
  92.   l = 0;
  93.   do {
  94.     fn = rink_enum_named(code, &l, &name);
  95.     printf("*** %s\n", name);
  96.     ((fn0)fn)();
  97.   } while(l >= 0);
  98. }
  99.  
  100.  
  101. ****************************************************************************
  102.  
  103. rink_readversion returns a pointer to a structure containing the version
  104. numbers of a segment.
  105.  
  106.    rink_version *rink_readversion(rink_seghandle sh);
  107.  
  108.  
  109. ****************************************************************************
  110.  
  111. rink_unload is used to remove a segement from the parents memory.
  112.  
  113.    void rink_unload(rink_seghandle ch);
  114.  
  115.  
  116. ****************************************************************************
  117.  
  118.  
  119. Using rinkptr and extractsym to create a pointer block map
  120. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. To tell rink which functions and data you want the segments to be able to
  122. call, you need to create a pointer block map. This is basically a list of
  123. symbols to which rink can link items in segments.
  124.  
  125. The format of the file is simple. Each line contains a symbol name. Blank
  126. lines are ignored, and lines beginning with '#' are comments.
  127.  
  128. To help in creating these maps, extractsym will extract a list of possible
  129. symbols from an AOF file, or from an ALF (library) file. This list can be
  130. used directly as a pointer block map.
  131.  
  132. It's command line syntax is
  133.  
  134.   extractsym o|e <output file> <input files>
  135.  
  136. The first argument tells it whether to overwrite or to extend the output
  137. file. The latter is useful if all the AOF files you want to include are too
  138. long for one command line.
  139.  
  140. The input files are simply a list of AOF files. You can include as many as
  141. you want.
  142.  
  143. For library files you need to specify which AOF files within the library you
  144. want to scan. This is done by specifing the internal name after a comma, for
  145. example, 'C:o.RISC_OSLib,o.werr'. You can use a '*' wildcard, although it
  146. must be the last character of the filename.
  147.  
  148. Use libfile to find a list of all AOF files inside the library, or <name>,*
  149. to include all symbols.
  150.  
  151. As an example, the demo program uses
  152.  
  153.   extractsym o ptrblkmap o.rinkdemo C:o.stubs
  154.  
  155. to generate it's map from the shared C library stubs and it's own main
  156. program. This allows access to all C library functions and functions within
  157. the program to the segments.
  158.  
  159.  
  160. In creating the pointer block map, you have two options. You can either use
  161. extractsym to create the map directly, or you can create the map by hand.
  162. The first method has the advantage that it is easy to do, but the second
  163. means that you can create maps which are backwards compatible.
  164.  
  165. To ensure that segments which have been rinked with an old version of rink
  166. are still compatible, only add symbols to the end. A good strategy is to
  167. create a map by hand at the beginning of the project containing the symbols
  168. for your library (stubs or perhaps UnixLib) and then add to this as rink
  169. faults symbols not found in the map.
  170.  
  171. You can then either add them one by one, or use extractsym to get all the
  172. symbols out of an object file to add all the symbols in an AOF file.
  173.  
  174.  
  175. Creating the pointer block
  176. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  177. After creating the pointer block map, you need to create the pointer block
  178. for linking into your program. rinkptr performs this function. It's command
  179. line syntax is
  180.  
  181.   rinkptr <map filename> <output filename>
  182.  
  183. For example,
  184.  
  185.   rinkptr ptrblkmap o.pointerblk
  186.  
  187. You should remake the pointer block every time you change the pointer block
  188. map and re-rink all segments, otherwise segments could be linked to the wrong
  189. things, giving unpredicitable results.
  190.  
  191.  
  192. The sugar functions
  193. ~~~~~~~~~~~~~~~~~~~
  194. The rink run time system requires memory allocation and memory freeing
  195. routines. These default to malloc and free respectively. However, these may
  196. not be appropriate for your program. You can change them with the -A and -F
  197. command line switches on rinkptr.
  198.  
  199. For example, to change them to my_alloc and my_free, use
  200.  
  201.   rinkptr ptrblkmap o.pointerblk -A my_alloc -F my_free
  202.  
  203.  
  204. The rink run time system can generate it's own errors, not just returning OS
  205. errors. You may want to change the default error messages, perhaps for
  206. internationalisation or to change them to messages more appropirate for your
  207. application. You can do this by replacing the internal error translation
  208. function using the -T switch, for example
  209.  
  210.   rinkptr ptrblkmap o.pointerblk -T my_translation
  211.  
  212. Your function should have a prototype similar to
  213.  
  214.   os_error *my_translation(int err_number);
  215.  
  216. The default error translator returns a pointer to an error block with a
  217. textual message in english, and the error number as err_number. Values for
  218. err_number can be
  219.  
  220. Number  Default message
  221.   -1    "No room"
  222.   -2    "Not a rink segment"
  223.   -3    "Not a rink links file"
  224.   -4    "Segment is too recent"
  225.  
  226.  
  227.  
  228.  
  229.