From eb15151705d47d23da844449126cc6b4879f110e Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 Dec 2013 02:02:25 +0100 Subject: Move options/config related files from mpvcore/ to options/ Since m_option.h and options.h are extremely often included, a lot of files have to be changed. Moving path.c/h to options/ is a bit questionable, but since this is mainly about access to config files (which are also handled in options/), it's probably ok. --- audio/decode/ad_lavc.c | 2 +- audio/decode/ad_spdif.c | 2 +- audio/filter/af.c | 4 +- audio/filter/af.h | 2 +- audio/filter/af_bs2b.c | 2 +- audio/filter/af_export.c | 2 +- audio/filter/af_format.c | 2 +- audio/filter/af_lavfi.c | 2 +- audio/filter/af_lavrresample.c | 2 +- audio/filter/af_scaletempo.c | 2 +- audio/out/ao.c | 4 +- audio/out/ao_alsa.c | 4 +- audio/out/ao_coreaudio.c | 2 +- audio/out/ao_dsound.c | 2 +- audio/out/ao_jack.c | 2 +- audio/out/ao_lavc.c | 2 +- audio/out/ao_null.c | 2 +- audio/out/ao_openal.c | 2 +- audio/out/ao_oss.c | 2 +- audio/out/ao_pcm.c | 2 +- audio/out/ao_portaudio.c | 2 +- audio/out/ao_rsound.c | 2 +- audio/out/ao_sdl.c | 2 +- audio/out/ao_sndio.c | 2 +- audio/out/ao_wasapi.c | 2 +- demux/demux.c | 2 +- demux/demux_lavf.c | 4 +- demux/demux_libass.c | 2 +- demux/demux_mkv.c | 2 +- demux/demux_playlist.c | 4 +- demux/demux_raw.c | 2 +- demux/demux_subreader.c | 2 +- demux/mf.c | 2 +- input/input.c | 7 +- input/input.h | 2 +- mpvcore/encode_lavc.c | 2 +- mpvcore/m_config.c | 755 ------------ mpvcore/m_config.h | 216 ---- mpvcore/m_option.c | 2477 ---------------------------------------- mpvcore/m_option.h | 648 ----------- mpvcore/m_property.c | 382 ------- mpvcore/m_property.h | 142 --- mpvcore/options.c | 886 -------------- mpvcore/options.h | 297 ----- mpvcore/parser-cfg.c | 277 ----- mpvcore/parser-cfg.h | 27 - mpvcore/parser-mpcmd.c | 294 ----- mpvcore/parser-mpcmd.h | 33 - mpvcore/path.c | 238 ---- mpvcore/path.h | 75 -- mpvcore/playlist.c | 2 +- mpvcore/playlist_parser.c | 3 +- old-makefile | 14 +- options/m_config.c | 755 ++++++++++++ options/m_config.h | 216 ++++ options/m_option.c | 2477 ++++++++++++++++++++++++++++++++++++++++ options/m_option.h | 648 +++++++++++ options/m_property.c | 382 +++++++ options/m_property.h | 142 +++ options/options.c | 886 ++++++++++++++ options/options.h | 297 +++++ options/parse_commandline.c | 294 +++++ options/parse_commandline.h | 33 + options/parse_configfile.c | 277 +++++ options/parse_configfile.h | 27 + options/path.c | 238 ++++ options/path.h | 75 ++ osdep/path-win.c | 2 +- player/audio.c | 2 +- player/command.c | 8 +- player/configfiles.c | 10 +- player/core.h | 2 +- player/loadfile.c | 10 +- player/lua.c | 6 +- player/main.c | 12 +- player/misc.c | 4 +- player/osd.c | 4 +- player/playloop.c | 4 +- player/screenshot.c | 2 +- player/sub.c | 2 +- player/timeline/tl_cue.c | 2 +- player/timeline/tl_matroska.c | 2 +- player/timeline/tl_mpv_edl.c | 2 +- player/video.c | 4 +- stream/cookies.c | 2 +- stream/resolve/resolve_quvi.c | 2 +- stream/resolve/resolve_quvi9.c | 2 +- stream/stream.c | 6 +- stream/stream_bluray.c | 2 +- stream/stream_cdda.c | 2 +- stream/stream_dvb.c | 4 +- stream/stream_dvd.c | 2 +- stream/stream_dvd.h | 2 +- stream/stream_dvdnav.c | 4 +- stream/stream_file.c | 2 +- stream/stream_lavf.c | 4 +- stream/stream_radio.c | 2 +- stream/stream_rar.c | 2 +- stream/stream_smb.c | 2 +- stream/stream_tv.c | 2 +- stream/stream_vcd.c | 2 +- sub/ass_mp.c | 4 +- sub/dec_sub.c | 2 +- sub/find_subfiles.c | 4 +- sub/osd.c | 2 +- sub/osd.h | 2 +- sub/osd_libass.c | 2 +- sub/sd_ass.c | 2 +- sub/sd_lavc.c | 2 +- sub/sd_spu.c | 2 +- video/decode/dec_video.c | 2 +- video/decode/vd_lavc.c | 4 +- video/filter/vf.c | 6 +- video/filter/vf_crop.c | 4 +- video/filter/vf_delogo.c | 2 +- video/filter/vf_divtc.c | 2 +- video/filter/vf_dlopen.c | 2 +- video/filter/vf_dsize.c | 2 +- video/filter/vf_eq.c | 2 +- video/filter/vf_expand.c | 4 +- video/filter/vf_format.c | 2 +- video/filter/vf_gradfun.c | 2 +- video/filter/vf_hqdn3d.c | 2 +- video/filter/vf_ilpack.c | 2 +- video/filter/vf_lavfi.c | 2 +- video/filter/vf_lavfi.h | 2 +- video/filter/vf_noformat.c | 2 +- video/filter/vf_noise.c | 2 +- video/filter/vf_phase.c | 2 +- video/filter/vf_pp.c | 2 +- video/filter/vf_pullup.c | 2 +- video/filter/vf_rotate.c | 2 +- video/filter/vf_scale.c | 4 +- video/filter/vf_stereo3d.c | 4 +- video/filter/vf_sub.c | 4 +- video/filter/vf_unsharp.c | 2 +- video/filter/vf_vavpp.c | 2 +- video/filter/vf_yadif.c | 2 +- video/image_writer.c | 2 +- video/out/aspect.c | 2 +- video/out/gl_common.c | 4 +- video/out/gl_lcms.c | 4 +- video/out/vo.c | 4 +- video/out/vo.h | 2 +- video/out/vo_corevideo.c | 2 +- video/out/vo_direct3d.c | 4 +- video/out/vo_image.c | 4 +- video/out/vo_lavc.c | 2 +- video/out/vo_opengl.c | 2 +- video/out/vo_opengl_old.c | 2 +- video/out/vo_sdl.c | 2 +- video/out/vo_vdpau.c | 4 +- video/out/vo_x11.c | 2 +- video/out/vo_xv.c | 4 +- video/out/w32_common.c | 2 +- video/out/wayland_common.c | 2 +- video/out/x11_common.c | 2 +- wscript_build.py | 16 +- 158 files changed, 6942 insertions(+), 6942 deletions(-) delete mode 100644 mpvcore/m_config.c delete mode 100644 mpvcore/m_config.h delete mode 100644 mpvcore/m_option.c delete mode 100644 mpvcore/m_option.h delete mode 100644 mpvcore/m_property.c delete mode 100644 mpvcore/m_property.h delete mode 100644 mpvcore/options.c delete mode 100644 mpvcore/options.h delete mode 100644 mpvcore/parser-cfg.c delete mode 100644 mpvcore/parser-cfg.h delete mode 100644 mpvcore/parser-mpcmd.c delete mode 100644 mpvcore/parser-mpcmd.h delete mode 100644 mpvcore/path.c delete mode 100644 mpvcore/path.h create mode 100644 options/m_config.c create mode 100644 options/m_config.h create mode 100644 options/m_option.c create mode 100644 options/m_option.h create mode 100644 options/m_property.c create mode 100644 options/m_property.h create mode 100644 options/options.c create mode 100644 options/options.h create mode 100644 options/parse_commandline.c create mode 100644 options/parse_commandline.h create mode 100644 options/parse_configfile.c create mode 100644 options/parse_configfile.h create mode 100644 options/path.c create mode 100644 options/path.h diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index f972bc581f..8b2c2d1727 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -32,7 +32,7 @@ #include "mpvcore/av_common.h" #include "mpvcore/codecs.h" #include "mpvcore/mp_msg.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/av_opts.h" #include "ad.h" diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index 8c3c7c3ea7..fdc12772b8 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -28,7 +28,7 @@ #include "config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/av_common.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "ad.h" #define OUTBUF_SIZE 65536 diff --git a/audio/filter/af.c b/audio/filter/af.c index e2f712d09e..dfe1666e0a 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -22,8 +22,8 @@ #include #include -#include "mpvcore/m_option.h" -#include "mpvcore/m_config.h" +#include "options/m_option.h" +#include "options/m_config.h" #include "af.h" diff --git a/audio/filter/af.h b/audio/filter/af.h index fb7f2b3b1d..260d4dae7e 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -25,7 +25,7 @@ #include "config.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "audio/format.h" #include "audio/chmap.h" #include "audio/audio.h" diff --git a/audio/filter/af_bs2b.c b/audio/filter/af_bs2b.c index aaada29a74..48df9197dc 100644 --- a/audio/filter/af_bs2b.c +++ b/audio/filter/af_bs2b.c @@ -27,7 +27,7 @@ #include #include "af.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" /// Internal specific data of the filter struct af_bs2b { diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c index d39154755b..bbea56cab9 100644 --- a/audio/filter/af_export.c +++ b/audio/filter/af_export.c @@ -43,7 +43,7 @@ #include "talloc.h" #include "af.h" -#include "mpvcore/path.h" +#include "options/path.h" #define DEF_SZ 512 // default buffer size (in samples) #define SHARED_FILE "mpv-af_export" /* default file name diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c index 552587b56e..17af1c43c9 100644 --- a/audio/filter/af_format.c +++ b/audio/filter/af_format.c @@ -19,7 +19,7 @@ #include -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "audio/format.h" #include "af.h" diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c index ab5b8d5495..e764d4fae8 100644 --- a/audio/filter/af_lavfi.c +++ b/audio/filter/af_lavfi.c @@ -38,7 +38,7 @@ #include "audio/fmt-conversion.h" #include "af.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/av_opts.h" #define IS_LIBAV_FORK (LIBAVFILTER_VERSION_MICRO < 100) diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index 7386c27fa6..65d380e873 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -55,7 +55,7 @@ #endif #include "mpvcore/mp_msg.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/av_opts.h" #include "audio/filter/af.h" #include "audio/fmt-conversion.h" diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c index 960aaf8c2e..c54fe44e36 100644 --- a/audio/filter/af_scaletempo.c +++ b/audio/filter/af_scaletempo.c @@ -39,7 +39,7 @@ #include "mpvcore/mp_common.h" #include "af.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" // Data for specific instances of this filter typedef struct af_scaletempo_s diff --git a/audio/out/ao.c b/audio/out/ao.c index 9c09730ec8..6434949cd9 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -27,8 +27,8 @@ #include "ao.h" #include "audio/format.h" -#include "mpvcore/options.h" -#include "mpvcore/m_config.h" +#include "options/options.h" +#include "options/m_config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/mpv_global.h" diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index b8de922cb9..372b490e9f 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -36,8 +36,8 @@ #include #include "config.h" -#include "mpvcore/options.h" -#include "mpvcore/m_option.h" +#include "options/options.h" +#include "options/m_option.h" #include "mpvcore/mp_msg.h" #define ALSA_PCM_NEW_HW_PARAMS_API diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index d61ce63d01..2fb7976c67 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -39,7 +39,7 @@ #include "ao.h" #include "audio/format.h" #include "osdep/timer.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/mp_ring.h" #include "mpvcore/mp_msg.h" #include "audio/out/ao_coreaudio_properties.h" diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c index ec5e83bd50..1ace4093b4 100644 --- a/audio/out/ao_dsound.c +++ b/audio/out/ao_dsound.c @@ -41,7 +41,7 @@ #include "audio/reorder_ch.h" #include "mpvcore/mp_msg.h" #include "osdep/timer.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" /** \todo use the definitions from the win32 api headers when they define these diff --git a/audio/out/ao_jack.c b/audio/out/ao_jack.c index 8a55a54239..8c54796e2b 100644 --- a/audio/out/ao_jack.c +++ b/audio/out/ao_jack.c @@ -34,7 +34,7 @@ #include "ao.h" #include "audio/format.h" #include "osdep/timer.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/mp_ring.h" diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 3b1bb20de6..713b952229 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -30,7 +30,7 @@ #include "compat/libav.h" #include "config.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/mp_common.h" #include "audio/format.h" #include "audio/fmt-conversion.h" diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c index 14ff16b5d7..282511ae40 100644 --- a/audio/out/ao_null.c +++ b/audio/out/ao_null.c @@ -30,7 +30,7 @@ #include "config.h" #include "osdep/timer.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/mp_msg.h" #include "audio/format.h" #include "ao.h" diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index c126852389..c6c2e9e8b8 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -40,7 +40,7 @@ #include "ao.h" #include "audio/format.h" #include "osdep/timer.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #define MAX_CHANS MP_NUM_CHANNELS #define NUM_BUF 128 diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index 3f37b34b60..9ff7d1a165 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -35,7 +35,7 @@ #include #include "config.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/mp_msg.h" #if HAVE_SYS_SOUNDCARD_H diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c index 1d88fc6665..2a086c549f 100644 --- a/audio/out/ao_pcm.c +++ b/audio/out/ao_pcm.c @@ -30,7 +30,7 @@ #include "talloc.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "audio/format.h" #include "audio/reorder_ch.h" #include "ao.h" diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c index fad1dc12d8..6e3d9680fd 100644 --- a/audio/out/ao_portaudio.c +++ b/audio/out/ao_portaudio.c @@ -26,7 +26,7 @@ #include #include "config.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "audio/format.h" #include "mpvcore/mp_msg.h" #include "mpvcore/mp_ring.h" diff --git a/audio/out/ao_rsound.c b/audio/out/ao_rsound.c index 4340deccba..6bd99030a1 100644 --- a/audio/out/ao_rsound.c +++ b/audio/out/ao_rsound.c @@ -29,7 +29,7 @@ #include "talloc.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "osdep/timer.h" #include "audio/format.h" #include "ao.h" diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c index c2b1c9d947..dd2fb894be 100644 --- a/audio/out/ao_sdl.c +++ b/audio/out/ao_sdl.c @@ -24,7 +24,7 @@ #include "talloc.h" #include "ao.h" #include "mpvcore/mp_msg.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "osdep/timer.h" #include diff --git a/audio/out/ao_sndio.c b/audio/out/ao_sndio.c index cfe0616943..6cf08cd095 100644 --- a/audio/out/ao_sndio.c +++ b/audio/out/ao_sndio.c @@ -22,7 +22,7 @@ #include #include -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/mp_msg.h" #include "audio/format.h" diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c index f1032f1c36..b2ac1f2343 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -30,7 +30,7 @@ #include #include "config.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "mpvcore/m_config.h" #include "audio/format.h" #include "mpvcore/mp_msg.h" diff --git a/demux/demux.c b/demux/demux.c index 7ae9328e3b..626804fcef 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -29,7 +29,7 @@ #include #include "config.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/av_common.h" #include "talloc.h" #include "mpvcore/mp_msg.h" diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 4accb6d8fb..c541f345e1 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -35,7 +35,7 @@ #include "compat/libav.h" #include "config.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/mp_msg.h" #include "mpvcore/av_opts.h" #include "mpvcore/av_common.h" @@ -44,7 +44,7 @@ #include "stream/stream.h" #include "demux.h" #include "stheader.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" #define INITIAL_PROBE_SIZE STREAM_BUFFER_SIZE #define PROBE_BUF_SIZE FFMIN(STREAM_MAX_BUFFER_SIZE, 2 * 1024 * 1024) diff --git a/demux/demux_libass.c b/demux/demux_libass.c index f304757ae3..15e149212b 100644 --- a/demux/demux_libass.c +++ b/demux/demux_libass.c @@ -21,7 +21,7 @@ #include #include -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/mp_msg.h" #include "mpvcore/charset_conv.h" #include "stream/stream.h" diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 94af8bf6b9..b3cf253be5 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -42,7 +42,7 @@ #endif #include "talloc.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/bstr.h" #include "stream/stream.h" #include "demux.h" diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index dc42c2ea1f..1a4882f92b 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -16,10 +16,10 @@ */ #include "mpvcore/mp_common.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/mp_msg.h" #include "mpvcore/playlist.h" -#include "mpvcore/path.h" +#include "options/path.h" #include "stream/stream.h" #include "demux.h" diff --git a/demux/demux_raw.c b/demux/demux_raw.c index ecabd2e714..12fa1741a8 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -23,7 +23,7 @@ #include #include -#include "mpvcore/m_option.h" +#include "options/m_option.h" #include "stream/stream.h" #include "demux.h" diff --git a/demux/demux_subreader.c b/demux/demux_subreader.c index 21bcf21614..a3cee1794b 100644 --- a/demux/demux_subreader.c +++ b/demux/demux_subreader.c @@ -34,7 +34,7 @@ #include "config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/mp_common.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "stream/stream.h" #include "demux/demux.h" diff --git a/demux/mf.c b/demux/mf.c index 443e2e411b..7b5b7aee3e 100644 --- a/demux/mf.c +++ b/demux/mf.c @@ -39,7 +39,7 @@ #include "talloc.h" #include "mpvcore/mp_msg.h" #include "stream/stream.h" -#include "mpvcore/path.h" +#include "options/path.h" #include "mpvcore/mp_talloc.h" #include "mf.h" diff --git a/input/input.c b/input/input.c index c7b27240c7..4d2c873211 100644 --- a/input/input.c +++ b/input/input.c @@ -43,11 +43,10 @@ #include "osdep/timer.h" #include "mpvcore/mp_msg.h" #include "mpvcore/mpv_global.h" -#include "mpvcore/m_config.h" -#include "mpvcore/m_option.h" -#include "mpvcore/path.h" +#include "options/m_option.h" +#include "options/path.h" #include "talloc.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "mpvcore/bstr.h" #include "stream/stream.h" #include "mpvcore/mp_common.h" diff --git a/input/input.h b/input/input.h index 1698c9cf9f..43c5742cf6 100644 --- a/input/input.h +++ b/input/input.h @@ -21,7 +21,7 @@ #include #include "mpvcore/bstr.h" -#include "mpvcore/m_option.h" +#include "options/m_option.h" // All command IDs enum mp_command_type { diff --git a/mpvcore/encode_lavc.c b/mpvcore/encode_lavc.c index d2017a7f37..0ea4be486a 100644 --- a/mpvcore/encode_lavc.c +++ b/mpvcore/encode_lavc.c @@ -25,7 +25,7 @@ #include "encode_lavc.h" #include "mpvcore/mp_msg.h" #include "video/vfcap.h" -#include "mpvcore/options.h" +#include "options/options.h" #include "osdep/timer.h" #include "video/out/vo.h" #include "talloc.h" diff --git a/mpvcore/m_config.c b/mpvcore/m_config.c deleted file mode 100644 index 203796055f..0000000000 --- a/mpvcore/m_config.c +++ /dev/null @@ -1,755 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer 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. - * - * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/// \file -/// \ingroup Config - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "talloc.h" - -#include "m_config.h" -#include "mpvcore/m_option.h" -#include "mpvcore/mp_msg.h" - -static const union m_option_value default_value; - -// Profiles allow to predefine some sets of options that can then -// be applied later on with the internal -profile option. -#define MAX_PROFILE_DEPTH 20 - -struct m_profile { - struct m_profile *next; - char *name; - char *desc; - int num_opts; - // Option/value pair array. - char **opts; -}; - -// In the file local case, this contains the old global value. -struct m_opt_backup { - struct m_opt_backup *next; - struct m_config_option *co; - void *backup; -}; - -static int parse_include(struct m_config *config, struct bstr param, bool set, - int flags) -{ - if (param.len == 0) - return M_OPT_MISSING_PARAM; - if (!set) - return 1; - char *filename = bstrdup0(NULL, param); - config->includefunc(config, filename, flags); - talloc_free(filename); - return 1; -} - -static int parse_profile(struct m_config *config, const struct m_option *opt, - struct bstr name, struct bstr param, bool set, int flags) -{ - if (!bstrcmp0(param, "help")) { - struct m_profile *p; - if (!config->profiles) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, - "No profiles have been defined.\n"); - return M_OPT_EXIT - 1; - } - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available profiles:\n"); - for (p = config->profiles; p; p = p->next) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n", p->name, - p->desc ? p->desc : ""); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT - 1; - } - - char **list = NULL; - int r = m_option_type_string_list.parse(opt, name, param, &list); - if (r < 0) - return r; - if (!list || !list[0]) - return M_OPT_INVALID; - for (int i = 0; list[i]; i++) { - struct m_profile *p = m_config_get_profile0(config, list[i]); - if (!p) { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Unknown profile '%s'.\n", - list[i]); - r = M_OPT_INVALID; - } else if (set) - m_config_set_profile(config, p, flags); - } - m_option_free(opt, &list); - return r; -} - -static int show_profile(struct m_config *config, bstr param) -{ - struct m_profile *p; - int i, j; - if (!param.len) - return M_OPT_MISSING_PARAM; - if (!(p = m_config_get_profile(config, param))) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown profile '%.*s'.\n", - BSTR_P(param)); - return M_OPT_EXIT - 1; - } - if (!config->profile_depth) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Profile %s: %s\n", p->name, - p->desc ? p->desc : ""); - config->profile_depth++; - for (i = 0; i < p->num_opts; i++) { - char spc[config->profile_depth + 1]; - for (j = 0; j < config->profile_depth; j++) - spc[j] = ' '; - spc[config->profile_depth] = '\0'; - - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc, - p->opts[2 * i], p->opts[2 * i + 1]); - - if (config->profile_depth < MAX_PROFILE_DEPTH - && !strcmp(p->opts[2*i], "profile")) { - char *e, *list = p->opts[2 * i + 1]; - while ((e = strchr(list, ','))) { - int l = e - list; - char tmp[l+1]; - if (!l) - continue; - memcpy(tmp, list, l); - tmp[l] = '\0'; - show_profile(config, bstr0(tmp)); - list = e + 1; - } - if (list[0] != '\0') - show_profile(config, bstr0(list)); - } - } - config->profile_depth--; - if (!config->profile_depth) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - return M_OPT_EXIT - 1; -} - -static int list_options(struct m_config *config) -{ - m_config_print_option_list(config); - return M_OPT_EXIT; -} - -// The memcpys are supposed to work around the strict aliasing violation, -// that would result if we just dereferenced a void** (where the void** is -// actually casted from struct some_type* ). -static void *substruct_read_ptr(const void *ptr) -{ - void *res; - memcpy(&res, ptr, sizeof(void*)); - return res; -} -static void substruct_write_ptr(void *ptr, void *val) -{ - memcpy(ptr, &val, sizeof(void*)); -} - -static void add_options(struct m_config *config, - const char *parent_name, - void *optstruct, - const void *optstruct_def, - const struct m_option *defs); - -static void config_destroy(void *p) -{ - struct m_config *config = p; - m_config_restore_backups(config); - for (int n = 0; n < config->num_opts; n++) - m_option_free(config->opts[n].opt, config->opts[n].data); -} - -struct m_config *m_config_new(void *talloc_ctx, size_t size, - const void *defaults, - const struct m_option *options) -{ - struct m_config *config = talloc(talloc_ctx, struct m_config); - talloc_set_destructor(config, config_destroy); - *config = (struct m_config) {0}; - // size==0 means a dummy object is created - if (size) { - config->optstruct = talloc_zero_size(config, size); - if (defaults) - memcpy(config->optstruct, defaults, size); - } - if (options) - add_options(config, "", config->optstruct, defaults, options); - return config; -} - -struct m_config *m_config_from_obj_desc(void *talloc_ctx, - struct m_obj_desc *desc) -{ - return m_config_new(talloc_ctx, desc->priv_size, desc->priv_defaults, - desc->options); -} - -// Like m_config_from_obj_desc(), but don't allocate option struct. -struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, - struct m_obj_desc *desc) -{ - return m_config_new(talloc_ctx, 0, desc->priv_defaults, desc->options); -} - -int m_config_set_obj_params(struct m_config *conf, char **args) -{ - for (int n = 0; args && args[n * 2 + 0]; n++) { - int r = m_config_set_option(conf, bstr0(args[n * 2 + 0]), - bstr0(args[n * 2 + 1])); - if (r < 0) - return r; - } - return 0; -} - -int m_config_apply_defaults(struct m_config *config, const char *name, - struct m_obj_settings *defaults) -{ - int r = 0; - for (int n = 0; defaults && defaults[n].name; n++) { - struct m_obj_settings *entry = &defaults[n]; - if (name && strcmp(entry->name, name) == 0) { - r = m_config_set_obj_params(config, entry->attribs); - break; - } - } - return r; -} - -static void ensure_backup(struct m_config *config, struct m_config_option *co) -{ - if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) - return; - if (co->opt->flags & M_OPT_GLOBAL) - return; - if (!co->data) - return; - for (struct m_opt_backup *cur = config->backup_opts; cur; cur = cur->next) { - if (cur->co->data == co->data) // comparing data ptr catches aliases - return; - } - struct m_opt_backup *bc = talloc_ptrtype(NULL, bc); - *bc = (struct m_opt_backup) { - .co = co, - .backup = talloc_zero_size(bc, co->opt->type->size), - }; - m_option_copy(co->opt, bc->backup, co->data); - bc->next = config->backup_opts; - config->backup_opts = bc; -} - -void m_config_restore_backups(struct m_config *config) -{ - while (config->backup_opts) { - struct m_opt_backup *bc = config->backup_opts; - config->backup_opts = bc->next; - - m_option_copy(bc->co->opt, bc->co->data, bc->backup); - m_option_free(bc->co->opt, bc->backup); - talloc_free(bc); - } -} - -void m_config_backup_opt(struct m_config *config, const char *opt) -{ - struct m_config_option *co = m_config_get_co(config, bstr0(opt)); - if (co) { - ensure_backup(config, co); - } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s not found.\n", opt); - } -} - -void m_config_backup_all_opts(struct m_config *config) -{ - for (int n = 0; n < config->num_opts; n++) - ensure_backup(config, &config->opts[n]); -} - -// Given an option --opt, add --no-opt (if applicable). -static void add_negation_option(struct m_config *config, - struct m_config_option *orig, - const char *parent_name) -{ - const struct m_option *opt = orig->opt; - int value; - if (opt->type == CONF_TYPE_FLAG) { - value = opt->min; - } else if (opt->type == CONF_TYPE_CHOICE) { - // Find out whether there's a "no" choice. - // m_option_parse() should be used for this, but it prints - // unsilenceable error messages. - struct m_opt_choice_alternatives *alt = opt->priv; - for ( ; alt->name; alt++) { - if (strcmp(alt->name, "no") == 0) - break; - } - if (!alt->name) - return; - value = alt->value; - } else { - return; - } - struct m_option *no_opt = talloc_ptrtype(config, no_opt); - *no_opt = (struct m_option) { - .name = opt->name, - .type = CONF_TYPE_STORE, - .flags = opt->flags & (M_OPT_NOCFG | M_OPT_GLOBAL | M_OPT_PRE_PARSE), - .is_new_option = opt->is_new_option, - .p = opt->p, - .offset = opt->offset, - .max = value, - }; - // Add --no-sub-opt - struct m_config_option co = *orig; - co.name = talloc_asprintf(config, "no-%s", orig->name); - co.opt = no_opt; - co.is_generated = true; - MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - // Add --sub-no-opt (unfortunately needed for: "--sub=...:no-opt") - if (parent_name[0]) { - co.name = talloc_asprintf(config, "%s-no-%s", parent_name, opt->name); - MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - } -} - -static void m_config_add_option(struct m_config *config, - const char *parent_name, - void *optstruct, - const void *optstruct_def, - const struct m_option *arg); - -static void add_options(struct m_config *config, - const char *parent_name, - void *optstruct, - const void *optstruct_def, - const struct m_option *defs) -{ - for (int i = 0; defs && defs[i].name; i++) - m_config_add_option(config, parent_name, optstruct, optstruct_def, &defs[i]); -} - -static void m_config_add_option(struct m_config *config, - const char *parent_name, - void *optstruct, - const void *optstruct_def, - const struct m_option *arg) -{ - assert(config != NULL); - assert(arg != NULL); - - struct m_config_option co = { - .opt = arg, - .name = arg->name, - }; - - if (arg->is_new_option) { - if (optstruct) - co.data = (char *)optstruct + arg->offset; - if (optstruct_def) - co.default_data = (char *)optstruct_def + arg->offset; - } else { - co.data = arg->p; - co.default_data = arg->p; - } - - if (arg->defval) - co.default_data = arg->defval; - - if (!co.default_data) - co.default_data = &default_value; - - // Fill in the full name - if (!co.name[0]) { - co.name = parent_name; - } else if (parent_name[0]) { - co.name = talloc_asprintf(config, "%s-%s", parent_name, co.name); - } - - // Option with children -> add them - if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) { - if (arg->type->flags & M_OPT_TYPE_USE_SUBSTRUCT) { - const struct m_sub_options *subopts = arg->priv; - - void *new_optstruct = NULL; - if (co.data) { - new_optstruct = m_config_alloc_struct(config, subopts); - substruct_write_ptr(co.data, new_optstruct); - } - - const void *new_optstruct_def = substruct_read_ptr(co.default_data); - if (!new_optstruct_def) - new_optstruct_def = subopts->defaults; - - add_options(config, co.name, new_optstruct, - new_optstruct_def, subopts->opts); - } else { - const struct m_option *sub = arg->p; - add_options(config, co.name, optstruct, optstruct_def, sub); - } - } else { - // Initialize options - if (co.data && co.default_data) { - if (arg->type->flags & M_OPT_TYPE_DYNAMIC) { - // Would leak memory by overwriting *co.data repeatedly. - for (int i = 0; i < config->num_opts; i++) { - if (co.data == config->opts[i].data) - assert(0); - } - } - // In case this is dynamic data, it has to be allocated and copied. - union m_option_value temp = {0}; - memcpy(&temp, co.default_data, arg->type->size); - memset(co.data, 0, arg->type->size); - m_option_copy(arg, co.data, &temp); - } - } - - if (arg->name[0]) // no own name -> hidden - MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - - add_negation_option(config, &co, parent_name); -} - -struct m_config_option *m_config_get_co(const struct m_config *config, - struct bstr name) -{ - - for (int n = 0; n < config->num_opts; n++) { - struct m_config_option *co = &config->opts[n]; - struct bstr coname = bstr0(co->name); - if ((co->opt->type->flags & M_OPT_TYPE_ALLOW_WILDCARD) - && bstr_endswith0(coname, "*")) { - coname.len--; - if (bstrcmp(bstr_splice(name, 0, coname.len), coname) == 0) - return co; - } else if (bstrcmp(coname, name) == 0) - return co; - } - return NULL; -} - -const char *m_config_get_positional_option(const struct m_config *config, int p) -{ - int pos = 0; - for (int n = 0; n < config->num_opts; n++) { - struct m_config_option *co = &config->opts[n]; - if (!co->is_generated) { - if (pos == p) - return co->name; - pos++; - } - } - return NULL; -} - -static int parse_subopts(struct m_config *config, char *name, char *prefix, - struct bstr param, int flags); - -static int m_config_parse_option(struct m_config *config, struct bstr name, - struct bstr param, int flags) -{ - assert(config != NULL); - assert(name.len != 0); - bool set = !(flags & M_SETOPT_CHECK_ONLY); - - struct m_config_option *co = m_config_get_co(config, name); - if (!co) - return M_OPT_UNKNOWN; - - // This is the only mandatory function - assert(co->opt->type->parse); - - if ((flags & M_SETOPT_PRE_PARSE_ONLY) && !(co->opt->flags & M_OPT_PRE_PARSE)) - return 0; - - if ((flags & M_SETOPT_PRESERVE_CMDLINE) && co->is_set_from_cmdline) - set = false; - - // Check if this option isn't forbidden in the current mode - if ((flags & M_SETOPT_FROM_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option can't be used in a config file.\n", - BSTR_P(name)); - return M_OPT_INVALID; - } - if (flags & M_SETOPT_BACKUP) { - if (co->opt->flags & M_OPT_GLOBAL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option is global and can't be set per-file.\n", - BSTR_P(name)); - return M_OPT_INVALID; - } - if (set) - ensure_backup(config, co); - } - - if (config->includefunc && bstr_equals0(name, "include")) - return parse_include(config, param, set, flags); - if (config->use_profiles && bstr_equals0(name, "profile")) - return parse_profile(config, co->opt, name, param, set, flags); - if (config->use_profiles && bstr_equals0(name, "show-profile")) - return show_profile(config, param); - if (bstr_equals0(name, "list-options")) - return list_options(config); - - // Option with children are a bit different to parse - if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) { - char prefix[110]; - assert(strlen(co->name) < 100); - sprintf(prefix, "%s-", co->name); - return parse_subopts(config, (char *)co->name, prefix, param, flags); - } - - int r = m_option_parse(co->opt, name, param, set ? co->data : NULL); - - if (r >= 0 && set && (flags & M_SETOPT_FROM_CMDLINE)) { - co->is_set_from_cmdline = true; - // Mark aliases too - if (co->data) { - for (int n = 0; n < config->num_opts; n++) { - struct m_config_option *co2 = &config->opts[n]; - if (co2->data == co->data) - co2->is_set_from_cmdline = true; - } - } - } - - return r; -} - -static int parse_subopts(struct m_config *config, char *name, char *prefix, - struct bstr param, int flags) -{ - char **lst = NULL; - // Split the argument into child options - int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, &lst); - if (r < 0) - return r; - // Parse the child options - for (int i = 0; lst && lst[2 * i]; i++) { - // Build the full name - char n[110]; - if (snprintf(n, 110, "%s%s", prefix, lst[2 * i]) > 100) - abort(); - r = m_config_parse_option(config,bstr0(n), bstr0(lst[2 * i + 1]), flags); - if (r < 0) { - if (r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Error parsing suboption %s/%s (%s)\n", - name, lst[2 * i], m_option_strerror(r)); - r = M_OPT_INVALID; - } - break; - } - } - talloc_free(lst); - return r; -} - -int m_config_parse_suboptions(struct m_config *config, char *name, - char *subopts) -{ - if (!subopts || !*subopts) - return 0; - int r = parse_subopts(config, name, "", bstr0(subopts), 0); - if (r < 0 && r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing suboption %s (%s)\n", - name, m_option_strerror(r)); - r = M_OPT_INVALID; - } - return r; -} - -int m_config_set_option_ext(struct m_config *config, struct bstr name, - struct bstr param, int flags) -{ - int r = m_config_parse_option(config, name, param, flags); - if (r < 0 && r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing option %.*s (%s)\n", - BSTR_P(name), m_option_strerror(r)); - r = M_OPT_INVALID; - } - return r; -} - -int m_config_set_option(struct m_config *config, struct bstr name, - struct bstr param) -{ - return m_config_set_option_ext(config, name, param, 0); -} - -const struct m_option *m_config_get_option(const struct m_config *config, - struct bstr name) -{ - assert(config != NULL); - - struct m_config_option *co = m_config_get_co(config, name); - return co ? co->opt : NULL; -} - -int m_config_option_requires_param(struct m_config *config, bstr name) -{ - const struct m_option *opt = m_config_get_option(config, name); - if (opt) { - if (bstr_endswith0(name, "-clr")) - return 0; - return m_option_required_params(opt); - } - return M_OPT_UNKNOWN; -} - -void m_config_print_option_list(const struct m_config *config) -{ - char min[50], max[50]; - int count = 0; - const char *prefix = config->is_toplevel ? "--" : ""; - - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Options:\n\n"); - for (int i = 0; i < config->num_opts; i++) { - struct m_config_option *co = &config->opts[i]; - const struct m_option *opt = co->opt; - if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) - continue; - if (co->is_generated) - continue; - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s%-30.30s", prefix, co->name); - if (opt->type == &m_option_type_choice) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " Choices:"); - struct m_opt_choice_alternatives *alt = opt->priv; - for (int n = 0; alt[n].name; n++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", alt[n].name); - if (opt->flags & (M_OPT_MIN | M_OPT_MAX)) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (or an integer)"); - } else { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", co->opt->type->name); - } - if (opt->flags & (M_OPT_MIN | M_OPT_MAX)) { - snprintf(min, sizeof(min), "any"); - snprintf(max, sizeof(max), "any"); - if (opt->flags & M_OPT_MIN) - snprintf(min, sizeof(min), "%.14g", opt->min); - if (opt->flags & M_OPT_MAX) - snprintf(max, sizeof(max), "%.14g", opt->max); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (%s to %s)", min, max); - } - char *def = NULL; - if (co->default_data) - def = m_option_print(co->opt, co->default_data); - if (def) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (default: %s)", def); - talloc_free(def); - } - if (opt->flags & CONF_GLOBAL) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [global]"); - if (opt->flags & CONF_NOCFG) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [nocfg]"); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); - count++; - } - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d options\n", count); -} - -struct m_profile *m_config_get_profile(const struct m_config *config, bstr name) -{ - for (struct m_profile *p = config->profiles; p; p = p->next) { - if (bstr_equals0(name, p->name)) - return p; - } - return NULL; -} - -struct m_profile *m_config_get_profile0(const struct m_config *config, - char *name) -{ - return m_config_get_profile(config, bstr0(name)); -} - -struct m_profile *m_config_add_profile(struct m_config *config, char *name) -{ - struct m_profile *p = m_config_get_profile0(config, name); - if (p) - return p; - p = talloc_zero(config, struct m_profile); - p->name = talloc_strdup(p, name); - p->next = config->profiles; - config->profiles = p; - return p; -} - -void m_profile_set_desc(struct m_profile *p, bstr desc) -{ - talloc_free(p->desc); - p->desc = bstrdup0(p, desc); -} - -int m_config_set_profile_option(struct m_config *config, struct m_profile *p, - bstr name, bstr val) -{ - int i = m_config_set_option_ext(config, name, val, - M_SETOPT_CHECK_ONLY | - M_SETOPT_FROM_CONFIG_FILE); - if (i < 0) - return i; - p->opts = talloc_realloc(p, p->opts, char *, 2 * (p->num_opts + 2)); - p->opts[p->num_opts * 2] = bstrdup0(p, name); - p->opts[p->num_opts * 2 + 1] = bstrdup0(p, val); - p->num_opts++; - p->opts[p->num_opts * 2] = p->opts[p->num_opts * 2 + 1] = NULL; - return 1; -} - -void m_config_set_profile(struct m_config *config, struct m_profile *p, - int flags) -{ - if (config->profile_depth > MAX_PROFILE_DEPTH) { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "WARNING: Profile inclusion too deep.\n"); - return; - } - config->profile_depth++; - for (int i = 0; i < p->num_opts; i++) { - m_config_set_option_ext(config, - bstr0(p->opts[2 * i]), - bstr0(p->opts[2 * i + 1]), - flags | M_SETOPT_FROM_CONFIG_FILE); - } - config->profile_depth--; -} - -void *m_config_alloc_struct(void *talloc_ctx, - const struct m_sub_options *subopts) -{ - void *substruct = talloc_zero_size(talloc_ctx, subopts->size); - if (subopts->defaults) - memcpy(substruct, subopts->defaults, subopts->size); - return substruct; -} diff --git a/mpvcore/m_config.h b/mpvcore/m_config.h deleted file mode 100644 index 8a8865d68e..0000000000 --- a/mpvcore/m_config.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer 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. - * - * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_M_CONFIG_H -#define MPLAYER_M_CONFIG_H - -#include -#include - -#include "mpvcore/bstr.h" - -// m_config provides an API to manipulate the config variables in MPlayer. -// It makes use of the Options API to provide a context stack that -// allows saving and later restoring the state of all variables. - -typedef struct m_profile m_profile_t; -struct m_option; -struct m_option_type; -struct m_sub_options; -struct m_obj_desc; -struct m_obj_settings; - -// Config option -struct m_config_option { - bool is_generated : 1; // Automatically added ("no-" options) - bool is_set_from_cmdline : 1; // Set by user from command line - const char *name; // Full name (ie option-subopt) - const struct m_option *opt; // Option description - void *data; // Raw value of the option - const void *default_data; // Raw default value -}; - -// Config object -/** \ingroup Config */ -typedef struct m_config { - // Registered options. - struct m_config_option *opts; // all options, even suboptions - int num_opts; - - // List of defined profiles. - struct m_profile *profiles; - // Depth when recursively including profiles. - int profile_depth; - - struct m_opt_backup *backup_opts; - - bool use_profiles; - bool is_toplevel; - int (*includefunc)(struct m_config *conf, char *filename, int flags); - - void *optstruct; // struct mpopts or other -} m_config_t; - -// Create a new config object. -// talloc_ctx: talloc parent context for the m_config allocation -// size: size of the optstruct (where option values are stored) -// size==0 creates a config object with no option struct allocated -// defaults: if not NULL, points to a struct of same type as optstruct, which -// contains default values for all options -// options: list of options. Each option defines a member of the optstruct -// and a corresponding option switch or sub-option field. -// suboptinit: if not NULL, initialize the suboption string (used for presets) -// Note that the m_config object will keep pointers to defaults and options. -struct m_config *m_config_new(void *talloc_ctx, size_t size, - const void *defaults, - const struct m_option *options); - -struct m_config *m_config_from_obj_desc(void *talloc_ctx, - struct m_obj_desc *desc); - -struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, - struct m_obj_desc *desc); - -int m_config_set_obj_params(struct m_config *conf, char **args); - -// Search for the object with the given name in the defaults list, and apply -// its parameters. -int m_config_apply_defaults(struct m_config *config, const char *name, - struct m_obj_settings *defaults); - -// Make sure the option is backed up. If it's already backed up, do nothing. -// All backed up options can be restored with m_config_restore_backups(). -void m_config_backup_opt(struct m_config *config, const char *opt); - -// Call m_config_backup_opt() on all options. -void m_config_backup_all_opts(struct m_config *config); - -// Restore all options backed up with m_config_backup_opt(), and delete the -// backups afterwards. -void m_config_restore_backups(struct m_config *config); - -enum { - M_SETOPT_PRE_PARSE_ONLY = 1, // Silently ignore non-M_OPT_PRE_PARSE opt. - M_SETOPT_CHECK_ONLY = 2, // Don't set, just check name/value - M_SETOPT_FROM_CONFIG_FILE = 4, // Reject M_OPT_NOCFG opt. (print error) - M_SETOPT_FROM_CMDLINE = 8, // Mark as set by command line - M_SETOPT_BACKUP = 16, // Call m_config_backup_opt() before - M_SETOPT_PRESERVE_CMDLINE = 32, // Don't set if already marked as FROM_CMDLINE -}; - -// Set the named option to the given string. -// flags: combination of M_SETOPT_* flags (0 for normal operation) -// Returns >= 0 on success, otherwise see OptionParserReturn. -int m_config_set_option_ext(struct m_config *config, struct bstr name, - struct bstr param, int flags); - -/* Set an option. (Like: m_config_set_option_ext(config, name, param, 0)) - * \param config The config object. - * \param name The option's name. - * \param param The value of the option, can be NULL. - * \return See \ref OptionParserReturn. - */ -int m_config_set_option(struct m_config *config, struct bstr name, - struct bstr param); - -static inline int m_config_set_option0(struct m_config *config, - const char *name, const char *param) -{ - return m_config_set_option(config, bstr0(name), bstr0(param)); -} - -int m_config_parse_suboptions(struct m_config *config, char *name, - char *subopts); - - -/* Get the option matching the given name. - * \param config The config object. - * \param name The option's name. - */ -const struct m_option *m_config_get_option(const struct m_config *config, - struct bstr name); - -struct m_config_option *m_config_get_co(const struct m_config *config, - struct bstr name); - -// Return the n-th option by position. n==0 is the first option. If there are -// less than (n + 1) options, return NULL. -const char *m_config_get_positional_option(const struct m_config *config, int n); - -// Return a hint to the option parser whether a parameter is/may be required. -// The option may still accept empty/non-empty parameters independent from -// this, and this function is useful only for handling ambiguous options like -// flags (e.g. "--a" is ok, "--a=yes" is also ok). -// Returns: error code (<0), or number of expected params (0, 1) -int m_config_option_requires_param(struct m_config *config, bstr name); - -/* Print a list of all registered options. - * \param config The config object. - */ -void m_config_print_option_list(const struct m_config *config); - - -/* Find the profile with the given name. - * \param config The config object. - * \param arg The profile's name. - * \return The profile object or NULL. - */ -struct m_profile *m_config_get_profile0(const struct m_config *config, - char *name); -struct m_profile *m_config_get_profile(const struct m_config *config, bstr name); - -/* Get the profile with the given name, creating it if necessary. - * \param config The config object. - * \param arg The profile's name. - * \return The profile object. - */ -struct m_profile *m_config_add_profile(struct m_config *config, char *name); - -/* Set the description of a profile. - * Used by the config file parser when defining a profile. - * - * \param p The profile object. - * \param arg The profile's name. - */ -void m_profile_set_desc(struct m_profile *p, bstr desc); - -/* Add an option to a profile. - * Used by the config file parser when defining a profile. - * - * \param config The config object. - * \param p The profile object. - * \param name The option's name. - * \param val The option's value. - */ -int m_config_set_profile_option(struct m_config *config, struct m_profile *p, - bstr name, bstr val); - -/* Enables profile usage - * Used by the config file parser when loading a profile. - * - * \param config The config object. - * \param p The profile object. - * \param flags M_SETOPT_* bits - */ -void m_config_set_profile(struct m_config *config, struct m_profile *p, - int flags); - -void *m_config_alloc_struct(void *talloc_ctx, - const struct m_sub_options *subopts); - -#endif /* MPLAYER_M_CONFIG_H */ diff --git a/mpvcore/m_option.c b/mpvcore/m_option.c deleted file mode 100644 index 85ac974861..0000000000 --- a/mpvcore/m_option.c +++ /dev/null @@ -1,2477 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer 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. - * - * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/// \file -/// \ingroup Options - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "talloc.h" -#include "mpvcore/mp_common.h" -#include "mpvcore/m_option.h" -#include "mpvcore/m_config.h" -#include "mpvcore/mp_msg.h" - -char *m_option_strerror(int code) -{ - switch (code) { - case M_OPT_UNKNOWN: - return "option not found"; - case M_OPT_MISSING_PARAM: - return "option requires parameter"; - case M_OPT_INVALID: - return "option parameter could not be parsed"; - case M_OPT_OUT_OF_RANGE: - return "parameter is outside values allowed for option"; - case M_OPT_DISALLOW_PARAM: - return "option doesn't take a parameter"; - case M_OPT_PARSER_ERR: - default: - return "parser error"; - } -} - -int m_option_required_params(const m_option_t *opt) -{ - if (((opt->flags & M_OPT_OPTIONAL_PARAM) || - (opt->type->flags & M_OPT_TYPE_OPTIONAL_PARAM))) - return 0; - return 1; -} - -static const struct m_option *m_option_list_findb(const struct m_option *list, - struct bstr name) -{ - for (int i = 0; list[i].name; i++) { - struct bstr lname = bstr0(list[i].name); - if ((list[i].type->flags & M_OPT_TYPE_ALLOW_WILDCARD) - && bstr_endswith0(lname, "*")) { - lname.len--; - if (bstrcmp(bstr_splice(name, 0, lname.len), lname) == 0) - return &list[i]; - } else if (bstrcmp(lname, name) == 0) - return &list[i]; - } - return NULL; -} - -const m_option_t *m_option_list_find(const m_option_t *list, const char *name) -{ - return m_option_list_findb(list, bstr0(name)); -} - -// Default function that just does a memcpy - -static void copy_opt(const m_option_t *opt, void *dst, const void *src) -{ - if (dst && src) - memcpy(dst, src, opt->type->size); -} - -// Flag - -#define VAL(x) (*(int *)(x)) - -static int clamp_flag(const m_option_t *opt, void *val) -{ - if (VAL(val) == opt->min || VAL(val) == opt->max) - return 0; - VAL(val) = opt->min; - return M_OPT_OUT_OF_RANGE; -} - -static int parse_flag(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - if (param.len) { - if (!bstrcmp0(param, "yes")) { - if (dst) - VAL(dst) = opt->max; - return 1; - } - if (!bstrcmp0(param, "no")) { - if (dst) - VAL(dst) = opt->min; - return 1; - } - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", - BSTR_P(name), BSTR_P(param)); - return M_OPT_INVALID; - } else { - if (dst) - VAL(dst) = opt->max; - return 0; - } -} - -static char *print_flag(const m_option_t *opt, const void *val) -{ - if (VAL(val) == opt->min) - return talloc_strdup(NULL, "no"); - else - return talloc_strdup(NULL, "yes"); -} - -static void add_flag(const m_option_t *opt, void *val, double add, bool wrap) -{ - if (fabs(add) < 0.5) - return; - bool state = VAL(val) != opt->min; - state = wrap ? !state : add > 0; - VAL(val) = state ? opt->max : opt->min; -} - -const m_option_type_t m_option_type_flag = { - // need yes or no in config files - .name = "Flag", - .size = sizeof(int), - .flags = M_OPT_TYPE_OPTIONAL_PARAM, - .parse = parse_flag, - .print = print_flag, - .copy = copy_opt, - .add = add_flag, - .clamp = clamp_flag, -}; - -// Single-value, write-only flag - -static int parse_store(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - if (param.len == 0 || bstrcmp0(param, "yes") == 0) { - if (dst) - VAL(dst) = opt->max; - return 0; - } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", - BSTR_P(name), BSTR_P(param)); - return M_OPT_DISALLOW_PARAM; - } -} - -const m_option_type_t m_option_type_store = { - // can only be activated - .name = "Flag", - .size = sizeof(int), - .flags = M_OPT_TYPE_OPTIONAL_PARAM, - .parse = parse_store, - .copy = copy_opt, -}; - -// Same for float types - -#undef VAL -#define VAL(x) (*(float *)(x)) - -static int parse_store_float(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - if (param.len == 0 || bstrcmp0(param, "yes") == 0) { - if (dst) - VAL(dst) = opt->max; - return 0; - } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", - BSTR_P(name), BSTR_P(param)); - return M_OPT_DISALLOW_PARAM; - } -} - -const m_option_type_t m_option_type_float_store = { - // can only be activated - .name = "Flag", - .size = sizeof(float), - .flags = M_OPT_TYPE_OPTIONAL_PARAM, - .parse = parse_store_float, - .copy = copy_opt, -}; - -// Integer - -#undef VAL - -static int clamp_longlong(const m_option_t *opt, void *val) -{ - long long v = *(long long *)val; - int r = 0; - if ((opt->flags & M_OPT_MAX) && (v > opt->max)) { - v = opt->max; - r = M_OPT_OUT_OF_RANGE; - } - if ((opt->flags & M_OPT_MIN) && (v < opt->min)) { - v = opt->min; - r = M_OPT_OUT_OF_RANGE; - } - *(long long *)val = v; - return r; -} - -static int parse_longlong(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - if (param.len == 0) - return M_OPT_MISSING_PARAM; - - struct bstr rest; - long long tmp_int = bstrtoll(param, &rest, 10); - if (rest.len) - tmp_int = bstrtoll(param, &rest, 0); - if (rest.len) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be an integer: %.*s\n", - BSTR_P(name), BSTR_P(param)); - return M_OPT_INVALID; - } - - if ((opt->flags & M_OPT_MIN) && (tmp_int < opt->min)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be >= %d: %.*s\n", - BSTR_P(name), (int) opt->min, BSTR_P(param)); - return M_OPT_OUT_OF_RANGE; - } - - if ((opt->flags & M_OPT_MAX) && (tmp_int > opt->max)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be <= %d: %.*s\n", - BSTR_P(name), (int) opt->max, BSTR_P(param)); - return M_OPT_OUT_OF_RANGE; - } - - if (dst) - *(long long *)dst = tmp_int; - - return 1; -} - -static int clamp_int(const m_option_t *opt, void *val) -{ - long long tmp = *(int *)val; - int r = clamp_longlong(opt, &tmp); - *(int *)val = tmp; - return r; -} - -static int clamp_int64(const m_option_t *opt, void *val) -{ - long long tmp = *(int64_t *)val; - int r = clamp_longlong(opt, &tmp); - *(int64_t *)val = tmp; - return r; -} - -static int parse_int(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - long long tmp; - int r = parse_longlong(opt, name, param, &tmp); - if (r >= 0 && dst) - *(int *)dst = tmp; - return r; -} - -static int parse_int64(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) -{ - long long tmp; - int r = parse_longlong(opt, name, param, &tmp); - if (r >= 0 && dst) - *(int64_t *)dst = tmp; - return r; -} - -static char *print_int(const m_option_t *opt, const void *val) -{