Example #1
0
extern struct window_info* window_info_init(char* title, si_t maxable, si_t minable, si_t modal)
{
	struct window_info* win_info_ptr = (struct window_info*)malloc(sizeof(struct window_info));
	if(NULL == win_info_ptr)
	{
		EGUI_PRINT_SYS_ERROR("failed to malloc window info status for window %s. malloc()", title);
		return NULL;
	}

    win_info_ptr->parent = NULL;
    win_info_ptr->lchild = NULL;
    win_info_ptr->rchild = NULL;
    win_info_ptr->name = "struct window_info";

	win_info_ptr->title = malloc(strlen(title) + 1);
	if(NULL == win_info_ptr->title)
	{
		EGUI_PRINT_SYS_ERROR("failed to malloc title for window %s. malloc()", title);
		free(win_info_ptr);
		return NULL; 
	}
    strncpy(win_info_ptr->title, title, strlen(title) + 1);

    /* 调用请求处理函数 */
    win_info_ptr->minimize_enable = minable;
    win_info_ptr->maximize_enable = maxable;
    win_info_ptr->modal = modal;
    win_info_ptr->need_restore = 0;

	return win_info_ptr;
}
Example #2
0
struct CreateSharedBufferParams MallocCreateSharedBufferParams() {
  struct CreateSharedBufferParams p;
  p.handle = (MojoHandle*)malloc(sizeof(MojoHandle));
  p.opts = (struct MojoCreateSharedBufferOptions*)malloc(
      sizeof(struct MojoCreateSharedBufferOptions));
  return p;
}
Example #3
0
int
init_list_for_dir(char *dir)
{
	int i, amount;
	struct dir_contents *contents;
	fileobj **list;

	amount = count_dir_entries(".", false, false);
	if (amount == 0)
		return (-1);

	contents = malloc(sizeof (contents));
	if (!contents) {
		return (-1);
	}

	list = malloc(sizeof (contents->list) * amount);
	if (!list) {
		return (-1);
	}

	for (i = 0; i < amount; i++) {
		list[i] = malloc(NAME_MAX + 1);
		if (!list[i]) {
			return (-1);
		}
	}

	contents->list = list;
	contents->amount = amount;

	file_list.contents = contents;

	return (0);
}
Example #4
0
unsigned int init_allocator(unsigned int _basic_block_size, unsigned int _length) {
    lists = log2(_length / _basic_block_size) + 1;
    mem_length = _length;

    start_pointer = malloc(_length);
    end_pointer = start_pointer - _length;

    free_list = malloc(lists * sizeof(Addr**));

    int i;
    for (i = 0; i < lists; i ++) {
        free_list[i] = (Addr*)malloc(sizeof(Addr**));
    }

    for (i = 0; i < lists; i ++) {
        free_list[i][0] = NULL;
        free_list[i][1] = NULL;
    }

    Header* h = start_pointer;
    h->empty = 1;
    h->next = NULL;
    h->prev = NULL;
    h->size = (_length - header_size);

    free_list[lists-1][0] = h;

    return h->size;
}
Example #5
0
void AddToPopulation(GainType Cost)
{
    int i, *P;
    Node *N;

    if (!Population) {
        assert(Population =
               (int **) malloc(MaxPopulationSize * sizeof(int *)));
        for (i = 0; i < MaxPopulationSize; i++)
            assert(Population[i] =
                   (int *) malloc((1 + Dimension) * sizeof(int)));
        assert(Fitness =
               (GainType *) malloc(MaxPopulationSize * sizeof(GainType)));
    }
    for (i = PopulationSize; i >= 1 && Cost < Fitness[i - 1]; i--) {
        Fitness[i] = Fitness[i - 1];
        P = Population[i];
        Population[i] = Population[i - 1];
        Population[i - 1] = P;
    }
    Fitness[i] = Cost;
    P = Population[i];
    N = FirstNode;
    i = 1;
    do
        P[i++] = N->Id;
    while ((N = N->Suc) != FirstNode);
    P[0] = P[Dimension];
    PopulationSize++;
}
Example #6
0
int main()  {
  double Delta_i;
  double* S;

  Delta_i=0.5;
  g_Ns=g_N*g_N;

	g_dim=dim_of_k();
  K=(double*)malloc(sizeof(double)*2*g_dim);
	init_K(K);

  S=(double*)malloc(sizeof(double)*3*g_dim);

  g_Delta=Delta_i;
  g_Uf=init_S(S);

  printf("Delta_i=%lf g_U=%lf",Delta_i,g_Uf);

	evolution(S);

  printf("Delta_i=%lf g_U=%lf",Delta_i,g_Uf);
  free(S);
	free(K);
  return 0;
}
Example #7
0
int main(int argc, char** argv) {
	//initialisation du contexte glut
	initGlut(argc, argv);

	Menu* menu = (Menu *) malloc(sizeof(Menu));

	Game* game = (Game *) malloc(sizeof(Game));

	//si probleme lors de la création du menu -> exit
	if (!MakeMenu(WINDOW_WIDTH, WINDOW_HEIGHT, menu, debut))
		return EXIT_FAILURE;

	//si porblème lors de la création du game -> exit
	if (!MakeGame(game)) {
		printf("Erreur MakeGame !!");
		return EXIT_FAILURE;
	}

	CallMenuDemarrage(menu, game);

	//liberation du *game
	FreeGame(game);
	free(game);
	game = NULL;

	//libéraiton du *menu
	free(menu);
	menu = NULL;

	return EXIT_SUCCESS;
}
static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
{
	snd_pcm_file_t *file = pcm->private_data;
	unsigned int channel;
	snd_pcm_t *slave = file->gen.slave;
	int err = _snd_pcm_hw_params(slave, params);
	if (err < 0)
		return err;
	file->buffer_bytes = snd_pcm_frames_to_bytes(slave, slave->buffer_size);
	file->wbuf_size = slave->buffer_size * 2;
	file->wbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->wbuf_size);
	file->wbuf_used_bytes = 0;
	assert(!file->wbuf);
	file->wbuf = malloc(file->wbuf_size_bytes);
	if (file->wbuf == NULL) {
		snd_pcm_file_hw_free(pcm);
		return -ENOMEM;
	}
	file->wbuf_areas = malloc(sizeof(*file->wbuf_areas) * slave->channels);
	if (file->wbuf_areas == NULL) {
		snd_pcm_file_hw_free(pcm);
		return -ENOMEM;
	}
	file->appl_ptr = file->file_ptr_bytes = 0;
	for (channel = 0; channel < slave->channels; ++channel) {
		snd_pcm_channel_area_t *a = &file->wbuf_areas[channel];
		a->addr = file->wbuf;
		a->first = slave->sample_bits * channel;
		a->step = slave->frame_bits;
	}
	return 0;
}
Example #9
0
static void
GrImageBufferAllocWrapper(void *r)
{
 nxImageBufferAllocReq *req = r;
 
 /* Add a new buffer to the end of the list */

 if (!imageListTail) {
   imageListHead = imageListTail = (imagelist_t *) malloc(sizeof(imagelist_t));
 }
 else {
   imageListTail->next = (imagelist_t *) malloc(sizeof(imagelist_t));
   imageListTail = imageListTail->next;
 }

 imageListTail->id = ++imageListId;
 imageListTail->data = (void *) malloc(req->size);
 imageListTail->size = req->size;
 imageListTail->offset = 0;

 imageListTail->next = 0;

 GsWriteType(current_fd,GrNumImageBufferAlloc);
 GsWrite(current_fd, &imageListTail->id, sizeof(int));
}
Example #10
0
/* fonction d'initialisation de notre chaine avec les 258 premiers elements de base
 * et declaration du tableau de pointeur sur un sous arbre-naire du dictionnaire
 * indexe par les codes */
arbre_n* init(){
	arbre_n* ptr_tmp;
	chaine_octet* chaine_tmp = (chaine_octet*) malloc(sizeof(chaine_octet));
	chaine_tmp->next = NULL;
	chaine_tmp->octet = 0;
	/* initialisation du premier element */
	ptr_arbre_n = create_elem(0, chaine_tmp, 0);
	tab_arbre[0] = ptr_arbre_n;
	
	ptr_tmp = ptr_arbre_n;
	for (int i=1;i<256;i++){
		chaine_tmp = (chaine_octet*) malloc(sizeof(chaine_octet));
		chaine_tmp->next = NULL;
		chaine_tmp->octet = i;
		ptr_tmp->freres = create_elem(i, chaine_tmp, 0); // dernier element de la chaine pointe sur Nil
		ptr_tmp = ptr_tmp->freres;
		tab_arbre[i] = ptr_tmp; // on met le pointeur sur l'element i dans tab[i]
	}
	
	ptr_tmp->freres = create_elem(256, NULL, 0); // dernier element de la chaine pointe sur Nil
	ptr_tmp = ptr_tmp->freres;
	tab_arbre[256] = ptr_tmp;
	ptr_tmp->freres = create_elem(257, NULL, 0); // dernier element de la chaine pointe sur Nil
	ptr_tmp = ptr_tmp->freres;
	tab_arbre[257] = ptr_tmp;
	ptr_tmp->freres = create_elem(258, NULL, 0); // dernier element de la chaine pointe sur Nil
	tab_arbre[258] = ptr_tmp->freres;

	nb_elem = 259;

	return ptr_arbre_n;
}
Example #11
0
/**
 * Add a friend message to the message queue and tries to send it if the
 * friend is online. Handles splitting of messages. (TODO: actually split messages)
 */
void
twc_message_queue_add_friend_message(struct t_twc_profile *profile,
                                     int32_t friend_number,
                                     const char *message,
                                     enum TWC_MESSAGE_TYPE message_type)
{
    struct t_twc_queued_message *queued_message
        = malloc(sizeof(struct t_twc_queued_message));

    time_t rawtime = time(NULL);
    queued_message->time = malloc(sizeof(struct tm));
    memcpy(queued_message->time, gmtime(&rawtime), sizeof(struct tm));

    queued_message->message = strdup(message);
    queued_message->message_type = message_type;

    // create a queue if needed and add message
    struct t_twc_list *message_queue
        = twc_message_queue_get_or_create(profile, friend_number);
    twc_list_item_new_data_add(message_queue, queued_message);

    // flush if friend is online
    if (profile->tox
        && tox_get_friend_connection_status(profile->tox, friend_number) == 1)
        twc_message_queue_flush_friend(profile, friend_number);
}
Example #12
0
int main(int argc, char ** argv) {

  const int n = 4;
  const int m = 6;

  int i, j;
  float ** a = malloc(n * sizeof(float *));
  float * a_ = malloc(n * m * sizeof(float));
  for (i = 0; i < n; i++) {
    a[i] = a_ + i * m;
    for (j = 0; j < m; j++) {
      a[i][j] = i+j;
    }
  }

  foo(n, m, a, 3.5);

  int nb = n < 10 ? n : 6;
  int mb = m < 10 ? m : 6;
  for (i = 0; i < nb; i++) {
    for (j = 0; j < mb; j++) {
      printf("\t%f", a[i][j]);
    }
    printf("\n");
  }

  return 0;
}
Example #13
0
buffer_t *
buffer_create(size_t max_length)
{
    buffer_t *buffer;
    size_t init_capacity;

    init_capacity = INIT_BUFFER_SIZE;
    if ( (max_length > 0) && (max_length < init_capacity) )
    {
        init_capacity = max_length;
    }

    buffer = (buffer_t*) malloc(sizeof(*buffer));
    if (buffer != NULL)
    {
        buffer->data = (unsigned char*) malloc(init_capacity);
        if (buffer->data == NULL)
            goto Error;
        buffer->length = 0;
        buffer->capacity = init_capacity;
        buffer->max_length = max_length;
    }
    return buffer;

Error:
    if (buffer != NULL)
        free(buffer->data);
    free(buffer);
    return NULL;
}
Example #14
0
int main(){
    uint64_t nodes = pow(2,SCALE);
    uint64_t edges = nodes*EDGEFACTOR;
    uint64_t *startVertex = malloc(edges*I64_BYTES);
    uint64_t *endVertex = malloc(edges*I64_BYTES);
    float initiator[] = {0.57,0.19,0.19,0.05};

    generate_graph(SCALE, EDGEFACTOR, startVertex, endVertex,initiator);

    char matrix[NODES][NODES] = {{0,1,0,0,0,0,0},
                                 {0,0,1,0,0,0,0},
                                 {0,0,0,1,0,0,0},
                                 {0,0,0,0,1,0,0},
                                 {0,0,0,0,0,1,0},
                                 {0,0,0,0,0,0,1},
                                 {0,0,0,0,0,0,0}};
    char parents[] = {0,0,0,0,0,0,0};
    char level[] = {0,0,0,0,0,0,0};

    double time = mytime();

    transpose_matrix(matrix);

    bfs_2d(matrix, level, parents);

    time = mytime() - time;
    printf("Time: %f\n", time/1000000);

    return 0;
}
Example #15
0
SC_FUNC int state_addlist(int *list,int count,int fsa)
{
  statepool *ptr;
  int last;

  assert(list!=NULL);
  assert(count>0);
  ptr=state_findlist(list,count,fsa,&last);
  if (ptr==NULL) {
    if ((ptr=(statepool*)malloc(sizeof(statepool)))==NULL)
      error(103);       /* insufficient memory */
    if ((ptr->states=(int*)malloc(count*sizeof(int)))==NULL) {
      free(ptr);
      error(103);       /* insufficient memory */
    } /* if */
    memcpy(ptr->states,list,count*sizeof(int));
    ptr->numstates=count;
    ptr->fsa=fsa;
    ptr->listid=last+1;
    ptr->next=statepool_tab.next;
    statepool_tab.next=ptr;
  } /* if */
  assert(ptr!=NULL);
  return ptr->listid;
}
Example #16
0
void add(int data) {
    if(data > 1000) {
        return;
    }
    if(head == NULL) {
        Node temp = malloc(sizeof(struct node));
        temp->data = data;
        temp->count = 1;
        temp->next = NULL;
        head = temp;
        return;
    }
    Node ptr = head;
    while(ptr->next != NULL) {
        if(ptr->data == data) {
            ptr->count++;
            return;
        }
        ptr = ptr->next;
    }
    Node temp = malloc(sizeof(struct node));
    temp->data = data;
    temp->count = 1;
    temp->next = NULL;
    ptr->next = temp;
    return;
}
Example #17
0
void setup(void) {
  /*Zero the struct and set the versions and keyframe_granule_shift.*/
  daala_info_init(&di);
  di.pic_width = 176;
  di.pic_height = 144;
  di.pixel_aspect_numerator = 128;
  di.pixel_aspect_denominator = 117;
  di.timebase_numerator = 30000;
  di.timebase_denominator = 1001;
  di.frame_duration = 30;
  di.nplanes = 2;
  dd = daala_encode_create(&di);
  ck_assert(dd != NULL);
  daala_comment_init(&dc);
  dc.comments = 2;
  dc.user_comments = (char **)malloc(sizeof(*dc.user_comments)*2);
  ck_assert(dc.user_comments != NULL);
  dc.comment_lengths = (int *)malloc(sizeof(*dc.comment_lengths)*2);
  ck_assert(dc.comment_lengths != NULL);
  dc.user_comments[0] = make_string("COMMENT=Comment 0");
  ck_assert(dc.user_comments[0] != NULL);
  dc.comment_lengths[0] = strlen(dc.user_comments[0]);
  dc.user_comments[1] = make_string("COMMENT=Comment 1 (this one longer)");
  ck_assert(dc.user_comments[1] != NULL);
  dc.comment_lengths[1] = strlen(dc.user_comments[1]);
}
Example #18
0
void Triangles::clear() {
    for (int i = 0; i < triangleCount; i++) {
        /*if (triangles[i].textureName != 0)
            delete triangles[i].textureName;*/
        if (triangles[i].isUsed)
            renderManager->removeTriangle(triangles[i].index);
    }
    free(triangles);

    for (int i = 0; i < vertexCount; i++) {
        if (vertices[i].isUsed)
            renderManager->removeTriangleVertex(vertices[i].index);
    }
    free(vertices);

    textureNames.clear();

    vertexCount = 0;
    vertexCapacity = 16;
    vertices = (Vertex*)malloc(vertexCapacity * sizeof(Vertex));
    memset(vertices, 0, vertexCapacity * sizeof(Vertex));

    triangleCount = 0;
    triangleCapacity = 16;
    triangles = (Triangle*)malloc(triangleCapacity * sizeof(Triangles));
    memset(triangles, 0, triangleCapacity * sizeof(Triangle));
}
Example #19
0
int main()
{
    struct node* head = NULL;
    struct node* second = NULL;
    struct node* third = NULL;
    
    
    head = (struct node*)malloc(sizeof(struct node));
    second =(struct node*)malloc(sizeof(struct node));
    third = (struct node*)malloc(sizeof(struct node));
    
    head->data = 1;
    head->next = second;
    
    second->data = 2;
    second->next = third;
    
    third->data =3;
    third->next = NULL;
    
    printlist(head);
    
    return 0;
    
}
Example #20
0
void insert(Tree* tree,int value){
    
    if(*tree == NULL){
        *tree = (Node*)malloc(sizeof(Node));
        (*tree)->key = value;
        return;
    }
    
    if((*tree)->key < value){
        //右子树
        if ((*tree)->rchild != NULL) {
            insert(&(*tree)->rchild, value);
        }else{
            Node* temp = (Node*)malloc(sizeof(Node));
            temp->key = value;
            (*tree)->rchild = temp;
        }
    }else{
        //左子树
        if((*tree)->lchild != NULL){
            insert(&(*tree)->lchild, value);
        }else{
            Node* temp = (Node*)malloc(sizeof(Node));
            temp->key = value;
            (*tree)->lchild = temp;
        }
    }
}
Example #21
0
static struct codebook *load(const char * name)
{
    FILE               *file;
    char		line[2048];
    char               *cursor = line;
    struct codebook    *b = malloc(sizeof(struct codebook));
    int			i;
    int			size;

    file = fopen(name, "rt");
    assert(file != NULL);

    *cursor = '\0';

    b->k = (int)get_float(file, name, &cursor, line, sizeof(line));
    b->m = (int)get_float(file, name ,&cursor, line, sizeof(line));
    size = b->k * b->m;

    b->cb = (float *)malloc(size * sizeof(float));

    for ( i = 0; i < size; i++ ) {
	b->cb[i] = get_float(file, name, &cursor, line, sizeof(line));
    }

    fclose(file);

    return b;
}
void execmd(char input[])
{
		
                char *token;
                char *result[256];
               
		if(strstr(input,"cd")){
			printf("into cd command\n");
              		char *token = strtok(input," ");
              		token = strtok(NULL," ");
        	        if(chdir(token) < 0){
	                      perror("wrong directory");
	                }       

		}
		else{
		        token = strtok(input," ");
		        result[0] = (char*)malloc(strlen(token)+1);
			strcpy(result[0],token);
		        int i=1;
		        while(token=strtok(NULL," ")){
		               result[i]=(char *)malloc(strlen(token)+1);
		               strcpy(result[i],token);
		               i++;
		        }
		        result[i] = NULL;
			execvp(result[0],result);				
		}

 
}
Example #23
0
//通过锁记录id查锁信息,通过这个查询的本来就不需要name,name都一样,直接用传输协议的参数
OLInfo *getOLInfoByID(uint16 userlock_id,uint64 starttime,uint8 num)
{
//	debug("in get ol info byid\n");
	if((userlock_id == (uint16)0) || (starttime == (uint64)0) || (num == (uint8)0))
		return NULL;
	MYSQL *conn = getIdleConn();
	MYSQL_RES *res;      //查询的result
	MYSQL_ROW row;
	char *sql_str = NULL;   //sql语句
	
	//设置字符编码为utf8
	mysql_setUTF8(conn);
	//设置插入语句
	sql_str = (char *)malloc(sizeof(char) * 200);
	memset(sql_str,0,200);
	sprintf(sql_str,"select open_time,close_time from OpenLockInfo where open_time > %llu and userlock_id = %2u order by open_time limit %1u",starttime,userlock_id,num);
	//执行查询
	if(mysql_query(conn,sql_str))
	{
		debug("getOLInfoByID error\n");
		recycleConn(conn);
		free(sql_str);
		return NULL;
	}
	//获取查询结果
	res = mysql_use_result(conn);
	OLInfo *info = NULL, *preInfo = NULL,*curInfo = NULL;
	//如果查询结果不为空
//	debug("middle get ol info by id\n");
	if((row = mysql_fetch_row(res)) != NULL)
	{
		curInfo = (OLInfo *)malloc(sizeof(OLInfo));
		memset(curInfo,0,sizeof(OLInfo));
		curInfo->open_time = (uint64)atoll(row[0]);
		if(row[1] == NULL)
			curInfo->close_time = 0;
		else
			curInfo->close_time = (uint64)atoll(row[1]);
		info = curInfo;
		preInfo = curInfo;
		while((row = mysql_fetch_row(res)) != NULL)
		{
			curInfo = (OLInfo *)malloc(sizeof(OLInfo));
			memset(curInfo,0,sizeof(OLInfo));
			curInfo->open_time = (uint64)atoll(row[0]);
			if(row[1] == NULL)
				curInfo->close_time = 0;
			else
				curInfo->close_time = (uint64)atoll(row[1]);
			preInfo->next = curInfo;
			preInfo = preInfo->next;
		}
	}
//	debug("after getolinfobyid \n");
	//释放资源
	mysql_free_result(res);
	recycleConn(conn);
	free(sql_str);
	return info;
}
Example #24
0
/*
 * Routine to communicate eigenvalues such that every process has
 * all computed eigenvalues (iu-il+1) in W; this routine is designed 
 * to be called right after 'pmrrr'.
 */
int PMR_comm_eigvals(MPI_Comm comm, int *nz, int *myfirstp, double *W)
{
  MPI_Comm comm_dup;
  MPI_Comm_dup(comm, &comm_dup);
  int nproc;
  MPI_Comm_size(comm_dup, &nproc);

  int *rcount = (int*)malloc(nproc*sizeof(int)); assert(rcount!=NULL);
  int *rdispl = (int*)malloc(nproc*sizeof(int)); assert(rdispl!=NULL);
  double *work = (double*)malloc((*nz+1)*sizeof(double)); assert(work!=NULL);

  if (*nz > 0)
    memcpy(work, W, (*nz)*sizeof(double) );

  MPI_Allgather(nz, 1, MPI_INT, rcount, 1, MPI_INT, comm_dup);

  MPI_Allgather(myfirstp, 1, MPI_INT, rdispl, 1, MPI_INT, comm_dup);
  
  MPI_Allgatherv
  (work, *nz, MPI_DOUBLE, W, rcount, rdispl, MPI_DOUBLE, comm_dup);

  MPI_Comm_free(&comm_dup);
  free(rcount);
  free(rdispl);
  free(work);

  return 0;
}
Example #25
0
struct DuplicateBufferHandleParams MallocDuplicateBufferHandleParams() {
  struct DuplicateBufferHandleParams p;
  p.duplicate = (MojoHandle*)malloc(sizeof(MojoHandle));
  p.opts = (struct MojoDuplicateBufferHandleOptions*)malloc(
      sizeof(struct MojoDuplicateBufferHandleOptions));
  return p;
}
Example #26
0
aniType* mkAni(SDL_Surface*img, int w,int h, int ticksPerFrame)
{
  if(!img)
  {
    return(NULL);
  }

  int numFrames = img->w/w;
  int i;

  aniType* ani = malloc( sizeof(aniType) );
  memset( ani, 0, sizeof(aniType) );


  ani->numFrames=numFrames;
  ani->numTicks=ticksPerFrame;
  ani->spr = malloc( sizeof(spriteType*) * numFrames );

  for(i=0;i<numFrames;i++)
  {
    ani->spr[i] = cutSprite(img, i*w,0, w,h);
  }

  return(ani);
}
Example #27
0
struct MessageArrays MallocMessageArrays(uint32_t num_bytes,
                                         uint32_t num_handles) {
  struct MessageArrays arrays;
  arrays.bytes = (void*)malloc(num_bytes * sizeof(void));
  arrays.handles = (MojoHandle*)malloc(num_handles * sizeof(MojoHandle));
  return arrays;
}
Example #28
0
OjCmpt TutorialComponent::create(std::string prettyName) {
	OjCmpt result;
	TutorialData *data = NULL;
	JausAddress tutorialAddr;
	// it is unbelieveable that I have to do this...what a HACK
	char szName[256];
	strcpy(szName, prettyName.c_str());
	// now, we create it using the global (groan) methods
	result = ojCmptCreate(szName, JAUS_EXPERIMENTAL_TUTORIAL_COMPONENT, TUTORIAL_THREAD_DESIRED_RATE_HZ);

	if (result == NULL) {
		// something bad happened...
		std::cout << "Error starting controller...aborting." << std::endl;
		return result;
	} else {
//<ROS2JAUS>
		//Spoof the comand line arguments to ROS
		char **argw = (char**)malloc(sizeof(char*)*2);
		char *str = (char*)malloc(sizeof(char)*strlen("tutorial"));
		str = "tutorial";
		argw[0] = str;
		argw[1] = NULL;
		int one = 1;

		ros::init(one, argw, "bridge");

		data = (TutorialData *)malloc(sizeof(TutorialData));

		data->nodeHandle = new ros::NodeHandle; 
		data->publisher = new ros::Publisher;
		data->subscriber = new ros::Subscriber;

		*(data->publisher) = data->nodeHandle->advertise<std_msgs::Int32>("chat", 1000);
//</ROS2JAUS>

		// Register function callback for the process message state
		ojCmptSetMessageProcessorCallback(result, TutorialComponent::processMessage);
		// Register function callback for the standby state
		ojCmptSetStateCallback(result, JAUS_STANDBY_STATE, TutorialComponent::standbyState);
		// Register function callback for the ready state
		ojCmptSetStateCallback(result, JAUS_READY_STATE, TutorialComponent::readyState);
		// Register function callback for the initialize state
		ojCmptSetStateCallback(result, JAUS_INITIALIZE_STATE, TutorialComponent::initState);
		// Register function callback for the shutdown state
		ojCmptSetStateCallback(result, JAUS_SHUTDOWN_STATE, TutorialComponent::shutdownState);
		ojCmptSetState(result, JAUS_INITIALIZE_STATE);

		// our address
		tutorialAddr = ojCmptGetAddress(result);

		data->oneNumberMessage = oneNumberMessageCreate();
		data->instance = tutorialAddr->instance;
		data->limit = 50000;
		data->running = JAUS_TRUE;

		ojCmptSetUserData(result, (void *)data);
	}
	return result;

}
Example #29
0
Stack CreateStack(int MaxElements)
{
    Stack S;

    S = (Stack) malloc (sizeof(struct StackRecord));
    if(S == 0) {
        printf("No memory for stack!\n");
        return 0;
    }

    S->Array = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->Array == 0) {
        printf("No memory for stack array\n");
        free(S);
        return 0;
    }

    S->MArray = (ElementType*) malloc (sizeof(ElementType)*MaxElements);
    if(S->MArray == 0) {
        printf("No memory for stack min array\n");
        free(S->Array);
        free(S);
        return 0;
    }

    S->TopOfStack = EmptyTOS;
    S->TopOfMStack = EmptyTOS;
    S->Capacity = MaxElements;

    return S;
}
Example #30
0
void newbspb(boss_sp_bullet **head,boss_sp_bullet **tail,int x, int y, clock_t time, void **img, int w, int h, int tframe, double speed, double angle,double r){	
	
	if(*head == NULL){		//if there are no explosion, create an new list
        (*head) = (boss_sp_bullet *)malloc(sizeof(boss_sp_bullet));
        (*tail) = (*head);
        (*tail) -> next = NULL;
        (*tail) -> previous = NULL;
    }else{		//add to queue
        (*tail) -> next = (boss_sp_bullet *)malloc(sizeof(boss_sp_bullet));
        (*tail) -> next -> previous = (*tail);
        (*tail)  = (*tail) -> next;
        (*tail) -> next = NULL;
    }
    (*tail) -> x = x;
    (*tail) -> y = y;
    (*tail) -> time = time;
    (*tail) -> img = img;
    (*tail) -> w = w;
    (*tail) -> h = h;
    (*tail) -> tframe = tframe;
    (*tail) -> frame = 0;
    (*tail) -> angle=angle;
    (*tail) -> speed = speed;
    (*tail) -> r = r;
}