Exemple #1
0
/*
 - enlarge - enlarge the strip
 == static void enlarge(struct parse *p, sopno size);
 */
static void
enlarge(
    struct parse *p,
    sopno size)
{
	sop *sp;

	_DIAGASSERT(p != NULL);

	if (p->ssize >= size)
		return;

	sp = (sop *)realloc(p->strip, size*sizeof(sop));
	if (sp == NULL) {
		SETERROR(REG_ESPACE);
		return;
	}
	p->strip = sp;
	p->ssize = size;
}
static gboolean
_write_attributes(GHashTable * attr_hash, int file, attr_writer_f writer, GError ** error)
{
	GHashTableIter iterator;
	gpointer key = NULL, value = NULL;
	GError *local_error = NULL;

	if (attr_hash == NULL) {
		SETERRCODE(error, EINVAL, "Invalid parameter attr_hash");
		return FALSE;
	}

	g_hash_table_iter_init(&iterator, attr_hash);

	while (g_hash_table_iter_next(&iterator, &key, &value)) {
		if (!writer(file, (gchar *) key, (gchar *) value, &local_error)) {
			SETERROR(error, "%s", local_error->message);
			g_clear_error(&local_error);
			return FALSE;
		}
	}

	return TRUE;
}
Exemple #3
0
/*
 - repeat - generate code for a bounded repetition, recursively if needed
 */
static void
repeat(struct parse *p,
    sopno start,		/* operand from here to end of strip */
    int from,			/* repeated from this number */
    int to)			/* to this number of times (maybe INFINITY) */
{
	sopno finish = HERE();
#	define	N	2
#	define	INF	3
#	define	REP(f, t)	((f)*8 + (t))
#	define	MAP(n)	(((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
	sopno copy;

	if (p->error != 0)	/* head off possible runaway recursion */
		return;

	assert(from <= to);

	switch (REP(MAP(from), MAP(to))) {
	case REP(0, 0):			/* must be user doing this */
		DROP(finish-start);	/* drop the operand */
		break;
	case REP(0, 1):			/* as x{1,1}? */
	case REP(0, N):			/* as x{1,n}? */
	case REP(0, INF):		/* as x{1,}? */
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, start);		/* offset is wrong... */
		repeat(p, start+1, 1, to);
		ASTERN(OOR1, start);
		AHEAD(start);			/* ... fix it */
		EMIT(OOR2, 0);
		AHEAD(THERE());
		ASTERN(O_CH, THERETHERE());
		break;
	case REP(1, 1):			/* trivial case */
		/* done */
		break;
	case REP(1, N):			/* as x?x{1,n-1} */
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, start);
		ASTERN(OOR1, start);
		AHEAD(start);
		EMIT(OOR2, 0);			/* offset very wrong... */
		AHEAD(THERE());			/* ...so fix it */
		ASTERN(O_CH, THERETHERE());
		copy = dupl(p, start+1, finish+1);
		assert(copy == finish+4);
		repeat(p, copy, 1, to-1);
		break;
	case REP(1, INF):		/* as x+ */
		INSERT(OPLUS_, start);
		ASTERN(O_PLUS, start);
		break;
	case REP(N, N):			/* as xx{m-1,n-1} */
		copy = dupl(p, start, finish);
		repeat(p, copy, from-1, to-1);
		break;
	case REP(N, INF):		/* as xx{n-1,INF} */
		copy = dupl(p, start, finish);
		repeat(p, copy, from-1, to);
		break;
	default:			/* "can't happen" */
		SETERROR(REG_ASSERT);	/* just in case */
		break;
	}
}
Exemple #4
0
/*
 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
 */
static int			/* was the simple RE an unbackslashed $? */
p_simp_re(struct parse *p,
    int starordinary)		/* is a leading * an ordinary character? */
{
	int c;
	int count;
	int count2;
	sopno pos;
	int i;
	sopno subno;
#	define	BACKSL	(1<<CHAR_BIT)

	pos = HERE();		/* repetion op, if any, covers from here */

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();
	if (c == '\\') {
		REQUIRE(MORE(), REG_EESCAPE);
		c = BACKSL | GETNEXT();
	}
	switch (c) {
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case BACKSL|'{':
		SETERROR(REG_BADRPT);
		break;
	case BACKSL|'(':
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		/* the MORE here is an error heuristic */
		if (MORE() && !SEETWO('\\', ')'))
			p_bre(p, '\\', ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
		break;
	case BACKSL|')':	/* should not get here -- must be user */
	case BACKSL|'}':
		SETERROR(REG_EPAREN);
		break;
	case BACKSL|'1':
	case BACKSL|'2':
	case BACKSL|'3':
	case BACKSL|'4':
	case BACKSL|'5':
	case BACKSL|'6':
	case BACKSL|'7':
	case BACKSL|'8':
	case BACKSL|'9':
		i = (c&~BACKSL) - '0';
		assert(i < NPAREN);
		if (p->pend[i] != 0) {
			assert(i <= p->g->nsub);
			EMIT(OBACK_, i);
			assert(p->pbegin[i] != 0);
			assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
			assert(OP(p->strip[p->pend[i]]) == ORPAREN);
			(void) dupl(p, p->pbegin[i]+1, p->pend[i]);
			EMIT(O_BACK, i);
		} else
			SETERROR(REG_ESUBREG);
		p->g->backrefs = 1;
		break;
	case '*':
		REQUIRE(starordinary, REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, (char)c);
		break;
	}

	if (EAT('*')) {		/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
	} else if (EATTWO('\\', '{')) {
		count = p_count(p);
		if (EAT(',')) {
			if (MORE() && isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EATTWO('\\', '}')) {	/* error heuristics */
			while (MORE() && !SEETWO('\\', '}'))
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
	} else if (c == '$')	/* $ (but not \$) ends it */
		return(1);

	return(0);
}
Exemple #5
0
/*
 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
 */
static void
p_ere_exp(struct parse *p)
{
	char c;
	sopno pos;
	int count;
	int count2;
	sopno subno;
	int wascaret = 0;

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();

	pos = HERE();
	switch (c) {
	case '(':
		REQUIRE(MORE(), REG_EPAREN);
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		if (!SEE(')'))
			p_ere(p, ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		MUSTEAT(')', REG_EPAREN);
		break;
#ifndef POSIX_MISTAKE
	case ')':		/* happens only if no current unmatched ( */
		/*
		 * You may ask, why the ifndef?  Because I didn't notice
		 * this until slightly too late for 1003.2, and none of the
		 * other 1003.2 regular-expression reviewers noticed it at
		 * all.  So an unmatched ) is legal POSIX, at least until
		 * we can get it fixed.
		 */
		SETERROR(REG_EPAREN);
		break;
#endif
	case '^':
		EMIT(OBOL, 0);
		p->g->iflags |= USEBOL;
		p->g->nbol++;
		wascaret = 1;
		break;
	case '$':
		EMIT(OEOL, 0);
		p->g->iflags |= USEEOL;
		p->g->neol++;
		break;
	case '|':
		SETERROR(REG_EMPTY);
		break;
	case '*':
	case '+':
	case '?':
		SETERROR(REG_BADRPT);
		break;
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case '\\':
		REQUIRE(MORE(), REG_EESCAPE);
		c = GETNEXT();
		ordinary(p, c);
		break;
	case '{':		/* okay as ordinary except if digit follows */
		REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, c);
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	/* we call { a repetition if followed by a digit */
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ))
		return;		/* no repetition, we're done */
	NEXT();

	REQUIRE(!wascaret, REG_BADRPT);
	switch (c) {
	case '*':	/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
		break;
	case '+':
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		break;
	case '?':
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, pos);		/* offset slightly wrong */
		ASTERN(OOR1, pos);		/* this one's right */
		AHEAD(pos);			/* fix the OCH_ */
		EMIT(OOR2, 0);			/* offset very wrong... */
		AHEAD(THERE());			/* ...so fix it */
		ASTERN(O_CH, THERETHERE());
		break;
	case '{':
		count = p_count(p);
		if (EAT(',')) {
			if (isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EAT('}')) {	/* error heuristics */
			while (MORE() && PEEK() != '}')
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ) )
		return;
	SETERROR(REG_BADRPT);
}
Exemple #6
0
/*
 - cli_regcomp_real - interface for parser and compilation
 */
int				/* 0 success, otherwise REG_something */
cli_regcomp_real(regex_t *preg, const char *pattern, int cflags)
{
	struct parse pa;
	struct re_guts *g;
	struct parse *p = &pa;
	int i;
	size_t len;
#ifdef REDEBUG
#	define	GOODFLAGS(f)	(f)
#else
#	define	GOODFLAGS(f)	((f)&~REG_DUMP)
#endif

	cflags = GOODFLAGS(cflags);
	if ((cflags&REG_EXTENDED) && (cflags&REG_NOSPEC))
		return(REG_INVARG);

	if (cflags&REG_PEND) {
		if (preg->re_endp < pattern)
			return(REG_INVARG);
		len = preg->re_endp - pattern;
	} else
		len = strlen((const char *)pattern);

	/* do the mallocs early so failure handling is easy */
	g = (struct re_guts *)cli_malloc(sizeof(struct re_guts) +
							(NC-1)*sizeof(cat_t));
	if (g == NULL)
		return(REG_ESPACE);
	p->ssize = len/(size_t)2*(size_t)3 + (size_t)1;	/* ugh */
	p->strip = (sop *)cli_calloc(p->ssize, sizeof(sop));
	p->slen = 0;
	if (p->strip == NULL) {
		free((char *)g);
		return(REG_ESPACE);
	}

	/* set things up */
	p->g = g;
	p->next = (char *)pattern;	/* convenience; we do not modify it */
	p->end = p->next + len;
	p->error = 0;
	p->ncsalloc = 0;
	for (i = 0; i < NPAREN; i++) {
		p->pbegin[i] = 0;
		p->pend[i] = 0;
	}
	g->csetsize = NC;
	g->sets = NULL;
	g->setbits = NULL;
	g->ncsets = 0;
	g->cflags = cflags;
	g->iflags = 0;
	g->nbol = 0;
	g->neol = 0;
	g->must = NULL;
	g->mlen = 0;
	g->nsub = 0;
	g->ncategories = 1;	/* category 0 is "everything else" */
	g->categories = &g->catspace[-(CHAR_MIN)];
	(void) memset((char *)g->catspace, 0, NC*sizeof(cat_t));
	g->backrefs = 0;

	/* do it */
	EMIT(OEND, 0);
	g->firststate = THERE();
	if (cflags&REG_EXTENDED)
		p_ere(p, OUT);
	else if (cflags&REG_NOSPEC)
		p_str(p);
	else
		p_bre(p, OUT, OUT);
	EMIT(OEND, 0);
	g->laststate = THERE();

	/* tidy up loose ends and fill things in */
	categorize(p, g);
	stripsnug(p, g);
	findmust(p, g);
	g->nplus = pluscount(p, g);
	g->magic = MAGIC2;
	preg->re_nsub = g->nsub;
	preg->re_g = g;
	preg->re_magic = MAGIC1;
#ifndef REDEBUG
	/* not debugging, so can't rely on the assert() in cli_regexec() */
	if (g->iflags&REGEX_BAD)
		SETERROR(REG_ASSERT);
#endif

	/* win or lose, we're done */
	if (p->error != 0)	/* lose */
		cli_regfree(preg);
	return(p->error);
}
gboolean
set_rawx_full_info_in_attr(const char *p, int filedes, GError **error,
		struct content_textinfo_s * content, struct chunk_textinfo_s * chunk,
		const char* compression_info, const char* compressed_size)
{
	struct attr_handle_s *attr_handle;
	GError *e = NULL;

	if (!_lazy_load_attr_from_file(p, &attr_handle, &e)) {
		SETERROR(error, "Failed to init the attribute management context : %s", e->message);
		g_clear_error(&e);
		return FALSE;
	}

	if (chunk) {
		_up(chunk->hash);

		SET(ATTR_NAME_CHUNK_ID, chunk->id);
		SET(ATTR_NAME_CHUNK_SIZE, chunk->size);
		SET(ATTR_NAME_CHUNK_HASH, chunk->hash);
		SET(ATTR_NAME_CHUNK_POS, chunk->position);
		SET(ATTR_NAME_CHUNK_METADATA, chunk->metadata);
	}

	if (content) {
		_up(content->container_id);
		_up(content->content_id);

		SET(ATTR_NAME_CONTENT_CONTAINER, content->container_id);
		SET(ATTR_NAME_CONTENT_ID, content->content_id);
		SET(ATTR_NAME_CONTENT_PATH, content->path);
		SET(ATTR_NAME_CONTENT_VERSION, content->version);
		SET(ATTR_NAME_CONTENT_SIZE, content->size);
		SET(ATTR_NAME_CONTENT_NBCHUNK, content->chunk_nb);

		SET(ATTR_NAME_CONTENT_STGPOL, content->storage_policy);
		SET(ATTR_NAME_CONTENT_MIMETYPE, content->mime_type);
		SET(ATTR_NAME_CONTENT_CHUNKMETHOD, content->chunk_method);
	}

	SET(ATTR_NAME_CHUNK_COMPRESSED_SIZE, compressed_size);
	SET(ATTR_NAME_CHUNK_METADATA_COMPRESS, compression_info);

	gboolean rc;
	if (filedes < 0)
		rc = _commit_attr_handle(attr_handle, &e);
	else
		rc = _commit_v2_attr_handle(filedes, attr_handle, &e);

	if (!rc) {
		SETERROR(error, "Could not write all the attributes on disk : %s", e->message);
		g_clear_error(&e);
		_clean_attr_handle(attr_handle, FALSE);
		return FALSE;
	}

	_clean_attr_handle(attr_handle, FALSE);
	return TRUE;

error_set_attr:
	SETERROR(error, "Failed to set attr in handle : %s", e->message);
	g_clear_error(&e);
	_clean_attr_handle(attr_handle, FALSE);
	return FALSE;
}
Exemple #8
0
/****************************************************************************
REMARKS:
Does the hard work to create the actual display device context.
****************************************************************************/
static MGLDC * _MGL_createDisplayDC(
    int mode,
    int virtualX,
    int virtualY,
    int numBuffers,
    ibool stereo,
    int refreshRate)
{
    MGLDC       *dc;
    driverent   *entry;
    modeent     *me = &DEV.availableModes[mode];
    PM_HWND     hwndConsole = (PM_HWND)NULL;

    /* Check if the mode is currently available */
    __MGL_result = grOK;
    if (mode >= DEV.numModes || DEV.availableModes[mode].driver == 0xFF) {
        SETERROR(grInvalidMode);
        return NULL;
        }
    _MGL_destroyCurrentMode();

    /* Allocate memory for the new DC */
    if ((dc = _LST_newNode(sizeof(MGLDC))) == NULL) {
        FATALERROR(grNoMem);
        return NULL;
        }

    /* The display device list is currently empty, so create the new
     * list and start the specified graphics mode
     */
    if ((DEV.dispDCList = _LST_create()) == NULL) {
        FATALERROR(grNoMem);
        goto Error;
        }

    /* Open a new fullscreen console for the mode, and save it's state */
    DEV.stateBuf = NULL;
    if (_MGL_consoleSupport && (GET_CURRENT_DEVICE() == 0)) {
        hwndConsole = PM_openConsole((PM_HWND)_MGL_hwndFullScreen,GET_CURRENT_DEVICE(),me->xRes,me->yRes,me->bits,true);
        if ((DEV.stateBuf = PM_malloc(PM_getConsoleStateSize())) == NULL) {
            FATALERROR(grNoMem);
            goto Error;
            }
        PM_saveConsoleState(DEV.stateBuf,hwndConsole);
        }

    /* Now intialise the driver */
    entry = &DEV.driverTable[me->driver];
    if (!_MGL_initDC(dc,entry,me,(MGL_HWND)hwndConsole,virtualX,virtualY,numBuffers,stereo,refreshRate))
        goto Error;

    /* Set the suspend application callback for the console */
    PM_setSuspendAppCallback(_MGL_suspendAppProc);

    /* Set up the mouse cursor */
    if (_MGL_consoleSupport) {
        _MS_setDisplayDC(dc);
        MS_setCursor(MGL_DEF_CURSOR);
        MS_moveTo(dc->mi.xRes/2,dc->mi.yRes/2);
        }

    /* Now clear the device page */
    MGL_makeCurrentDC(dc);
    MGL_clearDevice();

    /* And clear the event queue of any extraneous events */
    if (_MGL_consoleSupport) {
        EVT_flush(EVT_EVERYEVT);
    }

    /* Add the new DC to the start of the DC chain */
    RESET_DEFAULT_CW();
    _LST_addToHead(DEV.dispDCList,dc);
    return dc;

Error:
    if (hwndConsole) {
        if (DEV.stateBuf) {
            PM_restoreConsoleState(DEV.stateBuf,hwndConsole);
            PM_free(DEV.stateBuf);
            DEV.stateBuf = NULL;
            }
        PM_closeConsole(hwndConsole);
        }
    DEV.fullScreen = false;
    if (DEV.dispDCList && DEV.dispDCList->count == 0) {
        _LST_destroy(DEV.dispDCList,_LST_freeNode);
        DEV.dispDCList = NULL;
        }
    _LST_freeNode(dc);
    return NULL;
}
Exemple #9
0
/****************************************************************************
DESCRIPTION:
Copies a block of image data with destination transparency.

HEADER:
mgraph.h

PARAMETERS:
dst			- Destination device context
src			- Source device context
left		- Left coordinate of source image
top			- Top coordinate of source image
right		- Right coordinate of source image
bottom		- Bottom coordinate of source image
dstLeft		- Left coordinate of destination
dstTop		- Top coordinate of destination
transparent	- Transparent color to skip in source image
op			- Write mode to use during Blt

REMARKS:
Copies a block of bitmap data form one device context to another with either
source or destination transparency. When transferring the data with
destination transparency, pixels in the destination image that are equal to
the specified transparent color will be updated, and those pixels that are
not the same will be skipped. This is effectively the operation performed
for 'blueScreen'ing or color keying and can also be used for drawing
transparent sprites. Note however that destination transparency is very
slow in software compared to source transparency!

This routine has been highly optimized for maximum performance in all pixel
depths, so will provide a very fast method for performing transparent sprite
animation. However you may find that if you can use alternative techniques to
pre-compile the sprites (like using run length encoding etc.) you will be
able to build faster software based sprite animation code that can directly
access the device context surface. However this routine can also be used to
perform hardware accelerated Blt's between offscreen memory device's and the
display device when running in fullscreen modes, providing the hardware
accelerator (if present) can support this operation. If you have a hardware
accelerator capable of this, this will provide the ultimate performance for
transparent sprite animation.

The source and destination rectangles are clipped according to the current
clipping rectangles for the source and destination device contexts
respectively.

Note: 	The pixel depth and pixel format for the source bitmap and the
		device contexts must be the same or this routine will simply do
		nothing. This routine also only works with pixel depths that are
		at least 8 bits deep.

SEE ALSO:
MGL_srcTransBlt, MGL_dstTransBlt, MGL_bitBlt
****************************************************************************/
void MGLAPI MGL_dstTransBltCoord(
	MGLDC *dst,
	MGLDC *src,
	int left,
	int top,
	int right,
	int bottom,
	int dstLeft,
	int dstTop,
	color_t transparent,
	int op)
{
	rect_t	d,r,clip;
	int 	srcLeft,srcTop,srcRight,srcBottom;

	/* Check for valid contexts */
	if ((src == dst) || src->mi.bitsPerPixel < 8 || (src->mi.bitsPerPixel
			!= dst->mi.bitsPerPixel)) {
		SETERROR(grInvalidDevice);
		return;
		}

	/* In order to clip the results, we first clip the source rectangle to
	 * the source device context, and then clip the destination rectangle to
	 * the destination device context.
	 */
	if (src == _MGL_dcPtr)
		src = &DC;
	if (dst == _MGL_dcPtr)
		dst = &DC;
	d.left = left;				d.top = top;
	d.right = right;			d.bottom = bottom;
	if (!MGL_sectRect(src->a.clipRect,d,&d))
		return;
	dstLeft += (d.left - left);	dstTop += (d.top - top);
	left = d.left;				right = d.right;
	top = d.top;				bottom = d.bottom;

	/* Clip to destination device context */
	d.left = dstLeft;
	d.top = dstTop;
	d.right = dstLeft + (right-left);
	d.bottom = dstTop + (bottom-top);
	if (!MGL_sectRect(dst->a.clipRect,d,&d))
		return;
	left += (d.left - dstLeft);	right = left + (d.right - d.left);
	top += (d.top - dstTop);	bottom = top + (d.bottom - d.top);
	dstLeft = d.left;			dstTop = d.top;

	/* Now perform the blit operation */
	MAKE_HARDWARE_CURRENT(dst,true);
	if (src->deviceType == MGL_MEMORY_DEVICE || dst->deviceType == MGL_MEMORY_DEVICE) {
		/* Copy from one DC to any other DC when one is in system memory */
		if (dst->a.clipRegion) {
			left += src->a.viewPort.left;
			top += src->a.viewPort.top;
			right += src->a.viewPort.left;
			bottom += src->a.viewPort.top;
			d.left = dstLeft + dst->a.viewPort.left;
			d.top = dstTop + dst->a.viewPort.top;
			d.right = d.left + (right-left);
			d.bottom = d.top + (bottom-top);
			BEGIN_CLIP_REGION(clip,dst->intClipRegion);
				if (MGL_sectRect(clip,d,&r)) {
					srcLeft = left + (r.left - d.left);
					srcRight = srcLeft + (r.right - r.left);
					srcTop = top + (r.top - d.top);
					srcBottom = srcTop + (r.bottom - r.top);
					dst->r.DstTransBltSys(src->surface,src->mi.bytesPerLine,
						srcLeft,srcTop,srcRight-srcLeft,srcBottom-srcTop,
						r.left,r.top,op,transparent,false);
					}
			END_CLIP_REGION;
			}
		else {
			dst->r.DstTransBltSys(src->surface,src->mi.bytesPerLine,
				left + src->a.viewPort.left,top + src->a.viewPort.top,
				right - left,bottom - top,
				dstLeft + dst->a.viewPort.left,dstTop + dst->a.viewPort.top,
				op,transparent,false);
			}
		}
	else {
		/* BitBlt between two device contexts which may both be in
		 * hardware. We allow the MGL device driver determine how to
		 * handle the case, so that it can be done in hardware if
		 * available (such as blitting from offscreen DC or back buffers).
		 */
		if (dst->a.clipRegion) {
			left += src->a.viewPort.left;
			top += src->a.viewPort.top;
			right += src->a.viewPort.left;
			bottom += src->a.viewPort.top;
			d.left = dstLeft + dst->a.viewPort.left;
			d.top = dstTop + dst->a.viewPort.top;
			d.right = d.left + (right-left);
			d.bottom = d.top + (bottom-top);
			BEGIN_CLIP_REGION(clip,dst->intClipRegion);
				if (MGL_sectRect(clip,d,&r)) {
					srcLeft = left + (r.left - d.left);
					srcRight = srcLeft + (r.right - r.left);
					srcTop = top + (r.top - d.top);
					srcBottom = srcTop + (r.bottom - r.top);
					dstLeft = r.left;
					dstTop = r.top;
					src->r.DstTransBltDC(src,dst,
						srcLeft,srcTop,srcRight-srcLeft,srcBottom-srcTop,
						dstLeft,dstTop,op,transparent);
					}
			END_CLIP_REGION;
			}
		else {
			src->r.DstTransBltDC(src,dst,
				left + src->a.viewPort.left,top + src->a.viewPort.top,
				right - left,bottom - top,
				dstLeft + dst->a.viewPort.left,dstTop + dst->a.viewPort.top,op,transparent);
			}
		}
	RESTORE_HARDWARE(dst,true);
}
Exemple #10
0
/****************************************************************************
DESCRIPTION:
Stretches a block of image data from one device context to another.

HEADER:
mgraph.h

PARAMETERS:
dst			- Destination device context
src			- Source device context
left		- Left coordinate of source image
top			- Top coordinate of source image
right		- Right coordinate of source image
bottom	   	- Bottom coordinate of source image
dstLeft		- Left coordinate of destination image
dstTop		- Top coordinate of destination image
dstRight	- Right coordinate of destination image 
dstBottom	- Bottom coordinate of destination image 
op			- Write mode to use during Blt

REMARKS:
Copies a block of bitmap data form one device context to another, stretching or
shrinking the image as necessary to fit the destination rectangle for the destination
device context.

The source and destination device context may not be the same. This routine
has been highly optimized for absolute maximum performance, so it will
provide the fastest method of stretching bitmap data between device contexts,
and can also be used to stretch bitmap data from a memory device context
to a windowed device context.

This function will correctly handle StretchBlt's across device contexts with
differing pixel depths, and will perform the necessary pixel format
translation to convert from the source device to the destination device.
Note that although the code to implement this is highly optimized, this can
be a time consuming operation so you should attempt to pre-convert all
bitmaps to the current display device pixel format for maximum performance
if possible.

MGL does however have special case code to specifically handle translation of
24 bit RGB format bitmaps (the standard RGB DIB format used by Video for
Windows) to all 8 bit and above pixel formats. When converting from 24 bit
to 8 bit, MGL will dither bitmaps in real time from 24 bit to the 8 bit
halftone palette. This provides a solid foundation to build real time 24 bit
motion video playback in all supported video modes in MGL.

Note that when MGL_bitBlt is called for 4 and 8 bit source bitmaps MGL first
checks if the color palettes for the source and destination bitmaps are the
same. If they are not, MGL translates the pixel values from the source bitmap
to the destination color palette, looking for the closest match color if an
exact match is not found. In order to obtain maximum performance for blt'ing
bitmaps in color index modes, you should ensure that the color palette in
the sourcedevice matches the color palette in the destination device, or
you can turn off all identity palette checking in MGL with the
MGL_checkIdentityPalette function.

The source and destination rectangles are clipped according to the current
clipping rectangles for the source and destination device contexts
respectively, however the zoom factor is determined using the unclipped
source and destination rectangles.

SEE ALSO:
MGL_stretchBlt, MGL_bitBlt, MGL_bitBltCoord
****************************************************************************/
void MGLAPI MGL_stretchBltCoord(
	MGLDC *dst,
	MGLDC *src,
	int left,
	int top,
	int right,
	int bottom,
	int dstLeft,
	int dstTop,
	int dstRight,
	int dstBottom,
	int op)
{
	rect_t	d,r,clip;
	int		deltaSrc,deltaDst;
	int 	fdTop, fdLeft;
	fix32_t	zoomx,zoomy;
	ibool   clipIt = false;

	/* Check for valid device contexts */
	if ((src == dst) || src->mi.bitsPerPixel < 8) {
		SETERROR(grInvalidDevice);
		return;
		}
	if (src == _MGL_dcPtr)
		src = &DC;
	if (dst == _MGL_dcPtr)
		dst = &DC;

	/* Calculate the x zoom factor */
	deltaSrc = right - left;
	deltaDst = dstRight - dstLeft;
	if (deltaDst == deltaSrc)
		zoomx = MGL_FIX_1;
	else if (deltaDst == (deltaSrc * 2))
		zoomx = MGL_FIX_2;
	else
		zoomx = MGL_FixDiv(MGL_TOFIX(deltaDst),MGL_TOFIX(deltaSrc));

	/* Calculate the y zoom factor */
	deltaSrc = bottom - top;
	deltaDst = dstBottom - dstTop;
	if (deltaDst == deltaSrc)
		zoomy = MGL_FIX_1;
	else if (deltaDst == (deltaSrc * 2))
		zoomy = MGL_FIX_2;
	else
		zoomy = MGL_FixDiv(MGL_TOFIX(deltaDst),MGL_TOFIX(deltaSrc));

	/* Handle special case of 1:1 stretch */
	if (zoomx == MGL_FIX_1 && zoomy == MGL_FIX_1) {
		MGL_bitBltCoord(dst,src,left,top,right,bottom,dstLeft,dstTop,op);
		return;
		}

	/* Clip to the source device context */
	d.left = left;				d.top = top;
	d.right = right;			d.bottom = bottom;
	if (!MGL_sectRect(src->a.clipRect,d,&d))
		return;
	fdLeft = MGL_TOFIX(dstLeft) + ((d.left - left) * zoomx);
	fdTop = MGL_TOFIX(dstTop) + ((d.top - top) * zoomy);
	left = d.left;				right = d.right;
	top = d.top;				bottom = d.bottom;
	dstLeft = MGL_FIXROUND(fdLeft);
	dstTop = MGL_FIXROUND(fdTop);
	dstRight = dstLeft+MGL_FIXTOINT((right-left)*zoomx);
	dstBottom = dstTop+MGL_FIXTOINT((bottom-top)*zoomy);

	/* Clip the destination device context */
	d.left = dstLeft;			d.top = dstTop;
	d.right = dstRight;			d.bottom = dstBottom;
	if (!MGL_sectRect(dst->a.clipRect,d,&d))
		return;
	if ((dst->a.clipRegion) || (d.left != dstLeft) || (d.right  != dstRight)
			|| (d.top != dstTop) || (d.bottom != dstBottom))
		clipIt = true;

	/* Now perform the blit operation */
	MAKE_HARDWARE_CURRENT(dst,true);
	if (src->deviceType == MGL_MEMORY_DEVICE || dst->deviceType == MGL_MEMORY_DEVICE) {
		/* Copy from one DC to any other DC when one is in system memory */
		if (NEED_TRANSLATE_DC(src,dst)) {
			/* Translate the pixel information when doing the stretch Blt */
			if (dst->a.clipRegion) {
				left += src->a.viewPort.left;
				top += src->a.viewPort.top;
				right += src->a.viewPort.left;
				bottom += src->a.viewPort.top;
				d.left = dstLeft + dst->a.viewPort.left;
				d.top = dstTop + dst->a.viewPort.top;
				d.right = dstRight + dst->a.viewPort.left;
				d.bottom = dstBottom + dst->a.viewPort.top;
				BEGIN_CLIP_REGION(clip,dst->intClipRegion);
					if (MGL_sectRect(clip,d,&r)) {
						dst->r.StretchConvertBltSys(src->surface,src->mi.bytesPerLine,
							left,top,right-left,bottom-top,
							d.left,d.top,d.right-d.left,d.bottom-d.top,clipIt,
							r.left,r.top,r.right,r.bottom,
							src->mi.bitsPerPixel,GAPF(&src->pf),GAPAL(dst->colorTab),
							GAPAL(src->colorTab),dst->a.ditherMode,op,false);
						}
				END_CLIP_REGION;
				}
			else {
				dst->r.StretchConvertBltSys(src->surface,src->mi.bytesPerLine,
					left + src->a.viewPort.left,top + src->a.viewPort.top,
					right-left,bottom-top,
					dstLeft + dst->a.viewPort.left,dstTop + dst->a.viewPort.top,
					dstRight-dstLeft,dstBottom-dstTop,clipIt,
					dst->intClipRect.left,dst->intClipRect.top,
					dst->intClipRect.right,dst->intClipRect.bottom,
					src->mi.bitsPerPixel,GAPF(&src->pf),GAPAL(dst->colorTab),
					GAPAL(src->colorTab),dst->a.ditherMode,op,false);
				}
			}
		else {
			/* Perform the stretch blit with no pixel format conversion */
			if (dst->a.clipRegion) {
				left += src->a.viewPort.left;
				top += src->a.viewPort.top;
				right += src->a.viewPort.left;
				bottom += src->a.viewPort.top;
				d.left = dstLeft + dst->a.viewPort.left;
				d.top = dstTop + dst->a.viewPort.top;
				d.right = dstRight + dst->a.viewPort.left;
				d.bottom = dstBottom + dst->a.viewPort.top;
				BEGIN_CLIP_REGION(clip,dst->intClipRegion);
					if (MGL_sectRect(clip,d,&r)) {
						dst->r.StretchBltSys(src->surface,src->mi.bytesPerLine,
							left,top,right-left,bottom-top,
							d.left,d.top,d.right-d.left,d.bottom-d.top,clipIt,
							r.left,r.top,r.right,r.bottom,op,false);
						}
				END_CLIP_REGION;
				}
			else {
				dst->r.StretchBltSys(src->surface,src->mi.bytesPerLine,
					left + src->a.viewPort.left,top + src->a.viewPort.top,
					right-left,bottom-top,
					dstLeft + dst->a.viewPort.left,dstTop + dst->a.viewPort.top,
					dstRight-dstLeft,dstBottom-dstTop,clipIt,
					dst->intClipRect.left,dst->intClipRect.top,
					dst->intClipRect.right,dst->intClipRect.bottom,
					op,false);
				}
			}
		}
	else {
		/* StretchBlt between two device contexts which may both be in
		 * hardware. We allow the MGL device driver determine how to
		 * handle the case, so that it can be done in hardware if
		 * available (such as blitting from offscreen DC or back buffers).
		 */
		if (dst->a.clipRegion) {
			left += src->a.viewPort.left;
			top += src->a.viewPort.top;
			right += src->a.viewPort.left;
			bottom += src->a.viewPort.top;
			d.left = dstLeft + dst->a.viewPort.left;
			d.top = dstTop + dst->a.viewPort.top;
			d.right = dstRight + dst->a.viewPort.left;
			d.bottom = dstBottom + dst->a.viewPort.top;
			BEGIN_CLIP_REGION(clip,dst->intClipRegion);
				if (MGL_sectRect(clip,d,&r)) {
					dst->r.StretchBltDC(src,dst,
						left,top,right-left,bottom-top,
						d.left,d.top,d.right-d.left,d.bottom-d.top,clipIt,
						r.left,r.top,r.right,r.bottom,op);
					}
			END_CLIP_REGION;
			}
		else {
			dst->r.StretchBltDC(src,dst,
				left + src->a.viewPort.left,top + src->a.viewPort.top,
				right-left,bottom-top,
				dstLeft + dst->a.viewPort.left,dstTop + dst->a.viewPort.top,
				dstRight-dstLeft,dstBottom-dstTop,clipIt,
				dst->intClipRect.left,dst->intClipRect.top,
				dst->intClipRect.right,dst->intClipRect.bottom,op);
			}
		}
	RESTORE_HARDWARE(dst,true);
}
Exemple #11
0
/*
 - p_b_term - parse one term of a bracketed character list
 == static void p_b_term(struct parse *p, cset *cs);
 */
static void
p_b_term(
    struct parse *p,
    cset *cs)
{
	char c;
	char start, finish;
	int i;

	_DIAGASSERT(p != NULL);
	_DIAGASSERT(cs != NULL);

	/* classify what we've got */
	switch ((MORE()) ? PEEK() : '\0') {
	case '[':
		c = (MORE2()) ? PEEK2() : '\0';
		break;

	case '-':
		SETERROR(REG_ERANGE);
		return;			/* NOTE RETURN */

	default:
		c = '\0';
		break;
	}

	switch (c) {
	case ':':		/* character class */
		NEXT2();
		REQUIRE(MORE(), REG_EBRACK);
		c = PEEK();
		REQUIRE(c != '-' && c != ']', REG_ECTYPE);
		p_b_cclass(p, cs);
		REQUIRE(MORE(), REG_EBRACK);
		REQUIRE(EATTWO(':', ']'), REG_ECTYPE);
		break;
	case '=':		/* equivalence class */
		NEXT2();
		REQUIRE(MORE(), REG_EBRACK);
		c = PEEK();
		REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
		p_b_eclass(p, cs);
		REQUIRE(MORE(), REG_EBRACK);
		REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
		break;
	default:		/* symbol, ordinary character, or range */
/* xxx revision needed for multichar stuff */
		start = p_b_symbol(p);
		if (SEE('-') && MORE2() && PEEK2() != ']') {
			/* range */
			NEXT();
			if (EAT('-'))
				finish = '-';
			else
				finish = p_b_symbol(p);
		} else
			finish = start;
/* xxx what about signed chars here... */
		REQUIRE(start <= finish, REG_ERANGE);
		for (i = start; i <= finish; i++)
			CHadd(cs, i);
		break;
	}
}
Exemple #12
0
static int gssapi_decode_packet(void *context,
				const char *input, unsigned inputlen,
				char **output, unsigned *outputlen)
{
    context_t *text = (context_t *) context;
    OM_uint32 maj_stat, min_stat;
    gss_buffer_t input_token, output_token;
    gss_buffer_desc real_input_token, real_output_token;
    int result;
    
    if (text->state != SASL_GSSAPI_STATE_AUTHENTICATED) {
	SETERROR(text->utils, "GSSAPI Failure");
	return SASL_NOTDONE;
    }
    
    input_token = &real_input_token; 
    real_input_token.value = (char *) input;
    real_input_token.length = inputlen;
    
    output_token = &real_output_token;
    output_token->value = NULL;
    output_token->length = 0;
    
    GSS_LOCK_MUTEX(text->utils);
    maj_stat = gss_unwrap (&min_stat,
			   text->gss_ctx,
			   input_token,
			   output_token,
			   NULL,
			   NULL);
    GSS_UNLOCK_MUTEX(text->utils);
    
    if (GSS_ERROR(maj_stat))
	{
	    sasl_gss_seterror(text->utils,maj_stat,min_stat);
	    if (output_token->value) {
		GSS_LOCK_MUTEX(text->utils);
		gss_release_buffer(&min_stat, output_token);
		GSS_UNLOCK_MUTEX(text->utils);
	    }
	    return SASL_FAIL;
	}
    
    if (outputlen)
	*outputlen = output_token->length;
    
    if (output_token->value) {
	if (output) {
	    result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
				     &text->decode_once_buf_len,
				     *outputlen);
	    if(result != SASL_OK) {
		GSS_LOCK_MUTEX(text->utils);
		gss_release_buffer(&min_stat, output_token);
		GSS_UNLOCK_MUTEX(text->utils);
		return result;
	    }
	    *output = text->decode_once_buf;
	    memcpy(*output, output_token->value, *outputlen);
	}
	GSS_LOCK_MUTEX(text->utils);
	gss_release_buffer(&min_stat, output_token);
	GSS_UNLOCK_MUTEX(text->utils);
    }
    
    return SASL_OK;
}