Пример #1
0
END_TEST

START_TEST (test_split_str) {
    int ret;
    s_array * words;
    s_array * exp;
    words = init_s_array(1);
    exp = init_s_array(1);
    char * string = "one.1\ttwo.2\tthree.3\0";
    append_s_array(exp, "one.1");
    append_s_array(exp, "two.2");
    append_s_array(exp, "three.3");
    ret = split_str(string, words, 3);
    ck_assert_int_eq(ret, 0);
    ck_assert_int_eq(words->length, 3);
    ck_assert_msg((s_arrays_equal(words, exp) != 0),
            "unexpected result of `split_str`");
    ret = split_str(string, words, 3);
    ck_assert_int_eq(ret, 0);
    ret = split_str(string, words, 4);
    ck_assert_int_eq(ret, 3);
    ck_assert_msg((s_arrays_equal(words, exp) != 0),
            "unexpected result of `split_str`");
    free_s_array(words);
    free_s_array(exp);
}
Пример #2
0
void* display_func(void) {

    int i, j, error;
    char message_buffer[LENGHT_MESSAGE], message_buffer_2[LENGHT_MESSAGE];
    char filename[LENGHT_MESSAGE];
    char confirm_file[LENGHT_MESSAGE];
    FILE *fp;

    while (state == 0) {

        if (recieve_data(LENGHT_MESSAGE, message_buffer) == 0)
            draw_new(global_display, "system>> recieve error");

        //draw_new(global_display, message_buffer);
        if (message_buffer[0] == '0') {
            split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
            draw_new(global_display, message_buffer_2);
        }
        else if (message_buffer[0] == '1') {
            //do nothing
        }
        else if (message_buffer[0] == '2') {
            split_str(27, strlen(message_buffer) - 2, message_buffer, message_buffer_2);
            strcpy(username, message_buffer_2);
            split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
            draw_new(global_display, message_buffer_2);
        }
        else if (message_buffer[0] == '3') {
            split_str(1, strlen(message_buffer), message_buffer, message_buffer_2);
            draw_new(global_display, message_buffer_2);
            split_str(31, strlen(message_buffer) - 1, message_buffer, filename);

            sprintf(message_buffer_2, "downloaded/%s", filename);
            fp = fopen(message_buffer_2, "w+");
            error = 1;
            do {
                recieve_file(message_buffer);
                fprintf(fp, "%c", message_buffer[1]);
            }while(message_buffer[0] != '5');
            fclose(fp);

            draw_new(global_display, "system>> Downloaded file success.");

        }

        //Reset value in message_buffer for check while loop's condition
        strcpy(message_buffer, "");
        strcpy(message_buffer_2, "");

    }

    return 0;

}
Пример #3
0
  void load_program(std::string path){
    get_pause();
    while(node_view.size() > 0){
      delete_node(node_view.begin()->second);
    }
    clear_local();


    std::ifstream cin(path, std::ios::in);
    char buffer[100];
    std::string str;
    int state = 0;
    std::getline(cin,str);
    int n_nodes = lexical_cast<int,std::string>(str);
    std::cout << "N Nodes:" << n_nodes << "\n";
    std::vector<Node *> nodes;

    for(int i = 0; i < n_nodes;i++){
      std::getline(cin,str);
      std::vector<std::string> args = split_str(str);
      float y = lexical_cast<float,std::string>(args[args.size()-1]);
      args.pop_back();
      float x = lexical_cast<float,std::string>(args[args.size()-1]);
      args.pop_back();
      std::string full_name;
      for(int i = 0; i < args.size();i++){
	full_name += args[i];
	if(i != args.size()-1){
	  full_name += " ";
	}
      }
      std::cout << full_name << "\n";
      nodes.push_back(create_and_insert_node(full_name,Vec2f(x,y)));
    }

    std::getline(cin,str);
    int n_connections = lexical_cast<int,std::string>(str);
    for(int i = 0; i < n_connections;i++){
      std::getline(cin,str);
      std::vector<std::string> args = split_str(str);
      int out_node = lexical_cast<int,std::string>(args[0]);
      int out_port = lexical_cast<int,std::string>(args[1]);
      int in_node = lexical_cast<int,std::string>(args[2]);
      int in_port = lexical_cast<int,std::string>(args[3]);
      backend.connect_nodes(nodes[out_node],nodes[in_node],out_port,in_port);

    }
    release_pause();
    cin.close();
    std::cout << "Done loading.. \n";
  }
Пример #4
0
void netif_add_from_spec(struct netif **ifs, const char *spec) {
    _free_ char *tmp = NULL;
    _free_ char **opts = NULL;

    if (!spec) return;

    tmp = strdup(spec);
    fail_if(!tmp, "OOM");

    size_t c = split_str(tmp, &opts, ":");
    fail_if(!c, "Invalid netif spec '%s': not enough args", spec);

    if (if_nametoindex(opts[0])) {
        fail_if(c < 2, "Invalid netif spec '%s': not enough args",spec);

        netif_add(ifs, MOVE, opts[0], opts[1]);
    } else if (!strncmp(opts[0], "macvlan", 8)) {
        fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);

        netif_add(ifs, MACVLAN, opts[1], opts[2]);
    } else if (!strncmp(opts[0], "ipvlan", 8)) {
        fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);

        netif_add(ifs, IPVLAN, opts[1], opts[2]);
    } else if (!strncmp(opts[0], "veth", 5)) {
        fail_if(c < 3, "Invalid netif spec '%s': not enough args",spec);

        netif_add(ifs, VETH, opts[1], opts[2]);
    } else {
        fail_printf("Invalid netif spec '%s'", spec);
    }
}
size_t bodycallback(char *ptr, size_t size, size_t nmemb, void *userdata) {
	char* pstr = (char *)ptr;

	replace_char(pstr, '\r', ':');
	char **rows = split_str(pstr, '\n');
	if (rows == NULL || rows[0] == NULL) {
		free(rows);
		return nmemb*size;
	}

	int i = 0;
	for (i = 0; rows[i]; i++) {
#ifdef DEBUG
		fprintf(stderr, "Read body line: %s\n", rows[i]);
#endif

		BODY *curbody = (BODY *) malloc(sizeof(BODY) +  strlen(rows[i]) + 1);
		curbody->row = (char *) ((char*)curbody + sizeof(BODY));
		strcpy(curbody->row, rows[i]);
		curbody->next = body;
		body = curbody;
	}

	free(rows);
	return nmemb*size;
}
Пример #6
0
static PyObject *
_diypy3__binary_tree(PyObject *self, PyObject *args)
{
    int order;
    char *bt_str;
    char *str_slice_rec[BT_MAXSIZE];
    BTNODE *T;

    if (!PyArg_ParseTuple(args, "is", &order, &bt_str))
        return NULL;
    split_str(bt_str, str_slice_rec);
    temp_rec = str_slice_rec;
    pre_order_create(&T);
    printf("binary tree initialized\n");
    switch (order) {
        case 0:
            pre_order_visualize(T);
            indent = 0;
            break;
        default:
            PyErr_SetString(PyExc_ValueError,
                            "Unrecognised flag given");
            return NULL;
    }

    Py_RETURN_NONE;
}
Пример #7
0
static PyObject *
_diypy3__triplet_sparse_matrix(PyObject *self, PyObject *args)
{
    int mu;
    int nu;
    int tu;
    char *trismx_str;
    char *str_slice_rec[TRISMX_MAXSIZE];
    TRISMX M;
    TRISMX N;

    if (!PyArg_ParseTuple(args, "iiis", &mu,
                                        &nu,
                                        &tu,
                                        &trismx_str))
        return NULL;
    split_str(trismx_str, str_slice_rec);
    temp_rec = str_slice_rec;
    create_sparse_trismx(&M, mu, nu, tu);
    printf("triplet sparse matrix initialized\n");
    visualize_trismx(&M);
    printf("fast transpose this matrix:\n");
    fast_transpose_trismx(&M, &N);
    visualize_trismx(&N);

    Py_RETURN_NONE;
}
Пример #8
0
static PyObject *
_diypy3__link_queue(PyObject *self, PyObject *args)
{
    int i;
    int rec_size;
    char *queue_str;
    char *str_slice_rec[LNKQ_MAXSIZE];
    char *deq;
    LNKQ Q;

    if (!PyArg_ParseTuple(args, "s", &queue_str))
        return NULL;
    rec_size = split_str(queue_str, str_slice_rec);
    temp_rec = str_slice_rec;
    if (!init_queue(&Q))
        return NULL;
    printf("linked list queue initialized\n");
    printf("\n");
    for (i = 0; i < rec_size; i++) {
        printf("enqueue: %s\n", temp_rec[i]);
        enqueue(&Q, temp_rec[i]);
    }
    while (Q.front != Q.rear) {
        printf("\nstatus: ");
        show_queue(Q);
        dequeue(&Q, &deq);
        printf("dequeue: %s\n", deq);
    }
    printf("\nwarning: empty queue\n");

    Py_RETURN_NONE;
}
Пример #9
0
static void	perform_cmd(t_client *client, char *cmd)
{
  char		**tab;
  int		i;
  int		n;

  tab = split_str(cmd, ' ');
  n = 0;
  while (tab && tab[n])
    n++;
  if (n == 0)
    {
      free_tab(tab);
      return ;
    }
  i = 0;
  while (i < COMMANDS)
    {
      if (!my_strcmp_case(client->commands[i].str, tab[0]))
	{
	  client->commands[i].func(client, n, tab);
	  free_tab(tab);
	  return ;
	}
      i++;
    }
}
/** 
 * One time initializations done when we want to display a new training mission.
 * 
 * This does all the processing and setup required to actually display it, including 
 * starting the voice file playing
 */
void message_training_setup(int m, int length, char *special_message)
{
	if ((m < 0) || !Messages[m].message[0]) {  // remove current message from the screen
		Training_num_lines = 0;
		return;
	}

	// translate tokens in message to the real things
	if (special_message == NULL)
		message_translate_tokens(Training_buf, Messages[m].message);
	else
		message_translate_tokens(Training_buf, special_message);

	HUD_add_to_scrollback(Training_buf, HUD_SOURCE_TRAINING);

	// moved from message_training_display() because we got rid of an extra buffer and we have to determine
	// the number of lines earlier to avoid inadvertant modification of Training_buf.  - taylor
	training_process_message(Training_buf);
	Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_lengths, Training_lines, MAX_TRAINING_MESSAGE_LINES);

	Assert( Training_num_lines >= 0 );

	if (message_play_training_voice(Messages[m].wave_info.index) < 0) {
		if (length > 0)
			Training_message_timestamp = timestamp(length * 1000);
		else
			Training_message_timestamp = timestamp(TRAINING_TIMING_BASE + strlen(Messages[m].message) * TRAINING_TIMING);  // no voice file playing

	} else
		Training_message_timestamp = 0;
}
Пример #11
0
mat utils::load_matrix(string file_path, int xdim, int ydim){
    mat tmp_mat = randu<mat>(xdim+1, ydim);

    FILE * fin = fopen(file_path.c_str(), "r");
    if (!fin) {
        printf("Can't open file %s to read!", file_path.c_str());
        exit(1);
    }

    int xidx=0;
    char buff[BUFF_SIZE_LONG];
    while (fgets(buff, BUFF_SIZE_LONG-1, fin) != NULL){
        vector<char *> line_segments = split_str(buff, ' ');
        if (line_segments.size() != (unsigned int)ydim){
            printf("Dimension of latent factor can't match with model's.\n");
            exit(1);
        }
        for (unsigned int i=0; i<line_segments.size(); i++)
            tmp_mat(xidx+1, i) = atof(line_segments[i]);
        xidx++;
        memset(buff, 0, BUFF_SIZE_LONG);
    }
   
    if (xidx != xdim){
        cout << "read number of user:"******"original number of user:"******"Number of rows can't match.\n");
        exit(1);
    }

    return tmp_mat;
}
Пример #12
0
static bool seek_to_regname(FILE *f, const char *regname)
{
	char str[1024];

	while (true) {
		fpos_t pos;
		int r;

		r = fgetpos(f, &pos);
		if (r)
			myerr2("fgetpos failed");

		if (!fgets(str, sizeof(str), f))
			return false;

		char *parts[3] = { 0 };

		r = split_str(str, ",", parts, 3);
		if (r != 3)
			myerr("Failed to parse register description: '%s'", str);

		if (strcmp(regname, parts[0]) == 0) {
			r = fsetpos(f, &pos);
			if (r)
				myerr2("fsetpos failed");

			return true;
		}

		if (!seek_to_next_reg(f))
			return false;
	}

	return false;
}
Пример #13
0
void *_job_proc(void* data)
{
	queue_item *job = (queue_item*) data;
	char **job_desc = c_calloc_2(10, 30);

	int count = split_str(job->job_description, " ", job_desc);
	if (count == 0)
	{
		fprintf(stdout, "This job has some problem!\n");
	}
	else if (!strcmp(job_desc[0], "srun"))
	{
		drun_proc(count, job_desc);
	}
	else if (!strcmp(job_desc[0], "dcancel"))
	{
		//dcancel_proc(job_origin_desc_left);
	}
	else if (!strcmp(job_desc[0], "dinfo"))
	{
		//dinfo_proc(job_origin_desc_left);
	};
	pthread_exit(NULL);
	return NULL;
}
Пример #14
0
void	print_result(float *tab, int max)
{
	char	**tmp;
	int		degree;
	char	*reduced_form;

	reduced_form = get_reduced_form(tab, max);
	ft_putstr("\033[4mReduced form:\033[0;0m");
	ft_putendl(ft_strjoin(" ", ft_strjoin(reduced_form, " = 0")));
	tmp = split_str(reduced_form);
	degree = get_degree(tmp);
	ft_putendl(ft_strjoin("Polynomial degree: ", ft_itoa(degree)));
	if (!ft_strcmp(reduced_form, "0"))
		ft_putendl("\033[32mAll real numbers are solution.");
	else if (!check_all_tab(tab, max))
	{
		ft_putendl("\033[31mThere is no solution.");
		return ;
	}
	else if (degree > 2)
		print_error(3);
	else if (degree == 0 || degree == 1)
		print_result3(tab, degree);
	else if (degree >= 2)
		print_result4(tab);
	do_mlx(tab);
}
Пример #15
0
int GetOption (char *str, char *option, int option_len, char *value,
					  int val_len)
{
	char *argv[2];
	char key [MENU_TITLE_BUF_LEN +1] = {0};
	char val [VALUE_LEN +1] = {0};
	char *p;
	int argc;

	argv[0] = key;
	argv[1] = val;

	//split string to two part,key and value ,splited by SPACE or TAB
	argc = split_str (str, argv);


	//if split to two part, return 2.
	if( argc < 2 )
		return -1;

	//remove SPACE and TAB from key and val header and tail.
	p = trim (key);
	//copy to buffer.
	strncpy (option, p, option_len - 1);

	p = trim (val);
	//remove comment data from string.
	remove_comment(p);
	strncpy (value, p, val_len -1);

	return 0;
}
Пример #16
0
/*********************************************************************
 *	文字列 *buf から、パラメータを読み取り、( adrs , memcnt ) を決める
 *********************************************************************
 */
int	get_arg(char *buf)
{
	arena = AREA_RAM;
	if(*buf == 'p') {
		buf++; arena = AREA_PGMEM;
	}else
	if(*buf == 'r') {
		buf++; arena = AREA_EEPROM;
	}
	memcnt = 64;
	adrs2 = (-1);

	buf = sp_skip(buf);
	if(*buf==0) return 0;

	arg_cnt = split_str(buf,',',arg_ptr);
	scan_args(arg_cnt);

	if(arg_cnt>=1) {
		adrs = arg_hex[0];
	}
	if(arg_cnt>=2) {
		adrs2 = arg_hex[1];
		if(adrs2 != (-1) ) {
			memcnt = adrs2 - adrs + 1;
		}
		if(	memcnt < 0) {
			memcnt = adrs2;
		}
	}
	return arg_cnt;
}
Пример #17
0
struct reg_desc *find_reg_by_address(const char *regfile, uint64_t addr)
{
	char str[1024];

	FILE *f = fopen(regfile, "r");

	ERR_ON_ERRNO(f == NULL , "Failed to open regfile %s", regfile);

	if (!seek_to_regaddr(f, addr))
		return NULL;

	if (!fgets(str, sizeof(str), f))
		ERR("Failed to parse register");

	char *parts[3] = { 0 };

	int r = split_str(str, ",", parts, 3);

	ERR_ON(r != 3, "Failed to parse register description: '%s'", str);

	struct reg_desc *reg;
	reg = malloc(sizeof(struct reg_desc));
	memset(reg, 0, sizeof(*reg));
	reg->name = strdup(parts[0]);
	reg->offset = strtoull(parts[1], NULL, 0);
	reg->width = strtoul(parts[2], NULL, 0);

	parse_reg_fields(f, reg);

	fclose(f);

	return reg;
}
Пример #18
0
 //------------------------------------------------------------------------
 string qt_dbtreemodel_impl::_value( const row *r, const string& format, const string& columns ) const
 {
     if( !r )
         return string();
     
     string          result( format );
     vector<string>  dest;
     split_str( columns, ",", dest );
     
     for( size_t i = 0; i < dest.size(); ++i )
     {
         size_t n = result.find( "%s" );
         if( n != string::npos )
         {
             try {
                 result.replace( n, 2, r->at( str_to_size_t( dest[i] ) ) );
             } catch( std::out_of_range& ) {
                 _lprintf( LOG_ERR, "Column %lu is wrong\n", dest[i].c_str() );
                 continue;
             }
         }
     }
     
     return result;
 }
Пример #19
0
smartphone_gps_t parse_raw_data(char *buffer, size_t buf_size)
{
	fprintf(stderr, "Parsing smartphone gps data: %s\n", buffer);
	smartphone_gps_t gps;

	gps.time = time(NULL);
	
	/* Latitude */
	char *token = split_str(&buffer, ",");
	gps.lat = atof(token);
		
	/* Longitude */
	token = split_str(&buffer, ",");
	gps.lng = atof(token);

	return gps;
}
Пример #20
0
void techroom_init_desc(char *src, int w)
{
	Text_size = Text_offset = 0;
	if (!src) {
		return;
	}

	Text_size = split_str(src, w, Text_line_size, Text_lines, MAX_TEXT_LINES);
	Assert(Text_size >= 0 && Text_size < MAX_TEXT_LINES);
}
Пример #21
0
int main(int argc, char **argv)
{
    rados_t cluster;
    char cluster_name[] = "ceph";
    char user_name[] = "client.admin";
    APPNAME = &argv[0][2];
    uint64_t flags;
   
    int err;

    /* Initialize the cluster handle */
    err = rados_create2(&cluster, cluster_name, user_name, flags);
    // err = rados_create(&cluster, NULL);
    error_print(err, "Couldn't create the cluster handle!", "Created a cluster handle.");
    
    /* Read a Ceph configuration file to configure the cluster handle. */
    err = rados_conf_read_file(cluster, "/etc/ceph/ceph.conf");
    error_print(err, "Cannot read config file!", "Read the config file.");

    /* Connect to the cluster */
    err = rados_connect(cluster);
    error_print(err, "Cannot connect to cluster!", "Connected to the cluster.");

    /* List pools. */
    char buf[1024];
    err = rados_pool_list(cluster, buf, 1024);
    split_str(buf, 1024);
    error_print(err, "Cannot list pools!", buf);

    /* List pool stats */
    char *poolname = strtok(buf, ",");
    while(poolname != NULL)
    {
        rados_ioctx_t io;
        struct rados_pool_stat_t stats;
        
        err = rados_ioctx_create(cluster, poolname, &io);
        error_print(err, "Cannot create IO context!", "IO context created.");

        err = rados_ioctx_pool_stat(io, &stats);
        error_print(err, "Cannot list pool stats!", "Pool stats listed.");

        printf("[%s][%s]: Number of read: %"PRIu64"\n", APPNAME, poolname, stats.num_rd);
        printf("[%s][%s]: Number of read in kb: %"PRIu64"\n", APPNAME, poolname, stats.num_rd_kb);
        printf("[%s][%s]: Number of write: %"PRIu64"\n", APPNAME, poolname, stats.num_wr);
        printf("[%s][%s]: Number of write in kb: %"PRIu64"\n", APPNAME, poolname, stats.num_wr_kb);

        rados_ioctx_destroy(io);
        poolname = strtok(NULL, ",");
    }

    /* Shut down the cluster */
    rados_shutdown(cluster);
    printf("[%s]: Cluster shut down.\n", APPNAME);
}
enum nss_status _nss_shib_getgrgid_r(gid_t gid, struct group *result, char *buffer, size_t buflen, int *errnop)
{
#ifdef DEBUG
	fprintf(stderr, "\nEntering _nss_shib_getgrgid_r with gid=%d.\n", gid);
#endif

	int ret = NSS_STATUS_UNAVAIL;
	readconfig();
	char newurl[1024];
	sprintf(newurl, "%s", url_group);
	if (!geturl(newurl, username, password, cafile, sslcheck) || body == NULL) {
		ret = NSS_STATUS_UNAVAIL;
		goto getgrgid_err;
	}

	BODY *cursor = body;
	while (cursor)
	{
		char *cur_row = cursor->row;
		int count_separator = count_char_in_str(cur_row, ':');
		char **array = split_str(cur_row, ':');

		if (array[0] != NULL  && count_separator >= 3 && atoi(array[2]) == gid)
		{
			int setting = setgroupfromarray(array, result, buffer, buflen);
			if (setting != 0) {
				if (setting == 1) {
					if(array) free(array);

					*errnop = ERANGE;
					ret = NSS_STATUS_TRYAGAIN;
				}
				else {
					ret = NSS_STATUS_UNAVAIL;
				}
				goto getgrgid_err;
			}

#ifdef DEBUG
			fprintf(stderr, "Found item for gid=%d: [name=%s]\n", gid, array[0]);
#endif

			ret = NSS_STATUS_SUCCESS;
		}

		if(array) free(array);
		cursor = cursor->next;
	}  

getgrgid_err:
	cleanbody();
	return ret;
}
Пример #23
0
	bool matches_pattern( const string& str, const string& pattern, const char* pattern_delim_chars )
	{
		std::vector<std::string> patterns = split_str( pattern, pattern_delim_chars );
		for ( auto p : patterns ) {
#ifdef FLUT_COMP_MSVC
			flut_assert_msg( strcmp( pattern_delim_chars, ";" ) == 0, "Pattern delimiter must be ';' for MSVC" );
			if ( PathMatchSpecEx( str.c_str(), p.c_str(), PMSF_NORMAL ) == S_OK )
				return true;
#else
			if ( fnmatch( p.c_str(), str.c_str(), FNM_NOESCAPE ) == 0 )
				return true;
#endif
		}
		return false;
	}
Пример #24
0
// Split off the title and break up the body lines
void popup_split_lines(popup_info *pi, int flags)
{
	int	nlines, i, body_offset = 0;
	int	n_chars[POPUP_MAX_LINES];
	const char	*p_str[POPUP_MAX_LINES];

	gr_set_font(FONT1);
	n_chars[0]=0;

	nlines = split_str(pi->raw_text, 1000, n_chars, p_str, POPUP_MAX_LINES);
	Assert(nlines >= 0 && nlines <= POPUP_MAX_LINES );

	if ( flags & (PF_TITLE | PF_TITLE_BIG) ) {
		// get first line out
		strncpy(pi->title, p_str[0], n_chars[0]);
		pi->title[n_chars[0]] = 0;
		body_offset = 1;
	}

	if ( flags & PF_BODY_BIG ) {
		gr_set_font(FONT2);
	}

	nlines = split_str(pi->raw_text, Popup_text_coords[gr_screen.res][2], n_chars, p_str, POPUP_MAX_LINES);
	Assert(nlines >= 0 && nlines <= POPUP_MAX_LINES );

	pi->nlines = nlines - body_offset;

	for ( i = 0; i < pi->nlines; i++ ) {
		Assert(n_chars[i+body_offset] < POPUP_MAX_LINE_CHARS);
		strncpy(pi->msg_lines[i], p_str[i+body_offset], n_chars[i+body_offset]);
		pi->msg_lines[i][n_chars[i+body_offset]] = 0;
	}

	gr_set_font(FONT1);
}
int lexicographic_cmp_field(char* a, char* b)
{
    char* a_tokens[MAX_NUM_TOKENS];
    char* b_tokens[MAX_NUM_TOKENS];

    char* a_dup = str_dup(a);
    char* b_dup = str_dup(b);
    split_str(a_dup, a_tokens);
    split_str(b_dup, b_tokens);

    char* a_str = a_tokens[field];
    char* b_str = b_tokens[field];

    int index;
    for (index = 0; lexicographically_equal(a_str[index], b_str[index]); ++index)
    {
        if (a_str[index] == '\0')
        {
            return 0;
        }
    }

    return (sort_reverse ? b_str[index] - a_str[index] : a_str[index] - b_str[index]);
}
Пример #26
0
 void CWord_correct::make_cache(word_cache& cache,strhash& r_index,const std::string& search_word)
 {
     std::vector<std::string> ivec;
     split_str(search_word,ivec);//将查询词汇分割成每个单字,然后存到ivec中
     std::vector<std::string>::iterator iter=ivec.begin();
     for(iter;iter!=ivec.end();iter++)
     {
         std::set<std::pair<std::string,int> > temp=r_index[*iter];
         std::set<std::pair<std::string,int> >::iterator iter=temp.begin();
         for(iter;iter!=temp.end();iter++)
         {
             std::pair<std::string,int> apair=make_pair(iter->first,iter->second);
             cache.insert(apair);    
         }
     }
 }
Пример #27
0
/*********************************************************************
 *	文字列 *buf から、パラメータを読み取り、( adrs , memcnt ) を決める
 *********************************************************************
 */
int	get_arg(char *buf)
{
#if	0
	arena = AREA_RAM;
	if(*buf == 'p') {
		buf++; arena = AREA_PGMEM;
	}else
	if(*buf == 'r') {
		buf++; arena = AREA_EEPROM;
	}
#endif
	arena=MEM_BYTE;
	if(*buf == 'b') {
		buf++; 
	}else
	if(*buf == 'h') {
		buf++; arena = MEM_HALF;
	}else
	if(*buf == 'w') {
		buf++; arena = MEM_WORD;
	}
	

//	memcnt = 64;
	memcnt = 256;
	adrs2 = (-1);

	buf = sp_skip(buf);
	if(*buf==0) return 0;

	arg_cnt = split_str(buf,',',arg_ptr);
	scan_args(arg_cnt);

	if(arg_cnt>=1) {
		adrs = arg_hex[0];
	}
	if(arg_cnt>=2) {
		adrs2 = arg_hex[1];
		if(adrs2 != (-1) ) {
			memcnt = adrs2 - adrs + 1;
		}
		if(	memcnt < 0) {
			memcnt = adrs2;
		}
	}
	return arg_cnt;
}
Пример #28
0
	bool parse_ini_conf_file(const std::string& path, INIProperties& result,
			const char* sep)
	{
		char buf[kConfigLineMax + 1];
		FILE *fp;
		if ((fp = fopen(path.c_str(), "r")) == NULL)
		{
			return false;
		}
		uint32 lineno = 1;
		std::string current_tag = "";
		while (fgets(buf, kConfigLineMax, fp) != NULL)
		{
			char* line = trim_str(buf, "\r\n\t ");
			if (line[0] == '#' || line[0] == '\0')
			{
				lineno++;
				continue;
			}
			if (line[0] == '[' && line[strlen(line) - 1] == ']')
			{
				current_tag = std::string(line + 1, strlen(line) - 2);
				lineno++;
				continue;
			}
			std::vector<char*> sp_ret = split_str(line, sep);
			if (sp_ret.size() != 2)
			{
				ERROR_LOG("Invalid config line at line:%u", lineno);
				fclose(fp);
				return false;
			}
			char* key = trim_str(sp_ret[0], "\r\n\t ");
			char* value = trim_str(sp_ret[1], "\r\n\t ");
			Properties& current_prop = result[current_tag];
			if (current_prop.find(key) != current_prop.end())
			{
				ERROR_LOG("Duplicate key:%s in config.", key);
				fclose(fp);
				return false;
			}
			current_prop[key] = value;
			lineno++;
		}
		fclose(fp);
		return true;
	}
Пример #29
0
int GetTitle(const char *str,char * title, int title_buf_len)
{
	char *argv[2];
	char key [MENU_TITLE_BUF_LEN +1] = {0};
	char value [VALUE_LEN +1] = {0};
	char *p;
	int argc, len;
  
	argv[0] = key;
	argv[1] = value;

	//Parse string.
	argc = split_str (str, argv);

	if( argc < 1 )
		return -1;

	if( argc == 1 )
	{
		//Support for OLD style lable
		len = strlen (argv[0]);
		if( argv[0][len -1] == ':')
		{
			argv[0][len -1] = '\0';
			p=trim(argv[0]);
			//remove SPACE and TAB from begin and end of string.
			strncpy(title,p,title_buf_len);
			return 0;
		}
	}
	else
	{
		//remove SPACE and TAB from begin and end of string.
		p = trim (key);
		//check key.
		if( strcasecmp (p, "title") == 0 )
		{
			//remove SPACE and TAB from begin and end of string.
			p = trim (value);
			//remove comment data from string.
			remove_comment(p);
			strncpy (title, p, title_buf_len);
			return 0;
		}
	}
	return -1;
}
Пример #30
0
 void FrameDB::add_alias(const string& line) {
   // this is a mapping from something like [unknown module] to an exe 
   // provided at symbol generation time
   vector<string> mapping;
   split_str(line, "=>", mapping);
   
   if (mapping.size() != 2) {
     cerr << "Invalid mapping in viewer-data/symbtab: " << endl;
     cerr << "    " << line << endl;
     cerr << mapping.size() << endl;
     exit(1);
   }
   
   ModuleId orig(trim(mapping[1]));
   ModuleId alias(trim(mapping[0]));
   aliases[alias] = orig;
 }