⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpn.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * rpn.c : RPN evaluator for the HTTP Interface ***************************************************************************** * Copyright (C) 2001-2006 the VideoLAN team * $Id: rpn.c 16587 2006-09-10 17:02:54Z sam $ * * Authors: Gildas Bazin <gbazin@netcourrier.com> *          Laurent Aimar <fenrir@via.ecp.fr> *          Christophe Massiot <massiot@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#include "http.h"#include "vlc_url.h"#include "vlc_meta.h"#include "vlc_strings.h"static vlc_object_t *GetVLCObject( intf_thread_t *p_intf,                                   const char *psz_object,                                   vlc_bool_t *pb_need_release ){    intf_sys_t    *p_sys = p_intf->p_sys;    int i_object_type = 0;    vlc_object_t *p_object = NULL;    *pb_need_release = VLC_FALSE;    if( !strcmp( psz_object, "VLC_OBJECT_ROOT" ) )        i_object_type = VLC_OBJECT_ROOT;    else if( !strcmp( psz_object, "VLC_OBJECT_VLC" ) )        p_object = VLC_OBJECT(p_intf->p_vlc);    else if( !strcmp( psz_object, "VLC_OBJECT_INTF" ) )        p_object = VLC_OBJECT(p_intf);    else if( !strcmp( psz_object, "VLC_OBJECT_PLAYLIST" ) )        p_object = VLC_OBJECT(p_sys->p_playlist);    else if( !strcmp( psz_object, "VLC_OBJECT_INPUT" ) )        p_object = VLC_OBJECT(p_sys->p_input);    else if( !strcmp( psz_object, "VLC_OBJECT_VOUT" ) )        i_object_type = VLC_OBJECT_VOUT;    else if( !strcmp( psz_object, "VLC_OBJECT_AOUT" ) )        i_object_type = VLC_OBJECT_AOUT;    else if( !strcmp( psz_object, "VLC_OBJECT_SOUT" ) )        i_object_type = VLC_OBJECT_SOUT;    else        msg_Warn( p_intf, "unknown object type (%s)", psz_object );    if( p_object == NULL && i_object_type )    {        *pb_need_release = VLC_TRUE;        p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );    }    return p_object;}void E_(SSInit)( rpn_stack_t *st ){    st->i_stack = 0;}void E_(SSClean)( rpn_stack_t *st ){    while( st->i_stack > 0 )    {        free( st->stack[--st->i_stack] );    }}void E_(SSPush)( rpn_stack_t *st, const char *s ){    if( st->i_stack < STACK_MAX )    {        st->stack[st->i_stack++] = strdup( s );    }}char *E_(SSPop)( rpn_stack_t *st ){    if( st->i_stack <= 0 )    {        return strdup( "" );    }    else    {        return st->stack[--st->i_stack];    }}int E_(SSPopN)( rpn_stack_t *st, mvar_t  *vars ){    char *name;    char *value;    char *end;    int  i;    name = E_(SSPop)( st );    i = strtol( name, &end, 0 );    if( end == name )    {        value = E_(mvar_GetValue)( vars, name );        i = atoi( value );    }    free( name );    return( i );}void E_(SSPushN)( rpn_stack_t *st, int i ){    char v[12];    snprintf( v, sizeof (v), "%d", i );    E_(SSPush)( st, v );}void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t  *vars,                      rpn_stack_t *st, char *exp ){    intf_sys_t    *p_sys = p_intf->p_sys;    while( exp != NULL && *exp != '\0' )    {        char *p, *s;        /* skip space */        while( *exp == ' ' )        {            exp++;        }        if( *exp == '\'' )        {            /* extract string */            p = E_(FirstWord)( exp, exp );            E_(SSPush)( st, exp );            exp = p;            continue;        }        /* extract token */        p = E_(FirstWord)( exp, exp );        s = exp;        if( p == NULL )        {            exp += strlen( exp );        }        else        {            exp = p;        }        if( *s == '\0' )        {            break;        }        /* 1. Integer function */        if( !strcmp( s, "!" ) )        {            E_(SSPushN)( st, ~E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "^" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) ^ E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "&" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) & E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "|" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) | E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "+" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) + E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "-" ) )        {            int j = E_(SSPopN)( st, vars );            int i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, i - j );        }        else if( !strcmp( s, "*" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) * E_(SSPopN)( st, vars ) );        }        else if( !strcmp( s, "/" ) )        {            int i, j;            j = E_(SSPopN)( st, vars );            i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, j != 0 ? i / j : 0 );        }        else if( !strcmp( s, "%" ) )        {            int i, j;            j = E_(SSPopN)( st, vars );            i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, j != 0 ? i % j : 0 );        }        /* 2. integer tests */        else if( !strcmp( s, "=" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) == E_(SSPopN)( st, vars ) ? -1 : 0 );        }        else if( !strcmp( s, "!=" ) )        {            E_(SSPushN)( st, E_(SSPopN)( st, vars ) != E_(SSPopN)( st, vars ) ? -1 : 0 );        }        else if( !strcmp( s, "<" ) )        {            int j = E_(SSPopN)( st, vars );            int i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, i < j ? -1 : 0 );        }        else if( !strcmp( s, ">" ) )        {            int j = E_(SSPopN)( st, vars );            int i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, i > j ? -1 : 0 );        }        else if( !strcmp( s, "<=" ) )        {            int j = E_(SSPopN)( st, vars );            int i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, i <= j ? -1 : 0 );        }        else if( !strcmp( s, ">=" ) )        {            int j = E_(SSPopN)( st, vars );            int i = E_(SSPopN)( st, vars );            E_(SSPushN)( st, i >= j ? -1 : 0 );        }        /* 3. string functions */        else if( !strcmp( s, "strcat" ) )        {            char *s2 = E_(SSPop)( st );            char *s1 = E_(SSPop)( st );            char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );            strcpy( str, s1 );            strcat( str, s2 );            E_(SSPush)( st, str );            free( s1 );            free( s2 );            free( str );        }        else if( !strcmp( s, "strcmp" ) )        {            char *s2 = E_(SSPop)( st );            char *s1 = E_(SSPop)( st );            E_(SSPushN)( st, strcmp( s1, s2 ) );            free( s1 );            free( s2 );        }        else if( !strcmp( s, "strncmp" ) )        {            int n = E_(SSPopN)( st, vars );            char *s2 = E_(SSPop)( st );            char *s1 = E_(SSPop)( st );            E_(SSPushN)( st, strncmp( s1, s2 , n ) );            free( s1 );            free( s2 );        }        else if( !strcmp( s, "strsub" ) )        {            int n = E_(SSPopN)( st, vars );            int m = E_(SSPopN)( st, vars );            int i_len;            char *s = E_(SSPop)( st );            char *str;            if( n >= m )            {                i_len = n - m + 1;            }            else            {                i_len = 0;            }            str = malloc( i_len + 1 );            memcpy( str, s + m - 1, i_len );            str[ i_len ] = '\0';            E_(SSPush)( st, str );            free( s );            free( str );        }        else if( !strcmp( s, "strlen" ) )        {            char *str = E_(SSPop)( st );            E_(SSPushN)( st, strlen( str ) );            free( str );        }        else if( !strcmp( s, "str_replace" ) )        {            char *psz_to = E_(SSPop)( st );            char *psz_from = E_(SSPop)( st );            char *psz_in = E_(SSPop)( st );            char *psz_in_current = psz_in;            char *psz_out = malloc( strlen(psz_in) * strlen(psz_to) + 1 );            char *psz_out_current = psz_out;            while( (p = strstr( psz_in_current, psz_from )) != NULL )            {                memcpy( psz_out_current, psz_in_current, p - psz_in_current );                psz_out_current += p - psz_in_current;                strcpy( psz_out_current, psz_to );                psz_out_current += strlen(psz_to);                psz_in_current = p + strlen(psz_from);            }            strcpy( psz_out_current, psz_in_current );            psz_out_current += strlen(psz_in_current);            *psz_out_current = '\0';            E_(SSPush)( st, psz_out );            free( psz_to );            free( psz_from );            free( psz_in );            free( psz_out );        }        else if( !strcmp( s, "url_extract" ) )        {            char *url = E_(mvar_GetValue)( vars, "url_value" );            char *name = E_(SSPop)( st );            char value[512];            char *tmp;            E_(ExtractURIValue)( url, name, value, 512 );            decode_URI( value );            tmp = E_(FromUTF8)( p_intf, value );            E_(SSPush)( st, tmp );            free( tmp );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -