예제 #1
0
파일: scs.c 프로젝트: babongo/libscs
static int init_keyset (scs_t *ctx, scs_keyset_t *ks, const char *tid, int comp,
        scs_cipherset_t cipherset, const uint8_t *key, const uint8_t *hkey)
{
    if (set_tid(ctx, ks, tid))
        return SCS_ERR_BAD_TID;

    /* Set the compression flag as requested.  In case zlib is not available 
     * on the platform, ignore user request and set to false. */
    ks->comp = have_libz ? comp : 0;

    /* Setup keyset and cipherset. */
    switch ((ks->cipherset = cipherset))
    {
        case AES_128_CBC_HMAC_SHA1:
            ks->key_sz = ks->block_sz = 16;
            ks->hkey_sz = 20;
            break;
        default:
            return SCS_ERR_WRONG_CIPHERSET;
    }

    /* Create or attach new HMAC and cipher keys. */
    if (new_key(ks->key, key, ks->key_sz)
            || new_key(ks->hkey, hkey, ks->hkey_sz))
        return SCS_ERR_CRYPTO;

    return SCS_OK;
}
예제 #2
0
파일: scs.c 프로젝트: babongo/libscs
/**
 *  Refresh current keyset with the supplied keying material.
 *
 *  Update the current keyset with the supplied keying material (both HMAC and
 *  encryption keys must be given at once) and associate it with the supplied
 *  TID.  Note that the TID string must be different from the one currently in
 *  use.  In case of error, the current keyset is kept in use.
 *
 *  \param  ctx     The scs_t object that will be refreshed.
 *  \param  new_tid The new TID string.
 *  \param  key     Encryption key; it is assumed to be of the correct size, 
 *                  i.e. 16 bytes for AES 128.
 *  \param  hkey    HMAC key; it is assumed to be of the correct size, i.e. 20
 *                  bytes for SHA1-based HMAC.
 *
 *  \return \c 0 on success, \c -1 if an error occurs.
 */ 
int scs_refresh_keyset (scs_t *ctx, const char *new_tid, const uint8_t *key, 
        const uint8_t *hkey)
{
    time_t now;
    scs_keyset_t *ks = &ctx->cur_keyset;

    scs_keyset_t *cur = &ctx->cur_keyset, *prev = &ctx->prev_keyset, tmp;

    tmp = *prev;
    *prev = *cur;

    /* Get current timestamp. */
    if (what_time_is_it(ctx, &now))
        return -1;

    /* Create new keying material. */
    if (new_key(ks->key, key, ks->key_sz)
            || new_key(ks->hkey, hkey, ks->hkey_sz))
    {
        scs_set_error(ctx, SCS_ERR_CRYPTO, "keyset update failed.");
        goto recover;
    }

    /* Set new tid name. */
    if (set_tid(ctx, cur, new_tid))
        return -1;

    return 0;

recover:
    *cur = *prev;
    *prev = tmp;

    return -1;
}
예제 #3
0
void test_hash_table_free_functions(void)
{
	HashTable *hash_table;
	int *key;
	int *value;
	int i;

	/* Create a hash table, fill it with values */

	hash_table = hash_table_new(int_hash, int_equal);

	hash_table_register_free_functions(hash_table, free_key, free_value);

	allocated_values = 0;

	for (i=0; i<NUM_TEST_VALUES; ++i) {
		key = new_key(i);
		value = new_value(99);

		hash_table_insert(hash_table, key, value);
	}

	assert(allocated_keys == NUM_TEST_VALUES);
	assert(allocated_values == NUM_TEST_VALUES);

	/* Check that removing a key works */

	i = NUM_TEST_VALUES / 2;
	hash_table_remove(hash_table, &i);

	assert(allocated_keys == NUM_TEST_VALUES - 1);
	assert(allocated_values == NUM_TEST_VALUES - 1);

	/* Check that replacing an existing key works */

	key = new_key(NUM_TEST_VALUES / 3);
	value = new_value(999);

	assert(allocated_keys == NUM_TEST_VALUES);
	assert(allocated_values == NUM_TEST_VALUES);

	hash_table_insert(hash_table, key, value);

	assert(allocated_keys == NUM_TEST_VALUES - 1);
	assert(allocated_values == NUM_TEST_VALUES - 1);

	/* A free of the hash table should free all of the keys and values */

	hash_table_free(hash_table);

	assert(allocated_keys == 0);
	assert(allocated_values == 0);
}
  void
  Sender_exec_i::write_many ()
  {
    DDS4CCM_TEST_DEBUG << "Sender_exec_i::write_many" << std::endl;

    uint32_t nr_samples = this->keys_ * this->iterations_;
    UnkeyedWriterTest::UnkeyedWriterMessageSeq write_many_no_excep;
    write_many_no_excep.resize (nr_samples);
    //write with no exception
    for (uint32_t i = 1; i < nr_samples + 1; ++i)
    {
      OctetSeq reply_mesg (1);
      UnkeyedWriterTest::UnkeyedWriterMessage new_key ("KEY_1", 1, reply_mesg);
      write_many_no_excep[i-1] = new_key;
    }
    try
    {
      IDL::traits < UnkeyedWriterTest::UnkeyedWriterMessageConnector::Writer >::ref_type writer =
        this->context_->get_connection_info_write_data ();

      writer->write_many (write_many_no_excep);
      DDS4CCM_TEST_DEBUG << "write_many : written <"
        << write_many_no_excep.size () << "> samples."
        << std::endl;
    }
    catch (const CCM_DDS::InternalError& ex)
    {
      DDS4CCM_TEST_ERROR << "ERROR: Internal Error while write many writer "
        << ex << std::endl;
    }
    start_new_assignment (WRITER_ASSIGNMENT::TEST_EXCEPTION);
  }
예제 #5
0
  //@@{__RIDL_REGEN_MARKER__} - BEGIN : CIAO_CFT_EL_Test_Sender_Impl::Sender_exec_i[src_user_public_ops]
  void
  Sender_exec_i::start_publishing ()
  {
    for (uint16_t i = 1; i < this->keys_ + 1; ++i)
    {
      std::string const key ("KEY_" + std::to_string (i));
      CFT_EL_Message new_key (key, 0);
      this->samples_[key] = new_key;
    }
    this->last_key_ = this->samples_.begin ();

    // calculate the interval time
    long const usec = 1000000 / this->rate_;
    if (this->reactor ()->schedule_timer (
                this->ticker_.get (),
                0,
                ACE_Time_Value (0, usec),
                ACE_Time_Value (0, usec)) == -1)
    {
      DDS4CCM_TEST_ERROR << "Sender_exec_i::start_publishing : Error scheduling timer." << std::endl;
    }
    else
      DDS4CCM_TEST_DEBUG << "Sender_exec_i::start_publishing : Started timer." << std::endl;

  }
예제 #6
0
	event_node_ptr fake_event_source::release_key(const size_t time, const SDLKey key, const SDLMod mod)
	{
		SDL_Event event = make_key_event(SDL_KEYUP, key, mod);
		event_node_ptr new_key(new event_node_keyboard(time, event));
		add_event(new_key);
		return new_key;
	}
예제 #7
0
int main (int argc, char *argv[])
{
  char buff[1024];
  char *s;
  
  struct sig **lastsig = NULL;
  struct uid **lastuid = NULL;
  struct key *k = new_key();
  
  lastuid = &k->uids;

  if (argc == 2 && !strcmp (argv[1], "-S"))
    DontRequireSelfSig = 1;

  while (fgets (buff, sizeof (buff), stdin))
  {
    if ((s = strtok (buff, ":")))
    {
      if (!strcmp (s, "pub"))
      {
	do_key (k);
	k->rev = 0;
	k->uids = new_uid();

	lastuid = &k->uids->next;
	lastsig = &k->uids->sigs;

	strtok (NULL, ":");
	strtok (NULL, ":");
	strtok (NULL, ":");

	sprintf (k->id, "%s", strtok (NULL, ":"));
      }
      else if (!strcmp (s, "rev"))
	k->rev = 1;
      else if (!strcmp (s, "uid"))
      {
	struct uid *uid = *lastuid = new_uid();
	lastuid = &(*lastuid)->next;
	lastsig = &uid->sigs;
      }
      else if (!strcmp (s, "sig"))
      {
	struct sig *sig = *lastsig = new_sig();
	lastsig = &sig->next;
	sprintf (sig->id, "%s", strtok (NULL, ":"));
      }
    }
  }
  
  do_key (k);
  
  return 0;
}
예제 #8
0
파일: keys.c 프로젝트: BitchX/BitchX1.1
/* special interface to new_key for the default key bindings */
static void	snew_key (int meta, unsigned chr, char *what)
{
	int	i;
	int	j;

	if ((j = lookup_function(what, &i)) == 1)
		new_key(meta, chr, i, 0, NULL);
#if 0
	else
		ircpanic("Something bogus passed to snew_key");
#endif
}
예제 #9
0
/*
 * Process a key block
 */
static int
process_key(struct state *cur, struct block *info,
		const char *name, scconf_block *blk)
{
	unsigned int	type, id;
	struct state	state;

	if (get_authid(cur, name, &type, &id))
		return 1;

	init_state(cur, &state);
	state.key = new_key(cur->profile, type, id);
	return process_block(&state, info, name, blk);
}
예제 #10
0
파일: conn_server.cpp 프로젝트: CMXWL/kcpuv
int ConnServer::prepare_snd_conv(const sockaddr* addr, uv_udp_t* handle, uint32_t n) {
	_addr = *addr;
	_udp = handle;
	_n = n;
	_conv = new_conv();

	_next_snd_conv_tick = 0;

	_snd_conv.conv = CONV_SND_CONV;
	_snd_conv.n = n;
	_snd_conv.new_conv = _conv;
	_snd_conv.key = new_key();

	_key = _snd_conv.key;
	_status = CONV_SND_CONV;
	return init_kcp(_conv);
}
예제 #11
0
파일: split.cpp 프로젝트: greenlion/warpsql
shard map(MYSQL* conn, long long schema_id, long long column_id, std::string key_value) {
  std::string sql;
  sql = "select shard_name from shard_map_string join shards on shard_id = shards.id where column_id =" + std::to_string(column_id) + " and key_value = '" + key_value + "'";
  if(int err = mysql_query(conn, sql.c_str())) {
    std::cerr << "ERROR: " << err << ", " << mysql_error(conn) << "\n";
    exit(-1);
  }
  MYSQL_RES *result = mysql_store_result(conn);
  MYSQL_ROW row = mysql_fetch_row(result);
  if(!row) {
    if(!depth) return(new_key(conn, schema_id, column_id, key_value));
    std::cerr << "ERROR: recusive mapping failed after new key creation failed.  Invalid state.\n";
    exit(-1);
  }
  shard s = populate_shard(row);
  mysql_free_result(result);
  return s;
}
예제 #12
0
파일: keys.c 프로젝트: BitchX/BitchX1.1
static	void	snew_key_from_str (uc *string, char *what)
{
	int	i;
	int	meta;
	int	old_display;
	uc	chr;

	old_display = window_display;
	window_display = 0;
	if ((meta = parse_key(string, &chr)) == -1)
		return;
	window_display = old_display;

	if (lookup_function(what, &i) == 1)
		new_key(meta, chr, i, 0, NULL);

	return;
}
예제 #13
0
Handle<ScopedEVP_PKEY> JwkEc::To(int &key_type) {
	LOG_FUNC();

	LOG_INFO("Check key_type");
	if (!(key_type == NODESSL_KT_PRIVATE || key_type == NODESSL_KT_PUBLIC)) {
		THROW_ERROR("Wrong value of key_type");
	}

	LOG_INFO("import EC from JWK");
	ScopedEC_KEY ec_key(EC_KEY_new());

	LOG_INFO("set public key");
	ScopedEC_GROUP group(EC_GROUP_new_by_curve_name(this->crv));
	if (group.isEmpty()) {
		THROW_OPENSSL("EC_GROUP_new_by_curve_name");
	}

	EC_KEY_set_group(ec_key.Get(), group.Get());

	ScopedBIGNUM x(BN_dup(this->x.Get()));
	ScopedBIGNUM y(BN_dup(this->y.Get()));

	if (EC_KEY_set_public_key_affine_coordinates(ec_key.Get(), x.Get(), y.Get()) != 1) {
		THROW_OPENSSL("EC_KEY_set_public_key_affine_coordinates");
	}
	x.unref();
	y.unref();
	if (key_type == NODESSL_KT_PRIVATE) {
		LOG_INFO("set private key");

		ScopedBIGNUM d(BN_dup(this->d.Get()));
		if (EC_KEY_set_private_key(ec_key.Get(), d.Get()) != 1) {
			THROW_OPENSSL("EC_KEY_set_private_key");
		}
		d.unref();
	}

	LOG_INFO("set internal key");
	Handle<ScopedEVP_PKEY> new_key(new ScopedEVP_PKEY(EVP_PKEY_new()));
	EVP_PKEY_assign_EC_KEY(new_key->Get(), ec_key.Get());
	ec_key.unref();
	
	return new_key;
}
  void
  Sender_exec_i::start_publishing ()
  {
    std::lock_guard<std::mutex> __guard (this->mutex_);

    for (uint16_t i = 1; i < this->keys_ + 1; ++i)
    {
      std::string key("KEY_" + std::to_string (i));
      OctetSeq seq (1);
      UnkeyedWriterTest::UnkeyedWriterMessage new_key (
        key, 1, seq);
      this->ktests_[key] = new_key;

      DDS4CCM_TEST_DEBUG << "Created key : " << new_key << std::endl;
    }
   this->last_key_ = this->ktests_.begin ();
   reset_iterations ();
   this->start ();
  }
예제 #15
0
void LayoutParser::parseKey(const TagRowPtr &row)
{
    static const QStringList styleValues(QString::fromLatin1("normal,special,deadkey").split(','));
    static const QStringList widthValues(QString::fromLatin1("small,medium,large,x-large,xx-large,stretched").split(','));

    const QXmlStreamAttributes attributes(m_xml.attributes());
    const TagKey::Style style(enumValue("style", styleValues, TagKey::Normal));
    const TagKey::Width width(enumValue("width", widthValues, TagKey::Medium));
    const bool rtl(boolValue(attributes.value(QLatin1String("rtl")), false));
    const QString id(attributes.value(QLatin1String("id")).toString());
    TagKeyPtr new_key(new TagKey(style, width, rtl, id));

    row->appendElement(new_key);

    while (m_xml.readNextStartElement()) {
        const QStringRef name(m_xml.name());

        if (name == QLatin1String("binding")) {
            if (not new_key->binding()) {
                parseBinding(new_key);
            } else {
                error(QString::fromLatin1("Expected only one '<binding>', but got another one."));
            }
        } else if (name == QLatin1String("extended")) {
            if (not new_key->extended()) {
                parseExtended(new_key);
            } else {
                error(QString::fromLatin1("Expected only one '<extended>', but got another one."));
            }
        } else {
            error(QString::fromLatin1("Expected '<binding>' or '<extended>', but got '<%1>'.").arg(name.toString()));
        }
    }

    if (not new_key->binding()) {
        error(QString::fromLatin1("Expected exactly one '<binding>' but got none."));
    }
}
예제 #16
0
파일: INIFile.C 프로젝트: HeyJJ/ball
	bool INIFile::setLine(LineIterator line_it, const String& line)
	{
		// section lines cannot be changed with this method
		if (!isValid(line_it) || (*line_it)[0] == '[')
		{
			return false;
		}
		
		String new_key(line.before("="));
		new_key.trim();

		if ((*line_it).hasSubstring("=", 1))
		{
			// oh, this line had a key :(
			String old_key((*line_it).before("="));
			old_key.trim();

			if (old_key == new_key)
			{
				line_it.setLine_(line);
				return true;
			}

			// its a new key: delete the old one.
			line_it.getSection()->key_map_.remove(old_key);
		}

		line_it.setLine_(line);

		if (line.hasSubstring("=", 1))
		{
			// oh, the new line has a key :(
			line_it.getSection()->key_map_[new_key] = line_it.getPosition();		
		}

		return true;
	}
// returns all skies referenced by the day cycle, with their final names
// side effect: applies changes to all internal structures!
std::map<LLWLParamKey, LLWLParamSet> LLWLParamManager::finalizeFromDayCycle(LLWLParamKey::EScope scope)
{
	lldebugs << "mDay before finalizing:" << llendl;
	{
		for (std::map<F32, LLWLParamKey>::iterator iter = mDay.mTimeMap.begin(); iter != mDay.mTimeMap.end(); ++iter)
		{
			LLWLParamKey& key = iter->second;
			lldebugs << iter->first << "->" << key.name << llendl;
		}
	}

	std::map<LLWLParamKey, LLWLParamSet> final_references;

	// Move all referenced to desired scope, renaming if necessary
	// First, save skies referenced
	std::map<LLWLParamKey, LLWLParamSet> current_references; // all skies referenced by the day cycle, with their current names
	// guard against skies with same name and different scopes
	std::set<std::string> inserted_names;
	std::map<std::string, unsigned int> conflicted_names; // integer later used as a count, for uniquely renaming conflicts

	LLWLDayCycle& cycle = mDay;
	for(std::map<F32, LLWLParamKey>::iterator iter = cycle.mTimeMap.begin();
		iter != cycle.mTimeMap.end();
		++iter)
	{
		LLWLParamKey& key = iter->second;
		std::string desired_name = key.name;
		replace_newlines_with_whitespace(desired_name); // already shouldn't have newlines, but just in case
		if(inserted_names.find(desired_name) == inserted_names.end())
		{
			inserted_names.insert(desired_name);
		}
		else
		{
			// make exist in map
			conflicted_names[desired_name] = 0;
		}
		current_references[key] = mParamList[key];
	}

	// forget all old skies in target scope, and rebuild, renaming as needed
	clearParamSetsOfScope(scope);
	for(std::map<LLWLParamKey, LLWLParamSet>::iterator iter = current_references.begin(); iter != current_references.end(); ++iter)
	{
		const LLWLParamKey& old_key = iter->first;

		std::string desired_name(old_key.name);
		replace_newlines_with_whitespace(desired_name);

		LLWLParamKey new_key(desired_name, scope); // name will be replaced later if necessary

		// if this sky is one with a non-unique name, rename via appending a number
		// an existing preset of the target scope gets to keep its name
		if (scope != old_key.scope && conflicted_names.find(desired_name) != conflicted_names.end())
		{
			std::string& new_name = new_key.name;

			do
			{
				// if this executes more than once, this is an absurdly pathological case
				// (e.g. "x" repeated twice, but "x 1" already exists, so need to use "x 2")
				std::stringstream temp;
				temp << desired_name << " " << (++conflicted_names[desired_name]);
				new_name = temp.str();
			} while (inserted_names.find(new_name) != inserted_names.end());

			// yay, found one that works
			inserted_names.insert(new_name); // track names we consume here; shouldn't be necessary due to ++int? but just in case

			// *TODO factor out below into a rename()?

			LL_INFOS("Windlight") << "Renamed " << old_key.name << " (scope" << old_key.scope << ") to "
				<< new_key.name << " (scope " << new_key.scope << ")" << LL_ENDL;

			// update name in sky
			iter->second.mName = new_name;

			// update keys in day cycle
			for(std::map<F32, LLWLParamKey>::iterator frame = cycle.mTimeMap.begin(); frame != cycle.mTimeMap.end(); ++frame)
			{
				if (frame->second == old_key)
				{
					frame->second = new_key;
				}
			}

			// add to master sky map
			mParamList[new_key] = iter->second;
		}

		final_references[new_key] = iter->second;
	}

	lldebugs << "mDay after finalizing:" << llendl;
	{
		for (std::map<F32, LLWLParamKey>::iterator iter = mDay.mTimeMap.begin(); iter != mDay.mTimeMap.end(); ++iter)
		{
			LLWLParamKey& key = iter->second;
			lldebugs << iter->first << "->" << key.name << llendl;
		}
	}

	return final_references;
}
예제 #18
0
파일: keys.c 프로젝트: BitchX/BitchX1.1
/*
 * A lot of magic goes on in this function.  The general purpose of this
 * function is to take a "key-description" of any form, and canonicalize
 * it down into a resulting meta map (which is the return value), and return
 * the final character in 'term'.  Older algorithms only allowed you to 
 * specify META(X)-(Y), where X is the meta value to be returned and Y is
 * the character, and anything else was an error.  Now we allow you to specify
 * any arbitrary string -- if the leading part of the string is already bound
 * to a META key, then we can deal with that.  If the leading part of the
 * string is NOT bound to anything in particular, then we will bind it FOR
 * you, and the resulting meta state is returned.  This allows things like
 * this to work:
 *
 *	/BIND META2-C	BIND-ACTION	(Specify a meta map directly)
 *	/BIND ^[[A	BIND-ACTION	(^[[ is bound to META2 by default)
 *	/BIND ^[[11~	BIND-ACTION	(Force us to make suer ^[[11 is bound
 *					 to a meta map before returning.)
 */
static int	parse_key (const uc *sequence, uc *term)
{
	uc	*copy;
	uc	*end;
	int	return_meta = 0;
	int	meta;
	uc	last_character;
	uc	terminal_character;
	int	last;
	int	somethingN;
#ifdef GUI
	int mouse;
#endif

	/*
	 * Make a local copy of the string to be bound.  Redux all of
	 * the ^x modifers to their literal control characters.
	 */
	copy = alloca(strlen(sequence) + 4);
	copy_redux(sequence, copy);
	end = copy + strlen(copy) - 1;

#ifdef GUI
	for( mouse = 0; mouse < MAX_MOUSE; mouse++)
	{
		if (!my_strnicmp(sequence, mouse_actions[mouse], strlen(mouse_actions[mouse])))
		{
			*term=(char)mouse;
			return MAX_META;
		}
	}
#endif

	if (x_debug & DEBUG_AUTOKEY)
		yell("Starting with COPY := [%s]", copy);
	/*
	 * Remove any leading META description
	 */
	if ((meta = grok_meta(copy, (const uc **)&copy)) == -1)
		meta = 0;

	if (x_debug & DEBUG_AUTOKEY)
		yell("After META grokked, COPY := [%s]", copy);

	/*
	 * Remove any leading characters that also comprise a META
	 * description
	 */
	while (copy[0] && copy[1])
	{
		if (keys[meta] && KEY(meta, *copy) &&
				  KEY(meta, *copy)->key_index < 0)
		{
			meta = -(KEY(meta, *copy)->key_index);
			copy++;
			if (x_debug & DEBUG_AUTOKEY)
			{
				yell("First character of COPY switches to meta [%d]", meta);
				yell("After META grokked, COPY := [%s]", copy);
			}
			continue;
		}
		break;
	}

	if (x_debug & DEBUG_AUTOKEY)
		yell("After ALL META grokked, COPY := [%s]", copy);

	/*
	 * Check to see if the entire sequence was just a meta modifier
	 * or if it is a META-KEY modifier.  Either way, we're done.
	 */
	if (!copy[0] || !copy[1])
	{
		*term = copy[0];
		return meta;
	}

	/*
	 * Right now the input boils down to this:
	 *
	 * input := SOME_CHARACTERS + TERMINAL_CHARACTER + LAST_CHARACTER
	 * SOME_CHARACTERS 	:= <key>*
	 * TERMINAL_CHARACTER 	:= <key>
	 * LAST_CHARACTER 	:= <key>
	 *
	 * The previous check assures that 'terminal character' is not
	 * an empty value at this point.
	 */
	last_character = *end;
	*end-- = 0;
	terminal_character = *end;
	*end-- = 0;

	if (x_debug & DEBUG_AUTOKEY)
	{
		yell("Starting to work on the string:");
		yell("SOME_CHARACTERS := [%s] (%d)", copy, strlen(copy));
		yell("TERMINAL_CHARACTER := [%c]", terminal_character);
		yell("LAST_CHARACTER := [%c]", last_character);
	}


	/*
	 * Our ultimate goal is to return when the operation:
	 *	/bind META<something>-LAST_CHARACTER  <binding>
	 * will succeed.  So we need to find a place to put LAST_CHARACTER.
	 */
	last = return_meta = find_meta_map(last_character);
	if (x_debug & DEBUG_AUTOKEY)
	{
		yell("FIND_META_MAP says we can put [%c] in META [%d]", 
				last_character, return_meta);
	}

	/*
	 * So now we need to work backwards through the string linking
	 * each of the characters to the next one.  Starting with
	 * TERMINAL_CHARACTER, we find a meta map where that can be linked
	 * from (that map is somethingN1).  We then do:
	 *
	 *	/bind META<somethingN1>-TERMINAL_CHARACTER META<LAST>
	 *
	 * Where 'last' is the most previous meta map we linked to, starting
	 * with 'something'.
	 */
	while (*copy)
	{
		if (x_debug & DEBUG_AUTOKEY)
		{
			yell("COPY: [%s] (%d)", copy, strlen(copy));
			yell("Now we are going to bind the [%c] character to meta [%d] somehow.",
					terminal_character, last);
		}

		/*
		 * <something> is any meta map such that:
		 * /bind META<somethingN>-[TERMINAL CHARACTER] META<something>
		 */
		somethingN = find_meta_map(terminal_character);
		if (x_debug & DEBUG_AUTOKEY)
			yell("FIND_META_MAP says we can do this in META [%d]", somethingN);

		new_key(somethingN, terminal_character, -last, 1, NULL);
		show_binding(somethingN, terminal_character);

		/*
		 * Now we walk backwards in the string:  'last' now becomes
	 	 * the meta map we just linked, and we pop TERMINAL_CHARACTER
		 * off the end of SOME_CHARACTERS.  We repeat this until
		 * SOME_CHARACTERS is empty.
		 */
		last = somethingN;
		terminal_character = *end;
		*end-- = 0;
	}

	/*
	 * Make the final link from the initial meta state to our newly
	 * constructed chain...
	 */
	new_key(meta, terminal_character, -last, 1, NULL);
	show_binding(meta, terminal_character);

	/*
	 * Return the interesting information
	 */
	*term = last_character;
	return return_meta;

#if 0
	/* The rest of this isnt finished, hense is unsupported */
	say("The bind cannot occur because the character sequence to bind contains a leading substring that is bound to something else.");
	return -1;
#endif
}
예제 #19
0
  void process_site_event(OUTPUT* output) {
    // Get next site event to process.
    site_event_type site_event = *site_event_iterator_;

    // Move site iterator.
    site_event_iterator_type last = site_event_iterator_ + 1;

    // If a new site is an end point of some segment,
    // remove temporary nodes from the beach line data structure.
    if (!site_event.is_segment()) {
      while (!end_points_.empty() &&
             end_points_.top().first == site_event.point0()) {
        beach_line_iterator b_it = end_points_.top().second;
        end_points_.pop();
        beach_line_.erase(b_it);
      }
    } else {
      while (last != site_events_.end() &&
             last->is_segment() && last->point0() == site_event.point0())
        ++last;
    }

    // Find the node in the binary search tree with left arc
    // lying above the new site point.
    key_type new_key(*site_event_iterator_);
    beach_line_iterator right_it = beach_line_.lower_bound(new_key);

    for (; site_event_iterator_ != last; ++site_event_iterator_) {
      site_event = *site_event_iterator_;
      beach_line_iterator left_it = right_it;

      // Do further processing depending on the above node position.
      // For any two neighboring nodes the second site of the first node
      // is the same as the first site of the second node.
      if (right_it == beach_line_.end()) {
        // The above arc corresponds to the second arc of the last node.
        // Move the iterator to the last node.
        --left_it;

        // Get the second site of the last node
        const site_event_type& site_arc = left_it->first.right_site();

        // Insert new nodes into the beach line. Update the output.
        right_it = insert_new_arc(
            site_arc, site_arc, site_event, right_it, output);

        // Add a candidate circle to the circle event queue.
        // There could be only one new circle event formed by
        // a new bisector and the one on the left.
        activate_circle_event(left_it->first.left_site(),
                              left_it->first.right_site(),
                              site_event, right_it);
      } else if (right_it == beach_line_.begin()) {
        // The above arc corresponds to the first site of the first node.
        const site_event_type& site_arc = right_it->first.left_site();

        // Insert new nodes into the beach line. Update the output.
        left_it = insert_new_arc(
            site_arc, site_arc, site_event, right_it, output);

        // If the site event is a segment, update its direction.
        if (site_event.is_segment()) {
          site_event.inverse();
        }

        // Add a candidate circle to the circle event queue.
        // There could be only one new circle event formed by
        // a new bisector and the one on the right.
        activate_circle_event(site_event, right_it->first.left_site(),
            right_it->first.right_site(), right_it);
        right_it = left_it;
      } else {
        // The above arc corresponds neither to the first,
        // nor to the last site in the beach line.
        const site_event_type& site_arc2 = right_it->first.left_site();
        const site_event_type& site3 = right_it->first.right_site();

        // Remove the candidate circle from the event queue.
        deactivate_circle_event(&right_it->second);
        --left_it;
        const site_event_type& site_arc1 = left_it->first.right_site();
        const site_event_type& site1 = left_it->first.left_site();

        // Insert new nodes into the beach line. Update the output.
        beach_line_iterator new_node_it =
            insert_new_arc(site_arc1, site_arc2, site_event, right_it, output);

        // Add candidate circles to the circle event queue.
        // There could be up to two circle events formed by
        // a new bisector and the one on the left or right.
        activate_circle_event(site1, site_arc1, site_event, new_node_it);

        // If the site event is a segment, update its direction.
        if (site_event.is_segment()) {
          site_event.inverse();
        }
        activate_circle_event(site_event, site_arc2, site3, right_it);
        right_it = new_node_it;
      }
    }
  }
예제 #20
0
파일: getch.c 프로젝트: AgamAgarwal/minix
/*
 * Add a new key entry to the keymap pointed to by current.  Entry
 * contains the character to add to the keymap, type is the type of
 * entry to add (either multikey or leaf) and symbol is the symbolic
 * value for a leaf type entry.  The function returns a pointer to the
 * new keymap entry.
 */
static key_entry_t *
add_new_key(keymap_t *current, char chr, int key_type, int symbol)
{
	key_entry_t *the_key;
        int i, ki;

#ifdef DEBUG
	__CTRACE(__CTRACE_MISC,
	    "Adding character %s of type %d, symbol 0x%x\n",
	    unctrl(chr), key_type, symbol);
#endif
	if (current->mapping[(unsigned char) chr] < 0) {
		if (current->mapping[(unsigned char) chr] == MAPPING_UNUSED) {
			  /* first time for this char */
			current->mapping[(unsigned char) chr] =
				current->count;	/* map new entry */
			ki = current->count;

			  /* make sure we have room in the key array first */
			if ((current->count & (KEYMAP_ALLOC_CHUNK - 1)) == 0)
			{
				if ((current->key =
				     realloc(current->key,
					     ki * sizeof(key_entry_t *)
					     + KEYMAP_ALLOC_CHUNK * sizeof(key_entry_t *))) == NULL) {
					fprintf(stderr,
					  "Could not malloc for key entry\n");
					exit(1);
				}

				the_key = new_key();
				for (i = 0; i < KEYMAP_ALLOC_CHUNK; i++) {
					current->key[ki + i] = &the_key[i];
				}
			}
                } else {
			  /* the mapping was used but freed, reuse it */
			ki = - current->mapping[(unsigned char) chr];
			current->mapping[(unsigned char) chr] = ki;
		}

		current->count++;

		  /* point at the current key array element to use */
		the_key = current->key[ki];

		the_key->type = key_type;

		switch (key_type) {
		  case KEYMAP_MULTI:
			    /* need for next key */
#ifdef DEBUG
			  __CTRACE(__CTRACE_MISC, "Creating new keymap\n");
#endif
			  the_key->value.next = new_keymap();
			  the_key->enable = TRUE;
			  break;

		  case KEYMAP_LEAF:
				/* the associated symbol for the key */
#ifdef DEBUG
			  __CTRACE(__CTRACE_MISC, "Adding leaf key\n");
#endif
			  the_key->value.symbol = symbol;
			  the_key->enable = TRUE;
			  break;

		  default:
			  fprintf(stderr, "add_new_key: bad type passed\n");
			  exit(1);
		}
	} else {
		  /* the key is already known - just return the address. */
#ifdef DEBUG
		__CTRACE(__CTRACE_MISC, "Keymap already known\n");
#endif
		the_key = current->key[current->mapping[(unsigned char) chr]];
	}

        return the_key;
}