static void PrintMsg (void *d, int type, const vlc_log_t *p_item, const char *format, va_list ap) { FILE *stream = stderr; int verbose = (intptr_t)d; if (verbose < 0 || verbose < (type - VLC_MSG_ERR)) return; int canc = vlc_savecancel (); flockfile (stream); utf8_fprintf (stream, "[%0*"PRIxPTR"] ", ptr_width, p_item->i_object_id); if (p_item->psz_header != NULL) utf8_fprintf (stream, "[%s] ", p_item->psz_header); utf8_fprintf (stream, "%s %s%s: ", p_item->psz_module, p_item->psz_object_type, msg_type[type]); utf8_vfprintf (stream, format, ap); putc_unlocked ('\n', stream); #if defined (_WIN32) || defined (__OS2__) fflush (stream); #endif funlockfile (stream); vlc_restorecancel (canc); }
static void PrintColorMsg (void *d, int type, const msg_item_t *p_item, const char *format, va_list ap) { const int *pverbose = d; FILE *stream = stderr; if (*pverbose < 0 || *pverbose < (type - VLC_MSG_ERR)) return; int canc = vlc_savecancel (); flockfile (stream); fprintf (stream, "["GREEN"%p"GRAY"] ", (void *)p_item->i_object_id); if (p_item->psz_header != NULL) utf8_fprintf (stream, "[%s] ", p_item->psz_header); utf8_fprintf (stream, "%s %s%s: %s", p_item->psz_module, p_item->psz_object_type, msg_type[type], msg_color[type]); utf8_vfprintf (stream, format, ap); fputs (GRAY"\n", stream); #if defined (WIN32) || defined (__OS2__) fflush (stream); #endif funlockfile (stream); vlc_restorecancel (canc); }
/***************************************************************************** * PauseConsole: On Win32, wait for a key press before closing the console ***************************************************************************** * This function is useful only on Win32. *****************************************************************************/ static void PauseConsole( void ) { if( getenv( "PWD" ) ) return; /* Cygwin shell or Wine */ utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") ); getchar(); fclose( stdout ); }
static int usage_argh(const struct option *opts, FILE *outfile) { const char *s; int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh; if (opts->flags & PARSE_OPT_OPTARG) if (opts->long_name) s = literal ? "[=%s]" : "[=<%s>]"; else s = literal ? "[%s]" : "[<%s>]"; else s = literal ? " %s" : " <%s>"; return utf8_fprintf(outfile, s, opts->argh ? _(opts->argh) : _("...")); }
static int module_list(int argc, const char **argv, const char *prefix) { int i; struct pathspec pathspec; struct module_list list = MODULE_LIST_INIT; struct option module_list_options[] = { OPT_STRING(0, "prefix", &prefix, N_("path"), N_("alternative anchor for relative paths")), OPT_END() }; const char *const git_submodule_helper_usage[] = { N_("git submodule--helper list [--prefix=<path>] [<path>...]"), NULL }; argc = parse_options(argc, argv, prefix, module_list_options, git_submodule_helper_usage, 0); if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { printf("#unmatched\n"); return 1; } for (i = 0; i < list.nr; i++) { const struct cache_entry *ce = list.entries[i]; if (ce_stage(ce)) printf("%06o %s U\t", ce->ce_mode, sha1_to_hex(null_sha1)); else printf("%06o %s %d\t", ce->ce_mode, sha1_to_hex(ce->sha1), ce_stage(ce)); utf8_fprintf(stdout, "%s\n", ce->name); } return 0; }
static int usage_with_options_internal(struct parse_opt_ctx_t *ctx, const char * const *usagestr, const struct option *opts, int full, int err) { FILE *outfile = err ? stderr : stdout; if (!usagestr) return PARSE_OPT_HELP; if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL) fprintf(outfile, "cat <<\\EOF\n"); fprintf_ln(outfile, _("usage: %s"), _(*usagestr++)); while (*usagestr && **usagestr) /* TRANSLATORS: the colon here should align with the one in "usage: %s" translation */ fprintf_ln(outfile, _(" or: %s"), _(*usagestr++)); while (*usagestr) { if (**usagestr) fprintf_ln(outfile, _(" %s"), _(*usagestr)); else putchar('\n'); usagestr++; } if (opts->type != OPTION_GROUP) fputc('\n', outfile); for (; opts->type != OPTION_END; opts++) { size_t pos; int pad; if (opts->type == OPTION_GROUP) { fputc('\n', outfile); if (*opts->help) fprintf(outfile, "%s\n", _(opts->help)); continue; } if (!full && (opts->flags & PARSE_OPT_HIDDEN)) continue; pos = fprintf(outfile, " "); if (opts->short_name) { if (opts->flags & PARSE_OPT_NODASH) pos += fprintf(outfile, "%c", opts->short_name); else pos += fprintf(outfile, "-%c", opts->short_name); } if (opts->long_name && opts->short_name) pos += fprintf(outfile, ", "); if (opts->long_name) pos += fprintf(outfile, "--%s", opts->long_name); if (opts->type == OPTION_NUMBER) pos += utf8_fprintf(outfile, _("-NUM")); if ((opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !(opts->flags & PARSE_OPT_NOARG)) pos += usage_argh(opts, outfile); if (pos <= USAGE_OPTS_WIDTH) pad = USAGE_OPTS_WIDTH - pos; else { fputc('\n', outfile); pad = USAGE_OPTS_WIDTH; } fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help)); } fputc('\n', outfile); if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL) fputs("EOF\n", outfile); return PARSE_OPT_HELP; }
/** * Initialize a libvlc instance * This function initializes a previously allocated libvlc instance: * - CPU detection * - gettext initialization * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, const char *ppsz_argv[] ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); char * psz_modules = NULL; char * psz_parser = NULL; char * psz_control = NULL; playlist_t *p_playlist = NULL; char *psz_val; /* System specific initialization code */ system_Init(); /* Initialize the module bank and load the configuration of the * main module. We need to do this at this stage to be able to display * a short help if required by the user. (short help == main module * options) */ module_InitBank (); /* Get command line options that affect module loading. */ if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank (false); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* Find verbosity from VLC_VERBOSE environment variable */ { char *env = getenv( "VLC_VERBOSE" ); if( env != NULL ) priv->i_verbose = atoi( env ); } /* Announce who we are (TODO: only first instance?) */ msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE ); msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE ); msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset ); msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE ); /* Load the builtins and plugins into the module_bank. * We have to do it before config_Load*() because this also gets the * list of configuration options exported by each module and loads their * default values. */ size_t module_count = module_LoadPlugins (p_libvlc); /* * Override default configuration with config file settings */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) { if( var_InheritBool( p_libvlc, "reset-config" ) ) config_SaveConfigFile( p_libvlc ); /* Save default config */ else config_LoadConfigFile( p_libvlc ); } /* * Override configuration with command line settings */ int vlc_optind; if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { #ifdef WIN32 MessageBox (NULL, TEXT("The command line options could not be parsed.\n" "Make sure they are valid."), TEXT("VLC media player"), MB_OK|MB_ICONERROR); #endif module_EndBank (true); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* * Support for gettext */ #if defined( ENABLE_NLS ) \ && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) vlc_bindtextdomain (PACKAGE_NAME); #endif /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); if (config_PrintHelp (VLC_OBJECT(p_libvlc))) { module_EndBank (true); return VLC_EEXITSUCCESS; } if( module_count <= 1 ) { msg_Err( p_libvlc, "No plugins found! Check your VLC installation."); module_EndBank (true); return VLC_ENOITEM; } #ifdef HAVE_DAEMON /* Check for daemon mode */ if( var_InheritBool( p_libvlc, "daemon" ) ) { char *psz_pidfile = NULL; if( daemon( 1, 0) != 0 ) { msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" ); module_EndBank (true); return VLC_EEXIT; } b_daemon = true; /* lets check if we need to write the pidfile */ psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" ); if( psz_pidfile != NULL ) { FILE *pidfile; pid_t i_pid = getpid (); msg_Dbg( p_libvlc, "PID is %d, writing it to %s", i_pid, psz_pidfile ); pidfile = vlc_fopen( psz_pidfile,"w" ); if( pidfile != NULL ) { utf8_fprintf( pidfile, "%d", (int)i_pid ); fclose( pidfile ); } else { msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)", psz_pidfile ); } } free( psz_pidfile ); } #endif /* FIXME: could be replaced by using Unix sockets */ #ifdef HAVE_DBUS #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append" #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc" #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2" #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" dbus_threads_init_default(); if( var_InheritBool( p_libvlc, "one-instance" ) || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" ) && var_InheritBool( p_libvlc, "started-from-file" ) ) ) { /* Initialise D-Bus interface, check for other instances */ DBusConnection *p_conn = NULL; DBusError dbus_error; dbus_error_init( &dbus_error ); /* connect to the session bus */ p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error ); if( !p_conn ) { msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else { /* check if VLC is available on the bus * if not: D-Bus control is not enabled on the other * instance and we can't pass MRLs to it */ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) ) { if( dbus_error_is_set( &dbus_error ) ) { msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else msg_Dbg( p_libvlc, "No Media Player is running. " "Continuing normally." ); } else { int i_input; DBusMessage* p_dbus_msg = NULL; DBusMessageIter dbus_args; DBusPendingCall* p_dbus_pending = NULL; dbus_bool_t b_play; msg_Warn( p_libvlc, "Another Media Player is running. Exiting"); for( i_input = vlc_optind; i_input < i_argc;i_input++ ) { /* Skip input options, we can't pass them through D-Bus */ if( ppsz_argv[i_input][0] == ':' ) { msg_Warn( p_libvlc, "Ignoring option %s", ppsz_argv[i_input] ); continue; } /* We need to resolve relative paths in this instance */ char *psz_mrl; if( strstr( psz_mrl, "://" ) ) psz_mrl = strdup( ppsz_argv[i_input] ); else psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL ); const char *psz_after_track = MPRIS_APPEND; if( psz_mrl == NULL ) continue; msg_Dbg( p_libvlc, "Adds %s to the running Media Player", psz_mrl ); p_dbus_msg = dbus_message_new_method_call( MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" ); if ( NULL == p_dbus_msg ) { msg_Err( p_libvlc, "D-Bus problem" ); free( psz_mrl ); system_End( ); exit( 1 ); } /* append MRLs */ dbus_message_iter_init_append( p_dbus_msg, &dbus_args ); if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_STRING, &psz_mrl ) ) { dbus_message_unref( p_dbus_msg ); free( psz_mrl ); system_End( ); exit( 1 ); } free( psz_mrl ); if( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_OBJECT_PATH, &psz_after_track ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } b_play = TRUE; if( var_InheritBool( p_libvlc, "playlist-enqueue" ) ) b_play = FALSE; if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_BOOLEAN, &b_play ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } /* send message and get a handle for a reply */ if ( !dbus_connection_send_with_reply ( p_conn, p_dbus_msg, &p_dbus_pending, -1 ) ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } if ( NULL == p_dbus_pending ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } dbus_connection_flush( p_conn ); dbus_message_unref( p_dbus_msg ); /* block until we receive a reply */ dbus_pending_call_block( p_dbus_pending ); dbus_pending_call_unref( p_dbus_pending ); } /* processes all command line MRLs */ /* bye bye */ system_End( ); exit( 0 ); } } /* we unreference the connection when we've finished with it */ if( p_conn ) dbus_connection_unref( p_conn ); } #undef MPRIS_APPEND #undef MPRIS_BUS_NAME #undef MPRIS_OBJECT_PATH #undef MPRIS_TRACKLIST_INTERFACE #endif // HAVE_DBUS /* * Message queue options */ /* Last chance to set the verbosity. Once we start interfaces and other * threads, verbosity becomes read-only. */ var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); if( var_InheritBool( p_libvlc, "quiet" ) ) { var_SetInteger( p_libvlc, "verbose", -1 ); priv->i_verbose = -1; } vlc_threads_setup( p_libvlc ); if( priv->b_color ) priv->b_color = var_InheritBool( p_libvlc, "color" ); vlc_CPU_dump( VLC_OBJECT(p_libvlc) ); vlc_object_set_name( p_libvlc, "main" ); priv->b_stats = var_InheritBool( p_libvlc, "stats" ); /* * Initialize hotkey handling */ priv->actions = vlc_InitActions( p_libvlc ); /* Create a variable for showing the fullscreen interface */ var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL ); var_SetBool( p_libvlc, "intf-toggle-fscontrol", true ); /* Create a variable for the Boss Key */ var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID ); /* Create a variable for showing the main interface */ var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL ); /* Create a variable for showing the right click menu */ var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL ); /* variables for signalling creation of new files */ var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); /* some default internal settings */ var_Create( p_libvlc, "window", VLC_VAR_STRING ); var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); if( !p_playlist ) { msg_Err( p_libvlc, "playlist initialization failed" ); module_EndBank (true); return VLC_EGENERIC; } /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); #if defined(MEDIA_LIBRARY) /* Get the ML */ if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) ) { priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL ); if( !priv->p_ml ) { msg_Err( p_libvlc, "ML initialization failed" ); return VLC_EGENERIC; } } else { priv->p_ml = NULL; } #endif /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); if( psz_modules ) { char *p = psz_modules, *m; while( ( m = strsep( &p, " :," ) ) != NULL ) playlist_ServicesDiscoveryAdd( p_playlist, m ); free( psz_modules ); } #ifdef ENABLE_VLM /* Initialize VLM if vlm-conf is specified */ psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" ); if( psz_parser ) { priv->p_vlm = vlm_New( p_libvlc ); if( !priv->p_vlm ) msg_Err( p_libvlc, "VLM initialization failed" ); } free( psz_parser ); #endif /* * Load background interfaces */ psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" ); psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" ); if( psz_modules && psz_control ) { char* psz_tmp; if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 ) { free( psz_modules ); psz_modules = psz_tmp; } } else if( psz_control ) { free( psz_modules ); psz_modules = strdup( psz_control ); } psz_parser = psz_modules; while ( psz_parser && *psz_parser ) { char *psz_module, *psz_temp; psz_module = psz_parser; psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; psz_parser++; } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { intf_Create( p_libvlc, psz_temp ); free( psz_temp ); } } free( psz_modules ); free( psz_control ); /* * Always load the hotkeys interface if it exists */ intf_Create( p_libvlc, "hotkeys,none" ); if( var_InheritBool( p_libvlc, "file-logging" ) #ifdef HAVE_SYSLOG_H && !var_InheritBool( p_libvlc, "syslog" ) #endif ) { intf_Create( p_libvlc, "logger,none" ); } #ifdef HAVE_SYSLOG_H if( var_InheritBool( p_libvlc, "syslog" ) ) { char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" ); var_SetString( p_libvlc, "logmode", "syslog" ); intf_Create( p_libvlc, "logger,none" ); if( logmode ) { var_SetString( p_libvlc, "logmode", logmode ); free( logmode ); } var_Destroy( p_libvlc, "logmode" ); } #endif if( var_InheritBool( p_libvlc, "network-synchronisation") ) { intf_Create( p_libvlc, "netsync,none" ); } #ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS ); #endif #if defined (WIN32) || defined (__OS2__) var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER ); #endif /* * Get input filenames given as commandline arguments. * We assume that the remaining parameters are filenames * and their input options. */ GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* * Get --open argument */ psz_val = var_InheritString( p_libvlc, "open" ); if ( psz_val != NULL ) { playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0, -1, 0, NULL, 0, true, pl_Unlocked ); free( psz_val ); } return VLC_SUCCESS; }
static void TextPrint( const msg_item_t *p_msg, FILE *p_file ) { utf8_fprintf( p_file, "%s%s%s\n", p_msg->psz_module, ppsz_type[p_msg->i_type], p_msg->psz_msg ); }
static int update_clone(int argc, const char **argv, const char *prefix) { const char *update = NULL; int max_jobs = -1; struct string_list_item *item; struct pathspec pathspec; struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; struct option module_update_clone_options[] = { OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix, N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), OPT_STRING(0, "update", &update, N_("string"), N_("rebase, merge, checkout or none")), OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"), N_("reference repository")), OPT_STRING(0, "depth", &suc.depth, "<depth>", N_("Create a shallow clone truncated to the " "specified number of revisions")), OPT_INTEGER('j', "jobs", &max_jobs, N_("parallel jobs")), OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow, N_("whether the initial clone should follow the shallow recommendation")), OPT__QUIET(&suc.quiet, N_("don't print cloning progress")), OPT_BOOL(0, "progress", &suc.progress, N_("force cloning progress")), OPT_END() }; const char *const git_submodule_helper_usage[] = { N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"), NULL }; suc.prefix = prefix; argc = parse_options(argc, argv, prefix, module_update_clone_options, git_submodule_helper_usage, 0); if (update) if (parse_submodule_update_strategy(update, &suc.update) < 0) die(_("bad value for update parameter")); if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0) return 1; if (pathspec.nr) suc.warn_if_uninitialized = 1; /* Overlay the parsed .gitmodules file with .git/config */ gitmodules_config(); git_config(submodule_config, NULL); if (max_jobs < 0) max_jobs = parallel_submodules(); run_processes_parallel(max_jobs, update_clone_get_next_task, update_clone_start_failure, update_clone_task_finished, &suc); /* * We saved the output and put it out all at once now. * That means: * - the listener does not have to interleave their (checkout) * work with our fetching. The writes involved in a * checkout involve more straightforward sequential I/O. * - the listener can avoid doing any work if fetching failed. */ if (suc.quickstop) return 1; for_each_string_list_item(item, &suc.projectlines) utf8_fprintf(stdout, "%s", item->string); return 0; }
/***************************************************************************** * PrintMsg: output a standard message item to stderr ***************************************************************************** * Print a message to stderr, with colour formatting if needed. *****************************************************************************/ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item ) { # define COL(x) "\033[" #x ";1m" # define RED COL(31) # define GREEN COL(32) # define YELLOW COL(33) # define WHITE COL(0) # define GRAY "\033[0m" #ifdef UNDER_CE int i_dummy; #endif static const char ppsz_type[4][9] = { "", " error", " warning", " debug" }; static const char ppsz_color[4][8] = { WHITE, RED, YELLOW, GRAY }; const char *psz_object; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); int i_type = p_item->i_type; switch( i_type ) { case VLC_MSG_ERR: if( priv->i_verbose < 0 ) return; break; case VLC_MSG_INFO: if( priv->i_verbose < 0 ) return; break; case VLC_MSG_WARN: if( priv->i_verbose < 1 ) return; break; case VLC_MSG_DBG: if( priv->i_verbose < 2 ) return; break; } psz_object = p_item->psz_object_type; void * val = vlc_dictionary_value_for_key( &priv->msg_enabled_objects, p_item->psz_module ); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else { val = vlc_dictionary_value_for_key( &priv->msg_enabled_objects, psz_object ); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else if( !priv->msg_all_objects_enabled ) return; } #ifdef UNDER_CE # define CE_WRITE(str) WriteFile( QUEUE.logfile, \ str, strlen(str), &i_dummy, NULL ); CE_WRITE( p_item->psz_module ); CE_WRITE( " " ); CE_WRITE( psz_object ); CE_WRITE( ppsz_type[i_type] ); CE_WRITE( ": " ); CE_WRITE( p_item->psz_msg ); CE_WRITE( "\r\n" ); FlushFileBuffers( QUEUE.logfile ); #else int canc = vlc_savecancel (); /* Send the message to stderr */ utf8_fprintf( stderr, "[%s%p%s] %s%s%s %s%s: %s%s%s\n", priv->b_color ? GREEN : "", (void *)p_item->i_object_id, priv->b_color ? GRAY : "", p_item->psz_header ? p_item->psz_header : "", p_item->psz_header ? " " : "", p_item->psz_module, psz_object, ppsz_type[i_type], priv->b_color ? ppsz_color[i_type] : "", p_item->psz_msg, priv->b_color ? GRAY : "" ); # if defined(WIN32) fflush( stderr ); # endif vlc_restorecancel (canc); #endif }
/***************************************************************************** * PrintMsg: output a standard message item to stderr ***************************************************************************** * Print a message to stderr, with colour formatting if needed. *****************************************************************************/ static void PrintMsg ( vlc_object_t *p_this, const msg_item_t *p_item ) { # define COL(x,y) "\033[" #x ";" #y "m" # define RED COL(31,1) # define GREEN COL(32,1) # define YELLOW COL(0,33) # define WHITE COL(0,1) # define GRAY "\033[0m" static const char msgtype[4][9] = { "", " error", " warning", " debug" }; static const char msgcolor[4][8] = { WHITE, RED, YELLOW, GRAY }; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); int type = p_item->i_type; if (priv->i_verbose < 0 || priv->i_verbose < (type - VLC_MSG_ERR)) return; const char *objtype = p_item->psz_object_type; msg_bank_t *bank = priv->msg_bank; void * val = vlc_dictionary_value_for_key (&bank->enabled_objects, p_item->psz_module); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else { val = vlc_dictionary_value_for_key (&bank->enabled_objects, objtype); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else if( !bank->all_objects_enabled ) return; } /* Send the message to stderr */ FILE *stream = stderr; int canc = vlc_savecancel (); flockfile (stream); fprintf (stream, priv->b_color ? "["GREEN"%p"GRAY"] " : "[%p] ", (void *)p_item->i_object_id); if (p_item->psz_header != NULL) utf8_fprintf (stream, "[%s] ", p_item->psz_header); utf8_fprintf (stream, "%s %s%s: ", p_item->psz_module, objtype, msgtype[type]); if (priv->b_color) fputs (msgcolor[type], stream); fputs (p_item->psz_msg, stream); if (priv->b_color) fputs (GRAY, stream); putc_unlocked ('\n', stream); #if defined (WIN32) || defined (__OS2__) fflush (stream); #endif funlockfile (stream); #ifdef ANDROID int level[] = {ANDROID_LOG_INFO, ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_DEBUG}; __android_log_print( level[p_item->i_type], "faplayer", p_item->psz_header ? "[%p][%s] %s %s: %s" : "[%p]%s%s %s: %s", (void *) p_item->i_object_id, p_item->psz_header ? p_item->psz_header : "", p_item->psz_module, p_item->psz_object_type, p_item->psz_msg ); #endif vlc_restorecancel (canc); }
/***************************************************************************** * PrintMsg: output a standard message item to stderr ***************************************************************************** * Print a message to stderr, with colour formatting if needed. *****************************************************************************/ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item ) { # define COL(x) "\033[" #x ";1m" # define RED COL(31) # define GREEN COL(32) # define YELLOW COL(33) # define WHITE COL(0) # define GRAY "\033[0m" static const char ppsz_type[4][9] = { "", " error", " warning", " debug" }; static const char ppsz_color[4][8] = { WHITE, RED, YELLOW, GRAY }; const char *psz_object; libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); msg_bank_t *bank = priv->msg_bank; int i_type = p_item->i_type; switch( i_type ) { case VLC_MSG_ERR: if( priv->i_verbose < 0 ) return; break; case VLC_MSG_INFO: if( priv->i_verbose < 0 ) return; break; case VLC_MSG_WARN: if( priv->i_verbose < 1 ) return; break; case VLC_MSG_DBG: if( priv->i_verbose < 2 ) return; break; } psz_object = p_item->psz_object_type; void * val = vlc_dictionary_value_for_key (&bank->enabled_objects, p_item->psz_module); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else { val = vlc_dictionary_value_for_key (&bank->enabled_objects, psz_object); if( val == kObjectPrintingDisabled ) return; if( val == kObjectPrintingEnabled ) /* Allowed */; else if( !bank->all_objects_enabled ) return; } int canc = vlc_savecancel (); /* Send the message to stderr */ utf8_fprintf( stderr, "[%s%p%s] %s%s%s %s%s: %s%s%s\n", priv->b_color ? GREEN : "", (void *)p_item->i_object_id, priv->b_color ? GRAY : "", p_item->psz_header ? p_item->psz_header : "", p_item->psz_header ? " " : "", p_item->psz_module, psz_object, ppsz_type[i_type], priv->b_color ? ppsz_color[i_type] : "", p_item->psz_msg, priv->b_color ? GRAY : "" ); #ifdef WIN32 fflush( stderr ); #endif vlc_restorecancel (canc); }