rnd-20031203-3-src
[rocksndiamonds.git] / src / libgame / setup.c
index 05978dd4a967e86f1d2eaf8ed6e1b8397737a324..65ba26c79c5fd2a583e7e19dafe29a03fe904471 100644 (file)
@@ -441,6 +441,34 @@ char *getHelpTextFilename()
   return filename;
 }
 
+char *getLevelSetInfoFilename()
+{
+  static char *filename = NULL;
+  char *basenames[] =
+  {
+    "readme",
+    "readme.txt",
+    "README",
+    "README.txt",
+    "README.TXT",
+
+    NULL
+  };
+  int i;
+
+  for (i = 0; basenames[i] != NULL; i++)
+  {
+    if (filename != NULL)
+      free(filename);
+
+    filename = getPath2(getCurrentLevelDir(), basenames[i]);
+    if (fileExists(filename))
+      return filename;
+  }
+
+  return NULL;
+}
+
 static char *getCorrectedArtworkBasename(char *basename)
 {
   char *basename_corrected = basename;
@@ -1178,6 +1206,10 @@ char *getFormattedSetupEntry(char *token, char *value)
   int i;
   static char entry[MAX_LINE_LEN];
 
+  /* if value is an empty string, just return token without value */
+  if (*value == '\0')
+    return token;
+
   /* start with the token and some spaces to format output line */
   sprintf(entry, "%s:", token);
   for (i = strlen(entry); i < TOKEN_VALUE_POSITION; i++)
@@ -1359,6 +1391,14 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value)
       Error(ERR_EXIT, "cannot insert into hash -- aborting");
 }
 
+char *removeHashEntry(SetupFileHash *hash, char *token)
+{
+  if (hash == NULL)
+    return NULL;
+
+  return remove_hash_entry(hash, token);
+}
+
 #if 0
 #ifdef DEBUG
 static void printSetupFileHash(SetupFileHash *hash)
@@ -1375,7 +1415,6 @@ static void printSetupFileHash(SetupFileHash *hash)
 
 static void *loadSetupFileData(char *filename, boolean use_hash)
 {
-  int line_len;
   char line[MAX_LINE_LEN], previous_line[MAX_LINE_LEN];
   char *token, *value, *line_ptr;
   void *setup_file_data, *insert_ptr = NULL;
@@ -1450,38 +1489,37 @@ static void *loadSetupFileData(char *filename, boolean use_hash)
     if (*line == '\0')
       continue;
 
-    line_len = strlen(line);
-
     /* cut leading whitespaces from token */
     for (token = line; *token; token++)
       if (*token != ' ' && *token != '\t')
        break;
 
-    /* find end of token */
+    /* start with empty value as reliable default */
+    value = "";
+
+    /* find end of token to determine start of value */
     for (line_ptr = token; *line_ptr; line_ptr++)
     {
       if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':')
       {
-       *line_ptr = '\0';
+       *line_ptr = '\0';               /* terminate token string */
+       value = line_ptr + 1;           /* set beginning of value */
+
        break;
       }
     }
 
-    if (line_ptr < line + line_len)
-      value = line_ptr + 1;
-    else
-#if 1
-      value = "true";  /* treat tokens without value as "true" */
-#else
-      value = "\0";
-#endif
-
     /* cut leading whitespaces from value */
     for (; *value; value++)
       if (*value != ' ' && *value != '\t')
        break;
 
-    if (*token && *value)
+#if 0
+    if (*value == '\0')
+      value = "true";  /* treat tokens without value as "true" */
+#endif
+
+    if (*token)
     {
       if (use_hash)
        setHashEntry((SetupFileHash *)setup_file_data, token, value);