/* XEmacs routines to deal with CONCORD.
- Copyright (C) 2005,2006 MORIOKA Tomohiko
+ Copyright (C) 2005,2006,2008,2010 MORIOKA Tomohiko
This file is part of XEmacs.
#include "sysfile.h"
#include "buffer.h"
#include <errno.h>
-#include <concord.h>
+#include "elconcord.h"
+#ifdef HAVE_LIBCHISE
+# include <chise.h>
+#endif
EXFUN (Fread_from_string, 3);
-EXFUN (Fconcord_decode_object, 4);
-EXFUN (Fconcord_object_put, 3);
-EXFUN (Fconcord_object_get, 2);
-
Lisp_Object Qconcord;
Lisp_Object Qconcord_object;
Lisp_Object Qgenre, Q_id;
+#ifdef HAVE_LIBCHISE
+Lisp_Object Qcharacter;
+Lisp_Object Qfeature;
+#endif
Lisp_Object Vconcord_ds_hash_table;
Lisp_Object Vconcord_genre_hash_table;
Lisp_Object Vconcord_genre_object_hash_table;
-typedef struct Lisp_CONCORD_DS Lisp_CONCORD_DS;
-DECLARE_LRECORD (concord_ds, Lisp_CONCORD_DS);
+/*
+ * data source
+ */
Lisp_Object Qconcord_dsp;
-struct Lisp_CONCORD_DS
-{
- struct lcrecord_header header;
- CONCORD_DS ds;
-};
-
-#define XCONCORD_DS(x) XRECORD (x, concord_ds, Lisp_CONCORD_DS)
-#define XSET_CONCORD_DS(x, p) XSETRECORD (x, p, concord_ds)
-#define CONCORD_DS_P(x) RECORDP (x, concord_ds)
-#define CHECK_CONCORD_DS(x) CHECK_RECORD (x, concord_ds)
-#define CONCHECK_CONCORD_DS(x) CONCHECK_RECORD (x, concord_ds)
-
static Lisp_CONCORD_DS*
allocate_concord_ds (void)
{
CHECK_SYMBOL (genre);
retval = Fgethash (genre, Vconcord_genre_hash_table, Qunbound);
+#ifdef HAVE_LIBCHISE
+ if ( UNBOUNDP (retval) )
+ retval = Vchise_system_db_directory;
+#endif
if ( STRINGP (retval) )
{
retval = Fconcord_open_ds (retval, Qnil, Qnil, Qnil);
}
-typedef struct Lisp_CONCORD_Object Lisp_CONCORD_Object;
-DECLARE_LRECORD (concord_object, Lisp_CONCORD_Object);
+/*
+ * Concord-object
+ */
Lisp_Object Qconcord_objectp;
-struct Lisp_CONCORD_Object
-{
- struct lcrecord_header header;
- CONCORD_Genre genre;
- Lisp_Object id;
-};
-
-#define XCONCORD_OBJECT(x) XRECORD (x, concord_object, Lisp_CONCORD_Object)
-#define XSET_CONCORD_OBJECT(x, p) XSETRECORD (x, p, concord_object)
-#define CONCORD_OBJECT_P(x) RECORDP (x, concord_object)
-#define CHECK_CONCORD_OBJECT(x) CHECK_RECORD (x, concord_object)
-#define CONCHECK_CONCORD_OBJECT(x) CONCHECK_RECORD (x, concord_object)
-#define CONCORD_OBJECT_GENRE(x) ((x)->genre)
-#define CONCORD_OBJECT_ID(x) ((x)->id)
-#define XCONCORD_OBJECT_ID(x) CONCORD_OBJECT_ID (XCONCORD_OBJECT(x))
-#define XCONCORD_OBJECT_GENRE(x) CONCORD_OBJECT_GENRE (XCONCORD_OBJECT(x))
-
static Lisp_CONCORD_Object*
allocate_concord_object (void)
{
Lisp_CONCORD_Object* lcobj = XCONCORD_OBJECT (obj);
struct gcpro gcpro1, gcpro2;
- if (print_readably)
+#if 0
+ if ( print_readably )
{
+#endif
write_c_string ("#s(concord-object", printcharfun);
write_c_string (" genre ", printcharfun);
write_c_string (concord_genre_get_name (lcobj->genre), printcharfun);
print_internal (lcobj->id, printcharfun, escapeflag);
UNGCPRO;
write_c_string (")", printcharfun);
+#if 0
}
else
{
write_c_string ("#<concord-object \"", printcharfun);
- write_c_string (concord_ds_location
- (concord_genre_get_data_source (lcobj->genre)),
- printcharfun);
- write_c_string (":", printcharfun);
write_c_string (concord_genre_get_name (lcobj->genre), printcharfun);
write_c_string (";", printcharfun);
GCPRO2 (obj, printcharfun);
UNGCPRO;
write_c_string ("\">", printcharfun);
}
+#endif
}
static void
}
}
+static int
+concord_object_equal (Lisp_Object cobj1, Lisp_Object cobj2, int depth)
+{
+ return internal_equal ( XCONCORD_OBJECT_ID(cobj1),
+ XCONCORD_OBJECT_ID(cobj2), depth);
+}
+
static const struct lrecord_description concord_object_description[] = {
{ XD_LISP_OBJECT, offsetof (Lisp_CONCORD_Object, id) },
{ XD_END }
DEFINE_LRECORD_IMPLEMENTATION ("concord_object", concord_object,
mark_concord_object, print_concord_object,
- finalize_concord_object, 0, 0,
+ finalize_concord_object,
+ concord_object_equal, 0,
concord_object_description,
Lisp_CONCORD_Object);
return XCONCORD_OBJECT_ID (object);
}
+DEFUN ("concord-object-genre", Fconcord_object_genre, 1, 1, 0, /*
+Return genre of Concord-object OBJECT.
+*/
+ (object))
+{
+ CHECK_CONCORD_OBJECT (object);
+ return intern (concord_genre_get_name (XCONCORD_OBJECT_GENRE (object)));
+}
+
DEFUN ("concord-decode-object", Fconcord_decode_object, 2, 4, 0, /*
Make and return a Concord-object from FEATURE and VALUE.
Optional argument GENRE specifies the GENRE of the object.
Bufbyte *name_str;
CHECK_CONCORD_OBJECT (object);
+ CHECK_SYMBOL (feature);
name = symbol_name (XSYMBOL (feature));
name_str = string_data (name);
if ( NILP (concord_object_put (object, feature, value)) )
ffv = Fconcord_object_get (ret, rev_feature);
if (!CONSP (ffv))
concord_object_put (ret, rev_feature, list1 (object));
- else if (NILP (Fmemq (object, ffv)))
+ else if (NILP (Fmember (object, ffv)))
concord_object_put
(ret, rev_feature,
nconc2 (Fcopy_sequence (ffv), list1 (object)));
return Qt;
}
+DEFUN ("concord-object-adjoin", Fconcord_object_adjoin, 3, 3, 0, /*
+Cons ITEM onto the front of FEATURE's value of OBJECT only if it's not already there.
+*/
+ (object, feature, item))
+{
+ Lisp_Object ret = Fconcord_object_get (object, feature);
+
+ if ( NILP (Fmember (item, ret)) )
+ return Fconcord_object_put (object, feature, Fcons (item, ret));
+ return Qnil;
+}
+
+DEFUN ("concord-object-adjoin*", Fconcord_object_adjoinX, 3, 3, 0, /*
+Append ITEM onto the end of FEATURE's value of OBJECT only if it's not already there.
+*/
+ (object, feature, item))
+{
+ Lisp_Object ret = Fconcord_object_get (object, feature);
+
+ if ( NILP (Fmember (item, ret)) )
+ return Fconcord_object_put (object, feature, nconc2 (ret, list1 (item)));
+ return Qnil;
+}
+
struct closure_for_object_spec
{
char* object_id;
CONCORD_Feature feature,
CONCORD_String value)
{
- struct gcpro gcpro1, gcpro2, gcpro3;
+ struct gcpro gcpro1, gcpro2;
Lisp_Object obj, val, ret;
#if 0
obj = Fconcord_make_object (for_each_object_closure->genre,
obj,
for_each_object_closure->ds);
- UNGCPRO;
#if 0
val = read_from_c_string (CONCORD_String_data (value),
CONCORD_String_size (value) );
Qfile_name),
Qnil, Qnil));
#endif
- GCPRO3 (obj, val, ret);
+ UNGCPRO;
+ GCPRO2 (obj, val);
ret = call2 (for_each_object_closure->function, obj, val);
UNGCPRO;
for_each_object_closure->ret = ret;
}
static int
+concord_id_validate (Lisp_Object keyword, Lisp_Object value,
+ Error_behavior errb)
+{
+ if (ERRB_EQ (errb, ERROR_ME))
+ {
+ /* CHECK_SYMBOL (value); */
+ if ( INTP (value) || CHARP (value) || SYMBOLP (value) )
+ ;
+ else
+ dead_wrong_type_argument (Qsymbolp, value);
+ return 1;
+ }
+
+ return INTP (value) || CHARP (value) || SYMBOLP (value);
+}
+
+static int
concord_object_validate (Lisp_Object data, Error_behavior errb)
{
struct gcpro gcpro1, gcpro2, gcpro3;
defsymbol (&Qconcord_object, "concord-object");
defsymbol (&Qgenre, "genre");
defsymbol (&Q_id, "=id");
+#ifdef HAVE_LIBCHISE
+ defsymbol (&Qcharacter, "character");
+ defsymbol (&Qfeature, "feature");
+#endif
DEFSUBR (Fconcord_open_ds);
DEFSUBR (Fconcord_ds_p);
DEFSUBR (Fconcord_make_object);
DEFSUBR (Fconcord_object_p);
DEFSUBR (Fconcord_object_id);
+ DEFSUBR (Fconcord_object_genre);
DEFSUBR (Fconcord_decode_object);
DEFSUBR (Fconcord_object_get);
DEFSUBR (Fconcord_object_put);
+ DEFSUBR (Fconcord_object_adjoin);
+ DEFSUBR (Fconcord_object_adjoinX);
DEFSUBR (Fconcord_define_object);
DEFSUBR (Fconcord_object_spec);
DEFSUBR (Fconcord_foreach_object_in_feature);
concord_object_instantiate);
define_structure_type_keyword (st, Qgenre, concord_name_validate);
- define_structure_type_keyword (st, Q_id, concord_name_validate);
+ define_structure_type_keyword (st, Q_id, concord_id_validate);
}
void
Vconcord_genre_object_hash_table
= make_lisp_hash_table (16, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
}
+
+void
+complex_vars_of_concord (void)
+{
+#ifdef HAVE_LIBCHISE
+ Fconcord_assign_genre (Qcharacter, Vchise_system_db_directory);
+ Fconcord_assign_genre (Qfeature, Vchise_system_db_directory);
+#endif
+}