Ejemplo n.º 1
0
static void *start_element_handler(expat_parser *parser_data, const XML_Char *name, const XML_Char **atts)
{
    ErlNifBinary element_name;
    ERL_NIF_TERM attrs_list = enif_make_list(parser_data->env, 0);
    int i;

    element_name = encode_name(parser_data, name);
    for(i = 0; atts[i]; i += 2);
    while(i)
        {
            ErlNifBinary attr_name, attr_value;

            enif_alloc_binary(strlen(atts[i-1]), &attr_value);
            strcpy((char *) attr_value.data, (const char *)atts[i-1]);
            attr_name = encode_name(parser_data, atts[i-2]);

            ERL_NIF_TERM attr = enif_make_tuple(parser_data->env, 2,
                                                enif_make_binary(parser_data->env, &attr_name),
                                                enif_make_binary(parser_data->env, &attr_value));
            attrs_list = enif_make_list_cell(parser_data->env, attr, attrs_list);

            i -= 2;
        };

    if(parser_data->xmlns)
        attrs_list = enif_make_list_cell(parser_data->env, parser_data->xmlns, attrs_list);
    parser_data->xmlns = (ERL_NIF_TERM)NULL;

    ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 3, XML_ELEMENT_START,
                                         enif_make_binary(parser_data->env, &element_name),
                                         attrs_list);
    parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);

    return NULL;
};
Ejemplo n.º 2
0
static void *start_element_handler(expat_parser *parser_data, const XML_Char *name, const XML_Char **atts)
{
    ERL_NIF_TERM element_name;
    ERL_NIF_TERM attrs_list = enif_make_list(parser_data->env, 0);
    int i;

    element_name = encode_name(parser_data, name);
    for(i = 0; atts[i]; i += 2);
    while(i)
    {
        ERL_NIF_TERM attr_name, attr_value;

        size_t atts_len = strlen(atts[i-1]);
        unsigned char *attr_data = enif_make_new_binary(parser_data->env, atts_len, &attr_value);
        strncpy((char*)attr_data, (const char *)atts[i-1], atts_len);
        attr_name = encode_name(parser_data, atts[i-2]);

        ERL_NIF_TERM attr = enif_make_tuple(parser_data->env, 2, attr_name, attr_value);
        attrs_list = enif_make_list_cell(parser_data->env, attr, attrs_list);

        i -= 2;
    };


    ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 4, XML_ELEMENT_START,
                                         element_name,
                                         parser_data->xmlns,
                                         attrs_list);
    parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);
    parser_data->xmlns = enif_make_list(parser_data->env, 0);

    return NULL;
};
Ejemplo n.º 3
0
void *erlXML_StartElementHandler(expat_data *d,
				 const XML_Char *name,
				 const XML_Char **atts)
{
   int i;

   ei_x_encode_list_header(&event_buf, 1);
   ei_x_encode_tuple_header(&event_buf, 2);
   ei_x_encode_long(&event_buf, XML_START);
   ei_x_encode_tuple_header(&event_buf, 2);
   encode_name(name);
   ei_x_append(&event_buf, &xmlns_buf);
   ei_x_free(&xmlns_buf);
   ei_x_new(&xmlns_buf);

   for (i = 0; atts[i]; i += 2) {}

   if (i > 0)
   {
      ei_x_encode_list_header(&event_buf, i/2);

      for (i = 0; atts[i]; i += 2)
      {
	 ei_x_encode_tuple_header(&event_buf, 2);
	 encode_name(atts[i]);
	 ei_x_encode_binary(&event_buf, atts[i+1], strlen(atts[i+1]));
      }
   }

   ei_x_encode_empty_list(&event_buf);

   return NULL;
}
Ejemplo n.º 4
0
void *erlXML_EndElementHandler(expat_data *d,
			       const XML_Char *name)
{
   ei_x_encode_list_header(&event_buf, 1);
   ei_x_encode_tuple_header(&event_buf, 2);
   ei_x_encode_long(&event_buf, XML_END);
   encode_name(name);
   return NULL;
}
Ejemplo n.º 5
0
static void *end_element_handler(expat_parser *parser_data, const XML_Char *name)
{
    ERL_NIF_TERM element_name = encode_name(parser_data, name);

    ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 2, XML_ELEMENT_END, element_name);
    parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);

    return NULL;
};
/* Write the mount table entry described by MNT to a string.
   Return zero on success, nonzero on failure.  */
int
__addmntentstr (char *str, const struct mntent *mnt)
{
  struct mntent mntcopy = *mnt;
  /* Encode spaces and tabs in the names.  */
  encode_name (mntcopy.mnt_fsname);
  encode_name (mntcopy.mnt_dir);
  encode_name (mntcopy.mnt_type);
  encode_name (mntcopy.mnt_opts);

  return (sprintf (str, "%s %s %s %s %d %d\n",
		   mntcopy.mnt_fsname,
		   mntcopy.mnt_dir,
		   mntcopy.mnt_type,
		   mntcopy.mnt_opts,
		   mntcopy.mnt_freq,
		   mntcopy.mnt_passno)
	  < 0 ? 1 : 0);
}
Ejemplo n.º 7
0
/* Write the mount table entry described by MNT to STREAM.
   Return zero on success, nonzero on failure.  */
int addmntent (FILE *stream, const struct mntent *mnt)
{
  struct mntent mntcopy = *mnt;
  if (fseek (stream, 0, SEEK_END))
    return 1;

  /* Encode spaces and tabs in the names.  */
  encode_name (mntcopy.mnt_fsname);
  encode_name (mntcopy.mnt_dir);
  encode_name (mntcopy.mnt_type);
  encode_name (mntcopy.mnt_opts);

  return (fprintf (stream, "%s %s %s %s %d %d\n",
		   mntcopy.mnt_fsname,
		   mntcopy.mnt_dir,
		   mntcopy.mnt_type,
		   mntcopy.mnt_opts,
		   mntcopy.mnt_freq,
		   mntcopy.mnt_passno) < 0
	  || fflush (stream) != 0);
}
Ejemplo n.º 8
0
static void
dump_deps(_jc_splay_tree *tree, _jc_splay_node *node, int flags)
{
	_jc_dep *const dep = _JC_NODE2ITEM(tree, node);

	/* Sanity check */
	if (node == NULL)
		return;

	/* Do left subtree */
	dump_deps(tree, node->left, flags);

	/* Print this class */
	printf("%s\n", (flags & DUMP_ENCODE_NAMES) != 0 ?
	    encode_name(dep->ref.name) : dep->ref.name);

	/* Do right subtree */
	dump_deps(tree, node->right, flags);
}