2 * Copyright (C) 2009-2015 David Lutterkort
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: David Lutterkort <lutter@redhat.com>
25 * Transformers for going from file globs to path names in the tree
26 * functions are in transform.c
29 /* Filters for globbing files */
34 unsigned int include : 1;
37 struct filter *make_filter(struct string *glb, unsigned int include);
38 void free_filter(struct filter *filter);
40 /* Transformers that actually run lenses on contents of files */
44 struct filter *filter;
47 struct transform *make_transform(struct lens *lens, struct filter *filter);
48 void free_transform(struct transform *xform);
51 * When we pass a tree for a transform, the tree must have exactly one
52 * child with label "lens" whose value is the qualified name of the lens to
53 * use, and any number of children labelled "incl" or "excl" whose values
54 * are glob patterns used to filter which files to transform.
57 /* Verify that the tree XFM represents a valid transform. If it does not,
58 * add an 'error' child to it.
60 * Return 0 if XFM is a valid transform, -1 otherwise.
62 int transform_validate(struct augeas *aug, struct tree *xfm);
64 /* Load all files matching the TRANSFORM's filter into the tree in AUG by
65 * applying the TRANSFORM's lens to their contents and putting the
66 * resulting tree under "/files" + filename. Also stores some information
67 * about filename underneath "/augeas/files" + filename
68 * If a FILE is passed, only this FILE will be loaded.
70 int transform_load(struct augeas *aug, struct tree *xfm, const char *file);
72 /* Return 1 if TRANSFORM applies to PATH, 0 otherwise.
73 * PATH must not include "/files/".
75 int filter_matches(struct tree *xfm, const char *path);
77 /* Return 1 if TRANSFORM applies to PATH, 0 otherwise. The TRANSFORM
78 * applies to PATH if (1) PATH starts with "/files/" and (2) the rest of
79 * PATH matches the transform's filter
81 int transform_applies(struct tree *xfm, const char *path);
83 /* Save TREE into the file corresponding to PATH. It is assumed that the
84 * TRANSFORM applies to that PATH
86 int transform_save(struct augeas *aug, struct tree *xfm,
87 const char *path, struct tree *tree);
89 /* Transform TEXT into a tree and store it at PATH
91 int text_store(struct augeas *aug, const char *lens_name,
92 const char *path, const char *text);
94 /* Transform the tree at PATH back into TEXT_OUT, assuming TEXT_IN was
95 * used to initially generate the tree
97 int text_retrieve(struct augeas *aug, const char *lens_name,
98 const char *path, struct tree *tree,
99 const char *text_in, char **text_out);
101 /* Remove the file for TREE, either by moving it to a .augsave file or by
102 * unlinking it, depending on aug->flags. TREE must be the node underneath
103 * /augeas/files corresponding to the file to be removed.
105 * Return 0 on success, -1 on failure
107 int remove_file(struct augeas *aug, struct tree *tree);
109 /* Return a printable name for the transform XFM. Never returns NULL. */
110 const char *xfm_lens_name(struct tree *xfm);
112 /* Store a file-specific transformation error in /augeas/files/PATH/error */
113 ATTRIBUTE_FORMAT(printf, 4, 5)
114 void transform_file_error(struct augeas *aug, const char *status,
115 const char *filename, const char *format, ...);
121 * indent-tabs-mode: nil