aboutsummaryrefslogtreecommitdiff
path: root/src/triplet.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-02-16 16:17:03 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-02-16 16:23:53 +0200
commit6cfe6f8fe1b7506e772403fecc9d7298fc52dc74 (patch)
tree64e579d8895bfecfadceb9914f9f795d75e4ccbb /src/triplet.c
parent98ca4bb1bc96cc95bdd141cb653b17029957de38 (diff)
downloadwydawca-6cfe6f8fe1b7506e772403fecc9d7298fc52dc74.tar.gz
wydawca-6cfe6f8fe1b7506e772403fecc9d7298fc52dc74.tar.bz2
Improve keyword (meta) expansion, add testsuite framework
* src/meta.c: New file. * src/Makefile.am (wydawca_SOURCES): Add meta.c. * Makefile.am (SUBDIRS): Add tests. * configure.ac: Initialize testsuite. * src/cmdline.opt: Add preprocessor-related options: --[no-]preprocessor, -E * src/mail.c, src/triplet.c, src/verify.c, src/wydawca.c, src/wydawca.h: Use new expansion functions. * src/update-2.0.awk: Replace % markup with $. * etc/wydawca.rc: Switch to new meta-variable syntax. * gnulib.modules: Add c-ctype. * doc/Makefile.am (check-options): Rewrite. * doc/wydawca.texi: Mark unrevised/obsolete material. * tests/: New directory
Diffstat (limited to 'src/triplet.c')
-rw-r--r--src/triplet.c171
1 files changed, 84 insertions, 87 deletions
diff --git a/src/triplet.c b/src/triplet.c
index 9ac8313..2fafc8f 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -246,38 +246,37 @@ count_collected_triplets ()
}
-static char *
-expand_project_base (struct kw_expansion *exp, void *data)
+static const char *
+expand_project_base (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
return trp->project;
}
-static char *
-expand_url (struct kw_expansion *exp, void *data)
+static const char *
+expand_url (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
return trp->dpair->url;
}
-static char *
-expand_relative_dir (struct kw_expansion *exp, void *data)
+static const char *
+expand_relative_dir (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
- directive_get_value (trp, "directory", (const char**) &exp->value);
- exp->static_p = 1;
- return exp->value;
+ directive_get_value (trp, "directory", (const char**) &def->value);
+ return def->value;
}
-static char *
-expand_dest_dir (struct kw_expansion *exp, void *data)
+static const char *
+expand_dest_dir (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
return trp->dpair->dest_dir;
}
-static char *
-expand_source_dir (struct kw_expansion *exp, void *data)
+static const char *
+expand_source_dir (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
return trp->dpair->source_dir;
@@ -365,8 +364,8 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret)
return 0;
}
-static char *
-expand_triplet_full (struct kw_expansion *exp, void *data)
+static const char *
+expand_triplet_full (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
char *buf[FILE_TYPE_COUNT] = { NULL, NULL, NULL };
@@ -379,34 +378,32 @@ expand_triplet_full (struct kw_expansion *exp, void *data)
if (format_file_data (trp, file_directive, &buf[file_directive]) == 0)
size += strlen (buf[file_directive]) + 1;
- exp->value = xmalloc (size + 1);
- exp->value[0] = 0;
+ def->value = def->storage = xmalloc (size + 1);
+ def->value[0] = 0;
if (buf[file_dist])
{
- strcat(exp->value, buf[file_dist]);
- strcat(exp->value, "\n");
+ strcat (def->value, buf[file_dist]);
+ strcat (def->value, "\n");
}
if (buf[file_signature])
{
- strcat(exp->value, buf[file_signature]);
- strcat(exp->value, "\n");
+ strcat (def->value, buf[file_signature]);
+ strcat (def->value, "\n");
}
if (buf[file_directive])
{
- strcat(exp->value, buf[file_directive]);
- strcat(exp->value, "\n");
+ strcat (def->value, buf[file_directive]);
+ strcat (def->value, "\n");
}
- exp->value[size-1] = 0; /* Kill terminating newline */
+ def->value[size-1] = 0; /* Kill terminating newline */
free (buf[file_dist]);
free (buf[file_signature]);
free (buf[file_directive]);
-
- exp->static_p = 0;
- return exp->value;
+ return def->value;
}
-static char *
-expand_triplet_upload (struct kw_expansion *exp, void *data)
+static const char *
+expand_triplet_upload (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
char *buf[2] = { NULL, NULL };
@@ -417,56 +414,55 @@ expand_triplet_upload (struct kw_expansion *exp, void *data)
if (format_file_data (trp, file_signature, &buf[file_signature]) == 0)
size += strlen (buf[file_signature]) + 1;
- exp->value = xmalloc (size + 1);
- exp->value[0] = 0;
+ def->value = def->storage = xmalloc (size + 1);
+ def->value[0] = 0;
if (buf[file_dist])
{
- strcat(exp->value, buf[file_dist]);
- strcat(exp->value, "\n");
+ strcat (def->value, buf[file_dist]);
+ strcat (def->value, "\n");
}
if (buf[file_signature])
{
- strcat(exp->value, buf[file_signature]);
- strcat(exp->value, "\n");
+ strcat (def->value, buf[file_signature]);
+ strcat (def->value, "\n");
}
- exp->value[size-1] = 0; /* Kill terminating newline */
+ def->value[size-1] = 0; /* Kill terminating newline */
free (buf[file_dist]);
free (buf[file_signature]);
- exp->static_p = 0;
- return exp->value;
+ return def->value;
}
-static char *
-expand_triplet_dist (struct kw_expansion *exp, void *data)
+static const char *
+expand_triplet_dist (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
- format_file_data (trp, file_dist, &exp->value);
- exp->static_p = 0;
- return exp->value;
+ format_file_data (trp, file_dist, &def->storage);
+ def->value = def->storage;
+ return def->value;
}
-static char *
-expand_triplet_sig (struct kw_expansion *exp, void *data)
+static const char *
+expand_triplet_sig (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
- format_file_data (trp, file_signature, &exp->value);
- exp->static_p = 0;
- return exp->value;
+ format_file_data (trp, file_signature, &def->storage);
+ def->value = def->storage;
+ return def->value;
}
-static char *
-expand_triplet_directive (struct kw_expansion *exp, void *data)
+static const char *
+expand_triplet_directive (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
- format_file_data (trp, file_directive, &exp->value);
- exp->static_p = 0;
- return exp->value;
+ format_file_data (trp, file_directive, &def->storage);
+ def->value = def->storage;
+ return def->value;
}
-static char *
-expand_user_name (struct kw_expansion *exp, void *data)
+static const char *
+expand_user_name (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
return trp->user;
@@ -479,7 +475,7 @@ fill_user_data (struct file_triplet *trp)
struct access_method *method = trp->dpair->access_method[user_data_method];
char *text;
unsigned nrows, ncols;
- struct kw_expansion kwexp[4];
+ struct metadef def[5];
struct passwd *pw;
if (trp->user_data)
@@ -494,10 +490,11 @@ fill_user_data (struct file_triplet *trp)
pw = getpwuid (TRIPLET_UID (trp));
if (!pw)
return;
- make_default_kwexp (kwexp, pw->pw_name, trp->project);
- escape_kwexp (method, kwexp, NITEMS (kwexp));
- text = expand_param (method->param[1], kwexp, NITEMS (kwexp), NULL);
-
+ make_default_meta (def, pw->pw_name, trp->project);
+ meta_escape (method, def);
+ text = meta_expand_string (method->param[1], def, NULL);
+ meta_free (def);
+
rc = method_run (method, text);
free (text);
if (rc)
@@ -519,50 +516,50 @@ fill_user_data (struct file_triplet *trp)
}
}
-static char *
-expand_user_real_name (struct kw_expansion *exp, void *data)
+static const char *
+expand_user_real_name (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
fill_user_data (trp);
if (trp->user_data && trp->user_data[1])
return trp->user_data[1];
- exp->value = "UNKNOWN";
- exp->static_p = 1;
- return exp->value;
+ def->value = "UNKNOWN";
+ return def->value;
}
-static char *
-expand_user_email (struct kw_expansion *exp, void *data)
+static const char *
+expand_user_email (struct metadef *def, void *data)
{
struct file_triplet *trp = data;
fill_user_data (trp);
if (trp->user_data && trp->user_data[0])
return trp->user_data[0];
- exp->value = "UNKNOWN";
- exp->static_p = 1;
- return exp->value;
+ def->value = "UNKNOWN";
+ return def->value;
}
-struct kw_expansion triplet_exp[] = {
- { "project", NULL, 0, expand_project_base, NULL },
- { "url", NULL, 0, expand_url, NULL },
- { "dir", NULL, 0, expand_relative_dir, NULL },
- { "dest-dir", NULL, 0, expand_dest_dir, NULL },
- { "source-dir", NULL, 0, expand_source_dir, NULL },
- { "triplet:full", NULL, 0, expand_triplet_full, NULL },
- { "triplet:upload", NULL, 0, expand_triplet_upload, NULL },
- { "triplet:dist", NULL, 0, expand_triplet_dist, NULL },
- { "triplet:sig", NULL, 0, expand_triplet_sig, NULL },
- { "triplet:dir", NULL, 0, expand_triplet_directive, NULL },
- { "user", NULL, 0, expand_user_name, NULL },
- { "user:name", NULL, 0, expand_user_name, NULL },
- { "user:real-name", NULL, 0, expand_user_real_name, NULL },
- { "user:email", NULL, 0, expand_user_email, NULL },
+struct metadef triplet_meta[] = {
+ { "project", NULL, expand_project_base, NULL },
+ { "url", NULL, expand_url, NULL },
+ { "dir", NULL, expand_relative_dir, NULL },
+ { "dest-dir", NULL, expand_dest_dir, NULL },
+ { "source-dir", NULL, expand_source_dir, NULL },
+ { "triplet:full", NULL, expand_triplet_full, NULL },
+ { "triplet:upload", NULL, expand_triplet_upload, NULL },
+ { "triplet:dist", NULL, expand_triplet_dist, NULL },
+ { "triplet:sig", NULL, expand_triplet_sig, NULL },
+ { "triplet:dir", NULL, expand_triplet_directive, NULL },
+ { "user", NULL, expand_user_name, NULL },
+ { "user:name", NULL, expand_user_name, NULL },
+ { "user:real-name", NULL, expand_user_real_name, NULL },
+ { "user:email", NULL, expand_user_email, NULL },
+ { NULL }
};
char *
triplet_expand_param (const char *tmpl, struct file_triplet *trp)
{
- free_kwexp (triplet_exp, NITEMS (triplet_exp));
- return expand_param (tmpl, triplet_exp, NITEMS (triplet_exp), trp);
+ char *p = meta_expand_string (tmpl, triplet_meta, trp);
+ meta_free (triplet_meta);
+ return p;
}

Return to:

Send suggestions and report system problems to the System administrator.