Ejemplo n.º 1
0
static long media_device_setup_link(struct media_device *mdev,
				    struct media_link_desc __user *_ulink)
{
	struct media_link *link = NULL;
	struct media_link_desc ulink;
	struct media_entity *source;
	struct media_entity *sink;
	int ret;

	if (copy_from_user(&ulink, _ulink, sizeof(ulink)))
		return -EFAULT;

	source = find_entity(mdev, ulink.source.entity);
	sink = find_entity(mdev, ulink.sink.entity);

	if (source == NULL || sink == NULL)
		return -EINVAL;

	if (ulink.source.index >= source->num_pads ||
	    ulink.sink.index >= sink->num_pads)
		return -EINVAL;

	link = media_entity_find_link(&source->pads[ulink.source.index],
				      &sink->pads[ulink.sink.index]);
	if (link == NULL)
		return -EINVAL;

	
	ret = __media_entity_setup_link(link, ulink.flags);

	if (copy_to_user(_ulink, &ulink, sizeof(ulink)))
		return -EFAULT;

	return ret;
}
Ejemplo n.º 2
0
static void
force_local_option(xmlNode *xml, const char *attr_name, const char *attr_value)
{
    int max = 0;
    int lpc = 0;
    char *xpath_string = NULL;
    xmlXPathObjectPtr xpathObj = NULL;

    xpath_string = crm_strdup_printf("%.128s//%s//nvpair[@name='%.128s']",
                                     get_object_path(XML_CIB_TAG_CRMCONFIG),
                                     XML_CIB_TAG_PROPSET, attr_name);
    xpathObj = xpath_search(xml, xpath_string);
    max = numXpathResults(xpathObj);
    free(xpath_string);

    for (lpc = 0; lpc < max; lpc++) {
        xmlNode *match = getXpathResult(xpathObj, lpc);
        crm_trace("Forcing %s/%s = %s", ID(match), attr_name, attr_value);
        crm_xml_add(match, XML_NVPAIR_ATTR_VALUE, attr_value);
    }

    if(max == 0) {
        xmlNode *configuration = NULL;
        xmlNode *crm_config = NULL;
        xmlNode *cluster_property_set = NULL;

        crm_trace("Creating %s-%s for %s=%s",
                  CIB_OPTIONS_FIRST, attr_name, attr_name, attr_value);

        configuration = find_entity(xml, XML_CIB_TAG_CONFIGURATION, NULL);
        if (configuration == NULL) {
            configuration = create_xml_node(xml, XML_CIB_TAG_CONFIGURATION);
        }

        crm_config = find_entity(configuration, XML_CIB_TAG_CRMCONFIG, NULL);
        if (crm_config == NULL) {
            crm_config = create_xml_node(configuration, XML_CIB_TAG_CRMCONFIG);
        }

        cluster_property_set = find_entity(crm_config, XML_CIB_TAG_PROPSET, NULL);
        if (cluster_property_set == NULL) {
            cluster_property_set = create_xml_node(crm_config, XML_CIB_TAG_PROPSET);
            crm_xml_add(cluster_property_set, XML_ATTR_ID, CIB_OPTIONS_FIRST);
        }

        xml = create_xml_node(cluster_property_set, XML_CIB_TAG_NVPAIR);

        crm_xml_set_id(xml, "%s-%s", CIB_OPTIONS_FIRST, attr_name);
        crm_xml_add(xml, XML_NVPAIR_ATTR_NAME, attr_name);
        crm_xml_add(xml, XML_NVPAIR_ATTR_VALUE, attr_value);
    }
    freeXpathObject(xpathObj);
}
Ejemplo n.º 3
0
/* result must be freed with free */
static char *folder_request_friendly_name(struct folder *folder)
{
	int ret;
	const char *adjective;
	const char *name;
	char *friendly_name = NULL;
	unsigned max_names = rs_dll_get_count(&folders_names) *
				rs_dll_get_count(&folders_adjectives);

	errno = 0;
	if (rs_dll_get_count(&folder->entities) > max_names) {
		ULOGC("more than %u entities in folder %s, weird...", max_names,
				folder->name);
		errno = ENOMEM;
		return NULL;
	}

	do {
		adjective = pick_random_word(&folders_adjectives);
		name = pick_random_word(&folders_names);
		ut_string_free(&friendly_name); /* in case we loop */
		ret = asprintf(&friendly_name, "%s_%s", adjective, name);
		if (ret < 0) {
			ULOGE("asprintf error");
			errno = ENOMEM;
			return NULL;
		}
	} while (find_entity(folder, friendly_name) != NULL);

	return friendly_name;
}
Ejemplo n.º 4
0
int folder_store(const char *folder_name, struct folder_entity *entity)
{
	struct folder_entity *needle;
	struct folder *folder;

	ULOGD("%s(%s, %p)", __func__, folder_name, entity);

	folder = folder_find(folder_name);
	if (folder == NULL)
		return -ENOENT;
	entity->folder = folder;

	needle = find_entity(folder, folder_entity_get_sha1(entity));
	if (needle != NULL) {
		ULOGE("entity %s already exists",
				folder_entity_get_sha1(entity));
		return -EEXIST;
	}

	rs_dll_push(&folder->entities, &entity->node);

	/* must be done after stored, because it's _drop which frees it */
	ut_string_free(&entity->name);
	entity->name = folder_request_friendly_name(folder);
	if (entity->name == NULL)
		return -errno;

	return 0;
}
Ejemplo n.º 5
0
/* parse an entity or a normal char (only ASCII chars are expected) */
static int parse_entity(const char **pp)
{
    const char *p, *p1;
    char name[16], *q;
    int ch, ch1;

    p = *pp;
    ch = *p++;
    if (ch == '&') {
        p1 = p;
        q = name;
        for (;;) {
            ch1 = *p;
            if (ch1 == '\0')
                break;
            p++;
            if (ch1 == ';')
                break;
            *q++ = ch1;
            if (q >= name + sizeof(name) - 1)
                break;
        }
        *q = '\0';
        ch1 = find_entity(name);
        if (ch1 >= 0) {
            ch = ch1;
        } else {
            p = p1;
        }
    }
    *pp = p;
    return ch;
}
int			req_select_attack(t_engine *e, t_trame *trame, int src)
{
  t_game_select_attack	game;
  t_entity		*attacked;
  t_req_select_attack	req;
  int		i;

  if (trame->len != sizeof(game))
    {
      fprintf(stderr, "ERROR: req_select_attack: failed\n");
      return (1);
    }
  memcpy(&game, trame->msg, sizeof(game));
  req.id_req = game.id_req;
  attacked = find_entity(e, game.id_attacked);
  if (!attacked || !e->select[0][src])
    {
      fprintf(stderr, "ERROR: req_select_attack: failed\n");
      req.id_action = -1;
    }
  for (i = 0; i < FW_MAX_SELECT && e->select[i][src]; i++)
    if (src == e->select[i][src]->app)
      req.id_action = create_action(e, e->select[i][src], attacked);
  stock_msg(e->players[src].client,
	    TAG_SELECT_ATTACK_REPLY, sizeof(req), &req);
  return (0);
}
Ejemplo n.º 7
0
static long media_device_enum_entities(struct media_device *mdev,
				       struct media_entity_desc __user *uent)
{
	struct media_entity *ent;
	struct media_entity_desc u_ent;

	memset(&u_ent, 0, sizeof(u_ent));
	if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
		return -EFAULT;

	ent = find_entity(mdev, u_ent.id);

	if (ent == NULL)
		return -EINVAL;

	u_ent.id = ent->id;
	u_ent.name[0] = '\0';
	if (ent->name)
		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
	u_ent.type = ent->type;
	u_ent.revision = ent->revision;
	u_ent.flags = ent->flags;
	u_ent.group_id = ent->group_id;
	u_ent.pads = ent->num_pads;
	u_ent.links = ent->num_links - ent->num_backlinks;
	memcpy(&u_ent.raw, &ent->info, sizeof(ent->info));
	if (copy_to_user(uent, &u_ent, sizeof(u_ent)))
		return -EFAULT;
	return 0;
}
Ejemplo n.º 8
0
static int
delete_cib_object(xmlNode * parent, xmlNode * delete_spec)
{
    const char *object_name = NULL;
    const char *object_id = NULL;
    xmlNode *equiv_node = NULL;
    int result = pcmk_ok;

    if (delete_spec != NULL) {
        object_name = crm_element_name(delete_spec);
    }
    object_id = crm_element_value(delete_spec, XML_ATTR_ID);

    crm_trace("Processing: <%s id=%s>", crm_str(object_name), crm_str(object_id));

    if (delete_spec == NULL) {
        result = -EINVAL;

    } else if (parent == NULL) {
        result = -EINVAL;

    } else if (object_id == NULL) {
        /*  placeholder object */
        equiv_node = find_xml_node(parent, object_name, FALSE);

    } else {
        equiv_node = find_entity(parent, object_name, object_id);
    }

    if (result != pcmk_ok) {
        ;                       /* nothing */

    } else if (equiv_node == NULL) {
        result = pcmk_ok;

    } else if (xml_has_children(delete_spec) == FALSE) {
        /*  only leaves are deleted */
        crm_debug("Removing leaf: <%s id=%s>", crm_str(object_name), crm_str(object_id));
        free_xml(equiv_node);
        equiv_node = NULL;

    } else {
        xmlNode *child = NULL;

        for (child = __xml_first_child(delete_spec); child != NULL; child = __xml_next(child)) {
            int tmp_result = delete_cib_object(equiv_node, child);

            /*  only the first error is likely to be interesting */
            if (tmp_result != pcmk_ok && result == pcmk_ok) {
                result = tmp_result;
            }
        }
    }

    return result;
}
Ejemplo n.º 9
0
char *folder_get_info(const char *folder_name,
		const char *entity_identifier)
{
	int ret;
	char *info = NULL;
	char *old_info = NULL;
	char *value = NULL;
	const struct folder *folder;
	struct folder_entity *entity;
	struct rs_node *node = NULL;
	struct folder_property *property;

	errno = 0;
	if (ut_string_is_invalid(folder_name) ||
			ut_string_is_invalid(entity_identifier)) {
		errno = EINVAL;
		return NULL;
	}

	folder = folder_find(folder_name);
	if (folder == NULL) {
		errno = ENOENT;
		return NULL;
	}

	entity = find_entity(folder, entity_identifier);
	if (entity == NULL)
		return NULL;

	while ((node = rs_dll_next_from(&folder->properties, node)) != NULL) {
		property = to_property(node);
		ret = property_get(property, entity, &value);
		if (ret < 0) {
			ut_string_free(&info);
			ULOGE("property_get: %s", strerror(-ret));
			errno = -ret;
			return NULL;
		}
		old_info = info;
		ret = asprintf(&info, "%s%s: %s\n", info ? info : "",
				property->name, value);
		ut_string_free(&value);
		ut_string_free(&old_info);
		if (ret < 0) {
			info = NULL;
			ULOGE("asprintf error");
			errno = -ENOMEM;
			return NULL;
		}
	}

	return info == NULL ? strdup("") : info;
}
Ejemplo n.º 10
0
	/****************************************************************
	 * cli_present:
	 ****************************************************************/
int   cli_present(		/* Return: status			*/
    void  *entity		/* <r> entity name: dsc or c-string	*/
   )
   {
    char  entityString[128];
    struct cduEntity  *e;

    if (!currentSyntax)
        return(CLI_STS_IVREQTYP);

    make_entityString(entity,entityString,sizeof(entityString));

    e = find_entity(entityString,(void *)currentParameters);
    if (!e)
        e=find_entity(entityString,(void *)currentQualifiers);

    if (!e || !e->entL_status)
        return(CLI_STS_ABSENT);

    return(e->entL_status);
   }
Ejemplo n.º 11
0
tlp::node& ib::tulip_fabric_t::get_entity_node(const ib::guid_t& guid)
{
  entities_t::iterator entityitr = find_entity(guid);
  if(entityitr == entities.end()) abort();
  
  entity_nodes_t::iterator itr = entity_nodes.find(&entityitr->second);
  if(itr != entity_nodes.end())
    return itr->second;
  
  ///should not happen!
  assert(itr != entity_nodes.end());
  abort();
}
Ejemplo n.º 12
0
static long media_device_enum_links(struct media_device *mdev,
				    struct media_links_enum __user *ulinks)
{
	struct media_entity *entity;
	struct media_links_enum links;

	if (copy_from_user(&links, ulinks, sizeof(links)))
		return -EFAULT;

	entity = find_entity(mdev, links.entity);
	if (entity == NULL)
		return -EINVAL;

	if (links.pads) {
		unsigned int p;

		for (p = 0; p < entity->num_pads; p++) {
			//<2014/05/28 EricLin, Security Incident.
			struct media_pad_desc pad = {0};
			//>2014/05/28 EricLin
			media_device_kpad_to_upad(&entity->pads[p], &pad);
			if (copy_to_user(&links.pads[p], &pad, sizeof(pad)))
				return -EFAULT;
		}
	}

	if (links.links) {
		struct media_link_desc __user *ulink;
		unsigned int l;

		for (l = 0, ulink = links.links; l < entity->num_links; l++) {
			struct media_link_desc link;

			/* Ignore backlinks. */
			if (entity->links[l].source->entity != entity)
				continue;

			media_device_kpad_to_upad(entity->links[l].source,
						  &link.source);
			media_device_kpad_to_upad(entity->links[l].sink,
						  &link.sink);
			link.flags = entity->links[l].flags;
			if (copy_to_user(ulink, &link, sizeof(*ulink)))
				return -EFAULT;
			ulink++;
		}
	}
	if (copy_to_user(ulinks, &links, sizeof(*ulinks)))
		return -EFAULT;
	return 0;
}
Ejemplo n.º 13
0
static size_t
unescape_ent(struct buf *ob, const char *src, size_t size)
{
	size_t i = 0;

	if (size > 3 && src[0] == '#') {
		int codepoint = 0;

		if (isdigit(src[1])) {
			for (i = 1; i < size && isdigit(src[i]); ++i)
				codepoint = (codepoint * 10) + (src[i] - '0');
		}

		else if (src[1] == 'x' || src[1] == 'X') {
			for (i = 2; i < size && isxdigit(src[i]); ++i)
				codepoint = (codepoint * 16) + ((src[i] | 32) % 39 - 9);
		}

		if (i < size && src[i] == ';') {
			bufput_utf8(ob, codepoint);
			return i + 1;
		}
	}

	else {
		if (size > MAX_WORD_LENGTH)
			size = MAX_WORD_LENGTH;

		for (i = MIN_WORD_LENGTH; i < size; ++i) {
			if (src[i] == ' ')
				break;

			if (src[i] == ';') {
				const struct html_ent *entity = 
					find_entity(src, i);

				if (entity != NULL) {
					bufput(ob, entity->utf8, entity->utf8_len);
					return i + 1;
				}

				break;
			}
		}
	}

	bufputc(ob, '&');
	return 0;
}
static long __media_device_enum_links(struct media_device *mdev,
				      struct media_links_enum *links)
{
	struct media_entity *entity;

	entity = find_entity(mdev, links->entity);
	if (entity == NULL)
		return -EINVAL;

	if (links->pads) {
		unsigned int p;

		for (p = 0; p < entity->num_pads; p++) {
			struct media_pad_desc pad;

			memset(&pad, 0, sizeof(pad));
			media_device_kpad_to_upad(&entity->pads[p], &pad);
			if (copy_to_user(&links->pads[p], &pad, sizeof(pad)))
				return -EFAULT;
		}
	}

	if (links->links) {
		struct media_link_desc __user *ulink;
		unsigned int l;

		for (l = 0, ulink = links->links; l < entity->num_links; l++) {
			struct media_link_desc link;

			
			if (entity->links[l].source->entity != entity)
				continue;

			memset(&link, 0, sizeof(link));
			media_device_kpad_to_upad(entity->links[l].source,
						  &link.source);
			media_device_kpad_to_upad(entity->links[l].sink,
						  &link.sink);
			link.flags = entity->links[l].flags;
			if (copy_to_user(ulink, &link, sizeof(*ulink)))
				return -EFAULT;
			ulink++;
		}
	}

	return 0;
}
Ejemplo n.º 15
0
static size_t unescape_entity(lanli_buffer *ob, const uint8_t *data, size_t size) {
  size_t i = 0;

  if (size > 3 && data[0] == '#') {
    int codepoint = 0;

    if (_isdigit(data[1])) {
      for (i = 1; i < size && _isdigit(data[i]); ++i)
        codepoint = (codepoint * 10) + (data[i] - '0');
    }

    else if (data[1] == 'x' || data[1] == 'X') {
      for (i = 2; i < size && _isxdigit(data[i]); ++i)
        codepoint = (codepoint * 16) + ((data[i] | 32) % 39 - 9);
      if (i == 2) return 0;
    }

    if (i < size && data[i] == ';') {
      lanli_buffer_put_utf8(ob, codepoint);
      return i + 1;
    }
  }

  else {
    if (size > MAX_WORD_LENGTH)
      size = MAX_WORD_LENGTH;

    for (i = MIN_WORD_LENGTH; i < size; ++i) {
      if (data[i] == ' ')
        break;

      if (data[i] == ';') {
        const struct html_entity *entity = find_entity((const char *)data, i);

        if (entity != NULL) {
          lanli_buffer_put(ob, entity->utf8, entity->size);
          return i + 1;
        }

        break;
      }
    }
  }

  lanli_buffer_putc(ob, '&');
  return 0;
}
Ejemplo n.º 16
0
static int
add_cib_object(xmlNode * parent, xmlNode * new_obj)
{
    enum cib_errors result = cib_ok;
    const char *object_name = NULL;
    const char *object_id = NULL;
    xmlNode *equiv_node = NULL;

    if (new_obj != NULL) {
        object_name = crm_element_name(new_obj);
    }
    object_id = crm_element_value(new_obj, XML_ATTR_ID);

    crm_debug_3("Processing: <%s id=%s>", crm_str(object_name), crm_str(object_id));

    if (new_obj == NULL || object_name == NULL) {
        result = cib_NOOBJECT;

    } else if (parent == NULL) {
        result = cib_NOPARENT;

    } else if (object_id == NULL) {
        /*  placeholder object */
        equiv_node = find_xml_node(parent, object_name, FALSE);

    } else {
        equiv_node = find_entity(parent, object_name, object_id);
    }

    if (result != cib_ok) {
        ;                       /* do nothing */

    } else if (equiv_node != NULL) {
        result = cib_EXISTS;

    } else {
        result = update_cib_object(parent, new_obj);
    }

    return result;
}
Ejemplo n.º 17
0
static int
add_cib_object(xmlNode * parent, xmlNode * new_obj)
{
    int result = pcmk_ok;
    const char *object_name = NULL;
    const char *object_id = NULL;
    xmlNode *equiv_node = NULL;

    if (new_obj != NULL) {
        object_name = crm_element_name(new_obj);
    }
    object_id = crm_element_value(new_obj, XML_ATTR_ID);

    crm_trace("Processing: <%s id=%s>", crm_str(object_name), crm_str(object_id));

    if (new_obj == NULL || object_name == NULL) {
        result = -EINVAL;

    } else if (parent == NULL) {
        result = -EINVAL;

    } else if (object_id == NULL) {
        /*  placeholder object */
        equiv_node = find_xml_node(parent, object_name, FALSE);

    } else {
        equiv_node = find_entity(parent, object_name, object_id);
    }

    if (result != pcmk_ok) {
        ;                       /* do nothing */

    } else if (equiv_node != NULL) {
        result = -ENOTUNIQ;

    } else {
        result = update_cib_object(parent, new_obj);
    }

    return result;
}
Ejemplo n.º 18
0
static int entity_completion(struct preparation *preparation,
			struct folder_entity *entity)
{
	struct folder *folder;
	int ret = 0;

	if (entity == NULL) {
		ULOGW("%*s creation failed for identification string %s",
				(int)strlen(preparation->folder) - 1,
				preparation->folder,
				preparation->identification_string);
		ret = -EINVAL;
		goto out;
	}

	/* if already prepared, nothing to be done */
	folder = folder_find(preparation->folder);
	if (find_entity(folder, folder_entity_get_sha1(entity)))
		goto out;
	/* folder_store transfers the ownership of the entity to the folder */
	ret = folder_store(preparation->folder, entity);
	if (ret < 0) {
		do_drop(entity, false);
		ULOGE("folder_store: %s", strerror(-ret));
		goto out;
	}

	ret = 0;
out:
	if (ret >= 0)
		firmwared_notify(FWD_ANSWER_PREPARED,
				FWD_FORMAT_ANSWER_PREPARED,
				preparation->seqnum, preparation->folder,
				folder_entity_get_sha1(entity), entity->name);

	preparation->has_ended = true;

	return ret;
}
Ejemplo n.º 19
0
struct folder_entity *folder_find_entity(const char *folder_name,
		const char *entity_identifier)
{
	struct folder *folder;
	struct folder_entity *entity;

	errno = ENOENT;
	if (ut_string_is_invalid(folder_name) ||
			ut_string_is_invalid(entity_identifier)) {
		errno = EINVAL;
		return NULL;
	}

	folder = folder_find(folder_name);
	if (folder == NULL)
		return NULL;

	entity = find_entity(folder, entity_identifier);
	if (entity == NULL)
		errno = ENOENT;

	return entity;
}
Ejemplo n.º 20
0
void on_collision(Laser* laser, Entity* them) {
    Entity* shooter = find_entity(laser->shooter_id);

    switch (them->type) {
        case ENTITY_TYPE_ASTEROID: {
            if (shooter && shooter->type == ENTITY_TYPE_PLAYER) {
                add_score(them->asteroid->score);
            }

            spawn_children(them->asteroid);

            destroy_entity(them);
            destroy_entity(laser->entity);

            break;
        }
        case ENTITY_TYPE_PLAYER: {
            if (shooter && shooter->type == ENTITY_TYPE_ENEMY) {
                damage_player(them->player);
                destroy_entity(laser->entity);
            }

            break;
        }
        case ENTITY_TYPE_ENEMY: {
            if (shooter && shooter->type == ENTITY_TYPE_PLAYER) {
                add_score(them->enemy->score);

                destroy_entity(laser->entity);
                kill_enemy();
            }

            break;
        }
    }
}
Ejemplo n.º 21
0
void HTML::entity_decode(string& out, cstring& in, bool isattr)
{
	//this follows the HTML5 spec <https://html.spec.whatwg.org/#character-reference-state>
	//12.2.5.72 Character reference state
	if (isalnum(in[1]))
	{
		//12.2.5.73 Named character reference state
		const char * ent = find_entity(in.substr(1, ~0));
		if (!ent) goto fail;
		size_t entlen = strlen(ent);
		size_t entlen_cons = 1+entlen;
		if (ent[entlen-1]!=';')
		{
			if (in[entlen_cons]==';') entlen_cons++;
			else
			{
				if (isattr &&                    // If the character reference was consumed as part of an attribute,
				    /* checked above */          // and the last character matched is not a U+003B SEMICOLON character (;),
				    (in[entlen_cons]=='=' ||     // and the next input character is either a U+003D EQUALS SIGN character (=) 
				      isalnum(in[entlen_cons]))) // or an ASCII alphanumeric,
				{                                // then, for historical reasons,
					goto fail;                     // flush code points consumed as a character reference and switch to the return state
				}
			}
		}
		in = in.substr(entlen_cons, ~0);
		const char * entval = (ent+entlen+1);
		if (*entval == '?') entval++;
		out += entval;
		return;
	}
	else if (in[1]=='#')
	{
		//12.2.5.75 Numeric character reference state
		size_t ccode;
		if (in[2]=='x' || in[2]=='X')
		{
			//12.2.5.76 Hexademical character reference start state
			size_t n = 3;
			while (isxdigit(in[n])) n++;
			if (n==3) goto fail;
			if (!fromstringhex(in.substr(3, n), ccode)) ccode = 0xFFFD;
			if (in[n]==';') n++;
			in = in.substr(n, ~0);
		}
		else
		{
			//12.2.5.77 Decimal character reference start state
			size_t n = 2;
			while (isdigit(in[n])) n++;
			if (n==2) goto fail;
			if (!fromstring(in.substr(2, n), ccode)) ccode = 0xFFFD;
			if (in[n]==';') n++;
			in = in.substr(n, ~0);
		}
		//12.2.5.80 Numeric character reference end state
		if (ccode == 0x00) ccode = 0xFFFD;
		if (ccode >  0x10FFFF) ccode = 0xFFFD;
		if (ccode >= 0xD800 && ccode <= 0xDFFF) ccode = 0xFFFD;
		if (ccode >= 0x80 && ccode <= 0x9F)
		{
#define X 0xFFFD
static const uint16_t windows1252[32]={
	//00 to 7F map to themselves
	0x20AC, X,      0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
	0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, X,      0x017D, X,     
	X,      0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
	0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, X,      0x017E, 0x0178,
	//A0 to FF map to themselves
};
#undef X
			uint32_t newcp = windows1252[ccode-0x80]; // yes, this is in the spec
			if (newcp != 0xFFFD) ccode = newcp;
		}
		out += string::codepoint(ccode);
		return;
	}
	//else fall through
	
fail:
	out += '&';
	in = in.substr(1, ~0);
}
Ejemplo n.º 22
0
	/***************************************************************
	 * find_entity:
	 * Find the named entity:  parameter, qualifier, or keyword
	 ***************************************************************/
static struct cduEntity  *find_entity(	/* Return: addr of struct	*/
    char  entity[]			/* <r> entity name <upper case>	*/
   ,struct cduEntity  entityList[]	/* <r> params, quals, or keywds	*/
   )
   {
    int   k;
    char  *p;
    char  *t;
    struct cduValue  *val;
    struct cduEntity  *e;

    if (!entityList)
        return(0);

    p = strchr(entity,'.');			/* contains '.' ?	*/
    k = p ? (p-entity) : strlen(entity);	/*..set length to look at */
    if (!k)
       {
        fprintf(stderr,"\n*WARN* zero-length entity?\n\n");
        exit(0);			/*-----------------> err: exit	*/
       }

    for (e=entityList ; e->entA_name ; e++)
       {
        t = e->entA_label ? e->entA_label : e->entA_name;
        if (!strncmp(entity,t,k))
            break;

        if (!(e->entL_flags & ENT_M_PARAMETERS))
            continue;
        if (val = e->entA_value)
           {
            if ((t=val->val_dsc.dscA_pointer) && !strcmp(entity,t))
                break;
           }
/*        if (val = e->entA_value)
/*           {				/*...check keywords, if any	*/
/*            if (val->valA_userType)
/*               {
/*                kwd = find_entity(entity,(void *)val->valA_userType);
/*                if (kwd)
/*                   {
/*                    e = kwd;
/*                    break;
/*                   }
/*               }
/*           }					/*  */
       }
    if (!e->entA_name)
        return(0);			/*---------> return: not found	*/

    if (!p)
        return(e);			/*------> return: entity found	*/

			/*----------------------------------------------
			 * entity specifies a sub-entity.  Look for it ...
			 *----------------------------------------------*/
    val = e->entA_value;
    if (!val || !val->valA_userType)
        return(0);			/*---------> return: no keywds	*/

    return(find_entity(p+1,(void *)val->valA_userType));
   }
Ejemplo n.º 23
0
size_t
houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, size_t size)
{
	size_t i = 0;

	if (size >= 3 && src[0] == '#') {
		int codepoint  = 0;
		int num_digits = 0;

		if (_isdigit(src[1])) {
			for (i = 1; i < size && _isdigit(src[i]); ++i) {
				codepoint = (codepoint * 10) + (src[i] - '0');

				if (codepoint >= 0x110000) {
					// Keep counting digits but
					// avoid integer overflow.
					codepoint = 0x110000;
				}
			}

			num_digits = i - 1;
		}

		else if (src[1] == 'x' || src[1] == 'X') {
			for (i = 2; i < size && _isxdigit(src[i]); ++i) {
				codepoint = (codepoint * 16) + ((src[i] | 32) % 39 - 9);

				if (codepoint >= 0x110000) {
					// Keep counting digits but
					// avoid integer overflow.
					codepoint = 0x110000;
				}
			}

			num_digits = i - 2;
		}

		if (num_digits >= 1 && num_digits <= 8 &&
		    i < size && src[i] == ';') {
			if (codepoint == 0 ||
			    (codepoint >= 0xD800 && codepoint < 0xE000) ||
			    codepoint >= 0x110000) {
				codepoint = 0xFFFD;
			}
			utf8proc_encode_char(codepoint, ob);
			return i + 1;
		}
	}

	else {
		if (size > MAX_WORD_LENGTH)
			size = MAX_WORD_LENGTH;

		for (i = MIN_WORD_LENGTH; i < size; ++i) {
			if (src[i] == ' ')
				break;

			if (src[i] == ';') {
				const struct html_ent *entity = find_entity((char *)src, i);

				if (entity != NULL) {
					int len = 0;
					while (len < 4 && entity->utf8[len] != '\0') {
						++len;
					}
					cmark_strbuf_put(ob, entity->utf8, len);
					return i + 1;
				}

				break;
			}
		}
	}

	return 0;
}
Ejemplo n.º 24
0
	/****************************************************************
	 * cli_get_value:
	 ****************************************************************/
int   cli_get_value(		/* Return: status			*/
    void  *entity		/* <r> entity name: dsc or c-string	*/
   ,struct descriptor  *dsc_ret	/* <w> return value descriptor		*/
   )
   {
    int   k;
    int   sts;
    char  entityString[128];
    char  *p,*p2;
    struct cduEntity  *e;
    struct cduValue  *val;
    static struct descriptor  dsc_util = {
                                0,DSC_K_DTYPE_T,DSC_K_CLASS_S,0};

    if (!currentSyntax)
        return(CLI_STS_IVREQTYP);

    make_entityString(entity,entityString,sizeof(entityString));

		/*-----------------------------------------------------
		 * Check for "special" entities ...
		 *----------------------------------------------------*/
    p = 0;
    if (!strcmp(entityString,"$LINE"))
        p = dsc_cmdline.dscA_pointer;
    else if (!strcmp(entityString,"$VERB"))
        p = currentSyntax->vrbA_name;

    if (p)
       {
        str_copy_dx(dsc_ret,p);
        return(1);			/*------------> return: special	*/
       }

		/*--------------------------------------------------------
		 * Find requested entity and return its value ...
		 *-------------------------------------------------------*/
    e = find_entity(entityString,(void *)currentParameters);
    if (!e)
        e=find_entity(entityString,(void *)currentQualifiers);

    if (!e || !e->entL_status)
        return(CLI_STS_ABSENT);

    val = e->entA_value;
    if (!val)
        return(CLI_STS_IVREQTYP);

/*    if (val->valL_flags & VAL_M_USER_DEFINED_TYPE)
/*        return(CLI_STS_IVREQTYP);			/*  */

    if (!val->valA_substring)
        return(CLI_STS_ABSENT);

			/*------------------------------------------------
			 * Return 'value' string to caller ...
			 *-----------------------------------------------*/
    if (val->valL_flags & VAL_M_LIST)
       {
        p = val->valA_substring;
        p2 = strpbrk(p,"\01\02");	/* find delimter char	*/
        k = p2 ? (p2-p) : strlen(p);
        dsc_util.dscW_length = k;
        dsc_util.dscA_pointer = p;
        sts = str_copy_dx(dsc_ret,&dsc_util);
        val->valA_substring = p2;
       }
    else
       {
         int slen=strlen(val->valA_substring)+1;
         int len=sizeof(struct descriptor)>slen?sizeof(struct descriptor):slen;
	 char *tmp=strcpy(memset(malloc(len),0,len),val->valA_substring);
        sts = str_copy_dx(dsc_ret,tmp);
	free(tmp);
        val->valA_substring = 0;
       }

#ifdef vms
    if (val->valL_flags & VAL_M_DELTATIME)
       {				/* VMS deltatime only ...	*/
        p = strchr(dsc_ret->dscA_pointer,'-');
        if (p)  *p = ' ';		/*..replace '-' with blank	*/

        p = dsc_ret->dscA_pointer;
        k = strlen(p);
        if (k < dsc_ret->dscW_length)
            memset(p+k,' ',dsc_ret->dscW_length - k);
       }
#endif

    if (!val->valA_substring)
        return(1);			/*-------------> return: Normal	*/

    if (*val->valA_substring == '\01')		/* "Comma" delimiter	*/
       {
        val->valA_substring++;
        return(CLI_STS_COMMA);
       }

    if (*val->valA_substring == '\02')		/* "Plus" delimiter	*/
       {
        val->valA_substring++;
        return(CLI_STS_CONCAT);
       }

    return(cli_error(CLI_STS_BADLINE,"cli_get_value error ???"));
   }
Ejemplo n.º 25
0
static int
update_cib_object(xmlNode * parent, xmlNode * update)
{
    int result = pcmk_ok;
    xmlNode *target = NULL;
    xmlNode *a_child = NULL;
    const char *replace = NULL;
    const char *object_id = NULL;
    const char *object_name = NULL;

    CRM_CHECK(update != NULL, return -EINVAL);
    CRM_CHECK(parent != NULL, return -EINVAL);

    object_name = crm_element_name(update);
    CRM_CHECK(object_name != NULL, return -EINVAL);

    object_id = ID(update);
    crm_trace("Processing: <%s id=%s>", crm_str(object_name), crm_str(object_id));

    if (object_id == NULL) {
        /*  placeholder object */
        target = find_xml_node(parent, object_name, FALSE);

    } else {
        target = find_entity(parent, object_name, object_id);
    }

    if (target == NULL) {
        target = create_xml_node(parent, object_name);
    }

    crm_trace("Found node <%s id=%s> to update", crm_str(object_name), crm_str(object_id));

    replace = crm_element_value(update, XML_CIB_ATTR_REPLACE);
    if (replace != NULL) {
        xmlNode *remove = NULL;
        int last = 0, lpc = 0, len = 0;

        len = strlen(replace);
        while (lpc <= len) {
            if (replace[lpc] == ',' || replace[lpc] == 0) {
                char *replace_item = NULL;

                if (last == lpc) {
                    /* nothing to do */
                    last = lpc + 1;
                    goto incr;
                }

                replace_item = calloc(1, lpc - last + 1);
                memcpy(replace_item, replace + last, lpc - last);

                remove = find_xml_node(target, replace_item, FALSE);
                if (remove != NULL) {
                    crm_trace("Replacing node <%s> in <%s>",
                              replace_item, crm_element_name(target));
                    free_xml(remove);
                    remove = NULL;
                }
                free(replace_item);
                last = lpc + 1;
            }
  incr:
            lpc++;
        }
        xml_remove_prop(update, XML_CIB_ATTR_REPLACE);
        xml_remove_prop(target, XML_CIB_ATTR_REPLACE);
    }

    copy_in_properties(target, update);

    crm_trace("Processing children of <%s id=%s>", crm_str(object_name), crm_str(object_id));

    for (a_child = __xml_first_child(update); a_child != NULL; a_child = __xml_next(a_child)) {
        int tmp_result = 0;

        crm_trace("Updating child <%s id=%s>", crm_element_name(a_child), ID(a_child));

        tmp_result = update_cib_object(target, a_child);

        /*  only the first error is likely to be interesting */
        if (tmp_result != pcmk_ok) {
            crm_err("Error updating child <%s id=%s>", crm_element_name(a_child), ID(a_child));

            if (result == pcmk_ok) {
                result = tmp_result;
            }
        }
    }

    crm_trace("Finished with <%s id=%s>", crm_str(object_name), crm_str(object_id));

    return result;
}
Ejemplo n.º 26
0
int
main (int argc, char *argv[])
{
    char line[1000000];
    FILE *in, *out;
    int line_length;
    int total_num_root_entities;
    int total_num_sub_entities;
    long num_entities;
    unsigned long *temp;
    int index;
    int ret;
    int fd_entities_path, fd_hash_path;
    int result;
    int roots, subs;
    int num_lines = 0;
    int num_dups = 0;
    int json = 1;
    struct entity *entities = 0;
    struct hsearch_data htab;

    if (hcreate_r (LARGE_HASH_TABLE, &htab) == 0)
    {
        perror ("Could not create hash table");
        exit (2);
    }

// Begin MMAP stuff:
//
// Open an mmap file for writing.
// - Creating the file if it doesn't exist.
// - Truncating it to 0 size if it already exists. (not really needed)
// Note: "O_WRONLY" mode is not sufficient when mmaping.
//
    fd_entities_path =
        open (ENTITIES_FILEPATH, O_RDWR | O_CREAT | O_TRUNC, (mode_t) 0600);
    if (fd_entities_path == -1)
    {
        perror ("Error opening mmap file for writing");
        exit (EXIT_FAILURE);
    }
    fd_hash_path =
        open (HASH_FILEPATH, O_RDWR | O_CREAT | O_TRUNC, (mode_t) 0600);
    if (fd_hash_path == -1)
    {
        perror ("Error opening mmap file for writing");
        exit (EXIT_FAILURE);
    }

// Stretch the file size to the size of the (mmapped) array of ints
//
    result = lseek (fd_entities_path, ENTITIES_FILESIZE - 1, SEEK_SET);
    if (result == -1)
    {
        close (fd_entities_path);
        perror ("Error calling lseek() to 'stretch' the file");
        exit (EXIT_FAILURE);
    }
    result = lseek (fd_hash_path, HASH_FILESIZE - 1, SEEK_SET);
    if (result == -1)
    {
        close (fd_hash_path);
        perror ("Error calling lseek() to 'stretch' the file");
        exit (EXIT_FAILURE);
    }

// Something needs to be written at the end of the file to
// have the file actually have the new size.
// Just writing an empty string at the current file position will do.
// 
// Note:
//  - The current position in the file is at the end of the stretched
//    file due to the call to lseek().
//  - An empty string is actually a single '\0' character, so a zero-byte
//    will be written at the last byte of the file.
//    
    result = write (fd_entities_path, "", 1);
    if (result != 1)
    {
        close (fd_entities_path);
        perror ("Error writing last byte of the file");
        exit (EXIT_FAILURE);
    }
    result = write (fd_hash_path, "", 1);
    if (result != 1)
    {
        close (fd_hash_path);
        perror ("Error writing last byte of the file");
        exit (EXIT_FAILURE);
    }

// Now the file is ready to be mmapped.
//
    entities =
        mmap (0, ENTITIES_FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
              fd_entities_path, 0);
    if (entities == MAP_FAILED)
    {
        close (fd_entities_path);
        perror ("Error mmapping the entities file");
        exit (EXIT_FAILURE);
    }
    htab =
        mmap (0, HASH_FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
              fd_hash_path, 0);
    if (htab == MAP_FAILED)
    {
        close (fd_hash_path);
        perror ("Error mmapping the entities file");
        exit (EXIT_FAILURE);
    }

// End MMAP stuff


    in = fopen ("in.txt", "r");

    if (!json)
        printf ("Creating the in memory table... \n");

    num_entities = -1;
    while (1 == fscanf (in, "%[^\n]%n\n", line, &line_length))
    {                           //read one line
        char *word;
        unsigned long focal_root_entity = 0;    //Used when the Root Entity already exists
        char *ptr;
        {
            char *root = strtok_r (line, ",", &ptr);
            int i = 0;

            // First check whether the entry already exists:
            i = find_entity (root, &htab, num_entities);

            if (i > num_entities)
            {

                // Initialise this Root Entity:
                add_ent (&entities, &num_entities, root, &htab);

                focal_root_entity = num_entities;
                total_num_root_entities++;
            }
            else
            {                   //  If the root entity has been found:
                if (!json && DEBUG)
                    printf
                        ("***At line %d Root Entity %s was already found \n",
                         num_lines, root);
                num_dups++;


                focal_root_entity = i;
            }                   // if (found == 0)
        }

        for (; word = strtok_r (NULL, ",", &ptr);)
        {
            unsigned long sub_entity = 0;

            //First check whether the entity already exists :
            sub_entity = find_entity (word, &htab, num_entities);
            if (sub_entity > num_entities)
            {

                //Initialise this Sub Entity:
                add_ent (&entities, &num_entities, word, &htab);

                total_num_sub_entities++;
                sub_entity = num_entities;

            }                   //End found==0
            else
            {
                if (!json && DEBUG)
                    printf
                        ("***At line %d Sub Entity %s was already found \n",
                         num_lines, word);
                num_dups++;
            }


            // Now link the Sub Entity to the focal_root_entity using the index of the entity arrays :
            add_link (&entities[focal_root_entity], sub_entity);
            add_link (&entities[sub_entity], focal_root_entity);


        }                       // End for pos

        num_lines++;

    }                           // End while fscanf

    fclose (in);


// Now print out the entire set of Entities:



    if (json)
        printf ("[\n");
    {
        int i;
        roots = subs = 0;
        for (i = 0; i <= num_entities; i++)
        {
            int j;
            if (entities[i].num_links >= 0)
            {
                if (!json)
                    printf ("Root Entity '%s' discovered with %d sub links\n",
                            entities[i].entity_name, entities[i].num_links);
                roots++;

                for (j = 0; j <= entities[i].num_links; j++)
                {
                    if (((i > 0) || (j > 0)) && (json))
                        printf (",");
                    if (!json)
                        printf ("Sub Entity is %s\n",
                                entities[entities[i].links[j]].entity_name);
                    if (json)
                        printf
                            ("{\n   \"source\" : \"%s\",\n   \"target\" : \"%s\",\n   \"type\" : \"suit\"\n}\n",
                             entities[i].entity_name,
                             entities[entities[i].links[j]].entity_name);
                    subs++;
                }
                printf ("\n");

            }

        }
    }
    if (json)
        printf ("]\n");

    if (!json)
    {
        printf
            ("The number of root entities found were %d and the number of subs found were %d\n",
             roots, subs);
        printf
            ("The total number of Entities are %d read in %d lines with %d duplications.\n",
             num_entities, num_lines, num_dups);
    }


// Don't forget to free the mmapped memory
//
    if (munmap (entities, ENTITIES_FILESIZE) == -1)
    {
        perror ("Error un-mmapping the file");
        /* Decide here whether to close(fd) and exit() or not. Depends... */
    }
    if (munmap (htab, HASH_FILESIZE) == -1)
    {
        perror ("Error un-mmapping the file");
        /* Decide here whether to close(fd) and exit() or not. Depends... */
    }

// Un-mmaping doesn't close the file, so we still need to do that.
//
    close (fd_entities_path);
    close (fd_hash_path);


    return 0;
}
Ejemplo n.º 27
0
void demo_csgo::handle_netmessages<CSVCMsg_PacketEntities, svc_PacketEntities>(google::protobuf::io::CodedInputStream& cis) {
    CSVCMsg_PacketEntities msg;
    if(!msg.MergeFromCodedStream(&cis)) {
        std::cerr << "handle_netmessages<CSVCMsg_PacketEntities>(): !msg.MergeFromCodedStream(&cis)" << std::endl;
        return;
    }

    CBitRead bs(&msg.entity_data()[0], msg.entity_data().size());

	bool bAsDelta = msg.is_delta();
	int nHeaderCount = msg.updated_entries();
	int nBaseline = msg.baseline();
	bool bUpdateBaselines = msg.update_baseline();
	int nHeaderBase = -1;
	int nNewEntity = -1;
	int UpdateFlags = 0;

	UpdateType updateType = PreserveEnt;
	while ( updateType < Finished ) {
		nHeaderCount--;
		bool bIsEntity = ( nHeaderCount >= 0 ) ? true : false;
		if ( bIsEntity  ) {
			UpdateFlags = FHDR_ZERO;
			nNewEntity = nHeaderBase + 1 + bs.ReadUBitVar();
			nHeaderBase = nNewEntity;
			// leave pvs flag
			if(bs.ReadOneBit() == 0) {
				// enter pvs flag
				if(bs.ReadOneBit() != 0) {
					UpdateFlags |= FHDR_ENTERPVS;
				}
			} else {
				UpdateFlags |= FHDR_LEAVEPVS;
				// Force delete flag
				if(bs.ReadOneBit() != 0) {
					UpdateFlags |= FHDR_DELETE;
				}
			}
		}

		for( updateType = PreserveEnt; updateType == PreserveEnt; ) {
			// Figure out what kind of an update this is.
			if ( !bIsEntity || nNewEntity > ENTITY_SENTINEL) {
				updateType = Finished;
			} else {
				if(UpdateFlags & FHDR_ENTERPVS) {
					updateType = EnterPVS;
				} else if (UpdateFlags & FHDR_LEAVEPVS) {
					updateType = LeavePVS;
				} else {
					updateType = DeltaEnt;
				}
			}

			switch( updateType ) {
				case EnterPVS:	
					{
                        uint32_t uClass = bs.ReadUBitLong(m_server_classes_bits);
						uint32_t uSerialNum = bs.ReadUBitLong(NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS);
                        EntityEntry* entity = entities_add(nNewEntity, uClass, uSerialNum);
                        if(!read_new_entity(bs, entity)) {
							printf( "*****Error reading entity! Bailing on this PacketEntities!\n" );
							return;
						}
					}
					break;

				case LeavePVS:
					{
						if ( !bAsDelta ) {  // Should never happen on a full update.
							printf( "WARNING: LeavePVS on full update" );
							updateType = Failed;	// break out
							assert( 0 );
						} else {
							if (true) {
								if ( UpdateFlags & FHDR_DELETE ) {
									printf( "Entity leaves PVS and is deleted: id:%d\n", nNewEntity );
								} else {
									printf( "Entity leaves PVS: id:%d\n", nNewEntity );
								}
							}
                            entities_remove(nNewEntity);
						}
					}
					break;

				case DeltaEnt:
					{
                        EntityEntry* pEntity = find_entity(nNewEntity);
						if ( pEntity ) {
							if (true) {
								//printf( "Entity Delta update: id:%d, class:%d, serial:%d\n", pEntity->m_nEntity, pEntity->m_uClass, pEntity->m_uSerialNum );
							}
                            if ( !read_new_entity(bs, pEntity ) ) {
								printf( "*****Error reading entity! Bailing on this PacketEntities!\n" );
								return;
							}
						} else {
                            assert(0);
						}
					}
					break;

				case PreserveEnt:
					{
						if ( !bAsDelta ) {  // Should never happen on a full update.
							printf( "WARNING: PreserveEnt on full update" );
							updateType = Failed;	// break out
							assert( 0 );
						} else {
							if ( nNewEntity >= MAX_EDICTS ) {
								printf( "PreserveEnt: nNewEntity == MAX_EDICTS" );
								assert( 0 );
							} else {
								if (true) {
									printf( "PreserveEnt: id:%d\n", nNewEntity );
								}
							}
						}
					}
					break;

				default:
					break;
			}
		}
	}
}
Ejemplo n.º 28
0
int
main (int argc, char *argv[])
{
    char line[1000000];
    FILE *in, *out;
    int line_length;
    int total_num_root_entities;
    int total_num_sub_entities;
    int num_entities;
    unsigned long *temp;
    int index;
    int ret;
    int roots, subs;
    int json = 1;

    if (hcreate_r (200000, &htab) == 0)
    {
        perror ("Failed to create hash");
        exit (1);
    }

    struct entity *entities = 0;


    in = fopen ("in.txt", "r");
    out = fopen ("out.txt", "w");


    num_entities = -1;
    while (1 == fscanf (in, "%[^\n]%n\n", line, &line_length))
    {                           //read one line
        char *word;
        struct entity *focal_root = 0;  //Used when the Root Entity already exists
        char *ptr;
        {
            char *root = strtok_r (line, ",", &ptr);
            int i = 0;

            // First check whether the entry already exists:
            focal_root = find_entity (entities, num_entities, root);

            if (focal_root == NULL)
            {

                // Initialise this Root Entity:
                focal_root = add_ent (root);

                fprintf (out, "%s\n", root);

                total_num_root_entities++;
            }
        }

        for (; word = strtok_r (NULL, ",", &ptr);)
        {
            struct entity *entity = 0;

            //First check whether the entity already exists :
            entity = find_entity (entities, num_entities, word);
            if (entity == NULL)
            {

                //Initialise this Sub Entity:
                entity = add_ent (word);
            }

            // Now link the Sub Entity to the focal_root_entity using the index of the entity arrays :
            add_link (focal_root, entity);
            add_link (entity, focal_root);

            // Echo the word to the o/p file :
            fprintf (out, "%s\n", word);

        }                       // End for pos
    }
    fclose (out);
    fclose (in);


// Now print out the entire set of Entities:



    if (json)
        printf ("[\n");
    {
        int i;
        roots = subs = 0;
        for (i = 0; i <= num_entities; i++)
        {
            int j;
            if (entities[i].num_links >= 0)
            {
                if (!json)
                    printf ("Root Entity '%s' discovered with %d sub links\n",
                            entities[i].entity_name, entities[i].num_links);
                roots++;

                for (j = 0; j <= entities[i].num_links; j++)
                {
                    if (((i > 0) || (j > 0)) && (json))
                        printf (",");
                    if (!json)
                        printf ("Sub Entity is %s\n",
                                entities[entities[i].links[j]].entity_name);
                    if (json)
                        printf
                            ("{\n   \"source\" : \"%s\",\n   \"target\" : \"%s\",\n   \"type\" : \"suit\"\n}\n",
                             entities[i].entity_name,
                             entities[entities[i].links[j]].entity_name);
                    subs++;
                }
                printf ("\n");

            }

        }
    }
    if (json)
        printf ("]\n");

    if (!json)
    {
        printf
            ("The number of root entities found were %d and the number of subs found were %d\n",
             roots, subs);
        printf ("The total number of Entities are %d\n", num_entities);
        printf ("The total number of Root Entities are %d\n",
                total_num_root_entities);
        printf ("The total number of Sub Entities are %d\n",
                total_num_sub_entities);
    }




    hdestroy_r (&htab);


    return (0);
// fwrite the array of structs out to save them:
    out = fopen ("entities.bin", "wb");
    ret = fwrite (entities, sizeof (entities), 1, out);
    fclose (out);

// fread the array of structs in test:
    in = fopen ("entities.bin", "rb");
    ret = fread (entities, sizeof (entities), 1, in);
    fclose (in);

    return 0;
}