fprintf_line(stdout, line_string, line_length);
}
+
/* int2str() returns a number converted to a string;
the used memory is static, but will be overwritten by later calls,
so if you want to save the result, copy it to a private string buffer;
}
}
+
/* something similar to "int2str()" above, but allocates its own memory
and has a different interface; we cannot use "itoa()", because this
seems to be already defined when cross-compiling to the win32 target */
{
static char *a = NULL;
- if (a != NULL)
- free(a);
+ checked_free(a);
if (i > 2147483647) /* yes, this is a kludge */
i = 2147483647;
}
+/* calculate base-2 logarithm of argument (rounded down to integer;
+ this function returns the number of the highest bit set in argument) */
+
+int log_2(unsigned int x)
+{
+ int e = 0;
+
+ while ((1 << e) < x)
+ {
+ x -= (1 << e); /* for rounding down (rounding up: remove this line) */
+ e++;
+ }
+
+ return e;
+}
+
+
/* ------------------------------------------------------------------------- */
/* counter functions */
/* ------------------------------------------------------------------------- */
/* random generator functions */
/* ------------------------------------------------------------------------- */
-#if 0
-unsigned int SimpleRND(unsigned int max)
-{
- return (random_linux_libc(RND_FREE) % max);
-}
-
-unsigned int InitSimpleRND(long seed)
-{
- if (seed == NEW_RANDOMIZE)
- {
- struct timeval current_time;
-
- gettimeofday(¤t_time, NULL);
- seed = (long)current_time.tv_usec;
- }
-
- srandom_linux_libc(RND_FREE, (unsigned int) seed);
-
- return (unsigned int) seed;
-}
-
-unsigned int RND(unsigned int max)
-{
- return (random_linux_libc(RND_GAME) % max);
-}
-
-unsigned int InitRND(long seed)
-{
- if (seed == NEW_RANDOMIZE)
- {
- struct timeval current_time;
-
- gettimeofday(¤t_time, NULL);
- seed = (long)current_time.tv_usec;
- }
-
- srandom_linux_libc(RND_GAME, (unsigned int) seed);
-
- return (unsigned int) seed;
-}
-#endif
-
unsigned int init_random_number(int nr, long seed)
{
if (seed == NEW_RANDOMIZE)
return (unsigned int) seed;
}
-#if 1
-unsigned int get_random_number(int nr, unsigned int max)
+unsigned int get_random_number(int nr, int max)
{
return (max > 0 ? random_linux_libc(nr) % max : 0);
}
-#else
-unsigned int get_random_number(int nr, unsigned int max)
-{
- unsigned int rnd = (max > 0 ? random_linux_libc(nr) % max : 0);
-
- if (nr == 0 && FrameCounter < 2)
- printf("::: %d [%d]\n", rnd, FrameCounter);
-
-#if 0
- if (nr == 0 && FrameCounter < 2 && rnd == 8)
- rnd /= 0;
-#endif
-
- return rnd;
-}
-#endif
/* ------------------------------------------------------------------------- */
void setString(char **old_value, char *new_value)
{
- if (*old_value != NULL)
- free(*old_value);
+ checked_free(*old_value);
*old_value = getStringCopy(new_value);
}
if (option_arg == next_option)
options_left++;
- /* adjust path for level directory accordingly */
+ /* adjust paths for sub-directories in base directory accordingly */
options.level_directory =
getPath2(options.ro_base_directory, LEVELS_DIRECTORY);
+ options.graphics_directory =
+ getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY);
+ options.sounds_directory =
+ getPath2(options.ro_base_directory, SOUNDS_DIRECTORY);
+ options.music_directory =
+ getPath2(options.ro_base_directory, MUSIC_DIRECTORY);
+ options.docs_directory =
+ getPath2(options.ro_base_directory, DOCS_DIRECTORY);
}
else if (strncmp(option, "-levels", option_len) == 0)
{
options.execute_command = option_arg;
if (option_arg == next_option)
options_left++;
+
+#if 1
+ /* when doing batch processing, always enable verbose mode (warnings) */
+ options.verbose = TRUE;
+#endif
}
else if (*option == '-')
{
/* ------------------------------------------------------------------------- */
-/* memory allocation functions */
+/* checked memory allocation and freeing functions */
/* ------------------------------------------------------------------------- */
void *checked_malloc(unsigned long size)
return ptr;
}
+void checked_free(void *ptr)
+{
+ if (ptr != NULL) /* this check should be done by free() anyway */
+ free(ptr);
+}
+
/* ------------------------------------------------------------------------- */
/* various helper functions */
*y2 = help_y;
}
-short getFile16BitInteger(FILE *file, int byte_order)
+int getFile16BitInteger(FILE *file, int byte_order)
{
if (byte_order == BYTE_ORDER_BIG_ENDIAN)
- return ((fgetc(file) << 8) |
- (fgetc(file) << 0));
+ return ((fgetc(file) << 8) |
+ (fgetc(file) << 0));
else /* BYTE_ORDER_LITTLE_ENDIAN */
- return ((fgetc(file) << 0) |
- (fgetc(file) << 8));
+ return ((fgetc(file) << 0) |
+ (fgetc(file) << 8));
}
-void putFile16BitInteger(FILE *file, short value, int byte_order)
+void putFile16BitInteger(FILE *file, int value, int byte_order)
{
if (byte_order == BYTE_ORDER_BIG_ENDIAN)
{
- fputc((value >> 8) & 0xff, file);
- fputc((value >> 0) & 0xff, file);
+ fputc((value >> 8) & 0xff, file);
+ fputc((value >> 0) & 0xff, file);
}
else /* BYTE_ORDER_LITTLE_ENDIAN */
{
- fputc((value >> 0) & 0xff, file);
- fputc((value >> 8) & 0xff, file);
+ fputc((value >> 0) & 0xff, file);
+ fputc((value >> 8) & 0xff, file);
}
}
char c = name_ptr[6];
if (c >= '0' && c <= '9')
- key = KSYM_0 + (Key)(c - '0');
+ key = KSYM_KP_0 + (Key)(c - '0');
}
else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6)
{
boolean fileExists(char *filename)
{
+ if (filename == NULL)
+ return FALSE;
+
#if 0
printf("checking file '%s'\n", filename);
#endif
static char *basename_lower = NULL;
int basename_length, prefix_length;
- if (basename_lower != NULL)
- free(basename_lower);
+ checked_free(basename_lower);
if (basename == NULL || prefix == NULL)
return FALSE;
static char *basename_lower = NULL;
int basename_length, suffix_length;
- if (basename_lower != NULL)
- free(basename_lower);
+ checked_free(basename_lower);
if (basename == NULL || suffix == NULL)
return FALSE;
struct ListNodeInfo ***, int *);
struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list,
- struct ConfigInfo *suffix_list,
+ struct ConfigTypeInfo *suffix_list,
char **ignore_tokens,
int num_file_list_entries)
{
#define KNOWN_TOKEN_VALUE "[KNOWN_TOKEN_VALUE]"
static void read_token_parameters(SetupFileHash *setup_file_hash,
- struct ConfigInfo *suffix_list,
+ struct ConfigTypeInfo *suffix_list,
struct FileInfo *file_list_entry)
{
/* check for config token that is the base token without any suffixes */
static void add_dynamic_file_list_entry(struct FileInfo **list,
int *num_list_entries,
SetupFileHash *extra_file_hash,
- struct ConfigInfo *suffix_list,
+ struct ConfigTypeInfo *suffix_list,
int num_suffix_list_entries,
char *token)
{
new_list_entry = &(*list)[*num_list_entries - 1];
new_list_entry->token = getStringCopy(token);
+ new_list_entry->default_filename = NULL;
new_list_entry->filename = NULL;
new_list_entry->parameter = checked_calloc(parameter_array_size);
char *filename)
{
struct FileInfo *file_list = artwork_info->file_list;
- struct ConfigInfo *suffix_list = artwork_info->suffix_list;
+ struct ConfigTypeInfo *suffix_list = artwork_info->suffix_list;
char **base_prefixes = artwork_info->base_prefixes;
char **ext1_suffixes = artwork_info->ext1_suffixes;
char **ext2_suffixes = artwork_info->ext2_suffixes;
/* at this point, we do not need the setup file hash anymore -- free it */
freeSetupFileHash(setup_file_hash);
+#if 1
+ /* map deprecated to current tokens (using prefix match and replace) */
+ BEGIN_HASH_ITERATION(valid_file_hash, itr)
+ {
+ /* !!! make this dynamically configurable (init.c:InitArtworkConfig) !!! */
+ static char *map_token_prefix[][2] =
+ { /* old prefix -> new prefix */
+ { "char_procent", "char_percent" },
+ { NULL, NULL }
+ };
+ char *token = HASH_ITERATION_TOKEN(itr);
+
+ for (i = 0; map_token_prefix[i][0] != NULL; i++)
+ {
+ int token_prefix_length = strlen(map_token_prefix[i][0]);
+
+ if (strncmp(token, map_token_prefix[i][0], token_prefix_length) == 0)
+ {
+ char *value = HASH_ITERATION_VALUE(itr);
+ char *mapped_token = getStringCat2(map_token_prefix[i][1],
+ &token[token_prefix_length]);
+
+ /* add mapped token */
+ setHashEntry(valid_file_hash, mapped_token, value);
+
+ /* ignore old token (by setting it to "known" keyword) */
+ setHashEntry(valid_file_hash, token, known_token_value);
+
+ free(mapped_token);
+
+ break;
+ }
+ }
+ }
+ END_HASH_ITERATION(valid_file_hash, itr)
+#endif
+
/* read parameters for all known config file tokens */
for (i = 0; i < num_file_list_entries; i++)
read_token_parameters(valid_file_hash, suffix_list, &file_list[i]);
#endif
for (i = 0; i < num_dynamic_file_list_entries; i++)
+ {
LoadArtworkToList(artwork_info, &artwork_info->dynamic_artwork_list[i],
dynamic_file_list[i].filename, i);
+#if 0
+ printf("::: '%s', '0x%08x'\n",
+ dynamic_file_list[i].filename,
+ dynamic_file_list[i].default_filename);
+#endif
+ }
+
#if 0
dumpList(artwork_info->content_list);
#endif