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 B: Installing gawk 273To build some of the example extension libraries, cd to the extension directory and copy‘Makefile.pc’ to ‘Makefile’. You can then build using the same two targets. To run theexample awk scripts, you’ll need to either change the call to the extension function to matchthe name of the library (for instance, change "./ordchr.so" to "ordchr.dll" or simply"ordchr"), or rename the library to match the call (for instance, rename ‘ordchr.dll’ to‘ordchr.so’).If you build gawk.exe with one compiler but want to build an extension library with theother, you need to copy the import library. Visual C uses a library called ‘gawk.lib’, whileMinGW uses a library called ‘libgawk.a’. These files are equivalent and will interoperateif you give them the correct name. The resulting shared libraries are also interoperable.To create your own extension library, you can use the examples as models, butyou’re essentially on your own. Post to comp.lang.awk or send electronic mail toptjm@interlog.com if you have problems getting started. If you need to access functionsor variables which are not exported by gawk.exe, add them to ‘gawkw32.def’ and rebuild.You should also add ATTRIBUTE_EXPORTED to the declaration in ‘awk.h’ of any variablesyou add to ‘gawkw32.def’.Note that extension libraries have the name of the awk executable embedded in themat link time, so they will work only with gawk.exe. In particular, they won’t work if yourename gawk.exe to awk.exe or if you try to use pgawk.exe. You can perform profiling bytemporarily renaming pgawk.exe to gawk.exe. You can resolve this problem by changingthe program name in the definition of DYN_MAKEXP for your compiler.On Windows32, libraries are sought first in the current directory, then in the directorycontaining gawk.exe, and finally through the PATH environment variable.B.3.1.4 Using gawk on PC Operating SystemsWith the exception of the Cygwin environment, the ‘|&’ operator and TCP/IP networking(see Section 10.3 [Using gawk for Network <strong>Programming</strong>], page 172) are not supported forMS-DOS or MS-Windows. EMX (OS/2 only) does support at least the ‘|&’ operator.The OS/2 and MS-DOS versions of gawk search for program files as described inSection 11.4 [The <strong>AWK</strong>PATH Environment Variable], page 183. However, semicolons(rather than colons) separate elements in the <strong>AWK</strong>PATH variable. If <strong>AWK</strong>PATH is not setor is empty, then the default search path for OS/2 (16 bit) and MS-DOS versions is".;c:/lib/awk;c:/gnu/lib/awk".The search path for OS/2 (32 bit, EMX) is determined by the prefix directory (mostlikely ‘/usr’ or ‘c:/usr’) that has been specified as an option of the configure script like itis the case for the Unix versions. If ‘c:/usr’ is the prefix directory then the default searchpath contains ‘.’ and ‘c:/usr/share/awk’. Additionally, to support binary distributionsof gawk for OS/2 systems whose drive ‘c:’ might not support long file names or might notexist at all, there is a special environment variable. If UNIXROOT specifies a drive then thisspecific drive is also searched for program files. E.g., if UNIXROOT is set to ‘e:’ the completedefault search path is ".;c:/usr/share/awk;e:/usr/share/awk".An sh-like shell (as opposed to command.com under MS-DOS or cmd.exe under OS/2)may be useful for awk programming. Ian Stewartson has written an excellent shell for MS-DOS and OS/2, Daisuke Aoyama has ported GNU bash to MS-DOS using the DJGPP tools,and several shells are available for OS/2, including ksh. The file ‘README_d/README.pc’ in

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

Saved successfully!

Ooh no, something went wrong!