Angband
Data Structures | Functions | Variables
ui-prefs.c File Reference

Pref file handling code. More...

#include "angband.h"
#include "cave.h"
#include "game-input.h"
#include "grafmode.h"
#include "init.h"
#include "mon-util.h"
#include "monster.h"
#include "obj-ignore.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "object.h"
#include "project.h"
#include "trap.h"
#include "ui-display.h"
#include "ui-keymap.h"
#include "ui-prefs.h"
#include "ui-term.h"

Data Structures

struct  prefs_data
 

Pref file parser

More...

Functions

static void remove_old_dump (const char *cur_fname, const char *mark)
 Remove old lines from pref files.
static void pref_header (ang_file *fff, const char *mark)
 Output the header of a pref-file dump.
static void pref_footer (ang_file *fff, const char *mark)
 Output the footer of a pref-file dump.
void dump_monsters (ang_file *fff)
 Dump monsters.
void dump_objects (ang_file *fff)
 Dump objects.
void dump_autoinscriptions (ang_file *f)
 Dump autoinscriptions.
void dump_features (ang_file *fff)
 Dump features.
void dump_flavors (ang_file *fff)
 Dump flavors.
void dump_colors (ang_file *fff)
 Dump colors.
void option_dump (ang_file *fff)
 Write all current options to a user preference file.
bool prefs_save (const char *path, void(*dump)(ang_file *), const char *title)
 Save a set of preferences to file, overwriting any old preferences with the same title.
static enum parser_error parse_prefs_load (struct parser *p)
 Load another file.
static const char * process_pref_file_expr (char **sp, char *fp)
 Helper function for "process_pref_file()".
static enum parser_error parse_prefs_expr (struct parser *p)
 Parse one of the prefix-based logical expressions used in pref files.
static enum parser_error parse_prefs_object (struct parser *p)
static enum parser_error parse_prefs_monster (struct parser *p)
static enum parser_error parse_prefs_trap (struct parser *p)
static enum parser_error parse_prefs_feat (struct parser *p)
static enum parser_error parse_prefs_gf (struct parser *p)
static enum parser_error parse_prefs_flavor (struct parser *p)
static enum parser_error parse_prefs_inscribe (struct parser *p)
static enum parser_error parse_prefs_keymap_action (struct parser *p)
static enum parser_error parse_prefs_keymap_input (struct parser *p)
static enum parser_error parse_prefs_message (struct parser *p)
static enum parser_error parse_prefs_color (struct parser *p)
static enum parser_error parse_prefs_window (struct parser *p)
static struct parserinit_parse_prefs (bool user)
static errr finish_parse_prefs (struct parser *p)
errr process_pref_file_command (const char *s)
static void print_error (const char *name, struct parser *p)
static bool process_pref_file_layered (const char *name, bool quiet, bool user, const char *base_search_path, const char *fallback_search_path, bool *used_fallback)
 Process the user pref file with a given name and search paths.
bool process_pref_file (const char *name, bool quiet, bool user)
 Look for a pref file at its base location (falling back to another path if needed) and then in the user location.
void reset_visuals (bool load_prefs)
 Reset the "visual" lists.
void textui_prefs_init (void)
 Initialise the glyphs for monsters, objects, traps, flavors and terrain.
void textui_prefs_free (void)
 Free the glyph arrays for monsters, objects, traps, flavors and terrain.
void do_cmd_pref (void)
 Ask for a "user pref line" and process it.

Variables

int arg_graphics
bool arg_graphics_nice
int use_graphics
bytemonster_x_attr
wchar_t * monster_x_char
bytekind_x_attr
wchar_t * kind_x_char
bytefeat_x_attr [LIGHTING_MAX]
wchar_t * feat_x_char [LIGHTING_MAX]
bytetrap_x_attr
wchar_t * trap_x_char
byteflavor_x_attr
wchar_t * flavor_x_char
size_t flavor_max = 0
static const char * dump_separator = "#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#"
 

Pref file saving code


Detailed Description

Pref file handling code.

Copyright (c) 2003 Takeshi Mogami, Robert Ruehlmann Copyright (c) 2007 Pete Mack Copyright (c) 2010 Andi Sidwell

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.

Function Documentation

void do_cmd_pref ( void  )

Ask for a "user pref line" and process it.

References get_string(), my_strcpy(), process_pref_file_command(), and void().

void dump_autoinscriptions ( ang_file f)
void dump_colors ( ang_file fff)
void dump_features ( ang_file fff)
void dump_flavors ( ang_file fff)
void dump_monsters ( ang_file fff)
void dump_objects ( ang_file fff)
static errr finish_parse_prefs ( struct parser p)
static
static struct parser* init_parse_prefs ( bool  user)
staticread
void option_dump ( ang_file fff)

Write all current options to a user preference file.

References angband_term, ANGBAND_TERM_MAX, angband_term_name, file_putf(), i, int, N_ELEMENTS, window_flag, and window_flag_desc.

Referenced by do_dump_options(), and save_game().

static enum parser_error parse_prefs_color ( struct parser p)
static
static enum parser_error parse_prefs_expr ( struct parser p)
static

Parse one of the prefix-based logical expressions used in pref files.

References prefs_data::bypass, parser_getstr(), parser_priv(), process_pref_file_expr(), streq, string_free(), and string_make().

Referenced by init_parse_prefs().

static enum parser_error parse_prefs_feat ( struct parser p)
static
static enum parser_error parse_prefs_flavor ( struct parser p)
static
static enum parser_error parse_prefs_gf ( struct parser p)
static
static enum parser_error parse_prefs_inscribe ( struct parser p)
static
static enum parser_error parse_prefs_keymap_action ( struct parser p)
static
static enum parser_error parse_prefs_keymap_input ( struct parser p)
static
static enum parser_error parse_prefs_load ( struct parser p)
static
static enum parser_error parse_prefs_message ( struct parser p)
static
static enum parser_error parse_prefs_monster ( struct parser p)
static
static enum parser_error parse_prefs_object ( struct parser p)
static
static enum parser_error parse_prefs_trap ( struct parser p)
static
static enum parser_error parse_prefs_window ( struct parser p)
static
static void pref_footer ( ang_file fff,
const char *  mark 
)
static

Output the footer of a pref-file dump.

References dump_separator, and file_putf().

Referenced by prefs_save().

static void pref_header ( ang_file fff,
const char *  mark 
)
static

Output the header of a pref-file dump.

References dump_separator, and file_putf().

Referenced by prefs_save().

bool prefs_save ( const char *  path,
void(*)(ang_file *)  dump,
const char *  title 
)

Save a set of preferences to file, overwriting any old preferences with the same title.

Parameters
pathis the filename to dump to
dumpis a pointer to the function that does the writing to file
titleis the name of this set of preferences
Returns
TRUE on success, FALSE otherwise.

References FALSE, file_close(), file_open(), file_putf(), FTYPE_TEXT, MODE_APPEND, pref_footer(), pref_header(), remove_old_dump(), safe_setuid_drop(), safe_setuid_grab(), and TRUE.

Referenced by dump_pref_file(), and save_game().

static void print_error ( const char *  name,
struct parser p 
)
static
bool process_pref_file ( const char *  name,
bool  quiet,
bool  user 
)

Look for a pref file at its base location (falling back to another path if needed) and then in the user location.

This effectively will layer a user pref file on top of a default pref file.

Because of the way this function works, there might be some unexpected effects when a pref file triggers another pref file to be loaded. For example, pref/pref.prf causes message.prf to load. This means that the game will load pref/pref.prf, then pref/message.prf, then user/message.prf, and finally user/pref.prf.

Parameters
nameis the name of the pref file.
quietmeans "don't complain about not finding the file".
usershould be TRUE if the pref file is user-specific and not a game default.
Returns
TRUE if everything worked OK, FALSE otherwise.

References ANGBAND_DIR_PREF, ANGBAND_DIR_USER, FALSE, process_pref_file_layered(), and TRUE.

Referenced by do_cmd_pref_file_hack(), do_cmd_save_screen_html(), parse_prefs_load(), process_character_pref_files(), reset_visuals(), and textui_init().

errr process_pref_file_command ( const char *  s)
static const char* process_pref_file_expr ( char **  sp,
char *  fp 
)
static

Helper function for "process_pref_file()".

Input: v: output buffer array f: final character

Output: result

References ANGBAND_SYS, player::class, player_race::name, player_class::name, p, player_safe_name(), player::race, streq, and TRUE.

Referenced by parse_prefs_expr().

static bool process_pref_file_layered ( const char *  name,
bool  quiet,
bool  user,
const char *  base_search_path,
const char *  fallback_search_path,
bool used_fallback 
)
static

Process the user pref file with a given name and search paths.

Parameters
nameis the name of the pref file.
quietmeans "don't complain about not finding the file".
usershould be TRUE if the pref file is user-specific and not a game default.
base_search_pathis the first path that should be checked for the file
fallback_search_pathis the path that should be checked if the file couldn't be found at the base path.
used_fallbackwill be set on return to TRUE if the fallback path was used, FALSE otherwise.
Returns
TRUE if everything worked OK, FALSE otherwise.

References buf, FALSE, file_close(), file_exists(), file_getl(), file_open(), finish_parse_prefs(), init_parse_prefs(), mem_free(), MODE_READ, msg, p, parser_destroy(), parser_parse(), parser_priv(), path_build(), print_error(), and TRUE.

Referenced by process_pref_file().

static void remove_old_dump ( const char *  cur_fname,
const char *  mark 
)
static

Remove old lines from pref files.

If you are using setgid, make sure privileges were raised prior to calling this.

References buf, dump_separator, FALSE, file_close(), file_delete(), file_getl(), file_move(), file_open(), file_putf(), FTYPE_TEXT, MODE_READ, MODE_WRITE, msg, strnfmt(), and TRUE.

Referenced by prefs_save().

void reset_visuals ( bool  load_prefs)
void textui_prefs_free ( void  )

Free the glyph arrays for monsters, objects, traps, flavors and terrain.

References feat_x_attr, feat_x_char, flavor_x_attr, flavor_x_char, i, kind_x_attr, kind_x_char, LIGHTING_MAX, mem_free(), monster_x_attr, monster_x_char, trap_x_attr, and trap_x_char.

Referenced by teardown_tests(), and textui_cleanup().

void textui_prefs_init ( void  )

Variable Documentation

int arg_graphics

Referenced by default_layout_win(), and main().

bool arg_graphics_nice

Referenced by default_layout_win().

const char* dump_separator = "#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#"
static


Pref file saving code

Header and footer marker string for pref file dumps

Referenced by pref_footer(), pref_header(), and remove_old_dump().

byte* feat_x_attr[LIGHTING_MAX]
wchar_t* feat_x_char[LIGHTING_MAX]
size_t flavor_max = 0

Referenced by textui_prefs_init().

byte* flavor_x_attr
wchar_t* flavor_x_char
byte* kind_x_attr
wchar_t* kind_x_char
byte* monster_x_attr
wchar_t* monster_x_char
byte* trap_x_attr
wchar_t* trap_x_char
int use_graphics