You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
6.5 KiB

26 years ago
  1. WHAT IT IS
  2. It's a tool for automatically creating the basic framework for a PHP module
  3. and writing C code handling arguments passed to your functions from a simple
  4. configuration file. See an example at the end of this file.
  5. HOW TO USE IT
  6. Very simple. First, cd do directory ext/ in PHP 4 sources. If you just need
  7. the basic framework and will be writing all the code in your functions
  8. yourself, you can now do
  9. ./ext_skel --extname=module_name
  10. and everything you need is placed in directory module_name. In fact, if you
  11. don't need to test the existence of any external header files, libraries or
  12. functions in them, the module is already almost ready to be compiled in PHP.
  13. Just remove 3 comments in your_module_name/config.m4, cd back up to PHP
  14. sources top directory, and do
  15. ./buildconf; ./configure --enable-module_name; make
  16. But if you already have planned the overall scheme of your module, what
  17. functions it will contain, their return types and the arguments they take
  18. (a very good idea) and don't want to bother yourself with creating function
  19. definitions and handling arguments passed yourself, it's time to create a
  20. function definitions file, which you will give as an argument to ext_skel
  21. with option
  22. --proto=filename.
  23. FORMAT OF FUNCTION DEFINITIONS FILE
  24. All the definitions must be on one line. In it's simplest form, it's just
  25. the function name, ie.
  26. my_function
  27. but then you'll be left with an almost empty function body without any
  28. argument handling.
  29. Arguments are given in parenthesis after the function name, and are of
  30. the form 'argument_type argument_name'. Arguments are separated from each
  31. other with a comma and optional space. Argument_type can be one of int,
  32. bool, double, float, string, array, object or mixed.
  33. An optional argument is separated from the previous by an optional space,
  34. then '[' and of course comma and optional space, like all the other
  35. arguments. You should close a row of optional arguments with same amount of
  36. ']'s as there where '['s. Currently, it does not harm if you forget to do it
  37. or there is a wrong amount of ']'s, but this may change in the future.
  38. An additional short description may be added after the parameters.
  39. If present it will be filled into the 'proto' header comments in the stubs
  40. code and the <refpurpose> tag in the XML documentation.
  41. An example:
  42. my_function(int arg1, int arg2 [, int arg3 [, int arg4]]) this is my 1st
  43. Arguments arg3 and arg4 are optional.
  44. If possible, the function definition should also contain it's return type
  45. in front of the definition. It's not actually used for any C code generating
  46. purposes but PHP in-source documentation instead, and as such, very useful.
  47. It can be any of int, double, string, bool, array, object, resource, mixed
  48. or void.
  49. The file must contain nothing else but function definitions, no comments or
  50. empty lines.
  51. OTHER OPTIONS
  52. --no-help
  53. By default, ext_skel creates both comments in the source code and a test
  54. function to help first time module writers to get started and testing
  55. configuring and compiling their module. This option turns off all such things
  56. which may just annoy experienced PHP module coders. Especially useful with
  57. --stubs=file
  58. which will leave out also all module specific stuff and write just function
  59. stubs with function value declarations and passed argument handling, and
  60. function entries and definitions at the end of the file, for copying and
  61. pasting into an already existing module.
  62. --assign-params
  63. --string-lens
  64. By default, function proto 'void foo(string bar)' creates the following:
  65. ...
  66. zval **bar;
  67. ... (zend_get_parameters_ex() called in the middle...)
  68. convert_to_string_ex(bar);
  69. Specifying both of these options changes the generated code to:
  70. ...
  71. zval **bar_arg;
  72. int bar_len;
  73. char *bar = NULL;
  74. ... (zend_get_parameters_ex() called in the middle...)
  75. convert_to_string_ex(bar_arg);
  76. bar = Z_STRVAL_PP(bar_arg);
  77. bar_len = Z_STRLEN_PP(bar_arg);
  78. You shouldn't have to ask what happens if you leave --string-lens out. If you
  79. have to, it's questionable whether you should be reading this document.
  80. --with-xml[=file]
  81. Creates the basics for phpdoc .xml file.
  82. --full-xml
  83. Not implemented yet. When or if there will ever be created a framework for
  84. self-contained extensions to use phpdoc system for their documentation, this
  85. option enables it on the created xml file.
  86. CURRENT LIMITATIONS, BUGS AND OTHER ODDITIES
  87. Only arguments of types int, bool, double, float, string and array are
  88. handled. For other types you must write the code yourself. And for type
  89. mixed, it wouldn't even be possible to write anything, because only you
  90. know what to expect.
  91. It can't handle correctly, and probably never will, variable list of
  92. of arguments. (void foo(int bar [, ...])
  93. Don't trust the generated code too much. It tries to be useful in most of
  94. the situations you might encounter, but automatic code generation will never
  95. beat a programmer who knows the real situation at hand. ext_skel is generally
  96. best suited for quickly generating a wrapper for c-library functions you
  97. might want to have available in PHP too.
  98. This program doesn't have a --help option. It has --no-help instead.
  99. EXAMPLE
  100. The following _one_ line
  101. bool my_drawtext(resource image, string text, resource font, int x, int y [, int color])
  102. will create this function definition for you (note that there are a few
  103. question marks to be replaced by you, and you must of course add your own
  104. value definitions too):
  105. /* {{{ proto bool my_drawtext(resource image, string text, resource font, int x, int y[, int color])
  106. */
  107. PHP_FUNCTION(my_drawtext)
  108. {
  109. zval **image, **text, **font, **x, **y, **color;
  110. int argc;
  111. int image_id = -1;
  112. int font_id = -1;
  113. argc = ZEND_NUM_ARGS();
  114. if (argc < 5 || argc > 6 || zend_get_parameters_ex(argc, &image, &text, &font, &x, &y, &color) == FAILURE) {
  115. WRONG_PARAM_COUNT;
  116. }
  117. ZEND_FETCH_RESOURCE(???, ???, image, image_id, "???", ???_rsrc_id);
  118. ZEND_FETCH_RESOURCE(???, ???, font, font_id, "???", ???_rsrc_id);
  119. switch (argc) {
  120. case 6:
  121. convert_to_long_ex(color);
  122. /* Fall-through. */
  123. case 5:
  124. convert_to_long_ex(y);
  125. convert_to_long_ex(x);
  126. /* font: fetching resources already handled. */
  127. convert_to_string_ex(text);
  128. /* image: fetching resources already handled. */
  129. break;
  130. default:
  131. WRONG_PARAM_COUNT;
  132. }
  133. php_error(E_WARNING, "my_drawtext: not yet implemented");
  134. }
  135. /* }}} */