예제 #1
0
파일: cparse.c 프로젝트: AkiraSuu/lagopus
/* Parse result structure. */
struct cparam *
cparam_alloc(void) {
  struct cparam *cparam;

  cparam = calloc(1, sizeof(struct cparam));
  if (cparam == NULL) {
    return NULL;
  }

  cparam->args = vector_alloc();
  if (cparam->args == NULL) {
    cparam_free(cparam);
    return NULL;
  }

  cparam->matched = vector_alloc();
  if (cparam->matched == NULL) {
    cparam_free(cparam);
    return NULL;
  }

  cparam->candidate = vector_alloc();
  if (cparam->candidate == NULL) {
    cparam_free(cparam);
    return NULL;
  }

  cparam->argv = vector_alloc();
  if (cparam->argv == NULL) {
    cparam_free(cparam);
    return NULL;
  }

  return cparam;
}
예제 #2
0
파일: dict.c 프로젝트: gebi/multipath-tools
static int
blacklist_exceptions_handler(vector strvec)
{
	conf->elist_devnode = vector_alloc();
	conf->elist_wwid = vector_alloc();
	conf->elist_device = vector_alloc();

	if (!conf->elist_devnode || !conf->elist_wwid || !conf->elist_device)
		return 1;

	return 0;
}
예제 #3
0
파일: test.c 프로젝트: kkkier/Obj-det
void main( )
{
  Matrix *m, *mT, *eig_vec_J, *eig_vec_T, *L;
  Vector *eig_val_J, *eig_val_T;
  int i, j, tt_ja, tt_ho;

  m = matrix_alloc( 100, 50 );
  for( i = 0; i < m->dim_M; i++ )
    for( j = 0; j < m->dim_N; j++ )
      { 
        M( m, i, j) = (double) i*i + 120.0;
      }

  mT = matrix_alloc( 50, 100 );
  matrix_transpose( m, mT );
  
  eig_vec_J = matrix_alloc( 100, 100 );
  eig_val_J = vector_alloc( 100  );
  L       = matrix_alloc( 100, 100 );

  matrix_prod( m, mT, L );
  Start_Clock_once( &tt_ja );
  jacobi( L, eig_val_J, eig_vec_J );
  End_ms_Clock_once( tt_ja, 1, "jacobi used " );

  printf("done with jacobi\n" );
  /* for( i = 0; i < 100; i++ ) printf(" %f", V(eig_val_J,i) );
     printf("\n");
     for( i = 0; i < 100; i++ ) printf(" %f", M(eig_vec_J,i,0) );
     printf("\n");
   */

  matrix_prod( m, mT, L );
  eig_vec_T = matrix_alloc( 100, 100 );
  eig_val_T = vector_alloc( 100  );

  Start_Clock_once( &tt_ho );
  eigen_householder( L, eig_val_T, eig_vec_T );  
  End_ms_Clock_once( tt_ho, 1, "householder used " );

  printf(" done with householder\n" );
  /* for( i = 0; i < 100; i++ ) printf(" %f", V(eig_val_T,i) );
     printf("\n");
     for( i = 0; i < 100; i++ ) printf(" %f", M(eig_vec_T,i,0) );
     printf("\n");
   */


  
}
예제 #4
0
파일: falm.c 프로젝트: sverrkva/duquad
static void init_inner_problem(const struct Struct_FALM *s, struct Struct_FGM *p_in)
{
	// Setting the inner problem to point to the outer problem except for c and z0
	// Setting the inner problem to point to the same as the outer saves some memory
	p_in->H = s->H_hat;
	p_in->lb = s->prob->lb;
	p_in->ub = s->prob->ub;
    p_in->lb_is_inf = s->info->lb_is_inf;
	p_in->ub_is_inf = s->info->ub_is_inf;
	p_in->eigH_max = s->info->eigH_max;
	p_in->eigH_min = s->info->eigH_min;

	// Make own allocation for c (This is changing for each outer iteration)
	p_in->c = vector_alloc(N);
	p_in->z0 = vector_alloc(N);

	// Allocate other necessary vectors
	p_in->zopt = vector_alloc(N);
	p_in->z = vector_alloc(N);
	p_in->y = vector_alloc(N);
	p_in->znew = vector_alloc(N);
	p_in->ynew = vector_alloc(N);
	p_in->temp1_dim_N = vector_alloc(N);

	// Initialize options
	p_in->maxiter = s->opt->maxiter_inner;
	p_in->eps = s->opt->eps_inner;
}
예제 #5
0
파일: net.c 프로젝트: amohtasham/rstm
/* =============================================================================
 * net_alloc
 * =============================================================================
 */
net_t*
net_alloc (long numNode)
{
    net_t* netPtr;

    netPtr = (net_t*)SEQ_MALLOC(sizeof(net_t));
    if (netPtr) {
        vector_t* nodeVectorPtr = vector_alloc(numNode);
        if (nodeVectorPtr == NULL) {
            SEQ_FREE(netPtr);
            return NULL;
        }
        long i;
        for (i = 0; i < numNode; i++) {
            net_node_t* nodePtr = allocNode(i);
            if (nodePtr == NULL) {
                long j;
                for (j = 0; j < i; j++) {
                    nodePtr = (net_node_t*)vector_at(nodeVectorPtr, j);
                    freeNode(nodePtr);
                }
                vector_free(nodeVectorPtr);
                SEQ_FREE(netPtr);
                return NULL;
            }
            bool_t status = vector_pushBack(nodeVectorPtr, (void*)nodePtr);
            assert(status);
        }
        netPtr->nodeVectorPtr = nodeVectorPtr;
    }

    return netPtr;
}
예제 #6
0
/* Data initialization */
int
init_data(char *conf_file, void (*init_keywords) (void))
{
	int r;

	if (!keywords)
		keywords = vector_alloc();
	if (!keywords)
		return 1;
	stream = fopen(conf_file, "r");
	if (!stream) {
		syslog(LOG_WARNING, "Configuration file open problem");
		return 1;
	}

	/* Init Keywords structure */
	(*init_keywords) ();

/* Dump configuration *
  vector_dump(keywords);
  dump_keywords(keywords, 0);
*/

	/* Stream handling */
	r = process_stream(keywords);
	fclose(stream);
	//free_keywords(keywords);

	return r;
}
예제 #7
0
eng_table_t* eng_table_init() {
    eng_table_t* eng_table = my_malloc(sizeof(eng_table_t));
    
//    eng_table->eng_datas = vector_alloc((vector_entry_free_func)eng_data_destroy);
    eng_table->eng_keys = vector_alloc((vector_entry_free_func)eng_data_destroy);
    return eng_table;
}
예제 #8
0
static void
dpdk_interface_set_index(struct interface *ifp) {
  if (ifp_vector == NULL) {
    ifp_vector = vector_alloc();
  }
  vector_set_index(ifp_vector, ifp->info.eth_dpdk_phy.port_number, ifp);
}
예제 #9
0
int
_install_keyword(vector keywords, char *string,
		 int (*handler) (struct config *, vector),
		 int (*print) (struct config *, char *, int, void *), int unique)
{
	int i = 0;
	struct keyword *keyword;

	/* fetch last keyword */
	keyword = VECTOR_SLOT(keywords, VECTOR_SIZE(keywords) - 1);

	/* position to last sub level */
	for (i = 0; i < sublevel; i++)
		keyword =
		    VECTOR_SLOT(keyword->sub, VECTOR_SIZE(keyword->sub) - 1);

	/* First sub level allocation */
	if (!keyword->sub)
		keyword->sub = vector_alloc();

	if (!keyword->sub)
		return 1;

	/* add new sub keyword */
	return keyword_alloc(keyword->sub, string, handler, print, unique);
}
예제 #10
0
vector_t *
alloc_strvec(char *string)
{
	char *cp, *start, *token;
	size_t str_len;
	vector_t *strvec;

	if (!string)
		return NULL;

	cp = string;

	/* Skip white spaces */
	while (isspace((int) *cp) && *cp != '\0')
		cp++;

	/* Return if there is only white spaces */
	if (*cp == '\0')
		return NULL;

	/* Return if string begin with a comment */
	if (*cp == '!' || *cp == '#')
		return NULL;

	/* Create a vector and alloc each command piece */
	strvec = vector_alloc();

	while (1) {
		start = cp;

		/* Save a quoted string without the "s as a single string */
		if (*cp == '"') {
			start++;
			if (!(cp = strchr(start, '"'))) {
				log_message(LOG_INFO, "Unmatched quote: '%s'", string);
				return strvec;
			}
			str_len = (size_t)(cp - start);
			cp++;
		} else {
			while (!isspace((int) *cp) && *cp != '\0' && *cp != '"'
						   && *cp != '!' && *cp != '#')
				cp++;
			str_len = (size_t)(cp - start);
		}
		token = MALLOC(str_len + 1);
		memcpy(token, start, str_len);
		token[str_len] = '\0';

		/* Alloc & set the slot */
		vector_alloc_slot(strvec);
		vector_set_slot(strvec, token);

		while (isspace((int) *cp) && *cp != '\0')
			cp++;
		if (*cp == '\0' || *cp == '!' || *cp == '#')
			return strvec;
	}
}
예제 #11
0
int
load_keys (void)
{
	int r = 0;
	keys = vector_alloc();

	if (!keys)
		return 1;

	r += add_key(keys, "list", LIST, 0);
	r += add_key(keys, "show", LIST, 0);
	r += add_key(keys, "add", ADD, 0);
	r += add_key(keys, "remove", DEL, 0);
	r += add_key(keys, "del", DEL, 0);
	r += add_key(keys, "switch", SWITCH, 0);
	r += add_key(keys, "switchgroup", SWITCH, 0);
	r += add_key(keys, "suspend", SUSPEND, 0);
	r += add_key(keys, "resume", RESUME, 0);
	r += add_key(keys, "reinstate", REINSTATE, 0);
	r += add_key(keys, "fail", FAIL, 0);
	r += add_key(keys, "resize", RESIZE, 0);
	r += add_key(keys, "reset", RESET, 0);
	r += add_key(keys, "reload", RELOAD, 0);
	r += add_key(keys, "forcequeueing", FORCEQ, 0);
	r += add_key(keys, "disablequeueing", DISABLEQ, 0);
	r += add_key(keys, "restorequeueing", RESTOREQ, 0);
	r += add_key(keys, "paths", PATHS, 0);
	r += add_key(keys, "maps", MAPS, 0);
	r += add_key(keys, "multipaths", MAPS, 0);
	r += add_key(keys, "path", PATH, 1);
	r += add_key(keys, "map", MAP, 1);
	r += add_key(keys, "multipath", MAP, 1);
	r += add_key(keys, "group", GROUP, 1);
	r += add_key(keys, "reconfigure", RECONFIGURE, 0);
	r += add_key(keys, "daemon", DAEMON, 0);
	r += add_key(keys, "status", STATUS, 0);
	r += add_key(keys, "stats", STATS, 0);
	r += add_key(keys, "topology", TOPOLOGY, 0);
	r += add_key(keys, "config", CONFIG, 0);
	r += add_key(keys, "blacklist", BLACKLIST, 0);
	r += add_key(keys, "devices", DEVICES, 0);
	r += add_key(keys, "raw", RAW, 0);
	r += add_key(keys, "wildcards", WILDCARDS, 0);
	r += add_key(keys, "quit", QUIT, 0);
	r += add_key(keys, "exit", QUIT, 0);
	r += add_key(keys, "shutdown", SHUTDOWN, 0);
	r += add_key(keys, "getprstatus", GETPRSTATUS, 0);
	r += add_key(keys, "setprstatus", SETPRSTATUS, 0);
	r += add_key(keys, "unsetprstatus", UNSETPRSTATUS, 0);
	r += add_key(keys, "format", FMT, 1);
	r += add_key(keys, "json", JSON, 0);

	if (r) {
		free_keys(keys);
		keys = NULL;
		return 1;
	}
	return 0;
}
예제 #12
0
vector_t *
read_value_block(vector_t *strvec)
{
	char *buf;
	unsigned int word;
	char *str = NULL;
	char *dup;
	vector_t *vec = NULL;
	vector_t *elements = vector_alloc();
	int first = 1;
	int need_bob = 1;
	int got_eob = 0;

	buf = (char *) MALLOC(MAXBUF);
	while (first || read_line(buf, MAXBUF)) {
		if (first && vector_size(strvec) > 1) {
			vec = strvec;
			word = 1;
		}
		else {
			vec = alloc_strvec(buf);
			word = 0;
		}
		if (vec) {
			str = vector_slot(vec, word);
			if (need_bob) {
				if (!strcmp(str, BOB))
					word++;
				else
					log_message(LOG_INFO, "'{' missing at beginning of block %s", FMT_STR_VSLOT(strvec,0));
				need_bob = 0;
			}

			for (; word < vector_size(vec); word++) {
				str = vector_slot(vec, word);
				if (!strcmp(str, EOB)) {
					if (word != vector_size(vec) - 1)
						log_message(LOG_INFO, "Extra characters after '}' - \"%s\"", buf);
					got_eob = 1;
					break;
				}
				dup = (char *) MALLOC(strlen(str) + 1);
				memcpy(dup, str, strlen(str));
				vector_alloc_slot(elements);
				vector_set_slot(elements, dup);
			}
			if (vec != strvec)
				free_strvec(vec);
			if (got_eob)
				break;
		}
		memset(buf, 0, MAXBUF);
		first = 0;
	}

	FREE(buf);
	return elements;
}
예제 #13
0
static int
blacklist_exceptions_handler(struct config *conf, vector strvec)
{
	if (!conf->elist_devnode)
		conf->elist_devnode = vector_alloc();
	if (!conf->elist_wwid)
		conf->elist_wwid = vector_alloc();
	if (!conf->elist_device)
		conf->elist_device = vector_alloc();
	if (!conf->elist_property)
		conf->elist_property = vector_alloc();

	if (!conf->elist_devnode || !conf->elist_wwid ||
	    !conf->elist_device || !conf->elist_property)
		return 1;

	return 0;
}
예제 #14
0
int
alloc_handlers (void)
{
	handlers = vector_alloc();

	if (!handlers)
		return 1;

	return 0;
}
예제 #15
0
파일: dict.c 프로젝트: gebi/multipath-tools
/*
 * multipaths block handlers
 */
static int
multipaths_handler(vector strvec)
{
	conf->mptable = vector_alloc();

	if (!conf->mptable)
		return 1;

	return 0;
}
예제 #16
0
vector
read_value_block(void)
{
	char *buf;
	int i;
	char *str = NULL;
	char *dup;
	vector vec = NULL;
	vector elements = vector_alloc();

	if (!elements)
		return NULL;

	buf = (char *) MALLOC(MAXBUF);

	if (!buf)
		return NULL;

	while (read_line(buf, MAXBUF)) {
		vec = alloc_strvec(buf);
		if (vec) {
			str = VECTOR_SLOT(vec, 0);
			if (!strcmp(str, EOB)) {
				free_strvec(vec);
				break;
			}

			if (VECTOR_SIZE(vec))
				for (i = 0; i < VECTOR_SIZE(vec); i++) {
					str = VECTOR_SLOT(vec, i);
					dup = (char *) MALLOC(strlen(str) + 1);
					if (!dup)
						goto out;
					memcpy(dup, str, strlen(str));

					if (!vector_alloc_slot(elements)) {
						free_strvec(vec);
						goto out1;
					}

					vector_set_slot(elements, dup);
				}
			free_strvec(vec);
		}
		memset(buf, 0, MAXBUF);
	}
	FREE(buf);
	return elements;
out1:
	FREE(dup);
out:
	FREE(buf);
	return NULL;
}
예제 #17
0
static void
testCounts (adtree_t* adtreePtr, data_t* dataPtr)
{
    long numVar = dataPtr->numVar;
    vector_t* queryVectorPtr = vector_alloc(numVar);
    long v;
    for (v = -1; v < numVar; v++) {
        testCount(adtreePtr, dataPtr, queryVectorPtr, v, dataPtr->numVar);
    }
    vector_free(queryVectorPtr);
}
예제 #18
0
파일: maze.c 프로젝트: Ikulagin/transmem
/* =============================================================================
 * maze_alloc
 * =============================================================================
 */
maze_t*
maze_alloc ()
{
    maze_t* mazePtr;

    mazePtr = (maze_t*)malloc(sizeof(maze_t));
    if (mazePtr) {
        mazePtr->gridPtr = NULL;
        mazePtr->workQueuePtr = queue_alloc(1024);
        mazePtr->wallVectorPtr = vector_alloc(1);
        mazePtr->srcVectorPtr = vector_alloc(1);
        mazePtr->dstVectorPtr = vector_alloc(1);
        assert(mazePtr->workQueuePtr &&
               mazePtr->wallVectorPtr &&
               mazePtr->srcVectorPtr &&
               mazePtr->dstVectorPtr);
    }

    return mazePtr;
}
예제 #19
0
/*
 * devices block handlers
 */
static int
devices_handler(struct config *conf, vector strvec)
{
	if (!conf->hwtable)
		conf->hwtable = vector_alloc();

	if (!conf->hwtable)
		return 1;

	return 0;
}
예제 #20
0
파일: port.c 프로젝트: roccen/lagopus
struct vector *
ports_alloc(void) {
  struct vector *v;

  v = vector_alloc();
  if (v == NULL) {
    return NULL;
  }

  return v;
}
예제 #21
0
/*
 * multipaths block handlers
 */
static int
multipaths_handler(struct config *conf, vector strvec)
{
	if (!conf->mptable)
		conf->mptable = vector_alloc();

	if (!conf->mptable)
		return 1;

	return 0;
}
예제 #22
0
vector_t *
alloc_strvec(char *string)
{
	char *cp, *start, *token;
	int str_len;
	vector_t *strvec;

	if (!string)
		return NULL;

	cp = string;

	/* Skip white spaces */
	while (isspace((int) *cp) && *cp != '\0')
		cp++;

	/* Return if there is only white spaces */
	if (*cp == '\0')
		return NULL;

	/* Return if string begin with a comment */
	if (*cp == '!' || *cp == '#')
		return NULL;

	/* Create a vector and alloc each command piece */
	strvec = vector_alloc();

	while (1) {
		start = cp;
		if (*cp == '"') {
			cp++;
			token = MALLOC(2);
			*(token) = '"';
			*(token + 1) = '\0';
		} else {
			while (!isspace((int) *cp) && *cp != '\0' && *cp != '"')
				cp++;
			str_len = cp - start;
			token = MALLOC(str_len + 1);
			memcpy(token, start, str_len);
			*(token + str_len) = '\0';
		}

		/* Alloc & set the slot */
		vector_alloc_slot(strvec);
		vector_set_slot(strvec, token);

		while (isspace((int) *cp) && *cp != '\0')
			cp++;
		if (*cp == '\0' || *cp == '!' || *cp == '#')
			return strvec;
	}
}
예제 #23
0
void cmd_bucket_init() {
    cq_cmd_bucket = my_malloc(sizeof(cmd_bucket_t));
    cq_cmd_bucket->cmd_lists =
        vector_alloc((vector_entry_free_func)cmd_list_destroy);

    if (NULL == cq_cmd_bucket->cmd_lists) {
        log_error("init cmd vector failed!");
        abort();
    }

    return;
}
예제 #24
0
파일: vector.c 프로젝트: takayuki/al
int
main ()
{
    vector_t* vectorPtr;
    vector_t* copyVectorPtr;
    long data[] = {3, 1, 4, 1, 5, -1};
    long i;

    puts("Starting...");

    vectorPtr = vector_alloc(1);
    copyVectorPtr = vector_alloc(1);

    for (i = 0; data[i] >= 0; i++) {
        insertInt(vectorPtr, &data[i]);
    }

    vector_copy(copyVectorPtr, vectorPtr);

    while (i-- > 0) {
        removeInt(vectorPtr);
    }

    printf("copy ");
    printVector(copyVectorPtr);
    printf("sort ");
    vector_sort(copyVectorPtr, &compareInt);
    printVector(copyVectorPtr);

    vector_free(vectorPtr);
    vector_free(copyVectorPtr);

    puts("Done.");

    return 0;
}
예제 #25
0
/* =============================================================================
 * stream_alloc
 * =============================================================================
 */
stream_t*
stream_alloc (long percentAttack)
{
    stream_t* streamPtr;

    streamPtr = (stream_t*)malloc(sizeof(stream_t));
    if (streamPtr) {
        streamPtr->percentAttack = percentAttack;
        streamPtr->randomPtr = random_alloc();
        streamPtr->allocVectorPtr = vector_alloc(1);
        streamPtr->packetQueuePtr = queue_alloc(-1);
        streamPtr->attackMapPtr = MAP_ALLOC(NULL, NULL);
    }

    return streamPtr;
}
예제 #26
0
/* Standard allocation function, with initialization of the elements. */
matrix_t* matrix_alloc(size_t nbrows, size_t nbcols, bool s)
{
    size_t i;

    assert(nbcols>0 || nbrows==0);

    matrix_t* mat = (matrix_t*)malloc(sizeof(matrix_t));
    mat->nbrows = mat->_maxrows = nbrows;
    mat->nbcolumns = nbcols;
    mat->_sorted = s;
    mat->p = (numint_t**)malloc(nbrows * sizeof(numint_t*));
    for (i=0; i<nbrows; i++) {
        mat->p[i] = vector_alloc(nbcols);
    }
    return mat;
}
예제 #27
0
파일: cnode.c 프로젝트: D-TOKIOKA/lagopus
struct cnode *
cnode_alloc(void) {
  struct cnode *cnode;

  cnode = (struct cnode *)calloc(1, sizeof(struct cnode));
  if (cnode == NULL) {
    return NULL;
  }

  cnode->v = vector_alloc();
  if (cnode->v == NULL) {
    cnode_free(cnode);
    return NULL;
  }

  return cnode;
}
예제 #28
0
struct adapter_group *
alloc_adaptergroup(void)
{
	struct adapter_group *agp;

	agp = (struct adapter_group *)MALLOC(sizeof(struct adapter_group));

	if (!agp)
		return NULL;

	agp->host_groups = vector_alloc();
	if (!agp->host_groups) {
		FREE(agp);
		agp = NULL;
	}
	return agp;
}
예제 #29
0
/* Data initialization */
void
init_data(char *conf_file, vector_t * (*init_keywords) (void))
{
	/* Init Keywords structure */
	keywords = vector_alloc();
	(*init_keywords) ();

#if 0
	/* Dump configuration */
	vector_dump(keywords);
	dump_keywords(keywords, 0);
#endif

	/* Stream handling */
	current_keywords = keywords;
	read_conf_file((conf_file) ? conf_file : CONF);
	free_keywords(keywords);
}
예제 #30
0
struct pathgroup *
alloc_pathgroup (void)
{
	struct pathgroup * pgp;

	pgp = (struct pathgroup *)MALLOC(sizeof(struct pathgroup));

	if (!pgp)
		return NULL;

	pgp->paths = vector_alloc();

	if (!pgp->paths) {
		FREE(pgp);
		pgp = NULL;
	}

	return pgp;
}