viewmap.c

00001 #include <stdio.h>
00002 #include <sys/shm.h>
00003 #include <sys/stat.h>
00004 #include "map_definitions.h"
00005 
00006 int main ()
00007 {
00008         int segment_id;
00009         char *shared_memory;
00010         char c;
00011         unsigned char tmp;
00012         int i, j ;
00013         const int shared_segment_size = sizeof(char) * MAP_WIDTH * MAP_HEIGHT;
00014 
00015         /* Get segment identificator in a read only mode  */
00016         segment_id = shmget (SHM_MAP_KEY, shared_segment_size,
00017                              S_IRUSR );
00018 
00019         /* Attach the shared memory segment */
00020         shared_memory = (char*) shmat (segment_id, (void*) 0, 0);
00021         printf("Char %d", sizeof(char));
00022         /* Main boucle */
00023         do{
00024                 printf("\n+");
00025                 for(i=0;i<MAP_WIDTH;i++) printf("-");
00026                 printf("+\n");
00027                 for (j=0;j<MAP_HEIGHT;j++){
00028                         printf("|");
00029                         for(i=0;i<MAP_WIDTH;i++){
00030                                 tmp = (*(shared_memory+i+j*MAP_WIDTH));
00031                                 switch (tmp){
00032                                         case MAP_WALL  :        c='#'; break;
00033                                         case MAP_PATH  :        c='*'; break;
00034                                         case MAP_FREE  :        c=' '; break;
00035                                         case MAP_START :        c='S'; break;
00036                                         case MAP_GOAL  :        c='G'; break;
00037                                         default :               c='?'; break;
00038                                 }
00039                                 //printf("%x\t",(*(shared_memory+i+j*MAP_WIDTH)));
00040                                 printf("%c",c );
00041                         }
00042                         printf("|\n");
00043                 }
00044                 printf("+");
00045                 for(i=0;i<MAP_WIDTH;i++) printf("-");
00046                 printf("+\n");
00047                 printf("Enter a modification on the map (-1 to exit)\n");
00048                 printf("x="); scanf("%d",&i);
00049                 printf("y="); scanf("%d",&j);
00050                 printf("(%d,%d)\n", i,j);
00051                 if ((i<MAP_WIDTH) && (j<MAP_HEIGHT) && (i>=0) && (j>=0)) 
00052                         *(shared_memory+i+j*MAP_WIDTH)= MAP_WALL;
00053 
00054         } while (i!= -1);
00055         /* Detach the shared memory segment.  */
00056         shmdt (shared_memory);
00057 
00058         return 0;
00059 }

Generated on Thu Sep 13 11:28:28 2007 for DCE-Eurobot by  doxygen 1.5.3