コード例 #1
0
ファイル: KX_FontObject.cpp プロジェクト: UPBGE/blender
void KX_FontObject::UpdateBuckets()
{
	// Update datas and add mesh slot to be rendered only if the object is not culled.
	if (m_bVisible && m_meshUser) {
		if (m_pSGNode->IsDirty()) {
			GetOpenGLMatrix();
		}

		// Allow for some logic brick control
		if (GetProperty("Text")) {
			m_text = split_string(GetProperty("Text")->GetText());
		}

		// update the animated color
		GetObjectColor().getValue(m_color);

		// Font Objects don't use the glsl shader, this color management code is copied from gpu_shader_material.glsl
		float color[4];
		if (m_do_color_management) {
			linearrgb_to_srgb_v4(color, m_color);
		}
		else {
			copy_v4_v4(color, m_color);
		}


		// HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly
		const float RES = BGE_FONT_RES * m_resolution;

		const float size = m_fsize * NodeGetWorldScaling()[0] * RES;
		const float aspect = m_fsize / size;

		// Account for offset
		MT_Vector3 offset = NodeGetWorldOrientation() * m_offset * NodeGetWorldScaling();
		// Orient the spacing vector
		MT_Vector3 spacing = NodeGetWorldOrientation() * MT_Vector3(0.0f, m_fsize * m_line_spacing, 0.0f) * NodeGetWorldScaling()[1];

		RAS_TextUser *textUser = (RAS_TextUser *)m_meshUser;

		textUser->SetColor(MT_Vector4(color));
		textUser->SetFrontFace(!m_bIsNegativeScaling);
		textUser->SetFontId(m_fontid);
		textUser->SetSize(size);
		textUser->SetDpi(m_dpi);
		textUser->SetAspect(aspect);
		textUser->SetOffset(offset);
		textUser->SetSpacing(spacing);
		textUser->SetTexts(m_text);
		textUser->ActivateMeshSlots();
	}
}
コード例 #2
0
ファイル: Settings.cpp プロジェクト: dormantor/ofxCogEngine
	void SettingItem::AddValues(string vals) {
		if (vals.find(MULTIVAL_DELIMITER) != -1) {
			// more than one value
			vector<string> multiVals; 
			split_string(vals, MULTIVAL_DELIMITER, multiVals);
			
			for (string valpart : multiVals) {
				values.push_back(valpart);
			}
		}
		else {
			values.push_back(vals);
		}
	}
コード例 #3
0
ファイル: hotkeys.cpp プロジェクト: warmist/dfhack
static void enable_display()
{
    current_bindings.clear();
    sorted_keys.clear();
    display_active = true;
    skip_frames = 2;
    page = 0;
    vector<string> generic_keys;

    auto focus_string = "@" + Gui::getFocusString(Core::getTopViewscreen());
    for (int shifted = 0; shifted < 2; shifted++)
    {
        for (int ctrl = 0; ctrl < 2; ctrl++)
        {
            for (int alt = 0; alt < 2; alt++)
            {
                for (char c = 'A'; c <= 'Z'; c++)
                {
                    string sym;
                    if (shifted) sym += "Shift-";
                    if (ctrl) sym += "Ctrl-";
                    if (alt) sym += "Alt-";
                    sym += c;

                    auto list = Core::getInstance().ListKeyBindings(sym);
                    for (auto mode = list.begin(); mode != list.end(); mode++)
                    {
                        if (mode->find(":") == string::npos)
                        {
                            current_bindings[sym] = *mode;
                            generic_keys.push_back(sym);
                        }
                        else
                        {
                            vector<string> tokens;
                            split_string(&tokens, *mode, ":");
                            if (tokens[0] == focus_string)
                            {
                                current_bindings[sym] = tokens[1];
                                sorted_keys.push_back(sym);
                            }
                        }
                    }
                }
            }
        }
    }
    sorted_keys.insert(sorted_keys.end(), generic_keys.begin(), generic_keys.end());
    resize();
}
コード例 #4
0
ファイル: dice.cpp プロジェクト: smarmy/HellRogue
int roll_dice(const std::string& die)
{
  auto num_and_sides = split_string(die, 'd');
  int num = atoi(num_and_sides[0].c_str());
  int sides = atoi(num_and_sides[1].c_str());
  int sum = 0;

  for (int i = 0; i < num; i++)
  {
    sum += random(1, sides);
  }

  return sum;
}
コード例 #5
0
void
rest_test2d (void)
{
  GOptionContext *context;
  gboolean retval;
  GError *error = NULL;
  gchar **argv;
  int argc;
#ifndef SYMBIAN  
  GOptionEntry entries [] = { 
      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
      { NULL } 
  };
#else  
  GOptionEntry entries [2];
  
  entries[0].long_name = "test";
  entries[0].short_name = 0;
  entries[0].flags = 0;
  entries[0].arg = G_OPTION_ARG_NONE;
  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  entries[0].description =  NULL;
  entries[0].arg_description = NULL;
      
  entries[1].long_name = NULL;
  entries[1].short_name = 0;
  entries[1].arg_data = NULL;
  entries[1].description =  NULL;
  entries[1].arg_description = NULL;
#endif
        
  context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, entries, NULL);

  /* Now try parsing */
  argv = split_string ("program --test -- -bar", &argc);
  
  retval = g_option_context_parse (context, &argc, &argv, &error);
  g_assert (retval);

  /* Check array */
  g_assert (ignore_test1_boolean);
  g_assert (strcmp (argv[0], "program") == 0);
  g_assert (strcmp (argv[1], "--") == 0);
  g_assert (strcmp (argv[2], "-bar") == 0);
  g_assert (argv[3] == NULL);

  g_strfreev (argv);
  g_option_context_free (context);
}
コード例 #6
0
ファイル: libip.c プロジェクト: Otti0815/picosafe_stick
int parse_ip_port(char *line, t_ip_addr *ip, int *port) {
	char *s_ip, *s_port, sep = '?';

	if ((line == NULL) || (ip == NULL) || (port == NULL)) {
		return -1;
	}

#ifdef ENABLE_IPV6
	if (split_string(line, &s_ip, &s_port, ']') == 0) {
		if ((*s_ip != '[') || (*s_port != ':')) {
			return -1;
		}
		s_ip = remove_spaces(s_ip + 1);
		s_port = remove_spaces(s_port + 1);
	} else
#endif
	{
		s_port = line + strlen(line);
		do {
			if (s_port <= line) {
				return -1;
			}
			s_port--;
		} while ((*s_port != ':') && (*s_port != '.'));
		sep = *s_port;
		*s_port = '\0';
		s_ip = remove_spaces(line);
		s_port = remove_spaces(s_port + 1);
	}

	if (parse_ip(s_ip, ip) == -1) {
		return -1;
	} else if ((*port = str2int(s_port)) <= 0) {
		return -1;
	}

	if (sep != '?') {
		if ((ip->family == AF_INET) && (sep != ':')) {
			return -1;
		}
#ifdef ENABLE_IPV6
		if ((ip->family == AF_INET6) && (sep != '.')) {
			return -1;
		}
#endif
	}

	return 0;
}
コード例 #7
0
ファイル: libHttpMessage.cpp プロジェクト: mgronhol/Saiga
// Parse given url
void URI :: parse( std::string url ){
	// Part url into (protocol, rest)
	std::vector< std::string > parts = split_string( url, "://" ); 
	std::string rest;
	
	// If something essential is missing....
	if( parts.size() < 2 ){
		// error handling
		throw std::string( "Invalid URI!" );
		return;
		}
	
	protocol = parts[0];
	
	// If there was more of the "://" parts in the url, parse them back together
	if( parts.size() > 2 ){
		for( size_t i = 1 ; i < parts.size()-1 ; ++i ){
			rest += parts[i] + std::string( "://" );
			}
		rest += parts[parts.size()-1];
		}
	else{
		rest = parts[1];
		}
	
	size_t pos = rest.find_first_of( "/" );

	// If path separator is not there default into "/"
	if( pos == std::string::npos ){
		port = "80";
		path = "/";
		host = rest;
		return;
		}
	host = rest.substr( 0, pos );
	path = rest.substr( pos, rest.size() - pos );
	
	// If no port provided
	if( host.find_first_of( ":" ) == std::string::npos ){
		port = "80";
		}
	else{
		// Parse port, find_last_of is used because of the ivp6-addresses
		pos = host.find_last_of( ":" );
		port = host.substr( pos+1, host.size()-pos );
		host = host.substr( 0, pos );
		}
	
	}
コード例 #8
0
ファイル: fs_handler.cpp プロジェクト: aidin36/tocc
  std::vector<libtocc::FileInfo> FSHandler::query_by_path(std::string path)
  {
    // We assume that each element of the path is a tag, and return
    // everything matches with it.

    std::vector<std::string> path_items = split_string(path, '/');

    // The previous step didn't find the correct result. Now, assuming
    // that all the elements in path are tags.
    std::vector<std::string>::iterator path_items_iterator = path_items.begin();

    // Adding first element to the And.
    libtocc::Tag first_tag(path_items_iterator->c_str());
    libtocc::And third_main_and(first_tag);
    path_items_iterator++;

    for (; path_items_iterator != path_items.end(); path_items_iterator++)
    {
      if (*path_items_iterator == ".." || *path_items_iterator == ".")
      {
        // Ignore . or ..
        continue;
      }

      libtocc::Tag tag_expr(path_items_iterator->c_str());
      third_main_and.add(tag_expr);
    }

    // Executing the query.
    libtocc::Query third_query(third_main_and);
    libtocc::FileInfoCollection third_query_result =
        this->libtocc_manager->search_files(third_query);

    if (third_query_result.size() > 0)
    {
      std::vector<libtocc::FileInfo> result;
      libtocc::FileInfoCollection::Iterator query_result_iterator(&third_query_result);
      for (; !query_result_iterator.is_finished(); query_result_iterator.next())
      {
        result.push_back(*query_result_iterator.get());
      }

      return result;
    }

    // Nothing found? Returning an empty result.
    std::vector<libtocc::FileInfo> result;
    return result;
  }
コード例 #9
0
void
ignore_test2 (void)
{
  GOptionContext *context;
  gboolean retval;
  GError *error = NULL;
  gchar **argv;
  int argc;
  gchar *arg;
#ifndef SYMBIAN  
  GOptionEntry entries [] =
    { { "test", 't', 0, G_OPTION_ARG_NONE, &ignore_test2_boolean, NULL, NULL },
      { NULL } };
#else      
  GOptionEntry entries [2];
  
  entries[0].long_name = "test";
  entries[0].short_name = 't';
  entries[0].flags = 0;
  entries[0].arg = G_OPTION_ARG_NONE;
  entries[0].arg_data = (gpointer)&ignore_test2_boolean;
  entries[0].description =  NULL;
  entries[0].arg_description = NULL;
      
  entries[1].long_name = NULL;
  entries[1].short_name = 0;
  entries[1].arg_data = NULL;
  entries[1].description =  NULL;
  entries[1].arg_description = NULL;
#endif      

  context = g_option_context_new (NULL);
  g_option_context_set_ignore_unknown_options (context, TRUE);
  g_option_context_add_main_entries (context, entries, NULL);

  /* Now try parsing */
  argv = split_string ("program -test", &argc);
  
  retval = g_option_context_parse (context, &argc, &argv, &error);
  g_assert (retval);

  /* Check array */
  arg = join_stringv (argc, argv);
  g_assert (strcmp (arg, "program -es") == 0);

  g_free (arg);
  g_strfreev (argv);
  g_option_context_free (context);
}
コード例 #10
0
void
array_test1 (void)
{
  GOptionContext *context;
  gboolean retval;
  GError *error = NULL;
  gchar **argv;
  int argc;
#ifndef SYMBIAN  
  GOptionEntry entries [] =
    { { "test", 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
      { NULL } };
#else     
  GOptionEntry entries [2];
  
  entries[0].long_name = "test";
  entries[0].short_name = 0;
  entries[0].flags = 0;
  entries[0].arg = G_OPTION_ARG_STRING_ARRAY;
  entries[0].arg_data = (gpointer)&array_test1_array;
  entries[0].description =  NULL;
  entries[0].arg_description = NULL;
      
  entries[1].long_name = NULL;
  entries[1].short_name = 0;
  entries[1].arg_data = NULL;
  entries[1].description =  NULL;
  entries[1].arg_description = NULL;
#endif      
        
  context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, entries, NULL);

  /* Now try parsing */
  argv = split_string ("program --test foo --test bar", &argc);
  
  retval = g_option_context_parse (context, &argc, &argv, &error);
  g_assert (retval);

  /* Check array */
  g_assert (strcmp (array_test1_array[0], "foo") == 0);
  g_assert (strcmp (array_test1_array[1], "bar") == 0);
  g_assert (array_test1_array[2] == NULL);

  g_strfreev (array_test1_array);
  
  g_strfreev (argv);
  g_option_context_free (context);
}
コード例 #11
0
void
callback_test_optional_4 (void)
{
  GOptionContext *context;
  gboolean retval;
  GError *error = NULL;
  gchar **argv;
  int argc;
#ifndef SYMBIAN  
  GOptionEntry entries [] =
    { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
	callback_parse_optional, NULL, NULL },
      { NULL } };
#else      
  GOptionEntry entries [2];
  
  entries[0].long_name = "test";
  entries[0].short_name = 't';
  entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
  entries[0].arg = G_OPTION_ARG_CALLBACK;
  entries[0].arg_data = (gpointer)callback_parse_optional;
  entries[0].description =  NULL;
  entries[0].arg_description = NULL;
      
  entries[1].long_name = NULL;
  entries[1].short_name = 0;
  entries[1].arg_data = NULL;
  entries[1].description =  NULL;
  entries[1].arg_description = NULL;
#endif      
  
  context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, entries, NULL);

  /* Now try parsing */
  argv = split_string ("program -t", &argc);
  
  retval = g_option_context_parse (context, &argc, &argv, &error);
  g_assert (retval);

  g_assert (callback_test_optional_string == NULL);
  
  g_assert (callback_test_optional_boolean);

  g_free (callback_test_optional_string);
  
  g_strfreev (argv);
  g_option_context_free (context);
}
コード例 #12
0
void		case_content(t_server *server, t_client *client, char *str)
{
  t_case	*pos;
  char		*x;
  char		*y;

  if ((x = split_string(str, ' ', 1)) != NULL)
    {
      if ((y = split_string(str, ' ', 2)) != NULL)
	{
	  pos = find_case_by_index(server->map, atoi(x), atoi(y));
	  if (pos != NULL)
	    print_resources(client, pos, atoi(x), atoi(y));
	  else
	    client->messages = append_list(client->messages, strdup("sbp\n"));
	  free(y);
	}
      else
	client->messages = append_list(client->messages, strdup("sbp\n"));
      free(x);
    }
  else
    client->messages = append_list(client->messages, strdup("sbp\n"));
}
コード例 #13
0
void		makedir(t_server *serv, char *cmd)
{
  char		*dir;

  dir = split_string(cmd, ' ', 1);
  if (dir != NULL)
    {
      if (mkdir(dir, 0775) == -1)
	swrite(serv->cfd, "552 Folder exists\r\n");
      else
	swrite(serv->cfd, "257 Folder create\r\n");
    }
  else
    swrite(serv->cfd, "501 You must enter a folder name\r\n");
}
コード例 #14
0
// parallel update new web links
void* parallel_update(void* _parallel_init_info) {
	assert(_parallel_init_info != NULL);
	parallel_i_info* info = (parallel_i_info*) _parallel_init_info;
	assert(info->w != NULL);
	assert(info->c != NULL);
	
	web* w = info->w;
	redisContext **c = info->c;
	size_t n_threads = info->n_threads;
	size_t id = info->id;
	int mod = (int)n_threads;
	redisReply *reply;
	
	reply = redisCommand(c[id], "RENAME newly.edited.linkfrom reading.edited.linkfrom");
	freeReplyObject(reply);
	reply = redisCommand(c[id], "LRANGE reading.edited.linkfrom 0 -1");
	
	//printf("LRANGE reading.edited.linkfrom 0 -1\n");
	if (reply->type == REDIS_REPLY_ARRAY) {
		for (unsigned int i = 0; i < reply->elements; ++i) {
			char* uid1 = calloc(12, sizeof(char));
			char* uid2 = calloc(12, sizeof(char));
			split_string(reply->element[i]->str, uid1, uid2, ':');
			
			int from_uid = atoi(uid2);
			int to_uid = atoi(uid1);
			int lock_id = to_uid % mod;
			
			vec_push(w->webnodes[to_uid]->in_links, from_uid);
#ifdef USE_SPINLOCK
			pthread_spin_lock(&g_spin_locks[lock_id]);
#else
			pthread_mutex_lock(&g_mutex_locks[lock_id]);
#endif
			++w->webnodes[from_uid]->out_links_num;
#ifdef USE_SPINLOCK
			pthread_spin_unlock(&g_spin_locks[lock_id]);
#else
			pthread_mutex_unlock(&g_mutex_locks[lock_id]);
#endif
		}
	}
	freeReplyObject(reply);
	reply = redisCommand(c[id], "DEL reading.edited.linkfrom");
	//printf("DEL reading.edited.linkfrom\n");
	freeReplyObject(reply);
	return NULL;
}
コード例 #15
0
ファイル: master.cpp プロジェクト: kouhate/ardb
	void Master::AddSlave(Channel* slave, RedisCommandFrame& cmd)
	{
		DEBUG_LOG("Recv sync command:%s", cmd.ToString().c_str());
		slave->Flush();
		SlaveConnection* conn = NULL;
		NEW(conn, SlaveConnection);
		conn->conn = slave;
		if (!strcasecmp(cmd.GetCommand().c_str(), "sync"))
		{
			//Redis 2.6/2.4 send 'sync'
			conn->isRedisSlave = true;
			conn->sync_offset = -1;
		} else
		{
			conn->server_key = cmd.GetArguments()[0];
			const std::string& offset_str = cmd.GetArguments()[1];
			if (!string_toint64(offset_str, conn->sync_offset))
			{
				ERROR_LOG("Invalid offset argument:%s", offset_str.c_str());
				slave->Close();
				DELETE(conn);
				return;
			}
			//Redis 2.8+ send psync, Ardb send psync2
			if (!strcasecmp(cmd.GetCommand().c_str(), "psync"))
			{
				conn->isRedisSlave = true;
			} else
			{
				conn->isRedisSlave = false;
				if (cmd.GetArguments().size() >= 3)
				{
					std::vector<std::string> ss = split_string(cmd.GetArguments()[2], "|");
					for (uint32 i = 0; i < ss.size(); i++)
					{
						DBID id;
						if (string_touint32(ss[i], id))
						{
							conn->syncdbs.insert(id);
						}
					}
				}
			}
		}
		m_server->m_service->DetachChannel(slave, true);
		ReplicationInstruction inst(conn, REPL_INSTRUCTION_ADD_SLAVE);
		OfferReplInstruction(inst);
	}
コード例 #16
0
ファイル: irrealvm.cpp プロジェクト: Alshain-Oy/IRREAL
int main( int argc, char **argv ){


	IrrealContext context;
	IrrealStack code;

	if( argc < 2 ){
		fprintf( stderr, "Usage: %s file\n\n", argv[0] );
		return 1;
		}

	init_threading();
	
	std::string text = read_file( argv[1] );
	//printf( "'%s'\n", text.c_str() );
	std::vector<std::string> tokens = split_string( text );
	for( size_t i = 0 ; i < tokens.size() ; ++i ){
		//printf( "%s\n", tokens[i].c_str() );
		code.push( extract_value( tokens[i] ) );
		}
	
	//code._debug_print();
	
	context.getCodeStack()->merge( &code, true );
	global_vm_queue.push_front( context.get_id() );
	
	++global_running_vms;
	
	pthread_t workers[ NUM_OF_THREADS ];
	pthread_attr_t attr;
	
	void *status;
	
	pthread_attr_init( &attr );
	pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE );
	
	for( size_t i = 0 ; i < NUM_OF_THREADS ; ++i ){
		pthread_create( &workers[i], &attr, worker_thread, (void *)i );
		}
	
	pthread_attr_destroy( &attr );
	
	for( size_t i = 0 ; i < NUM_OF_THREADS ; ++i ){
		pthread_join( workers[i], &status ); 
		}
	pthread_exit( NULL );
	return 0;
	}
コード例 #17
0
bool	StringToPoint2( const std::string& str , SsPoint2& point )
{
	std::vector<SsString>	str_list;
	split_string( str , ' ' , str_list );
	if ( str_list.size() < 2 )
	{
		point.x = 0;
		point.y = 0;
		return false;
	}else{
		point.x = (float)atof( str_list[0].c_str() );
		point.y = (float)atof( str_list[1].c_str() );
	}

	return true;
}
コード例 #18
0
void spawn( char * program)
{
	pid_t chpid;
	int i;
	char ** arglist = split_string(program);
	i = 0;
	chpid = fork();
	if(chpid)
		return;
	else{		
		if(execvp( arglist[0], arglist)){ // on error
			fprintf (stderr,"can't execute: %s\n",arglist[0]);
			exit(10);
		}
	}
}
コード例 #19
0
ファイル: Camera.cpp プロジェクト: angryziber/darktable
vector<int> Camera::MultipleStringToInt(const xmlChar *in, const xmlChar *tag, const char* attribute) {
  int i;
  vector<int> ret;
  vector<string> v = split_string(string((const char*)in), ' ');

  for (uint32 j = 0; j < v.size(); j++) {
#if defined(__unix__) || defined(__APPLE__) || defined(__MINGW32__)
    if (EOF == sscanf(v[j].c_str(), "%d", &i))
#else
    if (EOF == sscanf_s(v[j].c_str(), "%d", &i))
#endif
      ThrowCME("Error parsing attribute %s in tag %s, in camera %s %s.", attribute, tag, make.c_str(), model.c_str());
    ret.push_back(i);
  }
  return ret;
}
コード例 #20
0
void
arg_test3 (void)
{
  GOptionContext *context;
  gboolean retval;
  GError *error = NULL;
  gchar **argv;
  int argc;
#ifndef SYMBIAN  
  GOptionEntry entries [] =
    { { "test", 0, 0, G_OPTION_ARG_FILENAME, &arg_test3_filename, NULL, NULL },
      { NULL } };
#else      
  GOptionEntry entries [2];
  
  entries[0].long_name = "test";
  entries[0].short_name = 0;
  entries[0].flags = 0;
  entries[0].arg = G_OPTION_ARG_FILENAME;
  entries[0].arg_data = (gpointer)&arg_test3_filename;
  entries[0].description =  NULL;
  entries[0].arg_description = NULL;
      
  entries[1].long_name = NULL;
  entries[1].short_name = 0;
  entries[1].arg_data = NULL;
  entries[1].description =  NULL;
  entries[1].arg_description = NULL;
#endif      
  
  context = g_option_context_new (NULL);
  g_option_context_add_main_entries (context, entries, NULL);

  /* Now try parsing */
  argv = split_string ("program --test foo.txt", &argc);
  
  retval = g_option_context_parse (context, &argc, &argv, &error);
  g_assert (retval);

  /* Last arg specified is the one that should be stored */
  g_assert (strcmp (arg_test3_filename, "foo.txt") == 0);

  g_free (arg_test3_filename);
  
  g_strfreev (argv);
  g_option_context_free (context);
}
コード例 #21
0
ファイル: utils.c プロジェクト: pombredanne/tdl
/******************************************************************************
* string_to_dbl_array_fmt()
* Convert a formatted string to an array of doubles
*
* Parameters
* ---------
* - a formatted string
* - nrow is number of rows in converted arrays
* - ncols is the number of columns
*
* Returns
* -------
* - new array
*
* Notes
* -----
* This will take a string with formatting and convert it to an arrays
* Semi-colons are used to deliniate rows of an array.
******************************************************************************/
double *string_to_dbl_array_fmt(char *str, int *nrow, int *ncol )
{
    int     n,j,k;
    double *arr;
    char   *temp;
    char  **strarr;
    //char *dummy;

    if (str == NULL){
        *nrow = 0;
        *ncol = 0;
        return (NULL);
    }

    strarr    = split_string(str, ";",   nrow, DEFAULT);
    strarr[0] = clean_string(strarr[0], NOCOPY);
    *ncol     = num_words_in_string(strarr[0]);

    for (j=1;j<*nrow;j++){
        strarr[j] = clean_string(strarr[j], NOCOPY);
        if( *ncol != num_words_in_string(strarr[j])){
            buff_print("Error: rows and cols dont match\n");
            *nrow = 1; *ncol = 1;
            clear_str_arr(strarr);
            return (NULL);
        }
    }

    n = (*nrow) * (*ncol);
    if (n == 0) {
        clear_str_arr(strarr);
        return( (double *)NULL );
    }
    arr = new_array(n, double);

    n = 0;
    for(j=0;j<*nrow;j++){
        for(k=0;k<*ncol;k++){
            temp = get_word_from_string(strarr[j],k+1);
            arr[n] = atof(temp);
            free(temp);
            n++;
        }
    }
    clear_str_arr(strarr);
    return(&arr[0]);
}
コード例 #22
0
ファイル: config.c プロジェクト: Toeger/f-irc
void add_filter(grep_target *gpt, const char *par, int linenr)
{
	char *err = NULL;
	string_array_t parts;

	init_string_array(&parts);

	split_string(par, ",", FALSE, &parts);

	if (string_array_get_n(&parts) != 4)
		error_exit(FALSE, "Parameter(s) missing for filter: %s (line %d)\n", err, linenr);

	if (add_grep_filter(gpt, string_array_get(&parts, 3), string_array_get(&parts, 0), string_array_get(&parts, 1), string_array_get(&parts, 2), &err) == FALSE)
		error_exit(FALSE, "Failed processing filter: %s (line %d)\n", err, linenr);

	free_splitted_string(&parts);
}
コード例 #23
0
ファイル: html.c プロジェクト: JamesTFarrington/roswell
char* sbcl_bin(char* file) {
  char* str;
  LVal ret3,ret2,ret;
  cond_printf(1,"uname=%s uname-m=%s\n",uname(),uname_m());
  ret=atag_list(file);
  ret2=remove_if_not1(filter_sbcl_uri,ret);
  if(ret2==(LVal)NULL) {
    fprintf(stderr,"this architecture is not supported.stop\n");
    exit(1);
  }
  if(verbose&2)
    print_list(ret2);
  ret3= split_string(firsts(ret2),"-");
  str=q(firsts(nthcdr(1,ret3)));
  sL(ret),sL(ret2),sL(ret3);
  return str;
}
コード例 #24
0
ファイル: connection.c プロジェクト: Kafei59/epitech-projects
void		connection(t_client *cli, char *s)
{
  char		*token;

  token = split_string(s, ' ', 0);
  if (token != NULL)
    {
      if (strcasecmp(token, "/server") == 0)
	{
	  if (!cli->is_connected)
	    get_new_connection(cli, s);
	}
      else if (!cli->is_connected)
	printf("You're not connected\n");
      free(token);
    }
}
コード例 #25
0
ファイル: sound.cpp プロジェクト: FelipeBR1988/Sparky
	Sound::Sound(const std::string& name, const std::string& filename)
		: m_Name(name), m_Filename(filename), m_Playing(false), m_Count(0)
	{
		std::vector<std::string> split = split_string(m_Filename, '.');
		if (split.size() < 2)
		{
			std::cout << "[Sound] Invalid file name '" << m_Filename << "'!" << std::endl;
			return;
		}
#ifdef SPARKY_PLATFORM_WEB
#else
		m_Sound = gau_load_sound_file(filename.c_str(), split.back().c_str());
		if (m_Sound == nullptr)
			std::cout << "[Sound] Could not load file '" << m_Filename << "'!" << std::endl;
#endif

	}
コード例 #26
0
void	        accept_file(t_server *serv, t_user *user, char *cmd)
{
  t_file	*file;
  char		*nick;

  nick = split_string(cmd, ' ', 1);
  if (nick != NULL)
    {
      file = get_file_by_fromto(serv->files, nick, user->nick);
      if (file != NULL)
	sending(serv, user, file);
      else
	swrite(user->fd, "502 ERR_USERSDONTMATCH :No file to download\r\n");
    }
  else
    swrite(user->fd, "461 ERR_NEEDMOREPARAMS :Not enough parameters\r\n");
}
コード例 #27
0
ファイル: ccn-lite-ctrl.c プロジェクト: tanupoo/ccn-lite
int
add_ccnl_name(unsigned char *out, char *ccn_path)
{
    char comp[256];
    int len = 0, len2 = 0;
    int h;
    memset(comp, 0 , 256);
    len += ccnl_ccnb_mkHeader(out + len, CCN_DTAG_NAME, CCN_TT_DTAG);
    while( (h = split_string(ccn_path + len2, '/', comp)) )
    {
        len2 += h;
        len += ccnl_ccnb_mkStrBlob(out + len, CCN_DTAG_COMPONENT, CCN_TT_DTAG, comp);
        memset(comp, 0 , 256);
    }
    out[len++] = 0;
    return len;
}
コード例 #28
0
ファイル: itsh.c プロジェクト: Ponty-/Past_Projects
/** setup_command(Command* cmd)
**		Take a command struct with the command line already set.
**		Set the arguments, redirects and whether to run in the background.
*/
void setup_command(Command* cmd) {
	cmd->redirectIn = NULL;
	cmd->redirectOut = NULL;
	cmd->background = 0;
	//Split command by spaces
	int numSpaces = count_char(cmd->cmdString, ' ');
	cmd->cmdArgs = split_string(cmd->cmdString, numSpaces, " ");
	//Get the input and output redirects, storing the index of the earliest arrow word
	int lastArg = numSpaces + 1;
	for (int i = 1; i < numSpaces + 1; i++) {
		if (!strcmp("<", cmd->cmdArgs[i])) {
			if (lastArg > i) {
				lastArg = i;
			}
			i++; //Increment 'i' to the file
			//Attempt to open the file for reading (input)
			cmd->redirectIn = fopen(cmd->cmdArgs[i], "r");
			//Check for errors
			if (!cmd->redirectIn) {
				perror("Redirect input error:");
			}
		} else if (!strcmp(">", cmd->cmdArgs[i])) {
			if (lastArg > i) {
				lastArg = i;
			}
			i++; //Increment 'i' to the file
			//Attempt to open the file for writing (output)
			cmd->redirectOut = fopen(cmd->cmdArgs[i], "w");
			//Check for errors
			if (!cmd->redirectOut) {
				perror("Redirect output error:");
			}
		}
	}
	//Get whether this is to be a background process
	if (!strcmp(cmd->cmdArgs[numSpaces], "&")){
		cmd->background = 1;
		
		if (lastArg > numSpaces) {
				lastArg = numSpaces;
		}
	}
	//Set up the argument list for execing (last element null)
	cmd->numArgs = lastArg;
}
コード例 #29
0
char * generate_share_strings(char * secret, int n, int t) {
	char ** result = split_string(secret, n, t);
	
	int len = strlen(secret);
	int key_len = 6 + 2 * len + 1;
	int i;

	char * shares = malloc(key_len * n + 1);

	for (i = 0; i < n; ++i)
	{
		sprintf(shares + i * key_len, "%s\n", result[i]);
	}

	free_string_shares(result, n);

	return shares;
}
コード例 #30
0
void KX_FontObject::DrawText()
{
    /* Allow for some logic brick control */
    if(this->GetProperty("Text"))
        m_text = split_string(this->GetProperty("Text")->GetText());

    /* only draws the text if visible */
    if(this->GetVisible() == 0) return;

    /* update the animated color */
    this->GetObjectColor().getValue(m_color);

    /* HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly */
    const float RES = BGE_FONT_RES * m_resolution;

    const float size = m_fsize * this->NodeGetWorldScaling()[0] * RES;
    const float aspect = m_fsize / size;

    /* Get a working copy of the OpenGLMatrix to use */
    double mat[16];
    memcpy(mat, this->GetOpenGLMatrix(), sizeof(double)*16);

    /* Account for offset */
    MT_Vector3 offset = this->NodeGetWorldOrientation() * m_offset * this->NodeGetWorldScaling();
    mat[12] += offset[0];
    mat[13] += offset[1];
    mat[14] += offset[2];

    /* Orient the spacing vector */
    MT_Vector3 spacing = MT_Vector3(0, m_fsize*m_line_spacing, 0);
    spacing = this->NodeGetWorldOrientation() * spacing * this->NodeGetWorldScaling()[1];

    /* Draw each line, taking spacing into consideration */
    for(int i=0; i<m_text.size(); ++i)
    {
        if (i!=0)
        {
            mat[12] -= spacing[0];
            mat[13] -= spacing[1];
            mat[14] -= spacing[2];
        }
        m_rendertools->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, m_color, mat, aspect);
    }
}