[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - * src/builtin.c: builtins for printing and inspecting lenses



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=03c54cb5523ab978c97791f42f85a52d1e308195
Commit:        03c54cb5523ab978c97791f42f85a52d1e308195
Parent:        6de28531fe3203032c8d3e9895da3f27eb62cf5b
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Fri Jan 15 16:55:35 2010 -0800
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Fri Jan 15 17:02:25 2010 -0800

* src/builtin.c: builtins for printing and inspecting lenses

---
 src/builtin.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/builtin.c b/src/builtin.c
index 78593fe..5296fb2 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -449,6 +449,75 @@ static struct value *lns_check_rec_glue(struct info *info,
     return lns_check_rec(info, l->lens, r->lens, check);
 }
 
+/*
+ * Print functions
+ */
+
+/* V_STRING -> V_UNIT */
+static struct value *pr_string(struct info *info, struct value *s) {
+    printf("%s", s->string->str);
+    return make_unit(ref(info));
+}
+
+/* V_REGEXP -> V_UNIT */
+static struct value *pr_regexp(struct info *info, struct value *r) {
+    print_regexp(stdout, r->regexp);
+    return make_unit(ref(info));
+}
+
+/* V_STRING -> V_UNIT */
+static struct value *pr_endline(struct info *info, struct value *s) {
+    printf("%s\n", s->string->str);
+    return make_unit(ref(info));
+}
+
+/*
+ * Lens inspection
+ */
+
+static struct value *lns_value_of_type(struct info *info, struct regexp *rx) {
+    struct value *result = make_value(V_REGEXP, ref(info));
+    if (rx)
+        result->regexp = ref(rx);
+    else
+        result->regexp = regexp_make_empty(ref(info));
+    return result;
+}
+
+/* V_LENS -> V_REGEXP */
+static struct value *lns_ctype(struct info *info, struct value *l) {
+    return lns_value_of_type(info, l->lens->ctype);
+}
+
+/* V_LENS -> V_REGEXP */
+static struct value *lns_atype(struct info *info, struct value *l) {
+    return lns_value_of_type(info, l->lens->atype);
+}
+
+/* V_LENS -> V_REGEXP */
+static struct value *lns_vtype(struct info *info, struct value *l) {
+    return lns_value_of_type(info, l->lens->vtype);
+}
+
+/* V_LENS -> V_REGEXP */
+static struct value *lns_ktype(struct info *info, struct value *l) {
+    return lns_value_of_type(info, l->lens->ktype);
+}
+
+/* V_LENS -> V_STRING */
+static struct value *lns_fmt_atype(struct info *info, struct value *l) {
+    struct value *result = NULL;
+    char *s = NULL;
+    int r;
+
+    r = lns_format_atype(l->lens, &s);
+    if (r < 0)
+        return exn_error();
+    result = make_value(V_STRING, ref(info));
+    result->string = make_string(s);
+    return result;
+}
+
 struct module *builtin_init(struct error *error) {
     struct module *modl = module_create("Builtin");
     int r;
@@ -488,6 +557,18 @@ struct module *builtin_init(struct error *error) {
                                                          T_TRANSFORM);
     DEFINE_NATIVE(modl, LNS_CHECK_REC_NAME,
                   2, lns_check_rec_glue, T_LENS, T_LENS, T_LENS);
+    /* Printing */
+    DEFINE_NATIVE(modl, "print_string", 1, pr_string, T_STRING, T_UNIT);
+    DEFINE_NATIVE(modl, "print_regexp", 1, pr_regexp, T_REGEXP, T_UNIT);
+    DEFINE_NATIVE(modl, "print_endline", 1, pr_endline, T_STRING, T_UNIT);
+
+    /* Lens inspection */
+    DEFINE_NATIVE(modl, "lens_ctype", 1, lns_ctype, T_LENS, T_REGEXP);
+    DEFINE_NATIVE(modl, "lens_atype", 1, lns_atype, T_LENS, T_REGEXP);
+    DEFINE_NATIVE(modl, "lens_vtype", 1, lns_vtype, T_LENS, T_REGEXP);
+    DEFINE_NATIVE(modl, "lens_ktype", 1, lns_ktype, T_LENS, T_REGEXP);
+    DEFINE_NATIVE(modl, "lens_format_atype", 1, lns_fmt_atype,
+                  T_LENS, T_STRING);
 
     /* System functions */
     struct module *sys = module_create("Sys");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]