ekg/themes.c File Reference

#include "ekg2-config.h"
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "dynstuff.h"
#include "stuff.h"
#include "themes.h"
#include "xmalloc.h"
#include "windows.h"
#include "userlist.h"
#include "debug.h"
#include "dynstuff_inline.h"
#include "queries.h"

Data Structures

struct  format

Defines

#define _XOPEN_SOURCE   600
#define ROL(x)   (((x>>25)&0x7f)|((x<<7)&0xffffff80))
#define NPAR   16
#define FORMAT_ADD(format, value, replace)   sprintf(tmp, format, status); format_add(tmp, value, replace)
#define FORMAT_ADDF(format, fvalue, replace)   FORMAT_ADD(format, theme_init_contact_helper(fvalue, color), replace);

Functions

static LIST_FREE_ITEM (list_format_free, struct format *)
 DYNSTUFF_LIST_DECLARE (formats, struct format, list_format_free, static __DYNSTUFF_ADD_BEGINNING, static __DYNSTUFF_REMOVE_ITER, static __DYNSTUFF_DESTROY) static int gim_hash(const char *name)
const char * format_find (const char *name)
static const char * format_ansi (char ch)
static char * va_format_string (const char *format, va_list ap)
fstring_tfstring_new (const char *str)
fstring_tfstring_new_format (const char *format,...)
void fstring_free (fstring_t *str)
char * format_string (const char *format,...)
static void print_window_c (window_t *w, int activity, const char *theme, va_list ap)
static window_tprint_window_find (const char *target, session_t *session, int separate)
void print_window (const char *target, session_t *session, int activity, int separate, const char *theme,...)
void print_info (const char *target, session_t *session, const char *theme,...)
void print_warning (const char *target, session_t *session, const char *theme,...)
void print_window_w (window_t *w, int activity, const char *theme,...)
void theme_cache_reset ()
void format_add (const char *name, const char *value, int replace)
static int format_remove (const char *name)
static FILE * theme_open (const char *prefix, const char *filename)
int theme_read (const char *filename, int replace)
int theme_write (const char *filename)
void theme_enumerate (int(*enumerator)(const char *theme, const char *value))
void theme_free ()
void theme_plugins_init ()
static const char * theme_init_contact_helper (const char *theme, char color)
static void theme_init_contact_status (const char *status, char color, int want_quick_list)
void theme_init ()

Variables

static char * prompt_cache = NULL
static char * prompt2_cache = NULL
static char * error_cache = NULL
static const char * timestamp_cache = NULL
static int no_prompt_cache = 0
static int no_prompt_cache_hash = 0x139dcbd6
static struct formatformats [0x100]

Define Documentation

#define _XOPEN_SOURCE   600

#define FORMAT_ADD ( format,
value,
replace   )     sprintf(tmp, format, status); format_add(tmp, value, replace)

#define FORMAT_ADDF ( format,
fvalue,
replace   )     FORMAT_ADD(format, theme_init_contact_helper(fvalue, color), replace);

#define NPAR   16

#define ROL (  )     (((x>>25)&0x7f)|((x<<7)&0xffffff80))


Function Documentation

DYNSTUFF_LIST_DECLARE ( formats  ,
struct  format,
list_format_free  ,
static  __DYNSTUFF_ADD_BEGINNING,
static  __DYNSTUFF_REMOVE_ITER,
static  __DYNSTUFF_DESTROY 
) const

gim_hash()

void format_add ( const char *  name,
const char *  value,
int  replace 
)

format_add()

Add format with name and value.
If replace set to 1, than if format with the same name exists. than format value will be replaced.

Todo:
What about creating global variable: formats_unique_here.. and if set to 1, don't search if this format already exists? It should speedup theme_init() a little.
Parameters:
name - name of format
value - value of format
replace - if this format exists and is set to 1 than format value will be replaced with new one. else do nothing.

static const char* format_ansi ( char  ch  )  [static]

const char* format_find ( const char *  name  ) 

static int format_remove ( const char *  name  )  [static]

format_remove()

Remove format with given name.

Todo:
We can speedup it a little, by passing to list_remove() ptr to previous item.. senseless?
Parameters:
name 
Returns:
0 if format was founded and removed from list
-1 else

char* format_string ( const char *  format,
  ... 
)

void fstring_free ( fstring_t str  ) 

fstring_free()

Free memory allocated by str

Todo:
XXX Think about freeing str->private
Parameters:
str - fstring_t * to free.

fstring_t* fstring_new ( const char *  str  ) 

fstring_new()

Change formatted ansi string (str) to Nowy-i-Lepszy (tm) [New-and-Better].

Parameters:
str - string
See also:
format_string() - Function to format strings.

fstring_free() - Function to free fstring_t.

Returns:
Allocated fstring_t.

fstring_t* fstring_new_format ( const char *  format,
  ... 
)

fstring_new_format()

char *tmp = format_string("format", .....); fstr = fstring_new(tmp); xfree(tmp);

static LIST_FREE_ITEM ( list_format_free  ,
struct format  
) [static]

void print_info ( const char *  target,
session_t session,
const char *  theme,
  ... 
)

void print_warning ( const char *  target,
session_t session,
const char *  theme,
  ... 
)

void print_window ( const char *  target,
session_t session,
int  activity,
int  separate,
const char *  theme,
  ... 
)

print_window()

Print given text in given window [target+ session]

Todo:
We have no policy for displaying messages by e.g. jabber resources.
For now we do: [only jabber]
  • If target has '/' inside. We put there NUL char.
  • After it we search for window with stripped '/'
  • If founded, than done.
    If not, we look for user in userlist.. And if not found, than we'll create new window with stripped '/' [only jabber]
Parameters:
target - target to look for.
session - session to look for.
activity - how important is text?
separate - if essence of text is important to create new window
theme - Name of format to format_string() with ... Text will be be built.
... 

static void print_window_c ( window_t w,
int  activity,
const char *  theme,
va_list  ap 
) [static]

print_window_c()

Mind abbreviation ;) print_window_c() -> print_window_common()
Common stuff for: print_window() and print_window_w()
Change w->act if needed, format theme, make fstring() and send everything to window_print()

Note:
We only check if w == NULL, if you send here wrong window_t ptr, everything can happen. don't do it. Yeah, we can do here window_find_ptr() but it'll slow down code a lot.

static window_t* print_window_find ( const char *  target,
session_t session,
int  separate 
) [static]

print_window_find()

Find given window [based on target and session] if not found, and separate set, create new one.

Print given text in given window [target+ session]

Todo:
We have no policy for displaying messages by e.g. jabber resources.
For now we do: [only jabber]
  • If target has '/' inside. We put there NUL char.
  • After it we search for window with stripped '/'
  • If founded, than done.
    If not, we look for user in userlist.. And if not found, than we'll create new window with stripped '/' [only jabber]
Parameters:
target - target to look for.
session - session to look for.
separate - if essence of text is important to create new window

void print_window_w ( window_t w,
int  activity,
const char *  theme,
  ... 
)

print_window_w()

Like print_window() but it takes window_t struct instead of target+session.

Note:
The same as in print_window_c(): we don't check if w is valid window ptr. Just be careful. If you are not sure call:
print_window_c(window_find_ptr(w), separate, theme, ...) And in worst case text will be displayed in (__status / or __current) window instead of a usual one.. But ekg2 won't crash.
Parameters:
w - window to display,
if NULL than __status or __current will be used. it depends on: config_default_status_window and config_display_crap variables.

void theme_cache_reset (  ) 

theme_cache_reset()

Remove cached: prompt_cache, prompt2_cache, error_cache and timestamp_cache
These values are used by va_format_string() to don't call format_find() on:
["prompt" "%>", "prompt2" "%)", "errror" "%!", "timestamp" "%#"]

void theme_enumerate ( int(*)(const char *theme, const char *value)  enumerator  ) 

void theme_free (  ) 

void theme_init (  ) 

static const char* theme_init_contact_helper ( const char *  theme,
char  color 
) [static]

static void theme_init_contact_status ( const char *  status,
char  color,
int  want_quick_list 
) [static]

static FILE* theme_open ( const char *  prefix,
const char *  filename 
) [static]

void theme_plugins_init (  ) 

int theme_read ( const char *  filename,
int  replace 
)

int theme_write ( const char *  filename  ) 

static char* va_format_string ( const char *  format,
va_list  ap 
) [static]


Variable Documentation

char * error_cache = NULL [static]

struct format* formats[0x100] [static]

int no_prompt_cache = 0 [static]

int no_prompt_cache_hash = 0x139dcbd6 [static]

char * prompt2_cache = NULL [static]

char* prompt_cache = NULL [static]

const char* timestamp_cache = NULL [static]


Generated on Sat Nov 22 22:30:44 2008 for ekg2 by  doxygen 1.5.1