Esempio n. 1
0
int main()
{
    int i;
    char strEntrada[200000];
    No *Raiz;
    pilha Pilha[10000];
    OP = (No*) malloc(sizeof(No));
    FILE *arq = fopen("string.in", "r");
    fscanf(arq,"%s",strEntrada);

    criaNo('@', &Raiz);
    Raiz = criaGrafo(strEntrada, Raiz);
    DecodificaOperacao(Raiz, Pilha);

    //for(i = 0; i<1; i++)
    while(Fim == 0 && Raiz->c != ':' && Raiz->c != '$')
    {
        OP = pop(Pilha);
        switch (OP->c)
        {
        case 'S':
            if(Verifica(3,Pilha, &Raiz))
            {
                S(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_S++;
                #endif
            }
            break;
        case 'K':
            K(Pilha, &Raiz);
            #ifdef CONT_FLAG
                cont_K++;
            #endif
            break;
        case 'B':
            if(Verifica(3,Pilha, &Raiz))
            {
                B(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_B++;
                #endif
            }
            break;
        case 'b':
            if(Verifica(3,Pilha, &Raiz))
            {
                BL(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_BL++;
                #endif
            }
            break;
        case 'P':
            if(Verifica(3,Pilha, &Raiz))
            {
                CL(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_CL++;
                #endif
            }
            break;
        case 'I':
            I(Pilha, &Raiz);
            #ifdef CONT_FLAG
                cont_I++;
            #endif
            break;
        case 'W':
            if(Verifica(3,Pilha, &Raiz))
            {
                SL(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_SL++;
                #endif
            }
            break;
        case 'C':
            if(Verifica(3,Pilha, &Raiz))
            {
                C(Pilha, &Raiz);
                #ifdef CONT_FLAG
                    cont_C++;
                #endif
            }
            break;
        case 'H': //Hd
            Hd(Pilha, &Raiz);
            break;
        case 'T': //Tl
            Tl(Pilha, &Raiz);
            break;
        case '*':
            MULT(Pilha, &Raiz);
            break;
        case '/':
            DIV(Pilha, &Raiz);
            break;
        case '-':
            SUB(Pilha, &Raiz);
            break;
        case '+':
            ADD(Pilha, &Raiz);
            break;
        case '^':
            POT(Pilha, &Raiz);
            break;
        default:
            Fim = 1;
            break;
        }
    }
    printf("Saida: ");
    printaGrafo(Raiz);
    printf("\n");
    printf("\nChamadas ao GC:%d\n", garbage);

#ifdef CONT_FLAG
    printf("S: %d\n",cont_S);
    printf("K: %d\n",cont_K);
    printf("I: %d\n",cont_I);
    printf("C: %d\n",cont_C);
    printf("B: %d\n",cont_B);
    printf("S': %d\n",cont_SL);
    printf("C': %d\n",cont_CL);
    printf("B': %d\n",cont_BL);
#endif

    return 0;
}
Esempio n. 2
0
File: mac.c Progetto: Mettbrot/vlc
int screen_DrawCursor( demux_sys_t *p_sys, CGPoint *cursor_pos )
{
    int size;
    int tmp1, tmp2, tmp3, tmp4;
    unsigned char *cursor_image;

    screen_data_t *p_data = p_sys->p_data;

    int seed = CGSCurrentCursorSeed();
    if( seed != p_data->cursor_seed )
    {
        p_data->cursor_need_update = 1;

        if( CGSGetGlobalCursorDataSize( p_data->connection, &size )
            != kCGErrorSuccess)
        {
            return VLC_EGENERIC;
        }

        cursor_image = ( unsigned char * )malloc( size );

        if( CGSGetGlobalCursorData( p_data->connection,
                                    cursor_image, &size,
                                    &tmp1,
                                    &p_data->cursor_rect, &p_data->cursor_hot,
                                    &tmp2, &tmp3, &tmp4 )
            != kCGErrorSuccess )
        {
            free( cursor_image );

            return VLC_EGENERIC;
        }

        long int pot_width, pot_height;

        POT( pot_width, p_data->cursor_rect.size.width );
        POT( pot_height, p_data->cursor_rect.size.height );

        p_data->cursor_texture_map_u =
            p_data->cursor_rect.size.width / ( double )pot_width;
        p_data->cursor_texture_map_v =
            p_data->cursor_rect.size.height / ( double )pot_height;

        /* We need transparent image larger than original,
         * use calloc to clear alpha value to 0. */
        char *pot_cursor_image = ( char * )calloc( pot_width * pot_height * 4, sizeof( char ) );
        int width, height;
        char *from, *to;

        width = p_data->cursor_rect.size.width;
        height = p_data->cursor_rect.size.height;

        from = ( char * )cursor_image;
        to = pot_cursor_image;

#ifdef __LITTLE_ENDIAN__
        int y, fromwidth, towidth;

        fromwidth = width * 4;
        towidth = pot_width * 4;

        for( y = height; y; y -- )
        {
            memcpy( to, from, fromwidth );
            to += towidth;
            from += fromwidth;
        }
#else
        int x, y, diff;
        diff = ( pot_width - width ) * 4;
        for( y = height; y; y -- )
        {
            for( x = width; x; x -- )
            {
                to[0] = from[3];
                to[1] = from[2];
                to[2] = from[1];
                to[3] = from[0];

                to += 4;
                from += 4;
            }

            to += diff;
        }
#endif

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, p_data->cursor_texture );
        glTexImage2D( GL_TEXTURE_2D, 0,
                      GL_RGBA8,
                      pot_width, pot_height, 0,
                      GL_RGBA, GL_UNSIGNED_BYTE,
                      pot_cursor_image );

        p_data->cursor_need_update = 0;
        p_data->cursor_seed = seed;

        free( pot_cursor_image );
        free( cursor_image );
    }
    else if( p_data->cursor_need_update )
    {
        return VLC_EGENERIC;
    }

    double x, y;
    double x1, y1, x2, y2;

    x = cursor_pos->x - p_sys->i_left - p_data->cursor_hot.x;
    y = cursor_pos->y - p_sys->i_top - p_data->cursor_hot.y;

    x1 = 2.0 * x / p_data->width - 1.0;
    y1 = 2.0 * y / p_data->height - 1.0;
    x2 = 2.0 * ( x + p_data->cursor_rect.size.width ) / p_data->width - 1.0;
    y2 = 2.0 * ( y + p_data->cursor_rect.size.height ) / p_data->height - 1.0;

    glColor3f( 1.0f, 1.0f, 1.0f );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glBindTexture( GL_TEXTURE_2D, p_data->cursor_texture );
    glBegin( GL_POLYGON );
    glTexCoord2f( 0.0, 0.0 );
    glVertex2f( x1, y1 );
    glTexCoord2f( p_data->cursor_texture_map_u, 0.0 );
    glVertex2f( x2, y1 );
    glTexCoord2f( p_data->cursor_texture_map_u, p_data->cursor_texture_map_v );
    glVertex2f( x2, y2 );
    glTexCoord2f( 0.0, p_data->cursor_texture_map_v );
    glVertex2f( x1, y2 );
    glEnd();
    glDisable( GL_BLEND );
    glDisable( GL_TEXTURE_2D );

    return VLC_SUCCESS;
}