Crossfire Client, Trunk  R19639
Functions | Variables
misc.c File Reference

Contains misc useful functions that may be useful to various parts of code, but are not especially tied to it. More...

#include "client.h"
#include <errno.h>
#include <glib.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/wait.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

static const char * getLogLevelText (LogLevel level)
 
void LOG (LogLevel level, const char *origin, const char *format,...)
 Log messages of a certain importance to stderr. More...
 
void logChildPipe (ChildProcess *child, LogLevel level, int flag)
 
void logPipe (ChildProcess *child, LogLevel level, int pipe)
 
int make_path_to_file (char *filename)
 If any directories in the given path doesn't exist, they are created. More...
 
void monitorChilds (void)
 
void purgePipe (ChildProcess *cp, int pipe)
 
ChildProcessraiseChild (char *name, int flag)
 
void replace_chars_with_string (char *buffer, const guint16 buffer_size, const char find, const char *replace)
 Convert a buffer of a specified maximum size by replacing token characters with a provided string. More...
 

Variables

ChildProcessFirstChild =NULL
 
ChildProcessLastChild =NULL
 
static const char *const LogLevelTexts []
 
int MINLOG = MINLOGLEVEL
 

Detailed Description

Contains misc useful functions that may be useful to various parts of code, but are not especially tied to it.

Definition in file misc.c.

Function Documentation

static const char* getLogLevelText ( LogLevel  level)
static

Definition at line 101 of file misc.c.

References LOG_CRITICAL, and LogLevelTexts.

Referenced by LOG().

Here is the caller graph for this function:

void LOG ( LogLevel  level,
const char *  origin,
const char *  format,
  ... 
)

Log messages of a certain importance to stderr.

See 'client.h' for a full list of possible log levels.

Definition at line 111 of file misc.c.

References getLogLevelText(), and MINLOG.

Referenced by AccountPlayersCmd(), add_marked_text_to_pane(), AddMeFail(), AddMeSuccess(), AddspellCmd(), AnimCmd(), beat_check(), cache_newpng(), common_item_command(), CompleteCmd(), config_check(), config_load_legacy(), create_icon_image(), DeleteInventory(), DeleteItem(), DeleteSpell(), display_newpng(), do_network(), do_num_free_items(), draw_magic_map(), DrawExtInfoCmd(), DrawInfoCmd(), event_loop(), Face2Cmd(), FailureCmd(), fill_combobox_from_datadir(), finish_face_cmd(), get_class_info(), get_exp_info(), get_image_info(), get_image_sums(), get_new_char_info(), get_race_info(), get_skill_info(), get_starting_map_info(), get_type_from_name(), GoodbyeCmd(), gtk_draw_map(), handle_query(), Image2Cmd(), image_add_hash(), image_find_hash(), image_process_line(), image_remove_hash(), init_connection(), init_default_keybindings(), init_image_cache_data(), init_sockets(), init_sounds(), init_ui(), inventory_get_styles(), inventory_init(), keybind_insert(), keybinding_get_data(), keybinding_selection_func(), keyfunc(), list_selection_func(), load_image(), load_theme(), logPipe(), MagicMapCmd(), Map2Cmd(), map_scrollCmd(), mapdata_init(), menu_quit_program(), metaserver1_get_info(), metaserver1_thread(), metaserver2_get_info(), metaserver2_writer(), metaserver_connect_to(), monitorChilds(), MusicCmd(), negotiate_connection(), on_combobox_rcs_changed(), on_keybinding_button_remove_clicked(), on_keybinding_button_update_clicked(), on_spell_cast_clicked(), on_spell_invoke_clicked(), on_spell_treeview_row_activated(), on_treeview_choose_character_activated(), on_window_destroy_event(), parse_args(), parse_keybind_line(), parse_keys_file(), pickup_init(), play_sound_effect(), PlayerCmd(), png_to_data(), png_to_gdkpixmap(), process_race_class_info(), purgePipe(), raiseChild(), ReplyInfoCmd(), rescale_rgba_data(), save_keys(), script_init(), send_command(), setup_config_window(), SetupCmd(), SockList_AddChar(), SockList_AddInt(), SockList_AddShort(), SockList_ReadPacket(), Sound2Cmd(), spell_get_styles(), stats_get_styles(), StatsCmd(), trigger_skill(), unbind_key(), UpdateItemCmd(), UpdspellCmd(), VersionCmd(), and write_socket().

Here is the call graph for this function:

void logChildPipe ( ChildProcess child,
LogLevel  level,
int  flag 
)

Definition at line 239 of file misc.c.

References CHILD_STDERR, CHILD_STDOUT, ChildProcess::flag, and logPipe().

Referenced by init_sounds().

Here is the call graph for this function:

Here is the caller graph for this function:

void logPipe ( ChildProcess child,
LogLevel  level,
int  pipe 
)

Definition at line 215 of file misc.c.

References PipeLog::level, LOG(), PipeLog::log, LOG_WARNING, ChildProcess::logger, PipeLog::name, ChildProcess::name, ChildProcess::pid, and ChildProcess::tube.

Referenced by logChildPipe().

Here is the call graph for this function:

Here is the caller graph for this function:

int make_path_to_file ( char *  filename)

If any directories in the given path doesn't exist, they are created.

Definition at line 85 of file misc.c.

Referenced by save_keys().

Here is the caller graph for this function:

void monitorChilds ( void  )

Definition at line 174 of file misc.c.

References FirstChild, LOG(), PipeLog::log, LOG_INFO, ChildProcess::logger, ChildProcess::name, ChildProcess::next, ChildProcess::pid, and purgePipe().

Here is the call graph for this function:

void purgePipe ( ChildProcess cp,
int  pipe 
)

Definition at line 138 of file misc.c.

References PipeLog::level, LOG(), LOG_ERROR, ChildProcess::logger, PipeLog::name, ChildProcess::name, and ChildProcess::tube.

Referenced by monitorChilds().

Here is the call graph for this function:

Here is the caller graph for this function:

ChildProcess* raiseChild ( char *  name,
int  flag 
)

Definition at line 252 of file misc.c.

References CHILD_PIPEERR, CHILD_PIPEIN, CHILD_PIPEOUT, CHILD_SILENTFAIL, CHILD_STDERR, CHILD_STDIN, CHILD_STDOUT, CHILD_TUBE, ChildProcess::flag, LOG(), LOG_ERROR, LOG_INFO, name, ChildProcess::name, ChildProcess::next, and ChildProcess::pid.

Referenced by init_sounds().

Here is the call graph for this function:

Here is the caller graph for this function:

void replace_chars_with_string ( char *  buffer,
const guint16  buffer_size,
const char  find,
const char *  replace 
)

Convert a buffer of a specified maximum size by replacing token characters with a provided string.

Given a buffered template string "/input/to/edit", the maximum size of the buffer, a token '/', and a replacement string ":", the input string is transformed to ":input:to:edit". If the replacement string is empty, the token characters are simply removed. The template is processed from left to right, replacing token characters as they are found. Replacement strings are always inserted whole. If token replacement would overflow the size of the conversion buffer, the token is not replaced, and the remaining portion of the input string is appended after truncating it as required to avoid overfilling the buffer.

Parameters
bufferA string to perform a find and replace operation on.
buffer_sizeAllocated buffer size (used to avoid buffer overflow).
findA token character to find and replace in the buffer.
replaceA string that is to replace each token in the buffer.

Definition at line 50 of file misc.c.

Variable Documentation

ChildProcess* FirstChild =NULL

Definition at line 132 of file misc.c.

Referenced by monitorChilds().

ChildProcess* LastChild =NULL

Definition at line 133 of file misc.c.

const char* const LogLevelTexts[]
static
Initial value:
= {
"\x1b[34;1m" "DD" "\x1b[0m",
"\x1b[32;1m" "II" "\x1b[0m",
"\x1b[35;1m" "WW" "\x1b[0m",
"\x1b[31;1m" "EE" "\x1b[0m",
"\x1b[31;1m" "!!" "\x1b[0m",
"\x1b[30;1m" "??" "\x1b[0m",
}

Definition at line 92 of file misc.c.

Referenced by getLogLevelText().

int MINLOG = MINLOGLEVEL

Definition at line 105 of file misc.c.

Referenced by LOG().