Added USR1 status shower.
authorviric@llimona
Fri, 16 Feb 2007 23:53:32 +0100
changeset 27 545f73869d65
parent 26 95fccfcbd04c
child 28 cd27cb410375
Added USR1 status shower.
os.c
--- a/os.c	Fri Feb 16 22:57:36 2007 +0100
+++ b/os.c	Fri Feb 16 23:53:32 2007 +0100
@@ -109,8 +109,8 @@
 	for (j = 0; j<Temp.SizeY; j++)
 	{
 		for (i=0; i<Temp.SizeX; i++)
-			fprintf(stderr,"%c", Temp.Cells[j][i]);
-		fprintf(stderr,"\n");
+			fprintf(stdout,"%c", Temp.Cells[j][i]);
+		fprintf(stdout,"\n");
 	}
 
 #if 0
@@ -123,29 +123,34 @@
 	}
 #endif
 
-	fprintf(stderr,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
-	fprintf(stderr,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
+	fprintf(stdout,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
+	fprintf(stdout,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
 			Temp.NumBoxesInPlatform);
 
 }
 
 void PrintMove(const struct BoxMove b)
 {
-	fprintf(stderr,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
+	fprintf(stdout,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
 }
 
 void show_percent_and_map()
 {
-	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
+	fprintf(stdout, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
 		min_depth_period, max_depth_period);
 	if(actual_map != NULL)
 		ShowMap(actual_map);
-	fflush(stderr);
+	fflush(stdout);
 	min_depth_period = MAX_STEPS;
 	max_depth_period = 0;
 }
 
-static void show_percent_callback(const int parameter)
+static void show_percent_usr1_callback(const int parameter)
+{
+	show_percent_and_map();
+}
+
+static void show_percent_alarm_callback(const int parameter)
 {
 	show_percent_and_map();
 	alarm(ALARM_SECONDS);
@@ -156,7 +161,7 @@
         struct sigaction my_action;
         int result;
 
-        my_action.sa_handler = show_percent_callback;
+        my_action.sa_handler = show_percent_alarm_callback;
         my_action.sa_flags = 0;
         memset(&my_action.sa_mask, 0, sizeof(my_action.sa_mask));
 
@@ -166,10 +171,24 @@
 	alarm(1);
 }
 
+static void program_usr1()
+{
+        struct sigaction my_action;
+        int result;
+
+        my_action.sa_handler = show_percent_usr1_callback;
+        my_action.sa_flags = 0;
+        memset(&my_action.sa_mask, 0, sizeof(my_action.sa_mask));
+
+        result = sigaction(SIGUSR1, &my_action, NULL);
+        assert(result == 0);
+}
+
 void init_os()
 {
 #ifndef DEBUG
-//	program_alarm();
+	program_usr1();
+	/* program_alarm();*/
 #endif
 }