コード例 #1
0
int	count_word_char(char* str, char* charset)
{
	int	i;
	int	nb;

	i = 0;
	nb = 0;
	while (str[i])
	{
		while (str[i] && is_sep_char(str[i], charset))
			i = i + 1;
		if (str[i])
			nb = nb + 1;
		while (str[i] && !is_sep_char(str[i], charset))
			i = i + 1;
	}
	return (nb);
}
コード例 #2
0
ファイル: tree_op.c プロジェクト: gtsong/CHAP2
int assign_sp_code(char *line, struct sp_list *sp_code, int num_sp_code)
{
	char *pt;
	char buf[100];
	int i = 0;
	int num_sp = 0;

	pt = line;
	while(((*pt) != '\0') && ((*pt) != ';')) {
		buf[0] = '\0';
		if( !is_sep_char(*pt) ) {
			i = 0;
			while(!is_sep_char(*pt)) {
				buf[i++] = *pt;
				pt++;
			}
			buf[i] = '\0';
		}

		if( (buf[0] != '\0') && ((*pt) == '[') ) {
			if( num_sp < num_sp_code ) {
				strcpy(sp_code[num_sp].name, buf);
			}
			pt++;
			i = 0;
			while(!is_sep_char(*pt)) {
				buf[i++] = *pt;
				pt++;
			}
			buf[i] = '\0';
			if( (i > 0) && (num_sp < num_sp_code) ) {
				sp_code[num_sp].id = atoi(buf);
			}
			num_sp++;
			if( num_sp > num_sp_code ) {
				fatalf("overflow: number of species %d vs. %d\n", num_sp, num_sp_code);
			}
			buf[0] = '\0';
		}
		pt++;
	}
	return(num_sp);
}
コード例 #3
0
int	add_word_char(char* str, char** tab, int* i, char* charset)
{
	int	index;

	index = 0;
	while (str[index] && !is_sep_char(str[index], charset))
		index = index + 1;
	*tab = calloc(index + 1, sizeof(**tab));
	if (!*tab)
		return (1);
	*tab = id_strncpy(*tab, str, index);
	*i = *i + index;
	return (0);
}
コード例 #4
0
ファイル: http.c プロジェクト: mogi57/nmap-5.61TEST4-android
/* RFC 2616, section 2.2. */
static int is_token_char(char c)
{
    return !iscntrl((int) (unsigned char) c) && !is_sep_char((int) (unsigned char) c);
}
コード例 #5
0
ファイル: tree_op.c プロジェクト: gtsong/CHAP2
struct p_tree *read_one_line(char *one_line) {
	struct p_tree *p = NULL, *q = NULL, *t = NULL;
	struct p_tree *stack[STACK_SIZE];
	char buf[100];
	char *pt;
	int i, top = 0;
	double b_len = 1;
//	int count_gene = 0;
	int state;
	int temp_len;
	int temp_id = -1;

	pt = one_line;
	while(*pt != '\0' && *pt != ';') {
		if( !is_sep_char(*pt) ) {
			i = 0;
			while(!is_sep_char(*pt)) {
				buf[i++] = *pt;
				pt++;
			}
			buf[i] = '\0';
//			count_gene++;
			state = NAME;

			p = (struct p_tree *) ckalloc(sizeof(struct p_tree));	
			init_tree(p);
//			p->nid = count_node;
//			count_node++;
			temp_len = strlen(buf) + 1;
			p->name = (char *) ckalloc(temp_len * sizeof(char));
			strcpy(p->name, buf);
			buf[0] = '\0';
//			p->gid = count_gene;
			p->left = NULL;
			p->right = NULL;
		}

		switch (*pt) 
		{
			case ':': 
				pt++;
				if (sscanf(pt, "%lf", &b_len) != 1) {
					printf("branch length error %s\n", pt);
					exit(EXIT_FAILURE);
				}
				while (!is_sep_char(*pt))
					pt++;
				break;
				
			case '(': 
				p = (struct p_tree *) ckalloc(sizeof(struct p_tree));
				init_tree(p);
//				p->nid = count_node;
//				count_node++;
				p->left = NULL;
				p->right = NULL;
				stack[top++] = p;
				pt++;
				state = LPAR;
				break;
			
			case '[':
				pt++;
				i = 0;
				while(!is_sep_char(*pt)) {
					buf[i++] = *pt;
					pt++;
				}
				buf[i] = '\0';
				temp_id = atoi(buf);
				p->nid = temp_id;
				buf[0] = '\0';
				state = LBR;
				break;

			case ']':
				pt++;
				state = RBR;
				break;

			case ',': 
				p->b_len = b_len;
				q = stack[top-1];
				if( q->left == NULL ) {
					if( temp_id != -1 ) {
						p->sp_code = temp_id;
						temp_id = -1;
					}
					q->left = p;
				}
				else if( q->right == NULL ) {
					p->sp_code = temp_id;
					temp_id = -1;
					q->right = p;
				}
				else {
					t = (struct p_tree *) ckalloc(sizeof(struct p_tree));
					init_tree(t);
//					t->nid = count_node;
//					count_node++;
					if( temp_id != -1 ) {
						q->sp_code = temp_id;
						temp_id = -1;
					}
					t->left = q;
					t->right = NULL;
					stack[top-1] = t;
				}

				q = stack[top-1];
				p->parent = q;
				pt++;
				state = COMMA;
				break;
				
			case ')': 
				if( top == 0 ) {
					printf("tree description unbalanced\n");
					exit(EXIT_FAILURE);
				}
				else
				{
					q = stack[--top];
					p->parent = q;
					p->b_len = b_len;
					if( q->right == NULL ) 
					{
						if( temp_id != -1 ) {
							p->sp_code = temp_id;
							temp_id = -1;
						}
						q->right = p;
						p = q;
					}
					else {
						t = (struct p_tree *) ckalloc(sizeof(struct p_tree));
						init_tree(t);
//						t->nid = count_node;
//						count_node++;
						if( temp_id != -1 ) {
							p->sp_code = temp_id;
							temp_id = -1;
						}
						t->left = q;
						t->right = p;
						stack[top-1] = t;
						p = t;
					}
					pt++;
				}
				state = RPAR;
				break;
				
			case ';':
				break;

			default:
				printf("undefined symbol\n");
				exit(EXIT_FAILURE);
				break;
		}
	}

	p->b_len = 1;
	if( temp_id != -1 ) {
		p->sp_code = temp_id;
	}
	return p;
}