コード例 #1
0
LoadState
SkFontManager::checkPreData()
{
    LoadState state = load_true;
    SkStream * inStream = openReadStream( SYSTEM_DL_PREDATA_FILE );
    preDataHeader header = { 0, 0, 0 };

    if( !inStream )
    {
        state = load_false;
        goto END0;
    }

    inStream->read( &header, SYSTEM_DL_PREDATA_HEADER_LEN );

    if( header.tag != __key() )
    {
        state = load_false;
        goto END0;
    }

    if( getUpdateVersion() == header.updateVersion )
    {
        state = load_true;
        goto END0;
    }
    else
    {
        state = load_change;
        goto END0;
    }

END0:
    if( inStream )
        SkDELETE( inStream );
    return state;
}
コード例 #2
0
ファイル: bindings.c プロジェクト: dmilith/ekg2-bsd
/*
 * binding_key()
 *
 * analizuje nazwê klawisza i wpisuje akcjê do odpowiedniej mapy.
 *
 * 0/-1.
 */
static int binding_key(struct binding *b, const char *key, int add)
{
    /* debug("Key: %s\n", key); */
    if (!xstrncasecmp(key, ("Alt-"), 4)) {
        unsigned char ch;

#define __key(x, y, z) \
	if (!xstrcasecmp(key + 4, (x))) { \
		b->key = saprintf("Alt-%s", (x)); \
		if (add) { \
			ncurses_binding_map_meta[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \
			if (z) \
				ncurses_binding_map_meta[z] = ncurses_binding_map_meta[y]; \
		} \
		return 0; \
	}

        __key("Enter", 13, 0);
        __key("Backspace", KEY_BACKSPACE, 127);
        __key("Home", KEY_HOME, KEY_FIND);
        __key("End", KEY_END, KEY_SELECT);
        __key("Delete", KEY_DC, 0);
        __key("Insert", KEY_IC, 0);
        __key("Left", KEY_LEFT, 0);
        __key("Right", KEY_RIGHT, 0);
        __key("Up", KEY_UP, 0);
        __key("Down", KEY_DOWN, 0);
        __key("PageUp", KEY_PPAGE, 0);
        __key("PageDown", KEY_NPAGE, 0);

#undef __key

        if (xstrlen(key) != 5)
            return -1;

        ch = xtoupper(key[4]);

        b->key = saprintf(("Alt-%c"), ch);	/* XXX Alt-Ó ??? */

        if (add) {
            ncurses_binding_map_meta[ch] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding)));
            if (xisalpha(ch))
                ncurses_binding_map_meta[xtolower(ch)] = ncurses_binding_map_meta[ch];
        }

        return 0;
    }

    if (!xstrncasecmp(key, ("Ctrl-"), 5)) {
        unsigned char ch;

//		if (xstrlen(key) != 6)
//			return -1;
#define __key(x, y, z) \
	if (!xstrcasecmp(key + 5, (x))) { \
		b->key = saprintf("Ctrl-%s", (x)); \
		if (add) { \
			ncurses_binding_map[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \
			if (z) \
				ncurses_binding_map[z] = ncurses_binding_map[y]; \
		} \
		return 0; \
	}

        __key("Enter", KEY_CTRL_ENTER, 0);
        __key("Escape", KEY_CTRL_ESCAPE, 0);
        __key("Delete", KEY_CTRL_DC, 0);
        __key("Backspace", KEY_CTRL_BACKSPACE, 0);
        __key("Tab", KEY_CTRL_TAB, 0);

#undef __key

        ch = xtoupper(key[5]);
        b->key = saprintf(("Ctrl-%c"), ch);

        if (add) {
            if (xisalpha(ch))
                ncurses_binding_map[ch - 64] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding)));
            else
                return -1;
        }

        return 0;
    }

    if (xtoupper(key[0]) == 'F' && atoi(key + 1)) {
        int f = atoi(key + 1);

        if (f < 1 || f > 63)
            return -1;

        b->key = saprintf(("F%d"), f);

        if (add)
            ncurses_binding_map[KEY_F(f)] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding)));

        return 0;
    }

#define __key(x, y, z) \
	if (!xstrcasecmp(key, (x))) { \
		b->key = xstrdup((x)); \
		if (add) { \
			ncurses_binding_map[y] = LIST_ADD2(&bindings, xmemdup(b, sizeof(struct binding))); \
			if (z) \
				ncurses_binding_map[z] = ncurses_binding_map[y]; \
		} \
		return 0; \
	}

    __key("Enter", 13, 0);
    __key("Escape", 27, 0);
    __key("Home", KEY_HOME, KEY_FIND);
    __key("End", KEY_END, KEY_SELECT);
    __key("Delete", KEY_DC, 0);
    __key("Insert", KEY_IC, 0);
    __key("Backspace", KEY_BACKSPACE, 127);
    __key("Tab", 9, 0);
    __key("Left", KEY_LEFT, 0);
    __key("Right", KEY_RIGHT, 0);
    __key("Up", KEY_UP, 0);
    __key("Down", KEY_DOWN, 0);
    __key("PageUp", KEY_PPAGE, 0);
    __key("PageDown", KEY_NPAGE, 0);

#undef __key

    return -1;
}
コード例 #3
0
bool
SkFontManager::savePreData()
{
    SkStream * inStream = openReadStream( SYSTEM_DL_PREDATA_FILE );
    SkFILEWStream * outStream = NULL;
    preDataHeader header = { 1, __key(), 0 };
    SkString permission;

    if( !inStream )
    {
        setUpdateVersion( 2 );
        header.updateVersion++;
        header.count = mDownloadFonts.numFonts();
        goto SAVE0;
    }
    else
    {
        inStream->read( &header, SYSTEM_DL_PREDATA_HEADER_LEN );

        if( header.tag != __key() )
        {
            header.updateVersion = 1;
            header.tag = __key();
            header.count = mDownloadFonts.numFonts();
            goto SAVE1;
        }

        header.count = mDownloadFonts.numFonts();
        header.updateVersion++;
        if( header.updateVersion >= 0xFFFFFFFE )
            header.updateVersion = 2;
    }

SAVE1:
    SkDELETE( inStream );
    inStream = NULL;

SAVE0:
    outStream = openWriteStream( SYSTEM_DL_PREDATA_FILE );

    if( !outStream )
    {
        if( permission_denied() )
            goto SKIP_ERROR0;
        HyLogef( "outStream is null" );
        goto ERROR0;
    }

    outStream->write( &header, SYSTEM_DL_PREDATA_HEADER_LEN );

    for( uint32_t n = 0 ; n < header.count ; n++ )
    {
        SkFontData * font = mDownloadFonts.getFont( n );
        font->writePreData( outStream );
    }

    SkDELETE( outStream );
    outStream = NULL;

    //setUpdateVersion( header.updateVersion );

    permission.set( SYSTEM_FONT_PERMISSION_SET );
    permission.append( SYSTEM_DL_PREDATA_FILE );
    system( permission.c_str() );

    HyLogi( "Font Configuration Data (%d), saved.", header.updateVersion );
    return true;

SKIP_ERROR0:
    return false;

ERROR0:
    if( outStream )
        SkDELETE( outStream );
    return false;
}
コード例 #4
0
LoadState
SkFontManager::loadPreData( uint32_t * newFontIndex, bool boot )
{
    LoadState state = load_true;
    preDataHeader header = { 0, 0, 0 };
    uint32_t curFontIndex = ( boot == true ? readFontConfig() : getCurrentFontIndex() );
    uint32_t curNewFontIndex = curFontIndex;
    uint32_t numEmbeddedFonts = mEmbeddedFonts.numFonts();
    bool statePass = ( curFontIndex < numEmbeddedFonts ? true : false );
    bool system = ( newFontIndex != NULL ? true : false );
    SkStream * stream = NULL;

    if( openPreDataRead( &stream ) == false )
    {
        if( no_such_file() || permission_denied() )
            goto SKIP_ERROR0;

        HyLogef( "openPreDataRead(%s (%d))", strerror( errno ), errno );
        goto ERROR0;
    }

    stream->read( &header, SYSTEM_DL_PREDATA_HEADER_LEN );

    if( header.tag != __key() )
    {
        HyLogef( "Wrong tag" );
        goto ERROR0;
    }

LOAD_START:
    if( getUpdateVersion() == 0 ) // Boot Load & reload.
    {
        setUpdateVersion( header.updateVersion );

        if( header.count == 0 )
            goto SUCCEED0;

        for( uint32_t n = 0 ; n < header.count ; n++ )
        {
            SkFontData * font = SkNEW( SkFontData );

            if( font )
            {
                font->readPreData( stream );

                if( font->checkCertify( system ) == true )
                {
                    font->loadFont();
                    mDownloadFonts.addFonts( font );
                }
                else
                {
                    if( ( system == true ) && ( statePass == false ) )
                    {
                        if( state != load_restart )
                        {
                            if( ( numEmbeddedFonts + n ) == curFontIndex )
                            {
                                state = load_restart;
                            }
                            else
                            {
                                state = load_change;
                                if( ( numEmbeddedFonts + n ) < curFontIndex )
                                    curNewFontIndex--;
                            }
                        }
                    }
                    else
                    {
                        state = load_change;
                    }

                    font->deleteFiles();
                    SkDELETE( font );
                    font = NULL;
                }
            }
            else
            {
                HyLogef( "SkNEW( SkFontData )" );
                continue;
            }
        }
    }
    else // Fonts change
    {
        if( getUpdateVersion() == header.updateVersion )
        {
            goto SUCCEED0;
        }
        else
        {
            mDownloadFonts.resetFonts();
            setUpdateVersion( 0 );
            goto LOAD_START;
        }
    }

SUCCEED0:
    if( ( system == true ) && ( statePass == false ) )
    {
        switch( state )
        {
        case load_change:
            *newFontIndex = curNewFontIndex;
            break;
        case load_restart:
            *newFontIndex = SYSTEM_DEFAULT_FAMILY_INDEX;
            break;
        default:
            *newFontIndex = curFontIndex;
            break;
        }
    }
    else if( ( system == true ) && ( statePass == true ) )
    {
        *newFontIndex = curFontIndex;
    }

    if( stream )
        SkDELETE( stream );
    return state;

SKIP_ERROR0:
    return load_false;

ERROR0:
    if( stream )
        SkDELETE( stream );
    return load_false;
}