Crossfire Client, Trunk  R19307
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 <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.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.
void logChildPipe (ChildProcess *child, LogLevel level, int flag)
void logPipe (ChildProcess *child, LogLevel level, int pipe)
int make_path_to_dir (char *directory)
 Verifies that the directory exists, creates it if necessary Returns -1 on failure.
int make_path_to_file (char *filename)
 If any directories in the given path doesn't exist, they are created.
void monitorChilds (void)
void purgePipe (ChildProcess *cp, int pipe)
ChildProcessraiseChild (char *name, int flag)
void replace_chars_with_string (char *buffer, const uint16 buffer_size, const char find, const char *replace)
 Convert a buffer of a specified maximum size by replacing token characters with a provided string.
char * strdup_local (const char *str)
 A replacement of strdup(), since it's not defined at some unix variants.

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 173 of file misc.c.

References LOG_CRITICAL.

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 183 of file misc.c.

References getLogLevelText().

Referenced by AccountPlayersCmd(), add_marked_text_to_pane(), add_to_textbuf(), AddMeFail(), AddMeSuccess(), AddspellCmd(), AnimCmd(), cache_newpng(), common_item_command(), CompleteCmd(), create_icon_image(), DeleteInventory(), DeleteItem(), DeleteSpell(), display_newpng(), do_network(), do_num_free_items(), draw_ext_info(), 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(), info_get_styles(), init_client_vars(), 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_defaults(), load_image(), load_msgctrl_configuration(), load_theme(), load_window_positions(), logPipe(), MagicMapCmd(), make_path_to_file(), Map2Cmd(), map_scrollCmd(), mapdata_init(), menu_quit_program(), message_callback(), 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_defaults(), save_keys(), save_msgctrl_configuration(), script_init(), send_command(), setup_config_window(), SetupCmd(), 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 311 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 287 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_dir ( char *  directory)

Verifies that the directory exists, creates it if necessary Returns -1 on failure.

Definition at line 85 of file misc.c.

References MAX_BUF.

Referenced by init_client_vars().

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 126 of file misc.c.

References LOG(), LOG_ERROR, and MAX_BUF.

Referenced by save_defaults(), save_keys(), and save_msgctrl_configuration().

Here is the call graph for this function:

Here is the caller graph for this function:

void monitorChilds ( void  )

Definition at line 246 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 210 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 324 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 uint16  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 49 of file misc.c.

char* strdup_local ( const char *  str)

A replacement of strdup(), since it's not defined at some unix variants.

Definition at line 158 of file misc.c.

Referenced by get_image_info(), get_skill_info(), init_sounds(), keybind_insert(), load_defaults(), read_config_window(), and requestface().

Here is the caller graph for this function:


Variable Documentation

Definition at line 204 of file misc.c.

Referenced by monitorChilds().

Definition at line 205 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 164 of file misc.c.

int MINLOG = MINLOGLEVEL

Definition at line 177 of file misc.c.

Referenced by parse_args().