Beispiel #1
0
int testCharacter(){
    char testchar[] = "[({ ax})]";
   
    int charlength = strlen(testchar);
    int i;
    int loopCtr = 0;


    for( i = 0; i < charlength; i++ ){
	char c = inputChar();

	while( testchar[i] != c){
		c = inputChar();
		
		loopCtr++;
		
		if( loopCtr == 1000000 ){
			printf("Failure: Could not generate: testchar[%c]\n", testchar[i]);
			exit(1);	
		}
	}
	printf("Success:%c == testchar[i], After: %i\n",c,loopCtr);
    }
    return 0;

}
int main(int argc, const char * argv[]) {
    
    FILE *employeesFIle; // Criaçao e/ou teste do arquivo de Funcionarios
    if((employeesFIle = fopen("df.bin", "rb")) == NULL){ //teste de exitencia
        if((employeesFIle = fopen("df.bin", "ab"))    == NULL){ //teste de erro na criaçao
            inputChar("\n-----\nErro na abertura ou criaçao do arquivo de parametros\n Contacte o suporte\n\n Tecle enter para fechar o programa\n");
            fflush(stdin);
            return 0;
        }
    }
    fclose(employeesFIle);
    
    FILE *productsFile; // Criaçao e/ou teste do arquivo de Materiais
    if((productsFile = fopen("dm.bin", "rb")) == NULL){ //Teste de existencia
        if((productsFile = fopen("dm.bin", "ab"))    == NULL){ // Teste de erro na criaçao
            inputChar("\n-----\nErro na abertura ou criaçao do arquivo de parametros\n Contacte o suporte\n\n Tecle enter para fechar o programa\n");
            fflush(stdin);
            return 0;
        }
    }
    
    fclose(productsFile);
    
    
    controll();
    return 0;
}
Beispiel #3
0
void testme()
{
  int tcCount = 0;
  char *s;
  char c;
  int state = 0;
  while (1)
  {
    tcCount++;
    c = inputChar();
    s = inputString();
    printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);

    if (c == '[' && state == 0) state = 1;
    if (c == '(' && state == 1) state = 2;
    if (c == '{' && state == 2) state = 3;
    if (c == ' '&& state == 3) state = 4;
    if (c == 'a' && state == 4) state = 5;
    if (c == 'x' && state == 5) state = 6;
    if (c == '}' && state == 6) state = 7;
    if (c == ')' && state == 7) state = 8;
    if (c == ']' && state == 8) state = 9;
    if (s[0] == 'r' && s[1] == 'e'
       && s[2] == 's' && s[3] == 'e'
       && s[4] == 't' && s[5] == '\0'
       && state == 9)
    {
      printf("error ");
      exit(200);
    }
  }
}
Beispiel #4
0
bool CGUIEditBox::processIMEEvent(const SEvent& event)
{
    switch(event.InputMethodEvent.Event)
    {
    case EIME_CHAR_INPUT:
        inputChar(event.InputMethodEvent.Char);
        return true;
    case EIME_CHANGE_POS:
    {
        core::position2di pos = calculateICPos();

        IGUIFont* font = OverrideFont;
        IGUISkin* skin = Environment->getSkin();

        if (!OverrideFont)
            font = skin->getFont();

        irr::updateICPos(event.InputMethodEvent.Handle, pos.X,pos.Y, font->getDimension(L"|").Height);

        return true;
    }
    default:
        break;
    }

    return false;
}
Beispiel #5
0
char *inputString()
{
  char randomString[6];
  int i;
  for(i=0; i<5;i++){
    randomString[i]=inputChar();

  }
  randomString[5] = '\0';
    // TODO: rewrite this function
    return &randomString;
}
Beispiel #6
0
char *inputString()
{
    // TODO: rewrite this function
    char *randString = NULL;
    randString = malloc(sizeof(char) * (6));

    for(int i = 0; i < 6; i++) {
        randString[i] = inputChar();
    }

    return randString;
}
Beispiel #7
0
/*
    Function Name:  inputString
    Parameters:     None
    Returns:        This function returns a random, null-terminated, six-character
                    string that is built from the folloiwng set of characters:
                    "abcdefghijklmnopqrstuvwxyz([{}]) ".  
    Description:    This function begins by allocating a pointer to a character array 
                    that can hold six characters. Next, it loops five times, each time 
                    calling the inputChar function to store a random character in an 
                    appropriate index. Finally, it appends the null terminator at the 
                    end of the string.  Then the string is returned.
*/
char *inputString() {
    char *string = malloc(sizeof(char) * 6);
    int iteration;

    for (iteration = 0; iteration < 5; iteration++) {
        string[iteration] = inputChar();
    }

    string[5] = '\0';

    return string;
}
Beispiel #8
0
char *inputString()
{
    int strLen = random() % 5;

    if (strLen == 0)
        strLen = 5;

    char *fullString = malloc(sizeof(char) * (strLen +1));

    int i = 0;
    for (; i < strLen; i++)
        fullString[i] = inputChar();

    fullString[strLen] = '\0';
    return fullString;
}
Beispiel #9
0
/*
Creates a string of 6 chars (incl. null terminator) and fills it with the random
letters generated by inputChar().
*/
char *inputString()
{
	int i;
	static char randString[6];	//String has max of 5 chars, +1 for null terminator
	
	for(i = 0; i < 5; i++)
	{
		randString[i] = inputChar();
	}
	randString[5] = '\0';
#if FINDFASTER
	randString[0] = 'r';
	randString[1] = 'e';
	randString[2] = 's';
#endif
//	printf("DEBUG: randString = %s\n",randString);	
    return randString;
}
Beispiel #10
0
static void keyboardHandleKey(void* data,
                              struct wl_keyboard* keyboard,
                              uint32_t serial,
                              uint32_t time,
                              uint32_t key,
                              uint32_t state)
{
    int keyCode;
    int action;
    _GLFWwindow* window = _glfw.wl.keyboardFocus;
    GLFWbool shouldRepeat;
    struct itimerspec timer = {};

    if (!window)
        return;

    keyCode = toGLFWKeyCode(key);
    action = state == WL_KEYBOARD_KEY_STATE_PRESSED
            ? GLFW_PRESS : GLFW_RELEASE;

    _glfw.wl.serial = serial;
    _glfwInputKey(window, keyCode, key, action,
                  _glfw.wl.xkb.modifiers);

    if (action == GLFW_PRESS)
    {
        shouldRepeat = inputChar(window, key);

        if (shouldRepeat && _glfw.wl.keyboardRepeatRate > 0)
        {
            _glfw.wl.keyboardLastKey = keyCode;
            _glfw.wl.keyboardLastScancode = key;
            if (_glfw.wl.keyboardRepeatRate > 1)
                timer.it_interval.tv_nsec = 1000000000 / _glfw.wl.keyboardRepeatRate;
            else
                timer.it_interval.tv_sec = 1;
            timer.it_value.tv_sec = _glfw.wl.keyboardRepeatDelay / 1000;
            timer.it_value.tv_nsec = (_glfw.wl.keyboardRepeatDelay % 1000) * 1000000;
        }
    }
    timerfd_settime(_glfw.wl.timerfd, 0, &timer, NULL);
}
Beispiel #11
0
void chartoascii(){
    int userChoise = 0;
    char didExit = 'a';
    while(1){
        char c;

        system("cls");

        setConsoleColor(FOREGROUND_BLUE | FOREGROUND_INTENSITY);

        printf ("########################################\n");
        printf ("######  Welcome on char to ascii  ######\n");
        printf ("########################################\n");
        printf ("\n");
        fflush(stdout);

        printf ("########################################\n");
        printf ("# Press char and get it to ascii       #\n");
        printf ("# 1 : take a char                      #\n");
        printf( "# 2 : validate                         #\n");
        printf ("########################################\n");
        printf ("\n");
        fflush(stdout);

        /* Restore original attributes */
        setConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

        printf("Enter a character: ");
        c = inputChar();
        printf("ASCII value of %c = %d\n",c,c);

        printf ("Do you want to exit? (q) :");
        didExit = needToExit();
        if(didExit == 'q'){
            asciiHomeDisplay();
            userChoise = userInputInt(3);
            asciiHomeUse(userChoise);
        }
    }
}
Beispiel #12
0
static void keyboardHandleKey(void* data,
                              struct wl_keyboard* keyboard,
                              uint32_t serial,
                              uint32_t time,
                              uint32_t key,
                              uint32_t state)
{
    int keyCode;
    int action;
    _GLFWwindow* window = _glfw.wl.keyboardFocus;

    if (!window)
        return;

    keyCode = toGLFWKeyCode(key);
    action = state == WL_KEYBOARD_KEY_STATE_PRESSED
            ? GLFW_PRESS : GLFW_RELEASE;

    _glfwInputKey(window, keyCode, key, action,
                  _glfw.wl.xkb.modifiers);

    if (action == GLFW_PRESS)
        inputChar(window, key);
}
Beispiel #13
0
	bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
	{
		s_debug = _debug;
		s_reset = _reset;

		WindowHandle handle = { UINT16_MAX };

		bool mouseLock = inputIsMouseLocked();

		const Event* ev;
		do
		{
			struct SE
			{
				SE(WindowHandle _handle)
					: m_ev(poll(_handle) )
				{
				}

				~SE()
				{
					if (NULL != m_ev)
					{
						release(m_ev);
					}
				}

				const Event* m_ev;

			} scopeEvent(handle);
			ev = scopeEvent.m_ev;

			if (NULL != ev)
			{
				handle = ev->m_handle;
				WindowState& win = s_window[handle.idx];

				switch (ev->m_type)
				{
				case Event::Axis:
					{
						const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
						inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
					}
					break;

				case Event::Char:
					{
						const CharEvent* chev = static_cast<const CharEvent*>(ev);
						win.m_handle = chev->m_handle;
						inputChar(chev->m_len, chev->m_char);
					}
					break;

				case Event::Exit:
					return true;

				case Event::Gamepad:
					{
						const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
						DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
					}
					break;

				case Event::Mouse:
					{
						const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
						win.m_handle = mouse->m_handle;

						if (mouse->m_move)
						{
							inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
						}
						else
						{
							inputSetMouseButtonState(mouse->m_button, mouse->m_down);
						}

						if (!mouseLock)
						{
							if (mouse->m_move)
							{
								win.m_mouse.m_mx = mouse->m_mx;
								win.m_mouse.m_my = mouse->m_my;
								win.m_mouse.m_mz = mouse->m_mz;
							}
							else
							{
								win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
							}
						}
					}
					break;

				case Event::Key:
					{
						const KeyEvent* key = static_cast<const KeyEvent*>(ev);
						win.m_handle = key->m_handle;

						inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
					}
					break;

				case Event::Size:
					{
						const SizeEvent* size = static_cast<const SizeEvent*>(ev);
						win.m_handle = size->m_handle;
						win.m_width  = size->m_width;
						win.m_height = size->m_height;
						_reset  = win.m_handle.idx == 0
								? !s_reset
								: _reset
								; // force reset
					}
					break;

				case Event::Window:
					{
						const WindowEvent* window = static_cast<const WindowEvent*>(ev);
						win.m_handle = window->m_handle;
						win.m_nwh    = window->m_nwh;
						ev = NULL;
					}
					break;

				default:
					break;
				}
			}

			inputProcess();

		} while (NULL != ev);

		if (isValid(handle) )
		{
			const WindowState& win = s_window[handle.idx];
			_state = win;

			if (handle.idx == 0)
			{
				inputSetMouseResolution(win.m_width, win.m_height);
			}
		}

		if (_reset != s_reset)
		{
			_reset = s_reset;
			bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
			inputSetMouseResolution(s_window[0].m_width, s_window[0].m_height);
		}

		_debug = s_debug;

		return s_exit;
	}
Beispiel #14
0
	bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
	{
		s_debug = _debug;
		s_reset = _reset;

		WindowHandle handle = { UINT16_MAX };

		bool mouseLock = inputIsMouseLocked();

		const Event* ev;
		do
		{
			struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
			ev = scopeEvent.m_ev;

			if (NULL != ev)
			{
				switch (ev->m_type)
				{
				case Event::Axis:
					{
						const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
						inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
					}
					break;

				case Event::Char:
					{
						const CharEvent* chev = static_cast<const CharEvent*>(ev);
						inputChar(chev->m_len, chev->m_char);
					}
					break;

				case Event::Exit:
					return true;

				case Event::Gamepad:
					{
						const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
						DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
					}
					break;

				case Event::Mouse:
					{
						const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
						handle = mouse->m_handle;

						if (mouse->m_move)
						{
							inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
						}
						else
						{
							inputSetMouseButtonState(mouse->m_button, mouse->m_down);
						}

						if (NULL != _mouse
						&&  !mouseLock)
						{
							if (mouse->m_move)
							{
								_mouse->m_mx = mouse->m_mx;
								_mouse->m_my = mouse->m_my;
								_mouse->m_mz = mouse->m_mz;
							}
							else
							{
								_mouse->m_buttons[mouse->m_button] = mouse->m_down;
							}
						}
					}
					break;

				case Event::Key:
					{
						const KeyEvent* key = static_cast<const KeyEvent*>(ev);
						handle = key->m_handle;

						inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
					}
					break;

				case Event::Size:
					{
						const SizeEvent* size = static_cast<const SizeEvent*>(ev);
						handle  = size->m_handle;
						_width  = size->m_width;
						_height = size->m_height;
						_reset  = !s_reset; // force reset
					}
					break;

				case Event::Window:
					break;

				default:
					break;
				}
			}

			inputProcess();

		} while (NULL != ev);

		if (handle.idx == 0
		&&  _reset != s_reset)
		{
			_reset = s_reset;
			bgfx::reset(_width, _height, _reset);
			inputSetMouseResolution(_width, _height);
		}

		_debug = s_debug;

		return s_exit;
	}
Beispiel #15
0
bool CGUIEditBox::processKey(const SEvent& event)
{
    if (!event.KeyInput.PressedDown)
        return false;

    bool textChanged = false;
    s32 newMarkBegin = MarkBegin;
    s32 newMarkEnd = MarkEnd;

    // control shortcut handling

    if (event.KeyInput.Control)
    {
        // german backlash '\' entered with control + '?'
        if ( event.KeyInput.Char == '\\' )
        {
            inputChar(event.KeyInput.Char);
            return true;
        }

        switch(event.KeyInput.Key)
        {
        case KEY_KEY_A:
            // select all
            newMarkBegin = 0;
            newMarkEnd = Text.size();
            break;
        case KEY_KEY_C:
            // copy to clipboard
            if (!PasswordBox && Operator && MarkBegin != MarkEnd)
            {
                const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
                const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

                core::stringw s;
                s = Text.subString(realmbgn, realmend - realmbgn).c_str();
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                Operator->copyToClipboard(s.c_str());
#else
                Operator->copyToClipboard(StringUtils::wideToUtf8(s).c_str());
#endif
            }
            break;
        case KEY_KEY_X:
            // cut to the clipboard
            if (!PasswordBox && Operator && MarkBegin != MarkEnd)
            {
                const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
                const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

                // copy
                core::stringw sc;
                sc = Text.subString(realmbgn, realmend - realmbgn).c_str();
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                Operator->copyToClipboard(sc.c_str());
#else
                Operator->copyToClipboard(StringUtils::wideToUtf8(sc).c_str());
#endif

                if (isEnabled())
                {
                    // delete
                    core::stringw s;
                    s = Text.subString(0, realmbgn);
                    s.append( Text.subString(realmend, Text.size()-realmend) );
                    Text = s;

                    CursorPos = realmbgn;
                    newMarkBegin = 0;
                    newMarkEnd = 0;
                    textChanged = true;
                }
            }
            break;

        case KEY_KEY_V:
            if ( !isEnabled() )
                break;

            // paste from the clipboard
            if (Operator)
            {
                const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
                const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

                // add new character
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                const wchar_t* p = Operator->getTextFromClipboard();
#else
                const c8* p = Operator->getTextFromClipboard();
#endif
                if (p)
                {
                    if (MarkBegin == MarkEnd)
                    {
                        // insert text
                        core::stringw s = Text.subString(0, CursorPos);
#ifndef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                        s.append(StringUtils::utf8ToWide(p));
#else
                        s.append(p);
#endif
                        s.append( Text.subString(CursorPos, Text.size()-CursorPos) );

                        if (!Max || s.size()<=Max) // thx to Fish FH for fix
                        {
                            Text = s;
#ifndef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                            s = StringUtils::utf8ToWide(p);
#else
                            s = p;
#endif
                            CursorPos += s.size();
                        }
                    }
                    else
                    {
                        // replace text

                        core::stringw s = Text.subString(0, realmbgn);

#ifndef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                        s.append(StringUtils::utf8ToWide(p));
#else
                        s.append(p);
#endif
                        s.append( Text.subString(realmend, Text.size()-realmend) );

                        if (!Max || s.size()<=Max)  // thx to Fish FH for fix
                        {
                            Text = s;
#ifndef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
                            s = StringUtils::utf8ToWide(p);
#else
                            s = p;
#endif
                            CursorPos = realmbgn + s.size();
                        }
                    }
                }

                newMarkBegin = 0;
                newMarkEnd = 0;
                textChanged = true;
            }
            break;
        case KEY_HOME:
            if (!m_rtl)
            {
                // move/highlight to start of text
                if (event.KeyInput.Shift)
                {
                    newMarkEnd = CursorPos;
                    newMarkBegin = 0;
                    CursorPos = 0;
                }
                else
                {
                    CursorPos = 0;
                    newMarkBegin = 0;
                    newMarkEnd = 0;
                }
            }
            break;
        case KEY_END:
            if (!m_rtl)
            {
                // move/highlight to end of text
                if (event.KeyInput.Shift)
                {
                    newMarkBegin = CursorPos;
                    newMarkEnd = Text.size();
                    CursorPos = 0;
                }
                else
                {
                    CursorPos = Text.size();
                    newMarkBegin = 0;
                    newMarkEnd = 0;
                }
            }
            break;
        default:
            return false;
        }
    }
    // default keyboard handling
    else
    switch(event.KeyInput.Key)
    {
            /*
        case KEY_KEY_Q:
            inputChar(L'\u05DC');
            textChanged = true;
            return true;
        case KEY_KEY_W:
            inputChar(L'\u05DB');
            textChanged = true;
            return true;
        case KEY_KEY_E:
            inputChar(L'\u05DA');
            textChanged = true;
            return true;
        case KEY_KEY_R:
            inputChar(L'\u05D9');
            textChanged = true;
            return true;
        case KEY_KEY_T:
            inputChar(L'\u05D8');
            textChanged = true;
            return true;
        case KEY_KEY_Y:
            inputChar(L'\u05D7');
            textChanged = true;
            return true;
            */

    case KEY_END:
        if (!m_rtl)
        {
            s32 p = Text.size();
            if (WordWrap || MultiLine)
            {
                p = getLineFromPos(CursorPos);
                p = BrokenTextPositions[p] + (s32)BrokenText[p].size();
                if (p > 0 && (Text[p-1] == L'\r' || Text[p-1] == L'\n' ))
                    p-=1;
            }

            if (event.KeyInput.Shift)
            {
                if (MarkBegin == MarkEnd)
                    newMarkBegin = CursorPos;

                newMarkEnd = p;
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }
            CursorPos = p;
            BlinkStartTime = getTime();
        }
        break;
    case KEY_HOME:
        if (!m_rtl)
        {

            s32 p = 0;
            if (WordWrap || MultiLine)
            {
                p = getLineFromPos(CursorPos);
                p = BrokenTextPositions[p];
            }

            if (event.KeyInput.Shift)
            {
                if (MarkBegin == MarkEnd)
                    newMarkBegin = CursorPos;
                newMarkEnd = p;
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }
            CursorPos = p;
            BlinkStartTime = getTime();
        }
        break;
    case KEY_RETURN:
        if (MultiLine)
        {
            inputChar(L'\n');
            return true;
        }
        else
        {
            sendGuiEvent( EGET_EDITBOX_ENTER );
        }
        break;
    case KEY_LEFT:
        if (!m_rtl)
        {
            if (event.KeyInput.Shift)
            {
                if (CursorPos > 0)
                {
                    if (MarkBegin == MarkEnd)
                        newMarkBegin = CursorPos;

                    newMarkEnd = CursorPos-1;
                }
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }

            if (CursorPos > 0) CursorPos--;
            BlinkStartTime = getTime();
        }
        break;

    case KEY_RIGHT:
        if (!m_rtl)
        {
            if (event.KeyInput.Shift)
            {
                if (Text.size() > (u32)CursorPos)
                {
                    if (MarkBegin == MarkEnd)
                        newMarkBegin = CursorPos;

                    newMarkEnd = CursorPos+1;
                }
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }

            if (Text.size() > (u32)CursorPos) CursorPos++;
            BlinkStartTime = getTime();
        }
        break;
    case KEY_UP:
        if (MultiLine || (WordWrap && BrokenText.size() > 1) )
        {
            s32 lineNo = getLineFromPos(CursorPos);
            s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
            if (lineNo > 0)
            {
                s32 cp = CursorPos - BrokenTextPositions[lineNo];
                if ((s32)BrokenText[lineNo-1].size() < cp)
                    CursorPos = BrokenTextPositions[lineNo-1] + (s32)BrokenText[lineNo-1].size()-1;
                else
                    CursorPos = BrokenTextPositions[lineNo-1] + cp;
            }

            if (event.KeyInput.Shift)
            {
                newMarkBegin = mb;
                newMarkEnd = CursorPos;
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }

        }
        else
        {
            return false;
        }
        break;
    case KEY_DOWN:
        if (MultiLine || (WordWrap && BrokenText.size() > 1) )
        {
            s32 lineNo = getLineFromPos(CursorPos);
            s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
            if (lineNo < (s32)BrokenText.size()-1)
            {
                s32 cp = CursorPos - BrokenTextPositions[lineNo];
                if ((s32)BrokenText[lineNo+1].size() < cp)
                    CursorPos = BrokenTextPositions[lineNo+1] + BrokenText[lineNo+1].size()-1;
                else
                    CursorPos = BrokenTextPositions[lineNo+1] + cp;
            }

            if (event.KeyInput.Shift)
            {
                newMarkBegin = mb;
                newMarkEnd = CursorPos;
            }
            else
            {
                newMarkBegin = 0;
                newMarkEnd = 0;
            }

        }
        else
        {
            return false;
        }
        break;

    case KEY_BACK:
        if ( !isEnabled() )
            break;

        if (Text.size())
        {
            core::stringw s;

            if (MarkBegin != MarkEnd)
            {
                // delete marked text
                const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
                const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

                s = Text.subString(0, realmbgn);
                s.append( Text.subString(realmend, Text.size()-realmend) );
                Text = s;

                CursorPos = realmbgn;
            }
            else
            {
                // delete text behind cursor
                if (CursorPos>0)
                    s = Text.subString(0, CursorPos-1);
                else
                    s = L"";
                s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
                Text = s;
                --CursorPos;
            }

            if (CursorPos < 0)
                CursorPos = 0;
            BlinkStartTime = getTime();
            newMarkBegin = 0;
            newMarkEnd = 0;
            textChanged = true;
        }
        break;
    case KEY_DELETE:
        if ( !isEnabled() )
            break;

        if (Text.size() != 0)
        {
            core::stringw s;

            if (MarkBegin != MarkEnd)
            {
                // delete marked text
                const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
                const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;

                s = Text.subString(0, realmbgn);
                s.append( Text.subString(realmend, Text.size()-realmend) );
                Text = s;

                CursorPos = realmbgn;
            }
            else
            {
                // delete text before cursor
                s = Text.subString(0, CursorPos);
                s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) );
                Text = s;
            }

            if (CursorPos > (s32)Text.size())
                CursorPos = (s32)Text.size();

            BlinkStartTime = getTime();
            newMarkBegin = 0;
            newMarkEnd = 0;
            textChanged = true;
        }
        break;

    case KEY_ESCAPE:
    case KEY_TAB:
    case KEY_SHIFT:
    case KEY_F1:
    case KEY_F2:
    case KEY_F3:
    case KEY_F4:
    case KEY_F5:
    case KEY_F6:
    case KEY_F7:
    case KEY_F8:
    case KEY_F9:
    case KEY_F10:
    case KEY_F11:
    case KEY_F12:
    case KEY_F13:
    case KEY_F14:
    case KEY_F15:
    case KEY_F16:
    case KEY_F17:
    case KEY_F18:
    case KEY_F19:
    case KEY_F20:
    case KEY_F21:
    case KEY_F22:
    case KEY_F23:
    case KEY_F24:
        // ignore these keys
        return false;

    default:
        inputChar(event.KeyInput.Char);
        return true;
    }

    // Set new text markers
    setTextMarkers( newMarkBegin, newMarkEnd );

    // break the text if it has changed
    if (textChanged)
    {
        breakText();
        sendGuiEvent(EGET_EDITBOX_CHANGED);
    }

    calculateScrollPos();

#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
    switch(event.KeyInput.Key)
    {
    // If cursor points the surrogate low, send KEY_LEFT event.
    case KEY_UP:
    case KEY_DOWN:
        if (MultiLine || (WordWrap && BrokenText.size() > 1) )
        {
            if (UTF16_IS_SURROGATE_LO(Text[CursorPos]))
            {
                SEvent leftEvent;
                leftEvent = event;
                leftEvent.KeyInput.Key = KEY_LEFT;
                Environment->postEventFromUser(leftEvent);
            }
        }
        break;
    // If cursor points the surrogate low, send a same event.
    case KEY_LEFT:
    case KEY_RIGHT:
    case KEY_DELETE:
        if (UTF16_IS_SURROGATE_LO(Text[CursorPos]))
            Environment->postEventFromUser(event);
        break;
    // If cursor points front of the surrogate high, send a same event.
    case KEY_BACK:
        if (CursorPos > 0)
        {
            if (UTF16_IS_SURROGATE_HI(Text[CursorPos-1]))
                Environment->postEventFromUser(event);
        }
        break;
    default:
        break;
    }
#endif
    return true;
}
Beispiel #16
0
string wordEncoder::getNextChunk(size_t maxLength)
{
	size_t remaining = m_length - m_pos;

	if (remaining == 0)
		return string();

	vmime::string chunk;
	vmime::utility::outputStreamStringAdapter chunkStream(chunk);

	// Simple encoding
	if (m_simple)
	{
		// WARNING! Simple encoding can encode a non-integral number of
		// characters and then may generate incorrectly-formed words!

		if (m_encoding == ENCODING_B64)
		{
			// Here, we have a formula to compute the maximum number of source
			// bytes to encode knowing the maximum number of encoded chars. In
			// Base64 encoding, 3 bytes of input provide 4 bytes of output.
			size_t inputCount =
				std::min(remaining, (maxLength > 1) ? ((maxLength - 1) * 3) / 4 : 1);

			// Encode chunk
			utility::inputStreamStringAdapter in(m_buffer, m_pos, m_pos + inputCount);

			m_encoder->encode(in, chunkStream);
			m_pos += inputCount;
		}
		else // ENCODING_QP
		{
			// Compute exactly how much input bytes are needed to have an output
			// string length of less than 'maxLength' bytes. In Quoted-Printable
			// encoding, encoded bytes take 3 bytes.
			size_t inputCount = 0;
			size_t outputCount = 0;

			while ((inputCount == 0 || outputCount < maxLength) && (inputCount < remaining))
			{
				unsigned char c = m_buffer[m_pos + inputCount];

				inputCount++;
				outputCount += utility::encoder::qpEncoder::RFC2047_getEncodedLength(c);
			}

			// Encode chunk
			utility::inputStreamStringAdapter in(m_buffer, m_pos, m_pos + inputCount);

			m_encoder->encode(in, chunkStream);
			m_pos += inputCount;
		}
	}
	// Fully RFC-compliant encoding
	else
	{
		shared_ptr <charsetConverter> conv = charsetConverter::create(charsets::UTF_8, m_charset);

		size_t inputCount = 0;
		size_t outputCount = 0;
		string encodeBuffer;

		while ((inputCount == 0 || outputCount < maxLength) && (inputCount < remaining))
		{
			// Get the next UTF8 character
			size_t inputCharLength =
				getUTF8CharLength(m_buffer, m_pos + inputCount, m_length);

			string inputChar(m_buffer.begin() + m_pos + inputCount,
				m_buffer.begin() + m_pos + inputCount + inputCharLength);

			// Convert back to original encoding
			string encodeBytes;
			conv->convert(inputChar, encodeBytes);

			encodeBuffer += encodeBytes;

			// Compute number of output bytes
			if (m_encoding == ENCODING_B64)
			{
				outputCount = std::max(static_cast <size_t>(4),
					(encodeBuffer.length() * 4) / 3);
			}
			else // ENCODING_QP
			{
				for (size_t i = 0, n = encodeBytes.length() ; i < n ; ++i)
				{
					unsigned char c = encodeBytes[i];
					outputCount += utility::encoder::qpEncoder::RFC2047_getEncodedLength(c);
				}
			}

			inputCount += inputCharLength;
		}

		// Encode chunk
		utility::inputStreamStringAdapter in(encodeBuffer);

		m_encoder->encode(in, chunkStream);
		m_pos += inputCount;
	}

	return chunk;
}