README.EXT_SKEL 6.8 KB

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