Esempio n. 1
0
File: binary.c Progetto: idtek/knot
_public_
int dnssec_binary_from_base64(const dnssec_binary_t *base64,
			      dnssec_binary_t *binary)
{
	if (!base64 || !binary) {
		return DNSSEC_EINVAL;
	}

	if (base64->size == 0) {
		clear_struct(binary);
		return DNSSEC_EOK;
	}

	size_t raw_size = BASE64_DECODE_LENGTH(base64->size);
	uint8_t *raw = malloc(raw_size);
	if (raw == NULL) {
		return DNSSEC_ENOMEM;
	}

	size_t real_size = base64_decode_raw(base64->data, base64->size,
					     raw, raw_size);
	if (real_size == 0) {
		free(raw);
		return DNSSEC_EINVAL;
	}

	binary->data = raw;
	binary->size = real_size;

	return DNSSEC_EOK;
}
Esempio n. 2
0
Errcode set_flipath(char *fliname, Fli_id *flid, Flipath *fp)

/* note this sets size to sizeof(Flipath) not length of string! it
 * returns adjusted size of length for actual path string length if
 * successful */
{
Errcode err;
char pbuf[PATH_SIZE];

	clear_struct(&fp->fid);
	if(fliname && flid)
	{
		if((err = get_full_path(fliname,pbuf)) < 0)
			return(err);
		fp->fid = *flid;
	}
	else
		sprintf(pbuf,"%s.flc", unnamed_str );

	fp->id.type = FP_FLIPATH;
	fp->id.size = sizeof(Flipath);
	fp->id.version = FLIPATH_VERSION;

	return((OFFSET(Flipath,path)+1) + sprintf(fp->path,"%s", pbuf));
}
Esempio n. 3
0
static Errcode do_sep_tool()
{
Errcode err;
Sep_cb sep;
USHORT flags;

	if (!pti_input())
		return(Success);
	clear_struct(&sep);
	if((err = gather_ctable(&sep)) >= 0)
	{
		if(from_menu)
		{
			if(vs.multi)
			{
				flags = AUTO_UNZOOM;
				if(vl.ink->needs & INK_NEEDS_CEL)
					flags |= AUTO_USESCEL;
			}
			else
				flags = 0;

			err = go_autodraw(sep1,&sep,flags);
		}
		else
		{
			sep1(&sep);
			err = save_redo_sep(&sep.p);
		}
	}
	free_ctable(&sep);
	return(err);
}
Esempio n. 4
0
static void tween_do_star(Poly *p, int startype)
/* Rubberband out some star class poly and replace active end with
   result if successful */
{
int theta, rad, rad2;
Poly rp;
Errcode err;

if (p != NULL)
	{
	clear_struct(&rp);
	if ((err = rub_keep_star_type(&rp, startype, get_pcolor(p),
								  &theta,&rad,&rad2) )
		>= Success)
		{
		free_polypoints(p);
		*p = rp;
		p->polymagic = POLYMAGIC;
		softerr(force_other(p),NULL);
		redraw_both_ends();
		}
	else
		free_polypoints(&rp);
	}
}
Esempio n. 5
0
/*!
 * Free allocated key parameters and clear the structure.
 */
static void key_params_free(key_params_t *params)
{
	assert(params);

	free(params->id);
	dnssec_binary_free(&params->public_key);

	clear_struct(params);
}
Esempio n. 6
0
void tween_menu(
	Boolean renderable	/* grey out render button? */
	)	
/* entry point to tween menu */
{
Tween_cb rtcb;
Menuhdr tpull;
void *ss = NULL;
void *oundo;
void *oredo;

	if(MENU_ISOPEN(&twe_menu))
		return;
	/* save and clear undo and redo functions */
	oredo = vl.redoit;
	oundo = vl.undoit;
	vl.redoit = NULL;
	vl.undoit = NULL;

	hide_mp();
	clear_struct(&rtcb);
	twcb = &rtcb;
	twe_set_colors();
	twcb->oflxdata = flxtime_data; /* save old one */
	twcb->optool = vl.ptool;  /* save old one */
	fliborder_on();
	if (load_soft_pull(&tpull, 7, "tween", TWEENP_MUID,
		tween_selit, tween_dopull) < Success)
		goto OUT;
	if (load_tween_panel_strings(&ss) < Success)
		goto OUT;
	twe_enable_refresh();
	set_curptool(&tween_pen_tool);
	load_tween_state();
	init_tween_state(&twcb->old);
	twcb->last_made = TRUE;
	twcb->renderable = renderable;
	if (tween_save_undo()<Success)
		goto OUT;
	tween_redraw();
	menu_to_quickcent(&twe_menu);
	do_menuloop(vb.screen,&twe_menu,NULL,&tpull,tween_menu_keys);
	tween_undraw();
	save_tween_state();
	trash_tween_state(&twcb->old);
	trash_tween_state(&twcb->cur);
OUT:
	twe_disable_refresh();
	smu_free_pull(&tpull);
	smu_free_scatters(&ss);
	flxtime_data = twcb->oflxdata;
	restore_pentool(twcb->optool);
	twcb = NULL;
	show_mp();
	vl.redoit = oredo; /* restore old undo and redo functions */
	vl.undoit = oundo;
}
Esempio n. 7
0
File: binary.c Progetto: idtek/knot
_public_
void dnssec_binary_free(dnssec_binary_t *binary)
{
	if (!binary) {
		return;
	}

	free(binary->data);
	clear_struct(binary);
}
Esempio n. 8
0
Errcode draw_slatmask(void *data, SHORT size)
{
	Boolean *pvertical = data;
	Pframedat pfd;
	assert(size >= 0);

	clear_struct(&pfd);
	pfd.dest = vb.pencel;
	make_blind_mask(SCALE_ONE/2, &pfd, *pvertical,sgrey,swhite,size);
	return(Success);
}
Esempio n. 9
0
static Errcode make_dissolve_mask(int tscale0,int tscale1,Pframedat *pfd)
{
Errcode err;
Coor x, y, dy;
Rasthdr spec;
ULONG pcount;
ULONG cp;
Rcel *dest = pfd->dest;
Bytemap *dotmask;
UBYTE *plane;
UBYTE dotcol;
(void)tscale0;

	clear_struct(&spec);
	spec.width = 320;
	spec.height = 200;
	spec.pdepth = 8;

	if((err = pj_alloc_bytemap(&spec,&dotmask)) < Success)
		return(err);

	pj_set_rast(dotmask,pfd->invert);
	plane = (UBYTE *)(dotmask->bm.bp[0]);
	dotcol = !pfd->invert;

	pcount = (tscale1 * (320*200) + SCALE_ONE/2) / SCALE_ONE;

	cp = 0;
	while(pcount-- > 0)
	{
		plane[cp] = dotcol;
		cp += (27*27);
		cp %= (320*200);
	}

	y = 0;
	for(;;)
	{
		dy = y;
		for(x = 0;x < dest->width;x += 320)
		{
			pj_blitrect(dotmask,0,0,dest,x,dy,320,200);
			--dy;
		}
		if((dy + 200) >= dest->height)
			break;
		y += 200;
	}
	pj_rast_free(dotmask);
	return(Success);
}
Esempio n. 10
0
Errcode pcx_save_screen(FILE *out, Rcel *screen)
/* Save out header, pixel, and color map corresponding to screen.  Assumes
 * file open and at start of  file. */
{
Pcx_header rhdr;
UBYTE *buf = NULL;
Errcode err = Success;
int width = screen->width, height = screen->height, i;

												/* Set up header */
clear_struct(&rhdr);
rhdr.magic = 10;
rhdr.version = 5;
rhdr.encode = 1;
rhdr.bitpx = 8;
rhdr.x1 = 0;
rhdr.y1 = 0;
rhdr.x2 = screen->width-1;
rhdr.y2 = screen->height-1;
rhdr.cardw = screen->width;
rhdr.cardh = screen->height;
rhdr.nplanes = 1;
rhdr.bpl = screen->width;
if (fwrite(&rhdr, sizeof(rhdr), 1, out) < 1)	/* Write header */
	goto IOERR;
if ((buf = malloc(screen->width)) == NULL)		/* Get line buffer */
	{
	err = Err_no_memory;
	goto OUT;
	}
for (i=0; i<height; i++)						/* Write out each line */
	{
	pj_get_hseg(screen, buf, 0, i, width);
	pcx_comp_buf(out, buf, width);
	if (ferror(out) != 0)
		goto IOERR;
	}
putc(PCX_CMAP_MAGIC,out);						/* Write out color map */
fwrite(screen->cmap->ctab,  sizeof(screen->cmap->ctab[0]),  
	screen->cmap->num_colors, out);
if (ferror(out) != 0)
	goto IOERR;
goto OUT;
IOERR:
	err = pj_errno_errcode();
	goto OUT;
OUT:
	pj_freez(&buf);
	return(err);
}
Esempio n. 11
0
Errcode do_sep_redo(Sep_p *sep)
{
Sep_cb scb;
Errcode err;

clear_struct(&scb);
scb.p = *sep;
if ((err = get_abs_ctable(&scb)) >= Success)
	{
	sep1(&scb);
	}
free_ctable(&scb);
return(err);
}
Esempio n. 12
0
Errcode unpcx_init(
	Unpcx_obj *upo, 	/* line unpacker object */
	int bpl, 			/* bytes-per-line */
	FILE *file)			/* source file */
/* Initialize object and allocate buffer big enough for bpl bytes plus
 * overflow.  */
{
clear_struct(upo);
if ((upo->buf = malloc(bpl + PCX_MAX_RUN + 1)) ==  NULL)
	return(Err_no_memory);
upo->over = upo->buf + bpl;		/* Overflow area is just past buf proper */
upo->file = file;
upo->bpl = bpl;
return(Success);
}
Esempio n. 13
0
Errcode save_tween(char *name, Tween_state *ts)
{
	Errcode err;
	XFILE *f;
	Errcode cerr;
	Tween_file_header tfh;
	Tween_link *link, *next;

	err = xffopen(name, &f, XWRITEONLY);
	if (err < Success)
		return err;

	clear_struct(&tfh);
	tfh.magic = TWEEN_MAGIC;
	tfh.tcount = 2;
	tfh.link_count = listlen(&ts->links);

	err = xffwrite(f, &tfh, sizeof(tfh));
	if (err < Success)
		goto cleanup;

	for (link = (Tween_link *)(ts->links.head);
			NULL != (next = (Tween_link *)(link->node.next));
			link = next) {
		err = xffwrite(f, &link->start, 2*sizeof(link->start));
		if (err < Success)
			goto cleanup;
	}

	err = s_poly(f, &ts->p0);
	if (err < Success)
		goto cleanup;

	err = s_poly(f, &ts->p1);
	if (err < Success)
		goto cleanup;

cleanup:
	cerr = xffclose(&f);
	if (cerr < Success) { /* return primary error, not close error */
		if (err >= Success) /* but if close is 1st error return it... */
			err = cerr;
	}

	if (err < Success)
		pj_delete(name);
	return err;
}
Esempio n. 14
0
static Errcode force_other(Poly *p)
/* Make sure other poly exists, forcing it to be a clone of this one if
   necessary .  Free up any old links. */
{
Poly *other;
Errcode err = Success;

set_last_made();
other = other_poly(p);
if (other->polymagic != POLYMAGIC)
	{
	clear_struct(other);
	err = update_poly(p,other);
	}
free_dl_list(&twcb->cur.links);
return(err);
}
Esempio n. 15
0
static void init_fscroller(void)
{
SHORT tname;

	tname = fscroller.top_name; /* save top name */
	free_wild_list(&wild_lst);
	clear_struct(&fscroller);
	fscroller.top_name = tname; /* replace top name */

	build_wild_list(&wild_lst, fq_drawer, wild_stringq.string, TRUE);
	fscroller.names = wild_lst;
	fscroller.scroll_sel = &fscroll_sel;
	fscroller.list_sel = &flist_sel;
	fscroller.feel_1_cel = feel_1_fname;
	fscroller.font = icb.input_screen->mufont;
	init_name_scroller(&fscroller,icb.input_screen);
}
Esempio n. 16
0
Errcode sv_fli(char *name)

/* writes whole current tflx out to a fli file */
{
int i;
Fli_frame *cbuf;
Flifile flif;    /* output fli */
Errcode err;

	if(!flix.fd)
		return(Err_bad_input);
	clear_struct(&flif);

	scrub_cur_frame();
	if((err = pj_fli_cel_alloc_cbuf(&cbuf,vb.pencel)) < 0)
		goto error;

	if((err = save_fli_start(name, &flif)) < 0)
		goto error;

	/* write out all tflx frame chunks to fli file */

	for (i=0; i<=flix.hdr.frame_count; i++)
	{
		if((err = read_flx_frame(&flix,cbuf,i)) < 0)
			goto error;

		if(i == 0)
			err = pj_i_add_frame1_rec(name,&flif,cbuf);
		else if(i == flix.hdr.frame_count)
			err = pj_i_add_ring_rec(name,&flif,cbuf);
		else
			err = pj_i_add_next_rec(name,&flif,cbuf);

		if(err < Success)
			goto error;
	}
	cleans();

error:
	err = softerr(err,"!%s", "cant_save", name);
	pj_fli_close(&flif);
	pj_gentle_free(cbuf);
	return(err);
}
Esempio n. 17
0
int dnssec_kasp_create(dnssec_kasp_t **kasp_ptr,
                       const dnssec_kasp_store_functions_t *functions)
{
	if (!kasp_ptr || !functions) {
		return DNSSEC_EINVAL;
	}

	dnssec_kasp_t *kasp = malloc(sizeof(*kasp));
	if (!kasp) {
		return DNSSEC_ENOMEM;
	}

	clear_struct(kasp);
	kasp->functions = functions;

	*kasp_ptr = kasp;
	return DNSSEC_EOK;
}
Esempio n. 18
0
static Errcode po_poe_over_some(void *effect, void *data, enum automodes tmode)
/*****************************************************************************
 * This does a function over time without bringing up the Time Select panel.
 *	 the POE version: takes a real C routine pointer, not a Poco routine ptr.
 ****************************************************************************/
{
	Errcode err;
	Autoarg aa;

	free_render_cashes();
	clear_struct(&aa);
	aa.avec = effect;
	aa.flags = AUTO_UNZOOM;
	aa.avecdat = data;
	err = noask_do_auto(&aa, tmode);
	make_render_cashes();
	return(err);
}
Esempio n. 19
0
/*!
 * Add DNSKEY into a keyset.
 */
static int keyset_add_dnskey(dnssec_list_t *keyset, dnssec_key_t *dnskey,
			     const dnssec_kasp_key_timing_t *timing)
{
	dnssec_kasp_key_t *kasp_key = malloc(sizeof(*kasp_key));
	if (!kasp_key) {
		return DNSSEC_ENOMEM;
	}

	clear_struct(kasp_key);
	kasp_key->key = dnskey;
	kasp_key->timing = *timing;

	int result = dnssec_list_append(keyset, kasp_key);
	if (result != DNSSEC_EOK) {
		free(kasp_key);
	}

	return result;
}
Esempio n. 20
0
Errcode alloc_flipath(char *fliname, Flifile *flif, Flipath **pfpath)

/* allocate and make up a flipath chunk to represent a fli will free before
 * allocating so the input must be initialized if FLIF is null the id will
 * be 0s */
{
Errcode err;
Flipath fp;
Fli_id zid;

	clear_struct(&zid); /* a fudge but if it's not a fli we zero out id */
	if((err = set_flipath(fliname, flif?&flif->hdr.id:&zid, &fp)) < Success)
		return(err);
	fp.id.size = err;
	free_flipath(pfpath);
	if((*pfpath = pj_malloc(fp.id.size)) == NULL)
		return(Err_no_memory);
	copy_flipath(&fp,*pfpath);
	return(Success);
}
Esempio n. 21
0
Errcode vset_get_pathinfo(int ptype, Vset_path *pathinfo)
{
Errcode err = Success;
Vsetfile vsf;

	if(((unsigned int)ptype) < VSET_NUM_PATHS
		&& (err = reopen_tsettings(&vsf)) >= Success)
	{
		err = xffreadoset(vsf.xf, pathinfo, path_type_offset(&vsf,ptype),
						  sizeof(Vset_path));
		close_vsetfile(&vsf);
	}
	else
		clear_struct(pathinfo);

	/* certain types we will initialize from others if they are not set */

	if(pathinfo->scroller_top == 0
		&& pathinfo->path[0] == 0
		&& pathinfo->wildcard[0] == 0)
	{
		switch(ptype)
		{
			case JOIN_PATH:
			case JOIN_MASK_PATH:
				ptype = FLI_PATH;
				break;
			default:
				goto done;
		}
		err = vset_get_pathinfo(ptype, pathinfo);
		*pj_get_path_name(pathinfo->path) = 0;
		pathinfo->wildcard[0] = 0;
	}
done:
	return(err);
}
Esempio n. 22
0
static Errcode write_flxframe(Flxfile *flxf, char *name, void *frame)

/* assumes this is the next record in the tempflx during serial creation 
 * and previous record was written using this */
{
Errcode err;
Flx *flx;
LONG size = ((Fli_frame *)frame)->size;

	if(flxf->hdr.frame_count >= flxf->hdr.frames_in_table)
	{
		err = Err_too_many_frames;
		goto error;
	}

	flx = flxf->idx + flxf->hdr.frame_count;
	
	if(pj_i_is_empty_rec(frame))
	{
		(flx + 1)->foff = flx->foff; /* propogate forward */
		clear_struct(flx);
		size = 0;
	}
	else
	{
		if((err = pj_writeoset(flix.fd,frame,flx->foff,size)) < Success)
			goto error;
		flx->fsize = size;
		(flx + 1)->foff = flx->foff + size;
	}
	++flxf->hdr.frame_count;
	flxf->hdr.size += size;
	return(Success);
error:
	return(flx_write_error(err,name));
}
Esempio n. 23
0
void close_macro(void)
{
BYTE olevel;
static UBYTE eoflags[2] = {(MACRO_REC|MR_EOF),(MACRO_REC|MR_EOF)};

	if(Mcb.fp != NULL)
	{
		if(icb.macro_mode == MAKE_MACRO)
		{
			Mcb.mh.id.size = fftell(Mcb.fp);
			ffwrite(Mcb.fp,&eoflags,sizeof(eoflags)); /* two bytes of eof */
			ffwriteoset(Mcb.fp,&Mcb.mh,0,sizeof(Mcb.mh));
		}
		ffclose(&Mcb.fp);
	}

	/* clear all but abort nesting level count */
	olevel = Mcb.ab_level;
	clear_struct(&Mcb);
	Mcb.ab_level = olevel;

	icb.macro_clocked = 0;
	icb.macro_mode = 0;
}
Esempio n. 24
0
static Errcode po_over_some(Popot *effect, Popot *data, enum automodes tmode)
/*****************************************************************************
 * This does a function over time without bringing up the Time Select panel.
 ****************************************************************************/
{
	void *fuf;
	Poco1_dat pd;
	Errcode err;
	Autoarg aa;

	if ((fuf = effect->pt) == NULL)
		return(builtin_err = Err_null_ref);
	pd.pdata = data;
	if ((pd.code = po_fuf_code(fuf)) == NULL)
		return(Err_function_not_found);
	free_render_cashes();
	clear_struct(&aa);
	aa.avec = poco1;
	aa.flags = AUTO_UNZOOM;
	aa.avecdat = &pd;
	err = noask_do_auto(&aa, tmode);
	make_render_cashes();
	return(err);
}
Esempio n. 25
0
Errcode load_fli_fcel(char *flipath,char *tempname,char *celfli_name,
					  Flicel **pfc)

/* loads a fli file as a newly allocated flicel, if tempname is non-null
 * builds a temp fli from the fli or points a tempname file to the fli 
 * if the tempname is NULL it will not build a temp file and will point the 
 * ram cel to the fli even if the fli is on a removable device */
{
Errcode err;
Flifile flif;
Flicel *fc;
LONG chunksize;
Chunkparse_data pd;
Boolean make_flicopy; 
Boolean found_celdata;
char device[DEV_NAME_LEN];

	if((err = alloc_fcel(pfc)) < Success)
		return(err);
	fc = *pfc;

	if(tempname)
	{
		if(NULL == (fc->tpath = clone_string(tempname)))
		{
			err = Err_no_memory;
			goto error;
		}
	}

	clear_struct(&flif);

	if((err = get_path_device(flipath,device)) < Success) 
		goto error;

	/* if allowed make sure cel fli file is not on removable drive */
	make_flicopy = (tempname != NULL   
					&& celfli_name != NULL  
					&& !pj_is_fixed(device));

	/* attempth to open fli requested as cel */

	if (make_flicopy) {
		err = pj_fli_open(flipath, &flif, XREADONLY);
		if (err < Success)
			goto error;
	}
	else {
		err = pj_fli_open(flipath, &flif, XREADWRITE_OPEN);
		if (err < Success)
			goto error;

		/* we've got to have a valid update time ! */
		if(flif.hdr.id.update_time == 0)
		{
			if((err = pj_i_flush_head(&flif)) < Success)
				goto error;
		}
	}

	found_celdata = FALSE;
	init_chunkparse(&pd, flif.xf, FCID_PREFIX, sizeof(Fli_head), 0, 0);
	while(get_next_chunk(&pd))
	{
		if(pd.type == FP_CELDATA)
		{
			if(pd.fchunk.size == sizeof(Celdata))
			{
				/* try to read it */
				pd.error = read_parsed_chunk(&pd,&fc->cd,-1); 
				found_celdata = TRUE;
			}
			break;
		}
	}

	if(pd.error < Success && pd.error != Err_no_chunk)
	{
		err = pd.error;
		goto error;
	}

	if(!found_celdata)
	{
		/* No positioning chunk found. Just put cel in upper left corner */
		fc->cd.cent.x = flif.hdr.width>>1;
		fc->cd.cent.y = flif.hdr.height>>1;
	}
Esempio n. 26
0
Errcode load_ramfli(Ramfli *rfl, Flifile *flif)
{
Errcode err;
int frame_ix;
Ramframe frame;
Ramframe *rf;
Names first_one;
Ramframe *tail = (Ramframe *)&first_one;
LONG allocsize;
ULONG flags;
extern long mem_free;
long mem_needed;
Boolean ram_required = TRUE;

/* size to read in initially */
#define CHECK_SIZE  (sizeof(Ramframe) - OFFSET(Ramframe,frame))

	first_one.next = NULL;
	free_ramfli_data(rfl);

	/* load header from input one */

	if((rfl->fhead = pj_malloc(sizeof(Fli_head))) == NULL)
	{
		err = Err_no_memory;
		goto no_mem_error;
	}

	*(rfl->fhead) = flif->hdr;

	/* read in the frames */

	flags = rfl->flags;
	clear_struct(&frame);
	frame.frame.size = flif->hdr.frame1_oset;
	frame_ix = -1;

	mem_needed = flif->hdr.size; 

	while(++frame_ix <= (SHORT)(flif->hdr.frame_count))
	{
		frame.doff += frame.frame.size;

		/* the last frame if it is an empty frame will only be
		 * sizeof(Fli_frame) so we may have an Err_eof on the last 
		 * frame */

		if((err = pj_readoset(flif->fd,&frame.frame,
								  frame.doff,CHECK_SIZE)) < Success)
		{
			if(frame_ix != flif->hdr.frame_count)
				goto error;
			if((err = pj_readoset(flif->fd,&frame.frame,
							  frame.doff,sizeof(frame.frame))) < Success)
			{
				goto error;
			}
		}

		if( (!(flags & RF_LOAD_FIRST)) && frame_ix == 0)
			goto add_empty_frame;

		if( (!(flags & RF_LOAD_RING)) && frame_ix == flif->hdr.frame_count)
			goto load_empty_frame;

		/* simple memory test does not account for an un-needed ring frame */

		if((mem_needed - frame.doff) >= mem_free)
			goto no_mem_error;

		allocsize = OFFSET(Ramframe,frame)+frame.frame.size;

		if((rf = pj_malloc(allocsize)) == NULL)
		{
			if(ram_required)
				goto no_mem_error;
			goto add_empty_frame;
		}

		/* add next frame to list */
		rf->next = NULL;
		tail->next = rf;
		tail = rf;

		memcpy(rf,&frame,Min(allocsize,sizeof(frame)));

		if(allocsize < sizeof(frame))
			goto add_full_frame;

		/* read in data: It there is a pstamp chunk we don't need it so 
		 * bypass it and adjust frame data. Otherwise read whole chunk */

#ifdef DOESNT_WORK
		if(frame.first_chunk.type == FLI_PSTAMP)
		{
			rf->frame.size -= frame.first_chunk.size;
			rf->doff += frame.first_chunk.size;

			if(rf->frame.size > sizeof(Fli_frame)
				&& (err = pj_readoset(flif->fd,&(rf->first_chunk),
									  rf->doff + sizeof(Fli_frame),
								rf->frame.size - sizeof(Fli_frame))) < Success)
			{
				goto error;
			}
			--rf->frame.chunks; /* one less chunk */
		}
		else 
#endif	
		
		if(frame.frame.size > CHECK_SIZE 
				 && (err = pj_read_ecode(flif->fd,(rf + 1),
							frame.frame.size - CHECK_SIZE)) < Success)
		{
			goto error;
		}

	add_full_frame:

		rf->doff = -frame.doff; /* negative offset means we have a 
							   	 * good ram record */
		continue;

	add_empty_frame:

		if(rfl->fhead)
			pj_freez(&(rfl->fhead));

	load_empty_frame:

		/* this is a little truncated ramframe only up to doff which is 
		 * is positive in this case negative for a ram record */

		if((rf = pj_malloc(POSTOSET(Ramframe,doff))) == NULL)
			goto no_mem_error;

		rf->doff = frame.doff;
		rf->next = NULL;
		tail->next = rf;
		tail = rf;
	}
	rfl->frames = (Ramframe *)first_one.next;
	return(Success);

no_mem_error:

	/* if specified as required and not ok off disk ERROR out */

	free_slist(first_one.next); /* we need enough ram to have requestor */
	first_one.next = NULL;

	if(ram_required && !ask_ok_off_disk(rfl))
		err = Err_reported;
	else
		err = Success;

error:
	pj_freez(&(rfl->fhead));
	free_slist(first_one.next);
	return(err);
#undef CHECK_SIZE
}
Esempio n. 27
0
Errcode alloc_dev_sels(Button *hanger,  /* where to install device buttons */
					   Rectangle *size, /* width and height is size 
					   					 * x,y spacing UNSCALED referenced
										 * to 320 X 200 */
					   int numcols,int numrows,
					   char *drawer,  /* string to put directory into */
					   /* function and data to call after drawer is changed */
					   Errcode (*on_newdrawer)(void *), void *ond_data )
/*
 * Allocate and initialized one button on a file menu for each logical drive.
 * Store the button list on hanger->children.  Also allocates ".." and "\"
 * buttons at the start.
 *
 * The buttons will all have the same seeme & feelme.  The drive # will
 * be stored in the identity field, or -1 or -2 for the ".." and "\".
 * The seeme & feelme do a little switch on the identity to decide
 * how to process it if a drive or not.
 */
{
Errcode err;
UBYTE devices[MAX_DEVICES];
int dev_count;
Dsel_group *dg;
long bsize;
Button *sel;
int i,ix;

	if((dev_count = pj_get_devices(devices)) < 0)
		return(dev_count); 

	bsize = (dev_count+2)*sizeof(Button);

		/* Allocate enough space for all buttons and a Dsel_group. */
	if ((err = ealloc((void **)&(hanger->children), bsize + sizeof(Dsel_group)))
			< Success)
		return(err);

	sel = hanger->children;
	dg = (Dsel_group *)OPTR(sel,bsize);	/* Point dg to after buttons */
	dg->drawer = drawer;
	dg->on_newd_data = ond_data;

	if (on_newdrawer) {
		dg->on_newdrawer = on_newdrawer;
	}
	else { /* just in case it's not supplied */
		dg->on_newdrawer = (Errcode (*)(void *))pj_errdo_unimpl;
	}

	hanger->seeme = hang_dev_sels;

	ix = 0; 
	--sel;
	for(i = -2; i < dev_count;++i)
	{
		++sel;
		clear_struct(sel);
		sel->next = sel+1;
		sel->orig_rect.width = size->width;
		sel->orig_rect.height = size->height;
		sel->orig_rect.x = size->x * (ix%numcols);
		sel->orig_rect.y = size->y * (ix/numcols);
		sel->seeme = see_device;
		sel->feelme = new_dev;
		sel->group = dg;

		if(i >= 0)
		{
			sel->identity = devices[i];
			sel->key_equiv = devices[i]+'a';
			sel->flags = MB_GHILITE;
		}
		else
			sel->identity = i;

		if(++ix >= (numcols*numrows))
			break;
	}
	sel->next = NULL;
	return(Success);
}
Esempio n. 28
0
static Errcode open_file(Pdr *pd, char *path, Image_file **pif,
						 Anim_info *ainfo )
/*****************************************************************************
 * Open up the file, and if possible verify header.
 ****************************************************************************/
{
Ifile *gf;
FILE *f;
Errcode err = Success;
UBYTE *sbuf;
Riff_head rif;
int i;

*pif = NULL;	/* for better error recovery */

if((gf = zalloc(sizeof(*gf))) == NULL)
	return(Err_no_memory);

if((f = gf->file = fopen(path, "rb")) == NULL)
	{
	err = pj_errno_errcode();
	goto ERROR;
	}
if (fread(&rif, sizeof(rif), 1, f) != 1)
	{
	err = Err_truncated;
	goto ERROR;
	}
intel_swap(&rif.xoff);
intel_swap(&rif.yoff);
intel_swap(&rif.width);
intel_swap(&rif.height);
intel_swap(&rif.depth);
intel_swap(&rif.frame_count);
intel_swap(&rif.jiffies_frame);
intel_swap(&rif.frames_written);
if (rif.frames_written == 0)
	rif.frames_written = rif.frame_count;
gf->rif = rif;
if (memcmp(&rif.iff_type, "RIFF", 4) != 0)
	{
	err = Err_bad_magic;
	goto ERROR;
	}
if (rif.depth > 8 || rif.depth < 1)
	{
	err = Err_pdepth_not_avail;
	goto ERROR;
	}
gf->bpr = ((rif.width+7)>>3);
gf->psize = gf->bpr*rif.height;
						/** Allocate bitplanes for Amiga screen
						 ** simulation.
						 **/
if ((gf->sbuf = sbuf = malloc(gf->psize*rif.depth)) == NULL)
	{
	err = Err_no_memory;
	goto ERROR;
	}
for (i=0; i<rif.depth; ++i)
	{
	gf->planes[i] = sbuf;
	sbuf += gf->psize;
	}
if ((err = make_ytable(&gf->ytable, gf->bpr, rif.height)) < Success)
	goto ERROR;
if (ainfo != NULL)		/* fill in ainfo structure if any */
	{
	clear_struct(ainfo);
	ainfo->depth = 8;
	ainfo->x = rif.xoff;
	ainfo->y = rif.yoff;
	ainfo->width = rif.width;
	ainfo->height = rif.height;
	ainfo->num_frames = rif.frames_written;
	ainfo->millisec_per_frame = 1000*rif.jiffies_frame/60;
	}
*pif = (Image_file *)gf;
return(Success);

ERROR:
close_file(&gf);
return(err);
}
Esempio n. 29
0
static Errcode write_transition_frames(Initpframe init_pframe,
									   Getmask get_mask_frame,
									   Closepframe cleanup_pframe)

/* note the scaling is done so that it goes from 0 to one less than frame after
 * wipe the frame before is all cel a and the frame after is all cel b and all
 * inbetween are part a and part a from 1/(count+1) count/(count+1) proportion
 * of mask generator 0 being all a and count being all b */
{
Errcode err;
SHORT frame_a, frame_b;
Cmap *cmapa, *cmapb, *dcmap;
int mask_scale0, mask_scale1, cmap_scale;
Pframedat pfd;
LONG cbufsize, size;
Celcfit blend_cfit;

	clear_struct(&pfd);
	if(ccb.preview_mode)
	{
		pfd.dest = undof;
		pfd.history = vb.pencel;
		save_undo();
	}
	else
	{
		pfd.dest = vb.pencel;
		pfd.history = undof;
	}

	init_celcfit(&blend_cfit);

	err = reopen_fcelio(ccb.start_cel, XREADONLY);
	if (err < Success)
		goto error;

	err = reopen_fcelio(ccb.end_cel, XREADONLY);
	if (err < Success)
		goto error;

	cbufsize = pj_fli_cel_cbuf_size(pfd.dest);
	if( fcel_needs_seekbuf(ccb.fcelb)
		&& (size = fcel_cbuf_size(ccb.fcelb)) > cbufsize)
	{
		cbufsize = size;
	}
	if((vs.co_type == COMP_MASK)
		&& fcel_needs_seekbuf(ccb.mask_cel)
		&& ((size = fcel_cbuf_size(ccb.mask_cel)) > cbufsize))
	{
			cbufsize = size;
	}

	if(NULL == (pfd.cbuf = pj_malloc(cbufsize)))
		goto nomem_error;

	/* the mask mover uses cel a and cel b not start_cel and end_cel
	 * uses invert flag */

	pfd.reverse_wipe = vs.co_reverse;
	pfd.acfit = ccb.fcela->cfit->ctable;
	pfd.bcfit = ccb.fcelb->cfit->ctable;
	pfd.frame_count = ccb.transition_frames;

	/** calculate and preset frame counts etc */

	frame_a = ccb.cela_transtart;
	frame_b = ccb.celb_start;
	cmapa = ccb.start_cel->rc->cmap;
	cmapb = ccb.end_cel->rc->cmap;
	dcmap = pfd.dest->cmap;

	if(init_pframe && (err = (*init_pframe)(&pfd)) < Success)
		goto error;

	for(pfd.frame = 0;pfd.frame < pfd.frame_count;++pfd.frame)
	{
		if(!ccb.preview_mode)
			save_undo();

		if((err = poll_abort()) < Success)
			goto error;

		if((err = gb_seek_fcel_frame(ccb.start_cel, frame_a,
									 pfd.cbuf, FALSE)) < Success)
		{
			goto error;
		}
		if((err = gb_seek_fcel_frame(ccb.end_cel, frame_b,
									 pfd.cbuf, FALSE)) < Success)
		{
			goto error;
		}

		if(pfd.frame_count > 1)
		{
			mask_scale0 = rscale_by(SCALE_ONE, pfd.frame, pfd.frame_count-1);
			mask_scale1 = cmap_scale =
				rscale_by(SCALE_ONE, pfd.frame + 1,pfd.frame_count+1);

			if(pfd.reverse_wipe)
			{
				mask_scale0 = SCALE_ONE - mask_scale0;
				mask_scale1 = SCALE_ONE - mask_scale1;
			}
		}
		else
		{
			mask_scale0 = mask_scale1 = cmap_scale = SCALE_ONE/2;
		}


		if((err = (*get_mask_frame)(mask_scale0,mask_scale1,&pfd)) < Success)
			goto error;

		if((err = make_trans_colors(cmap_scale,cmapa,cmapb,dcmap)) < Success)
			goto error;

		if(!ccb.preview_mode && !cmaps_same(dcmap,undof->cmap))
			see_cmap();

		/* note cfit is done in absolute order so docfit is set to absolute
		 * order (not start and end) because the mask_move_cels() does
		 * move in this order and doesn't care about start and end */

		pfd.docfit = 0;
		if(make_simple_cfit(ccb.fcela->rc->cmap,dcmap,
							ccb.fcela->cfit,ccb.clearc))
		{
			pfd.docfit = 1;
		}
		if(make_simple_cfit(ccb.fcelb->rc->cmap,dcmap,
							ccb.fcelb->cfit,ccb.clearc))
		{
			pfd.docfit |= 2;
		}

		if((err = mask_move_cels(&pfd)) < Success)
			goto error;

		if(!ccb.preview_mode)
		{
			if(flix.hdr.frame_count == 0)
				err = write_first_flxframe(NULL,&flix,pfd.cbuf,pfd.dest);
			else
			{
				err = write_next_flxframe(NULL,&flix,pfd.cbuf,
										  pfd.history,pfd.dest);
			}
			if(err < Success)
				goto error;
			dirties();
		}
		else
		{
			++ccb.preview_frame; /* for poll abort verify in preview */
			zoom_unundo();
		}

		if(!vs.co_still)
		{
			++frame_a;
			++frame_b;
		}
	}
	goto done;

nomem_error:
	err = Err_no_memory;
error:
done:
	if(cleanup_pframe)
		(*cleanup_pframe)(&pfd);
	pj_gentle_free(pfd.cbuf);
	close_fcelio(ccb.fcelb);
	close_fcelio(ccb.fcela);
	return(err);
}
Esempio n. 30
0
Errcode init_screen(Screen_mode *smode,Screen_mode *altmode, 
					Errcode (*init_with_screen)(void *iwdat), void *iwdat ) 

/* try to open video in smode, if that fails try altmode if altmode is
 * is the same as smode, simply fail. If altmode is NULL try generic MCGA 
 * mode. if a screen is opened successfully setup every thing else
 * needed for menuing system, if window and menu system open fails, cleanup
 * screen and return Error. If smode is selected return 0 altmode 1. 
 * if screen stuff is open before this is called one must call 
 * cleanup_screen() first.  The init_with_screen() function
 * is used since most systems here need to have things intimately linked
 * with the screen that must be present for the screen to be considered
 * valid if it is NULL it won't be called. If it returns error the screen is
 * cleaned up and the error returned */
{
int err = Err_nogood;
Screen_mode sm;
Errcode goodret = 0;
extern char pj_mcga_name[];

	/* set up GS segment */
	pj_set_gs();

	/* open screen driver and open screen */

	sm = *smode;

	if(vb.ivmode == -1) /* not yet saved */
		vb.ivmode = pj_get_vmode(); /* save startup dos video mode */

	if((err = open_screen(&sm, sm.drv_name)) < Success)
	{
		if(altmode == smode) /* no alternate */
			goto error;
		if(altmode != NULL)
			sm = *altmode;
		else
		{
			clear_struct(&sm);
			strcpy(sm.drv_name,pj_mcga_name);
		}

		if ((err = open_screen(&sm, sm.drv_name)) < Success)
			goto error;
		goodret = 1;
	}
	else
		goodret = 0;

	/* install and set initial colormap */
	pj_get_default_cmap(vb.cel_a->cmap);
	pj_cmap_load(vb.cel_a,vb.cel_a->cmap);

	/* open window control on display rasters */
	{
	WscrInit newscr;

		clear_mem(&newscr,sizeof(newscr));
		newscr.max_wins = 10;
		newscr.disp_driver = vb.vd;
		newscr.cel_a = vb.cel_a;
		newscr.cel_b = vb.cel_b;
		newscr.flags = (WS_MUCOLORS); /* yep we want 'em */
		newscr.cursor = (Cursorhdr *)get_default_cursor();

		if((err = open_wscreen(&vb.screen,&newscr)) < 0)
			goto error;

		vb.screen->mc_ideals = &vconfg.mc_ideals;
	}

	/* set pre calc'd center point */

	vb.scrcent.x = vb.screen->wndo.width>>1;
	vb.scrcent.y = vb.screen->wndo.height>>1;

	/* for safety set initial window to whole screen */
	vb.pencel = (Rcel *)&(vb.screen->wndo); 

	if((err = init_muscreen(vb.screen)) < 0) /* initialize menu control */
		goto error;

	set_menu_scale(vb.screen);
	set_cursor(vb.screen->cursor);

	if((err = init_input()) < 0)  /* at this point we may use text boxes */
		goto error;

	if(init_with_screen != NULL
		&& (err = init_with_screen(iwdat)) < Success)
	{
		goto error;
	}

	init_wrefresh(vb.screen); 

	/* save actual operational setting in config file */

	if(memcmp(&sm,&vconfg.smode))
	{
		vconfg.smode = sm;
		rewrite_config();
	}
	return(goodret);
error:
	cleanup_screen();
	return(err);
}