view src/video/caca/SDL_cacaevents.c @ 4388:1524d3237820 SDL-1.2

Fixed bug #896 John Popplewell 2009-12-08 23:05:50 PST Originally reported by AKFoerster on the mailing list. Error decoding UTF8 Russian text to UTF-16LE on Windows, but specifically on platforms without iconv support (the default on Windows). Valid UTF8 characters are flagged as being overlong and then substituted by the UNKNOWN_UNICODE character. After studying the testiconv.c example program, reading the RFCs and putting some printf statements in SDL_iconv.c the problem is in a test for 'Maximum overlong sequences', specifically 4.2.1, which is carried out by the following code: } else if ( p[0] >= 0xC0 ) { if ( (p[0] & 0xE0) != 0xC0 ) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if ( (p[0] & 0xCE) == 0xC0 ) { <<<<<<<< here overlong = SDL_TRUE; } ch = (Uint32)(p[0] & 0x1F); left = 1; } } else { Here is the 2-byte encoding of a character in range 00000080 - 000007FF 110xxxxx 10xxxxxx The line in question is supposed to be checking for an overlong sequence which would be less than 11000001 10111111 which should be represented as a single byte. BUT, the mask value (0xCE) is wrong, it isn't checking the top-most bit: 11000001 value 11001110 mask (incorrect) ^ and should be (0xDE): 11000001 value 11011110 mask (correct) making the above code: } else if ( p[0] >= 0xC0 ) { if ( (p[0] & 0xE0) != 0xC0 ) { /* Skip illegal sequences return SDL_ICONV_EILSEQ; */ ch = UNKNOWN_UNICODE; } else { if ( (p[0] & 0xDE) == 0xC0 ) { <<<<<<<< here overlong = SDL_TRUE; } ch = (Uint32)(p[0] & 0x1F); left = 1; } } else { I can supply a test program and/or a patch if required, best regards, John Popplewell
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 08:00:57 +0000
parents d1c0ac95d023
children
line wrap: on
line source

/*
    SDL - Simple DirectMedia Layer
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Sam Lantinga
    slouken@libsdl.org
*/

#ifdef SAVE_RCSID
static char rcsid =
 "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
#endif

#include <stdio.h>

#include <caca.h>
#ifdef CACA_API_VERSION_1
#include <caca0.h>
#endif

#include "SDL.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_cacavideo.h"
#include "SDL_cacaevents_c.h"

void Caca_PumpEvents(_THIS)
{
	int posted = 0;
	int event;
	SDL_keysym keysym;

	if( ! this->screen ) /* Wait till we got the screen initialised */
	  return;

	do {
		posted = 0;

		/* Get libcaca event */
		SDL_mutexP(Caca_mutex);
		event = caca_get_event(CACA_EVENT_ANY);
		SDL_mutexV(Caca_mutex);

		if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) {
			int key;
			switch ( event & 0xffffff )
			{
				case CACA_KEY_LEFT: key = SDLK_LEFT; break;
				case CACA_KEY_RIGHT: key = SDLK_RIGHT; break;
				case CACA_KEY_UP: key = SDLK_UP; break;
				case CACA_KEY_DOWN: key = SDLK_DOWN; break;
				default: key = event & 0xff; break;
			}
			/* Key pressed */
/*    		printf("Key pressed: %d (%c)\n", key, key); */
			keysym.scancode = key;
			keysym.sym = key;
			keysym.mod = KMOD_NONE;
			keysym.unicode = 0;
			if ( SDL_TranslateUNICODE ) {
				keysym.unicode = key;
			}
			posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym);
		}
		else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) {
			/* FIXME: we currently ignore the button type! */
			int button = event & 0x00ffffff;
			if ( button > 3 ) {
				button = 1;
			}
			posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0);
		}
		else if ( event & CACA_EVENT_MOUSE_MOTION ) {
			int new_x = 0, new_y = 0;
			new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width();
			new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height();
			posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y);
		}
	} while ( posted );
}

void Caca_InitOSKeymap(_THIS)
{
    return;
}