From 1044318e9dd0a6dfe000b5fe1bf11109a01e9ce5 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3deyes@gmail.com>
Date: Fri, 27 Mar 2015 09:41:50 +0300
Subject: Add Haiku support


diff --git a/BillardGL.cpp b/BillardGL.cpp
index 1566fe3..39f934d 100644
--- a/BillardGL.cpp
+++ b/BillardGL.cpp
@@ -11,6 +11,10 @@
 #include <math.h>
 #include <string.h>
 
+#if defined(__HAIKU__)
+#include <unistd.h>
+#endif
+
 #include "Textfeld.h"
 #include "Schild.h"
 #include "Tisch.h"
@@ -262,7 +266,16 @@ void timerEvent() {
 
 int main(int argc, char **argv)
 { 
-  //char string[10];  
+  //char string[10];
+#if defined(__HAIKU__)  
+  if (argc && argv[0]) {
+ 	char * slash = strrchr(argv[0], '/');
+	char c = *(slash+1);
+	*(slash + 1) = '\0';
+	chdir(argv[0]);
+	*(slash + 1) = c;
+  }
+#endif
 
   KommandoZeilenParameter(argc,argv);
   
@@ -285,7 +298,11 @@ int main(int argc, char **argv)
     glutFullScreen();
   } else {
     glutInitWindowSize (BildschirmAufloesung,(BildschirmAufloesung*3)/4);
+#if !defined(__HAIKU__)
     glutInitWindowPosition (0, 0);
+#else
+	glutInitWindowPosition (100, 100);
+#endif
     glutCreateWindow ("BillardGL 1.7");
   }
 
diff --git a/KommandoZeilenParameter.cpp b/KommandoZeilenParameter.cpp
index 5ff8285..44cdae7 100644
--- a/KommandoZeilenParameter.cpp
+++ b/KommandoZeilenParameter.cpp
@@ -8,8 +8,13 @@
 void SchreibeKonfiguration(){
   FILE *f;
 #ifndef _WIN32
-  char dateiname[40];
+  char dateiname[80];
+#ifdef __HAIKU__
+  sprintf(dateiname,"%s/config/settings/BillardGL.conf.v7",getenv("HOME"));
+#else
   sprintf(dateiname,"%s/.BillardGL.conf.v7",getenv("HOME"));
+#endif  
+  
   f=fopen(dateiname,"w+");
 #endif
 #ifdef _WIN32
@@ -65,8 +70,12 @@ void SchreibeKonfiguration(){
 void LeseKonfiguration(){
   FILE *f;
 #ifndef _WIN32
-  char dateiname[40];
-  sprintf(dateiname,"%s/.BillardGL.conf.v7",getenv("HOME"));
+  char dateiname[80];
+#ifdef __HAIKU__
+  sprintf(dateiname,"%s/config/settings/BillardGL.conf.v7",getenv("HOME"));
+#else  
+   sprintf(dateiname,"%s/.BillardGL.conf.v7",getenv("HOME"));
+#endif  
   f=fopen(dateiname,"r");
 #endif
 #ifdef _WIN32
@@ -153,8 +162,11 @@ void KommandoZeilenParameter(int argc,char **argv) {
   AmbientesLicht       = 1;
   TischLampen          = 2;
   GrueneLampe          = 0;
-
+#if defined(__HAIKU__)
+  FullScreen           = 0;
+#else
   FullScreen           = 1;
+#endif  
 
   EffektLautstaerke    = .5;
   MusikLautstaerke     = .5;
diff --git a/Makefile b/Makefile
index 2418824..75af448 100644
--- a/Makefile
+++ b/Makefile
@@ -8,11 +8,11 @@
 CC	=	gcc
 CXX	=	g++
 CFLAGS	=	-pipe -Wall -W -DNO_DEBUG -g
-CXXFLAGS=	-pipe -Wall -W -DNO_DEBUG -g 
+CXXFLAGS=	-pipe -Wall -W -DNO_DEBUG
 INCPATH	=	-I/usr/X11R6/include 
 LINK	=	g++
 LFLAGS	=	
-LIBS	=	-L/usr/X11R6/lib -lGL -lGLU -lglut -lXmu -lXext -lX11 -lm -lXi
+LIBS	=	-lGL -lGLU -lglut
 
 ## -lqgl -lGLU
 
diff --git a/Namen.h b/Namen.h
index fa3874b..b04a5c1 100644
--- a/Namen.h
+++ b/Namen.h
@@ -22,7 +22,7 @@
 #define COMPUTERGEGNERSPIEL 104
 #define TUTORIAL 105
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__HAIKU__)
 #define PFAD "/usr/share/BillardGL/"
 #endif
 
-- 
2.23.0


From 45d89f9b8e2d1a73a6568c631df5bca7de55c717 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 25 Nov 2018 12:29:17 +1000
Subject: Fix build for gcc7


diff --git a/bmp.cpp b/bmp.cpp
index 2dafaac..6d92960 100644
--- a/bmp.cpp
+++ b/bmp.cpp
@@ -4,14 +4,15 @@
 // Modified by Volker Blanz, 25.4.2001
 //
 
-#include <iostream.h>
-#include <fstream.h>
+#include <iostream>
+#include <fstream>
 #include <stdio.h>
 #include <string.h>
 #include "LA.h"
 #include "Namen.h"
 #include "bmp.h"
 
+using namespace std;
 // from ioutil:
 
 WORDX readWord(FILE *f) {
-- 
2.23.0


From 5b8e9509363f2ddc79c94661a7e7b5fa28787e81 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 5 Sep 2019 23:17:51 +1000
Subject: Resolve symlink


diff --git a/BillardGL.cpp b/BillardGL.cpp
index 39f934d..a6965e7 100644
--- a/BillardGL.cpp
+++ b/BillardGL.cpp
@@ -268,12 +268,12 @@ int main(int argc, char **argv)
 { 
   //char string[10];
 #if defined(__HAIKU__)  
-  if (argc && argv[0]) {
- 	char * slash = strrchr(argv[0], '/');
-	char c = *(slash+1);
-	*(slash + 1) = '\0';
-	chdir(argv[0]);
-	*(slash + 1) = c;
+  char *binpath = realpath(argv[0], NULL);
+  if (binpath != NULL) {
+    char *appdir = strrchr(binpath, '/');
+    *appdir = '\0';
+    chdir(binpath);
+    free(binpath);
   }
 #endif
 
-- 
2.23.0

