1  /*
       2   * lsfd-filter.c - filtering engine for lsfd
       3   *
       4   * Copyright (C) 2021 Red Hat, Inc.
       5   * Copyright (C) 2021 Masatake YAMATO <yamato@redhat.com>
       6   *
       7   * This file may be redistributed under the terms of the
       8   * GNU Lesser General Public License.
       9   */
      10  #ifndef UTIL_LINUX_LSFD_FILTER_H
      11  #define UTIL_LINUX_LSFD_FILTER_H
      12  
      13  #include "libsmartcols.h"
      14  #include <stdio.h>
      15  #include <stdbool.h>
      16  
      17  #define LSFD_FILTER_UNKNOWN_COL_ID -1
      18  
      19  struct lsfd_filter;
      20  
      21  /*
      22   * @column_name_to_id: a function converting a column name to its id.
      23   *
      24   * @column_name_to_id should return LSFD_FILTER_UNKNOWN_COL_ID if
      25   * an unknown column name is given.
      26   */
      27  struct lsfd_filter *lsfd_filter_new(const char *const expr, struct libscols_table *tb,
      28  				      int ncols,
      29  				      int (*column_name_to_id)(const char *, void *),
      30  				      struct libscols_column *(*add_column_by_id)(struct libscols_table *, int, void*),
      31  				      void *data);
      32  
      33  /* Call lsfd_filter_get_errmsg() after lsfd_filter_new() to detect
      34   * whether lsfd_filter_new() is failed or not. Returning NULL means,
      35   * lsfd_filter_new() is successful. */
      36  const char *lsfd_filter_get_errmsg(struct lsfd_filter *filter);
      37  void lsfd_filter_free(struct lsfd_filter *filter);
      38  bool lsfd_filter_apply(struct lsfd_filter *filter, struct libscols_line *ln);
      39  
      40  /* Dumping AST. */
      41  void lsfd_filter_dump(struct lsfd_filter *filter, FILE *stream);
      42  
      43  #endif	/* UTIL_LINUX_LSFD_FILTER_H */