Ludum Dare 29
HackSoc's entry for the Ludum Dare Jam 29
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
utils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SCREENWIDTH   80
 
#define SCREENHEIGHT   25
 
#define xalloc(T)   _xalloc(sizeof(T))
 
#define xcalloc(S, T)   _xalloc((S) * sizeof(T));
 
#define xfree(P)   _xfree((void **)&(P))
 
#define lengthof(x)   (sizeof(x) / sizeof(x[0]))
 

Functions

void mvaddprintf (unsigned int y, unsigned int x, const char *fmt,...)
 
char * strdup (const char *str)
 
void mvaddchcol (unsigned int y, unsigned int x, char chr, int fg, int bg, bool bold)
 
const void ** list_choice (bool nochoice, const char *prompt, const char *prompt2, bool multi, bool empty, const char *choices[], const void *results[])
 
const void * random_choice (const void *choices[])
 
void show_help ()
 
void * _xalloc (size_t size)
 
void _xfree (void **ptr)
 

Macro Definition Documentation

#define lengthof (   x)    (sizeof(x) / sizeof(x[0]))

Wrapper for getting the length of an array.

#define SCREENHEIGHT   25

The height of the screen, in characters.

#define SCREENWIDTH   80

The width of the screen, in characters.

#define xalloc (   T)    _xalloc(sizeof(T))

Wrapper macro for _xalloc to add the sizeof.

#define xcalloc (   S,
 
)    _xalloc((S) * sizeof(T));

Handy calloc-like function using _xalloc.

#define xfree (   P)    _xfree((void **)&(P))

Wrapper macro for _xfree to add the extra indirection.

Function Documentation

void* _xalloc ( size_t  size)

Allocate (and zero) memory and immediately bail out if it fails.

Parameters
sizeAmount of memory to allocate (in bytes).
Returns
Allocated memory.
Note
Do not use this directly, use the xalloc macro instead.
void _xfree ( void **  ptr)

Free a non-NULL pointer.

Parameters
ptrPointer to memory to free.
Note
Do not use this directly, use the xfree macro instead.
const void** list_choice ( bool  nochoice,
const char *  prompt,
const char *  prompt2,
bool  multi,
bool  empty,
const char *  choices[],
const void *  results[] 
)

Select from a list of things, berate the player if they enter a bad choice. This clears the screen before and after running.

Parameters
nochoiceThis isn't a choice, just a list.
promptThe initial question.
prompt2The prompt to use after a bad choice.
multiAllow multiple selections.
emptyAllow an empty selection.
choicesNULL-terminated list of choice names.
resultsNULL-terminated list of actual results.
Returns
The results corresponding to the choices, or NULL.

Here is the call graph for this function:

Here is the caller graph for this function:

void mvaddchcol ( unsigned int  y,
unsigned int  x,
char  chr,
int  fg,
int  bg,
bool  bold 
)

Render the given char at the given position with the given colour pair.

Parameters
yThe Y position
xThe X position
chrThe character to render
fgThe foreground colour
bgThe background colour
boldWhether to bold or not

Here is the caller graph for this function:

void mvaddprintf ( unsigned int  y,
unsigned int  x,
const char *  fmt,
  ... 
)

printf the given string at the given position.

Parameters
yy-coordinate of the screen.
xx-coordinate of the screen.
fmtFormat of the string.

Here is the caller graph for this function:

const void* random_choice ( const void *  choices[])

Select a random value from a list

Parameters
choicesNULL-terminates list of choices.

Here is the caller graph for this function:

void show_help ( )

Show some help text to the player.

Here is the call graph for this function:

Here is the caller graph for this function:

char* strdup ( const char *  str)

Duplicate a string

Parameters
strString to duplicate

Here is the caller graph for this function: