Freeciv-3.2: /fast/freeciv/nightly/S3_2/utility/inputfile.c File Reference

Freeciv-3.2

Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions | Variables
inputfile.c File Reference
`#include <stdarg.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "astring.h"`
`#include "fcintl.h"`
`#include "ioz.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "inputfile.h"`

Go to the source code of this file.

## Data Structures

struct | inputfile

## Macros

#define | INF_DEBUG_FOUND FALSE
#define | INF_DEBUG_NOT_FOUND FALSE
#define | INF_MAGIC (0xabdc0132) /* arbitrary */
#define | inf_log(inf, level, message, ...)
#define | inf_warn(inf, message) inf_log(inf, LOG_NORMAL, "%s", message);

## Typedefs

typedef const char *(* | get_token_fn_t) (struct inputfile *inf)

## Functions

static const char * | get_token_section_name (struct inputfile *inf)
static const char * | get_token_entry_name (struct inputfile *inf)
static const char * | get_token_eol (struct inputfile *inf)
static const char * | get_token_table_start (struct inputfile *inf)
static const char * | get_token_table_end (struct inputfile *inf)
static const char * | get_token_comma (struct inputfile *inf)
static const char * | get_token_value (struct inputfile *inf)
static bool | read_a_line (struct inputfile *inf)
static bool | is_comment (int c)
static void | init_zeros (struct inputfile *inf)
static bool | inf_sanity_check (struct inputfile *inf)
static const char * | inf_filename (struct inputfile *inf)
struct inputfile * | inf_from_file (const char *filename, datafilename_fn_t datafn)
struct inputfile * | inf_from_stream (fz_FILE *stream, datafilename_fn_t datafn)
static void | inf_close_partial (struct inputfile *inf)
void | inf_close (struct inputfile *inf)
static bool | have_line (struct inputfile *inf)
static bool | at_eol (struct inputfile *inf)
bool | inf_at_eof (struct inputfile *inf)
static bool | check_include (struct inputfile *inf)
char * | inf_log_str (struct inputfile *inf, const char *message,...)
const char * | inf_token (struct inputfile *inf, enum inf_token_type type)
int | inf_discard_tokens (struct inputfile *inf, enum inf_token_type type)
static const char * | get_token_white_char (struct inputfile *inf, char target)

## Variables

struct { |
const char * name |
get_token_fn_t func |
} | tok_tab [INF_TOK_LAST] |

## Macro Definition Documentation

## ◆ INF_DEBUG_FOUND

#define INF_DEBUG_FOUND FALSE

Definition at line 85 of file inputfile.c.

## ◆ INF_DEBUG_NOT_FOUND

#define INF_DEBUG_NOT_FOUND FALSE

Definition at line 86 of file inputfile.c.

## ◆ inf_log

#define inf_log | ( |  | inf,
|  |  | level,
|  |  | message,
|  |  | ...
| ) |  |

Value:
if (log_do_output_for_level(level)) { \
do_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, level, "%s", \
inf_log_str(inf, message, ## __VA_ARGS__)); \
}
incite_cost
char * incite_cost
Definition comments.c:74
inf_log_str
char * inf_log_str(struct inputfile *inf, const char *message,...)
Definition inputfile.c:567
__FC_LINE__
#define __FC_LINE__
Definition log.h:40
log_do_output_for_level
#define log_do_output_for_level(level)
Definition log.h:89
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
message
Definition messagewin_common.h:29
FALSE
#define FALSE
Definition support.h:47

Definition at line 143 of file inputfile.c.

## ◆ INF_MAGIC

#define INF_MAGIC (0xabdc0132) /* arbitrary */

Definition at line 88 of file inputfile.c.

## ◆ inf_warn

#define inf_warn | ( |  | inf,
|  |  | message
| ) |  | inf_log(inf, LOG_NORMAL, "%s", message);

Definition at line 148 of file inputfile.c.

## Typedef Documentation

## ◆ get_token_fn_t

typedef const char *(* get_token_fn_t) (struct inputfile *inf)

Definition at line 116 of file inputfile.c.

## Function Documentation

## ◆ at_eol()

static bool at_eol | ( | struct inputfile * | inf | ) |

static

Return TRUE if current pos is at end of current line.

Definition at line 332 of file inputfile.c.

Referenced by get_token_eol().

## ◆ check_include()

static bool check_include | ( | struct inputfile * | inf | ) |

static

Check for an include command, which is an isolated line with: include "filename" If a file is included via this mechanism, returns 1, and sets up data appropriately: (*inf) will now correspond to the new file, which is opened but no data read, and inf->included_from is set to newly malloced memory which corresponds to the old file.

Definition at line 363 of file inputfile.c.

Referenced by read_a_line().

## ◆ get_token_comma()

static const char * get_token_comma | ( | struct inputfile * | inf | ) |

static

Get flag token comma, or NULL if that is not next token.

Definition at line 795 of file inputfile.c.

## ◆ get_token_entry_name()

static const char * get_token_entry_name | ( | struct inputfile * | inf | ) |

static

Returns next entry name from inputfile. Skips white spaces and comments. Sets inputfile position after entry name.

Definition at line 689 of file inputfile.c.

## ◆ get_token_eol()

static const char * get_token_eol | ( | struct inputfile * | inf | ) |

static

If inputfile is at end-of-line, frees current line, and returns " ". If there is still something on that line, returns NULL.

Definition at line 729 of file inputfile.c.

## ◆ get_token_section_name()

static const char * get_token_section_name | ( | struct inputfile * | inf | ) |

static

Returns section name in current position of inputfile. Returns NULL if there is no section name on that position. Sets inputfile position after section name.

Definition at line 661 of file inputfile.c.

## ◆ get_token_table_end()

static const char * get_token_table_end | ( | struct inputfile * | inf | ) |

static

Get flag token for table end, or NULL if that is not next token.

Definition at line 787 of file inputfile.c.

## ◆ get_token_table_start()

static const char * get_token_table_start | ( | struct inputfile * | inf | ) |

static

Get flag token for table start, or NULL if that is not next token.

Definition at line 779 of file inputfile.c.

## ◆ get_token_value()

static const char * get_token_value | ( | struct inputfile * | inf | ) |

static

This one is more complicated; note that it may read in multiple lines.

Definition at line 803 of file inputfile.c.

## ◆ get_token_white_char()

static const char * get_token_white_char | ( | struct inputfile * | inf,
|  | char | target
| ) |  |

static

Get a flag token of a single character, with optional preceeding whitespace.

Definition at line 757 of file inputfile.c.

Referenced by get_token_comma(), get_token_table_end(), and get_token_table_start().

## ◆ have_line()

static bool have_line | ( | struct inputfile * | inf | ) |

static

Return TRUE if have data for current line.

Definition at line 320 of file inputfile.c.

Referenced by get_token_entry_name(), get_token_eol(), get_token_section_name(), get_token_value(), get_token_white_char(), and inf_token().

## ◆ inf_at_eof()

bool inf_at_eof | ( | struct inputfile * | inf | ) |

Return TRUE if current pos is at end of file.

Definition at line 346 of file inputfile.c.

Referenced by secfile_from_input_file().

## ◆ inf_close()

void inf_close | ( | struct inputfile * | inf | ) |

Close the file and free associated memory, included any partially recursed included files, and the memory allocated for 'inf' itself. Should only be used on an actually open inputfile. After this, the pointer should not be used.

Definition at line 300 of file inputfile.c.

Referenced by inf_close(), and secfile_from_input_file().

## ◆ inf_close_partial()

static void inf_close_partial | ( | struct inputfile * | inf | ) |

static

Close the file and free associated memory, but don't recurse included_from files, and don't free the actual memory where the inf record is stored (ie, the memory where the users pointer points to). This is used when closing an included file.

Definition at line 264 of file inputfile.c.

Referenced by inf_close(), and read_a_line().

## ◆ inf_discard_tokens()

int inf_discard_tokens | ( | struct inputfile * | inf,
|  | enum inf_token_type | type
| ) |  |

Read as many tokens of specified type as possible, discarding the results; returns number of such tokens read and discarded.

Definition at line 645 of file inputfile.c.

Referenced by secfile_from_input_file().

## ◆ inf_filename()

static const char * inf_filename | ( | struct inputfile * | inf | ) |

static

Return the filename the inputfile was loaded as, or "(anonymous)" if this inputfile was loaded from a stream rather than from a file.

Definition at line 206 of file inputfile.c.

Referenced by inf_close(), inf_close_partial(), inf_from_stream(), and inf_log_str().

## ◆ inf_from_file()

struct inputfile * inf_from_file | ( | const char * | filename,
|  | datafilename_fn_t | datafn
| ) |  |

Open the file, and return an allocated, initialized structure. Returns NULL if the file could not be opened.

Definition at line 219 of file inputfile.c.

Referenced by check_include(), and secfile_load_section().

## ◆ inf_from_stream()

struct inputfile * inf_from_stream | ( | fz_FILE * | stream,
|  | datafilename_fn_t | datafn
| ) |  |

Open the stream, and return an allocated, initialized structure. Returns NULL if the file could not be opened.

Definition at line 241 of file inputfile.c.

Referenced by inf_from_file(), and secfile_from_stream().

## ◆ inf_log_str()

char * inf_log_str | ( | struct inputfile * | inf,
|  | const char * | message,
|  |  | ...
| ) |  |

Return a detailed log message, including information on current line number etc. Message can be NULL: then just logs information on where we are in the file.

Definition at line 567 of file inputfile.c.

Referenced by entry_from_inf_token(), and secfile_from_input_file().

## ◆ inf_sanity_check()

static bool inf_sanity_check | ( | struct inputfile * | inf | ) |

static

Check sensible values for an opened inputfile.

Definition at line 182 of file inputfile.c.

Referenced by at_eol(), check_include(), have_line(), inf_at_eof(), inf_close(), inf_close_partial(), inf_log_str(), inf_sanity_check(), inf_token(), and read_a_line().

## ◆ inf_token()

const char * inf_token | ( | struct inputfile * | inf,
|  | enum inf_token_type | type
| ) |  |

Returns token of given type from given inputfile.

Definition at line 607 of file inputfile.c.

Referenced by inf_discard_tokens(), and secfile_from_input_file().

## ◆ init_zeros()

static void init_zeros | ( | struct inputfile * | inf | ) |

static

Set values to zeros; should have free'd/closed everything before this if appropriate.

Definition at line 163 of file inputfile.c.

Referenced by inf_close_partial(), and inf_from_stream().

## ◆ is_comment()

static bool is_comment | ( | int | c | ) |

static

Return true if c is a 'comment' character: '#' or ';'

Definition at line 154 of file inputfile.c.

Referenced by check_include(), get_token_entry_name(), get_token_eol(), and get_token_value().

## ◆ read_a_line()

static bool read_a_line | ( | struct inputfile * | inf | ) |

static

Read a new line into cur_line. Increments line_num and cur_line_pos. Returns FALSE if didn't read or other problem: treat as EOF. Strips newline from input.

Definition at line 471 of file inputfile.c.

Referenced by get_token_value(), inf_token(), and read_a_line().

## Variable Documentation

## ◆ func

get_token_fn_t func

Definition at line 128 of file inputfile.c.

Referenced by choice_dialog::add_item(), connections_set_close_callback(), choice_dialog::execute_action(), fc_at_quick_exit(), fc_sidewidget::fc_sidewidget(), inf_token(), popup_action_selection(), popup_pillage_dialog(), popup_sabotage_dialog(), real_players_dialog_update(), fc_sidewidget::set_left_click(), fc_sidewidget::set_right_click(), fc_sidewidget::set_wheel_down(), fc_sidewidget::set_wheel_up(), spy_steal_shared(), try_default_city_action(), and try_default_unit_action().

## ◆ name

const char* name

Definition at line 127 of file inputfile.c.

Referenced by _by_name(), achievement_by_rule_name(), action_by_rule_name(), add_column(), advance_by_rule_name(), advance_by_translated_name(), ai_skill_callback(), pregame_options::ailevel_change(), ailevel_name(), api_edit_create_base(), api_edit_create_city(), api_edit_create_extra(), api_edit_create_owned_extra(), api_edit_create_road(), api_edit_remove_extra(), api_find_action_type_by_name(), api_find_counter_by_name(), api_find_player_by_name(), api_methods_tile_has_base(), api_methods_tile_has_extra(), api_methods_tile_has_road(), api_specenum_create_table(), audio_get_all_plugin_names(), audio_select_plugin(), boot_help_texts(), city_dialog::buy(), buy_callback(), change_build_target(), chatline_autocomplete(), check_leader_names(), check_player_or_user_name(), choice_dialog_add(), choice_dialog_start(), city_build(), city_dialog_update_building(), city_list_find_name(), city_name_compare(), city_name_suggestion(), city_rename(), city_style_name_translation(), city_style_rule_name(), client_handle_packet(), client_ss_by_name(), cmd_reply_no_such_conn(), cmd_reply_no_such_player(), comment_write(), compat_load_020400(), compat_load_020500(), compat_load_020600(), compat_load_030100(), compat_load_030200(), complain_ambiguous(), counter_by_rule_name(), counter_by_translated_name(), create_city(), create_city_for_player(), create_city_virtual(), create_command_newcomer(), create_command_pregame(), cut_client_connection(), delegate_command(), disaster_by_rule_name(), dlsend_packet_city_name_suggestion_info(), dlsend_packet_ruleset_multiplier(), dsend_packet_city_name_suggestion_info(), dsend_packet_city_rename(), dsend_packet_nation_select_req(), dsend_packet_ruleset_multiplier(), dsend_packet_save_scenario(), dsend_packet_unit_do_action(), edit_buffer_copy(), entry_from_inf_token(), entry_from_token(), entry_new(), entry_set_name(), execute_orders(), extra_type_by_rule_name(), extra_type_by_translated_name(), extract_sequence_text(), extviewer_refresh_widgets(), finish_city(), game_city_by_name(), get_city_dialog_output_text(), fc_font::get_font(), get_help_item_spec(), get_output_name(), get_soundplugin_list(), get_ui_filename(), get_unique_guest_name(), global_worklist_load(), global_worklist_new(), global_worklist_set_name(), goods_by_rule_name(), goods_by_translated_name(), government_by_rule_name(), government_by_translated_name(), handle_chat_msg_req(), handle_city_name_suggestion_info(), handle_city_rename(), handle_nation_select_req(), handle_ruleset_select(), handle_save_scenario(), handle_unit_do_action(), improvement_by_rule_name(), improvement_by_translated_name(), inf_token(), insert_generated_text(), insert_veteran_help(), is_ascii_name(), is_default_city_name(), is_guest_name(), is_on_allowed_list(), is_reg_file_for_access(), is_safe_filename(), is_secfile_entry_name_valid(), is_valid_username(), kick_command(), load_nation_names(), load_ruleset_game(), load_ruleset_nations(), load_style_names(), lookup_option(), lookup_option_level(), lookup_req_list(), lookup_resource(), lookup_terrain(), luascript_do_string(), luascript_push_args(), makeup_connection_name(), mapimg_help(), match_prefix_full(), modpack_file_from_ruleset_cache(), mpdb_installed_version(), mpdb_update_modpack(), multiplier_by_rule_name(), multipliers_init(), name_and_sort_items(), nation_by_rule_name(), nation_by_translated_plural(), nation_city_new(), nation_group_by_rule_name(), nation_group_new(), nation_leader_by_name(), nation_leader_new(), nation_set_by_rule_name(), net_lookup_service(), netfile_add_form_int(), netfile_add_form_str(), objprop_new(), objprop_refresh_widget(), observe_command(), option_dialog::option_dialog(), option_dialog_new(), option_dialog_popup(), option_dialog_popup(), optset_option_by_name(), city_production_delegate::paint(), pick_random_player_name(), player_by_name(), player_by_name_prefix(), player_by_user(), player_by_user_delegated(), player_name_check(), plocation_field_new(), plrdata_slot_init(), plrdata_slot_replace(), popup_choice_dialog(), popup_hurry_production_dialog(), popup_pillage_dialog(), popup_worklist_editor(), property_editor_add_page(), property_filter_match(), property_page_new(), qtg_get_useable_themes_in_directory(), qtg_gui_load_theme(), races_leader_callback(), real_city_report_dialog_update_city(), real_conn_list_dialog_update(), real_info_city_report_dialog_update(), real_menus_update(), receive_packet_city_info_100(), receive_packet_city_name_suggestion_info_100(), receive_packet_city_rename_100(), receive_packet_city_short_info_100(), receive_packet_edit_city_100(), receive_packet_edit_player_100(), receive_packet_nation_select_req_100(), receive_packet_player_info_100(), receive_packet_ruleset_achievement_100(), receive_packet_ruleset_building_100(), receive_packet_ruleset_city_100(), receive_packet_ruleset_control_100(), receive_packet_ruleset_counter_100(), receive_packet_ruleset_disaster_100(), receive_packet_ruleset_extra_100(), receive_packet_ruleset_extra_flag_100(), receive_packet_ruleset_goods_100(), receive_packet_ruleset_government_100(), receive_packet_ruleset_impr_flag_100(), receive_packet_ruleset_multiplier_100(), receive_packet_ruleset_style_100(), receive_packet_ruleset_tech_100(), receive_packet_ruleset_tech_class_100(), receive_packet_ruleset_tech_flag_100(), receive_packet_ruleset_terrain_100(), receive_packet_ruleset_terrain_flag_100(), receive_packet_ruleset_unit_100(), receive_packet_ruleset_unit_class_100(), receive_packet_ruleset_unit_class_flag_100(), receive_packet_ruleset_unit_flag_100(), receive_packet_save_scenario_100(), receive_packet_scenario_info_100(), receive_packet_server_setting_const_100(), receive_packet_unit_do_action_100(), redraw_unit_info_label(), refresh_city_names(), refresh_production_label(), remove_player_command(), report_demographics(), request_do_action(), research_advance_name_translation(), research_advance_rule_name(), resend_desired_settable_options(), rscompat_setting_needs_special_handling(), rscompat_settings_do_special_handling(), ruleset_cache_listcmd_cb(), ruleset_entry_changed(), ruleset_load_names(), ruleset_selected(), save_actions_ruleset(), save_buildings_ruleset(), save_cities_ruleset(), save_effects_ruleset(), save_game_ruleset(), save_governments_ruleset(), save_name_translation(), save_nations_ruleset(), save_ruleset(), save_styles_ruleset(), save_techs_ruleset(), save_terrain_ruleset(), save_units_ruleset(), science_report_combo_get_active(), search_for_city_name(), secfile_lookup_enum_data(), secfile_lookup_enum_default_data(), secfile_section_by_name(), secfile_section_new(), section_entry_bool_new(), section_entry_by_name(), section_entry_filereference_new(), section_entry_float_new(), section_entry_int_new(), section_entry_str_new(), section_set_name(), send_ruleset_cities(), send_ruleset_team_names(), server_handle_packet(), server_option_bitwise_set(), server_option_enum_set(), server_player_name_is_allowed(), server_player_set_name(), server_player_set_name_full(), server_setting_by_name(), server_ss_by_name(), set_ai_level(), set_ai_level_named(), set_default_ai_type_name(), fc_font::set_font(), set_user_extra_flag_name(), set_user_impr_flag_name(), set_user_tech_flag_name(), set_user_terrain_flag_name(), set_user_unit_class_flag_name(), set_user_unit_type_flag_name(), settable_option_upgrade_value(), setting_bitwise_bit(), setting_bitwise_secfile_str(), setting_bitwise_to_str(), setting_bool_secfile_str(), setting_bool_to_str(), setting_by_name(), setting_enum_secfile_str(), setting_enum_to_str(), setting_enum_val(), setting_match_prefix_base(), setting_ruleset_one(), settings_game_load(), settings_ruleset(), mpgui::setup_list(), setup_modpack_list(), setup_modpack_list(), setup_modpack_list(), setup_modpack_list(), sex_by_name(), sg_load_player_city(), sg_load_player_city(), sg_load_player_main(), sg_load_player_main(), sg_load_player_units(), sg_load_player_units(), sg_load_ruledata(), sg_load_ruledata(), show_full_citybar(), show_small_citybar(), signal_callback_new(), sn_free(), special_by_rule_name(), specialist_by_rule_name(), specialist_by_translated_name(), srv_ready(), ssetv_by_rule_name(), style_by_rule_name(), take_command(), tech_class_by_rule_name(), technology_load(), technology_load(), technology_save(), terrain_by_rule_name(), terrain_by_translated_name(), text_tag_init_from_sequence(), theme_lookup_sprite_tag_alt(), themespec_reread(), tiles_lookup_sprite_tag_alt(), tileset_setup_citizen_types(), tilespec_reread(), timer_new(), timer_renew(), tolua_fcdb_fcdb_option00(), tolua_game_find_action02(), tolua_game_find_counter00(), tolua_game_find_player00(), tolua_game_Tile_has_base00(), tolua_game_Tile_has_extra00(), tolua_game_Tile_has_road00(), tolua_server_edit_create_base00(), tolua_server_edit_create_city00(), tolua_server_edit_create_extra00(), tolua_server_edit_create_owned_extra00(), tolua_server_edit_create_road00(), tolua_server_edit_remove_extra00(), tool_init(), trade_route_cancelling_type_by_name(), trade_route_type_by_name(), transfer_city_units(), unit_do_action(), unit_perform_action(), unit_type_by_rule_name(), unit_type_by_translated_name(), map_view::update_font(), info_tile::update_font(), update_info_label(), user_username(), valid_ruleset_filename(), worklist_load(), and worklist_load().

## ◆ [struct]

struct { ... } tok_tab[INF_TOK_LAST]

Initial value:
=
{
{ "section_name", get_token_section_name },
{ "entry_name", get_token_entry_name },
{ "end_of_line", get_token_eol },
{ "table_start", get_token_table_start },
{ "table_end", get_token_table_end },
{ "comma", get_token_comma },
{ "value", get_token_value },
}
get_token_value
static const char * get_token_value(struct inputfile *inf)
Definition inputfile.c:803
get_token_entry_name
static const char * get_token_entry_name(struct inputfile *inf)
Definition inputfile.c:689
get_token_section_name
static const char * get_token_section_name(struct inputfile *inf)
Definition inputfile.c:661
get_token_table_end
static const char * get_token_table_end(struct inputfile *inf)
Definition inputfile.c:787
get_token_table_start
static const char * get_token_table_start(struct inputfile *inf)
Definition inputfile.c:779
get_token_comma
static const char * get_token_comma(struct inputfile *inf)
Definition inputfile.c:795
get_token_eol
static const char * get_token_eol(struct inputfile *inf)
Definition inputfile.c:729

Referenced by inf_token().