Crossfire Server, Trunk  R20513
Data Structures | Functions | Variables
gridarta-types-convert.c File Reference

This small program will extract information from Gridarta's types.xml file to generate documentation about types and fields. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "define.h"
Include dependency graph for gridarta-types-convert.c:

Go to the source code of this file.

Data Structures

struct  attribute_definition
 One attribute. More...
 
struct  attribute_type
 One type for an attribute. More...
 
struct  flag_definition
 One flag. More...
 
struct  ignore_list
 One list of fields to ignore. More...
 
struct  type_attribute
 One attribute in a type. More...
 
struct  type_definition
 One object type. More...
 
struct  type_name
 

Functions

void add_required_parameter (type_definition *type, const char *buf)
 Add a required parameter to the specified type. More...
 
void add_type_to_attribute (attribute_definition *attribute, type_definition *type, int attr)
 
void copy_attributes (const type_definition *source, type_definition *type)
 
void copy_default_attributes (type_definition *type)
 
void dump_ignore_lists (void)
 
void dump_type (type_definition *type)
 
void dump_types (void)
 
type_attributeduplicate_attribute (type_attribute *attr)
 
const flag_definitionfind_flag (const char *name)
 Return flag if exists, NULL else. More...
 
ignore_listfind_ignore_list (const char *name)
 
type_definitionfind_type_definition (const char *name)
 Used for type import. More...
 
void free_attribute (type_attribute *attr)
 
attribute_definitionget_attribute (const char *name)
 Get an attribute, create it if it doesn't exist yet. More...
 
type_attributeget_attribute_for_type (type_definition *type, const char *attribute, int clean)
 Gets the attribute for the specified type. More...
 
attribute_typeget_description_for_attribute (attribute_definition *attribute, const char *description)
 Gets a type description for specified attribute, create it if doesn't exist. More...
 
type_definitionget_type_definition (void)
 Returns a new type_definition having the default attributes. More...
 
void ignore_attribute (type_definition *type, const char *attribute)
 Remove an attribute from the type. More...
 
void ignore_attributes (type_definition *type, ignore_list *list)
 Remove all attributes in the specified list from the type. More...
 
int is_custom_attribute (const char *attribute)
 
int main (int argc, char **argv)
 
void read_ignore_list (const char *name, FILE *file)
 Read the contents of a <ignore_list> tag. More...
 
char * read_line (char *buffer, int size, FILE *file)
 
void read_type (type_definition *type, FILE *file, const char *block_end)
 Read all lines related to a type, stop when "block_end" is found on a line. More...
 
int sort_type_attribute (const void *a, const void *b)
 To sort attributes. More...
 
void write_attribute_file (attribute_definition *attribute)
 Write the description of a field. More...
 
void write_attribute_index (void)
 Write the index of all attributes. More...
 
void write_attribute_reference (const char *attribute, FILE *file)
 Write the part to the right of a @ref for the specified attribute. More...
 
void write_type_file (type_definition *type)
 Write a type definition file. More...
 
void write_type_index (void)
 Write index of all types. More...
 

Variables

int attribute_count = 0
 
attribute_definition ** attributes = NULL
 
static const char * custom_attributes []
 Custom attributes we know about, to point to the right page. More...
 
type_definitiondefault_type = NULL
 Definitions all types have by default. More...
 
const char * destination_dir = "../doc/Developers"
 Root destination dir. More...
 
type_definitionfallback_type = NULL
 Dummy object type that non defined objects use. More...
 
const char * field_dir = "fields"
 Where the files about the fields will be stored. More...
 
static const flag_definition flags []
 Flag mapping. More...
 
static const char * in_living []
 Fields part of the living structure. More...
 
int list_count = 0
 
ignore_list ** lists = NULL
 
int type_count = 0
 
const char * type_dir = "types"
 Where the files about types will be stored. More...
 
static type_name type_names []
 
type_definition ** types = NULL
 Defined types. More...
 

Detailed Description

This small program will extract information from Gridarta's types.xml file to generate documentation about types and fields.

Files are placed in developer's documentation subdirs by default.

To build:

gcc -g -pg -O0 -Wall -pedantic gridarta-types-convert.c -I../include -o gridarta-types-convert

To run:

./gridarta-types-convert ../../gridarta/src/crossfire/src/main/resources/resource/conf/types.xml

(adjust the path according to your setup)

Note that someone wishing to tweak this program should know the format of Gridarta's types.xml.

This program isn't terribly robust, there could be more conditions, and it just doesn't free memory. May be fixed someday, but since it's a "run and exit", not high priority.

This program can be modified and altered at will, as long as it's for the Crossfire project. Else don't touch it :)

Note that "attribute" is used for "field in a object/living structure".

Author
Nicolas Weeger / Ryo_ on IRC
Date
2008-01-06

Definition in file gridarta-types-convert.c.

Function Documentation

void add_required_parameter ( type_definition type,
const char *  buf 
)

Add a required parameter to the specified type.

buf is the line read from the file, non processed.

Definition at line 476 of file gridarta-types-convert.c.

References flag_definition::code_name, find_flag(), type_definition::require_count, type_definition::required, snprintf, and strdup().

Referenced by read_type().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_type_to_attribute ( attribute_definition attribute,
type_definition type,
int  attr 
)

Definition at line 723 of file gridarta-types-convert.c.

References type_definition::attributes, attribute_type::count, type_attribute::description, get_description_for_attribute(), type_definition::name, type_definition::number, attribute_type::number, strdup(), and attribute_type::type.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void copy_attributes ( const type_definition source,
type_definition type 
)

Definition at line 368 of file gridarta-types-convert.c.

References type_definition::attribute_count, type_definition::attributes, type_attribute::description, type_attribute::field, get_attribute_for_type(), type_attribute::name, and strdup().

Referenced by copy_default_attributes(), and read_type().

Here is the call graph for this function:

Here is the caller graph for this function:

void copy_default_attributes ( type_definition type)

Definition at line 384 of file gridarta-types-convert.c.

References copy_attributes().

Referenced by get_type_definition().

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_ignore_lists ( void  )

Definition at line 772 of file gridarta-types-convert.c.

References ignore_list::count, and list_count.

void dump_type ( type_definition type)
void dump_types ( void  )

Definition at line 670 of file gridarta-types-convert.c.

References dump_type(), and type_count.

Here is the call graph for this function:

type_attribute* duplicate_attribute ( type_attribute attr)

Definition at line 323 of file gridarta-types-convert.c.

References type_attribute::description, type_attribute::field, type_attribute::name, and strdup().

Here is the call graph for this function:

const flag_definition* find_flag ( const char *  name)

Return flag if exists, NULL else.

Definition at line 196 of file gridarta-types-convert.c.

References flag_definition::field.

Referenced by add_required_parameter(), and write_attribute_reference().

Here is the caller graph for this function:

ignore_list* find_ignore_list ( const char *  name)

Definition at line 428 of file gridarta-types-convert.c.

References list_count.

Referenced by read_type().

Here is the caller graph for this function:

type_definition* find_type_definition ( const char *  name)

Used for type import.

Definition at line 409 of file gridarta-types-convert.c.

References type_count.

Referenced by read_type().

Here is the caller graph for this function:

void free_attribute ( type_attribute attr)

Definition at line 331 of file gridarta-types-convert.c.

References type_attribute::description, type_attribute::field, and type_attribute::name.

Referenced by ignore_attribute().

Here is the caller graph for this function:

attribute_definition* get_attribute ( const char *  name)

Get an attribute, create it if it doesn't exist yet.

Definition at line 681 of file gridarta-types-convert.c.

References attribute_count, attribute_definition::field, and strdup().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

type_attribute* get_attribute_for_type ( type_definition type,
const char *  attribute,
int  clean 
)

Gets the attribute for the specified type.

If it doesn't exist, create it. If the attribute is already defined, return the existing one, after cleaning its fields if clean is set.

Definition at line 342 of file gridarta-types-convert.c.

References type_definition::attribute_count, type_definition::attributes, type_attribute::description, type_attribute::field, type_attribute::name, and strdup().

Referenced by copy_attributes(), and read_type().

Here is the call graph for this function:

Here is the caller graph for this function:

attribute_type* get_description_for_attribute ( attribute_definition attribute,
const char *  description 
)

Gets a type description for specified attribute, create it if doesn't exist.

Definition at line 701 of file gridarta-types-convert.c.

References attribute_type::description, strdup(), attribute_definition::type_count, and attribute_definition::types.

Referenced by add_type_to_attribute().

Here is the call graph for this function:

Here is the caller graph for this function:

type_definition* get_type_definition ( void  )

Returns a new type_definition having the default attributes.

Definition at line 393 of file gridarta-types-convert.c.

References type_definition::attribute_count, type_definition::attributes, copy_default_attributes(), and type_definition::description.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void ignore_attribute ( type_definition type,
const char *  attribute 
)

Remove an attribute from the type.

Definition at line 446 of file gridarta-types-convert.c.

References type_definition::attribute_count, attribute_count, type_definition::attributes, type_attribute::field, and free_attribute().

Referenced by ignore_attributes(), and read_type().

Here is the call graph for this function:

Here is the caller graph for this function:

void ignore_attributes ( type_definition type,
ignore_list list 
)

Remove all attributes in the specified list from the type.

Definition at line 462 of file gridarta-types-convert.c.

References ignore_list::count, ignore_list::fields, and ignore_attribute().

Referenced by read_type().

Here is the call graph for this function:

Here is the caller graph for this function:

int is_custom_attribute ( const char *  attribute)

Definition at line 843 of file gridarta-types-convert.c.

References custom_attributes.

Referenced by write_attribute_file(), and write_attribute_reference().

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)
void read_ignore_list ( const char *  name,
FILE *  file 
)

Read the contents of a <ignore_list> tag.

Definition at line 735 of file gridarta-types-convert.c.

References ignore_list::count, ignore_list::fields, list_count, ignore_list::name, read_line(), and strdup().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

char* read_line ( char *  buffer,
int  size,
FILE *  file 
)
Todo:
remove spaces at line start/end.

Definition at line 441 of file gridarta-types-convert.c.

Referenced by main(), read_ignore_list(), and read_type().

Here is the caller graph for this function:

void read_type ( type_definition type,
FILE *  file,
const char *  block_end 
)

Read all lines related to a type, stop when "block_end" is found on a line.

Definition at line 511 of file gridarta-types-convert.c.

References add_required_parameter(), type_definition::attribute_count, type_definition::attributes, copy_attributes(), type_attribute::description, type_definition::description, find_ignore_list(), find_type_definition(), get_attribute_for_type(), ignore_attribute(), ignore_attributes(), type_attribute::name, type_definition::name, read_line(), sort_type_attribute(), and strdup().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int sort_type_attribute ( const void *  a,
const void *  b 
)

To sort attributes.

Definition at line 421 of file gridarta-types-convert.c.

Referenced by read_type().

Here is the caller graph for this function:

void write_attribute_file ( attribute_definition attribute)

Write the description of a field.

Definition at line 974 of file gridarta-types-convert.c.

References attribute_type::count, attribute_type::description, destination_dir, attribute_definition::field, field_dir, is_custom_attribute(), attribute_type::number, snprintf, attribute_definition::type_count, attribute_definition::types, and write_attribute_reference().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void write_attribute_index ( void  )

Write the index of all attributes.

Definition at line 951 of file gridarta-types-convert.c.

References attribute_count, destination_dir, field_dir, snprintf, and write_attribute_reference().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void write_attribute_reference ( const char *  attribute,
FILE *  file 
)

Write the part to the right of a @ref for the specified attribute.

Definition at line 855 of file gridarta-types-convert.c.

References flag_definition::code_name, find_flag(), in_living, and is_custom_attribute().

Referenced by write_attribute_file(), write_attribute_index(), and write_type_file().

Here is the call graph for this function:

Here is the caller graph for this function:

void write_type_file ( type_definition type)
void write_type_index ( void  )

Write index of all types.

Definition at line 930 of file gridarta-types-convert.c.

References destination_dir, snprintf, type_count, and type_dir.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

int attribute_count = 0
attribute_definition** attributes = NULL

Definition at line 90 of file gridarta-types-convert.c.

const char* custom_attributes[]
static

Custom attributes we know about, to point to the right page.

Definition at line 809 of file gridarta-types-convert.c.

Referenced by is_custom_attribute().

type_definition* default_type = NULL

Definitions all types have by default.

Definition at line 60 of file gridarta-types-convert.c.

const char* destination_dir = "../doc/Developers"

Root destination dir.

Definition at line 31 of file gridarta-types-convert.c.

Referenced by write_attribute_file(), write_attribute_index(), write_type_file(), and write_type_index().

type_definition* fallback_type = NULL

Dummy object type that non defined objects use.

Definition at line 63 of file gridarta-types-convert.c.

Referenced by main().

const char* field_dir = "fields"

Where the files about the fields will be stored.

Definition at line 32 of file gridarta-types-convert.c.

Referenced by write_attribute_file(), and write_attribute_index().

const flag_definition flags[]
static
const char* in_living[]
static
Initial value:
= {
"Str",
"Dex",
"Con",
"Wis",
"Cha",
"Int",
"Pow",
"wc",
"ac",
"hp",
"maxhp",
"sp",
"maxsp",
"grace",
"maxgrace",
"exp",
"food",
"dam",
"luck",
NULL
}

Fields part of the living structure.

Definition at line 785 of file gridarta-types-convert.c.

Referenced by write_attribute_reference().

int list_count = 0

Definition at line 73 of file gridarta-types-convert.c.

Referenced by dump_ignore_lists(), find_ignore_list(), and read_ignore_list().

ignore_list** lists = NULL

Definition at line 72 of file gridarta-types-convert.c.

Referenced by MessageFile::parseFile().

int type_count = 0

Definition at line 57 of file gridarta-types-convert.c.

Referenced by dump_types(), find_type_definition(), main(), and write_type_index().

const char* type_dir = "types"

Where the files about types will be stored.

Definition at line 33 of file gridarta-types-convert.c.

Referenced by write_type_file(), and write_type_index().

type_name type_names[]
static

Definition at line 210 of file gridarta-types-convert.c.

type_definition** types = NULL

Defined types.

Definition at line 55 of file gridarta-types-convert.c.

Referenced by command_applymode(), command_bowmode(), command_petmode(), command_usekeys(), and START_TEST().