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

📄 util.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
            for (i_child = 0 ; i_child < p_node->i_children ; i_child++)                E_(PlaylistListNode)( p_intf, p_pl,                                      p_node->pp_children[i_child],                                      name, s, i_depth + 1);        }    }}/**************************************************************************** * Seek command parsing handling ****************************************************************************/void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value ){    intf_sys_t     *p_sys = p_intf->p_sys;    vlc_value_t val;    int i_stock = 0;    uint64_t i_length;    int i_value = 0;    int i_relative = 0;#define POSITION_ABSOLUTE 12#define POSITION_REL_FOR 13#define POSITION_REL_BACK 11#define VL_TIME_ABSOLUTE 0#define VL_TIME_REL_FOR 1#define VL_TIME_REL_BACK -1    if( p_sys->p_input )    {        var_Get( p_sys->p_input, "length", &val );        i_length = val.i_time;        while( p_value[0] != '\0' )        {            switch(p_value[0])            {                case '+':                {                    i_relative = VL_TIME_REL_FOR;                    p_value++;                    break;                }                case '-':                {                    i_relative = VL_TIME_REL_BACK;                    p_value++;                    break;                }                case '0': case '1': case '2': case '3': case '4':                case '5': case '6': case '7': case '8': case '9':                {                    i_stock = strtol( p_value , &p_value , 10 );                    break;                }                case '%': /* for percentage ie position */                {                    i_relative += POSITION_ABSOLUTE;                    i_value = i_stock;                    i_stock = 0;                    p_value[0] = '\0';                    break;                }                case ':':                {                    i_value = 60 * (i_value + i_stock) ;                    i_stock = 0;                    p_value++;                    break;                }                case 'h': case 'H': /* hours */                {                    i_value += 3600 * i_stock;                    i_stock = 0;                    /* other characters which are not numbers are not                     * important */                    while( ((p_value[0] < '0') || (p_value[0] > '9'))                           && (p_value[0] != '\0') )                    {                        p_value++;                    }                    break;                }                case 'm': case 'M': case '\'': /* minutes */                {                    i_value += 60 * i_stock;                    i_stock = 0;                    p_value++;                    while( ((p_value[0] < '0') || (p_value[0] > '9'))                           && (p_value[0] != '\0') )                    {                        p_value++;                    }                    break;                }                case 's': case 'S': case '"':  /* seconds */                {                    i_value += i_stock;                    i_stock = 0;                    while( ((p_value[0] < '0') || (p_value[0] > '9'))                           && (p_value[0] != '\0') )                    {                        p_value++;                    }                    break;                }                default:                {                    p_value++;                    break;                }            }        }        /* if there is no known symbol, I consider it as seconds.         * Otherwise, i_stock = 0 */        i_value += i_stock;        switch(i_relative)        {            case VL_TIME_ABSOLUTE:            {                if( (uint64_t)( i_value ) * 1000000 <= i_length )                    val.i_time = (uint64_t)( i_value ) * 1000000;                else                    val.i_time = i_length;                var_Set( p_sys->p_input, "time", val );                msg_Dbg( p_intf, "requested seek position: %dsec", i_value );                break;            }            case VL_TIME_REL_FOR:            {                var_Get( p_sys->p_input, "time", &val );                if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )                {                    val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;                } else                {                    val.i_time = i_length;                }                var_Set( p_sys->p_input, "time", val );                msg_Dbg( p_intf, "requested seek position forward: %dsec", i_value );                break;            }            case VL_TIME_REL_BACK:            {                var_Get( p_sys->p_input, "time", &val );                if( (int64_t)( i_value ) * 1000000 > val.i_time )                {                    val.i_time = 0;                } else                {                    val.i_time = val.i_time - ((uint64_t)( i_value ) * 1000000);                }                var_Set( p_sys->p_input, "time", val );                msg_Dbg( p_intf, "requested seek position backward: %dsec", i_value );                break;            }            case POSITION_ABSOLUTE:            {                val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 ,                                            0.0 ), 100.0 );                var_Set( p_sys->p_input, "position", val );                msg_Dbg( p_intf, "requested seek percent: %d%%", i_value );                break;            }            case POSITION_REL_FOR:            {                var_Get( p_sys->p_input, "position", &val );                val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0,                                             0.0 ) , 100.0 );                var_Set( p_sys->p_input, "position", val );                msg_Dbg( p_intf, "requested seek percent forward: %d%%",                         i_value );                break;            }            case POSITION_REL_BACK:            {                var_Get( p_sys->p_input, "position", &val );                val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0,                                             0.0 ) , 100.0 );                var_Set( p_sys->p_input, "position", val );                msg_Dbg( p_intf, "requested seek percent backward: %d%%",                         i_value );                break;            }            default:            {                msg_Dbg( p_intf, "invalid seek request" );                break;            }        }    }#undef POSITION_ABSOLUTE#undef POSITION_REL_FOR#undef POSITION_REL_BACK#undef VL_TIME_ABSOLUTE#undef VL_TIME_REL_FOR#undef VL_TIME_REL_BACK}/**************************************************************************** * URI Parsing functions ****************************************************************************/int E_(TestURIParam)( char *psz_uri, const char *psz_name ){    char *p = psz_uri;    while( (p = strstr( p, psz_name )) )    {        /* Verify that we are dealing with a post/get argument */        if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')              && p[strlen(psz_name)] == '=' )        {            return VLC_TRUE;        }        p++;    }    return VLC_FALSE;}char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name,                             char *psz_value, int i_value_max ){    char *p = psz_uri;    while( (p = strstr( p, psz_name )) )    {        /* Verify that we are dealing with a post/get argument */        if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')              && p[strlen(psz_name)] == '=' )            break;        p++;    }    if( p )    {        int i_len;        p += strlen( psz_name );        if( *p == '=' ) p++;        if( strchr( p, '&' ) )        {            i_len = strchr( p, '&' ) - p;        }        else        {            /* for POST method */            if( strchr( p, '\n' ) )            {                i_len = strchr( p, '\n' ) - p;                if( i_len && *(p+i_len-1) == '\r' ) i_len--;            }            else            {                i_len = strlen( p );            }        }        i_len = __MIN( i_value_max - 1, i_len );        if( i_len > 0 )        {            strncpy( psz_value, p, i_len );            psz_value[i_len] = '\0';        }        else        {            strncpy( psz_value, "", i_value_max );        }        p += i_len;    }    else    {        strncpy( psz_value, "", i_value_max );    }    return p;}/* Since the resulting string is smaller we can work in place, so it is * permitted to have psz == new. new points to the first word of the * string, the function returns the remaining string. */char *E_(FirstWord)( char *psz, char *new ){    vlc_bool_t b_end;    while( *psz == ' ' )        psz++;    while( *psz != '\0' && *psz != ' ' )    {        if( *psz == '\'' )        {            char c = *psz++;            while( *psz != '\0' && *psz != c )            {                if( *psz == '\\' && psz[1] != '\0' )                    psz++;                *new++ = *psz++;            }            if( *psz == c )                psz++;        }        else        {            if( *psz == '\\' && psz[1] != '\0' )                psz++;            *new++ = *psz++;        }    }    b_end = !*psz;    *new++ = '\0';    if( !b_end )        return psz + 1;    else        return NULL;}/********************************************************************** * MRLParse: parse the MRL, find the MRL string and the options, * create an item with all information in it, and return the item. * return NULL if there is an error. **********************************************************************//* Function analog to FirstWord except that it relies on colon instead * of space to delimit option boundaries. */static char *FirstOption( char *psz, char *new ){    vlc_bool_t b_end, b_start = VLC_TRUE;    while( *psz == ' ' )        psz++;    while( *psz != '\0' && (*psz != ' ' || psz[1] != ':') )    {        if( *psz == '\'' )        {            char c = *psz++;            while( *psz != '\0' && *psz != c )            {                if( *psz == '\\' && psz[1] != '\0' )                    psz++;                *new++ = *psz++;                b_start = VLC_FALSE;            }            if( *psz == c )                psz++;        }        else        {            if( *psz == '\\' && psz[1] != '\0' )                psz++;            *new++ = *psz++;            b_start = VLC_FALSE;        }    }    b_end = !*psz;    if ( !b_start )        while (new[-1] == ' ')            new--;    *new++ = '\0';    if( !b_end )        return psz + 1;    else        return NULL;}playlist_item_t *E_(MRLParse)( intf_thread_t *p_intf, char *_psz,                               char *psz_name ){    char *psz = strdup( _psz );    char *s_mrl = psz;    char *s_temp;    playlist_item_t * p_item = NULL;    /* extract the mrl */    s_temp = FirstOption( s_mrl, s_mrl );    if( s_temp == NULL )    {        s_temp = s_mrl + strlen( s_mrl );    }    p_item = playlist_ItemNew( p_intf, s_mrl, psz_name );    s_mrl = s_temp;    /* now we can take care of the options */    while ( *s_mrl != '\0' )    {        s_temp = FirstOption( s_mrl, s_mrl );        if( s_mrl == '\0' )            break;        if( s_temp == NULL )        {            s_temp = s_mrl + strlen( s_mrl );        }        playlist_ItemAddOption( p_item, s_mrl );        s_mrl = s_temp;    }    free( psz );    return p_item;}/********************************************************************** * RealPath: parse ../, ~ and path stuff **********************************************************************/char *E_(RealPath)( intf_thread_t *p_intf, const char *psz_src ){    char *psz_dir;    char *p;    int i_len = strlen(psz_src);    char sep;#if defined( WIN32 )    sep = '\\';#else    sep = '/';#endif    psz_dir = malloc( i_len + 2 );    strcpy( psz_dir, psz_src );    /* Add a trailing sep to ease the .. step */    psz_dir[i_len] = sep;    psz_dir[i_len + 1] = '\0';#ifdef WIN32    /* Convert all / to native separator */    p = psz_dir;    while( (p = strchr( p, '/' )) != NULL )    {        *p = sep;    }#endif    /* Remove multiple separators and /./ */    p = psz_dir;    while( (p = strchr( p, sep )) != NULL )    {        if( p[1] == sep )            memmove( &p[1], &p[2], strlen(&p[2]) + 1 );        else if( p[1] == '.' && p[2] == sep )            memmove( &p[1], &p[3], strlen(&p[3]) + 1 );        else            p++;    }    if( psz_dir[0] == '~' )    {        char *dir = malloc( strlen(psz_dir)                             + strlen(p_intf->p_vlc->psz_userdir) );        /* This is incomplete : we should also support the ~cmassiot/ syntax. */        sprintf( dir, "%s%s", p_intf->p_vlc->psz_userdir, psz_dir + 1 );        free( psz_dir );        psz_dir = dir;    }    if( strlen(psz_dir) > 2 )    {        /* Fix all .. dir */        p = psz_dir + 3;        while( (p = strchr( p, sep )) != NULL )        {            if( p[-1] == '.' && p[-2] == '.' && p[-3] == sep )            {                char *q;                p[-3] = '\0';                if( (q = strrchr( psz_dir, sep )) != NULL )                {                    memmove( q + 1, p + 1, strlen(p + 1) + 1 );                    p = q + 1;                }                else                {                    memmove( psz_dir, p, strlen(p) + 1 );                    p = psz_dir + 3;                }            }            else                p++;        }    }    /* Remove trailing sep if there are at least 2 sep in the string     * (handles the C:\ stuff) */    p = strrchr( psz_dir, sep );    if( p != NULL && p[1] == '\0' && p != strchr( psz_dir, sep ) )        *p = '\0';    return psz_dir;}

⌨️ 快捷键说明

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