gboolean tf_grep_prepare(LogTemplateFunction *self, gpointer s, LogTemplate *parent, gint argc, gchar *argv[], GError **error) { TFCondState *state = (TFCondState *) s; GOptionContext *ctx; gint max_count = 0; GOptionEntry grep_options[] = { { "max-count", 'm', 0, G_OPTION_ARG_INT, &max_count, NULL, NULL }, { NULL } }; g_return_val_if_fail(error == NULL || *error == NULL, FALSE); ctx = g_option_context_new("grep"); g_option_context_add_main_entries(ctx, grep_options, NULL); if (!g_option_context_parse(ctx, &argc, &argv, error)) { g_option_context_free(ctx); g_free(argv); return FALSE; } g_option_context_free(ctx); if (argc < 3) { g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "$(grep) requires at least two arguments"); return FALSE; } state->grep_max_count = max_count; return tf_cond_prepare(self, s, parent, argc, argv, error); }
gboolean tf_grep_prepare(LogTemplateFunction *self, LogTemplate *parent, gint argc, gchar *argv[], gpointer *state, GDestroyNotify *state_destroy, GError **error) { g_return_val_if_fail(error == NULL || *error == NULL, FALSE); if (argc < 2) { g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "$(grep) requires at least two arguments"); return FALSE; } return tf_cond_prepare(self, parent, argc, argv, state, state_destroy, error); }
gboolean tf_if_prepare(LogTemplateFunction *self, gpointer s, LogTemplate *parent, gint argc, gchar *argv[], GError **error) { g_return_val_if_fail(error == NULL || *error == NULL, FALSE); if (argc != 4) { g_set_error(error, LOG_TEMPLATE_ERROR, LOG_TEMPLATE_ERROR_COMPILE, "$(if) requires three arguments"); return FALSE; } return tf_cond_prepare(self, s, parent, argc, argv, error); }