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

📄 util.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
                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 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 true;        }        p++;    }    return false;}static char *FindURIValue( char *psz_uri, const char *restrict psz_name,                           size_t *restrict p_len ){    char *p = psz_uri, *end;    size_t len;    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 == NULL )    {        *p_len = 0;        return NULL;    }    p += strlen( psz_name );    if( *p == '=' ) p++;    if( ( end = strchr( p, '\n' ) ) != NULL )    {        /* POST method */        if( ( end > p ) && ( end[-1] == '\r' ) )            end--;        len = end - p;    }    else    {        /* GET method */        if( ( end = strchr( p, '&' ) ) != NULL )            len = end - p;        else            len = strlen( p );    }    *p_len = len;    return p;}char *ExtractURIValue( char *restrict psz_uri,                           const char *restrict psz_name,                           char *restrict psz_buf, size_t bufsize ){    size_t len;    char *psz_value = FindURIValue( psz_uri, psz_name, &len );    char *psz_next;    if( psz_value == NULL )    {        if( bufsize > 0 )            *psz_buf = '\0';        return NULL;    }    psz_next = psz_value + len;    if( len >= bufsize )        len = bufsize - 1;    if( len > 0 )        strncpy( psz_buf, psz_value, len );    if( bufsize > 0 )        psz_buf[len] = '\0';    return psz_next;}char *ExtractURIString( char *restrict psz_uri,                            const char *restrict psz_name ){    size_t len;    char *psz_value = FindURIValue( psz_uri, psz_name, &len );    if( psz_value == NULL )        return NULL;    char *res = malloc( len + 1 );    if( res == NULL )        return NULL;    memcpy( res, psz_value, len );    res[len] = '\0';    return res;}/* 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 *FirstWord( char *psz, char *new ){    bool 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 ){    bool b_end, b_start = 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 = false;            }            if( *psz == c )                psz++;        }        else        {            if( *psz == '\\' && psz[1] != '\0' )                psz++;            *new++ = *psz++;            b_start = false;        }    }    b_end = !*psz;    if ( !b_start )        while (new[-1] == ' ')            new--;    *new++ = '\0';    if( !b_end )        return psz + 1;    else        return NULL;}input_item_t *MRLParse( intf_thread_t *p_intf, char *_psz,                                   char *psz_name ){    char *psz = strdup( _psz );    char *s_mrl = psz;    char *s_temp;    input_item_t * p_input = NULL;    /* extract the mrl */    s_temp = FirstOption( s_mrl, s_mrl );    if( s_temp == NULL )    {        s_temp = s_mrl + strlen( s_mrl );    }    p_input = input_item_New( 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 );        }        input_item_AddOption( p_input, s_mrl );        s_mrl = s_temp;    }    free( psz );    return p_input;}/********************************************************************** * RealPath: parse ../, ~ and path stuff **********************************************************************/char *RealPath( const char *psz_src ){    char *psz_dir;    char *p;    int i_len = strlen(psz_src);    const char sep = DIR_SEP_CHAR;    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';#if (DIR_SEP_CHAR != '/')    /* Convert all / to native separator */    p = psz_dir;    while( (p = strchr( p, '/' )) != NULL )    {        *p = sep;    }#endif    /* FIXME: this could be O(N) rather than O(N²)... */    /* 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;        asprintf( &dir, "%s%s", config_GetHomeDir(), 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 + -