/* * Copyright (C) 2002-2007 The Warp Rogue Team * Part of the Warp Rogue Project * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License. * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY. * * See the license.txt file for more details. */ /* * Module Name: Util * Description: Misc. utility functions */ #define ASCII_LF 0x0A #define ASCII_CR 0x0D #define ascii_to_integer(c) ((c) - '0') #define strings_equal(s1,s2) (strcmp((s1),(s2)) == 0) #define is_empty_string(s) ((s)[0] == '\0') #define clear_string(s) ((s)[0] = '\0') #define random_choice(p) (random_int(1, 100) <= (p)) #define sgn(x) ((x) == 0 ? 0 :((x) > 0 ? 1 : -1)) typedef int COORD_MODIFIER; typedef enum { COORD_Y, COORD_X } COORD_TYPE; COORD_MODIFIER direction_modifier(COORD_TYPE, DIRECTION); DIRECTION name_to_direction(const char *); DIRECTION * randomised_directions(DIRECTION *); void * checked_malloc(size_t); void * checked_realloc(void *, size_t); int divide_and_round_up(int, int); int percent(int, int); char * string_to_lowercase(char *); bool menu_key_to_index(int *, KEY_CODE, int); FILE * open_file(const char *, const char *); void close_file(FILE *); bool file_exists(const char *); long int file_length(FILE *); char * read_text_file(char *, PROGRAM_DIRECTORY, const char *);