rnd-19981124-1
[rocksndiamonds.git] / src / misc.c
index 2c01f36401e0e7eed881a71f23b5e1f4ab2baa3e..5da20e36bdd3cba70de1d1ef759c5cf3f9bfaae8 100644 (file)
@@ -27,6 +27,9 @@
 #include "random.h"
 #include "joystick.h"
 
+/* maximal allowed length of a command line option */
+#define MAX_OPTION_LEN         256
+
 static unsigned long mainCounter(int mode)
 {
   static struct timeval base_time = { 0, 0 };
@@ -226,12 +229,23 @@ char *getHomeDir()
 
 char *getPath2(char *path1, char *path2)
 {
-  char *complete_path = checked_malloc(strlen(path1) + strlen(path2) + 2);
+  char *complete_path = checked_malloc(strlen(path1) + 1 +
+                                      strlen(path2) + 1);
 
   sprintf(complete_path, "%s/%s", path1, path2);
   return complete_path;
 }
 
+char *getPath3(char *path1, char *path2, char *path3)
+{
+  char *complete_path = checked_malloc(strlen(path1) + 1 +
+                                      strlen(path2) + 1 +
+                                      strlen(path3) + 1);
+
+  sprintf(complete_path, "%s/%s/%s", path1, path2, path3);
+  return complete_path;
+}
+
 char *getStringCopy(char *s)
 {
   char *s_copy = checked_malloc(strlen(s) + 1);
@@ -347,10 +361,8 @@ void GetOptions(char *argv[])
       printf("--basepath == '%s'\n", options.base_directory);
 
       /* adjust path for level directory accordingly */
-      options.level_directory = checked_malloc(strlen(options.base_directory) +
-                                              strlen(LEVELS_DIRECTORY) + 2);
-      sprintf(options.level_directory, "%s/%s",
-             options.base_directory, LEVELS_DIRECTORY);
+      options.level_directory =
+       getPath2(options.base_directory, LEVELS_DIRECTORY);
     }
     else if (strncmp(option, "-levels", option_len) == 0)
     {
@@ -409,8 +421,12 @@ void Error(int mode, char *format, ...)
   FILE *output_stream = stderr;
   char *process_name = "";
 
-  if (mode & ERR_SOUNDSERVER)
+  if (mode & ERR_SOUND_SERVER)
     process_name = " sound server";
+  else if (mode & ERR_NETWORK_SERVER)
+    process_name = " network server";
+  else if (mode & ERR_NETWORK_CLIENT)
+    process_name = " network client **";
 
   if (format)
   {