예제 #1
0
파일: alist.c 프로젝트: jnbek/TekNap
Array_item *add_to_array (Array *array, Array_item *item)
{
	int count;
	int location = 0;
	Array_item *ret = (void *) 0 ;
	u_32int_t       mask;    

	if (array->hash == HASH_INSENSITIVE)
		item->hash = ci_alist_hash(item->name, &mask);
	else
		item->hash = cs_alist_hash(item->name, &mask);

	check_array_size(array);
	if (array->max)
	{
		find_array_item(array, item->name, &count, &location);
		if (count < 0)
		{
			ret = ((Array_item *) (( array ) -> list [ (  location ) ])) ;
			array->max--;
		}
		else
			move_array_items(array, location, array->max, 1);
	}

	array->list[location] = item;
	array->max++;
	return ret;
}
예제 #2
0
파일: alist.c 프로젝트: Cloudxtreme/bitchx
/*
 * Returns an entry that has been displaced, if any.
 */
Array_item *BX_add_to_array (Array *array, Array_item *item)
{
	int count;
	int location = 0;
	Array_item *ret = NULL;
	u_32int_t       mask;   /* Dummy var */

	if (array->hash == HASH_INSENSITIVE)
		item->hash = ci_alist_hash(item->name, &mask);
	else
		item->hash = cs_alist_hash(item->name, &mask);

	check_array_size(array);
	if (array->max)
	{
		find_array_item(array, item->name, &count, &location);
		if (count < 0)
		{
			ret = ARRAY_ITEM(array, location);
			array->max--;
		}
		else
			move_array_items(array, location, array->max, 1);
	}

	array->list[location] = item;
	array->max++;
	return ret;
}
예제 #3
0
파일: fset.c 프로젝트: BitchX/BitchX1.2
void add_new_fset(char *name, char *args)
{
	if (args && *args)
	{
		IrcVariable *tmp = NULL;
		int cnt, loc;
		tmp = (IrcVariable *)find_array_item((Array *)&ext_fset_list, name, &cnt, &loc);
		if (!tmp || cnt >= 0)
		{
			tmp = new_malloc(sizeof(IrcVariable));
			tmp->name = m_strdup(name);
			tmp->type = STR_TYPE_VAR;
			add_to_array((Array *)&ext_fset_list, (Array_item *)tmp);
		}
		malloc_strcpy(&tmp->string, args);
	}
	else 
	{
		IrcVariable *tmp;
		if ((tmp = (IrcVariable *)remove_from_array((Array *)&ext_fset_list, name)))
		{
			new_free(&tmp->name);
			new_free(&tmp->string);
			new_free(&tmp);
		}
	}
}
예제 #4
0
파일: fset.c 프로젝트: BitchX/BitchX1.2
IrcVariable *find_ext_fset_var(char *name)
{
IrcVariable *tmp = NULL;
int loc, cnt;
	tmp = (IrcVariable *)find_array_item((Array *)&ext_fset_list, name, &cnt, &loc);
	if (tmp && cnt < 0)
		return tmp;
	return NULL;
}
예제 #5
0
파일: alist.c 프로젝트: carriercomm/epic4
array_item *array_lookup (array *a, const char *name, int wild, int rem)
{
	int 	count, 
		location;

	if (rem)
		return remove_from_array(a, name);
	else
		return find_array_item(a, name, &count, &location);
}
예제 #6
0
파일: alist.c 프로젝트: Cloudxtreme/bitchx
/*
 * Returns the entry that has been removed, if any.
 */
Array_item *BX_remove_from_array (Array *array, char *name)
{
	int count, location = 0;

	if (array->max)
	{
		find_array_item(array, name, &count, &location);
		if (count >= 0)
			return NULL;

		return array_pop(array, location);
	}
	return NULL;	/* Cant delete whats not there */
}
예제 #7
0
파일: alist.c 프로젝트: jnbek/TekNap
Array_item *remove_from_array (Array *array, char *name)
{
	int count, location = 0;

	if (array->max)
	{
		find_array_item(array, name, &count, &location);
		if (count >= 0)
			return (void *) 0 ;

		return array_pop(array, location);
	}
	return (void *) 0 ;	 
}
예제 #8
0
파일: alist.c 프로젝트: Cloudxtreme/bitchx
/*
 * Returns the entry that has been removed, if any.
 */
Array_item *BX_remove_all_from_array (Array *array, char *name)
{
	int count, location = 0;
	Array_item *ret = NULL;

	if (array->max)
	{
		find_array_item(array, name, &count, &location);
		if (count == 0)
			return NULL;
		ret = ARRAY_ITEM(array, location);
		move_array_items(array, location + 1, array->max, -1);
		array->max--;
		return ret;
	}
	return NULL;	/* Cant delete whats not there */
}
예제 #9
0
파일: alist.c 프로젝트: jnbek/TekNap
Array_item *remove_all_from_array (Array *array, char *name)
{
	int count, location = 0;
	Array_item *ret = (void *) 0 ;

	if (array->max)
	{
		find_array_item(array, name, &count, &location);
		if (count == 0)
			return (void *) 0 ;
		ret = ((Array_item *) (( array ) -> list [ (  location ) ])) ;
		move_array_items(array, location + 1, array->max, -1);
		array->max--;
		return ret;
	}
	return (void *) 0 ;	 
}
예제 #10
0
파일: confparse.c 프로젝트: cygsxak/memlink
int    
confparser_parse(ConfParser* parser)
{
    FILE *f;

    f = fopen(parser->filename, "r");
    if (NULL == f)
        return -1;
    
    char buf[4096];
    char *pstart;
    int  lineno = 0;
    char key[100] = {0};
    while (fgets(buf, 4096, f) != NULL) {
        pstart = buf;
        lineno++;

        while (isblank(*pstart)) pstart++;
        if (pstart[0] == '#' || pstart[0] == '\r' || pstart[0] == '\n') {
            continue;
        }

        if (*pstart == '=') {
            DERROR("config file parse error! not key at line:%d\n", lineno);
            fclose(f);
            return -1;
        }

        char *sp = strchr(pstart, '=');
        if (sp == NULL) {
            if (*key == '\0') {
                DERROR("config file parse error! \"=\" not found at line:%d\n", lineno);
                fclose(f);
                return -1;
            }
        } else {
            char *end = sp - 1;
            while (end > pstart && isblank(*end)) {
                end--;
            }
            *(end + 1) = 0;
            strcpy(key, pstart);

            pstart = sp + 1;
            while (isblank(*pstart)) pstart++;
            if (*pstart == '\r' || *pstart == '\n')
                continue;
        }
        clean_end(pstart);
            

        
        ConfParam *param = parser->params;
        char *tmp = NULL, *item = NULL;
        while (param) {
            if (strcmp(param->name, key) == 0) {
            //    lastname = param->name;
                if (param->arraysize && param->dsti >= param->arraysize) {
                    DERROR("config parser error, too many items: %s line:%d\n", param->name, lineno);
                    fclose(f);
                    return -1;
                }
                switch(param->type) {
                case CONF_INT:
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            ((int*)param->dst)[param->dsti] = atoi(item);
                            //DERROR("%d\n", ((int*)param->dst)[param->dsti]);
                            param->dsti++;
                        }
                    }else{
                        *(int*)param->dst = atoi(pstart);
                    }
                    break;
                case CONF_FLOAT:
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            ((float*)param->dst)[param->dsti] = atof(item);
                            param->dsti++;
                        }
                    }else{
                        *(float*)param->dst = atof(pstart);
                    }
                    break;
                case CONF_STRING: 
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            snprintf(((char**)param->dst)[param->dsti], 1024, "%s", item);
                            param->dsti++;
                        }
                    }else{
                        snprintf((char*)param->dst, 1024, "%s", pstart);
                    }
                    break;
                case CONF_BOOL: {
                    int v = 0;    
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            v = bool_check(item);
                            if (v < 0) {
                                DERROR("conf error, %s must yes/no true/false at line:%d\n", 
                                            param->name, lineno);
                                fclose(f);
                                return -1;
                            }

                            ((int*)param->dst)[param->dsti] = v;
                            param->dsti++;
                        }
                    }else{
                        v = bool_check(pstart);
                        if (v < 0) {
                            DERROR("conf error, %s must yes/no true/false at line:%d\n", 
                                        param->name, lineno);
                            fclose(f);
                            return -1;
                        }
                        *(int*)param->dst = v;
                    }
                    break;
                }
                case CONF_ENUM: { // 枚举只能是整型
                    int v = 0;
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            if (enum_check(param, pstart, &v) == FALSE) {
                                DERROR("conf error, %s value error at line:%d\n", param->name, lineno);
                                fclose(f);
                                return -1;
                            }
                            ((int*)param->dst)[param->dsti] = v;
                            param->dsti++;
                        }
                    }else{
                        if (enum_check(param, pstart, &v) == FALSE) {
                            DERROR("conf error, %s value error at line:%d\n", param->name, lineno);
                            fclose(f);
                            return -1;
                        }
                        *(int*)param->dst = v;
                    }
                    break;
                }
                case CONF_USER: {
                    if (param->arraysize) {
                        while ((item = find_array_item(pstart, &tmp)) != NULL) {
                            if (param->param.userfunc(param->dst, item, param->dsti) == FALSE) {
                                DERROR("conf error, %s value error at line:%d\n", param->name, lineno);
                                fclose(f);
                                return -1;
                            }
                            //((int*)param->dst)[param->dsti] = v;
                            param->dsti++;
                        }
                    }else{
                        if (param->param.userfunc(param->dst, pstart, 0) == FALSE) {
                            DERROR("conf error, %s value error at line:%d\n", param->name, lineno);
                            fclose(f);
                            return -1;
                        }
                        //*(int*)param->dst = v;
                    }

                    break;
                }
                default:
                    DERROR("conf param type error at %s with type:%d\n", param->name, param->type);
                    fclose(f);
                    return -1;
                }
                break;
            }
            param = param->next;
        }
    }

    fclose(f);
    return 0;
}