char *from_ptr = real_name;
char *to_ptr = real_name_new;
- if (strchr(real_name, 'ß') == NULL) /* name does not contain 'ß' */
- {
- strncpy(real_name_new, real_name, MAX_USERNAME_LEN);
- real_name_new[MAX_USERNAME_LEN] = '\0';
-
- return real_name_new;
- }
-
- /* the user's real name may contain a 'ß' character (german sharp s),
- which has no equivalent in upper case letters (which our fonts use) */
+ /* copy the name string, but not more than MAX_USERNAME_LEN characters */
while (*from_ptr && (long)(to_ptr - real_name_new) < MAX_USERNAME_LEN - 1)
{
- if (*from_ptr != 'ß')
- *to_ptr++ = *from_ptr++;
- else
+ /* the name field read from "passwd" file may also contain additional
+ user information, separated by commas, which will be removed here */
+ if (*from_ptr == ',')
+ break;
+
+ /* the user's real name may contain 'ß' characters (german sharp s),
+ which have no equivalent in upper case letters (used by our fonts) */
+ if (*from_ptr == 'ß')
{
from_ptr++;
*to_ptr++ = 's';
*to_ptr++ = 's';
}
+ else
+ *to_ptr++ = *from_ptr++;
}
*to_ptr = '\0';
}
+/* ------------------------------------------------------------------------- */
+/* path manipulation functions */
+/* ------------------------------------------------------------------------- */
+
+static char *getLastPathSeparatorPtr(char *filename)
+{
+ char *last_separator = strrchr(filename, '/');
+
+#if !defined(PLATFORM_UNIX)
+ if (last_separator == NULL) /* also try DOS/Windows variant */
+ last_separator = strrchr(filename, '\\');
+#endif
+
+ return last_separator;
+}
+
+static char *getBaseNamePtr(char *filename)
+{
+ char *last_separator = getLastPathSeparatorPtr(filename);
+
+ if (last_separator != NULL)
+ return last_separator + 1; /* separator found: strip base path */
+ else
+ return filename; /* no separator found: filename has no path */
+}
+
+char *getBaseName(char *filename)
+{
+ return getStringCopy(getBaseNamePtr(filename));
+}
+
+char *getBasePath(char *filename)
+{
+ char *basepath = getStringCopy(filename);
+ char *last_separator = getLastPathSeparatorPtr(basepath);
+
+ if (last_separator != NULL)
+ *last_separator = '\0'; /* separator found: strip basename */
+ else
+ basepath = "."; /* no separator found: use current path */
+
+ return basepath;
+}
+
+
/* ------------------------------------------------------------------------- */
/* various string functions */
/* ------------------------------------------------------------------------- */
void GetOptions(char *argv[], void (*print_usage_function)(void))
{
+ char *ro_base_path = RO_BASE_PATH;
+ char *rw_base_path = RW_BASE_PATH;
char **options_left = &argv[1];
+#if !defined(PLATFORM_MACOSX)
+ /* if the program is configured to start from current directory (default),
+ determine program package directory (KDE/Konqueror does not do this by
+ itself and fails otherwise); on Mac OS X, the program binary is stored
+ in an application package directory -- do not try to use this directory
+ as the program data directory (Mac OS X handles this correctly anyway) */
+
+ if (strcmp(ro_base_path, ".") == 0)
+ ro_base_path = program.command_basepath;
+ if (strcmp(rw_base_path, ".") == 0)
+ rw_base_path = program.command_basepath;
+#endif
+
/* initialize global program options */
options.display_name = NULL;
options.server_host = NULL;
options.server_port = 0;
- options.ro_base_directory = RO_BASE_PATH;
- options.rw_base_directory = RW_BASE_PATH;
- options.level_directory = RO_BASE_PATH "/" LEVELS_DIRECTORY;
- options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY;
- options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY;
- options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY;
- options.docs_directory = RO_BASE_PATH "/" DOCS_DIRECTORY;
+ options.ro_base_directory = ro_base_path;
+ options.rw_base_directory = rw_base_path;
+ options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY);
+ options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY);
+ options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY);
+ options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY);
+ options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY);
options.execute_command = NULL;
options.serveronly = FALSE;
options.network = FALSE;
Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
/* this should be extended to separate options for ro and rw data */
- options.ro_base_directory = option_arg;
- options.rw_base_directory = option_arg;
+ options.ro_base_directory = ro_base_path = option_arg;
+ options.rw_base_directory = rw_base_path = option_arg;
if (option_arg == next_option)
options_left++;
/* 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);
+ options.level_directory = getPath2(ro_base_path, LEVELS_DIRECTORY);
+ options.graphics_directory = getPath2(ro_base_path, GRAPHICS_DIRECTORY);
+ options.sounds_directory = getPath2(ro_base_path, SOUNDS_DIRECTORY);
+ options.music_directory = getPath2(ro_base_path, MUSIC_DIRECTORY);
+ options.docs_directory = getPath2(ro_base_path, DOCS_DIRECTORY);
}
else if (strncmp(option, "-levels", option_len) == 0)
{
boolean FileIsGraphic(char *filename)
{
- char *basename = strrchr(filename, '/');
-
- basename = (basename != NULL ? basename + 1 : filename);
+ char *basename = getBaseNamePtr(filename);
return fileHasSuffix(basename, "pcx");
}
boolean FileIsSound(char *filename)
{
- char *basename = strrchr(filename, '/');
-
- basename = (basename != NULL ? basename + 1 : filename);
+ char *basename = getBaseNamePtr(filename);
return fileHasSuffix(basename, "wav");
}
boolean FileIsMusic(char *filename)
{
- char *basename = strrchr(filename, '/');
-
- basename = (basename != NULL ? basename + 1 : filename);
+ char *basename = getBaseNamePtr(filename);
if (FileIsSound(basename))
return TRUE;
/* functions for loading artwork configuration information */
/* ------------------------------------------------------------------------- */
+char *get_mapped_token(char *token)
+{
+ /* !!! make this dynamically configurable (init.c:InitArtworkConfig) !!! */
+ static char *map_token_prefix[][2] =
+ {
+ { "char_procent", "char_percent" },
+ { NULL, }
+ };
+ int i;
+
+ for (i = 0; map_token_prefix[i][0] != NULL; i++)
+ {
+ int len_token_prefix = strlen(map_token_prefix[i][0]);
+
+ if (strncmp(token, map_token_prefix[i][0], len_token_prefix) == 0)
+ return getStringCat2(map_token_prefix[i][1], &token[len_token_prefix]);
+ }
+
+ return NULL;
+}
+
/* This function checks if a string <s> of the format "string1, string2, ..."
exactly contains a string <s_contained>. */
/* 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);
+ char *mapped_token = get_mapped_token(token);
- for (i = 0; map_token_prefix[i][0] != NULL; i++)
+ if (mapped_token != NULL)
{
- 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);
+ char *value = HASH_ITERATION_VALUE(itr);
- /* ignore old token (by setting it to "known" keyword) */
- setHashEntry(valid_file_hash, token, known_token_value);
+ /* add mapped token */
+ setHashEntry(valid_file_hash, mapped_token, value);
- free(mapped_token);
+ /* ignore old token (by setting it to "known" keyword) */
+ setHashEntry(valid_file_hash, token, known_token_value);
- break;
- }
+ free(mapped_token);
}
}
END_HASH_ITERATION(valid_file_hash, itr)
boolean base_prefix_found = FALSE;
boolean parameter_suffix_found = FALSE;
+#if 0
+ printf("::: examining '%s' -> '%s'\n", token, HASH_ITERATION_VALUE(itr));
+#endif
+
/* skip all parameter definitions (handled by read_token_parameters()) */
for (i = 0; i < num_suffix_list_entries && !parameter_suffix_found; i++)
{
char *basename = file_list_entry->filename;
char *filename = getCustomArtworkFilename(basename, artwork_info->type);
+#if 0
+ if (strcmp(file_list_entry->token, "background.DOOR") == 0)
+ printf("::: replaceArtworkListEntry: '%s' => '%s'\n",
+ basename, filename);
+#endif
+
if (filename == NULL)
{
Error(ERR_WARN, "cannot find artwork file '%s'", basename);
return;
}
+#if 0
+ if (strcmp(file_list_entry->token, "background.DOOR") == 0)
+ printf("::: replaceArtworkListEntry: LOAD IT'\n");
+#endif
+
#if 0
printf("::: %s: '%s'\n", init_text[artwork_info->type], basename);
#endif
printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename);
#endif
+#if 0
+ if (strcmp(file_list_entry->token, "background.DOOR") == 0)
+ printf("::: -> '%s' -> '%s'\n",
+ file_list_entry->token, file_list_entry->filename);
+#endif
+
if (strcmp(file_list_entry->filename, UNDEFINED_FILENAME) == 0)
{
deleteArtworkListEntry(artwork_info, listnode);
#if 0
printf("loading artwork '%s' ... [%d]\n",
- basename, getNumNodes(artwork_info->content_list));
+ file_list_entry->filename, getNumNodes(artwork_info->content_list));
#endif
#if 1
for (i = 0; i < num_file_list_entries; i++)
{
#if 0
- if (strcmp(file_list[i].token, "background") == 0)
+ if (strcmp(file_list[i].token, "background.DOOR") == 0)
printf("::: '%s' -> '%s'\n", file_list[i].token, file_list[i].filename);
#endif
file_list[i].filename, i);
#endif
+#if 0
+ if (strcmp(file_list[i].token, "background.DOOR") == 0)
+ {
+ Bitmap *bitmap = getBitmapFromImageID(i);
+
+ printf("::: BITMAP: %08lx\n", bitmap);
+
+#if 0
+ BlitBitmap(bitmap, window, 0, 0, 100, 280, 0, 0);
+#endif
+ }
+#endif
+
#if 0
/* !!! NEW ARTWORK FALLBACK CODE !!! NEARLY UNTESTED !!! */
if (artwork_info->artwork_list[i] == NULL &&