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

📄 rpn.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * rpn.c : RPN evaluator for the HTTP Interface ***************************************************************************** * Copyright (C) 2001-2006 the VideoLAN team * $Id: 712b145d7b8af8c486b249de0be152442221eca1 $ * * 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. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#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,                                   bool *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 = false;    if( !strcmp( psz_object, "VLC_OBJECT_LIBVLC" ) )        p_object = VLC_OBJECT(p_intf->p_libvlc);    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        msg_Warn( p_intf, "unknown object type (%s)", psz_object );    if( p_object == NULL && i_object_type )    {        *pb_need_release = true;        p_object = vlc_object_find( p_intf, i_object_type, FIND_ANYWHERE );    }    return p_object;}void SSInit( rpn_stack_t *st ){    st->i_stack = 0;}void SSClean( rpn_stack_t *st ){    while( st->i_stack > 0 )    {        free( st->stack[--st->i_stack] );    }}void SSPush( rpn_stack_t *st, const char *s ){    if( st->i_stack < STACK_MAX )    {        st->stack[st->i_stack++] = strdup( s );    }}char *SSPop( rpn_stack_t *st ){    if( st->i_stack <= 0 )    {        return strdup( "" );    }    else    {        return st->stack[--st->i_stack];    }}int SSPopN( rpn_stack_t *st, mvar_t  *vars ){    char *name;    char *value;    char *end;    int  i;    name = SSPop( st );    i = strtol( name, &end, 0 );    if( end == name )    {        value = mvar_GetValue( vars, name );        i = atoi( value );    }    free( name );    return( i );}void SSPushN( rpn_stack_t *st, int i ){    char v[12];    snprintf( v, sizeof (v), "%d", i );    SSPush( st, v );}void 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 = FirstWord( exp, exp );            SSPush( st, exp );            exp = p;            continue;        }        /* extract token */        p = FirstWord( exp, exp );        s = exp;        if( p == NULL )        {            exp += strlen( exp );        }        else        {            exp = p;        }        if( *s == '\0' )        {            break;        }        /* 1. Integer function */        if( !strcmp( s, "!" ) )        {            SSPushN( st, ~SSPopN( st, vars ) );        }        else if( !strcmp( s, "^" ) )        {            SSPushN( st, SSPopN( st, vars ) ^ SSPopN( st, vars ) );        }        else if( !strcmp( s, "&" ) )        {            SSPushN( st, SSPopN( st, vars ) & SSPopN( st, vars ) );        }        else if( !strcmp( s, "|" ) )        {            SSPushN( st, SSPopN( st, vars ) | SSPopN( st, vars ) );        }        else if( !strcmp( s, "+" ) )        {            SSPushN( st, SSPopN( st, vars ) + SSPopN( st, vars ) );        }        else if( !strcmp( s, "-" ) )        {            int j = SSPopN( st, vars );            int i = SSPopN( st, vars );            SSPushN( st, i - j );        }        else if( !strcmp( s, "*" ) )        {            SSPushN( st, SSPopN( st, vars ) * SSPopN( st, vars ) );        }        else if( !strcmp( s, "/" ) )        {            int i, j;            j = SSPopN( st, vars );            i = SSPopN( st, vars );            SSPushN( st, j != 0 ? i / j : 0 );        }        else if( !strcmp( s, "%" ) )        {            int i, j;            j = SSPopN( st, vars );            i = SSPopN( st, vars );            SSPushN( st, j != 0 ? i % j : 0 );        }        /* 2. integer tests */        else if( !strcmp( s, "=" ) )        {            SSPushN( st, SSPopN( st, vars ) == SSPopN( st, vars ) ? -1 : 0 );        }        else if( !strcmp( s, "!=" ) )        {            SSPushN( st, SSPopN( st, vars ) != SSPopN( st, vars ) ? -1 : 0 );        }        else if( !strcmp( s, "<" ) )        {            int j = SSPopN( st, vars );            int i = SSPopN( st, vars );            SSPushN( st, i < j ? -1 : 0 );        }        else if( !strcmp( s, ">" ) )        {            int j = SSPopN( st, vars );            int i = SSPopN( st, vars );            SSPushN( st, i > j ? -1 : 0 );        }        else if( !strcmp( s, "<=" ) )        {            int j = SSPopN( st, vars );            int i = SSPopN( st, vars );            SSPushN( st, i <= j ? -1 : 0 );        }        else if( !strcmp( s, ">=" ) )        {            int j = SSPopN( st, vars );            int i = SSPopN( st, vars );            SSPushN( st, i >= j ? -1 : 0 );        }        /* 3. string functions */        else if( !strcmp( s, "strcat" ) )        {            char *s2 = SSPop( st );            char *s1 = SSPop( st );            char *str = malloc( strlen( s1 ) + strlen( s2 ) + 1 );            strcpy( str, s1 );            strcat( str, s2 );            SSPush( st, str );            free( s1 );            free( s2 );            free( str );        }        else if( !strcmp( s, "strcmp" ) )        {            char *s2 = SSPop( st );            char *s1 = SSPop( st );            SSPushN( st, strcmp( s1, s2 ) );            free( s1 );            free( s2 );        }        else if( !strcmp( s, "strncmp" ) )        {            int n = SSPopN( st, vars );            char *s2 = SSPop( st );            char *s1 = SSPop( st );            SSPushN( st, strncmp( s1, s2 , n ) );            free( s1 );            free( s2 );        }        else if( !strcmp( s, "strsub" ) )        {            int n = SSPopN( st, vars );            int m = SSPopN( st, vars );            int i_len;            char *s = 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';            SSPush( st, str );            free( s );            free( str );        }        else if( !strcmp( s, "strlen" ) )        {            char *str = SSPop( st );            SSPushN( st, strlen( str ) );            free( str );        }        else if( !strcmp( s, "str_replace" ) )        {            char *psz_to = SSPop( st );            char *psz_from = SSPop( st );            char *psz_in = 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';            SSPush( st, psz_out );            free( psz_to );            free( psz_from );            free( psz_in );            free( psz_out );        }        else if( !strcmp( s, "url_extract" ) )        {            char *url = mvar_GetValue( vars, "url_value" );            char *name = SSPop( st );            char *value = ExtractURIString( url, name );            if( value != NULL )            {                decode_URI( value );                SSPush( st, value );                free( value );            }            else                SSPush( st, "" );            free( name );        }        else if( !strcmp( s, "url_encode" ) )

⌨️ 快捷键说明

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