os.c
changeset 27 545f73869d65
parent 26 95fccfcbd04c
child 28 cd27cb410375
equal deleted inserted replaced
26:95fccfcbd04c 27:545f73869d65
   107 	}
   107 	}
   108 
   108 
   109 	for (j = 0; j<Temp.SizeY; j++)
   109 	for (j = 0; j<Temp.SizeY; j++)
   110 	{
   110 	{
   111 		for (i=0; i<Temp.SizeX; i++)
   111 		for (i=0; i<Temp.SizeX; i++)
   112 			fprintf(stderr,"%c", Temp.Cells[j][i]);
   112 			fprintf(stdout,"%c", Temp.Cells[j][i]);
   113 		fprintf(stderr,"\n");
   113 		fprintf(stdout,"\n");
   114 	}
   114 	}
   115 
   115 
   116 #if 0
   116 #if 0
   117 	/* Print Where the man can move */
   117 	/* Print Where the man can move */
   118 	for (j = 0; j<Temp.SizeY; j++)
   118 	for (j = 0; j<Temp.SizeY; j++)
   121 			printf("%c", Temp.ManMoves[j][i]);
   121 			printf("%c", Temp.ManMoves[j][i]);
   122 		printf("\n");
   122 		printf("\n");
   123 	}
   123 	}
   124 #endif
   124 #endif
   125 
   125 
   126 	fprintf(stderr,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
   126 	fprintf(stdout,"Man is at (%i,%i)\n", Temp.Man.x, Temp.Man.y);
   127 	fprintf(stderr,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
   127 	fprintf(stdout,"Platforms: %i, BoxesInPlatform: %i\n", Temp.NumPlatforms,
   128 			Temp.NumBoxesInPlatform);
   128 			Temp.NumBoxesInPlatform);
   129 
   129 
   130 }
   130 }
   131 
   131 
   132 void PrintMove(const struct BoxMove b)
   132 void PrintMove(const struct BoxMove b)
   133 {
   133 {
   134 	fprintf(stderr,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
   134 	fprintf(stdout,"Box: %i, Direction: {%i,%i}\n", b.box, b.dir.x, b.dir.y);
   135 }
   135 }
   136 
   136 
   137 void show_percent_and_map()
   137 void show_percent_and_map()
   138 {
   138 {
   139 	fprintf(stderr, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
   139 	fprintf(stdout, "Percent: %2.12f, depth: %i-%i\n", percent_to_show,
   140 		min_depth_period, max_depth_period);
   140 		min_depth_period, max_depth_period);
   141 	if(actual_map != NULL)
   141 	if(actual_map != NULL)
   142 		ShowMap(actual_map);
   142 		ShowMap(actual_map);
   143 	fflush(stderr);
   143 	fflush(stdout);
   144 	min_depth_period = MAX_STEPS;
   144 	min_depth_period = MAX_STEPS;
   145 	max_depth_period = 0;
   145 	max_depth_period = 0;
   146 }
   146 }
   147 
   147 
   148 static void show_percent_callback(const int parameter)
   148 static void show_percent_usr1_callback(const int parameter)
       
   149 {
       
   150 	show_percent_and_map();
       
   151 }
       
   152 
       
   153 static void show_percent_alarm_callback(const int parameter)
   149 {
   154 {
   150 	show_percent_and_map();
   155 	show_percent_and_map();
   151 	alarm(ALARM_SECONDS);
   156 	alarm(ALARM_SECONDS);
   152 }
   157 }
   153 
   158 
   154 static void program_alarm()
   159 static void program_alarm()
   155 {
   160 {
   156         struct sigaction my_action;
   161         struct sigaction my_action;
   157         int result;
   162         int result;
   158 
   163 
   159         my_action.sa_handler = show_percent_callback;
   164         my_action.sa_handler = show_percent_alarm_callback;
   160         my_action.sa_flags = 0;
   165         my_action.sa_flags = 0;
   161         memset(&my_action.sa_mask, 0, sizeof(my_action.sa_mask));
   166         memset(&my_action.sa_mask, 0, sizeof(my_action.sa_mask));
   162 
   167 
   163         result = sigaction(SIGALRM, &my_action, NULL);
   168         result = sigaction(SIGALRM, &my_action, NULL);
   164         assert(result == 0);
   169         assert(result == 0);
   165 
   170 
   166 	alarm(1);
   171 	alarm(1);
   167 }
   172 }
   168 
   173 
       
   174 static void program_usr1()
       
   175 {
       
   176         struct sigaction my_action;
       
   177         int result;
       
   178 
       
   179         my_action.sa_handler = show_percent_usr1_callback;
       
   180         my_action.sa_flags = 0;
       
   181         memset(&my_action.sa_mask, 0, sizeof(my_action.sa_mask));
       
   182 
       
   183         result = sigaction(SIGUSR1, &my_action, NULL);
       
   184         assert(result == 0);
       
   185 }
       
   186 
   169 void init_os()
   187 void init_os()
   170 {
   188 {
   171 #ifndef DEBUG
   189 #ifndef DEBUG
   172 //	program_alarm();
   190 	program_usr1();
       
   191 	/* program_alarm();*/
   173 #endif
   192 #endif
   174 }
   193 }
   175 
   194