Esempio n. 1
0
// odbiera zdarzenia
int HConsole::HandleKey( int key) {
    /* TODO (#1#): Implement HConsole::HandleKey() */
    if (key=='`'||key=='~') {
        m_bOpen=!m_bOpen;
        return 1;
    }


    if (key==SDLK_BACKSPACE) {
        if ( m_iCursorPos ) { // can we suppress safely?

            // suppress last character if cursor is at the last position
            if ( m_iCursorPos == m_iBuferLenght ) {
                m_iCursorPos--;
                m_iBuferLenght--;
                m_szBuffer[m_iCursorPos] = '\0';
            }
            // suppress previous character of current position
            else {
                for ( int j=m_iCursorPos-1; j<m_iBuferLenght-1; j++ ) {
                    m_szBuffer[j] = m_szBuffer[j+1]; // move chars to left
                }
                m_szBuffer[m_iBuferLenght-1] = '\0';
                m_iBuferLenght--;
                m_iCursorPos--;
            }
        }
    }
    if (key==SDLK_RETURN) {
        AddLine(m_szBuffer);
        m_iCursorPos=0;
        m_iBuferLenght=0;
        memset(m_szBuffer,0,CONBUFFSIZE+1);
        return 1;
    }
    if (key==SDLK_DELETE) {
        if ( m_iCursorPos<m_iBuferLenght ) {
            for (int j=m_iCursorPos; j<m_iBuferLenght-1; j++ ) {
                m_szBuffer[j] = m_szBuffer[j+1]; // move chars to left
            }
            m_szBuffer[m_iBuferLenght-1] = '\0';
            m_iBuferLenght--;
        }
        return 1;
    }
    if (key==SDLK_LEFT) {
        if ( m_iCursorPos ) m_iCursorPos--;
        return 1;
    }
    if (key==SDLK_RIGHT) {
        if ( m_iCursorPos<m_iBuferLenght ) m_iCursorPos++;
        return 1;
    }
    if (key==SDLK_HOME) {
        m_iCursorPos = 0;
        return 1;
    }
    if (key==SDLK_END) {
        m_iCursorPos = m_iBuferLenght;
        return 1;
    }

    AddToBuff(key);

    /*  if(key=='r'||key=='R') HTextureManager::GetSingleton().DumpReport();
        if(key=='l'||key=='L') {
        float start=HTimer::GetSingleton().GetCurrentTime();
        HEngineCore::GetSingleton().SetLoadingScreenTitle("I just like this loading screen!");
        HEngineCore::GetSingleton().LoadingScreenUpdate(0);
        while(HTimer::GetSingleton().GetCurrentTime()-start<1000){
        HEngineCore::GetSingleton().LoadingScreenUpdate((HTimer::GetSingleton().GetCurrentTime()-start)/1000);
        }
        HEngineCore::GetSingleton().LoadingScreenUpdate(1);
        }*/
//  printf("Console received \"%s\" key\n",SDL_GetKeyName((SDLKey)key));
}
Esempio n. 2
0
int main(void)
{
	char error = 1;
	char *input;
	char c;
	int32_t a = -1;
	struct wires *tmpWire;
	int str_buff = BUFFER;
	if (!(input = calloc(BUFFER, sizeof(char)))) {
		goto freeinput;
	}
	struct wires *wire;
	if (!(wire = calloc(1, sizeof(struct wires)))) {
		goto freewire;
	}
	struct operation *operations, *curOp, *tmpOp;
	if (!(operations = calloc(1, sizeof(struct operation)))) {
		fprintf(stderr, "Can't allocate operations memory\n");
		goto freemem;
	}
	struct buffer *inBuff, *tmpBuff;
	if (!(inBuff = calloc(1, sizeof(struct buffer)))) {
		fprintf(stderr, "Can't allocate buffer memory\n");
		goto freebuff;
	}
	// Declarations done, now down to work.
	tmpBuff = inBuff;
	// Get input and store in the buffers.
	while ((c = fgetc(stdin)) && !feof(stdin)) {
		if (c == '\n' || feof(stdin)) {
			tmpBuff = AddToBuff(tmpBuff, input);
			memset(input, 0, strlen(input));
		} else {
			input = AddToString(input, &str_buff, c);
		}
	}
	// Iterate at least once over the input
	do {
		// If "a" has a value, wipe everything, give it to "b"
		if ((tmpWire = GetFromWire(wire, "a"))) {
			a = tmpWire->value;
			FreeWires(wire);
			SaveToWire(wire, "b", a);
		} else {
			a = -1; // Flag value.
		}
		curOp = operations;
		// For every buffer, parse it into struct operation.
		for (tmpBuff = inBuff->next; tmpBuff; tmpBuff = tmpBuff->next) {
			tmpOp = calloc(1, sizeof(struct operation));
			curOp->next = tmpOp;
			tmpOp->prev = curOp;
			if (!(curOp = AddOperation(curOp->next, tmpBuff->line))) {
				goto freemem;
			}
		}
		// Then put into wires.
		OperationsToWires(wire, operations);
	} while (a == -1);
	PrintWires(wire);
	FreeWires(wire);
	error = 0; // If executing, no memory errors.
freebuff:
	FreeBuff(inBuff);
freemem:
	free(operations);
freewire:
	free(wire);
freeinput:
	free(input);
	return error;
}
Esempio n. 3
0
/*
 * FormatSel - format selector info
 */
static void FormatSel( char *which, WORD sel, char *buff )
{
    descriptor  desc;
    DWORD       base;
    DWORD       limit;

    buff[ 0 ] = 0;
    _buff = buff;
    GetADescriptor( sel, &desc );
    if( which != NULL ) {
        AddToBuff( "      %s = %04x  ", which, sel );
        if( sel == 0L ) {
            AddToBuff( "********  ********  ****  ****  *   ***    *\n" );
            return;
        }
    } else {
        AddToBuff( " %04x  ", sel );
    }

    base = GET_DESC_BASE( desc );
    limit = GET_DESC_LIMIT( desc );
    AddToBuff( "%08lx  %08lx  ", base, limit );
    if( desc.granularity ) {
        AddToBuff( "page  " );
    } else {
        AddToBuff( "byte  " );
    }
    if( desc.type == 2 ) {
        AddToBuff( "data  " );
    } else {
        AddToBuff( "code  " );
    }
    AddToBuff( "%1d   ", (WORD) desc.dpl );
    if( desc.type == 2 )  {
        AddToBuff( "R" );
        if( desc.writeable_or_readable ) AddToBuff( "/W" );
        else AddToBuff( "  " );
        AddToBuff( "    " );
    } else {
        AddToBuff( "Ex" );
        if( desc.writeable_or_readable ) AddToBuff( "/R" );
        else AddToBuff( "  " );
        AddToBuff( "   " );
    }
    if( desc.big_or_default ) {
        AddToBuff( "Y" );
    } else {
        AddToBuff( " " );
    }

} /* FormatSel */