Crossfire Server, Trunk
bwp.cpp File Reference
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <global.h>
#include <sys/stat.h>
#include "sproto.h"
+ Include dependency graph for bwp.cpp:

Go to the source code of this file.

Data Structures

struct  string_array
 

Macros

#define LO_NEWFILE   2
 
#define MAX_SIZE   64
 
#define NA   "n/a"
 

Typedefs

typedef struct string_array String_Array
 

Functions

static char * cat_template (char *source, char *add)
 
static char * do_template (const char *tpl, const char **vars, const char **values)
 
void free_data (String_Array *array)
 
static void free_if_used (char *p)
 
const char * join_with_comma (String_Array *array)
 
int main (int argc, char *argv[])
 
void push (String_Array *array, const char *string)
 
static int read_template (const char *name, char **buffer)
 
void set_map_timeout (void)
 
static int sort_archetypes (const void *a, const void *b)
 
static int sortbyname (const void *a, const void *b)
 

Variables

const char *const flag_names [NUM_FLAGS+1]
 
char * monster_attack_row
 
char * monster_canuse_row
 
char * monster_entry
 
char * monster_lore_row
 
char * monster_page_foot
 
char * monster_page_head
 
char * monster_protected_row
 
char * monster_special_row
 
char * monster_vulnerable_row
 

Macro Definition Documentation

◆ LO_NEWFILE

#define LO_NEWFILE   2

Definition at line 38 of file bwp.cpp.

◆ MAX_SIZE

#define MAX_SIZE   64

Definition at line 39 of file bwp.cpp.

◆ NA

#define NA   "n/a"

Definition at line 40 of file bwp.cpp.

Typedef Documentation

◆ String_Array

typedef struct string_array String_Array

Function Documentation

◆ cat_template()

static char* cat_template ( char *  source,
char *  add 
)
static

Concatenates a string, and free concatenated string.

Parameters
sourcestring to append to. Can be NULL.
addstring that is appened. Will be free()d after. Must not be NULL.
Returns
new string that should be free()d by caller.

Definition at line 117 of file bwp.cpp.

◆ do_template()

static char* do_template ( const char *  tpl,
const char **  vars,
const char **  values 
)
static

Processes a template.

Variables in the form #VARIABLE# will be substituted for specified values.

Parameters
templatetemplate to process.
varsvariables to replace. Array must be NULL-terminated.
valuesvariables to replace by. Must be the same size as vars, no NULL element allowed.
Returns
filled-in template, that must be free()d be caller. NULL if memory allocation error.
Note
returned string will be a memory block larger than required, for performance reasons.

Definition at line 190 of file bwp.cpp.

References disinfect::count, and rotate-tower::result.

Referenced by main().

+ Here is the caller graph for this function:

◆ free_data()

void free_data ( String_Array array)

Frees the item's data of specified String_Array.

Will free array->item and its fields.

Parameters
arrayelement we want to clean.

Definition at line 330 of file bwp.cpp.

References say::item.

Referenced by main().

+ Here is the caller graph for this function:

◆ free_if_used()

static void free_if_used ( char *  p)
static

Frees memory if the pointer was ever given a string.

There's probably a cleaner way to do this, but this frees the memory given to a pointer if the pointer points to a string longer than zero length. It's to get rid of "in free(): warning: junk pointer, too high to make sense" errors.

Parameters
pPointer to free memory from

Definition at line 258 of file bwp.cpp.

◆ join_with_comma()

const char* join_with_comma ( String_Array array)

Joins strings with a comma and space.

Takes an array of strings and joins them togther with a comma and a space between each of them.

Parameters
arrayPointer to struct of type String_Array, containing strings to join

Definition at line 349 of file bwp.cpp.

References sortbyname().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

◆ push()

void push ( String_Array array,
const char *  string 
)

Add a string to a String_Array struct

Adds the new string to the struct's 'item' array, and updates the 'count'value.

Parameters
arrayThe array to be appended
stringThe new string to append

Definition at line 315 of file bwp.cpp.

References strdup_local.

Referenced by check_trigger(), and main().

+ Here is the caller graph for this function:

◆ read_template()

static int read_template ( const char *  name,
char **  buffer 
)
static

Reads a file in memory.

Parameters
namefile path to read.
bufferwhere to store. Can be left uninitialized in case of errors.
Returns
1 if error, 0 else.

Definition at line 136 of file bwp.cpp.

References mad_mage_user::file, and give::name.

Referenced by main().

+ Here is the caller graph for this function:

◆ set_map_timeout()

void set_map_timeout ( void  )

Definition at line 698 of file bwp.cpp.

◆ sort_archetypes()

static int sort_archetypes ( const void *  a,
const void *  b 
)
static

Sort archetypes alphabetically

Used by qsort to sort archetypes alphabetically without regard to case

Parameters
aFirst value
bSecond value

Definition at line 293 of file bwp.cpp.

References disinfect::a, Ice::b, archetype::clone, object::name, and strcasecmp().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sortbyname()

static int sortbyname ( const void *  a,
const void *  b 
)
static

Sort values alphabetically

Used by qsort to sort values alphabetically without regard to case

Parameters
aFirst value
bSecond value

Definition at line 276 of file bwp.cpp.

References disinfect::a, Ice::b, and strcasecmp().

Referenced by join_with_comma().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ flag_names

const char* const flag_names[NUM_FLAGS+1]

This is a list of pointers that correspond to the FLAG_.. values. This is a simple 1:1 mapping - if FLAG_FRIENDLY is 15, then the 15'th element of this array should match that name. If an entry is NULL, that is a flag not to loaded/saved.

Copied from common/loader.c; perhaps should be defined elsewhere?

Definition at line 74 of file bwp.cpp.

Referenced by main().

◆ monster_attack_row

char* monster_attack_row

Definition at line 57 of file bwp.cpp.

Referenced by main().

◆ monster_canuse_row

char* monster_canuse_row

Definition at line 53 of file bwp.cpp.

Referenced by main().

◆ monster_entry

char* monster_entry

Definition at line 52 of file bwp.cpp.

Referenced by main().

◆ monster_lore_row

char* monster_lore_row

Definition at line 58 of file bwp.cpp.

Referenced by main().

◆ monster_page_foot

char* monster_page_foot

Definition at line 51 of file bwp.cpp.

Referenced by main().

◆ monster_page_head

char* monster_page_head

Definition at line 50 of file bwp.cpp.

Referenced by main().

◆ monster_protected_row

char* monster_protected_row

Definition at line 54 of file bwp.cpp.

Referenced by main().

◆ monster_special_row

char* monster_special_row

Definition at line 56 of file bwp.cpp.

Referenced by main().

◆ monster_vulnerable_row

char* monster_vulnerable_row

Definition at line 55 of file bwp.cpp.

Referenced by main().