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