+static void help( x264_param_t *defaults, int longhelp );
+static int parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt );
+static int encode( x264_param_t *param, cli_opt_t *opt );
+
+/* logging and printing for within the cli system */
+static int cli_log_level;
+void x264_cli_log( const char *name, int i_level, const char *fmt, ... )
+{
+ if( i_level > cli_log_level )
+ return;
+ char *s_level;
+ switch( i_level )
+ {
+ case X264_LOG_ERROR:
+ s_level = "error";
+ break;
+ case X264_LOG_WARNING:
+ s_level = "warning";
+ break;
+ case X264_LOG_INFO:
+ s_level = "info";
+ break;
+ case X264_LOG_DEBUG:
+ s_level = "debug";
+ break;
+ default:
+ s_level = "unknown";
+ break;
+ }
+ fprintf( stderr, "%s [%s]: ", name, s_level );
+ va_list arg;
+ va_start( arg, fmt );
+ x264_vfprintf( stderr, fmt, arg );
+ va_end( arg );
+}
+
+void x264_cli_printf( int i_level, const char *fmt, ... )
+{
+ if( i_level > cli_log_level )
+ return;
+ va_list arg;
+ va_start( arg, fmt );
+ x264_vfprintf( stderr, fmt, arg );
+ va_end( arg );
+}
+
+static void print_version_info( void )
+{
+#ifdef X264_POINTVER
+ printf( "x264 "X264_POINTVER"\n" );
+#else
+ printf( "x264 0.%d.X\n", X264_BUILD );
+#endif
+#if HAVE_SWSCALE
+ printf( "(libswscale %d.%d.%d)\n", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO );
+#endif
+#if HAVE_LAVF
+ printf( "(libavformat %d.%d.%d)\n", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO );
+#endif
+#if HAVE_FFMS
+ printf( "(ffmpegsource %d.%d.%d.%d)\n", FFMS_VERSION >> 24, (FFMS_VERSION & 0xff0000) >> 16, (FFMS_VERSION & 0xff00) >> 8, FFMS_VERSION & 0xff );
+#endif
+ printf( "built on " __DATE__ ", " );
+#ifdef __INTEL_COMPILER
+ printf( "intel: %.2f (%d)\n", __INTEL_COMPILER / 100.f, __INTEL_COMPILER_BUILD_DATE );
+#elif defined(__GNUC__)
+ printf( "gcc: " __VERSION__ "\n" );
+#elif defined(_MSC_FULL_VER)
+ printf( "msvc: %.2f (%u)\n", _MSC_VER / 100.f, _MSC_FULL_VER );
+#else
+ printf( "using an unknown compiler\n" );
+#endif
+ printf( "x264 configuration: --bit-depth=%d --chroma-format=%s\n", X264_BIT_DEPTH, chroma_format_names[X264_CHROMA_FORMAT] );
+ printf( "libx264 configuration: --bit-depth=%d --chroma-format=%s\n", x264_bit_depth, chroma_format_names[x264_chroma_format] );
+ printf( "x264 license: " );
+#if HAVE_GPL
+ printf( "GPL version 2 or later\n" );
+#else
+ printf( "Non-GPL commercial\n" );
+#endif
+#if HAVE_SWSCALE
+ const char *license = swscale_license();
+ printf( "libswscale%s%s license: %s\n", HAVE_LAVF ? "/libavformat" : "", HAVE_FFMS ? "/ffmpegsource" : "" , license );
+ if( !strcmp( license, "nonfree and unredistributable" ) ||
+ (!HAVE_GPL && (!strcmp( license, "GPL version 2 or later" )
+ || !strcmp( license, "GPL version 3 or later" ))))
+ printf( "WARNING: This binary is unredistributable!\n" );
+#endif
+}