#

mrbayes-3.1.2_no_tty_no_readline.patch

--- mrbayes-3.1.2.orig/bayes.c	2005-12-23 11:26:28.000000000 -0500
+++ mrbayes-3.1.2.patched/bayes.c	2009-06-05 01:12:51.000117000 -0400
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "mb.h"
 #include "globals.h"
 #include "bayes.h"
@@ -279,20 +280,69 @@
 			if (proc_id == 0)
 				{
 	#ifdef USE_READLINE
-		    cmdStrP = readline("MrBayes > ");
-			if(cmdStrP!=NULL) 
-			        {
-					strncpy(cmdStr,cmdStrP,CMD_STRING_LENGTH - 2);
-					if (*cmdStrP) 
-						add_history(cmdStrP);
-					free (cmdStrP);
-			        }
-			else /* fall through to if (feof(stdin))..*/
+			if (isatty(0))
+				{
+				cmdStrP = readline("MrBayes > ");
+				if(cmdStrP!=NULL) 
+						{
+						strncpy(cmdStr,cmdStrP,CMD_STRING_LENGTH - 2);
+						if (*cmdStrP) 
+							add_history(cmdStrP);
+						free (cmdStrP);
+						}
+				else
+						{
+						if (feof(stdin))
+							MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
+						else
+							MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
+						strcpy (cmdStr,"quit;n");
+						}
+				}
+			else
+				{
+					MrBayesPrint ("MrBayes > ");
+					fflush (stdin);
+					if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+						{
+						if (feof(stdin))
+							MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
+						else
+							MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
+						strcpy (cmdStr,"quit;n");
+						}
+				}
      #else
-				MrBayesPrint ("MrBayes > ");
-				fflush (stdin);
-				if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+					MrBayesPrint ("MrBayes > ");
+					fflush (stdin);
+					if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+						{
+						if (feof(stdin))
+							MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
+						else
+							MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
+						strcpy (cmdStr,"quit;n");
+						}
      #endif
+				}
+			ierror = MPI_Bcast (&cmdStr, CMD_STRING_LENGTH, MPI_CHAR, 0, MPI_COMM_WORLD);
+			if (ierror != MPI_SUCCESS)
+				{
+				MrBayesPrint ("%s   Problem broadcasting command stringn", spacer);
+				}
+#			else
+	#ifdef USE_READLINE
+			if (isatty(0))
+				{
+				cmdStrP = readline("MrBayes > ");
+				if(cmdStrP!=NULL) 
+						{
+						strncpy(cmdStr,cmdStrP,CMD_STRING_LENGTH - 2);
+						if (*cmdStrP) 
+							add_history(cmdStrP);
+						free (cmdStrP);
+						}
+				else
 					{
 					if (feof(stdin))
 						MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
@@ -301,34 +351,31 @@
 					strcpy (cmdStr,"quit;n");
 					}
 				}
-			ierror = MPI_Bcast (&cmdStr, CMD_STRING_LENGTH, MPI_CHAR, 0, MPI_COMM_WORLD);
-			if (ierror != MPI_SUCCESS)
+			else
 				{
-				MrBayesPrint ("%s   Problem broadcasting command stringn", spacer);
+				MrBayesPrint ("MrBayes > ");
+				fflush (stdin);
+				if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+					{
+					if (feof(stdin))
+						MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
+					else
+						MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
+					strcpy (cmdStr,"quit;n");
+					}
 				}
-#			else
-	#ifdef USE_READLINE
-		    cmdStrP = readline("MrBayes > ");
-			if(cmdStrP!=NULL) 
-			        {
-					strncpy(cmdStr,cmdStrP,CMD_STRING_LENGTH - 2);
-					if (*cmdStrP) 
-						add_history(cmdStrP);
-					free (cmdStrP);
-			        }
-			else /* fall through to if (feof(stdin))..*/
 	#else
-			MrBayesPrint ("MrBayes > ");
-			fflush (stdin);
-			if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+				MrBayesPrint ("MrBayes > ");
+				fflush (stdin);
+				if (fgets (cmdStr, CMD_STRING_LENGTH - 2, stdin) == NULL)
+					{
+					if (feof(stdin))
+						MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
+					else
+						MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
+					strcpy (cmdStr,"quit;n");
+					}
 	#endif
-				{
-				if (feof(stdin))
-					MrBayesPrint ("%s   End of File encountered on stdin; quittingn", spacer);
-				else
-					MrBayesPrint ("%s   Could not read command from stdin; quittingn", spacer);
-				strcpy (cmdStr,"quit;n");
-				}
 #			endif
 			}
 		i = 0;

CC BY-NC 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Permissions beyond the scope of this license may be available at Attribution.