読者です 読者をやめる 読者になる 読者になる

libmawkを使ってみる

C言語 AWK

http://repo.hu/projects/libmawk/

#include <stdio.h>
#include <stdlib.h>

#include <libmawk.h>

int main() {
  mawk_state_t *m;
  int argc = 2;
  char *argv[] = {"awk", "{print $2}"};

  m = libmawk_initialize(argc, argv);

  if (m == NULL) {
    exit(EXIT_FAILURE);
  }

  puts("---");

  libmawk_append_input(m, "London Bridge is broken down,\n");
  libmawk_append_input(m, "Broken down, bloken down.\n");
  libmawk_append_input(m, "London Bridge is bloken down,\n");
  libmawk_append_input(m, "My fair lady.\n");

  libmawk_run_main(m);

  libmawk_uninitialize(m);

  puts("---");

  return 0 ;
}


shell> gcc test.c -lmawk -o test
shell> ./test

    • -

Bridge
down,
Bridge
fair

    • -