summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2008-09-16 22:03:03 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2008-09-16 22:03:03 (GMT)
commit9c8ceb87234538c0740d3f02e40a4448ab995905 (patch) (side-by-side diff)
treefe808778b6297bc5fae2cda84d50d2c1caa6c1e7
parent99c453be5795d76e10b0a9cf1a2558367e538a1c (diff)
downloadmailfromd-9c8ceb87234538c0740d3f02e40a4448ab995905.tar.gz
mailfromd-9c8ceb87234538c0740d3f02e40a4448ab995905.tar.bz2
* mfd/bi_getopt.m4 (getopt): Use | as a short/long option
separator. Make sure optind/optarg are set before returning EOF. * mfd/gram.y (mailfromd_run): Remove superfluous call to env_leave_frame. * mfd/drivers.c (mark_type_argx, mark_type_vaptr): New functions. * mfd/prog.c (env_vaptr): Cast the result. * mfd/main.c (argpflag): Understand abbreviated forms of the --run option. * mfd/bi_db.m4 (dbfirst, dbnext, dbkey, dbvalue): New functions (proof of concept). git-svn-id: file:///svnroot/mailfromd/trunk@1670 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog15
-rw-r--r--mfd/bi_db.m4146
-rw-r--r--mfd/bi_getopt.m411
-rw-r--r--mfd/drivers.c12
-rw-r--r--mfd/gram.y2
-rw-r--r--mfd/main.c10
-rw-r--r--mfd/prog.c2
7 files changed, 188 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 3116aef..4702c19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-09-17 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * mfd/bi_getopt.m4 (getopt): Use | as a short/long option
+ separator.
+ Make sure optind/optarg are set before returning EOF.
+ * mfd/gram.y (mailfromd_run): Remove superfluous call to
+ env_leave_frame.
+ * mfd/drivers.c (mark_type_argx, mark_type_vaptr): New functions.
+ * mfd/prog.c (env_vaptr): Cast the result.
+ * mfd/main.c (argpflag): Understand abbreviated forms of the --run
+ option.
+
+ * mfd/bi_db.m4 (dbfirst, dbnext, dbkey, dbvalue): New functions
+ (proof of concept).
+
2008-09-16 Sergey Poznyakoff <gray@gnu.org.ua>
Implement functions with variable number of arguments and 'run' mode.
diff --git a/mfd/bi_db.m4 b/mfd/bi_db.m4
index 024337e..f3c6c21 100644
--- a/mfd/bi_db.m4
+++ b/mfd/bi_db.m4
@@ -144,6 +144,152 @@ MF_DEFUN(dbdel, VOID, STRING dbname, STRING keystr, OPTIONAL, NUMBER null)
END
+#define NUMDB 128
+
+struct db_tab {
+ int used;
+ DBM_FILE db;
+ DBM_DATUM key;
+};
+
+static void *
+alloc_db_tab()
+{
+ return xcalloc(NUMDB, sizeof(struct db_tab));
+}
+
+static void
+close_db_tab(struct db_tab *dbt)
+{
+ if (dbt->used) {
+ mu_dbm_datum_free(&dbt->key);
+ mu_dbm_close(&dbt->db);
+ dbt->used = 0;
+ }
+}
+
+static void
+destroy_db_tab(void *data)
+{
+ int i;
+ struct db_tab *db = data;
+ for (i = 0; i < NUMDB; i++)
+ close_db_tab(db + i);
+ free(db);
+}
+
+MF_DECLARE_DATA(DBTAB, alloc_db_tab, destroy_db_tab);
+
+static int
+new_db_tab(struct db_tab *dbt)
+{
+ int i;
+ for (i = 0; i < NUMDB; i++)
+ if (!dbt[i].used) {
+ dbt[i].used = 1;
+ return i;
+ }
+ return -1;
+}
+
+
+
+MF_DEFUN(dbfirst, NUMBER, STRING dbname)
+{
+ int rc;
+ int n;
+ struct db_tab *dbt = MF_GET_DATA;
+ DBM_FILE db;
+ DBM_DATUM key;
+
+ if (mu_dbm_open(dbname, &db, MU_STREAM_RDWR, 0640, NULL))
+ MF_THROW(mfe_dbfailure,
+ _("mu_dbm_open(%s) failed: %s"),
+ dbname,
+ mu_dbm_strerror());
+ rc = mu_dbm_firstkey(&db, &key);
+ MF_ASSERT(rc == 0, mfe_dbfailure,
+ _("mu_dbm_firstkey failed: %s"),
+ mu_dbm_strerror());
+ n = new_db_tab(dbt);
+ MF_ASSERT(n >= 0,
+ mfe_failure,
+ _("No more database entries available"));
+ dbt += n;
+ dbt->db = db;
+ dbt->key = key;
+ MF_RETURN(n);
+}
+END
+
+MF_DEFUN(dbnext, NUMBER, NUMBER dn)
+{
+ struct db_tab *dbt = MF_GET_DATA + dn;
+ DBM_DATUM nextkey;
+ int rc;
+
+ MF_ASSERT(dn >= 0 && dn < NUMDB && dbt->used,
+ mfe_range,
+ _("Invalid database descriptor"));
+
+ rc = mu_dbm_nextkey(&dbt->db, dbt->key, &nextkey);
+ if (rc) {
+ close_db_tab(dbt);
+ MF_RETURN(0);
+ }
+ mu_dbm_datum_free(&dbt->key);
+ dbt->key = nextkey;
+ MF_RETURN(1);
+}
+END
+
+MF_DEFUN(dbkey, STRING, NUMBER dn)
+{
+ size_t off, len;
+ char *s;
+ struct db_tab *dbt = MF_GET_DATA + dn;
+
+ MF_ASSERT(dn >= 0 && dn < NUMDB && dbt->used,
+ mfe_range,
+ _("Invalid database descriptor"));
+
+ len = MU_DATUM_SIZE(dbt->key);
+ s = MF_ALLOC_HEAP(off, len + 1);
+ memcpy(s, MU_DATUM_PTR(dbt->key), len);
+ s[len] = 0;
+ MF_RETURN(off);
+}
+END
+
+MF_DEFUN(dbvalue, STRING, NUMBER dn)
+{
+ int rc;
+ size_t off, len;
+ char *s;
+ struct db_tab *dbt = MF_GET_DATA + dn;
+ DBM_DATUM contents;
+
+ MF_ASSERT(dn >= 0 && dn < NUMDB && dbt->used,
+ mfe_range,
+ _("Invalid database descriptor"));
+
+ memset(&contents, 0, sizeof contents);
+ rc = mu_dbm_fetch(&dbt->db, dbt->key, &contents);
+ MF_ASSERT(rc == 0,
+ mfe_dbfailure,
+ _("Key not found: %s"),
+ mu_dbm_strerror());
+
+ len = MU_DATUM_SIZE(contents);
+ s = MF_ALLOC_HEAP(off, len + 1);
+ memcpy(s, MU_DATUM_PTR(contents), len);
+ s[len] = 0;
+ mu_dbm_datum_free(&contents);
+ MF_RETURN(off);
+}
+END
+
+
static void
greylist_print_item(const char *key, size_t size, const void *content)
{
diff --git a/mfd/bi_getopt.m4 b/mfd/bi_getopt.m4
index 70a7e55..2125b89 100644
--- a/mfd/bi_getopt.m4
+++ b/mfd/bi_getopt.m4
@@ -54,7 +54,7 @@ MF_DEFUN_VARARGS(getopt, STRING, NUMBER argc, NUMBER argoff)
size = lsize = lcnt = 0;
for (i = 0; i < n; i++) {
MF_VA_ARG(i, STRING, str);
- len = strcspn(str, ",");
+ len = strcspn(str, "|");
size += len;
if (str[len]) {
lcnt++;
@@ -74,7 +74,7 @@ MF_DEFUN_VARARGS(getopt, STRING, NUMBER argc, NUMBER argoff)
int val;
MF_VA_ARG(i, STRING, str);
- len = strcspn(str, ",");
+ len = strcspn(str, "|");
if (len > 0) {
memcpy(optstr + size, str, len);
@@ -108,14 +108,17 @@ MF_DEFUN_VARARGS(getopt, STRING, NUMBER argc, NUMBER argoff)
} else
option = NULL;
}
+
+ if (xargc == 0 || optstr == NULL || option == 0)
+ MF_RETURN_STRING("");
optind = (int) MF_VAR_REF(optind);
rc = getopt_long(xargc, xargv, optstr, option, &long_idx);
- if (rc == EOF)
- MF_RETURN_STRING("");
MF_VAR_REF(optind, optind);
MF_VAR_SET_STRING(optarg, optarg);
+ if (rc == EOF)
+ MF_RETURN_STRING("");
if (rc < 256) {
char s[2];
s[0] = rc;
diff --git a/mfd/drivers.c b/mfd/drivers.c
index 3e5df6f..3cff97b 100644
--- a/mfd/drivers.c
+++ b/mfd/drivers.c
@@ -1224,6 +1224,12 @@ print_type_argx(NODE *node, int level)
}
void
+mark_type_argx(NODE *node)
+{
+ mark(node->v.argx.node);
+}
+
+void
code_argxref(NODE *node)
{
code_op(opcode_push);
@@ -1267,6 +1273,12 @@ print_type_vaptr(NODE *node, int level)
}
void
+mark_type_vaptr(NODE *node)
+{
+ mark(node->v.node);
+}
+
+void
code_type_vaptr(NODE *node, struct locus **old_locus)
{
NODE *arg = node->v.node;
diff --git a/mfd/gram.y b/mfd/gram.y
index 2ec203a..6dfa159 100644
--- a/mfd/gram.y
+++ b/mfd/gram.y
@@ -3041,7 +3041,6 @@ mailfromd_run(prog_counter_t entry_point, int argc, char **argv)
int rc, i;
mu_assoc_t dict = NULL;
eval_environ_t env;
- sfsistat status;
dict_init(&dict);
env = create_environment(NULL,
@@ -3058,7 +3057,6 @@ mailfromd_run(prog_counter_t entry_point, int argc, char **argv)
env_make_frame0(env);
rc = eval_environment(env, entry_point);
- env_leave_frame(env, 0);
env_final_gc(env);
rc = (int) env_get_reg(env);
destroy_environment(env);
diff --git a/mfd/main.c b/mfd/main.c
index 284723b..02b6849 100644
--- a/mfd/main.c
+++ b/mfd/main.c
@@ -2003,12 +2003,16 @@ argpflag(int argc, char **argv)
{
int i;
int flag = 0;
- for (i = 0; i < argc; i++)
- if (strncmp(argv[i], "--run", 5) == 0
- && (argv[i][5] == 0 || argv[i][5] == '=')) {
+ for (i = 0; i < argc; i++) {
+ size_t len = strcspn(argv[i], "=");
+ if (len > 3
+ && (memcmp(argv[i], "--r", 3) == 0
+ || memcmp(argv[i], "--ru", 4) == 0
+ || memcmp(argv[i], "--run", 5) == 0)) {
flag = ARGP_IN_ORDER;
break;
}
+ }
return flag;
}
diff --git a/mfd/prog.c b/mfd/prog.c
index 8420a91..4a36307 100644
--- a/mfd/prog.c
+++ b/mfd/prog.c
@@ -319,7 +319,7 @@ env_base(eval_environ_t env, size_t frame)
char *
env_vaptr(eval_environ_t env, size_t off)
{
- return env->dataseg + (size_t) env->dataseg[off];
+ return (char*)(env->dataseg + (size_t) env->dataseg[off]);
}
void

Return to:

Send suggestions and report system problems to the System administrator.