Angband
Macros | Functions | Variables
datafile.c File Reference

Angband data file reading and writing routines. More...

#include "angband.h"
#include "datafile.h"
#include "game-world.h"
#include "init.h"
#include "parser.h"
#include "list-parser-errors.h"
#include "list-stats.h"
#include "list-object-modifiers.h"
#include "list-elements.h"

Macros

#define PARSE_ERROR(a, b)   b,
 
#define STAT(a)   #a,
 
#define OBJ_MOD(a)   #a,
 
#define ELEM(a)   #a,
 

Functions

static void print_error (struct file_parser *fp, struct parser *p)
 

Angband datafile parsing routines

More...
 
errr run_parser (struct file_parser *fp)
 
errr parse_file_quit_not_found (struct parser *p, const char *filename)
 The basic file parsing function. More...
 
errr parse_file (struct parser *p, const char *filename)
 The basic file parsing function. More...
 
void cleanup_parser (struct file_parser *fp)
 
int lookup_flag (const char **flag_table, const char *flag_name)
 
bool find_value_arg (char *value_name, char *string, int *num)
 Gets a name and argument for a value expression of the form NAME[arg]. More...
 
errr grab_rand_value (random_value *value, const char **value_type, const char *name_and_value)
 Get the random value argument from a value expression and put it into the appropriate place in an array. More...
 
errr grab_int_value (int *value, const char **value_type, const char *name_and_value)
 Get the integer argument from a value expression and put it into the appropriate place in an array. More...
 
errr grab_index_and_int (int *value, int *index, const char **value_type, const char *prefix, const char *name_and_value)
 Get the integer argument from a value expression and the index in the value_type array of the suffix used to build the value string. More...
 
errr grab_base_and_int (int *value, char **base, const char *name_and_value)
 Get the integer argument from a slay value expression and the monster base name it is slaying. More...
 
errr grab_name (const char *from, const char *what, const char *list[], int max, int *num)
 
errr grab_flag (bitflag *flags, const size_t size, const char **flag_table, const char *flag_name)
 
errr remove_flag (bitflag *flags, const size_t size, const char **flag_table, const char *flag_name)
 
void write_flags (ang_file *fff, const char *intro_text, bitflag *flags, int flag_size, const char *names[])
 

Angband datafile writing routines

More...
 
void file_archive (char *fname, char *append)
 Archive a data file from ANGBAND_DIR_USER into ANGBAND_DIR_ARCHIVE. More...
 
void activate_randart_file (void)
 Prepare the randart file for the current seed to be loaded. More...
 
void deactivate_randart_file (void)
 Move the randart file to the archive directory. More...
 

Variables

const char * parser_error_str [PARSE_ERROR_MAX]
 

Detailed Description

Angband data file reading and writing routines.

Copyright (c) 2017 Nick McConnell

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

This file deals with Angband specific functions for reading and writing of data files; basic parser functions are in parser.c.

Macro Definition Documentation

#define ELEM (   a)    #a,
#define OBJ_MOD (   a)    #a,
#define PARSE_ERROR (   a,
 
)    b,
#define STAT (   a)    #a,

Function Documentation

void activate_randart_file ( void  )

Prepare the randart file for the current seed to be loaded.

References ANGBAND_DIR_ARCHIVE, ANGBAND_DIR_USER, file_move(), format(), path_build(), and seed_randart.

Referenced by rd_misc().

void cleanup_parser ( struct file_parser fp)
void deactivate_randart_file ( void  )

Move the randart file to the archive directory.

References file_archive(), seed_randart, and strnfmt().

Referenced by close_game().

void file_archive ( char *  fname,
char *  append 
)

Archive a data file from ANGBAND_DIR_USER into ANGBAND_DIR_ARCHIVE.

References ANGBAND_DIR_ARCHIVE, ANGBAND_DIR_USER, file_exists(), file_move(), format(), i, my_strcpy(), and path_build().

Referenced by deactivate_randart_file().

bool find_value_arg ( char *  value_name,
char *  string,
int num 
)

Gets a name and argument for a value expression of the form NAME[arg].

Parameters
name_and_valueis the expression
stringis the random value string to return (NULL if not required)
numis the integer to return (NULL if not required)

Referenced by grab_base_and_int(), grab_index_and_int(), grab_int_value(), and grab_rand_value().

errr grab_base_and_int ( int value,
char **  base,
const char *  name_and_value 
)

Get the integer argument from a slay value expression and the monster base name it is slaying.

Parameters
valuethe integer value
basethe monster base name
name_and_valuethe value expression being matched
Returns
0 if successful, otherwise an error value

References find_value_arg(), my_strcpy(), NULL, and string_make().

errr grab_flag ( bitflag flags,
const size_t  size,
const char **  flag_table,
const char *  flag_name 
)
errr grab_index_and_int ( int value,
int index,
const char **  value_type,
const char *  prefix,
const char *  name_and_value 
)

Get the integer argument from a value expression and the index in the value_type array of the suffix used to build the value string.

Parameters
valuethe integer value
indexthe information on where to put it (eg array index)
value_typethe variable suffix of the possible value strings
prefixthe constant prefix of the possible value strings
name_and_valuethe value expression being matched
Returns
0 if successful, otherwise an error value

References find_value_arg(), i, my_strcat(), my_strcpy(), NULL, and streq.

Referenced by parse_artifact_values(), parse_curse_values(), parse_ego_values(), parse_object_values(), and parse_p_race_values().

errr grab_int_value ( int value,
const char **  value_type,
const char *  name_and_value 
)

Get the integer argument from a value expression and put it into the appropriate place in an array.

Parameters
valuethe target array of integers
value_typethe possible value strings
name_and_valuethe value expression being matched
Returns
0 if successful, otherwise an error value

References find_value_arg(), i, my_strcpy(), NULL, and streq.

Referenced by parse_artifact_values(), and parse_ego_min_val().

errr grab_name ( const char *  from,
const char *  what,
const char *  list[],
int  max,
int num 
)
errr grab_rand_value ( random_value value,
const char **  value_type,
const char *  name_and_value 
)

Get the random value argument from a value expression and put it into the appropriate place in an array.

Parameters
valuethe target array of values
value_typethe possible value strings
name_and_valuethe value expression being matched
Returns
0 if successful, otherwise an error value

References dice_free(), dice_new(), dice_parse_string(), dice_random_value(), find_value_arg(), i, my_strcpy(), NULL, and streq.

Referenced by parse_ego_values(), and parse_object_values().

int lookup_flag ( const char **  flag_table,
const char *  flag_name 
)
errr parse_file ( struct parser p,
const char *  filename 
)
errr parse_file_quit_not_found ( struct parser p,
const char *  filename 
)
static void print_error ( struct file_parser fp,
struct parser p 
)
static
errr remove_flag ( bitflag flags,
const size_t  size,
const char **  flag_table,
const char *  flag_name 
)

References flag, FLAG_END, flag_off(), and lookup_flag().

Referenced by parse_monster_flags_off().

errr run_parser ( struct file_parser fp)
void write_flags ( ang_file fff,
const char *  intro_text,
bitflag flags,
int  flag_size,
const char *  names[] 
)


Angband datafile writing routines

Write the flag lines for a set of flags.

References buf, file_putf(), flag, FLAG_END, flag_next(), FLAG_START, my_strcat(), and my_strcpy().

Referenced by write_lore_entries().

Variable Documentation

const char* parser_error_str[PARSE_ERROR_MAX]

Referenced by print_error().