Пример #1
0
Файл: main.c Проект: YliesC/42sh
void	my_free(t_utils *utils)
{
  free_struct((t_base *)utils->env);
  free_struct((t_base *)utils->history);
  free_struct((t_base *)utils->alias);
  free_tab(utils->path);
}
Пример #2
0
void			init_lines(t_area *ar, struct termios *oldline)
{
  struct winsize	w;
  int			li;
  int			co;

  if (ioctl(0, TIOCGWINSZ, &w) < 0)
    {
      restore_mode(oldline, ar);
      my_put_error(ERR_IOCTL);
      free_struct(ar);
      exit(EXIT_FAILURE);
    }
  li = w.ws_row;
  co = w.ws_col;
  if (li < 4 || co < ar->size)
    {
      restore_mode(oldline, ar);
      my_put_error(ERR_SIZE);
      free_struct(ar);
      exit(EXIT_FAILURE);
    }
  if (li != ar->li || co != ar->co)
    aff_list_resize(ar, li, co);
}
Пример #3
0
void * sec_object_init(char * uuid,struct struct_elem_attr *  share_data_desc)
{
	int ret;
	SEC_OBJECT * sec_object;

	sec_object=kmalloc(sizeof(SEC_OBJECT),GFP_KERNEL);
	if(sec_object==NULL)
		return NULL;
	memset(sec_object,0,sizeof(SEC_OBJECT));

	if(uuid==NULL)
		return NULL;
	strncpy(sec_object->uuid,uuid,DIGEST_SIZE*2);

	if(share_data_desc!=NULL)
	{
		sec_object->struct_template=create_struct_template(share_data_desc);
		if((sec_object->struct_template == NULL)
			&& IS_ERR(sec_object->struct_template))
			return NULL;
		ret=alloc_struct(&(sec_object->share_data),sec_object->struct_template);	
		if(ret<0)
		{
			kfree(sec_object);
			return NULL;
		}
	}
	ret=pthread_rwlock_init(&(sec_object->rwlock),NULL);
	if(ret<0)
	{
		free_struct(sec_object->share_data,sec_object->struct_template);
		return -EINVAL;
	}
	return sec_object;
}
Пример #4
0
void c_free_struct(                   //free a structure
                   void *deadstruct,  //structure to free
                   INT32 count,       //no of bytes
                   const char *name   //class name
                  ) {
  free_struct(deadstruct, count, name); 
}
Пример #5
0
int			main(int argc, char **argv)
{
  struct termios	oldline;
  t_area		ar;

  if (argc > 1)
    {
      non_canonical_mode(&oldline);
      init_term(&ar, argv, argc);
      display_arguments(&ar);
      while ((ar.len = read(0, ar.buff, sizeof(ar.buff))))
	{
	  x_read(ar.len);
	  init_lines(&ar, &oldline);
	  check_ctrl(&ar);
	  check_keys(&ar, ar.len);
	  check_select(&ar);
	  if (my_exit(&oldline, &ar) == 1 || void_exit(&ar, &oldline) == 1)
	    return (EXIT_SUCCESS);
	}
      restore_mode(&oldline, &ar);
      free_struct(&ar);
    }
  else
    my_put_error(ERR_ARGV);
  return (EXIT_SUCCESS);
}
Пример #6
0
void REJMAP::remove_pos(           //Cut out an element
                        inT16 pos  //element to remove
                       ) {
  REJ *new_ptr;                  //new, smaller map
  int i;

  ASSERT_HOST (pos >= 0);
  ASSERT_HOST (pos < len);
  ASSERT_HOST (len > 0);

  len--;
  if (len > 0)
    new_ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"),
      0, len * sizeof (REJ));
  else
    new_ptr = NULL;

  for (i = 0; i < pos; i++)
    new_ptr[i] = ptr[i];         //copy pre pos

  for (; pos < len; pos++)
    new_ptr[pos] = ptr[pos + 1]; //copy post pos

                                 //delete old map
  free_struct (ptr, (len + 1) * sizeof (REJ), "REJ");
  ptr = new_ptr;
}
Пример #7
0
/**
 * This routine frees all memory consumed by a temporary
 * configuration.
 *
 * @param Config  config to be freed
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Thu Mar 14 13:34:23 1991, DSJ, Created.
 */
void FreeTempConfig(TEMP_CONFIG Config) {
  assert (Config != NULL);

  destroy_nodes (Config->ContextsSeen, memfree);
  FreeBitVector (Config->Protos);
  free_struct (Config, sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT");

}                                /* FreeTempConfig */
Пример #8
0
void		free_list(t_param *my_param, t_conf *cmd)
{
  if (cmd->string_cmd)
    free(cmd->string_cmd);
  if (cmd)
    free(cmd);
  free_struct(my_param);
}
Пример #9
0
void 		clean_mem(t_mysh *mysh)
{
  int 		ret;

  ret = mysh->ret_val;
  free_list(&mysh->tab_sel_ctrl);
  free_command(mysh);
  free_struct(mysh);
  exit(ret);
}
void itdb_sysinfo_properties_free (SysInfoIpodProperties *props)
{
    g_list_foreach (props->artwork_formats, (GFunc)free_image_format, NULL);
    g_list_free (props->artwork_formats);
    g_list_foreach (props->photo_formats, (GFunc)free_image_format, NULL);
    g_list_free (props->photo_formats);
    g_list_foreach (props->chapter_image_formats, (GFunc)free_image_format, NULL);
    g_list_free (props->chapter_image_formats);
    free_struct (sysinfo_ipod_properties_fields_mapping, props);
}
Пример #11
0
int main()
{
  struct test *t;
  t = malloc(sizeof(struct test));
  t->ptr1 = malloc(100);
  t->ptr2 = NULL;
  free(t->ptr1);
  free_struct(t);
  return 0;
}
Пример #12
0
void REJMAP::initialise(  //Redefine map
                        inT16 length) {
  if (ptr != NULL)
    free_struct (ptr, len * sizeof (REJ), "REJ");
  len = length;
  if (len > 0)
    ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"),
      0, len * sizeof (REJ));
  else
    ptr = NULL;
}
Пример #13
0
/**
 * This routine deallocates all of the memory consumed by
 * a micro-feature outline.
 * @param arg   micro-feature outline to be freed
 * @return none
 * @note Exceptions: none
 * @note History: 7/27/89, DSJ, Created.
 */
void FreeMFOutline(void *arg) {  //MFOUTLINE                             Outline)
  MFOUTLINE Start;
  MFOUTLINE Outline = (MFOUTLINE) arg;

  /* break the circular outline so we can use std. techniques to deallocate */
  Start = list_rest (Outline);
  set_rest(Outline, NIL_LIST);
  while (Start != NULL) {
    free_struct (first_node (Start), sizeof (MFEDGEPT), "MFEDGEPT");
    Start = pop (Start);
  }

}                                /* FreeMFOutline */
Пример #14
0
static void
free_dragon(Display *display, dragonstruct *dp)
{
	if (dp->stippledGC != None) {
		XFreeGC(display, dp->stippledGC);
		dp->stippledGC = None;
	}
	if (dp->graypix != None) {
		XFreePixmap(display, dp->graypix);
		dp->graypix = None;
	}
	free_struct(dp);
}
Пример #15
0
void 		my_exit(t_mysh *mysh)
{
  int 		exite;

  exite = (mysh->tab_com[1]) ? check_str(mysh->tab_com[1]) : 0;
  if (comp_str(mysh->tab_com[0], "exit") == 1)
    {
      if (aff_prompt() == 1)
	my_putstr("exit\n");
      free_command(mysh);
      free_struct(mysh);
      exit(exite);
    }
}
Пример #16
0
static void
free_demon(Display *display, demonstruct *dp)
{
	int         shade;

	if (dp->stippledGC != None) {
		XFreeGC(display, dp->stippledGC);
		dp->stippledGC = None;
	}
	for (shade = 0; shade < dp->init_bits; shade++) {
		XFreePixmap(display, dp->pixmaps[shade]);
	}
	dp->init_bits = 0;
	free_struct(dp);
}
Пример #17
0
/*---------------------------------------------------------------------------*/
void FreeFeature(FEATURE Feature) {
/*
 **	Parameters:
 **		Feature		feature to be deallocated.
 **	Globals: none
 **	Operation: Release the memory consumed by the specified feature.
 **	Return: none
 **	Exceptions: none
 **	History: Mon May 21 13:33:27 1990, DSJ, Created.
 */
  if (Feature) {
    free_struct (Feature, sizeof (FEATURE_STRUCT)
      + sizeof (FLOAT32) * (Feature->Type->NumParams - 1),
      "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
  }

}                                /* FreeFeature */
Пример #18
0
DLLSYM void free_string(              //free a string
                        char *string  //string to free
                       ) {
#ifdef RAYS_MALLOC
  if (((ptrdiff_t) string & 3) == 1) { //one over word
    string--;                    //get id marker
    if (*string == 0) {
      free_mem(string);  //generally free it
      return;
    }
    else if (*string <= MAX_STRUCTS * sizeof (MEMUNION)) {
                                 //free structure
      free_struct (string, *string, "alloc_string");
      return;
    }
  }
  tprintf ("Non-string given to free_string");
#else
  free(string);
#endif
}
Пример #19
0
void	shutdown_server(int signal_id, t_server *server)
{
  if (close(server->socket) == -1)
    my_error("Can't close server socket", ERRNO);
  free_struct(server);
  if (signal_id != EXIT_FAILURE && signal_id != EXIT_SUCCESS)
    fprintf(stderr, "\rServer received signal[%d]\n", signal_id);
  if (server == NULL)
    exit(EXIT_FAILURE);
  shutdown_users(server);
  if (server->user != NULL)
    free(server->user);
  if (server->id_users != NULL)
    free(server->id_users);
  if (server->exec != NULL)
    free(server->exec);
  if (server->fd_type != NULL)
    free(server->fd_type);
  if (signal_id != EXIT_SUCCESS)
    exit(EXIT_FAILURE);
  exit(EXIT_SUCCESS);
}
Пример #20
0
int sec_object_reset(void * sec_obj)
{
	int ret;
	void * share_data;
	void * struct_template;
	SEC_OBJECT * sec_object=(SEC_OBJECT *)sec_obj;

	pthread_rwlock_wrlock(&(sec_object->rwlock));
	sec_object->state = -1;
	share_data=sec_object->share_data;
	struct_template=sec_object->struct_template;
	sec_object->share_data=NULL;
	sec_object->struct_template=NULL;
	sec_object->pointer=NULL;
	pthread_rwlock_unlock(&(sec_object->rwlock));

	if(share_data!=NULL)
		free_struct(share_data,struct_template);
	if(struct_template!=NULL)
		free_struct_template(sec_object->struct_template);
	return 0;
}
Пример #21
0
int	gere_key(int keycode, t_lx *mlx)
{
  mlx->key_l = 0;
  mlx->key_u = 0;
  mlx->key_r = 0;
  mlx->key_d = 0;
  if (keycode == 65307)
    {
      free_struct(mlx);
      exit(EXIT_SUCCESS);
    }
  else if (keycode == 65361)
    mlx->key_l = 1;
  else if (keycode == 65362)
    mlx->key_u = 1;
  else if (keycode == 65363)
    mlx->key_r = 1;
  else if (keycode == 65364)
    mlx->key_d = 1;
  next(mlx);
  return (0);
}
Пример #22
0
/*
 * Parse a structure
 */
static struct rpc_struct* new_struct(rpc_ctx_t* ctx, str* line)
{
	char* comma, *colon;
	struct rpc_struct* s;
	str left, right = STR_NULL, name, value;
	struct text_chunk* n, *v;

	if (!line->len) {
		rpc_fault(ctx, 400, "Line %d Empty - Structure Expected", 
					ctx->line_no);
		return 0;
	}

	s = (struct rpc_struct*)ctl_malloc(sizeof(struct rpc_struct));
	if (!s) {
		rpc_fault(ctx, 500, "Internal Server Error (No Memory Left)");
		return 0;
	}
	memset(s, 0, sizeof(struct rpc_struct));
	s->ctx = ctx;
	
	left = *line;
	do {
		comma = q_memchr(left.s, ',', left.len);
		if (comma) {
			right.s = comma + 1;
			right.len = left.len - (comma - left.s) - 1;
			left.len = comma - left.s;
		}
		
		     /* Split the record to name and value */
		colon = q_memchr(left.s, ':', left.len);
		if (!colon) {
			rpc_fault(ctx, 400, "Colon missing in struct on line %d",
							ctx->line_no);
			goto err;;
		}
		name.s = left.s;
		name.len = colon - name.s;
		value.s = colon + 1;
		value.len = left.len - (colon - left.s) - 1;
		
		     /* Create name chunk */
		n = new_chunk_unescape(&name);
		if (!n) {
			rpc_fault(ctx, 400, "Error while processing struct member '%.*s' "
						"on line %d", name.len, ZSW(name.s), ctx->line_no);
			goto err;
		}
		n->next = s->names;
		s->names = n;

		     /* Create value chunk */
		v = new_chunk_unescape(&value);
		if (!v) {
			rpc_fault(ctx, 400, "Error while processing struct membeer '%.*s'"
						" on line %d", name.len, ZSW(name.s), ctx->line_no);
			goto err;
		}
		v->next = s->values;
		s->values = v;

		left = right;
	} while(comma);

	return s;
 err:
	if (s) free_struct(s);
	return 0;
}
static void free_image_format (Itdb_ArtworkFormat *format)
{
    free_struct (sysinfo_image_format_fields_mapping, format);
}
Пример #24
0
void FreePermConfig(PERM_CONFIG Config) {
  assert(Config != NULL);
  Efree(Config->Ambigs);
  free_struct(Config, sizeof(PERM_CONFIG_STRUCT), "PERM_CONFIG_STRUCT");
}
Пример #25
0
/*---------------------------------------------------------------------------*/
void FreeTempProto(void *arg) {
  PROTO proto = (PROTO) arg;

  free_struct (proto, sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT");
}
Пример #26
0
ENTRYPOINT void
init_demon (ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	int         size = MI_SIZE(mi), nk;
	demonstruct *dp;

	if (demons == NULL) {
		if ((demons = (demonstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (demonstruct))) == NULL)
			return;
	}
	dp = &demons[MI_SCREEN(mi)];

	dp->generation = 0;
	dp->redrawing = 0;
#ifdef DO_STIPPLE
	if (MI_NPIXELS(mi) < NUMSTIPPLES) {
          Window window = MI_WINDOW(mi);
          if (dp->stippledGC == None) {
			XGCValues   gcv;

			gcv.fill_style = FillOpaqueStippled;
			if ((dp->stippledGC = XCreateGC(display, window,
				 GCFillStyle, &gcv)) == None) {
				free_demon(display, dp);
				return;
			}
		}
		if (dp->init_bits == 0) {
			int         i;

			for (i = 1; i < NUMSTIPPLES; i++) {
				DEMONBITS(stipples[i], STIPPLESIZE, STIPPLESIZE);
			}
		}
	}
#endif /* DO_STIPPLE */
	free_struct(dp);

	for (nk = 0; nk < NEIGHBORKINDS; nk++) {
		if (neighbors == plots[0][nk]) {
			dp->neighbors = plots[0][nk];
			break;
		}
		if (nk == NEIGHBORKINDS - 1) {
			nk = NRAND(NEIGHBORKINDS);
			dp->neighbors = plots[0][nk];
			break;
		}
	}

	dp->states = MI_COUNT(mi);
	if (dp->states < -MINSTATES)
		dp->states = NRAND(-dp->states - MINSTATES + 1) + MINSTATES;
	else if (dp->states < MINSTATES)
		dp->states = plots[1][nk];
	if ((dp->cellList = (CellList **) calloc(dp->states,
		sizeof (CellList *))) == NULL) {
		free_demon(display, dp);
		return;
	}
	if ((dp->ncells = (int *) calloc(dp->states, sizeof (int))) == NULL) {
		free_demon(display, dp);
		return;
	}

	dp->state = 0;

	dp->width = MI_WIDTH(mi);
	dp->height = MI_HEIGHT(mi);

	if (dp->neighbors == 6) {
		int         nccols, ncrows, i;

		if (dp->width < 8)
			dp->width = 8;
		if (dp->height < 8)
			dp->height = 8;
		if (size < -MINSIZE)
			dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE);
			else
				dp->ys = MINSIZE;
		} else
			dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) /
					       MINGRIDSIZE));
		dp->xs = dp->ys;
		nccols = MAX(dp->width / dp->xs - 2, 2);
		ncrows = MAX(dp->height / dp->ys - 1, 4);
		dp->ncols = nccols / 2;
		dp->nrows = 2 * (ncrows / 4);
		dp->xb = (dp->width - dp->xs * nccols) / 2 + dp->xs / 2;
		dp->yb = (dp->height - dp->ys * (ncrows / 2) * 2) / 2 + dp->ys - 2;
		for (i = 0; i < 6; i++) {
			dp->shape.hexagon[i].x = (dp->xs - 1) * hexagonUnit[i].x;
			dp->shape.hexagon[i].y = ((dp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3;
		}
	} else if (dp->neighbors == 4 || dp->neighbors == 8) {
		if (size < -MINSIZE)
			dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE);
			else
				dp->ys = MINSIZE;
		} else
			dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) /
					       MINGRIDSIZE));
		dp->xs = dp->ys;
		dp->ncols = MAX(dp->width / dp->xs, 2);
		dp->nrows = MAX(dp->height / dp->ys, 2);
		dp->xb = (dp->width - dp->xs * dp->ncols) / 2;
		dp->yb = (dp->height - dp->ys * dp->nrows) / 2;
	} else {		/* TRI */
		int         orient, i;

		if (dp->width < 2)
			dp->width = 2;
		if (dp->height < 2)
			dp->height = 2;
		if (size < -MINSIZE)
			dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE);
			else
				dp->ys = MINSIZE;
		} else
			dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) /
					       MINGRIDSIZE));
		dp->xs = (int) (1.52 * dp->ys);
		dp->ncols = (MAX(dp->width / dp->xs - 1, 2) / 2) * 2;
		dp->nrows = (MAX(dp->height / dp->ys - 1, 2) / 2) * 2;
		dp->xb = (dp->width - dp->xs * dp->ncols) / 2 + dp->xs / 2;
		dp->yb = (dp->height - dp->ys * dp->nrows) / 2 + dp->ys / 2;
		for (orient = 0; orient < 2; orient++) {
			for (i = 0; i < 3; i++) {
				dp->shape.triangle[orient][i].x =
					(dp->xs - 2) * triangleUnit[orient][i].x;
				dp->shape.triangle[orient][i].y =
					(dp->ys - 2) * triangleUnit[orient][i].y;
			}
		}
	}

	MI_CLEARWINDOW(mi);

	if ((dp->oldcell = (unsigned char *)
		malloc(dp->ncols * dp->nrows * sizeof (unsigned char))) == NULL) {
		free_demon(display, dp);
		return;
	}

	if ((dp->newcell = (unsigned char *)
		malloc(dp->ncols * dp->nrows * sizeof (unsigned char))) == NULL) {
		free_demon(display, dp);
		return;
	}

	RandomSoup(mi);
}
Пример #27
0
int main(int argc, char *argv[])
{
    FILE *fp;
    int i = 0;
    char line[MAX_LAST_NAME_SIZE];
    struct timespec start, end;
    double cpu_time1, cpu_time2;

    /* check file opening */
    fp = fopen(DICT_FILE, "r");
    if (fp == NULL) {
        printf("cannot open the file\n");
        return -1;
    }

    /* build the entry */
    entry *pHead, *e;
    pHead = (entry *) malloc(sizeof(entry));
    printf("size of entry : %lu bytes\n", sizeof(entry));
    e = pHead;
    e->pNext = NULL;

#if defined(__GNUC__)
    __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
    clock_gettime(CLOCK_REALTIME, &start);
    while (fgets(line, sizeof(line), fp)) {
        while (line[i] != '\0')
            i++;
        line[i - 1] = '\0';
        i = 0;
        e = append(line, e);
    }
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time1 = diff_in_second(start, end);

    /* close file as soon as possible */
    fclose(fp);

    e = pHead;

    /* the givn last name to find */
    char input[MAX_LAST_NAME_SIZE] = "zyxel";
    e = pHead;

    assert(findName(input, e) &&
           "Did you implement findName() in " IMPL "?");
    assert(0 == strcmp(findName(input, e)->lastName, "zyxel"));

#if defined(__GNUC__)
    __builtin___clear_cache((char *) pHead, (char *) pHead + sizeof(entry));
#endif
    /* compute the execution time */
    clock_gettime(CLOCK_REALTIME, &start);
    findName(input, e);
    clock_gettime(CLOCK_REALTIME, &end);
    cpu_time2 = diff_in_second(start, end);

    printf("execution time of append() : %lf sec\n", cpu_time1);
    printf("execution time of findName() : %lf sec\n", cpu_time2);

	free_struct(e);

    return 0;
}
Пример #28
0
void
init_dragon(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         size = MI_SIZE(mi);
	dragonstruct *dp;

	if (dragons == NULL) {
		if ((dragons = (dragonstruct *) calloc(MI_NUM_SCREENS(mi),
					      sizeof (dragonstruct))) == NULL)
			return;
	}
	dp = &dragons[MI_SCREEN(mi)];

	dp->generation = 0;
	dp->redrawing = 0;
	if (MI_NPIXELS(mi) <= 2) {
		if (dp->stippledGC == None) {
			XGCValues   gcv;

			gcv.fill_style = FillOpaqueStippled;
			if ((dp->stippledGC = XCreateGC(display, window,
				 GCFillStyle, &gcv)) == None) {
				free_dragon(display, dp);
				return;
			}
		}
		if (dp->graypix == None) {
			if ((dp->graypix = XCreateBitmapFromData(display, window,
				(char *) gray1_bits, gray1_width, gray1_height)) == None) {
				free_dragon(display, dp);
				return;
			}
		}
	}
	free_struct(dp);
	if (MI_NPIXELS(mi) > 2)
		dp->color = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));

	if ((dp->cellList = (CellList **) calloc(STATES,
			sizeof (CellList *))) == NULL) {
		free_dragon(display, dp);
		return;
	}
	if ((dp->ncells = (int *) calloc(STATES, sizeof (int))) == NULL) {
		free_dragon(display, dp);
		return;
	}

	dp->addlist = 0;

	dp->width = MI_WIDTH(mi);
	dp->height = MI_HEIGHT(mi);

	{
		int         nccols, ncrows, i;

		if (dp->width < 8)
			dp->width = 8;
		if (dp->height < 8)
			dp->height = 8;
		if (size < -MINSIZE)
			dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) /
				      MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE;
		else if (size < MINSIZE) {
			if (!size)
				dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE);
			else
				dp->ys = MINSIZE;
		} else
			dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) /
					       MINGRIDSIZE));
		dp->xs = dp->ys;
		nccols = MAX(dp->width / dp->xs - 2, 2);
		ncrows = MAX(dp->height / dp->ys - 1, 4);
		dp->ncols = nccols / 2;
		dp->nrows = 2 * (ncrows / 4);
		dp->xb = (dp->width - dp->xs * nccols) / 2 + dp->xs / 2;
		dp->yb = (dp->height - dp->ys * (ncrows / 2) * 2) / 2 - dp->ys / 4;
		for (i = 0; i < 6; i++) {
			dp->hexagon[i].x = dp->xs * hexagonUnit[i].x;
			dp->hexagon[i].y = ((dp->ys + 1) * hexagonUnit[i].y / 2) * 4 / 3;
		}
	}

	MI_CLEARWINDOW(mi);

	if ((dp->oldcell = (unsigned char *)
		calloc(dp->ncols * dp->nrows,
			sizeof (unsigned char))) == NULL) {
		free_dragon(display, dp);
		return;
	}
	if (!SetSoup(mi)) {
		free_dragon(display, dp);
		return;
	}
}
Пример #29
0
/*-------------------------------------------------------------------------*/
struct_t *
struct_new_anonymous (int num_members)

/* Create an empty anonymous struct instance with <num_members>
 * and return its pointer.
 * Return NULL when out of memory.
 *
 * The returned struct will have one reference.
 */

{
    struct_type_t * pType;
    struct_t      * pStruct;
    int             i;
    char            buf[100];
    Bool            gotError;

    (void) ref_mstring(STR_ANONYMOUS);
    (void) ref_mstring(STR_ANONYMOUS);
    pType = struct_new_type( STR_ANONYMOUS
                           , STR_ANONYMOUS
                           , 0
                           , NULL, num_members, NULL);
    if (pType == NULL)
        return NULL;

    pStruct = struct_new(pType);
    free_struct_type(pType);
      /* struct_new() added one ref, but since this is an anonymous
       * struct, the struct instance will hold the only ref.
       */

    if (pStruct == NULL)
    {
        // the type was not referenced by struct_new() in this case, so it must
        // not be freed.
        return NULL;
    }


    /* Create default members */
    gotError = MY_FALSE;
    for (i = 0; i < num_members; i++)
    {
        sprintf(buf, "m-%d", i);
        pType->member[i].name = new_tabled(buf);
        if (!pType->member[i].name)
        {
            debug_message("(%s:%d) Out of memory (%zu bytes) for member name\n"
                         , __FILE__, __LINE__, strlen(buf)
                         );
            gotError = MY_TRUE;
            break;
        }
        pType->member[i].type = lpctype_mixed;
    }

    if (gotError)
    {
        free_struct(pStruct);
        pStruct = NULL;
    }

    return pStruct;
} /* struct_new_anonymous() */
Пример #30
0
/*
 * Man FIFO routine running in the FIFO
 * processes requests received
 * through the FIFO file repeatedly
 */
int fifo_process(char* msg_buf, int size, int* bytes_needed, void *sh,
					void** saved_state)
{
	rpc_export_t* exp;
	char* buf;
	int line_len;
	char *file_sep;
	struct text_chunk* p;
	struct rpc_struct* s;
	int r;
	int req_size;
	static rpc_ctx_t context; 

	DBG("process_fifo: called with %d bytes, offset %d: %.*s\n",
			size, (int)(long)*saved_state, size, msg_buf);
	/* search for the end of the request (\n\r) */
	if (size < 6){ /* min fifo request */
		*bytes_needed=6-size;
		return 0; /* we want more bytes, nothing processed */
	}
	for (r=1+(int)(long)*saved_state;r<size;r++){
		if ((msg_buf[r]=='\n' || msg_buf[r]=='\r') &&
			(msg_buf[r-1]=='\n'|| msg_buf[r-1]=='\r')){
			/* found double cr, or double lf => end of request */
			req_size=r;
			goto process;
		}
	}
	/* no end of request found => ask for more bytes */
	*bytes_needed=1;
	/* save current offset, to optimize search */
	*saved_state=(void*)(long)(r-1);
	return 0; /* we want again the whole buffer */
process:
	
	DBG("process_fifo  %d bytes request: %.*s\n", 
			req_size, req_size, msg_buf);
	file_sep = 0;
	context.method = 0;
	context.reply_file = 0;
	context.body = 0;
	context.code = 200;
	context.reason = "OK";
	context.reply_sent = 0;
	context.last = 0;
	context.line_no = 0;
	context.read_h.s=msg_buf;
	context.read_h.end=msg_buf+size;
	context.read_h.crt=msg_buf;
	context.send_h=(struct send_handle*)sh;
		     /* commands must look this way ':<command>:[filename]' */
		if (read_line(&buf, &line_len, &context.read_h) < 0) {
			     /* line breaking must have failed -- consume the rest
			      * and proceed to a new request
			      */
			ERR("Command expected\n");
			goto consume;
		}
		context.line_no++;
		if (line_len == 0) {
			DBG("Empty command received\n");
			goto consume;
		}
		if (line_len < 3) {
			ERR("Command must have at least 3 chars\n");
			goto consume;
		}
		if (*buf != CMD_SEPARATOR) {
			ERR("Command must begin with %c: %.*s\n", 
			    CMD_SEPARATOR, line_len, buf);
			goto consume;
		}

		context.method = buf + 1;
		file_sep = strchr(context.method, CMD_SEPARATOR);
		if (file_sep == NULL) {
			ERR("File separator missing\n");
			goto consume;
		}
		if (file_sep == context.method) {
			ERR("Empty command\n");
			goto consume;
		}
		if (*(file_sep + 1) == 0) context.reply_file = NULL; 
		else {
			context.reply_file = file_sep + 1;
			context.reply_file = trim_filename(context.reply_file);
			if (context.reply_file == 0) {
				ERR("Trimming filename\n");
				goto consume;
			}
		}
		     /* make command zero-terminated */
		*file_sep = 0;
		
		exp = find_rpc_export(context.method, 0);
		if (!exp || !exp->function) {
			DBG("Command %s not found\n", context.method);
			rpc_fault(&context, 500, "Command '%s' not found", context.method);
			goto consume;
		}

		exp->function(&func_param, &context);

	consume:
		if (!context.reply_sent) {
			rpc_send(&context);
		}

		if (context.reply_file) { 
			ctl_free(context.reply_file); 
			context.reply_file = 0; 
		}
		
		     /* Collect garbage (unescaped strings and structures) */
		while(context.strs) {
			p = context.strs;
			context.strs = context.strs->next;
			free_chunk(p);
		}

		while(context.structs) {
			s = context.structs;
			context.structs = context.structs->next;
			free_struct(s);
		}

		*bytes_needed=0;
		DBG("Command consumed\n");
		DBG("process_fifo: returning %d, bytes_needed 0\n", req_size+1);
		return req_size+1; /* all was processed (including terminating \n)*/

}