aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-06-21 09:56:11 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-06-21 09:56:11 +0000
commit13d89e6bc712dc43dbc1ba61c79612e51ba96470 (patch)
tree4eb4e494377b8e6f5b2b090c51c5f7c18853bbd0
parenta9a78104cef456d854e2797403f54c502435443e (diff)
downloadellinika-13d89e6bc712dc43dbc1ba61c79612e51ba96470.tar.gz
ellinika-13d89e6bc712dc43dbc1ba61c79612e51ba96470.tar.bz2
Use pending_links for resolving antonym and cross-reference links.
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@157 941c8c0f-9102-463b-b60b-cd22ce0e6858
-rw-r--r--src/main.c118
1 files changed, 41 insertions, 77 deletions
diff --git a/src/main.c b/src/main.c
index bd2f6f5..edbcef3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,6 +8,7 @@ char *sql_password;
char *sql_user;
int debug;
int compile_only;
+int cleanup_flag;
static int error_count;
static RAD_LIST *include_list;
static char *m4_bin = "/usr/bin/m4"; /* FIXME: Should be autoconf'ed */
@@ -66,9 +67,6 @@ create_node(RAD_LIST *hdr, RAD_LIST *descr)
static unsigned long dict_index;
static unsigned long article_index;
-static RAD_LIST *antonym_list;
-static RAD_LIST *xref_list;
-
int
_emit_headers(void *item, void *data)
{
@@ -88,36 +86,12 @@ _emit_headers(void *item, void *data)
return 0;
}
-int
-insert_antonym(unsigned long dict_index, u_char *value)
-{
- unsigned long index;
- if (sql_query_n(&index,
- "SELECT ident FROM dict WHERE word=\"%s\"",
- value) == 0) {
- sql_query("REPLACE INTO antonym VALUES (%lu,%lu)",
- index, dict_index);
- sql_query("REPLACE INTO antonym VALUES (%lu,%lu)",
- dict_index, index);
- return 0;
- }
- return 1;
-}
-
-int
-insert_xref(unsigned long dict_index, u_char *value)
+static void
+set_link(char *type, unsigned long dict_index, u_char *value)
{
- unsigned long index;
- if (sql_query_n(&index,
- "SELECT ident FROM dict WHERE word=\"%s\"",
- value) == 0) {
- sql_query("REPLACE INTO xref VALUES (%lu,%lu)",
- index, dict_index);
- sql_query("REPLACE INTO xref VALUES (%lu,%lu)",
- dict_index, index);
- return 0;
- }
- return 1;
+ sql_query("INSERT INTO pending_links (type,originator,word) "
+ "VALUES('%s',%lu,'%s')",
+ type, dict_index, value);
}
int
@@ -147,33 +121,16 @@ _emit_descr(void *item, void *data)
break;
case descr_antonym:
- if (insert_antonym(dict_index, descr->value)) {
- struct xref *p = emalloc(sizeof(*p));
- p->index = dict_index;
- p->value = descr->value;
- list_append(antonym_list, p);
- }
+ set_link("ANT", dict_index, descr->value);
break;
case descr_xref:
- if (insert_xref(dict_index, descr->value)) {
- struct xref *p = emalloc(sizeof(*p));
- p->index = dict_index;
- p->value = descr->value;
- list_append(xref_list, p);
- }
+ set_link("XREF", dict_index, descr->value);
break;
}
return 0;
}
-static int
-cmp_descr_type(const void *a, const void *b)
-{
- const struct descr *da = a, *db = b;
- return da->type != db->type;
-}
-
int
emit_node(void *item, void *data)
{
@@ -188,26 +145,31 @@ emit_node(void *item, void *data)
return 0;
}
-int
-_antonym_fixup(void *item, void *data)
-{
- struct xref *ant = item;
- if (insert_antonym(ant->index, ant->value)) {
- fprintf(stderr, "unresolved antonym: %lu - \"%s\"\n",
- ant->index, ant->value);
- }
- return 0;
-}
-int
-_xref_fixup(void *item, void *data)
+void
+pending_fixup()
{
- struct xref *ant = item;
- if (insert_xref(ant->index, ant->value)) {
- fprintf(stderr, "unresolved cross reference: %lu - \"%s\"\n",
- ant->index, ant->value);
- }
- return 0;
+ unsigned long val;
+
+ sql_query("INSERT IGNORE INTO links "
+ "SELECT p.type,p.originator,d.ident "
+ "FROM dict d, pending_links p "
+ "WHERE p.word = d.word AND p.type != 'CLOSED'");
+ sql_query("INSERT IGNORE INTO links "
+ "SELECT p.type,d.ident,p.originator "
+ "FROM dict d, pending_links p "
+ "WHERE p.word = d.word AND p.type != 'CLOSED'");
+ sql_query("UPDATE pending_links p, dict d SET p.type='CLOSED' "
+ "WHERE p.word = d.word");
+
+ if (cleanup_flag)
+ sql_query("DELETE FROM pending_links WHERE type = 'CLOSED'");
+
+ if (sql_query("SELECT count(*) FROM pending_links "
+ " WHERE type != 'CLOSED' "
+ " GROUP BY word") == 0)
+ fprintf (stderr, "%lu unresolved references\n",
+ sql_num_tuples());
}
@@ -231,11 +193,16 @@ main(int argc, char **argv)
{
int rc;
- while ((rc = getopt(argc, argv, "cd:h:I:m:P:p:u:v")) != EOF) {
+ while ((rc = getopt(argc, argv, "cCd:h:I:m:P:p:u:v")) != EOF) {
switch (rc) {
case 'c':
compile_only = 1;
break;
+
+ case 'C':
+ cleanup_flag = 1;
+ break;
+
case 'd':
sql_database = optarg;
break;
@@ -264,7 +231,8 @@ main(int argc, char **argv)
if (!include_list)
include_list = list_create();
list_append(include_list, optarg);
-
+ break;
+
case 'm':
m4_bin = optarg;
}
@@ -283,16 +251,12 @@ main(int argc, char **argv)
if (compile_only)
return 0;
- antonym_list = list_create();
- xref_list = list_create();
-
sql_query_n(&dict_index,
"SELECT ident FROM dict ORDER BY ident DESC LIMIT 1");
list_iterate(node_list, emit_node, NULL);
-
- list_iterate(antonym_list, _antonym_fixup, NULL);
- list_iterate(xref_list, _xref_fixup, NULL);
+
+ pending_fixup();
update_stat();

Return to:

Send suggestions and report system problems to the System administrator.