EXPORT.HOWTO 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. HOW TO IMPLEMENT A NEW EXPORT MODULE:
  2. As an example look at exp-txt.c (it implements two modules which
  3. are pretty similar).
  4. You have to create one exported structure (struct export_module).
  5. This structure holds the following data:
  6. 1. The name of the format (example: "ascii").
  7. 2. The default extension to use for building filenames ("txt").
  8. 3. A list of module options. It's a 0 terminated array of char
  9. pointers, one for each option (similar to argv of main).
  10. If an option string contains a '=', it is an option that
  11. requires an argument. The part after the '=' is ignored at
  12. the moment. Later, I want to add help messages that show
  13. these options strings and then the part after the '=' becomes
  14. useful.
  15. If you do not have local options, set this field to 0.
  16. 4. The number of bytes for local data in the export structure.
  17. There you may store data collected during option parsing or
  18. for whatever you want.
  19. Don't use global variables for storing this data! With
  20. alevt-cap you may give:
  21. alevt-cap -format ascii,color 100 -format ascii 100
  22. to save the page in two different formats. Using global
  23. vars would inhibit this. The data area in struct export
  24. starts at the 'data' field. You have to cast it to the
  25. appropriate type (see the D macro in exp-txt.c).
  26. If you do not need local data, set this field to 0.
  27. 5. An open function (or call it constructor). It is called
  28. when your module is needed and it is passed a struct export
  29. (the instance). This function may be used to initialize
  30. the local data in the export struct.
  31. If all goes well return 0. Else call export_error (see
  32. below) and return -1.
  33. If you do not need an open function, set this field to 0.
  34. 6. A close function (or call it destructor). It is called
  35. when your module is no longer needed. If you allocated
  36. memory in the open func, this is the place to free it.
  37. If you do not need a close function, set it to 0.
  38. 7. An option function. It is called for each module option
  39. the user has given. It is passed an option number (first
  40. option in the option-array gives 1, ...) and a char pointer
  41. to the argument for that option (0 if the option does not
  42. need an arg). The argument pointer keeps valid until the
  43. close function is called.
  44. If all goes well, return 0. Else call export_error and
  45. return -1.
  46. If you gave an option list at point 3 you have to specify
  47. this function. Else set it to 0.
  48. 8. An output function. It is called to produce the output.
  49. It is given the file name to use and a fmt_page pointer.
  50. The fmt_page contains an interpreted image of the page.
  51. There are no control chars in it. It uses the character
  52. set defined by the two fonts.
  53. These function may be called consecutive for multiple
  54. pages. Don't expect one output for one open/close.
  55. Return codes as above... (0: ok, -1: error).
  56. The export_error function: If one of your functions wants to
  57. report an error, it has to use the export_error function.
  58. It's a printf like function to set error messages. In alevt-cap
  59. these messages are printed to stderr, in alevt they will be
  60. shown in the status line (so don't make them too long).
  61. The last step is to add your export_module structure to the
  62. list of modules in export.c (at the top).
  63. Please, make sure that this structure is the only exported
  64. symbol. All other things should be static.
  65. That's all. A structure describing your module and 4 functions
  66. (open, close, option, output) to implement it. Shouldn't be too
  67. complicated.
  68. Ciao, ET.