--- - branch: MAIN date: Wed Aug 31 04:19:41 UTC 2011 files: - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/Makefile pathrev: othersrc/external/historical/eawk/Makefile@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/awkgram.y pathrev: othersrc/external/historical/eawk/dist/awkgram.y@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/FIXES pathrev: othersrc/external/historical/eawk/dist/FIXES@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/Makefile pathrev: othersrc/external/historical/eawk/dist/Makefile@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/README pathrev: othersrc/external/historical/eawk/dist/README@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl9.sh pathrev: othersrc/external/historical/eawk/dist/dl9.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/EAWK pathrev: othersrc/external/historical/eawk/dist/EAWK@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/eawk.1 pathrev: othersrc/external/historical/eawk/dist/eawk.1@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/awkre.h pathrev: othersrc/external/historical/eawk/dist/awkre.h@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dlA.sh pathrev: othersrc/external/historical/eawk/dist/dlA.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dlB.sh pathrev: othersrc/external/historical/eawk/dist/dlB.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dlC.sh pathrev: othersrc/external/historical/eawk/dist/dlC.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/libeawk.3 pathrev: othersrc/external/historical/eawk/dist/libeawk.3@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl.sh pathrev: othersrc/external/historical/eawk/dist/dl.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl2.sh pathrev: othersrc/external/historical/eawk/dist/dl2.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/b.c pathrev: othersrc/external/historical/eawk/dist/b.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl3.sh pathrev: othersrc/external/historical/eawk/dist/dl3.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl4.sh pathrev: othersrc/external/historical/eawk/dist/dl4.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl5.sh pathrev: othersrc/external/historical/eawk/dist/dl5.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl6.sh pathrev: othersrc/external/historical/eawk/dist/dl6.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl7.sh pathrev: othersrc/external/historical/eawk/dist/dl7.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/lex.c pathrev: othersrc/external/historical/eawk/dist/lex.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/dl8.sh pathrev: othersrc/external/historical/eawk/dist/dl8.sh@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/proto.h pathrev: othersrc/external/historical/eawk/dist/proto.h@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/lib.c pathrev: othersrc/external/historical/eawk/dist/lib.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/main.c pathrev: othersrc/external/historical/eawk/dist/main.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/parse.c pathrev: othersrc/external/historical/eawk/dist/parse.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/proctab.c pathrev: othersrc/external/historical/eawk/dist/proctab.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/run.c pathrev: othersrc/external/historical/eawk/dist/run.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/eawk.h pathrev: othersrc/external/historical/eawk/dist/eawk.h@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/dist/tran.c pathrev: othersrc/external/historical/eawk/dist/tran.c@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/eawk/Makefile pathrev: othersrc/external/historical/eawk/eawk/Makefile@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/eawk/expected pathrev: othersrc/external/historical/eawk/eawk/expected@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/libeawk/Makefile pathrev: othersrc/external/historical/eawk/libeawk/Makefile@1.1.1.1 type: imported - new: 1.1.1.1 old: '0' path: othersrc/external/historical/eawk/libeawk/shlib_version pathrev: othersrc/external/historical/eawk/libeawk/shlib_version@1.1.1.1 type: imported id: 20110831T041941Z.673799da940fc46bb0a6071beb51c0a4d59bdbec log: "Embedded Awk\n============\n\nThis is a heresy I have done, of my own free will and volition, and\nwhich I now know as being a sin.\n\nFirstly, I have butchered the one true awk source code, made\nit re-entrant and embeddable in C programs, and now present it\nas a library (libeawk) and a small driver program (eawk). \ The\ndriver program now uses getopt_long, and gives a good idea of\nhow to use eawk in embedded code.\n\nFurthermore, I have \"added\" to the one true language. \ The\nadditions are 4 functions:\n\n\tdlopen(handle, shared object name)\n\tdlproto(handle, C function prototype as a string)\n\tdlcall(handle, function, function args...)\n\tdlclose(handle)\n\nwhich allows you to do such abominations as:\n\n\tdlopen(libc, \"libc\");\n\tdlproto(libc, \"long write(int, awkptr, long)\")\n\tdlcall(libc, \"write\", 1, \"hi\\n\", 3)\n\tdlclose(libc)\n\n(i.e. allows interfacing to shared libraries and shared objects without\nany C glue or other shim in between the scripting language and the\ncompiled library).\n\nPlease note that you can specify the prototype at the same time as the\nforeign function call, with dlcall:\n\n\tdlopen(libc, \"libc\");\n\tdlcall(libc, \"long write(int, awkptr, long)\", 1, \"hi\\n\", 3)\n\nand then:\n\n% eawk 'BEGIN { dlopen(libc, \"libc\"); dlcall(libc, \"int printf(awkptr)\", \"Hello world\\n\") }' /dev/null\nHello world\n%\n\nIn fact, the following scripts are all equivalent:\n\n% eawk 'BEGIN { dlopen(libc, \"libc\"); dlcall(libc, \"long write(int, awkptr, long)\", 1, \"Hello world\\n\", 12) }' /dev/null\nHello world\n% eawk 'BEGIN { dlopen(libc, \"libc\"); dlcall(libc, \"int printf(awkptr)\", \"Hello world\\n\") }' /dev/null\nHello world\n% eawk 'BEGIN { dlopen(libc, \"libc\"); dlcall(libc, \"int fprintf(cvar, awkptr)\", \"stdout\", \"Hello world\\n\") }' /dev/null\nHello world\n\nThe type of arguments, and the return type, given in the dlproto()\ncalls is important:\n\n\tawkptr - a string as passed from the eawk script\n\tcptr - a pointer to an object in the compiled shared object\n\tcref - the address of a pointer to an object in the compiled\n\t\tshared object. this is used to map the construct:\n\t\t\t&cp\n\t\tinto an awk string\n\tcvar - the awk string which maps to a compiled well-known\n\t\tvariable in the compiled shared object, typically\n\t\tstdin, stdout and stderr\n\tvoid - no return type\n\tbool - the boolean type\n\tint - standard integer type on this machine\n\tlong - native long on this machine\n\tint64 - 64-bit data type\n\nIn order to support foreign functions which typically use a structure\npassed into every function as a handle (very much like the eawk\nimplementation here), I'd also added two other functions which can be\ncalled from scripts:\n\n\tbuf = dlalloc(size)\n\tdlfree(buf)\n\nand also a new prototype keyword called \"cptr\" - this is functionally\nequivalent to long, but more intuitively obvious that the argument should\nbe pre-allocated storage (at the native layer).\n\n% eawk 'BEGIN {\n\tdlopen(libc, \"libc\")\n\tsize = 1024\n\tbuf = dlalloc(size)\n\tdlcall(libc, \"int snprintf(cptr, int, awkptr, int)\", buf, size, \"allocated size is %d\\n\", size)\n\tdlcall(libc, \"int printf(cptr)\", buf)\n\tdlfree(buf)\n}' /dev/null\nallocated size is 1024\n%\n\nFinally, we need a way to get information back from C structures and\nstorage into an awk script, and we do that with the\n\n\tvar = dlfield(storage, offset, type)\n\nfunction. This can be used as follows:\n\n% eawk 'BEGIN {\n\tdlopen(libc, \"libc\")\n\tst = dlalloc(1024)\n\tdlcall(libc, \"int stat(awkptr, cptr)\", \"/etc/group\", st)\n\tmode = dlfield(st, 8, \"int16\")\n\tprintf(\"%s mode is %o\\n\", \"/etc/group\", mode)\n\tdlfree(st)\n}' /dev/null\nmode is 100644\n%\n\nTo illustrate some of the dlcall features a bit further, this script\nwill print out the keys in the user's keyring, by direct calling of\nexported frunctionality from libnetpgp:\n\n% eawk '\nBEGIN {\n\tdlopen(libc, \"libc\")\n\tdlopen(libnetpgp, \"libnetpgp\")\n\tnetpgp = dlalloc(2048)\n\tret = dlcall(libnetpgp, \"int netpgp_set_homedir(cptr, awkptr, awkptr, int)\", netpgp, ENVIRON[\"HOME\"], \"/.gnupg\", quiet = 1)\n\tret = dlcall(libnetpgp, \"int netpgp_init(cptr)\", netpgp)\n}\nEND {\n\tret = dlcall(libnetpgp, \"int netpgp_list_keys_json(cptr, cref, int)\", netpgp, json, psigs = 0)\n\tret = dlcall(libnetpgp, \"int netpgp_format_json(cvar, cptr, int)\", \"stdout\", json, psigs = 0)\n}' /dev/null\n126 keys found\nsignature \ 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12\nKey fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 \nuid Alistair Crooks \nuid Alistair Crooks \nuid Alistair Crooks \nuid Alistair Crooks \nuid Alistair Crooks (Yahoo!) \nencryption 2048/RSA (Encrypt or Sign) 79deb61e488eee74 2004-01-12\n...\n%\n\nNote that the prototype for netpgp_list_keys_json() above is:\n\n\tint netpgp_list_keys_json(netpgp_t *, char **, const int);\n\nand the prototype for netpgp_format_json is:\n\n\tint netpgp_format_json(void *, const char *, const int);\n\nand so the signature of the compiled function in the shared object\ndefines the type of arguments that are passed via dlcall.\n\nAnother example is that of calculating a digest using the SHA256_File\nfunction in libc.\n\n% eawk 'BEGIN {\n\tf = \"../Makefile\"\n\tdlopen(libc, \"libc\")\n\tbuf = dlalloc(65)\n\tdlcall(libc, \"cptr SHA256_File(awkptr, cptr)\", f, buf)\n\tdlcall(libc, \"int printf(awkptr, awkptr, cptr)\", \"SHA256 (%s) = %s\\n\", f, buf) }')\n}'\nSHA256 (../Makefile) = a6ccb2e57801867720b434d8dfc248d62389c518457ea1a022861819151f2b1f\n% digest sha256 ../Makefile\nSHA256 (../Makefile) = a6ccb2e57801867720b434d8dfc248d62389c518457ea1a022861819151f2b1f\n%\n\nI've had these changes around in my own tree for over 2 and a half years.\nIt's finally time to commit them.\n\nAlistair Crooks\nWed Aug 30 19:45:50 PDT 2011\n\nStatus:\n\nVendor Tag:\tBWK\nRelease Tags:\teawk-base\n" module: othersrc subject: 'CVS commit: othersrc/external/historical/eawk' unixtime: '1314764381' user: agc