Esempio n. 1
0
/**
 * toChar
 */
JSValueRef toCharForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    PRIMITIVE_GET_ARRAY(char);
    GET_NUMBER(0,index);
    JSChar buf[1];
    buf[0] = (JSChar)value[(size_t)index];
    JSStringRef stringRef = JSStringCreateWithCharacters(buf, 1);
    JSValueRef result = JSValueMakeString(ctx,stringRef);
    JSStringRelease(stringRef);
    return result;
}
Esempio n. 2
0
File: cbc.c Progetto: vocho/openqnx
/*
 * This encrypts using the Cipher Block Chaining mode of DES
 */
int
cbc_encode(char *msgbuf, int n, FILE *fp)
{
	int inverse = 0;	/* 0 to encrypt, 1 to decrypt */

	/*
	 * do the transformation
	 */
	if (n == 8) {
		for (n = 0; n < 8; n++)
			CHAR(msgbuf, n) ^= CHAR(ivec, n);
		DES_XFORM(UBUFFER(msgbuf));
		MEMCPY(BUFFER(ivec), BUFFER(msgbuf), 8);
		return WRITE(BUFFER(msgbuf), 8, fp);
	}
	/*
	 * at EOF or last block -- in either case, the last byte contains
	 * the character representation of the number of bytes in it
	 */
/*
	MEMZERO(msgbuf +  n, 8 - n);
*/
	/*
	 *  Pad the last block randomly
	 */
	(void)MEMCPY(BUFFER(msgbuf + n), BUFFER(pvec), 8 - n);
	CHAR(msgbuf, 7) = n;
	for (n = 0; n < 8; n++)
		CHAR(msgbuf, n) ^= CHAR(ivec, n);
	DES_XFORM(UBUFFER(msgbuf));
	return WRITE(BUFFER(msgbuf), 8, fp);
}
Esempio n. 3
0
/*
** Pad the requested row from the current width to 'newWidth' with spaces...
*/
void
_DtTermPrimBufferPadLineWc
(
    const TermBuffer  tb,
    const short       row,
    const short       width
)
{
    short       i;
    short       widthInc;
    TermLine    line;
    wchar_t    *pwc;
    
    line = LINE_OF_TBUF(tb, row);

    if (isDebugFSet('i', 1)) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
	(void) _termBufferValidateLineWc(tb, row);
    }

    /*
    ** if this line is part of the selection, disown the selection...
    */
    if (IS_IN_SELECTION(line, MIN(width, WIDTH(line)),
			MAX(width, WIDTH(line))))
    {
	(void) _DtTermPrimSelectDisown(WIDGET(tb));
    }

    widthInc = MIN(COLS(tb), width) - WIDTH(line);

    for (i = 0, pwc = (wchar_t *)BUFFER(line) + MAX(0, LENGTH(line));
         i < widthInc;
         i++, pwc++)
    {
        *pwc = L' ';
	LENGTH(line)++;
    }
    if (CLEAR_ENH(tb))
    {
        (*CLEAR_ENH(tb))(tb, row, WIDTH(line), widthInc);
    }
    _DtTermPrimBufferSetLineWidth(tb, row, WIDTH(line) + widthInc);
    if (isDebugFSet('i', 1)) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
	_termBufferValidateLineWc(tb, row);
    }
}
Esempio n. 4
0
static value_t Buffer_iterate( PREFUNC, value_t buf )
{
	ARGCHECK_1( buf );
	if (BUFFER(self)->size) {
		struct closure *out = ALLOC( Buffer_iterator_function, 2 );
		out->slots[0] = buf;
		out->slots[1] = num_zero;
		return out;
	}
	else {
		return &Buffer_iterator_done;
	}
}
Esempio n. 5
0
static VAStatus lnc__MPEG4ES_process_picture_param(context_ENC_p ctx, object_buffer_p obj_buffer)
{
    VAStatus vaStatus = VA_STATUS_SUCCESS;
    VAEncPictureParameterBufferMPEG4 *pBuffer;
    lnc_cmdbuf_p cmdbuf = ctx->obj_context->lnc_cmdbuf;
    IMG_BOOL bIsVOPCoded = IMG_TRUE;

    ASSERT(obj_buffer->type == VAEncPictureParameterBufferType);

    if ((obj_buffer->num_elements != 1) ||
        (obj_buffer->size != sizeof(VAEncPictureParameterBufferMPEG4))) {
        return VA_STATUS_ERROR_UNKNOWN;
    }

    /* Transfer ownership of VAEncPictureParameterBufferMPEG4 data */
    pBuffer = (VAEncPictureParameterBufferMPEG4 *) obj_buffer->buffer_data;
    obj_buffer->buffer_data = NULL;
    obj_buffer->size = 0;

    ctx->ref_surface = SURFACE(pBuffer->reference_picture);
    ctx->dest_surface = SURFACE(pBuffer->reconstructed_picture);
    ctx->coded_buf = BUFFER(pBuffer->coded_buf);

    ASSERT(ctx->Width == pBuffer->picture_width);
    ASSERT(ctx->Height == pBuffer->picture_height);

    if (ctx->sRCParams.RCEnable && ctx->sRCParams.FrameSkip)
        bIsVOPCoded = IMG_FALSE;

    /* save current cmdbuf write pointer for MPEG4 frameskip redo
     * MPEG4 picture header need re-patch, and no slice header needed
     * for a skipped frame
     */
    cmdbuf->cmd_idx_saved_frameskip = cmdbuf->cmd_idx;

    lnc__MPEG4_prepare_vop_header((IMG_UINT32 *)(cmdbuf->header_mem_p + ctx->pic_header_ofs),
                                  bIsVOPCoded,
                                  pBuffer->vop_time_increment, /* In testbench, this should be FrameNum */
                                  4,/* default value is 4,search range */
                                  pBuffer->picture_type,
                                  ctx->MPEG4_vop_time_increment_resolution/* defaule value */);

    lnc_cmdbuf_insert_command(cmdbuf, MTX_CMDID_DO_HEADER, 2, 1);
    RELOC_CMDBUF(cmdbuf->cmd_idx++, ctx->pic_header_ofs, &cmdbuf->header_mem);

    vaStatus = lnc_RenderPictureParameter(ctx);

    free(pBuffer);
    return vaStatus;
}
Esempio n. 6
0
static VALUE Buffer_skip(VALUE self, VALUE sn)
{
    BUFFER(self, b);

    unsigned long n = FIX2ULONG(sn);

    /* do nothing */
    if(n == 0) {
        return ULONG2NUM(0);
    }

    size_t sz = read_until_eof(b, Qnil, n);
    return ULONG2NUM(sz);
}
Esempio n. 7
0
    /*
    ** replace the characters with spaces...
    */
    for (pwchar = startCharInfo.u.pwc;
	 pwchar < startCharInfo.u.pwc + lengthErase;
	 pwchar++)
    {
	*pwchar = L' ';
    }
}

#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
static void
_termBufferValidateLineWc
(
    const TermBuffer tb,
    const short row
)
{
    wchar_t    *pwc;
    TermLine    line;
    
    line = LINE_OF_TBUF(tb, row);
    for (pwc = (wchar_t *)BUFFER(line);
         pwc < (wchar_t *)BUFFER(line) + LENGTH(line);
         pwc++)
    {
        if (wcwidth(*pwc) == -1)
        {
            fprintf(stderr, "_termBufferValidateLineWc: invalid wide char\n");
	    /* replace the character with a space... */
	    *pwc = L' ';
            break;
        }
    }
}
Esempio n. 8
0
File: cbc.c Progetto: vocho/openqnx
/*
 * This decrypts using the Cipher Block Chaining mode of DES
 *	msgbuf	I/O buffer
 *	fp	input file descriptor
 */
int
cbc_decode(char *msgbuf, FILE *fp)
{
	Desbuf tbuf;	/* temp buffer for initialization vector */
	int n;			/* number of bytes actually read */
	int c;			/* used to test for EOF */
	int inverse = 1;	/* 0 to encrypt, 1 to decrypt */

	if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) {
		/*
		 * do the transformation
		 */
		MEMCPY(BUFFER(tbuf), BUFFER(msgbuf), 8);
		DES_XFORM(UBUFFER(msgbuf));
		for (c = 0; c < 8; c++)
			UCHAR(msgbuf, c) ^= UCHAR(ivec, c);
		MEMCPY(BUFFER(ivec), BUFFER(tbuf), 8);
		/*
		 * if the last one, handle it specially
		 */
		if ((c = fgetc(fp)) == EOF) {
			n = CHAR(msgbuf, 7);
			if (n < 0 || n > 7) {
				des_error("decryption failed (block corrupted)");
				return EOF;
			}
		} else
			(void)ungetc(c, fp);
		return n;
	}
	if (n > 0)
		des_error("decryption failed (incomplete block)");
	else if (n < 0)
		des_error("cannot read file");
	return EOF;
}
Esempio n. 9
0
/**
 * putString
 */
JSValueRef putStringForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    ARGCOUNTMIN(1);
    auto string = HyperloopToString(ctx,arguments[0]);
    if (string!=nullptr)
    {
		std::wstring w_str(string->Begin());
		std::string s_str(w_str.begin(), w_str.end());
        const char *copy = s_str.c_str();
        size_t length = strlen(copy);
        CHECK_SIZE_AND_GROW(length,0);
        memcpy(buffer->buffer,copy,length);
    }
    return JSValueMakeUndefined(ctx);
}
Esempio n. 10
0
/**
 * reset
 */
JSValueRef resetForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    if (buffer->length)
    {
        if (buffer->type == JSBufferTypePointer)
        {
            free(buffer->buffer);
        }
        buffer->length = sizeof(int);
        buffer->buffer = malloc(buffer->length);
        buffer->type = JSBufferTypePointer;
        memset(buffer->buffer,0,buffer->length);
    }
    return object;
}
Esempio n. 11
0
static value_t Buffer_iterator_next( PREFUNC, value_t iterator )
{
	ARGCHECK_1( iterator );
	value_t buf = iterator->slots[0];
	size_t offset = IntFromFixint( iterator->slots[1] );
	offset++;
	if (BUFFER(buf)->size > offset) {
		struct closure *out = ALLOC( Buffer_iterator_function, 2 );
		out->slots[0] = buf;
		out->slots[1] = NumberFromInt( zone, offset );
		return out;
	}
	else {
		return &Buffer_iterator_done;
	}
}
Esempio n. 12
0
/**
 * putChar
 */
JSValueRef putCharForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    ARGCOUNTMIN(1);
    GET_JSARRAY(0, values, values_size);
    if (values != nullptr) {
        GET_NUMBER(1,index);
        CHECK_SIZE_AND_GROW(sizeof(char),(index + values_size - 1));
        SET_JSVALUES_AS_PRIMITIVE(char, index, values, values_size);
    } else {
        GET_CHAR(0,value);
        GET_NUMBER(1,index);
        CHECK_SIZE_AND_GROW(sizeof(char),index);
        PRIMITIVE_SET(char,index);
    }
    return object;
}
Esempio n. 13
0
static VALUE Buffer_read_all(int argc, VALUE* argv, VALUE self)
{
    VALUE out = Qnil;
    unsigned long n = 0;
    bool all = false;

    switch(argc) {
    case 2:
        out = argv[1];
        /* pass through */
    case 1:
        n = FIX2ULONG(argv[0]);
        break;
    case 0:
        all = true;
        break;
    default:
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
    }

    BUFFER(self, b);

    if(out != Qnil) {
        CHECK_STRING_TYPE(out);
    }

    if(all) {
        return read_all(b, out);
    }

    if(n == 0) {
        /* do nothing */
        MAKE_EMPTY_STRING(out);
        return out;
    }

    if(!msgpack_buffer_ensure_readable(b, n)) {
        rb_raise(rb_eEOFError, "end of buffer reached");
    }

    MAKE_EMPTY_STRING(out);
    size_t sz = msgpack_buffer_read_to_string_nonblock(b, out, n);

    return out;
}
Esempio n. 14
0
static VALUE Buffer_skip_all(VALUE self, VALUE sn)
{
    BUFFER(self, b);

    unsigned long n = FIX2ULONG(sn);

    /* do nothing */
    if(n == 0) {
        return self;
    }

    if(!msgpack_buffer_ensure_readable(b, n)) {
        rb_raise(rb_eEOFError, "end of buffer reached");
    }

    msgpack_buffer_skip_nonblock(b, n);

    return self;
}
Esempio n. 15
0
/**
 * slice
 */
JSValueRef sliceForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    MIN_SIZE(2);
    GET_NUMBER(0,index);
    GET_NUMBER(1,length);
    if (length > buffer->length)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("length requested is greater than internal buffer length");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }
    if ((int)index >= buffer->length || (int)index < 0)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("index requested is invalid");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }
    if (buffer->type!=JSBufferTypePointer)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("cannot slice a non-pointer buffer");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

	throw ref new Exception(0, "JSBuffer's sliceForJSBuffer has not been implemented on Windows yet.");
    /*void *memory = malloc(length);
    void *start = &(buffer->buffer[(int)index]);
    memcpy(memory,start,length);
    JSBuffer *newbuffer = (JSBuffer *)malloc(sizeof(JSBuffer));
    newbuffer->buffer = memory;
    newbuffer->length = length;
    newbuffer->type = JSBufferTypePointer;

    return MakeObjectForJSBuffer(ctx,newbuffer);*/
}
Esempio n. 16
0
/**
 * duplicate
 */
JSValueRef duplicateForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    JSBuffer *newbuf = (JSBuffer *)malloc(sizeof(JSBuffer));
    newbuf->length = buffer->length;
    if (buffer->length)
    {
        if (buffer->type == JSBufferTypePointer)
        {
            newbuf->buffer = malloc(newbuf->length);
            memcpy(newbuf->buffer, buffer->buffer, buffer->length);
        }
        else
        {
            // JSValueRef is a copy
            newbuf->buffer = buffer->buffer;
        }
        newbuf->type = buffer->type;
    }
    return MakeObjectForJSBuffer (ctx, newbuf);
}
Esempio n. 17
0
File: cbc.c Progetto: vocho/openqnx
/*
 * get keyword from tty or stdin
 */
int
get_keyword(void)
{
	char *p;			/* used to obtain the key */
	Desbuf msgbuf;			/* I/O buffer */

	/*
	 * get the key
	 */
	if (*(p = getpass("Enter key: "))) {

		/*
		 * copy it, nul-padded, into the key area
		 */
		expand_des_key(BUFFER(msgbuf), p);
		MEMZERO(p, _PASSWORD_LEN);
		set_des_key(msgbuf);
		MEMZERO(msgbuf, sizeof msgbuf);
		return 1;
	}
	return 0;
}
Esempio n. 18
0
static VAStatus
intel_encoder_check_mpeg2_parameter(VADriverContextP ctx,
                                    struct encode_state *encode_state,
                                    struct intel_encoder_context *encoder_context)
{
    struct i965_driver_data *i965 = i965_driver_data(ctx);
    VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer;
    struct object_surface *obj_surface;	
    struct object_buffer *obj_buffer;
    int i = 0;
    
    obj_surface = SURFACE(pic_param->reconstructed_picture);
    assert(obj_surface); /* It is possible the store buffer isn't allocated yet */
    
    if (!obj_surface)
        goto error;
    
    encode_state->reconstructed_object = obj_surface;    
    obj_buffer = BUFFER(pic_param->coded_buf);
    assert(obj_buffer && obj_buffer->buffer_store && obj_buffer->buffer_store->bo);

    if (!obj_buffer || !obj_buffer->buffer_store || !obj_buffer->buffer_store->bo)
        goto error;

    encode_state->coded_buf_object = obj_buffer;

    if (pic_param->picture_type == VAEncPictureTypeIntra) {
    } else if (pic_param->picture_type == VAEncPictureTypePredictive) {
        assert(pic_param->forward_reference_picture != VA_INVALID_SURFACE);
        obj_surface = SURFACE(pic_param->forward_reference_picture);
        assert(obj_surface && obj_surface->bo);

        if (!obj_surface || !obj_surface->bo)
            goto error;

        encode_state->reference_objects[i++] = obj_surface;
    } else if (pic_param->picture_type == VAEncPictureTypeBidirectional) {
        assert(pic_param->forward_reference_picture != VA_INVALID_SURFACE);
        obj_surface = SURFACE(pic_param->forward_reference_picture);
        assert(obj_surface && obj_surface->bo);

        if (!obj_surface || !obj_surface->bo)
            goto error;

        encode_state->reference_objects[i++] = obj_surface;

        assert(pic_param->backward_reference_picture != VA_INVALID_SURFACE);
        obj_surface = SURFACE(pic_param->backward_reference_picture);
        assert(obj_surface && obj_surface->bo);

        if (!obj_surface || !obj_surface->bo)
            goto error;

        encode_state->reference_objects[i++] = obj_surface;
    } else 
        goto error;

    for ( ; i < 16; i++)
        encode_state->reference_objects[i] = NULL;

    return VA_STATUS_SUCCESS;

error:
    return VA_STATUS_ERROR_INVALID_PARAMETER;
}
Esempio n. 19
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)

{

	static DWORD          dwCharSet = DEFAULT_CHARSET ;

	static int            cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,

		xCaret, yCaret ;

	static TCHAR *pBuffer = NULL ;

	HDC                           hdc ;

	int                           x, y, i ;

	PAINTSTRUCT           ps ;

	TEXTMETRIC            tm ;



	switch (message)

	{

	case   WM_INPUTLANGCHANGE:

		dwCharSet = wParam ;

		// fall through

	case   WM_CREATE:

		hdc = GetDC (hwnd) ;

		SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,

			dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;



		GetTextMetrics (hdc, &tm) ;

		cxChar = tm.tmAveCharWidth ;

		cyChar = tm.tmHeight ;



		DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;

		ReleaseDC (hwnd, hdc) ;

		// fall through              

	case   WM_SIZE:

		// obtain window size in pixels


		if (message == WM_SIZE)

		{

			cxClient = LOWORD (lParam) ;

			cyClient = HIWORD (lParam) ;

		}

		// calculate window size in characters



		cxBuffer = max (1, cxClient / cxChar) ;

		cyBuffer = max (1, cyClient / cyChar) ;



		// allocate memory for buffer and clear it



		if (pBuffer != NULL)

			free (pBuffer) ;


		pBuffer = (TCHAR *) malloc (cxBuffer * cyBuffer * sizeof (TCHAR)) ;



		for (y = 0 ; y < cyBuffer ; y++)

			for (x = 0 ; x < cxBuffer ; x++)

				BUFFER(x,y) = ' ' ;


		// set caret to upper left corner


		xCaret = 0 ;

		yCaret = 0 ;



		if (hwnd == GetFocus ())

			SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;


		InvalidateRect (hwnd, NULL, TRUE) ;

		return 0 ;



	case   WM_SETFOCUS:

		// create and show the caret

		CreateCaret (hwnd, NULL, cxChar, cyChar) ;

		SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;

		ShowCaret (hwnd) ;

		return 0 ;



	case WM_KILLFOCUS:

		// hide and destroy the caret

		HideCaret (hwnd) ;

		DestroyCaret () ;

		return 0 ;



	case   WM_KEYDOWN:

		switch (wParam)

		{

		case VK_HOME:

			xCaret = 0 ;

			break ;



		case   VK_END:

			xCaret = cxBuffer - 1 ;

			break ;



		case   VK_PRIOR:

			yCaret = 0 ;

			break ;



		case   VK_NEXT:

			yCaret = cyBuffer - 1 ;

			break ;



		case   VK_LEFT:

			xCaret = max (xCaret - 1, 0) ;

			break ;



		case   VK_RIGHT:

			xCaret = min (xCaret + 1, cxBuffer - 1) ;

			break ;



		case   VK_UP:

			yCaret = max (yCaret - 1, 0) ;

			break ;



		case   VK_DOWN:

			yCaret = min (yCaret + 1, cyBuffer - 1) ;

			break ;



		case   VK_DELETE:

			for (x = xCaret ; x < cxBuffer - 1 ; x++)

				BUFFER (x, yCaret) = BUFFER (x + 1, yCaret) ;



			BUFFER (cxBuffer - 1, yCaret) = ' ' ;



			HideCaret (hwnd) ;

			hdc = GetDC (hwnd) ;



			SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,

				dwCharSet, 0, 0, 0,FIXED_PITCH, NULL)) ;

			TextOut (hdc, xCaret * cxChar, yCaret * cyChar,

				& BUFFER (xCaret, yCaret),

				cxBuffer - xCaret) ;


			DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;

			ReleaseDC (hwnd, hdc) ;

			ShowCaret (hwnd) ;

			break ;

		}

		SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;

		return 0 ;



	case   WM_CHAR:

		for (i = 0 ; i < (int) LOWORD (lParam) ; i++)

		{

			switch (wParam)

			{

			case '\b':                                           // backspace

				if (xCaret > 0)

				{

					xCaret-- ;

					SendMessage (hwnd, WM_KEYDOWN, VK_DELETE, 1) ;

				}

				break ;



			case '\t':                                                  // tab

				do

				{

					SendMessage (hwnd, WM_CHAR, ' ', 1) ;

				}

				while (xCaret % 8 != 0) ;

				break ;

			case '\n':                                                  // line feed

				if (++yCaret == cyBuffer)

					yCaret = 0 ;

				break ;



			case '\r':                                                  // carriage return

				xCaret = 0 ;



				if (++yCaret == cyBuffer)

					yCaret = 0 ;

				break ;



			case '\x1B':                                       // escape

				for (y = 0 ; y < cyBuffer ; y++)

					for (x = 0 ; x < cxBuffer ; x++)

						BUFFER (x, y) = ' ' ;



				xCaret = 0 ;

				yCaret = 0 ;



				InvalidateRect (hwnd, NULL, FALSE) ;

				break ;



			default:                                                    // character codes

				BUFFER (xCaret, yCaret) = (TCHAR) wParam ;



				HideCaret (hwnd) ;

				hdc = GetDC (hwnd) ;



				SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,

					dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

				TextOut (hdc, xCaret * cxChar, yCaret * cyChar,

					& BUFFER (xCaret, yCaret), 1) ;

				DeleteObject (

					SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;

				ReleaseDC (hwnd, hdc) ;

				ShowCaret (hwnd) ;


				if (++xCaret == cxBuffer)

				{

					xCaret = 0 ;

					if (++yCaret == cyBuffer)

						yCaret = 0 ;

				}

				break ;

			}

		}



		SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;

		return 0 ;



	case   WM_PAINT:

		hdc = BeginPaint (hwnd, &ps) ;



		SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,

			dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

		for (y = 0 ; y < cyBuffer ; y++)

			TextOut (hdc, 0, y * cyChar, & BUFFER(0,y), cxBuffer) ;

		DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;

		EndPaint (hwnd, &ps) ;

		return 0 ;



	case   WM_DESTROY:

		PostQuitMessage (0) ;

		return 0 ;

	}

	return DefWindowProc (hwnd, message, wParam, lParam) ;

}
Esempio n. 20
0
int do_apriori (int argc, char *argv[])
{                               /* --- main function */
  int    i, k = 0, n;           /* loop variables, counters */
  char   *s;                    /* to traverse the options */
  char   **optarg = NULL;       /* option argument */
  char   *fn_in   = NULL;       /* name of input  file */
  char   *fn_out  = NULL;       /* name of output file */
  char   *fn_app  = NULL;       /* name of item appearances file */
  char   *blanks  = NULL;       /* blanks */
  char   *fldseps = NULL;       /* field  separators */
  char   *recseps = NULL;       /* record separators */
  char   *comment = NULL;       /* comment indicators */
  char   *used    = NULL;       /* item usage vector */
  double supp     = 0.1;        /* minimal support    (in percent) */
  double smax     = 1.0;        /* maximal support    (in percent) */
  double conf     = 0.8;        /* minimal confidence (in percent) */
  int    mode     = IST_BODY;   /* search mode (rule support def.) */
  int    target   = 'r';        /* target type (sets/rules/h.edges) */
  int    arem     = 0;          /* additional rule evaluation measure */
  int    lift     = 0;          /* flag for printing the lift */
  double minval   = 0.1;        /* minimal evaluation measure value */
  double lftval   = 0;          /* lift value (confidence/prior) */
  int    minlen   = 1;          /* minimal rule length */
  int    maxlen   = INT_MAX;    /* maximal rule length */
  int    load     = 1;          /* flag for loading transactions */
  int    sort     = 2;          /* flag for item sorting and recoding */
  double filter   = 0.1;        /* item usage filtering parameter */
  int    tree     = 1;          /* flag for transaction tree */
  int    heap     = 1;          /* flag for heap sort vs. quick sort */
  int    c2scf    = 0;          /* flag for conv. to scanable form */
  char   *sep     = " ";        /* item separator for output */
  char   *fmt     = "%.1f";     /* output format for support/conf. */
  int    sout     = 1;          /* flag for abs./rel. support output */
  int    ext      = 0;          /* flag for extended support output */
  int    aval     = 0;          /* flag for add. eval. measure value */
  int    maxcnt   = 0;          /* maximal number of items per set */
  int    tacnt;                 /* number of transactions */
  int    frq;                   /* frequency of an item set */
  int    *map, *set;            /* identifier map, item set */
  int    verbose  = 0;          /* flag for verboseness */
  const  char *name;            /* buffer for item names */
  static char buf[4*TS_SIZE+4]; /* buffer for formatting */
  clock_t     t, tt, tc, x;     /* timer for measurements */

  #ifndef QUIET                 /* if not quiet version */
  prgname = argv[0];            /* get program name for error msgs. */

  /* --- print usage message --- */
  if (argc > 1) {               /* if arguments are given */
    fprintf(stderr, "%s - %s\n", argv[0], DESCRIPTION);
    fprintf(stderr, VERSION); } /* print a startup message */
  else {                        /* if no arguments given */
    printf("usage: %s [options] infile outfile [appfile]\n", argv[0]);
    printf("%s\n", DESCRIPTION);
    printf("%s\n", VERSION);
    printf("-t#      target type (default: association rules)\n"
           "         (s: item sets, c: closed item sets,"
                    " m: maximal item sets,\n"
           "          r: association rules,"
                    " h: association hyperedges)\n");
    printf("-m#      minimal number of items per set/rule/hyperedge "
                    "(default: %d)\n", minlen);
    printf("-n#      maximal number of items per set/rule/hyperedge "
                    "(default: no limit)\n");
    printf("-s#      minimal support    of a     set/rule/hyperedge "
                    "(default: %g%%)\n", supp *100);
    printf("-S#      maximal support    of a     set/rule/hyperedge "
                    "(default: %g%%)\n", smax *100);
    printf("-c#      minimal confidence of a         rule/hyperedge "
                    "(default: %g%%)\n", conf *100);
    printf("-o       use original definition of the support of a rule "
                    "(body & head)\n");
    printf("-k#      item separator for output "
                    "(default: \"%s\")\n", sep);
    printf("-p#      output format for support/confidence "
                    "(default: \"%s\")\n", fmt);
    printf("-x       extended support output "
                    "(print both rule support types)\n");
    printf("-a       print absolute support "
                    "(number of transactions)\n");
    printf("-y       print lift value (confidence divided by prior)\n");
    printf("-e#      additional evaluation measure (default: none)\n");
    printf("-!       print a list of additional evaluation measures\n");
    printf("-d#      minimal value of additional evaluation measure "
                    "(default: %g%%)\n", minval *100);
    printf("-v       print value of additional "
                    "rule evaluation measure\n");
    printf("-g       write output in scanable form "
                    "(quote certain characters)\n");
    printf("-l       do not load transactions into memory "
                    "(work on input file)\n");
    printf("-q#      sort items w.r.t. their frequency (default: %d)\n"
           "         (1: ascending, -1: descending, 0: do not sort,\n"
           "          2: ascending, -2: descending w.r.t. "
                    "transaction size sum)\n", sort);
    printf("-u#      filter unused items from transactions "
                    "(default: %g)\n", filter);
    printf("         (0: do not filter items w.r.t. usage in sets,\n"
           "         <0: fraction of removed items for filtering,\n"
           "         >0: take execution times ratio into account)\n");
    printf("-h       do not organize transactions as a prefix tree\n");
    printf("-j       use quicksort to sort the transactions "
                    "(default: heapsort)\n");
    printf("-z       minimize memory usage "
                    "(default: maximize speed)\n");
    printf("-b/f/r#  blank characters, field and record separators\n"
           "         (default: \" \\t\\r\", \" \\t\", \"\\n\")\n");
    printf("-C#      comment characters (default: \"#\")\n");
    printf("-V       verbose\n");

    printf("infile   file to read transactions from\n");
    printf("outfile  file to write item sets/association rules"
                    "/hyperedges to\n");
    printf("appfile  file stating item appearances (optional)\n");
    return 0;                   /* print a usage message */
  }                             /* and abort the program */
  #endif  /* #ifndef QUIET */

  /* --- evaluate arguments --- */
  for (i = 1; i < argc; i++) {  /* traverse arguments */
    s = argv[i];                /* get option argument */
    if (optarg) { *optarg = s; optarg = NULL; continue; }
    if ((*s == '-') && *++s) {  /* -- if argument is an option */
      while (*s) {              /* traverse options */
        switch (*s++) {         /* evaluate switches */
          case '!': help();                         break;
          case 't': target = (*s) ? *s++ : 'r';     break;
          case 'm': minlen = (int)strtol(s, &s, 0); break;
          case 'n': maxlen = (int)strtol(s, &s, 0); break;
          case 's': supp   = 0.01*strtod(s, &s);    break;
          case 'S': smax   = 0.01*strtod(s, &s);    break;
          case 'c': conf   = 0.01*strtod(s, &s);    break;
          case 'o': mode  |= IST_BOTH;              break;
          case 'k': optarg = &sep;                  break;
          case 'p': optarg = &fmt;                  break;
          case 'x': ext    = 1;                     break;
          case 'a': sout  |= 2;                     break;
          case 'y': lift   = 1;                     break;
          case 'e': arem   = (*s) ? *s++ : 0;       break;
          case 'd': minval = 0.01*strtod(s, &s);    break;
          case 'v': aval   = 1;                     break;
          case 'g': c2scf  = 1;                     break;
          case 'l': load   = 0;                     break;
          case 'q': sort   = (int)strtol(s, &s, 0); break;
          case 'u': filter =      strtod(s, &s);    break;
          case 'h': tree   = 0;                     break;
          case 'j': heap   = 0;                     break;
          case 'z': mode  |= IST_MEMOPT;            break;
          case 'b': optarg = &blanks;               break;
          case 'f': optarg = &fldseps;              break;
          case 'r': optarg = &recseps;              break;
          case 'C': optarg = &comment;              break;
          case 'V': verbose = 1;                    break;
          default : error(E_OPTION, *--s);          break;
        }                       /* set option variables */
        if (optarg && *s) { *optarg = s; optarg = NULL; break; }
      } }                       /* get option argument */
    else {                      /* -- if argument is no option */
      switch (k++) {            /* evaluate non-options */
        case  0: fn_in  = s;      break;
        case  1: fn_out = s;      break;
        case  2: fn_app = s;      break;
        default: error(E_ARGCNT); break;
      }                         /* note filenames */
    }
  }
  if (optarg) error(E_OPTARG);  /* check option argument */
  if ((k < 2) || (k > 3))       /* and the number of arguments */
    error(E_ARGCNT);            /* (either in/out or in/out/app) */
  if ((!fn_in || !*fn_in) && (fn_app && !*fn_app))
    error(E_STDIN);             /* stdin must not be used twice */
  switch (target) {             /* check and translate target type */
    case 's': target = TT_SET;               break;
    case 'c': target = TT_CLSET;             break;
    case 'm': target = TT_MFSET;             break;
    case 'r': target = TT_RULE;              break;
    case 'h': target = TT_HEDGE;             break;
    case 'g': target = TT_GROUP;             break;
    default : error(E_TARGET, (char)target); break;
  }
  if (supp > 1)                 /* check the minimal support */
    error(E_SUPP, supp);        /* (< 0: absolute number) */
  if ((conf  <  0) || (conf > 1))
    error(E_CONF, conf);        /* check the minimal confidence */
  if (minlen <= 0) error(E_RULELEN, minlen);  /* check the limits */
  if (maxlen <= 0) error(E_RULELEN, maxlen);  /* for the rule length */
  switch (arem) {               /* check and translate measure */
    case  0 : case '0': arem = EM_NONE;     break;
    case 'd': case '1': arem = EM_DIFF;     break;
    case 'q': case '2': arem = EM_QUOT;     break;
    case 'a': case '3': arem = EM_AIMP;     break;
    case 'i': case '4': arem = EM_INFO;     break;
    case 'c': case '5': arem = EM_CHI2;     break;
    case 'p': case '6': arem = EM_PVAL;     break;
    default : error(E_MEASURE, (char)arem); break;
  }
  if (target <= TT_MFSET) {     /* in item set mode neutralize */
    mode |= IST_BOTH; conf = 1;}/* rule specific settings */
  if (arem == EM_NONE)          /* if no add. rule eval. measure, */
    aval = 0;                   /* clear the corresp. output flag */
  if ((filter <= -1) || (filter >= 1)) filter = 0;

  /* --- create item set and transaction set --- */
  itemset = is_create(-1);      /* create an item set and */
  if (!itemset) error(E_NOMEM); /* set the special characters */
  is_chars(itemset, blanks, fldseps, recseps, comment);
  if (load) {                   /* if to load the transactions */
    taset = tas_create(itemset);
    if (!taset) error(E_NOMEM); /* create a transaction set */
  }                             /* to store the transactions */
  MSG(fprintf(stderr, "\n"));   /* terminate the startup message */

  /* --- read item appearances --- */
  if (fn_app) {                 /* if item appearances are given */
    t = clock();                /* start the timer */
    if (*fn_app)                /* if an app. file name is given, */
      in = fopen(fn_app, "r");  /* open the item appearances file */
    else {                      /* if no app. file name is given, */
      in = stdin; fn_app = "<stdin>"; }   /* read from std. input */
    MSG(fprintf(stderr, "reading %s ... ", fn_app));
    if (!in) error(E_FOPEN, fn_app);
    k = is_readapp(itemset,in); /* read the item appearances */
    if (k  != 0) error(k, fn_app, RECCNT(itemset), BUFFER(itemset));
    if (in != stdin)            /* if not read from standard input, */
      fclose(in);               /* close the input file */
    MSG(fprintf(stderr, "[%d item(s)]", is_cnt(itemset)));
    MSG(fprintf(stderr, " done [%.2fs].\n", SEC_SINCE(t)));
  }                             /* print a log message */

  /* --- read transactions --- */
  t = clock();                  /* start the timer */
  if (fn_in && *fn_in)          /* if an input file name is given, */
    in = fopen(fn_in, "r");     /* open input file for reading */
  else {                        /* if no input file name is given, */
    in = stdin; fn_in = "<stdin>"; }   /* read from standard input */
  MSG(fprintf(stderr, "reading %s ... \n", fn_in));
  if (!in) error(E_FOPEN, fn_in);
  while (1) {                   /* transaction read loop */
    k = is_read(itemset, in);   /* read the next transaction */
    if (k < 0) error(k, fn_in, RECCNT(itemset), BUFFER(itemset));
    if (k > 0) break;           /* check for error and end of file */
    k = is_tsize(itemset);      /* update the maximal */
    if (k > maxcnt) maxcnt = k; /* transaction size */
    if (taset && (tas_add(taset, NULL, 0) != 0))
      error(E_NOMEM);           /* add the loaded transaction */
  }                             /* to the transaction set */
  if (taset) {                  /* if transactions have been loaded */
    if (in != stdin) fclose(in);/* if not read from standard input, */
    in = NULL;                  /* close the input file */
  }                             /* clear the file variable */
  n     = is_cnt(itemset);      /* get the number of items */
  tacnt = is_gettac(itemset);   /* and the number of transactions */
  MSG(fprintf(stderr, "[%d item(s), %d transaction(s)]", n, tacnt));
  MSG(fprintf(stderr, " done [%.2fs].", SEC_SINCE(t)));
  if ((n <= 0) || (tacnt <= 0)) error(E_NOTAS);
  MSG(fprintf(stderr, "\n"));   /* check for at least one transaction */
  if (supp >= 0)                /* if relative support is given */
    supp = ceil(tacnt *supp);   /* compute absolute support */
  else {                        /* if absolute support is given, */
    supp = ceil(-100  *supp);   /* make the support value positive */
    if (!(sout & 2)) sout = 2;  /* switch to absolute support output */
  }                             /* do the same with the max. support */
  smax = floor(((smax >= 0) ? tacnt : -100) *smax);

  /* --- sort and recode items --- */
  MSG(fprintf(stderr, "filtering, sorting and recoding items ... "));
  t   = clock();                /* start the timer */
  map = (int*)malloc(is_cnt(itemset) *sizeof(int));
  if (!map) error(E_NOMEM);     /* create an item identifier map */
  k = (int)((mode & IST_HEAD) ? supp : ceil(supp *conf));
  n = is_recode(itemset, k, sort, map);
  if (taset) {                  /* sort and recode the items and */
    tas_recode(taset, map,n);   /* recode the loaded transactions */
    maxcnt = tas_max(taset);    /* get the new maximal t.a. size */
  }                             /* (may be smaller than before) */
  free(map);                    /* delete the item identifier map */
  MSG(fprintf(stderr, "[%d item(s)] ", n));
  MSG(fprintf(stderr, "done [%.2fs].", SEC_SINCE(t)));
  if (n <= 0) error(E_NOFREQ);  /* print a log message and */
  MSG(fprintf(stderr, "\n"));   /* check the number of items */
  if (maxlen > maxcnt)          /* clamp the set/rule length */
    maxlen = maxcnt;            /* to the maximum set size */

  /* --- create a transaction tree --- */
  tt = 0;                       /* init. the tree construction time */
  if (tree && taset) {          /* if transactions were loaded */
    MSG(fprintf(stderr, "creating transaction tree ... "));
    t = clock();                /* start the timer */
    tatree = tat_create(taset, heap); 
    if (!tatree) error(E_NOMEM);/* create a transaction tree */
    if (filter == 0) {          /* if a tree rebuild is not needed, */
      tas_delete(taset, 0); taset = NULL; }  /* delete transactions */
    tt = clock() -t;            /* note the time for the construction */
    MSG(fprintf(stderr, "done [%.2fs].\n", SEC_SINCE(t)));
  }                             /* print a log message */

  /* --- create an item set tree --- */
  t = clock(); tc = 0;          /* start the timer */
  istree = ist_create(itemset, mode, (int)supp, conf);
  if (!istree) error(E_NOMEM);  /* create an item set tree */

  /* --- check item subsets --- */
  if (filter) {                 /* if to filter unused items */
    used = (char*)malloc(is_cnt(itemset) *sizeof(char));
    if (!used) error(E_NOMEM);  /* create a flag vector */
  }                             /* for the items */
  MSG(fprintf(stderr, "checking subsets of size 1"));
  while (ist_height(istree) < maxlen) {
    if (filter != 0) {          /* if to filter w.r.t. item usage, */
      i = ist_check(istree, used);     /* check current item usage */
      if (i < maxlen) maxlen = i;      /* update the maximum size */
      if (ist_height(istree) >= i) break;
    }                           /* check the tree height */
    k = ist_addlvl(istree);     /* while max. height is not reached, */
    if (k <  0) error(E_NOMEM); /* add a level to the item set tree */
    if (k != 0) break;          /* if no level was added, abort */
    MSG(fprintf(stderr, " %d", ist_height(istree)));
    if (tatree) {               /* if a transaction tree was created */
      if (((filter < 0)         /* if to filter w.r.t. item usage */
      &&   (i < -filter *n))    /* and enough items were removed */
      ||  ((filter > 0)         /* or counting time is long enough */
      &&   (i < n) && (i *(double)tt < filter *n *tc))) {
        n = i; x = clock();     /* note the new number of items */
        tas_filter(taset, used);/* and remove unnecessary items */
        tat_delete(tatree);     /* delete the transaction tree */
        tatree = tat_create(taset, heap);
        if (!tatree) error(E_NOMEM);
        tt = clock() -x;        /* rebuild the transaction tree and */
      }                         /* note the new construction time */
      x  = clock();             /* count the transaction tree */
      ist_countx(istree, tatree);
      tc = clock() -x; }        /* note the new count time */
    else if (taset) {           /* if transactions were loaded */
      if (((filter < 0)         /* if to filter w.r.t. item usage */
      &&   (i <= -filter *n))   /* and enough items were removed */
      ||  ((filter > 0)         /* or counting time is long enough */
      &&   (i *(double)tt <= filter *n *tc))) {
        n = i; x = clock();     /* note the new number of items */
        tas_filter(taset, used);/* and remove unnecessary items */
        tt = clock() -t;        /* from the transactions */
      }                         /* note the filtering time */
      for (i = tacnt; --i >= 0;)/* traverse and count transactions */
        ist_count(istree, tas_tract(taset, i), tas_tsize(taset, i));
      tc = clock() -t; }        /* note the new count time */
    else {                      /* if to work on the input file, */
      rewind(in);               /* reset the file position */
      for (maxcnt = 0; (i = is_read(itemset, in)) == 0; ) {
        if (filter != 0)        /* (re)read the transactions and */
          is_filter(itemset, used);  /* remove unnecessary items */
        k = is_tsize(itemset);  /* update the maximum size */
        if (k > maxcnt) maxcnt = k;  /* of a transaction */
        ist_count(istree, is_tract(itemset), k);
      }                         /* count the transaction in the tree */
      if (i < 0) error(i, fn_in, RECCNT(itemset), BUFFER(itemset));
      if (maxcnt < maxlen)      /* update the maximal rule length */
        maxlen = maxcnt;        /* according to the max. t.a. size */
    }                           /* (may be smaller than before) */
  }
  if (!taset && !tatree) {      /* if transactions were not loaded */
    if (in != stdin) fclose(in);/* if not read from standard input, */
    in = NULL;                  /* close the input file */
  }                             /* clear the file variable */
  MSG(fprintf(stderr, " done [%.2fs].\n", SEC_SINCE(t)));

  /* --- filter found item sets --- */
  if ((target == TT_CLSET) || (target == TT_MFSET)) {
    MSG(fprintf(stderr, "filtering %s item sets ... ",
        (target == TT_MFSET) ? "maximal" : "closed"));
    t = clock();                /* filter the item sets */
    ist_filter(istree, (target == TT_MFSET) ? IST_MAXFRQ : IST_CLOSED);
    MSG(fprintf(stderr, "done [%.2fs].\n", SEC_SINCE(t)));
  }                             /* (filter takes longer than print) */

  /* --- sort transactions --- */
  if (target <= TT_MFSET) {     /* if to find frequent item sets */
    if (!taset)                 /* transactions must be loaded */
      ext = 0;                  /* for extended support output */
    else if (ext) {             /* if extended output is requested */
      MSG(fprintf(stderr, "sorting transactions ... "));
      t = clock();              /* start the timer */
      tas_sort(taset, heap);    /* sort the transactions */
      MSG(fprintf(stderr, "done [%.2fs].\n", SEC_SINCE(t)));
    }                           /* (sorting is necessary to find the */
  }                             /* number of identical transactions) */

  /* --- print item sets/rules/hyperedges --- */
  t = clock();                  /* start the timer */
  if (fn_out && *fn_out)        /* if an output file name is given, */
    out = fopen(fn_out, "w");   /* open the output file */
  else {                        /* if no output file name is given, */
    out = stdout; fn_out = "<stdout>"; }    /* write to std. output */
  MSG(fprintf(stderr, "writing %s ... ", fn_out));
  if (!out) error(E_FOPEN, fn_out);
  ist_init(istree, minlen, arem, minval);
  set = is_tract(itemset);      /* get the transaction buffer */
  if (target <= TT_MFSET) {     /* if to find frequent item sets */
    for (n = 0; 1; ) {          /* extract item sets from the tree */
      k = ist_set(istree, set, &frq, &conf);
      if (k <= 0) break;        /* get the next frequent item set */
      if (frq > smax) continue; /* check against maximal support */
      for (i = 0; i < k; i++) { /* traverse the set's items */
        name = is_name(itemset, set[i]);
        if (c2scf) { sc_format(buf, name, 0); name = buf; }
        fputs(name, out);       /* print the name of the next item */
        fputs((i < k-1) ? sep : " ", out);
      }                         /* print a separator */
      fputs(" (", out);         /* print the item set's support */
      if (sout & 1) { fprintf(out, fmt, (frq/(double)tacnt) *100);
                      if (sout & 2) fputc('/', out); }
      if (sout & 2) { fprintf(out, "%d", frq); }
      if (ext) {                /* if to print the extended support */
        frq = tas_occur(taset, set, k);
        fputs(", ", out);       /* get the number of occurrences */
        fprintf(out, fmt, (frq/(double)tacnt) *100);
        if (sout & 2) fprintf(out, "/%d", frq);
      }                         /* print the extended support data */
      if (aval) { fputs(", ", out); fprintf(out, fmt, conf *100); }
      fputs(")\n", out);        /* print the add. eval. measure, */
      n++;                      /* terminate the support output, */
    } }                         /* and count the item set */
  else if (target == TT_RULE) { /* if to find association rules, */
    for (n = 0; 1; ) {          /* extract rules from tree */
      k = ist_rule(istree, set, &frq, &conf, &lftval, &minval);
      if (k <= 0) break;        /* get the next association rule */
      if (frq > smax) continue; /* check against maximal support */
      for (i = 0; i < k; i++) { /* traverse the rule's items */
        name = is_name(itemset, set[i]);
        if (c2scf) { sc_format(buf, name, 0); name = buf; }
        fputs(name, out);       /* print the next item */
        fputs((i <= 0) ? " <- " : ((i < k-1) ? sep : " "), out);
      }                         /* print a separator */
      fputs(" (", out);         /* print the rule evaluation */
      if (sout & 1) supp = frq/(double)tacnt;
      if (ext && !(mode & IST_HEAD)) {
        if (sout & 1) { fprintf(out, fmt, supp *conf *100);
                        if (sout & 2) fputc('/', out); }
        if (sout & 2) { fprintf(out, "%d", (int)(frq *conf +0.5));}
        fputs(", ", out);       /* print the support of the rule */
      }                         /* from  the support of the body */
      if (sout & 1) { fprintf(out, fmt, supp *100);
                      if (sout & 2) fputc('/', out); }
      if (sout & 2) { fprintf(out, "%d", frq); }
      fputs(", ", out);         /* print the rule support */
      if (ext && (mode & IST_HEAD)) {
        if (sout & 1) { fprintf(out, fmt, (supp/conf) *100);
                        if (sout & 2) fputc('/', out); }
        if (sout & 2) { fprintf(out, "%d", (int)(frq /conf +0.5));}
        fputs(", ", out);       /* print the support of the body */
      }                         /* from  the support of the rule */
      fprintf(out, fmt, conf *100); /* print the rule confidence */
      if (lift) { fputs(", ", out); fprintf(out, fmt, lftval *100); }
      if (aval) { fputs(", ", out); fprintf(out, fmt, minval *100); }
      fputs(")\n", out);        /* print the value of the additional */
      n++;                      /* rule evaluation measure and */
    } }                         /* count the association rule */
  else if (target == TT_HEDGE){ /* if to find association hyperedges */
    for (n = 0; 1; ) {          /* extract hyperedges from tree */
      k = ist_hedge(istree, set, &frq, &conf, &minval);
      if (k <= 0) break;        /* get the next hyperedge */
      if (frq > smax) continue; /* check against maximal support */
      for (i = 0; i < k; i++) { /* traverse the edge's items */
        name = is_name(itemset, set[i]);
        if (c2scf) { sc_format(buf, name, 0); name = buf; }
        fputs(name, out);       /* print the name of the next item */
        fputs((i < k-1) ? sep : " ", out);
      }                         /* print a separator */
      fputs(" (", out);         /* print the hyperedge evaluation */
      if (sout & 1) { fprintf(out, fmt, (frq/(double)tacnt) *100);
                      if (sout & 2) fputc('/', out); }
      if (sout & 2) { fprintf(out, "%d", frq); }
      fputs(", ", out); fprintf(out, fmt, conf *100);
      if (aval) { fputs(", ", out); fprintf(out, fmt, minval *100); }
      fputs(")\n", out);        /* print support and confidence */
      n++;                      /* of the hyperedge and */
    } }                         /* count the hyperedge */
  else {                        /* if to find association groups */
    for (n = 0; 1; ) {          /* extract groups from tree */
      k = ist_group(istree, set, &frq, &minval);
      if (k <= 0) break;        /* get the next group */
      if (frq > smax) continue; /* check against maximal support */
      for (i = 0; i < k; i++) { /* traverse the group's items */
        name = is_name(itemset, set[i]);
        if (c2scf) { sc_format(buf, name, 0); name = buf; }
        fputs(name, out);       /* print the name of the next item */
        fputs((i < k-1) ? sep : " ", out);
      }                         /* print a separator */
      fputs(" (", out);         /* print the group evaluation */
      if (sout & 1) { fprintf(out, fmt, (frq/(double)tacnt) *100);
                      if (sout & 2) fputc('/', out); }
      if (sout & 2) { fprintf(out, "%d", frq); }
      if (aval) { fputs(", ", out); fprintf(out, fmt, minval *100); }
      fputs(")\n", out);        /* print support and add. measure */
      n++;                      /* and count the group */
    }
  }  /* if (target <= TT_MFSET) .. else .. */
  if (fflush(out) != 0) error(E_FWRITE, fn_out);
  if (out != stdout) fclose(out);
  out = NULL;                   /* close the output file */
  MSG(fprintf(stderr, "[%d %s(s)] done ", n, ttypes[target]));
  MSG(fprintf(stderr, "[%.2fs].\n", SEC_SINCE(t)));
  #ifdef BENCH
  printf("number of support counters: %d\n", istree->sccnt);
  printf("necessary support counters: %d\n", istree->scnec);
  printf("number of child pointers  : %d\n", istree->cpcnt);
  printf("necessary child pointers  : %d\n", istree->cpnec);
  printf("allocated memory (bytes)  : %d\n", istree->bytes);
  #endif

  /* --- clean up --- */
  #ifndef NDEBUG                /* if this is a debug version */
  free(used);                   /* delete the item app. vector */
  ist_delete(istree);           /* delete the item set tree, */
  if (tatree) tat_delete(tatree);     /* the transaction tree, */
  if (taset)  tas_delete(taset, 0);   /* the transaction set, */
  is_delete(itemset);                 /* and the item set */
  #endif
  #ifdef STORAGE                /* if storage debugging */
  showmem("at end of program"); /* check memory usage */
  #endif
  return 0;                     /* return 'ok' */
}  /* main() */
Esempio n. 21
0
static VAStatus vsp_vp8_process_picture_param(
    psb_driver_data_p driver_data,
    context_VPP_p ctx,
    object_buffer_p obj_buffer,
    VASurfaceID surface_id)

{
    VAStatus vaStatus = VA_STATUS_SUCCESS;
    vsp_cmdbuf_p cmdbuf = ctx->obj_context->vsp_cmdbuf;

    VAEncPictureParameterBufferVP8 *va_pic =
        (VAEncPictureParameterBufferVP8 *) obj_buffer->buffer_data;
    struct VssVp8encPictureParameterBuffer *pic =
        (struct VssVp8encPictureParameterBuffer *)cmdbuf->pic_param_p;
    struct VssVp8encSequenceParameterBuffer *seq =
        (struct VssVp8encSequenceParameterBuffer *)cmdbuf->seq_param_p;
    int ref_frame_width, ref_frame_height;
    vp8_fw_pic_flags flags;

    ref_frame_width = (ctx->vp8_seq_param.frame_width + 2 * 32 + 63) & (~63);
    ref_frame_height = (ctx->vp8_seq_param.frame_height + 2 * 32 + 63) & (~63);

    //map parameters
    object_buffer_p pObj = BUFFER(va_pic->coded_buf); //tobe modified
    if (!pObj)
        return VA_STATUS_ERROR_UNKNOWN;

    object_surface_p src_surface = SURFACE(surface_id);

    pic->input_frame.surface_id = surface_id;
    pic->input_frame.irq        = 1;
    pic->input_frame.height     = ctx->vp8_seq_param.frame_height;
    pic->input_frame.width      = ctx->vp8_seq_param.frame_width;
    /* NOTE: In VIED API doc, stride must be the nearest integer multiple of 32 */
    /* use vaCreateSurfaceWithAttribute with VAExternalMemoryNULL to create surface*/
    //pic->input_frame.stride     = (ctx->frame_width + 31) & (~31);
    pic->input_frame.stride     = ctx->obj_context->current_render_target->psb_surface->stride;
    pic->input_frame.format     = 0; /* TODO: Specify NV12 = 0 */

    pic->recon_frame.irq = 0;
    pic->recon_frame.width = ref_frame_width;
    pic->recon_frame.height = ref_frame_height;

    pic->version = 0;

    flags.value = 0;
    flags.bits.force_kf = va_pic->ref_flags.bits.force_kf;
    flags.bits.no_ref_last = va_pic->ref_flags.bits.no_ref_last;
    flags.bits.no_ref_gf = va_pic->ref_flags.bits.no_ref_gf;
    flags.bits.no_ref_arf = va_pic->ref_flags.bits.no_ref_arf;
    flags.bits.upd_last  = va_pic->pic_flags.bits.refresh_last;
    flags.bits.upd_gf  = va_pic->pic_flags.bits.copy_buffer_to_golden;
    flags.bits.upd_arf  = va_pic->pic_flags.bits.copy_buffer_to_alternate;
    flags.bits.no_upd_last  = !va_pic->pic_flags.bits.refresh_last;
    flags.bits.no_upd_gf  = !va_pic->pic_flags.bits.refresh_golden_frame;
    flags.bits.no_upd_arf  = !va_pic->pic_flags.bits.refresh_alternate_frame;
    flags.bits.upd_entropy  = va_pic->pic_flags.bits.refresh_entropy_probs;
    if (ctx->temporal_layer_number > 1)
        flags.bits.upd_entropy = 0;
    pic->pic_flags = flags.value;

    pic->prev_frame_dropped = 0; /* Not yet used */
    pic->cpuused            = 5;
    pic->sharpness          = va_pic->sharpness_level;
    pic->num_token_partitions = va_pic->pic_flags.bits.num_token_partitions; /* 2^2 = 4 partitions */
    pic->encoded_frame_size = pObj->size & ~31;
    pic->encoded_frame_base = (uint32_t)pObj->buffer_data;

    {
        vsp_cmdbuf_reloc_pic_param(&(pic->encoded_frame_base),
                                   ctx->pic_param_offset, pObj->psb_buffer,
                                   cmdbuf->param_mem_loc, pic);
    }

    {
        object_surface_p cur_surf = SURFACE(surface_id);
        if (!cur_surf)
            return VA_STATUS_ERROR_UNKNOWN;

        vsp_cmdbuf_reloc_pic_param(&(pic->input_frame.base),
                                   0, &(cur_surf->psb_surface->buf),
                                   cmdbuf->param_mem_loc, pic);
        vsp_cmdbuf_reloc_pic_param(&(pic->input_frame.base_uv),
                                   pic->input_frame.stride * ctx->obj_context->current_render_target->height,
                                   &(cur_surf->psb_surface->buf),
                                   cmdbuf->param_mem_loc, pic);
    }

    *cmdbuf->cmd_idx++ = CONTEXT_VP8_ID;
    *cmdbuf->cmd_idx++ = VssVp8encEncodeFrameCommand;
    VSP_RELOC_CMDBUF(cmdbuf->cmd_idx++, ctx->pic_param_offset, &cmdbuf->param_mem);
    *cmdbuf->cmd_idx++ = sizeof(struct VssVp8encPictureParameterBuffer);
    *cmdbuf->cmd_idx++ = 0;
    *cmdbuf->cmd_idx++ = 0;
    *cmdbuf->cmd_idx++ = wsbmKBufHandle(wsbmKBuf(pObj->psb_buffer->drm_buf)) ;
    *cmdbuf->cmd_idx++ = wsbmKBufHandle(wsbmKBuf((&cmdbuf->param_mem)->drm_buf));

    return vaStatus;
}
VAStatus rockchip_CreateImage(
    VADriverContextP ctx,
    VAImageFormat *format,
    int width,
    int height,
    VAImage *out_image
)
{
    INIT_DRIVER_DATA
    VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;

    if (!format || !out_image)
        return VA_STATUS_ERROR_INVALID_PARAMETER;

    out_image->image_id = VA_INVALID_ID;
    out_image->buf = VA_INVALID_ID;

    VAImageID image_id = object_heap_allocate(&driver_data->image_heap);
    if (image_id == VA_INVALID_ID) {
        va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
        goto error;
    }

    object_image_p obj_image = IMAGE(image_id);
    if (!obj_image) {
        va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
        goto error;
    }

    obj_image->ref_cnt = 1;

    VAImage * const image = &obj_image->image;
    image->image_id = image_id;
    image->buf = VA_INVALID_ID;

    switch (format->fourcc) {
    case VA_FOURCC_NV12:
        image->num_planes = 2;
        image->pitches[0] = width;
        image->offsets[0] = 0;
        image->pitches[1] = width;
        image->offsets[1] = width * height;
        image->data_size = width * height * 3 / 2;
        image->num_palette_entries = 0;
        image->entry_bytes = 0;
        image->component_order[0] = 'Y';
        image->component_order[1] = 'U';
        image->component_order[2] = 'V';
        image->component_order[3] = '\0';
        break;
    case VA_FOURCC_YV12:
    case VA_FOURCC_IYUV:
        image->num_planes = 3;
        image->pitches[0] = width;
        image->offsets[0] = 0;
        image->pitches[1] = width / 2;
        image->offsets[1] = width * height;
        image->pitches[2] = width / 2;
        image->offsets[2] = width * height * 5 / 4;
        image->data_size = width * height * 3 / 2;
        image->num_palette_entries = 0;
        image->entry_bytes = 0;
        image->component_order[0] = 'Y';
        image->component_order[1] = 'U';
        image->component_order[2] = 'V';
        image->component_order[3] = '\0';
        break;
    default:
        goto error;
    }

    va_status = rockchip_CreateBuffer(ctx, 0, VAImageBufferType,
                                      image->data_size, 1, NULL,
                                      &image->buf);
    if (va_status != VA_STATUS_SUCCESS)
        goto error;

    object_buffer_p obj_buffer = BUFFER(image->buf);
    if (!obj_buffer)
        goto error;

    image->image_id = image_id;
    image->format = *format;
    image->width = width;
    image->height = height;

    *out_image = *image;

    return VA_STATUS_SUCCESS;

error:
    rockchip_DestroyImage(ctx, image_id);
    return va_status;
}
Esempio n. 23
0
VAStatus ved_QueryVideoProcPipelineCaps(
        VADriverContextP    ctx,
        VAContextID         context,
        VABufferID         *filters,
        unsigned int        num_filters,
        VAProcPipelineCaps *pipeline_caps)
{
    INIT_DRIVER_DATA;
    VAStatus vaStatus = VA_STATUS_SUCCESS;
    object_context_p obj_context;
    object_config_p obj_config;
    VAProcFilterParameterBufferBase *base;
    object_buffer_p buf;

    /* check if ctx is right */
    obj_context = CONTEXT(context);
    if (NULL == obj_context) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Failed to find context\n");
        vaStatus = VA_STATUS_ERROR_INVALID_CONTEXT;
        goto err;
    }

    obj_config = CONFIG(obj_context->config_id);
    if (NULL == obj_config) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Failed to find config\n");
        vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
        goto err;
    }

    /* check if filters and num_filters and pipeline-caps are right */
    if (num_filters != 1) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "invalid num_filters %d\n", num_filters);
        vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
        goto err;
    }

    if (NULL == filters || pipeline_caps == NULL) {
        drv_debug_msg(VIDEO_DEBUG_ERROR, "invalid filters %p or pipeline_caps %p\n", filters, pipeline_caps);
        vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
        goto err;
    }

    memset(pipeline_caps, 0, sizeof(*pipeline_caps));

    buf = BUFFER(*(filters));

    if (buf == NULL){
        drv_debug_msg(VIDEO_DEBUG_ERROR, "invalid filter buffer: NULL \n");
        vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
        goto err;
    }

    base = (VAProcFilterParameterBufferBase *)buf->buffer_data;
    /* check filter buffer setting */
    switch (base->type) {
    case VAProcFilterNone:
#ifndef BAYTRAIL
        pipeline_caps->rotation_flags = (1 << VA_ROTATION_NONE);
        pipeline_caps->rotation_flags |= (1 << VA_ROTATION_90);
        pipeline_caps->rotation_flags |= (1 << VA_ROTATION_180);
        pipeline_caps->rotation_flags |= (1 << VA_ROTATION_270);
#endif
        break;

    default:
        drv_debug_msg(VIDEO_DEBUG_ERROR, "Do NOT support the filter type %d\n", base->type);
        vaStatus = VA_STATUS_ERROR_UNKNOWN;
        goto err;
    }
err:
    return vaStatus;
}
Esempio n. 24
0
long FAR PASCAL _export WndProc (HWND hwnd,
                                 UINT message,
                                 UINT wParam,
                                 LONG lParam)
   {
   
   static char    *pBuffer = NULL;
   static int     cxChar,
                  cyChar,
                  cxClient,
                  cyClient,
                  cxBuffer,
                  cyBuffer,
                  xCaret,
                  yCaret;
   HDC            hdc;              //handle to device context
   int            x,
                  y,
                  i;
   PAINTSTRUCT    ps;           
   TEXTMETRIC     tm;

   TRACE_STR("ENTER WndProc");
   switch(message)
      {
      case WM_CREATE :
         {
         TRACE_DELIM('=');
         TRACE_STR("WM_CREATE..");
         
         hdc = GetDC(hwnd);
         SelectObject (hdc, GetStockObject(SYSTEM_FIXED_FONT));
         
         GetTextMetrics(hdc, &tm);
         // Suggested character width for all chars in fixed width font...
         cxChar = tm.tmAveCharWidth;
         // character height 
         cyChar = tm.tmHeight;
         ReleaseDC (hwnd,hdc);
         TRACE_STR("EXIT WM_CREATE..");
         TRACE_STR("EXIT WndProc");
         return 0;          
         }
      case WM_SIZE:
         {
         TRACE_STR("WM_SIZE..");

         // current window size in pixels...
         cyClient = HIWORD(lParam);
         cxClient = LOWORD(lParam);
         TRACE_INT(cxClient);
         TRACE_INT(cyClient);

         //Window size in characters in current font...
         cxBuffer = max(1,cxClient/cxChar);
         cyBuffer = max(1,cyClient/cyChar);
         TRACE_INT(cxBuffer);
         TRACE_INT(cyBuffer);

         if (pBuffer != NULL)
            free(pBuffer);

         if ( ( ((LONG) (cxBuffer * cyBuffer)) > 65535L                 ) ||
              ((pBuffer = (char *) malloc (cxBuffer * cyBuffer)) == NULL)
            )
            {
            MessageBox (hwnd,
                        "Window too large. Cannot"
                        "Allocate enough memory.",
                        "Type",
                        MB_ICONEXCLAMATION | MB_OK
                       );
            }
         else
            {
            TRACE_FARP(pBuffer);
            for (y=0; y < cyBuffer ; y++)
               for (x = 0; x < cxBuffer ; x++)
                  BUFFER(x,y) = ' ';
            }
         xCaret = 0;
         yCaret = 0;

         if (hwnd == GetFocus())
            {
            SetCaretPos (xCaret * cxChar, yCaret * cyChar);
            }           
         
         TRACE_STR("EXIT WM_SIZE..");
         TRACE_STR("EXIT WndProc");
         return 0;       
         }

      case WM_SETFOCUS :
         {
         TRACE_STR("ENTER WM_SETFOCUS..");
         CreateCaret(hwnd, NULL, cxChar, cyChar);
         SetCaretPos(xCaret * cxChar, yCaret * cyChar);
         ShowCaret(hwnd);
         TRACE_STR("EXIT WM_SETFOCUS..");
         TRACE_STR("EXIT WndProc");
         return 0;       
         }
         
      case WM_KEYDOWN :
         {
         TRACE_STR("ENTER WM_KEYDOWN...");
         TRACE_INT(wParam);
         switch(wParam)
            {
            case VK_HOME:
               {
               xCaret = 0;
               break;
               }
            case VK_END:
               {
               xCaret = cxBuffer - 1;
               break;
               }
            case VK_PRIOR:
               {
               yCaret = 0;
               break;
               }
            case VK_NEXT:
               {
               yCaret = cyBuffer - 1;
               break;
               }
            case VK_LEFT:
               {
               xCaret = max(xCaret - 1, 0);
               break;
               }
            case VK_RIGHT:
               {
               xCaret = min(xCaret + 1, cxBuffer - 1);
               break;
               }
            case VK_UP:
               {
               yCaret = max(yCaret - 1, 0);
               break;
               }
            case VK_DOWN:
               {
               yCaret = min(yCaret + 1, cyBuffer - 1);
               break;
               }
            case VK_DELETE:
               {
               for (x = xCaret ; x < cxBuffer; x++)
                  BUFFER(x,yCaret) = BUFFER(x+1, yCaret);
               BUFFER(cxBuffer - 1, yCaret) = ' ';
               HideCaret(hwnd);
               hdc = GetDC(hwnd);

               SelectObject(hdc,
                            GetStockObject(SYSTEM_FIXED_FONT));
               TextOut(hdc,
                       xCaret * cxChar,
                       yCaret * cyChar,
                       &BUFFER(xCaret,yCaret),
                       cxBuffer - xCaret
                       );               
               ShowCaret(hwnd);
               ReleaseDC(hwnd, hdc);                        
               break;
               }
            }
         SetCaretPos(xCaret*cxChar, yCaret*cyChar);   
         TRACE_STR("EXIT WM_KEYDOWN...");
         TRACE_STR("EXIT WndProc");
         return 0;
         }       
      case WM_CHAR :
         {
         TRACE_STR("ENTER WM_CHAR...");
         TRACE_INT(wParam);
         for (i = 0; i < (int) LOWORD(lParam) ; i++)
            {
            switch(wParam)
               {
               case '\b': //backspace
                  {
                  TRACE_STR(">>BACKSPACE..");
                  if(xCaret > 0)
                     {
                     xCaret--;
                     SendMessage(hwnd, 
                                 WM_KEYDOWN,
                                 VK_DELETE,
                                 1L
                                );
                     }
                  TRACE_STR(">>END BACKSPACE..");
                  break;
                  }
               case '\t': //tab
                  {
                  TRACE_STR(">>TAB..");
                  // EXTREMELY curious!
                  do
                     {
                     // this is acted upon immediately!
                     // it calls WndProc for 'hwnd' with the indicated
                     // message/wParam/lParam...
                     SendMessage(hwnd, 
                                 WM_CHAR, 
                                 ' ',
                                 1L
                                );
                     }
                  while (xCaret % 8 != 0);                     
                  TRACE_STR(">>END TAB..");
                  break;
                  }
               case '\n': //linefeed
                  {
                  TRACE_STR(">>LINEFEED..");
                  if (++yCaret == cyBuffer)
                     yCaret = 0;
                  TRACE_STR(">>END LINEFEED..");
                  break;
                  }
               case '\r': //carraige return
                  {
                  TRACE_STR(">>CARRAIGE RETURN..");
                  xCaret = 0;
                  if (++yCaret == cyBuffer)
                     yCaret = 0;
                  TRACE_STR(">>END CARRAIGE RETURN..");
                  break;
                  }
               case '\x1B': //excape (!)
                  {
                  TRACE_STR(">>ESCAPE...");
                  for(y=0;y<cyBuffer; y++)
                     {
                     for(x=0; x<cxBuffer; x++)
                        {
                        BUFFER(x,y) = ' ';
                        }
                     }
                  xCaret = 0;
                  yCaret = 0;
                  InvalidateRect(hwnd,NULL,FALSE);   
                  TRACE_STR(">>END ESCAPE...");
                  break;
                  }
               default :
                  {
                  TRACE_STR(">>default...");
                  BUFFER(xCaret,yCaret) = (char) wParam;

                  HideCaret(hwnd);
                  hdc = GetDC(hwnd);
                  SelectObject(hdc,
                               GetStockObject(SYSTEM_FIXED_FONT));
                  TextOut(hdc,
                          xCaret*cxChar,
                          yCaret*cyChar,
                          &BUFFER(xCaret,yCaret),
                          1);
                  ShowCaret(hwnd);
                  ReleaseDC(hwnd,hdc);
                  if(++xCaret == cxBuffer)
                     {
                     xCaret = 0;
                     if(++yCaret == cyBuffer)
                        yCaret = 0;
                     }                          
                  TRACE_STR(">>END default...");
                  break;
                  }
               }
            }
         SetCaretPos (xCaret * cxChar, yCaret * cyChar);
         TRACE_STR("EXIT WM_CHAR...");
         TRACE_STR("EXIT WndProc");
         return 0;   
         }       
      case WM_PAINT :
         {
         TRACE_STR("WM_PAINT..");
         // Invalidate the entire client area and erase it....
         //get the device context handle for use in painting the sucker...
         hdc = BeginPaint(hwnd, &ps);
         
         // set up the font as fixed width font...
         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));

         for (y = 0; y<cyBuffer; y++)
            {
            TextOut(hdc,
                    0,
                    y * cyChar,
                    &BUFFER(0,y),
                    cxBuffer);
            }
         EndPaint (hwnd, &ps);
         TRACE_STR("EXIT WM_PAINT...");
         TRACE_STR("EXIT WndProc");
         return 0;      
         }
      case WM_DESTROY :
         {
         // insert a WM_QUIT in the queue...
         TRACE_STR("WM_DESTROY..");
         PostQuitMessage (0);
         TRACE_STR("EXIT WndProc");
         return 0;            
         }
      }//switch
   TRACE_STR("EXIT WndProc");
   return DefWindowProc (hwnd, message, wParam, lParam);   
   } //WndProc
Esempio n. 25
0
/**
 * return the length of the buffer
 */
JSValueRef GetLengthForJSBuffers (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
    BUFFER(buffer);
    return JSValueMakeNumber(ctx, buffer->length);
}
Esempio n. 26
0
/*
** This is a helper function that inserts characters into the specified
** buffer in overwrite mode.
*/
static void
_primBufferOverwriteWc
(
    const TermBuffer  tb,
    const short       row,
          short      *col,
          wchar_t    *newChars,
          short       numChars,
          short      *lengthInc,
          short      *widthInc,
          short      *widthInsert,  /* width of inserted characters           */
          termChar   *returnChars,  /* pointer to overflow buffer             */
          short      *returnLength  /* count of characters in overflow buffer */
)
{
           short        charWidth;
           short        insertOverflow; /* # of newChars that would overflow */
           short        lengthInsert;
           short        localCol;
           TermLine     line;
    const  char        *pStart;
    TermCharInfoRec     charInfo;
    TermCharInfoRec     startCharInfo;
	   
    line = LINE_OF_TBUF(tb, row);

    /*
    ** make a copy of *col because it may be modified by
    ** _patchUpChar()
    */
    localCol = *col;
    
    /*
    ** first decide how many characters we can overwrite before
    ** running off the end of the line.
    */
    _countWidth(newChars, numChars, COLS(tb) - localCol, &lengthInsert,
	        widthInsert);
	   
    /* 
    ** We are overwriting:
    **      - determine the length and width increments
    **      - put any extra new characters into the overflow buffer
    */
    if (localCol == WIDTH(line))
    {
	/*
	** we are appending to the end of the line, this is easy...
	*/
	*widthInc  = *widthInsert;
        *lengthInc = lengthInsert;
	pStart    = (char *)BUFFER(line) +  (LENGTH(line) * sizeof(wchar_t));
    }
    else
    {
	/*
	** we are overwriting characters in the middle of the line...
	**
	** make sure we are not trying to overwrite the second column
	** of a two column character.
	*/
	_patchUpChar(tb, row, col, &startCharInfo);
	
	/*
	** see if we have to deal with the end of the line...
	*/
	if (localCol + *widthInsert < WIDTH(line))
	{
	    /*
	    ** the line width will remain constant, but the length may 
	    ** change...
	    */
	    *widthInc = 0;

	    /*
	    ** make sure we are not trying to overwrite the first column
	    ** of a two column character.
	    */
	    _DtTermPrimGetCharacterInfo(tb, row, localCol + *widthInsert,
					&charInfo);
	    if ((charInfo.width == 2) &&
		(charInfo.startCol == localCol + *widthInsert - 1))
	    {
		/*
		** We are about to overwrite column 1 of a 2 column
		** character.  Replace it with a space before we proceed
		** (we make adjustments later to make it look like we
		** replaced the second column with a space).
		*/
		*charInfo.u.pwc = L' ';
	    
		/*
		** now update the charInfo (since we replaced the 2 column
		** character with a single column space)...
		*/
		charInfo.width = 1;
	    }

	    /*
	    ** at this point, startCharInfo points to the first
	    ** character to replace, now we want charInfo.u.pwc
	    ** to point to the character one past the last one
	    ** we want to replace
	    */
	    *lengthInc = lengthInsert - (charInfo.u.pwc - startCharInfo.u.pwc);
	    
	    if (*lengthInc != 0)
	    {
		memmove(charInfo.u.pwc + *lengthInc, charInfo.u.pwc,
			(LENGTH(line) - charInfo.idx) * sizeof(wchar_t));
	    }
	}
	else
	{
	    /*
	    ** the line may get wider and longer...
	    */
	    *widthInc  = localCol + *widthInsert - WIDTH(line);
	    *lengthInc = startCharInfo.idx + lengthInsert - LENGTH(line);
	}
	pStart = startCharInfo.u.pc;
    }

    /*
    ** now insert the new characters...
    */
    memcpy((void *)pStart, newChars, lengthInsert * sizeof(wchar_t));

    /*
    ** put any overflow into the overflow buffer
    */
    *returnLength = numChars - lengthInsert;
    if (*returnLength > 0)
    {
	memcpy(returnChars, newChars + lengthInsert,
	       *returnLength * sizeof(wchar_t));
    }
}
Esempio n. 27
0
/*
** This is a helper function that inserts characters into the specified
** buffer in insert mode.
*/
static void
_primBufferInsertWc
(
    const TermBuffer  tb,
    const short       row,
          short      *col,
          wchar_t    *newChars,
          short       numChars,
          short      *lengthInc,
          short      *widthInc,
	  short      *widthInsert,  /* width of inserted characters      */
          termChar   *returnChars,  /* pointer to overflow buffer             */
          short      *returnLength  /* count of characters in overflow buffer */
)
{
    short             charWidth;
    short             lengthInsert;
    short             insertOverflow; /* # of newChars that would overflow */
    short             overflowLength;
    short             overflowWidth;
    short             localCol;
    TermLine          line;
    wchar_t          *pwc;
    TermCharInfoRec   charInfo;

    /*
    ** make a copy of *col because it may be modified by
    ** _patchUpChar()
    */
    localCol = *col;
    
    /*
    ** first decide how many characters we can insert before
    ** running off the end of the line...
    */
    _countWidth(newChars, numChars, COLS(tb) - localCol, &lengthInsert,
	        widthInsert);
	   
    /*
    ** return any extra characters...
    */
    *returnLength = numChars - lengthInsert;
	   
    if (*returnLength > 0)
    {
        /*
        ** we have some overflow...
	*/
	memcpy(returnChars, newChars + lengthInsert,
	       *returnLength * sizeof(wchar_t));
    }
	
    /*
    ** make sure we are not trying to overwrite the second column
    ** of a two column character.
    */
    _patchUpChar(tb, row, col, &charInfo);
	   
    /*
    ** Decide how many characters we can insert before running off the
    ** end of the buffer...
    */
    line = LINE_OF_TBUF(tb, row);
    if (WIDTH(line) + *widthInsert <= COLS(tb))
    {
	/*
	** there is no overflow, we can insert all "lengthInsert" characters...
	*/
	*widthInc      = *widthInsert;
	*lengthInc     = lengthInsert;
	overflowLength = 0;
    }
    else
    {
	overflowWidth = WIDTH(line) + *widthInsert - COLS(tb);
	
	/* 
	** inserting the new characters will overflow the line buffer,
	** remove as many of the current characters on the line
	** as necessary to prevent buffer overflow
	*/
	if (overflowWidth > 0)
	{
	    *widthInc = *widthInsert - overflowWidth;
	    
	    for (pwc = ((wchar_t *)BUFFER(line)) + LENGTH(line) - 1; 
		 pwc >= charInfo.u.pwc; pwc--)
	    {
		overflowWidth -= MAX(1, wcwidth(*pwc));

		if (overflowWidth <= 0)
		{
		    /* 
		    ** we've removed enough characters, pwc points to the
		    ** first character to remove...
		    */
		    break;
		}
	    }

	    /*
	    ** final adjustment to widthInc (at this point overflowWidth
	    ** is either 0 (we removed exactly "overflowWidth" worth of
	    ** characters) or -1 (we removed "overflowWidth + 1" worth of
	    ** characters because we removed some 2 column characters)
	    */
	    *widthInc += overflowWidth;
        }

	overflowLength = ((wchar_t *)BUFFER(line)) + LENGTH(line) - pwc; 

	if (overflowLength > 0)
	{
	    *lengthInc = lengthInsert - overflowLength;
	    
	    /* 
	    ** copy the displaced characters from the line to the 
	    ** overflow buffer...
	    */
	    memcpy(returnChars + *returnLength, pwc,
		   overflowLength * sizeof(wchar_t));
	    *returnLength += overflowLength;
        }
    }

    /* 
    ** Any overflow has been taken care of, now it's time to make
    ** room for the new characters...
    **
    ** at this point:
    **      charInfo.pchar points to the character at col
    */
    memmove(charInfo.u.pwc + lengthInsert, charInfo.u.pwc,
	    (((LENGTH(line) - charInfo.idx) - overflowLength) * 
	     sizeof(wchar_t)));

    /*
    ** copy the new characters into the buffer
    */	   
    memcpy(charInfo.u.pwc, newChars, lengthInsert * sizeof(wchar_t));
}
Esempio n. 28
0
/**
 * put
 */
JSValueRef putForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    ARGCOUNT(4);
    JSValueRef bufValueRef = arguments[0];
    if (!JSValueIsObject(ctx,bufValueRef))
    {
        JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }
    JSObjectRef bufObjectRef = JSValueToObject(ctx,bufValueRef,exception);
    CHECK_EXCEPTION_UNDEFINED
    JSBuffer *srcBuffer = (JSBuffer*)HyperloopGetPrivateObjectAsJSBuffer(bufObjectRef);
    if (srcBuffer==nullptr)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("first argument must be a buffer object (JSBuffer nullptr)");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

    GET_NUMBER(1,srcIndex);
    GET_NUMBER(2,srcLength);
    GET_NUMBER(3,destIndex);

    if (srcLength > srcBuffer->length)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("source length passed in greater than source buffer length");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

    if (srcLength <= 0)
    {
        JSStringRef string = JSStringCreateWithUTF8CString("source length must be greater than 0");
        JSValueRef message = JSValueMakeString(ctx, string);
        JSStringRelease(string);
        *exception = JSObjectMakeError(ctx, 1, &message, 0);
        return JSValueMakeUndefined(ctx);
    }

	throw ref new Exception(0, "JSBuffer's putForJSBuffer has not been implemented on Windows yet.");
    /*void *src = &(srcBuffer->buffer[(int)srcIndex]);
    size_t newsize = (buffer->length - (int)destIndex);
    newsize = newsize + srcLength - newsize;
    void *dest = &(buffer->buffer[(int)destIndex]);

    if (newsize  > buffer->length)
    {
        // new to grow it
        void *copy = malloc(buffer->length);
        size_t copylen = buffer->length;
        memcpy(copy, buffer->buffer, copylen);
        free(buffer->buffer);
        buffer->buffer = malloc(newsize);
        buffer->length = newsize;
        memcpy(buffer->buffer,copy,copylen);
    }
    memcpy(dest, src, (int)srcLength);

    return object;*/
}
Esempio n. 29
0
/**
 * toBoolArray
 */
JSValueRef toBoolArrayForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    GET_ARRAY(bool);
}
Esempio n. 30
0
/**
 * isNan
 */
JSValueRef isNaNForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    BUFFER(buffer);
    PRIMITIVE_GET(float);
    return JSValueMakeBoolean(ctx, isnan(value));
}