21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix C: Implementation Notes 287use of separate suffixes, instead of plain ‘gawkmisc.c’, makes it possible to move filesfrom a port’s subdirectory into the main subdirectory, without accidentally destroyingthe real ‘gawkmisc.c’ file. (Currently, this is only an issue for the PC operating systemports.)6. Supply a ‘Makefile’ as well as any other C source and header files that are necessary foryour operating system. All your code should be in a separate subdirectory, with a namethat is the same as, or reminiscent of, either your operating system or the computersystem. If possible, try to structure things so that it is not necessary to move files outof the subdirectory into the main source directory. If that is not possible, then be sureto avoid using names for your files that duplicate the names of files in the main sourcedirectory.7. Update the documentation. Please write a section (or sections) for this book describingthe installation and compilation steps needed to compile and/or install gawk for yoursystem.8. Be prepared to sign the appropriate paperwork. In order for the FSF to distributeyour code, you must either place your code in the public domain and submit a signedstatement to that effect, or assign the copyright in your code to the FSF.Following these steps makes it much easier to integrate your changes into gawk and havethem coexist happily with other operating systems’ code that is already there.In the code that you supply and maintain, feel free to use a coding style and brace layoutthat suits your taste.C.3 Adding New Built-in Functions to gawkDanger Will Robinson! Danger!!Warning! Warning!The RobotBeginning with gawk 3.1, it is possible to add new built-in functions to gawk usingdynamically loaded libraries. This facility is available on systems (such as GNU/Linux)that support the dlopen and dlsym functions. This section describes how to write anduse dynamically loaded extensions for gawk. Experience with programming in C or C++ isnecessary when reading this section.Caution: The facilities described in this section are very much subject to change in afuture gawk release. Be aware that you may have to re-do everything, perhaps from scratch,at some future time.Caution: If you have written your own dynamic extensions, be sure to recompile themfor each new gawk release. There is no guarantee of binary compatibility between differentreleases, nor will there ever be such a guarantee.C.3.1 A Minimal Introduction to gawk InternalsThe truth is that gawk was not designed for simple extensibility. The facilities for addingfunctions using shared libraries work, but are something of a “bag on the side.” Thus, thistour is brief and simplistic; would-be gawk hackers are encouraged to spend some time readingthe source code before trying to write extensions based on the material presented here.Of particular note are the files ‘awk.h’, ‘builtin.c’, and ‘eval.c’. Reading ‘awkgram.y’in order to see how the parse tree is built would also be of use.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!