diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-02 20:45:46 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-02 20:45:46 -0400 |
commit | 9ee8aeb59ad3b3873d52f3c9a2ab80b28c4c2c20 (patch) | |
tree | b51848f2af88f781a920b75ff6aca4efe815bdda /gawkapi.c | |
parent | f0391b8a4db649853ecc47a10b09d7c4b04330cf (diff) | |
download | egawk-9ee8aeb59ad3b3873d52f3c9a2ab80b28c4c2c20.tar.gz egawk-9ee8aeb59ad3b3873d52f3c9a2ab80b28c4c2c20.tar.bz2 egawk-9ee8aeb59ad3b3873d52f3c9a2ab80b28c4c2c20.zip |
After the gawkapi get_file function opens a file, call the BEGINFILE block.
Diffstat (limited to 'gawkapi.c')
-rw-r--r-- | gawkapi.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -1054,6 +1054,9 @@ api_lookup_file(awk_ext_id_t id, const char *name, size_t namelen) /* api_get_file --- return a handle to an existing or newly opened file */ +extern INSTRUCTION *main_beginfile; +extern int currule; + static const awk_input_buf_t * api_get_file(awk_ext_id_t id, const char *name, size_t namelen, const char *filetype, size_t typelen) { @@ -1065,8 +1068,27 @@ api_get_file(awk_ext_id_t id, const char *name, size_t namelen, const char *file if (curfile == NULL) { if (nextfile(& curfile, false) <= 0) return NULL; - /* XXX Fix me! */ - fputs("Bug: need to call BEGINFILE!\n", stderr); + { + INSTRUCTION *pc = main_beginfile; + /* save execution state */ + int save_rule = currule; + char *save_source = source; + + while (1) { + if (!pc) + fatal(_("cannot find end of BEGINFILE rule")); + if (pc->opcode == Op_after_beginfile) + break; + pc = pc->nexti; + } + pc->opcode = Op_stop; + (void) (*interpret)(main_beginfile); + pc->opcode = Op_after_beginfile; + after_beginfile(& curfile); + /* restore execution state */ + currule = save_rule; + source = save_source; + } } return &curfile->public; } |