1EXAMPLE(7)                      libmawk manual                      EXAMPLE(7)
2
3
4

NAME

6       libmawk example - how to use the library
7

SYNOPSIS

9       #include <libmawk.h>
10
11

DESCRIPTION

13       Libmawk  is a library that lets applications to embed awk scripts using
14       the code of the popular implementation mawk.  The normal process is  to
15       call  libmawk_initialize() to set up a new mawk context (with script(s)
16       loaded), then in the main loop feed  it  using  libmawk_append_input().
17       For  "out  of  band" communication, the program may also call functions
18       implemented in awk and read (or modify) global  variables  of  the  awk
19       script.  The  hos  tapplication usally will also bind some of its func‐
20       tions to the context using libmawk_register_function, which allows  the
21       awk  script  to  call the host applicaiton's functions directly as they
22       were awk builtins or user defined functions. After the main  loop,  the
23       application  destroys  the  context freeing up all memory allocated for
24       the script(s).
25
26       One context is for one awk program. One awk program may consist of mul‐
27       tiple  script  files  (just  as with command line awk, with multiple -f
28       filename arguments). Libmawk is instance safe, the host application may
29       create  multiple  instances of contexts with the same or with different
30       set of awk scripts loaded. These  contexts  are  totally  separate,  no
31       variables,  functions  or  any  sort of states are shared. However, the
32       host application may  provide  means  of  communication  between  those
33       scripts  by  custom  functions  or by copying variable contents between
34       them.
35

Example application

37       The following example application creates a single  context  to  demon‐
38       strate all the above mentioned functionality.
39
40
41
42libmawk                           2009-08-10                        EXAMPLE(7)
Impressum