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

📄 configuration.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 5 页
字号:
                psz_name = malloc( strlen(p_item->psz_name) + 4 );                if( psz_name == NULL ) continue;                strcpy( psz_name, "no-" );                strcat( psz_name, p_item->psz_name );                p_longopts[i_index].name = psz_name;                p_longopts[i_index].has_arg = no_argument;                p_longopts[i_index].flag = &flag;                p_longopts[i_index].val = 1;                i_index++;            }            /* If item also has a short option, add it */            if( p_item->i_short )            {                pp_shortopts[(int)p_item->i_short] = p_item;                psz_shortopts[i_shortopts] = p_item->i_short;                i_shortopts++;                if( p_item->i_type != CONFIG_ITEM_BOOL )                {                    psz_shortopts[i_shortopts] = ':';                    i_shortopts++;                    if( p_item->i_short == 'v' )                    {                        psz_shortopts[i_shortopts] = ':';                        i_shortopts++;                    }                }            }        }    }    /* We don't need the module list anymore */    vlc_list_release( p_list );    /* Close the longopts and shortopts structures */    memset( &p_longopts[i_index], 0, sizeof(struct option) );    psz_shortopts[i_shortopts] = '\0';    /*     * Parse the command line options     */    opterr = 0;    optind = 1;    while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,                                  p_longopts, &i_index ) ) != EOF )    {        /* A long option has been recognized */        if( i_cmd == 0 )        {            module_config_t *p_conf;            char *psz_name = (char *)p_longopts[i_index].name;            /* Check if we deal with a --nofoo or --no-foo long option */            if( flag ) psz_name += psz_name[2] == '-' ? 3 : 2;            /* Store the configuration option */            p_conf = config_FindConfig( p_this, psz_name );            if( p_conf )            {                /* Check if the option is derecated */                if( p_conf->psz_current )                {                    if( !b_ignore_errors )                    {                        if( p_conf->b_strict )                        {                            fprintf( stderr,                                     "Error: option --%s is deprecated. "                                     "Use --%s instead.\n",                                     p_conf->psz_name, p_conf->psz_current);                            /*free */                            for( i_index = 0; p_longopts[i_index].name; i_index++ )                                free( (char *)p_longopts[i_index].name );                            free( p_longopts );                            free( psz_shortopts );                            return -1;                        }                        fprintf(stderr,                                "Warning: option --%s is deprecated. "                                "You should use --%s instead.\n",                                p_conf->psz_name, p_conf->psz_current);                    }                    psz_name=p_conf->psz_current;                    p_conf = config_FindConfig( p_this, psz_name );                }            switch( p_conf->i_type )            {                case CONFIG_ITEM_STRING:                case CONFIG_ITEM_FILE:                case CONFIG_ITEM_DIRECTORY:                case CONFIG_ITEM_MODULE:                case CONFIG_ITEM_MODULE_LIST:                case CONFIG_ITEM_MODULE_LIST_CAT:                case CONFIG_ITEM_MODULE_CAT:                    config_PutPsz( p_this, psz_name, optarg );                    break;                case CONFIG_ITEM_INTEGER:                    config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));                    break;                case CONFIG_ITEM_FLOAT:                    config_PutFloat( p_this, psz_name, (float)atof(optarg) );                    break;                case CONFIG_ITEM_KEY:                    config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );                    break;                case CONFIG_ITEM_BOOL:                    config_PutInt( p_this, psz_name, !flag );                    break;            }            continue;        }    }    /* A short option has been recognized */    if( pp_shortopts[i_cmd] != NULL )    {        switch( pp_shortopts[i_cmd]->i_type )        {            case CONFIG_ITEM_STRING:            case CONFIG_ITEM_FILE:            case CONFIG_ITEM_DIRECTORY:            case CONFIG_ITEM_MODULE:            case CONFIG_ITEM_MODULE_CAT:            case CONFIG_ITEM_MODULE_LIST:            case CONFIG_ITEM_MODULE_LIST_CAT:                config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg );                break;            case CONFIG_ITEM_INTEGER:                if( i_cmd == 'v' )                {                    if( optarg )                    {                        if( *optarg == 'v' ) /* eg. -vvv */                        {                            i_verbose++;                            while( *optarg == 'v' )                            {                                i_verbose++;                                optarg++;                            }                        }                        else                        {                            i_verbose += atoi( optarg ); /* eg. -v2 */                        }                    }                    else                    {                        i_verbose++; /* -v */                    }                    config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,                                           i_verbose );                }                else                {                    config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,                                           strtol(optarg, 0, 0) );                }                break;            case CONFIG_ITEM_BOOL:                config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 );                break;            }            continue;        }        /* Internal error: unknown option */        if( !b_ignore_errors )        {            fprintf( stderr, "%s: unknown option"                     " or missing mandatory argument ",                     p_this->p_vlc->psz_object_name );            if( optopt )            {                fprintf( stderr, "`-%c'\n", optopt );            }            else            {                fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] );            }            fprintf( stderr, "Try `%s --help' for more information.\n",                             p_this->p_vlc->psz_object_name );            for( i_index = 0; p_longopts[i_index].name; i_index++ )                free( (char *)p_longopts[i_index].name );            free( p_longopts );            free( psz_shortopts );            return -1;        }    }    /* Free allocated resources */    for( i_index = 0; p_longopts[i_index].name; i_index++ )        free( (char *)p_longopts[i_index].name );    free( p_longopts );    free( psz_shortopts );    if( b_ignore_errors ) free( ppsz_argv );    return 0;}/***************************************************************************** * config_GetHomeDir: find the user's home directory. ***************************************************************************** * This function will try by different ways to find the user's home path. * Note that this function is not reentrant, it should be called only once * at the beginning of main where the result will be stored for later use. *****************************************************************************/char *config_GetHomeDir( void ){    char *p_tmp, *p_homedir = NULL;#if defined(HAVE_GETPWUID)    struct passwd *p_pw = NULL;#endif#if defined(WIN32) && !defined(UNDER_CE)    typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,                                               LPSTR );#ifndef CSIDL_FLAG_CREATE#   define CSIDL_FLAG_CREATE 0x8000#endif#ifndef CSIDL_APPDATA#   define CSIDL_APPDATA 0x1A#endif#ifndef SHGFP_TYPE_CURRENT#   define SHGFP_TYPE_CURRENT 0#endif    HINSTANCE shfolder_dll;    SHGETFOLDERPATH SHGetFolderPath ;    /* load the shfolder dll to retrieve SHGetFolderPath */    if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )    {        SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,                                                  _T("SHGetFolderPathA") );        if ( SHGetFolderPath != NULL )        {            p_homedir = (char *)malloc( MAX_PATH );            if( !p_homedir ) return NULL;            /* get the "Application Data" folder for the current user */            if( S_OK == SHGetFolderPath( NULL,                                         CSIDL_APPDATA | CSIDL_FLAG_CREATE,                                         NULL, SHGFP_TYPE_CURRENT,                                         p_homedir ) )            {                FreeLibrary( shfolder_dll );                return p_homedir;            }            free( p_homedir );            p_homedir = NULL;        }        FreeLibrary( shfolder_dll );    }#elif defined(UNDER_CE)#ifndef CSIDL_APPDATA#   define CSIDL_APPDATA 0x1A#endif    wchar_t p_whomedir[MAX_PATH];    /* get the "Application Data" folder for the current user */    if( SHGetSpecialFolderPath( NULL, p_whomedir, CSIDL_APPDATA, 1 ) )    {        p_homedir = (char *)malloc( MAX_PATH );        if( !p_homedir ) return NULL;        sprintf( p_homedir, "%ls", p_whomedir );        return p_homedir;    }#endif#if defined(HAVE_GETPWUID)    if( ( p_pw = getpwuid( getuid() ) ) == NULL )#endif    {        if( ( p_tmp = getenv( "HOME" ) ) == NULL )        {            if( ( p_tmp = getenv( "TMP" ) ) == NULL )            {                p_tmp = "/tmp";            }        }        p_homedir = strdup( p_tmp );    }#if defined(HAVE_GETPWUID)    else    {        p_homedir = strdup( p_pw->pw_dir );    }#endif    return p_homedir;}static int ConfigStringToKey( char *psz_key ){    int i_key = 0;    unsigned int i;    char *psz_parser = strchr( psz_key, '-' );    while( psz_parser && psz_parser != psz_key )    {        for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )        {            if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,                              strlen( vlc_modifiers[i].psz_key_string ) ) )            {                i_key |= vlc_modifiers[i].i_key_code;            }        }        psz_key = psz_parser + 1;        psz_parser = strchr( psz_key, '-' );    }    for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )    {        if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )        {            i_key |= vlc_keys[i].i_key_code;            break;        }    }    return i_key;}static char *ConfigKeyToString( int i_key ){    char *psz_key = malloc( 100 );    char *p;    size_t index;    if ( !psz_key )    {        return NULL;    }    *psz_key = '\0';    p = psz_key;    for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));         index++ )    {        if( i_key & vlc_modifiers[index].i_key_code )        {            p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );        }    }    for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));         index++)    {        if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )        {            p += sprintf( p, "%s", vlc_keys[index].psz_key_string );            break;        }    }    return psz_key;}

⌨️ 快捷键说明

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