Esempio n. 1
0
/* Clear, generate and display the map */
void draw_map( CHAR_DATA *ch, char *desc )
{
  int x, y;
  static char buf[MAX_STRING_LENGTH];

  xprintf( buf, desc );
  /* Remove undesirable characters */
  reformat_desc( buf );

  /* Clear map */
  for( y = 0; y <= MAPY; y++ )
  {
    for( x = 0; x <= MAPX; x++ )
    {
      clear_coord( x, y );
    }
  }

  /* Start with players pos at centre of map */
  x = MAPX / 2;
  y = MAPY / 2;

  map[x][y].vnum = ch->in_room->vnum;
  map[x][y].depth = 0;

  /* Generate the map */
  map_exits( ch, ch->in_room, x, y, 0 );

  /* Current position should be a "X" */
  map[x][y].tegn = 'X';

  /* Send the map */
  show_map( ch, buf );
}
Esempio n. 2
0
void	resolve_sudo(char *str, int num)
{
  int	**map;
  int	*order_priority;

  if (num > 0)
    printf("####################\n");
  if ((order_priority = malloc(sizeof(int) * (81))) == NULL)
    return ;
  map = NULL;
  map = mllc_map(map);
  put_nbr_in_map_to_2d(str, map, num);
  if ((check_error_solvable(map)) == -1)
    {
      show_X();
      return ;
    }
  put_priority_in_map(map);
  get_order_to_resolve(order_priority, map);
  replace_all_zero(map, 0, order_priority);
  if ((check_error_solvable(map)) == -1)
    {
      show_X();
      return ;
    }
  show_map(map);
  free_tabs(order_priority, map);
}
Esempio n. 3
0
void	algo(char before[SIZE_X][SIZE_Y], char after[SIZE_X][SIZE_Y], int turn)
{
	int	i;
	int j;

	i = -1;
	j = -1;
	if (turn == 0)
		turn = -1;
	while (turn != 0)
	{
		while (++i < SIZE_X)
		{
			while (++j < SIZE_Y)
			{
				if (check_around(before, i, j) == 3)
					after[i][j] = 1;
				else if (check_around(before, i, j) == 2 && before[i][j] == 1)
					after[i][j] = 1;
				else
					after[i][j] = 0;
			}
			j = -1;
		}
		i = -1;
		copy_map(after, before);
		clear_map(after);
		ft_putstr("\033[H\033[2J");
		show_map(before);
		usleep(TURN_TIME);
		if (turn != -1)
			--turn;
	}
}
Esempio n. 4
0
int		main(int ac, char **av)
{
  int		v;
  t_map		map;
  t_graph	**pile;

  if (ac != 2)
    return (1);
  if (load_map(&map, av[1]) == -1 ||
      create_graph(&map) == -1 ||
      link_room(&map) == -1)
    return (1);
  if ((pile = malloc(sizeof(t_graph *))) == NULL)
    return (1);
  *pile = NULL;
  if ((v = search_path(map.start, map.end, &pile)) == 0)
    {
      printf("No solution found\n");
      return (1);
    }
  else if (v == -1)
    return (2);
  set_path(map.end);
  show_map(&map);
  free(pile);
  free_all(&map);
  return (0);
}
Esempio n. 5
0
int main()
{
  printf("%s\n","BattleShip!");
  player_score=0;
  computer_score=0;
  srand(time(0));
  inut_hitmap();
  inut_map();
  inut_buffer(); 
  place_ships();
  
   while(1)
   {
     show_map();
     shoot();//defult shooting algerithm just shoots at random coordnets; really sucks as a player
     gethit();
     
     if(win()>1 || ships_left()<=0)
        break;
   }

   if(computer_score>player_score)
       printf("%s\n","computer wins");
   else if(computer_score<player_score)
       printf("%s\n","player wins");
   else if(computer_score==player_score)
       printf("%s\n","tie, howd that happen");  

}
int main(int argc, char *argv[])
{
    int usage = 1;
    
    for(argc--, argv++; argc > 0; argc--, argv++) {
        if(!strcmp(argv[0],"-v")) {
            verbose = 1;
            continue;
        }
        if(!strcmp(argv[0],"-t")) {
            terse = 1;
            continue;
        }
        if(!strcmp(argv[0],"-a")) {
            addresses = 1;
            continue;
        }
        show_map(atoi(argv[0]));
        usage = 0;
    }

    if(usage) {
        fprintf(stderr,
                "showmap [-t] [-v] [-c] <pid>\n"
                "        -t = terse (show only items with private pages)\n"
                "        -v = verbose (don't coalesce adjacant maps)\n"
                "        -a = addresses (show virtual memory map)\n"
                );
    }

	return 0;
}
Esempio n. 7
0
void show_route(int **maze, TCellPtr pstack, int nrow, int ncol, int top)
{
	int i, j;
	int choice = 1; // 用于保存输出选项 
	int ** newmap = setup_mat( nrow, ncol); //newmap[][]存放迷宫的出路路径图中的迷宫单元 
	for(i = 0; i < nrow; i++)  
		for( j = 0; j < ncol; j++)
			newmap[i][j] = GWALL;  // 采用字符“#”填充整个迷宫

	while(choice)
	{
		printf("\n请选择显示方式:\n  1.显示原始迷宫图\n  2.显示迷宫出路路径坐标\n  3.显示迷宫出路模拟图\n  0.结束游戏\n");
		printf("\n请选择相应的数字: ");
		scanf_s("%d", &choice);
		getchar();

		switch(choice){    //选择显示方式			
		case 0:
			break;
		case 1:
			show_map(maze, nrow, ncol);
			break;
		case 2:
			{
				printf("\n迷宫出路路径为:");     //输出出路路径
				printf("\n行\t列");
				for( i = 0; i <= top; i++)
					printf("\n%d\t%d", pstack[i].row, pstack[i].col);
				printf("\n%d\t%d",nrow, ncol);
				//choice = 0;
				break;
			}
		case 3:
			{
				// 采用符号“-”填充与路径相对应的迷宫单元
				for( i = 0; i <= top; i++){
					newmap[pstack[i].row][pstack[i].col] = GPATH;
				}
				newmap[nrow - 2][ncol - 2] = GPATH; // 填充出口单元

				printf("\n迷宫的出路模拟显示图形如下\n");
				//输出迷宫穿越路线图
				for(i = 0; i < nrow; i++) {  
					for( j = 0; j < ncol; j++){
						printf("%c ", newmap[i][j]);
					}
					printf("\n");
				}
				break;
			}
		default:
			{
				printf("输入错误,请重新输入!\n");
				scanf_s("%d", &choice);
			}
		}//switch(choice)
	}//while(choice)
	destroy_map(newmap,  nrow); // 回收为迷宫地图分配的内存空间
}
Esempio n. 8
0
void show_screen() {
  graphmode();
  show_map();
  show_sm_map();
  show_side();
  show_player();
  show_messages();
  }
Esempio n. 9
0
/**************************************************
*
*   FUNCTION:
*       print_table - "Print Table"
*
*   DESCRIPTION:
*       Prints the symbol table.
*
*   RETURNS:
*       Returns an error code
*
*   ERRORS:
*       * Returns SYM_PRINT_ERROR if there was
*         an error encountered while printing
*         anything
*       * Returns SYM_NO_ERROR if no errors were
*         encountered
*
**************************************************/
sym_table_error_t8 print_table
(
    void
)
{
    if( ERR_NO_ERROR != show_map( __keyword_table, __print_entry ) )
    {
        return( SYM_PRINT_ERROR );
    }

    if( ERR_NO_ERROR != show_map( __id_table, __print_entry ) )
    {
        return( SYM_PRINT_ERROR );
    }

    return( SYM_NO_ERROR );

}   /* print_table() */
Esempio n. 10
0
static void show_maps(struct uio_info_t *info)
{
	int ret;
	int mi = 0;
	do {
		ret = show_map(info, mi);
		mi++;
	} while ((ret == 0)&&(mi < MAX_UIO_MAPS));
}
int main(int argc, char *argv[])
{
    int usage = 1;
    int result = 0;
    int pid;
    char *arg;
    char *argend;

    signal(SIGPIPE, SIG_IGN);
    for (argc--, argv++; argc > 0; argc--, argv++) {
        arg = argv[0];
        if (!strcmp(arg,"-v")) {
            verbose = true;
            continue;
        }
        if (!strcmp(arg,"-t")) {
            terse = true;
            continue;
        }
        if (!strcmp(arg,"-a")) {
            addresses = true;
            continue;
        }
        if (!strcmp(arg,"-q")) {
            quiet = true;
            continue;
        }
        if (argc != 1) {
            fprintf(stderr, "too many arguments\n");
            break;
        }
        pid = strtol(arg, &argend, 10);
        if (*arg && !*argend) {
            usage = 0;
            if (show_map(pid)) {
                result = 1;
            }
            break;
        }
        fprintf(stderr, "unrecognized argument: %s\n", arg);
        break;
    }

    if (usage) {
        fprintf(stderr,
                "showmap [-t] [-v] [-c] [-q] <pid>\n"
                "        -t = terse (show only items with private pages)\n"
                "        -v = verbose (don't coalesce maps with the same name)\n"
                "        -a = addresses (show virtual memory map)\n"
                "        -q = quiet (don't show error if map could not be read)\n"
                );
        result = 1;
    }

    return result;
}
Esempio n. 12
0
int			main(int ac, char **av)
{
	char	before[SIZE_X][SIZE_Y];
	char	after[SIZE_X][SIZE_Y];

	(void)ac;
	clear_map(before);
	clear_map(after);
	init_map(before, ft_atoi(av[1]));
	show_map(before);
	usleep(TURN_TIME);
	algo(before, after, ft_atoi(av[2]));
	return (0);
}
Esempio n. 13
0
int	display_map(t_player *p, char is_first_player, char gui)
{
  if (is_first_player)
    {
      if (gui)
	{
          if (send_msg(p->ids[MSG], T_REFRESH, 0) ||
              receive_msg(p->ids[MSG], T_DONE, 0) == -1)
            return (FAILURE);
        }
      else
        show_map(p->map, p->m_size);
    }
  return (SUCCESS);
}
Esempio n. 14
0
/* Clear, generate and display the map */
void draw_room_map( CHAR_DATA * ch, const char *desc )
{
	int x, y;
	static char buf[MAX_STRING_LENGTH];

	mudstrlcpy( buf, desc, MAX_STRING_LENGTH );
	/*
	 * Remove undesirable characters 
	 */
	reformat_desc( buf );

	/*
	 * Clear map 
	 */
	for ( y = 0; y <= MAPY; ++y )
	{
		for ( x = 0; x <= MAPX; ++x )
		{
			clear_coord( x, y );
		}
	}

	/*
	 * Start with players pos at centre of map 
	 */
	x = MAPX / 2;
	y = MAPY / 2;

	dmap[x][y].vnum = ch->in_room->vnum;
	dmap[x][y].depth = 0;

	/*
	 * Generate the map 
	 */
	map_exits( ch, ch->in_room, x, y, 0 );

	/*
	 * Current position should be a "X" 
	 */
	dmap[x][y].tegn = '@';
	dmap[x][y].sector = -1;

	/*
	 * Send the map 
	 */
	show_map( ch, buf );
}
Esempio n. 15
0
void do_map( char_data* ch, char* argument )
{
  int flags;
  int     x;
  int     y;

  if( !get_flags( ch, argument, &flags, "lv", "Map" ) )
    return;

  x = 60;
  y = 20;

  if( is_set( &flags, 0 ) ) { x = 100;  y = 40; } 
  if( is_set( &flags, 1 ) ) { x = 160;  y = 60; } 

  show_map( ch, y, x );
}
Esempio n. 16
0
int main()
{
	void * buffer;
	size_t buffer_size;
	char** commandlist;
    size_t commandsnum; 
	char commandbuf[MAXARGSLEN+1];
	
	printf("Hello! Please input buffer size:\n > ");
	if(scanf("%zu", &buffer_size) != 1)
	{
		printf("Wrong buffer size! Sorry, good bye.\n");
		return 1;
	}

	buffer = init_buffer(buffer_size);
	if (buffer == NULL)
	{
		printf("Cannot allocate buffer with size %zu B (too small or too big)\n", buffer_size);
		return 1;
	}
	
	printf("Type 'exit' for quit or type 'help' to know how to use.\n");
	while(1)
	{
		if (fgets(commandbuf, MAXARGSLEN+1, stdin) && strlen(commandbuf) > 1)
		{
			commandlist = split_str(commandbuf, &commandsnum);
			if (commandsnum > 0)
			{
				if(strcmp(commandlist[0], "help") == 0) {
					show_help();
				} else if (strcmp(commandlist[0], "ALLOC") == 0 || strcmp(commandlist[0], "alloc") == 0 ) {
					if (commandsnum != 2)
					{
						printf("Error: ALLOC must have the one positive integer argument.\n");
						free_commandlist(commandlist, commandsnum);
						continue;
					}
					long alloc_size = atol(commandlist[1]); 
					if (alloc_size <= 0)
					{
						printf("Error: ALLOC argument must be positive integer.\n");
						free_commandlist(commandlist, commandsnum);
						continue;
					}
					size_t res = my_alloc(buffer, (size_t)alloc_size);
					if ( res == 0 )
					{
						printf("-\n");
						continue;
					}
					printf("+ %zu\n", res);
				} else if (strcmp(commandlist[0], "FREE") == 0 || strcmp(commandlist[0], "free") == 0 ) {
					if (commandsnum != 2)
					{
						printf("Error: FREE must have the one positive integer argument.\n");
						free_commandlist(commandlist, commandsnum);
						continue;
					}
					long free_address = atol(commandlist[1]); 
					if (free_address <= 0)
					{
						printf("Error: FREE argument must be positive integer.\n");
						free_commandlist(commandlist, commandsnum);
						continue;
					}
					if (my_free(buffer, (size_t)free_address) == 0)
						printf("+\n");
					else
						printf("-\n");
				} else if (strcmp(commandlist[0], "INFO") == 0 || strcmp(commandlist[0], "info") == 0 ) {
					show_info(buffer, buffer_size);
				} else if (strcmp(commandlist[0], "MAP") == 0 || strcmp(commandlist[0], "map") == 0 ) {
					show_map(buffer, buffer_size);
				} else if (strcmp(commandlist[0], "EXIT") == 0 || strcmp(commandlist[0], "exit") == 0 ) {
					printf("Thank you for using this allocator! Good bye.\n");
					break;
				} else {
					printf("Unknown command: %s\n", commandlist[0]);
				}
			}
			
			free_commandlist(commandlist, commandsnum);
		}	
		printf(" > ");
	}
	
	free(buffer);
	
	return 0;
}
Esempio n. 17
0
void nfc_reader(nfc_device_desc_t *pnddDevices, int times){

    char c_pubN[128];
    char c_pubKey[3];
    memset(c_pubN,0,sizeof(c_pubN));
    memset(c_pubKey,0,sizeof(c_pubKey));

    size_t  i,j,k,l;

    size_t  sourceLength,destLength;

    bool    res;
    byte_t pbrData[256];
    byte_t QueryDataWithFrame[256];

    int mode;


//    char *g_pubN = "AA030736A1480CC78576531EDF2D1153C18C22F1D0CAA5DBC7B52E3183B6BCC24F8853F7621F6E9473827DC32789E12F2D324BAE4C53A26F71ECF77C78914E107CC76B25507946F68A5D0FF9BD9D1EBB4234B2482E3824C2D3F55EA1D108DA2CF7F1B48D23FF7508DDCD4824E5E1D7C5B74FFB4A7F3492B3E0E3EEF3EA7B76F1";
//    char *g_pubKey = "10001";
//    char *g_priKey = "5F074248EEED6EF7374A643BA5537393F5637744E307E29D6E8B7F3E7DF8EE994E0B4DA3C15D005A4A166E655EFC5ABA1BF1390C3BEDA3A5D770350585FEF23AABCA9774C98AD60015926D4D843C82F52E52923A41F2387F7A54CBAD6416543549FED54ACE2D21F5B6B9B593549E57FEE48AA4FAFDF4C12B47EA34B4574DFAE1";

//    bool verbose = false;
//    byte_t pbrDatabuf[256];
//    char *randData_char;
//    char *plain;
//    randData_char = (char *)malloc(sizeof(char)*4);
//    plain = (char *)malloc(sizeof(char)*4);

//    char *plain_receive;
//    plain_receive = (char *)malloc(sizeof(char)*4);

//    char *cipherResult_send;
//    cipherResult_send = (char*)malloc(sizeof(char)*129);

//    char *cipherResult_send_hex;
//    cipherResult_send_hex = (char *)malloc(sizeof(char)*260);

//    unsigned char *cipherResult_send_hex;
//    cipherResult_send_hex = (unsigned char*)malloc(sizeof(char)*129);

//    byte_t cipherDataWithFrame_receive[256];
//    byte_t cipherDataWithoutFrame_receive[128];
//    byte_t cipherDataWithoutFrame[128];
//    byte_t QueryDataWithoutFrame[256];

    signal (SIGINT, stop_polling);
//  进行NFC设备的连接
    pnd = pn532_uart_connect (pnddDevices);

    if (pnd == NULL) {
        TraceLog("%s","Unable to connect to NFC device.");
        printf("Unable to connect to NFC device.");
        exit (EXIT_FAILURE);
    }

    printf ("Connected to NFC reader: %s\n", pnd->acName);
    printf ("NFC reader is on! \n");
    //SAMConfiguration
    memset(pbrData,0,sizeof(pbrData));
    byte_t pbtData1[] = { 0x14, 0x01, 0x00, 0x00};
    res = pn532_uart_send(pnd,pbtData1,sizeof(pbtData1));
    if(!res){
        TraceLog("%s","SAMConfiguration pn532_uart_send ERROR!");
        printf ("SAMConfiguration pn532_uart_send ERROR!");
    }
    int n = pn532_uart_receive (pnd,pbrData,sizeof(pbrData));

    if(n < 0){
        printf("SAMConfiguration receive %d\n",n);
        goto theend;
    }

    //List Passive Target
    memset(pbrData,0,sizeof(pbrData));
    byte_t pbtData2[] = { 0x4A, 0x01, 0x00};
    res = pn532_uart_send(pnd,pbtData2,sizeof(pbtData2));
    if(!res){
        TraceLog("%s","List Passive Target pn532_uart_send ERROR!");
        printf ("List Passive Target pn532_uart_send ERROR!\n");
    }

    n = pn532_uart_receive (pnd,pbrData,sizeof(pbrData));
    printf("List Passive Target%d",n);
    int iv=0;
    while( n<=0 ){
        if(iv++ > times){
            goto theend;
        }

        pn532_uart_send(pnd,pbtData2,sizeof(pbtData2));
        n = pn532_uart_receive (pnd,pbrData,sizeof(pbrData));
//        sleep(0.5);
    }

    if(pbrData[0] != 0x01){
        TraceLog("%s","List Passive Target pn532_uart_receive ERROR!");
        printf("List Passive Target pn532_uart_receive ERROR!\n");
        goto theend;
    }
    printf("List Passive Target success ! \n");

    unsigned char content[256];
    unsigned char mapsrc[256];
    unsigned char mapdes[256];

    byte_t mapsrcHEX[256];
    byte_t mapdesHEX[256];
    byte_t mapconHEX[256];

    memset(mapsrcHEX,0,sizeof(mapsrcHEX));
    memset(mapdesHEX,0,sizeof(mapdesHEX));
    memset(content,0,sizeof(content));

    //区分swp卡和双界面卡
    if((pbrData[15] == 0x90)||(pbrData[15] == 0x42)||(pbrData[15] == 0x48)||(pbrData[15] == 0xA1)){
        mode = 1;
        TraceLog("%s","use swp card.");
        printf("use swp card\n");
        //Select APP on mobile phone
        memset(pbrData,0,sizeof(pbrData));
        //byte_t pbtData3[] = { 0x40, 0x01, 0x00, 0xA4, 0x04, 0x00, 0x0A, 0x62, 0x75, 0x70, 0x74, 0x2E, 0x64, 0x65,0x6d, 0x6f, 0x2e};
        byte_t pbtData3[] = { 0x40, 0x01, 0x00, 0xA4, 0x04, 0x00, 0x0D, 0x62, 0x75, 0x70, 0x74, 0x2E, 0x6E, 0x65, 0x77, 0x70, 0x75, 0x73,0x68,0x2e};
        res = pn532_uart_send (pnd,pbtData3,sizeof(pbtData3));
        if(!res){
            TraceLog("%s","Select APP pn532_uart_send ERROR!");
            printf ("Select APP pn532_uart_send ERROR!");
            goto theend;
        }
        //printf("%d",res);
        n = pn532_uart_receive(pnd,pbrData,sizeof(pbrData));
        if(n <= 0){
            TraceLog("%s","Select APP pn532_uart_receive ERROR!");
            printf ("Select APP pn532_uart_receive ERROR!");
            goto theend;
        }

        if(pbrData[0] != 0x00){
            TraceLog("%s","Select APP Status Error!");
            printf("Select APP Status Error! \n");
            goto theend;
        }
        //Map search
        memset(QueryDataWithFrame,0,sizeof(QueryDataWithFrame));
        //test mobile
        byte_t pbtData5[] = { 0x40, 0x01, 0x00, 0x76, 0x00, 0x00,0x1E};

        pn532_uart_send (pnd,pbtData5,sizeof(pbtData5));
        n = pn532_uart_receive(pnd,QueryDataWithFrame,sizeof(QueryDataWithFrame));
        printf("QueryDataWithFrame length:%d \n",n);
        if(QueryDataWithFrame[0] != 0x00){
            TraceLog("%s","QueryData Error!");
            printf("QueryData Error! \n");
            goto theend;
        }

        for(l = 0;l < n-3;l++){
           content[l] = QueryDataWithFrame[l+1];
           if(n>50){
               goto theend;
           }
        }

        sourceLength = content[0];
        destLength = content[sourceLength+1];

        for(l=0;l<sourceLength+1;l++){
            mapsrc[l]=content[l+1];
        }
        for(l=0;l<destLength+1;l++){
            mapdes[l]=content[l+2+sourceLength];
        }
    }
    else{
        TraceLog("%s","use dual interface card.");
        printf("use dual interface card\n");
        mode = 0;
        //Select APP on mobile phone 1
        memset(pbrData,0,sizeof(pbrData));
        byte_t pbtData3[] = { 0x40, 0x01, 0x00, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00};
        res = pn532_uart_send (pnd,pbtData3,sizeof(pbtData3));
        if(!res){
            TraceLog("%s","Select APP1 pn532_uart_send ERROR!");
            printf ("Select APP1 pn532_uart_send ERROR!");
            goto theend;
        }
        n = pn532_uart_receive(pnd,pbrData,sizeof(pbrData));
        if(n <= 0){
            TraceLog("%s","Select APP1 pn532_uart_receive ERROR!");
            printf ("Select APP1 pn532_uart_receive ERROR!");
            goto theend;
        }
        if(pbrData[0] != 0x00){
            TraceLog("%s","Select APP1 on mobile phone 1 Error!");
            printf("Select APP1 on mobile phone 1 Error! \n");
            goto theend;
        }
        //Select APP on mobile phone 2
        memset(pbrData,0,sizeof(pbrData));

        byte_t pbtData4[] = { 0x40, 0x01, 0x00, 0xA4, 0x00, 0x00, 0x02, 0xDF, 0x03};
        res = pn532_uart_send (pnd,pbtData4,sizeof(pbtData4));
        if(!res){
            TraceLog("%s","Select APP2 pn532_uart_send ERROR!");
            printf ("Select APP2 pn532_uart_send ERROR!");
            goto theend;
        }
        n = pn532_uart_receive(pnd,pbrData,sizeof(pbrData));
        if(n <= 0){
            TraceLog("%s","Select APP2 pn532_uart_receive ERROR!");
            printf ("Select APP2 pn532_uart_receive ERROR!");
            goto theend;
        }
        if(pbrData[0] != 0x00){
            TraceLog("%s","Select APP on mobile phone 2 Error!");
            printf("Select APP on mobile phone 2 Error! \n");
            goto theend;
        }
        //Select APP on mobile phone 3
        memset(pbrData,0,sizeof(pbrData));
        byte_t pbtData5[] = { 0x40, 0x01, 0x00, 0xA4, 0x00, 0x00, 0x02, 0xEF, 0x02};
        res = pn532_uart_send (pnd,pbtData5,sizeof(pbtData5));
        if(!res){
            TraceLog("%s","Select APP3 pn532_uart_send ERROR!");
            printf ("Select APP3 pn532_uart_send ERROR!");
            goto theend;
        }
        n = pn532_uart_receive(pnd,pbrData,sizeof(pbrData));
        if(n <= 0){
            TraceLog("%s","SSelect APP3 pn532_uart_receive ERROR!");
            printf ("Select APP3 pn532_uart_receive ERROR!");
            goto theend;
        }
        if(pbrData[0] != 0x00){
            TraceLog("%s","Select APP on mobile phone 3 Error!");
            printf("Select APP on mobile phone 3 Error! \n");
            goto theend;
        }

        //Map search
        memset(QueryDataWithFrame,0,sizeof(QueryDataWithFrame));
        //test mobile
        byte_t pbtData6[] = { 0x40, 0x01, 0x00, 0xB0, 0x00, 0x00,0x20};
        pn532_uart_send (pnd,pbtData6,sizeof(pbtData6));
        n = pn532_uart_receive(pnd,QueryDataWithFrame,sizeof(QueryDataWithFrame));
        printf("\nQueryDataWithFrame length:%d \n",n);

        if(QueryDataWithFrame[0] != 0x00){
            printf("QueryData Error! \n");
            goto theend;
        }

        for(l = 0;l < n-3;l++){
           content[l] = QueryDataWithFrame[l+3];
        }

        destLength = content[0];
        sourceLength = content[destLength+2];
        for(l=0;l<destLength;l++){
            mapdes[l]=content[l+1];
        }
        for(l=0;l<sourceLength;l++){
            mapsrc[l]=content[l+3+destLength];
        }

    }

    int conLen = sourceLength+destLength+2;
    int mapsrcln = gsmString2Bytes(mapsrc,sourceLength,mapsrcHEX);
    int mapdesln = gsmString2Bytes(mapdes,destLength,mapdesHEX);
    int mapconln = gsmString2Bytes(content,conLen,mapconHEX);

    write(STDOUT_FILENO, mapsrcHEX, mapsrcln);
    write(STDOUT_FILENO, mapdesHEX, mapdesln);
    write(STDOUT_FILENO, mapconHEX, mapconln);
    bool bMapStarted = false;
    if((mapsrcln==0)||(mapdesln==0)){
        TraceLog("%s","source or dest value is null.");
    }
    else{
        //download map
        if((mapsrcHEX[0]!=0x30)&&(mapsrcln!=0)&&(mapdesln!=0)&&(!bMapStarted)){
            TraceLog("nfc-main.c:bMapStarted:%d",bMapStarted);
            int res = show_map(mapsrcHEX,mapsrcln,mapdesHEX,mapdesln,mode,bMapStarted);//启动地图,关闭video
            if(res==0){
                bMapStarted = true;
            }
//            sleep(0.1);
            TraceLog("%s","show_map is end.");
        }

        //如果mode=1  swp card 时,向管理平台发送日志
        if((mapsrcHEX[0]!=0x30)&&(mode == 1)){
            char *iccid = load_user_info(pnd);
            byte_t iccidHEX[20];
            int iccidln=gsmString2Bytes(iccid,10,iccidHEX);
            if( iccidHEX[0]=='0'){
                goto theend;
            }
            char *reader_website;
            reader_website = (char *)malloc(sizeof(char)*256);
            memset(reader_website,0,sizeof(reader_website));
            strcat(reader_website,configInfo.serverIP);
            strcat(reader_website,"/NFC/TerminalAction?terminalId=");
            strcat(reader_website,configInfo.terminalId);
            strcat(reader_website,"&type=02&content=");
    //        strcat(reader_website,"http://192.168.1.101:8080/NFC/TerminalAction?terminalId=01&type=02&content=");
    //        strncat(reader_website,mapsrcHEX,mapsrcln);
    //        strncat(reader_website,mapdesHEX,mapdesln);
            strncat(reader_website,mapconHEX,mapconln);
            strcat(reader_website,"&iccid=");
            strncat(reader_website,iccidHEX,iccidln);
            int len_reader_website = strlen(reader_website);
            write(STDOUT_FILENO, reader_website, len_reader_website);
            TraceLog("%s",reader_website);

            WebTransUpload(reader_website);
            sleep(0.1);

            free(reader_website);
        }
        else if((mapsrc[0]==0x00)&&(mapsrc[1]==0x2a)&&(mapsrc[2]==0x00)&&(mapsrc[3]==0x23)){ //*#
            char *dual_website;
            char *tagNumber;
            tagNumber = (char *)malloc(sizeof(char)*32);
            memset(tagNumber,0,sizeof(tagNumber));
            sprintf(tagNumber,"%d",tagCount+1);
            dual_website = (char *)malloc(sizeof(char)*256);
            memset(dual_website,0,sizeof(dual_website));
            strcat(dual_website,configInfo.serverIP);
            strcat(dual_website,"/NFC/TerminalAction?terminalId=");
            strcat(dual_website,configInfo.terminalId);
            strcat(dual_website,"&type=03&content=");
            strcat(dual_website,tagNumber);
            TraceLog("%s",dual_website);
            dualInterfaceUpload(dual_website);

            pwm();
            TraceLog("%s","*#:pwm");

            free(tagNumber);
            free(dual_website);
        }
        else if((mode==0)&&(mapsrc[0]!=0x00)){  //daul
            char *dual_website;
            dual_website = (char *)malloc(sizeof(char)*256);
            memset(dual_website,0,sizeof(dual_website));
            strcat(dual_website,configInfo.serverIP);
            strcat(dual_website,"/NFC/TerminalAction?terminalId=");
            strcat(dual_website,configInfo.terminalId);
            strcat(dual_website,"&type=04&content=");
            strncat(dual_website,mapconHEX,mapconln);

            dualInterfaceUpload(dual_website);
            TraceLog("%s",dual_website);
            free(dual_website);
        }
    }

    theend:
//    free(randData_char);
//    free(plain);
//    free(plain_receive);
//    free(cipherResult_send);
    pn532_uart_disconnect (pnd);
}
Esempio n. 18
0
int main(int argc, char *argv[]) {
    int usage = 1;
    int result = 0;
    char *filename = NULL;
    char temp_filename[128] = {};
    bool file_mode = false;

    signal(SIGPIPE, SIG_IGN);
    for (int i = 1; i < argc; ++i) {
        char* arg = argv[i];
        if (!strcmp(arg,"-v")) {
            verbose = true;
        } else if (!strcmp(arg,"-t")) {
            terse = true;
        } else if (!strcmp(arg,"-a")) {
            addresses = true;
        } else if (!strcmp(arg,"-q")) {
            quiet = true;
        } else if (!strcmp(arg,"-f")) {
            file_mode = true;
        } else {
            if (i + 1 != argc) {
                fprintf(stderr, "too many arguments\n");
                break;
            }
            if (file_mode) {
                filename = arg;
                usage = 0;
            } else {
                char *argend;
                int pid = strtol(arg, &argend, 10);
                if (*arg && !*argend) {
                    usage = 0;
                    snprintf(temp_filename, sizeof(temp_filename), "/proc/%d/smaps", pid);
                    filename = temp_filename;
                }
            }

            if (filename != nullptr) {
                if (show_map(filename)) {
                    result = 1;
                }
                break;
            }
            fprintf(stderr, "unrecognized argument: %s\n", arg);
            break;
        }
    }

    if (usage) {
        fprintf(stderr,
                "showmap [-t] [-v] [-c] [-q] [-f] <pid|file>\n"
                "        -t = terse (show only items with private pages)\n"
                "        -v = verbose (don't coalesce maps with the same name)\n"
                "        -a = addresses (show virtual memory map)\n"
                "        -q = quiet (don't show error if map could not be read)\n"
                "        -f = read from input file instead of pid\n"
                );
        result = 1;
    }

    return result;
}
Esempio n. 19
0
int main (void) {
  	generate_map();
  	show_map();
   	return 0;
}
Esempio n. 20
0
File: word.c Progetto: mikelcq/C_NLP
int main (int argc, char *argv[])
{
  int i;
  wstack_type wstack;

  char buff[100];
  SenType sentence;

  printf("starting, loading dict \n");

  /* initial */
  if (dict_load() == -1)
  {
    printf("load dict err!\n");
    return 0;
  }
  dump_dict(&dicts[0], 1);


  printf("creating stack...\n");

  create_wstack(&wstack, 50);
  if (!wstack.array)
  {
    printf("stack alloc err!\n");
    goto MAINEND;
  }

  printf("get a input ...\n");
  
  /* reading sentence from a file or input */
  sentence.pdata = buff;
  sentence.len = sizeof(buff);
  if (0 > sentence_read(&sentence))
  {
    printf("reading err!\n");
    goto MAINEND;
  }

  printf("analyzing...\n");

  /* core algorithm of word segmentation */
  wdseg_full_type wdsegmnt;
  word_seg(sentence, &wdsegmnt, &wstack);


  printf("Done, size: %d \n", wdsegmnt.num);

  /* show result */
  for (i = 0; i < wdsegmnt.num; i++)
  {
    printf("the %dth anwser: \n", i);
    show_map(&wdsegmnt.psegmnt[i]);  
  }


MAINEND:
  if (wstack.array)
  {
    printf("free stack \n");
    free(wstack.array);
  }
  if(dicts[0].indexWdPool.pstart)
  {
    printf("free dict data \n");
    free(dicts[0].indexWdPool.pstart);
  }
  if (dicts[0].pindex)
  {
    printf("free dict wd \n");
    free(dicts[0].index);
  }

  return 0;
}
Esempio n. 21
0
File: word.c Progetto: mikelcq/C_NLP
int word_seg(SenType sen, wdseg_full_type *pwdseg, wstack_type *pwstack)
{
  int i,ic,it;
  char cached_found = 0;
  WordType tempwd;
  wdseg_type wdseg_cache[20];
  wdseg_type temp_seg, currt_seg;

  int reach_sen_end = 0;
  char *pcurrt = NULL;
  int cachlen = 0;
  int currt_pos = 0;  /* current postion in sentence */

  char debug_wd[MAX_WORD_LEN*2+1];

  /* init datas*/
  clear_map(&temp_seg);
  clear_map(&currt_seg);
  for (it = 0; it < 20; it++)
    clear_map(&wdseg_cache[it]);


  printf("wordseg for sentence(len %d):%s \n", sen.len, sen.pdata);

//  show_map(&currt_seg);


  /* set start point of segmnt map */
  pcurrt = sen.pdata;
  AddPoint2Map(&currt_seg, currt_pos, 0);

//  printf(" current_seg: \n");
//  show_map(&currt_seg);

  for (;;)
  {


    /* step 1. scan.*/
    printf("\n....... step 1  ........ \n");

    
    /* check through cache first */
#ifdef CACHE_SUPPORT
    cached_found = 0;
    for (ic = 0; ic < cachlen; ic++)
    {
      if (point_in_map(currt_pos, &wdseg_cache[ic]))
      {
        printf("cached found!\n");


        
        cached_found++;
        map_merge(&currt_seg, &wdseg_cache[ic], currt_pos);
        wdseg_cache[cachlen - 1 + cached_found] = currt_seg;
        
        show_map(&currt_seg);
      }
    }
    
    if (cached_found > 0) 
      cachlen += cached_found;
#endif

    if (0 == cached_found)
    {


      /* sen end check . */
      reach_sen_end = currt_pos + MAX_WORD_LEN - sen.len/CCLEN;
      if ( reach_sen_end > 0 )/* reach sentence end. */
      {
        printf("reach sen end.");
        i = reach_sen_end; 
      }

        
      for (i = MAX_WORD_LEN; i > 0; i--)
      {
        /* make a word*/
        tempwd.pdata = pcurrt;
        tempwd.len = i*CCLEN;
  
        
  
  
        /* to check the exist of a word in dictionary */
        if (check_dict_word(&dicts[0], &tempwd, NULL))
        {
        
          memcpy(debug_wd, tempwd.pdata, tempwd.len);
          debug_wd[tempwd.len]='\0';
          printf("find in dict: len %d ,[%s] \n", tempwd.len, debug_wd);

          
          /* add new point to segmnt map */
          temp_seg = currt_seg;
          AddPoint2Map(&temp_seg, currt_pos, tempwd.len/CCLEN);
          //show_map(&temp_seg);
  
          /* check sentence end, if success then cache it.  */
          if (segmap2len(temp_seg) == sen.len)
          {

            printf(" got a sucess: \n");
            //show_map(&temp_seg);

            wdseg_cache[cachlen++] = temp_seg;
          }
          else
          {
            printf(" put a agenda : \n");
            show_map(&temp_seg);
            
            put_agenda((wstack_item_type*)&temp_seg, pwstack);
          }
        }
  
       
  
        
      }
    }




   printf("\n........ step 2 ........\n");


    /* step 2. get next agenda, if none, then exit. */
    if (get_agenda(&currt_seg, pwstack) == -1)
    {

      printf(" got none from stack ! \n");
      break; /* the end */

    }

    printf("reset currt_seg: \n");
    show_map(&currt_seg);

    /* sync the current data pointer and map postion*/
    currt_pos = segmap2len(currt_seg)/CCLEN;
    pcurrt = sen.pdata + currt_pos*CCLEN;

    printf("currt_pos:%d, pcurrt:%s \n", currt_pos, pcurrt);

  
  }


  pwdseg->psegmnt = wdseg_cache;
  pwdseg->num = cachlen;

  if (cachlen > 0)
    return 0; /* success */
  else
    return -1;
}
Esempio n. 22
0
static int show_tid_map(struct seq_file *m, void *_p)
{
	return show_map(m, _p, 0);
}
static int show_pid_map(struct seq_file *m, void *v)
{
	return show_map(m, v, 1);
}