* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
- * $Id: data1.h,v 1.10 2002-05-13 14:13:37 adam Exp $
+ * $Id: data1.h,v 1.11 2002-05-21 07:43:16 adam Exp $
*/
#ifndef DATA1_H
/* variant specification (a triple, actually) */
#define DATA1N_variant 4
int which;
-
+ /* comment (same as data) */
+#define DATA1N_comment 5
union
{
struct
YAZ_EXPORT data1_node *data1_mk_text (data1_handle dh, NMEM mem,
const char *buf, data1_node *parent);
+YAZ_EXPORT data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
+ const char *buf, size_t len,
+ data1_node *parent);
+
+YAZ_EXPORT data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
+ const char *buf, data1_node *parent);
+
YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem,
const char *name);
* Copyright (c) 2002, Index Data.
* See the file LICENSE for details.
*
- * $Id: d1_expat.c,v 1.1 2002-05-13 14:13:37 adam Exp $
+ * $Id: d1_expat.c,v 1.2 2002-05-21 07:43:16 adam Exp $
*/
#if HAVE_EXPAT_H
static void cb_start (void *user, const char *el, const char **attr)
{
struct user_info *ui = (struct user_info*) user;
- if (ui->level)
- {
- ui->d1_stack[ui->level] = data1_mk_tag (ui->dh, ui->nmem, el, attr,
+ ui->d1_stack[ui->level] = data1_mk_tag (ui->dh, ui->nmem, el, attr,
ui->d1_stack[ui->level-1]);
- }
- else
- {
- ui->d1_stack[0] = data1_mk_root (ui->dh, ui->nmem, el);
- }
ui->level++;
+ printf ("cb_start %s\n", el);
}
static void cb_end (void *user, const char *el)
struct user_info *ui = (struct user_info*) user;
ui->level--;
+ printf ("cb_end %s\n", el);
}
static void cb_chardata (void *user, const char *s, int len)
{
struct user_info *ui = (struct user_info*) user;
- ui->d1_stack[ui->level] = data1_mk_text_n (ui->dh, ui->nmem, s, len,
- ui->d1_stack[ui->level -1]);
+ int i;
+
+ for (i = 0; i<len; i++)
+ if (!strchr ("\n\n ", s[i]))
+ break;
+ if (i != len)
+ {
+ ui->d1_stack[ui->level] = data1_mk_text_n (ui->dh, ui->nmem, s, len,
+ ui->d1_stack[ui->level -1]);
+ }
+}
+
+static void cb_decl (void *user, const char *version, const char*encoding,
+ int standalone)
+{
+ printf ("decl version=%s encoding=%s\n", version ? version : "null",
+ encoding ? encoding : "null");
+}
+
+static void cb_processing (void *userData, const char *target,
+ const char *data)
+{
+ printf ("decl processing target=%s data=%s\n", target ? target : "null",
+ data ? data : "null");
+}
+
+static void cb_comment (void *userData, const char *data)
+{
+ printf ("decl comment data=%s\n", data ? data : "null");
+}
+
+static void cb_doctype_start (void *userData, const char *doctypeName,
+ const char *sysid, const char *pubid,
+ int has_internal_subset)
+{
+ printf ("doctype start doctype=%s sysid=%s pubid=%s\n",
+ doctypeName, sysid, pubid);
+}
+
+static void cb_doctype_end (void *userData)
+{
+ printf ("doctype end\n");
+}
+
+
+static void cb_entity_decl (void *userData, const char *entityName,
+ int is_parameter_entity,
+ const char *value, int value_length,
+ const char *base, const char *systemId,
+ const char *publicId, const char *notationName)
+{
+ printf ("entity %s is_para_entry=%d value=%.*s base=%s systemId=%s\n"
+ " publicId=%s notationName=%s\n",
+ entityName, is_parameter_entity, value_length, value,
+ base, systemId, publicId, notationName);
+
}
#define XML_CHUNK 1024
struct user_info uinfo;
int done = 0;
- uinfo.level = 0;
+ uinfo.level = 1;
uinfo.dh = dh;
- uinfo.d1_stack[0] = 0;
uinfo.nmem = m;
-
+ uinfo.d1_stack[0] = data1_mk_root (dh, m, "root");
+ uinfo.d1_stack[1] = 0; /* indicate no children (see end of routine) */
+
parser = XML_ParserCreate (0 /* encoding */);
XML_SetElementHandler (parser, cb_start, cb_end);
XML_SetCharacterDataHandler (parser, cb_chardata);
+ XML_SetXmlDeclHandler (parser, cb_decl);
+ XML_SetProcessingInstructionHandler (parser, cb_processing);
XML_SetUserData (parser, &uinfo);
+ XML_SetCommentHandler (parser, cb_comment);
+ XML_SetDoctypeDeclHandler (parser, cb_doctype_start, cb_doctype_end);
+ XML_SetEntityDeclHandler (parser, cb_entity_decl);
while (!done)
{
XML_ParseBuffer (parser, r, done);
}
XML_ParserFree (parser);
+ if (!uinfo.d1_stack[1])
+ return 0;
return uinfo.d1_stack[0];
}
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: d1_read.c,v 1.42 2002-05-13 14:13:37 adam Exp $
+ * $Id: d1_read.c,v 1.43 2002-05-21 07:43:16 adam Exp $
*/
#include <assert.h>
while (attr && *attr)
{
*p = (data1_xattr*) nmem_malloc (nmem, sizeof(**p));
- (*p)->name = nmem_strdup (nmem, attr[0]);
- (*p)->value = nmem_strdup (nmem, attr[1]);
+ (*p)->name = nmem_strdup (nmem, *attr++);
+ (*p)->value = nmem_strdup (nmem, *attr++);
p = &(*p)->next;
}
*p = 0;
return res;
}
-
data1_node *data1_mk_text (data1_handle dh, NMEM mem,
const char *buf, data1_node *parent)
{
return data1_mk_text_n (dh, mem, buf, strlen(buf), parent);
}
+data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
+ const char *buf, size_t len,
+ data1_node *parent)
+{
+ data1_node *res = data1_mk_node2 (dh, mem, DATA1N_comment, parent);
+ res->u.data.what = DATA1I_text;
+ res->u.data.len = len;
+
+ res->u.data.data = data1_insert_string_n (dh, res, mem, buf, len);
+ return res;
+}
+
+data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
+ const char *buf, data1_node *parent)
+{
+ return data1_mk_comment_n (dh, mem, buf, strlen(buf), parent);
+}
+
char *data1_insert_string_n (data1_handle dh, data1_node *res,
NMEM m, const char *str, size_t len)
{
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: d1_write.c,v 1.11 2002-05-13 14:13:37 adam Exp $
+ * $Id: d1_write.c,v 1.12 2002-05-21 07:43:16 adam Exp $
*/
#include <string.h>
wrbuf_write(b, line, strlen(line));
}
}
- else if (c->which == DATA1N_data)
+ else if (c->which == DATA1N_data || c->which == DATA1N_comment)
{
char *p = c->u.data.data;
int l = c->u.data.len;
int first = 1;
int lcol = col;
- sprintf(line, "%*s", col, "");
- wrbuf_write(b, line, strlen(line));
+ if (!c->u.data.formatted_text)
+ {
+ sprintf(line, "%*s", col, "");
+ wrbuf_write(b, line, strlen(line));
+ }
+ if (c->which == DATA1N_comment)
+ {
+ wrbuf_write (b, "<!--", 4);
+ }
switch (c->u.data.what)
{
case DATA1I_text:
- while (l)
- {
- int wlen;
-
- while (l && d1_isspace(*p))
- p++, l--;
- if (!l)
- break;
- /* break if we'll cross margin and word is not too long */
- if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN && wlen <
- IDSGML_MARGIN)
- {
- sprintf(line, "\n%*s", col, "");
- lcol = col;
- wrbuf_write(b, line, strlen(line));
- first = 1;
- }
- if (!first)
- {
- wrbuf_putc(b, ' ');
- lcol++;
- }
- while (l && !d1_isspace(*p))
- {
- wrbuf_putc(b, *p);
- p++;
- l--;
- lcol++;
- }
- first = 0;
- }
- wrbuf_write(b, "\n", 1);
+ if (c->u.data.formatted_text)
+ {
+ wrbuf_write (b, p, l);
+ }
+ else
+ {
+ while (l)
+ {
+ int wlen;
+
+ while (l && d1_isspace(*p))
+ p++, l--;
+ if (!l)
+ break;
+ /* break if we cross margin and word is not too long */
+ if (lcol + (wlen = wordlen(p, l)) > IDSGML_MARGIN &&
+ wlen < IDSGML_MARGIN)
+ {
+ sprintf(line, "\n%*s", col, "");
+ lcol = col;
+ wrbuf_write(b, line, strlen(line));
+ first = 1;
+ }
+ if (!first)
+ {
+ wrbuf_putc(b, ' ');
+ lcol++;
+ }
+ while (l && !d1_isspace(*p))
+ {
+ wrbuf_putc(b, *p);
+ p++;
+ l--;
+ lcol++;
+ }
+ first = 0;
+ }
+ wrbuf_write(b, "\n", 1);
+ }
break;
case DATA1I_num:
wrbuf_write(b, c->u.data.data, c->u.data.len);
case DATA1I_oid:
wrbuf_write(b, c->u.data.data, c->u.data.len);
}
+ if (c->which == DATA1N_comment)
+ {
+ wrbuf_write (b, "-->", 3);
+ }
}
}
return 0;