Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

misc.h File Reference

Random definitions used everywhere in Xconq. More...

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Namespaces

namespace  Xconq

Classes

struct  a_packed_bool_table
 Table of Packed Booleans. More...

struct  a_library_path
 Library path. More...


Defines

#define TRUE   (1)
#define FALSE   (0)
#define CONST   const
 const definiton.

#define ABS(x)   (((x) < 0) ? (0 - (x)) : (x))
 Absolute value.

#define min(x, y)   (((x) < (y)) ? (x) : (y))
 Minimum value.

#define max(x, y)   (((x) > (y)) ? (x) : (y))
 Maximum value.

#define between(lo, n, hi)   ((lo) <= (n) && (n) <= (hi))
 Is between.

#define limitn(lo, n, hi)
 Limit value.

#define flip_coin()   (xrandom(257) % 2)
 Random true/false.

#define avg(a, b)   (((a) + (b)) / 2)
 Average.

#define dice1(N, NUMDICE, SPOTS, OFFSET)
 Decompose dice representation into Type 1 dice parts.

#define dice2(N, NUMDICE, SPOTS, OFFSET)
 Decompose dice representation into Type 2 dice parts.

#define normalize_on_pmscale(n, max, range)   ((max) ? (((n) * (range)) / (max)) : 0)
 Normalize a number on a scale between -range and +range.

#define isspace(c)   ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
 Is space.

#define lowercase(c)   (isupper(c) ? tolower(c) : (c))
#define uppercase(c)   (islower(c) ? toupper(c) : (c))
#define empty_string(s)   ((s) == NULL || s[0] == '\0')
 Is string empty.

#define get_packed_bool(tbl, m, n)   (((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] & (1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)) ? TRUE : FALSE)
 Get a boolean value from a table of packed booleans.

#define set_packed_bool(tbl, m, n, boolval)   ((boolval) ? ((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] |= (1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)) : ((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] &= ~(1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)))
 Set a boolean value in a table of packed booleans.

#define valid_packed_bool_table(tbl)   (((tbl) != NULL) && ((tbl)->pbools != NULL) && ((tbl)->sizeofint > 0) && ((tbl)->rdim1size >= 0) && ((tbl)->dim2size > 0))
 Validate a supposed table of packed booleans.

#define assert_warning(cond, msg)   { assert(cond); if (!(cond)) run_warning(msg); }
#define assert_warning_break(cond, msg)   { assert(cond); if (!(cond)) { run_warning(msg); break; } }
#define assert_warning_continue(cond, msg)   { assert(cond); if (!(cond)) { run_warning(msg); continue; } }
#define assert_warning_goto(cond, msg, label)   { assert(cond); if (!(cond)) { run_warning(msg); goto label; } }
#define assert_warning_return(cond, msg, retval)   { assert(cond); if (!(cond)) { run_warning(msg); return retval; } }
#define assert_error(cond, msg)   { assert(cond); if (!(cond)) run_error(msg); }
#define assert_break(cond)   { assert(cond); if (!(cond)) break; }
#define assert_continue(cond)   { assert(cond); if (!(cond)) continue; }
#define assert_goto(cond, label)   { assert(cond); if (!(cond)) goto label; }
#define assert_return(cond, retval)   { assert(cond); if (!(cond)) return retval; }
#define Dprintf   if (0) debug_printf
#define DMprintf   if (0) debugm_printf
#define DGprintf   if (0) debugg_printf
#define Dprintlisp(X)
#define DMprintlisp(X)
#define DGprintlisp(X)
#define Debug   (0)
#define DebugM   (0)
#define DebugG   (0)
#define dfp   stdout
#define dmfp   stdout
#define dgfp   stdout
#define for_all_library_paths(p)   for (p = xconq_libs; p != NULL; p = p->next)
 Iterate library paths.


Typedefs

typedef a_packed_bool_table PackedBoolTable
 Table of Packed Booleans.

typedef a_library_path LibraryPath
 Library path.


Functions

PackedBoolTablecreate_packed_bool_table (int m, int n)
 Prototypes of functions used in the packed boolean implementation.

void init_packed_bool_table (PackedBoolTable *tbl)
void destroy_packed_bool_table (PackedBoolTable *tbl)
void init_xrandom (int seed)
int xrandom (int m)
int probability (int prob)
int prob_fraction (int n)
void * xmalloc (int amt)
void report_malloc (void)
void tprintf (char *buf, char *str,...)
void tnprintf (char *buf, int n, char *str,...)
int select_by_weight (int *arr, int numvals)
char * copy_string (char *str)
char * pad_blanks (char *str, int n)
int iindex (int ch, char *str)
long idifftime (time_t t1, time_t t0)
void case_panic (char *str, int var)
int isqrt (int i)
void init_debug_to_stdout (void)
void update_debugging (void)
void toggle_debugging (int *flagp)
void debug_printf (char *str,...)
void debugm_printf (char *str,...)
void debugg_printf (char *str,...)
void prealloc_debug (void)
void record_activity_start (char *type, int detail)
void record_activity_end (char *type, int detail)
void dump_activity_trace (void)
void vtprintf (char *buf, char *str, va_list ap)
void log_warning (char *typ, char *str)
int write_entire_game_state (char *fname)
char * find_name (char *fname)
FILE * open_file (char *filename, char *mode)
void save_game (char *fname)
void close_displays (void)

Variables

char spbuf []
 ???

char tmpbuf []
 ???

LibraryPathxconq_libs
 Library path list.

LibraryPathlast_user_xconq_lib
 Last user library.


Detailed Description

Random definitions used everywhere in Xconq.

This file contains miscellaneous macro and constant definitions.


Define Documentation

#define ABS  )     (((x) < 0) ? (0 - (x)) : (x))
 

Absolute value.

If the system does not define an absolute value macro, use this definition. The absolute value of a number is the number stripped of it's sign and expressed as a positive number. I.e. ABS(-3) == 3, ABS(3) == 3.

Parameters:
x is the number of which to take the absolute value.
Returns:
the absolute value of x.

#define assert_break cond   )     { assert(cond); if (!(cond)) break; }
 

#define assert_continue cond   )     { assert(cond); if (!(cond)) continue; }
 

#define assert_error cond,
msg   )     { assert(cond); if (!(cond)) run_error(msg); }
 

#define assert_goto cond,
label   )     { assert(cond); if (!(cond)) goto label; }
 

#define assert_return cond,
retval   )     { assert(cond); if (!(cond)) return retval; }
 

#define assert_warning cond,
msg   )     { assert(cond); if (!(cond)) run_warning(msg); }
 

#define assert_warning_break cond,
msg   )     { assert(cond); if (!(cond)) { run_warning(msg); break; } }
 

#define assert_warning_continue cond,
msg   )     { assert(cond); if (!(cond)) { run_warning(msg); continue; } }
 

#define assert_warning_goto cond,
msg,
label   )     { assert(cond); if (!(cond)) { run_warning(msg); goto label; } }
 

#define assert_warning_return cond,
msg,
retval   )     { assert(cond); if (!(cond)) { run_warning(msg); return retval; } }
 

#define avg a,
 )     (((a) + (b)) / 2)
 

Average.

Calculates the average value. Note that if sum of the numbers is greater than the range of the fundamental type,the answer will be wrong.

Parameters:
a is a number
b is a number
Returns:
the average of a and b

#define between lo,
n,
hi   )     ((lo) <= (n) && (n) <= (hi))
 

Is between.

Determines if a number is between two other numbers (inclusive).

Parameters:
lo is the low value to check
n is the number to be checked
hi is the high value to check
Returns:
  • true if n is between lo and hi (inclusive);
  • false otherwise.

#define CONST   const
 

const definiton.

This is how we do optional const decls.

#define Debug   (0)
 

#define DebugG   (0)
 

#define DebugM   (0)
 

#define dfp   stdout
 

#define dgfp   stdout
 

#define DGprintf   if (0) debugg_printf
 

#define DGprintlisp  ) 
 

#define dice1 N,
NUMDICE,
SPOTS,
OFFSET   ) 
 

Value:

(((0 == ((N) >> 14)) || (3 == ((N) >> 14))) ?   \
     (NUMDICE = 0, SPOTS = 0, OFFSET = (N)) :   \
     (NUMDICE = (((N) >> 11) & 0x07) + 1,  \
      SPOTS = (((N) >> 7) & 0x0f) + 2,  \
      OFFSET = ((N) & 0x8000) ? (-((N) & 0x7f) - 1) : ((N) & 0x7f)))
Decompose dice representation into Type 1 dice parts.

#define dice2 N,
NUMDICE,
SPOTS,
OFFSET   ) 
 

Value:

(((0 == ((N) >> 14)) || (3 == ((N) >> 14))) ?   \
     (NUMDICE = 0, SPOTS = 0, OFFSET = (N)) :   \
     (NUMDICE = ((N) & 0x8000) ? -((((N) >> 11) & 0x07) + 1) \
                                  : (((N) >> 11) & 0x07) + 1,  \
      SPOTS = (((N) >> 7) & 0x0f) + 2,  \
      OFFSET = ((N) & 0x8000) ? -((N) & 0x7f) : ((N) & 0x7f)))
Decompose dice representation into Type 2 dice parts.

#define dmfp   stdout
 

#define DMprintf   if (0) debugm_printf
 

#define DMprintlisp  ) 
 

#define Dprintf   if (0) debug_printf
 

#define Dprintlisp  ) 
 

#define empty_string  )     ((s) == NULL || s[0] == '\0')
 

Is string empty.

This tests a string to see if it has anything in it.

Parameters:
s is a char* to a null terminated string, or a null.
Returns:
  • true if an empty string;
  • false otherwise.

#define FALSE   (0)
 

 
#define flip_coin  )     (xrandom(257) % 2)
 

Random true/false.

Returns:
true or false randomly

#define for_all_library_paths  )     for (p = xconq_libs; p != NULL; p = p->next)
 

Iterate library paths.

This defines a for loop header to walk through all library paths in a library path list.

Parameters:
p is a LibraryPath iteration variable..

#define get_packed_bool tbl,
m,
 )     (((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] & (1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)) ? TRUE : FALSE)
 

Get a boolean value from a table of packed booleans.

#define isspace  )     ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r')
 

Is space.

If the system doesn't provide a definition of isspace, this will define it. If a charact si a space, newline, tab or carraige return, this is a space.

Parameters:
c is character to test.
Returns:
  • true if c is a space, tab, newline, or carriage return;
  • false otherwise.

#define limitn lo,
n,
hi   ) 
 

Value:

((n) \
    < (lo) ? (lo) : ((n) > (hi) ? (hi) : (n)))
Limit value.

Limits the value of the paramter to be between a high and low value (inclusive).

Parameters:
lo is the low value
n is the number to limit
hi is the high value
Returns:
  • lo if n is less than lo;
  • n if n is between lo and hi;
  • hi if n is greater than hi.

#define lowercase  )     (isupper(c) ? tolower(c) : (c))
 

#define max x,
 )     (((x) > (y)) ? (x) : (y))
 

Maximum value.

If the system doesn't define a maximum value macro or function, use this one. Find the larger of two numbers.

Parameters:
x is a number.
y is a number.
Returns:
the larger of the two numbers.

#define min x,
 )     (((x) < (y)) ? (x) : (y))
 

Minimum value.

If the system doesn't define a minimum value macro or function, use this one. Find the smaller of two numbers.

Parameters:
x is a number.
y is a number.
Returns:
the smaller of the two numbers.

#define normalize_on_pmscale n,
max,
range   )     ((max) ? (((n) * (range)) / (max)) : 0)
 

Normalize a number on a scale between -range and +range.

#define set_packed_bool tbl,
m,
n,
boolval   )     ((boolval) ? ((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] |= (1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)) : ((tbl)->pbools[((tbl)->whichway ? (m) : (n)) * (tbl)->rdim1size + ((tbl)->whichway ? (n) : (m)) / (tbl)->sizeofint] &= ~(1 << ((tbl)->whichway ? (n) : (m)) % (tbl)->sizeofint)))
 

Set a boolean value in a table of packed booleans.

#define TRUE   (1)
 

#define uppercase  )     (islower(c) ? toupper(c) : (c))
 

#define valid_packed_bool_table tbl   )     (((tbl) != NULL) && ((tbl)->pbools != NULL) && ((tbl)->sizeofint > 0) && ((tbl)->rdim1size >= 0) && ((tbl)->dim2size > 0))
 

Validate a supposed table of packed booleans.


Typedef Documentation

typedef struct a_library_path LibraryPath
 

Library path.

List of paths for the library.

typedef struct a_packed_bool_table PackedBoolTable
 

Table of Packed Booleans.

This structure contains an array of packed booleans.


Function Documentation

void case_panic char *  str,
int  var
 

void close_displays void   ) 
 

char* copy_string char *  str  ) 
 

PackedBoolTable* create_packed_bool_table int  m,
int  n
 

Prototypes of functions used in the packed boolean implementation.

void debug_printf char *  str,
... 
 

void debugg_printf char *  str,
... 
 

void debugm_printf char *  str,
... 
 

void destroy_packed_bool_table PackedBoolTable tbl  ) 
 

void dump_activity_trace void   ) 
 

char* find_name char *  fname  ) 
 

long idifftime time_t  t1,
time_t  t0
 

int iindex int  ch,
char *  str
 

void init_debug_to_stdout void   ) 
 

void init_packed_bool_table PackedBoolTable tbl  ) 
 

void init_xrandom int  seed  ) 
 

int isqrt int  i  ) 
 

void log_warning char *  typ,
char *  str
 

FILE* open_file char *  filename,
char *  mode
 

char* pad_blanks char *  str,
int  n
 

void prealloc_debug void   ) 
 

int prob_fraction int  n  ) 
 

int probability int  prob  ) 
 

void record_activity_end char *  type,
int  detail
 

void record_activity_start char *  type,
int  detail
 

void report_malloc void   ) 
 

void save_game char *  fname  ) 
 

int select_by_weight int *  arr,
int  numvals
 

void tnprintf char *  buf,
int  n,
char *  str,
... 
 

void toggle_debugging int *  flagp  ) 
 

void tprintf char *  buf,
char *  str,
... 
 

void update_debugging void   ) 
 

void vtprintf char *  buf,
char *  str,
va_list  ap
 

int write_entire_game_state char *  fname  ) 
 

void* xmalloc int  amt  ) 
 

int xrandom int  m  ) 
 


Variable Documentation

LibraryPath* last_user_xconq_lib
 

Last user library.

Pointer to last LibraryPath loaded by user.

char spbuf[]
 

???

char tmpbuf[]
 

???

LibraryPath* xconq_libs
 

Library path list.

List of LibraryPath's to Xconq libraries (games)


Generated on Sat Sep 17 10:29:19 2005 for XconqKernel by doxygen 1.3.6