Esempio n. 1
19
   void comp()
    {
       int a,b;
       cout<<endl;
       textcolor(RED);
       clreol();
       cout<<"  This is the computer's move"<<endl<<endl;
       a=3,b=3;
       for(int x=0;x<3;++x)
	 {
	  if(tic[x][0]!=' '&& tic[x][0]== tic[x][1] && tic[x][2]==' ')
	      {
		 a=x;
		 b=2;
		 break;
	      }
	  else
	  if(tic[x][0]!=' '&& tic[x][0]== tic[x][2] && tic[x][1]==' ')
	      {
		 a=x;
		 b=1;
		 break;
	      }
	  else
	  if(tic[x][1]!=' '&& tic[x][1]== tic[x][2] && tic[x][0]==' ')
	      {
		 a=x;
		 b=0;
		 break;
	      }
	 }
      if(a==3)
	{
	 for(int x=0;x<3;++x)
	    {
	     if(tic[0][x]!=' '&& tic[0][x]== tic[1][x] && tic[2][x]==' ')
	      {
		 a=2;
		 b=x;
		 break;
	      }
	  else
	  if(tic[0][x]!=' '&& tic[0][x]== tic[2][x] && tic[1][x]==' ')
	      {
		 a=1;
		 b=x;
		 break;
	      }
	  else
	  if(tic[1][x]!=' '&& tic[1][x]== tic[2][x] && tic[0][x]==' ')
	      {
		 a=0;
		 b=x;
		 break;
	      }
	 }
	 }
      if(a==3)
	{
	  if(tic[0][0]!=' '&& tic[0][0]== tic[1][1] && tic[2][2]==' ')
	      {
		 a=2;
		 b=2;
	      }
	   else
	  if(tic[0][0]!=' '&& tic[0][0]== tic[2][2] && tic[1][1]==' ')
	      {
		 a=1;
		 b=1;
	      }
	  else
	  if(tic[1][1]!=' '&& tic[1][1]== tic[2][2] && tic[0][0]==' ')
	      {
		 a=0;
		 b=0;
	      }
	  else
	  if(tic[0][2]!=' '&& tic[0][2]== tic[1][1] && tic[2][0]==' ')
	      {
		 a=2;
		 b=0;

	      }
	  else
	  if(tic[0][2]!=' '&& tic[0][2]== tic[2][0] && tic[1][1]==' ')
	      {
		 a=1;
		 b=1;

	      }
	  else
	  if(tic[1][1]!=' '&& tic[1][1]== tic[2][0] && tic[0][2]==' ')
	      {
		 a=0;
		 b=2;

	      }
	   }
	  if(a==3)
	   {
	    for(int m=0;m<=2;++m)
	      for(int l=0;l<=2;++l)
		    {
		      if(tic[m][l]==' ')
			 {
			   a=m;
			   b=l;
			   break;
			 }
		    }
	  }

       tic[a][b]='O';
       ++sum;
       display();
       d=check();
       if(d==0)
	  if(sum==9)
	    draw();
	  else
	     user();
       else
	 {
	   cout<<endl;
	   getch();
	   pcwin();

	 }
	   getch();
	   menu();
     }
Esempio n. 2
1
File: Menu.C Progetto: bbidulock/wmx
void ShowGeometry::remove()
{
    XUnmapWindow(display(), m_window[screen()]);
}
Esempio n. 3
0
File: Menu.C Progetto: bbidulock/wmx
Menu::~Menu()
{
    XUnmapWindow(display(), m_window[screen()]);
}
Esempio n. 4
0
//----------------------------------------------------------------------------------------------
void LoggerWidget::logSuccess (const QString & info)
{
    _logConsole->setTextColor (Qt::green);
    display (info);
}
Esempio n. 5
0
int main(int argc, char **argv)
{

    int i;
    for (i = 1; i < argc; ++i) {
        const char *arg = argv[i];

        if (arg[0] != '-') {
            break;
        }

        if (!strcmp(arg, "--")) {
            break;
        } else if (!strcmp(arg, "-b")) {
            benchmark = true;
            retrace::verbosity = -1;
        } else if (!strcmp(arg, "-c")) {
            compare_prefix = argv[++i];
            if (snapshot_frequency == FREQUENCY_NEVER) {
                snapshot_frequency = FREQUENCY_FRAME;
            }
        } else if (!strcmp(arg, "-D")) {
            dump_state = atoi(argv[++i]);
            retrace::verbosity = -2;
        } else if (!strcmp(arg, "-db")) {
            double_buffer = true;
        } else if (!strcmp(arg, "-sb")) {
            double_buffer = false;
        } else if (!strcmp(arg, "--help")) {
            usage();
            return 0;
        } else if (!strcmp(arg, "-s")) {
            snapshot_prefix = argv[++i];
            if (snapshot_frequency == FREQUENCY_NEVER) {
                snapshot_frequency = FREQUENCY_FRAME;
            }
        } else if (!strcmp(arg, "-S")) {
            arg = argv[++i];
            if (!strcmp(arg, "frame")) {
                snapshot_frequency = FREQUENCY_FRAME;
            } else if (!strcmp(arg, "framebuffer")) {
                snapshot_frequency = FREQUENCY_FRAMEBUFFER;
            } else if (!strcmp(arg, "draw")) {
                snapshot_frequency = FREQUENCY_DRAW;
            } else {
                std::cerr << "error: unknown frequency " << arg << "\n";
                usage();
                return 1;
            }
            if (snapshot_prefix == NULL) {
                snapshot_prefix = "";
            }
        } else if (!strcmp(arg, "-v")) {
            ++retrace::verbosity;
        } else if (!strcmp(arg, "-w")) {
            wait = true;
        } else {
            std::cerr << "error: unknown option " << arg << "\n";
            usage();
            return 1;
        }
    }

    ws = glws::createNativeWindowSystem();
    visual = ws->createVisual(double_buffer);

    for ( ; i < argc; ++i) {
        if (!parser.open(argv[i])) {
            std::cerr << "error: failed to open " << argv[i] << "\n";
            return 1;
        }

        display();

        parser.close();
    }

    return 0;
}
Esempio n. 6
0
void processUdpPacket( struct trafficRecord *tr, const u_char *packet ) {
  const struct udphdr *udp_ptr;
  const char *payload;
  const char *tmp_ptr;
  const int size_udp = sizeof( struct udphdr );

  PRIVATE int bytes_sent;
  PRIVATE u_int ip_hlen, ip_ver, ip_off, ip_offidx;
  PRIVATE int ip_len;
  PRIVATE char s_ip_addr_str[MAX_IP_ADDR_LEN+1];
  PRIVATE char d_ip_addr_str[MAX_IP_ADDR_LEN+1];
  PRIVATE struct in_addr addr;
  PRIVATE struct tm pkt_time;
  PRIVATE int payload_size;
  /* pre-allocated traffic record */
  PRIVATE struct trafficRecord *tr_tmp, *tmpTrPtr;
  PRIVATE struct tcpFlow *tf_ptr;
  time_t currentTime = time( NULL );

  /* process packet */

  /*
   * udp decode
   */

#ifdef DEBUG
  if ( config->debug >= 5 ) {
    display( LOG_DEBUG, "UDP packet" );
  }
#endif

  /* pointers are fun */
  udp_ptr = (struct udphdr*)( packet );

#ifdef BSD_DERIVED
  tr->sPort = ntohs( udp_ptr->uh_sport );
  tr->dPort = ntohs( udp_ptr->uh_dport );
#else
  tr->sPort = ntohs( udp_ptr->source );
  tr->dPort = ntohs( udp_ptr->dest );
#endif

#ifdef DEBUG
  if ( config->debug >= 3 ) {
    display( LOG_INFO, "UDP: S: %d D: %d", ntohs( tr->sPort ), ntohs( tr->dPort ) );
  }
#endif

  /*
   * write to log
   */
    
  XSTRNCPY( s_ip_addr_str, inet_ntoa( tr->sIp ), MAX_IP_ADDR_LEN );
  XSTRNCPY( d_ip_addr_str, inet_ntoa( tr->dIp ), MAX_IP_ADDR_LEN );
  fprintf( config->log_st, "[%04d/%02d/%02d %02d:%02d:%02d] %16s:%-5u -> %16s:%-5u UDP\n",
	   tr->wireTime.tm_year+1900,
	   tr->wireTime.tm_mon+1,
	   tr->wireTime.tm_mday,
	   tr->wireTime.tm_hour,
	   tr->wireTime.tm_min,
	   tr->wireTime.tm_sec,
	   s_ip_addr_str,
	   tr->sPort,
	   d_ip_addr_str,
	   tr->dPort
	   );

  /*
   * done with packet, fall through
   */
  
  /* cleanup, we will do nothing with this packet */
  return;
}
Esempio n. 7
0
/* You can either create a query or create a log entry.  They use very
 * similar syntax, but:
 * - if you're making a query, you can use >, <, etc.
 * - if you're logging, you can't.
 * This is tracked by recording whether any non-exact relations
 * have been requested ("query_only"), and refusing to set the -l
 * flag if they have, and refusing to accept any such relation
 * if the -l flag is already set.
 */
int
main(int argc, char **argv) {
	pseudo_query_t *traits = 0, *current = 0, *new_trait = 0;
	char *s;
	log_history history;
	int query_only = 0;
	int o;
	int bad_args = 0;
	char *format = "%s %-12.12R %-4y %7o: [mode %04m, %2a] %p %T";

	while ((o = getopt(argc, argv, "vla:c:d:DE:f:F:g:G:hi:I:m:M:o:O:p:P:r:R:s:S:t:T:u:Uy:")) != -1) {
		switch (o) {
		case 'P':
			s = PSEUDO_ROOT_PATH(AT_FDCWD, optarg, AT_SYMLINK_NOFOLLOW);
			if (!s)
				pseudo_diag("Can't resolve prefix path '%s'\n", optarg);
			pseudo_set_value("PSEUDO_PREFIX", s);
			break;
		case 'v':
			pseudo_debug_verbose();
			break;
		case 'l':
			opt_l = 1;
			break;
		case 'D':
			opt_D = 1;
			query_only = 1;
			break;
		case 'E':
			timeformat = strdup(optarg);
			break;
		case 'F':
			/* disallow specifying -F with -l */
			format = strdup(optarg);
			query_only = 1;
			break;
		case 'U':
			opt_U = 1;
			query_only = 1;
			break;
		case 'I':		/* PSQF_ID */
			query_only = 1;
					/* FALLTHROUGH */
		case 'a':		/* PSQF_ACCESS */
		case 'c':		/* PSQF_CLIENT */
		case 'd':		/* PSQF_DEV */
		case 'f':		/* PSQF_FD */
		case 'g':		/* PSQF_GID */
		case 'G':		/* PSQF_TAG */
		case 'i':		/* PSQF_INODE */
		case 'm':		/* PSQF_PERM */
		case 'M':		/* PSQF_MODE */
		case 'o':		/* PSQF_OP */
		case 'O':		/* PSQF_ORDER */
		case 'p':		/* PSQF_PATH */
		case 'r':		/* PSQF_RESULT */
		case 'R':		/* PSQF_PROGRAM */
		case 's':		/* PSQF_STAMP */
		case 'S':		/* PSQF_SEVERITY */
		case 't':		/* PSQF_FTYPE */
		case 'T':		/* PSQF_TEXT */
		case 'u':		/* PSQF_UID */
		case 'y':		/* PSQF_TYPE */
			new_trait = plog_trait(o, optarg);
			if (!new_trait) {
				bad_args = 1;
			}
			break;
		case 'h':
			usage(EXIT_SUCCESS);
			break;
		case '?':		/* FALLTHROUGH */
		default:
			fprintf(stderr, "unknown option '%c'\n", optopt);
			usage(EXIT_FAILURE);
			break;
		}
		if (new_trait) {
			if (current) {
				current->next = new_trait;
				current = current->next;
			} else {
				traits = new_trait;
				current = new_trait;
			}
			new_trait = 0;
		}
	}

	if (optind < argc) {
		pseudo_diag("Error: Extra arguments not associated with any option.\n");
		usage(EXIT_FAILURE);
	}

	if (query_only && opt_l) {
		pseudo_diag("Error: -l cannot be used with query-only options or flags.\n");
		bad_args = 1;
	}

	/* should be set only if we have already diagnosed the bad arguments. */
	if (bad_args)
		exit(EXIT_FAILURE);

	if (!pseudo_get_prefix(argv[0])) {
		pseudo_diag("Can't figure out prefix.  Set PSEUDO_PREFIX or invoke with full path.\n");
		exit(EXIT_FAILURE);
	}

	if (!pseudo_get_bindir()) {
		pseudo_diag("Can't figure out bindir.  Set PSEUDO_BINDIR.\n");
		exit(EXIT_FAILURE);
	}

	if (!pseudo_get_libdir()) {
		pseudo_diag("Can't figure out libdir.  Set PSEUDO_LIBDIR.\n");
		exit(EXIT_FAILURE);
	}

	if (!pseudo_get_localstatedir()) {
		pseudo_diag("Can't figure out localstatedir.  Set PSEUDO_LOCALSTATEDIR.\n");
		exit(EXIT_FAILURE);
	}

	if (opt_l) {
		pdb_log_traits(traits);
	} else {
		int fields;
		fields = format_scan(format);
		if (fields == -1) {
			pseudo_diag("couldn't parse format string (%s).\n", format);
			return EXIT_FAILURE;
		}
		if (opt_D) {
			if (pdb_delete(traits, fields)) {
				pseudo_diag("errors occurred trying to delete entries.\n");
			}
		} else {
			history = pdb_history(traits, fields, opt_U);
			if (history) {
				log_entry *e;
				while ((e = pdb_history_entry(history)) != NULL) {
					display(e, format);
					log_entry_free(e);
				}
				pdb_history_free(history);
			} else {
				pseudo_diag("could not retrieve history.\n");
				return EXIT_FAILURE;
			}
		}
	}
	return 0;
}
Esempio n. 8
0
void rgb_lcd::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) 
{

    Wire.begin();
    
    if (lines > 1) {
        _displayfunction |= LCD_2LINE;
    }
    _numlines = lines;
    _currline = 0;

    // for some 1 line displays you can select a 10 pixel high font
    if ((dotsize != 0) && (lines == 1)) {
        _displayfunction |= LCD_5x10DOTS;
    }

    // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
    // according to datasheet, we need at least 40ms after power rises above 2.7V
    // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
    delayMicroseconds(50000);


    // this is according to the hitachi HD44780 datasheet
    // page 45 figure 23

    // Send function set command sequence
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(4500);  // wait more than 4.1ms

    // second try
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(150);

    // third go
    command(LCD_FUNCTIONSET | _displayfunction);


    // finally, set # lines, font size, etc.
    command(LCD_FUNCTIONSET | _displayfunction);

    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
    display();

    // clear it off
    clear();

    // Initialize to default text direction (for romance languages)
    _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
    // set the entry mode
    command(LCD_ENTRYMODESET | _displaymode);
    
    
    // backlight init
    setReg(0, 0);
    setReg(1, 0);
    setReg(0x08, 0xAA);     // all led control by pwm
    
    setColorWhite();

}
Esempio n. 9
0
void InterfaceTree::interfaceListChanged()
{
#ifdef HAVE_LIBPCAP
    display();
#endif
}
Esempio n. 10
0
void selectionsort(struct node **start)
{	struct node *ptr1,*ptr2,*ptr3,*ptr4,*ptr5;
	ptr1=*start;
    while(ptr1->next!=NULL)
	{
		ptr2=ptr1->next;
	    while(ptr2!=NULL)
		{
			if(ptr1->data>ptr2->data)
			{
			 	if(ptr1==*start)
				{
					if(ptr2==ptr1->next)
					{
						ptr1->next=ptr2->next;
						ptr2->next=ptr1;
						*start=ptr2;
						ptr3=ptr1;
						ptr1=ptr2;
						ptr2=ptr3;
						}
					else
					{
						ptr3=ptr1->next;
						ptr1->next=ptr2->next;
						ptr4->next=ptr1;
						ptr2->next=ptr3;
						*start=ptr2;
						ptr3=ptr1;
						ptr1=ptr2;
						ptr2=ptr3;	
					}
				}
				else
				{
					if(ptr2==ptr1->next)
					{
					ptr1->next=ptr2->next;
					ptr2->next=ptr1;
					ptr5->next=ptr2;
					ptr3=ptr1;
					ptr1=ptr2;
					ptr2=ptr3;
					}
		   			else
		   		{
				    ptr3=ptr1->next;
		   		    ptr1->next=ptr2->next;
		   		    ptr4->next=ptr1;
		   		    ptr2->next=ptr3;
		   		    ptr5->next=ptr2;
		   		    ptr3=ptr1;
		   		    ptr1=ptr2;
					ptr2=ptr3;
	            }
		   	 }
	     	
	    }
	       ptr4=ptr2;
	        ptr2=ptr2->next;
			
	}
	display(&*start);
      		 printf("\n");
      		 ptr5=ptr1;
	   		ptr1=ptr1->next;
}
}
Esempio n. 11
0
    void player2()
     {
       do
	{
	  cout<<endl;
	  textcolor(RED);
	  clreol();
	  cout<<"  PLAYER 2's MOVE"<<endl<<endl;
	  cout<<"  ENTER THE COORDINATES WHERE YOU WANT TO PUT YOUR 'O' "<<endl;
	  cout<<"  x=";
	  cin>>x;
	  if(x==-1)
	     menu();
	  cout<<endl;
	  cout<<"  y=";
	  cin>>y;
	  if((x<0)||(x>2)||(y<0)||(y>2))            //check for valid coordinates
	    {
	     cout<<endl;
	     textcolor(BLUE);
	     clreol();
	     cout<<" *.ENTER THE CORRECT COORDINATES!!!!"<<endl<<endl;
	    }
	}while((x<0)||(x>2)||(y<0)||(y>2));

       if(tic[x][y]==' ')                        //check for vacant space at entered coordinates
	   {
	     tic[x][y]='O';
	     cout<<endl<<endl;
	     ++sum;
	     textbackground(GREEN);
	     textcolor(WHITE);
	     clrscr();
	     display();                     //calling function display
	   }
       else
	   {
	     textcolor(BLUE);
	     clreol();
	     cout<<"\t\tTHIS POSITION IS ALREADY FILLED."<<endl;
	     textcolor(BLUE);
	     clreol();
	     cout<<"\t\tCHOOSE SOME OTHER COORDINATES"<<endl;
	     player2();                              //user function call
	   }

     d=check();                                  //check function call
     if(d==0)
       {
	 if(sum==9)
	    draw();
	 else
	    user();	                        //user function call
       }
     else
       {
	 cout<<endl;
	 player2win();

       }
   }
Esempio n. 12
0
/*======== void parse_file () ==========
Inputs:   char * filename 
          struct matrix * transform, 
          struct matrix * pm,
          screen s
	  color c
Returns: 

Goes through the file named filename and performs all of the actions listed in that file.
The file follows the following format:
     Every command is a single character that takes up a line
     Any command that requires arguments must have those arguments in the second line.
     The commands are as follows:
         l: add a line to the edge matrix - 
	    takes 6 arguemnts (x0, y0, z0, x1, y1, z1)
	 i: set the transform matrix to the identity matrix - 
	 s: create a scale matrix, 
	    then multiply the transform matrix by the scale matrix - 
	    takes 3 arguments (sx, sy, sz)
	 t: create a translation matrix, 
	    then multiply the transform matrix by the translation matrix - 
	    takes 3 arguments (tx, ty, tz)
	 x: create an x-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 y: create an y-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 z: create an z-axis rotation matrix,
	    then multiply the transform matrix by the rotation matrix -
	    takes 1 argument (theta)
	 a: apply the current transformation matrix to the 
	    edge matrix
	 v: draw the lines of the edge matrix to the screen
	    display the screen
	 g: draw the lines of the edge matrix to the screen
	    save the screen to a file -
	    takes 1 argument (file name)
	 q: end parsing

See the file script for an example of the file format


IMPORTANT MATH NOTE:
the trig functions int math.h use radian mesure, but us normal
humans use degrees, so the file will contain degrees for rotations,
be sure to conver those degrees to radians (M_PI is the constant
for PI)

jdyrlandweaver
====================*/
void parse_file ( char * filename, 
                  struct matrix * transform, 
                  struct matrix * pm,
                  screen s ,
		  color c ) {
  FILE *file = fopen(filename,"r");
  char *line = (char *)malloc(MAX_LINE_SIZE);
  double *args = (double *)malloc(MAX_ARG_SIZE * sizeof(double));

  while(fgets(line,MAX_LINE_SIZE,file)) {
    switch (line[0]) {
    case 'l':
      read_args(file,args);
      add_edge(pm,args[0],args[1],args[2],args[3],args[4],args[5]);
      break;
    case 'i':
      ident(transform);
      break;
    case 's':
      read_args(file,args);
      struct matrix *scale = make_scale(args[0],args[1],args[2]);
      matrix_mult(scale,transform);
      free_matrix(scale);
      break;
    case 't':
      read_args(file,args);
      struct matrix *translate = make_translate(args[0],args[1],args[2]);
      matrix_mult(translate,transform);
      free_matrix(translate);
      break;
    case 'x':
      read_args(file,args);
      struct matrix *rotx = make_rotX(args[0]);
      matrix_mult(rotx,transform);
      free_matrix(rotx);
      break;
    case 'y':
      read_args(file,args);
      struct matrix *roty = make_rotY(args[0]);
      matrix_mult(roty,transform);
      free_matrix(roty);
      break;
    case 'z':
      read_args(file,args);
      struct matrix *rotz = make_rotZ(args[0]);
      matrix_mult(rotz,transform);
      free_matrix(rotz);
      break;
    case 'a':
      matrix_mult(transform,pm);
      break;
    case 'v':
      clear_screen(s);
      draw_lines(pm,s,c);
      display(s);
      break;
    case 'g':
      draw_lines(pm,s,c);
      fgets(line,MAX_LINE_SIZE,file);
      save_extension(s,line);
      break;
    case 'q':
      return;
    default:
      printf("fatal: el comando no se encuentra\n");
      return;
    }
  }
  free(line);
  free(args);
  fclose(file);
}
Esempio n. 13
0
int main()
{//intializing the chessboard
    /**********************************************************************/

     for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            chessboard[i][j]=NULL;
        }
    }
    //initializing white horse
    whorse[0].setposition(0,1);
    chessboard[0][1]=&whorse[0];
    whorse[1].setposition(0,6);
    chessboard[0][6]=&whorse[1];
    //initializing black horse
    bhorse[0].setposition(7,1);
    chessboard[7][1]=&bhorse[0];
    bhorse[1].setposition(7,6);
    chessboard[7][6]=&bhorse[1];
    //initializing white uut
    wuut[0].setposition(0,2);
    chessboard[0][2]=&wuut[0];
    wuut[1].setposition(0,5);
    chessboard[0][5]=&wuut[1];
    //intializing white uut
    buut[0].setposition(7,2);
    chessboard[7][2]=&buut[0];
    buut[1].setposition(7,5);
    chessboard[7][5]=&buut[1];

    welephant[0].setposition(0,0);//initializing white elephant
    chessboard[0][0]=&welephant[0];

    welephant[1].setposition(0,7);
    chessboard[0][7]=&welephant[1];

 belephant[0].setposition(7,0);//initializing black elephant1
    chessboard[7][0]=&belephant[0];
    //chessboard[7][0]->setposition(7,0);

    belephant[1].setposition(7,7);//initializing black elephant1
    chessboard[7][7]=&belephant[1];
    //chessboard[7][7]->setposition(7,7);
    for(int j=0;j<8;j++)             //initializing blacksoldier
    {
        b[j].setposition(6,j);
        chessboard[6][j]=&b[j];

    }
          bk.setposition(7,3);
      chessboard[7][3]=&bk;//initializing black king

            wk.setposition(0,3);
      chessboard[0][3]=&wk;//initializing white king
    for(int j=0;j<8;j++)//initializing whitesoldier
    {
        w[j].setposition(1,j);
        chessboard[1][j]=&w[j];

    }
     bqueen.setposition(7,4);
    chessboard[7][4]=&bqueen;//initializing black queen

    wqueen.setposition(0,4);//initiliazing white queen
    chessboard[0][4]=&wqueen;
int blackcurposx,blackcurposy;
int whitecurposx,whitecurposy;
//getbothkingpos(wk,bk,blackcurposx,blackcurposy,whitecurposx,whitecurposy);
/*******************************************************************************/
string player1,player2;
int player1x,player1y;
int player2x,player2y;
int choice;
cout<<"player 1::white player\"WHITE BACKGROUND\"\n";
cout<<"player 2::black player\"BLACK BACKGROUND\"\n\n";
system("color 70");
cout<<"Player 1 name::";
cin>>player1;
system("color 07");
cout<<"Player 2 name::";
cin>>player2;
cout<<"\nlets start\n";
display();
while(2){
 cout<<player1<<"chance:\n";
while(2)
{
        system("color 70");
    cout<<"enter cordinates \n";
    while(2)
    {
        cin>>player1x;
        cin>>player1y;
        if(chessboard[player1x][player1y]==NULL)
        {
            cout<<"pls "<<player1<<",select players\n";
        }
        else if(chessboard[player1x][player1y]->givetypeofplayer()==0)
        {
            cout<<"pls "<<player1<<",select your own players\n";
        }
        else
        break;
    }
    chessboard[player1x][player1y]->findpossiblelocationtomoveorattack();
    if(chessboard[player1x][player1y]->noofattackpos!=0 && chessboard[player1x][player1y]->noofmovepos!=0)
    {
        if(chessboard[player1x][player1y]->givemetheplayer()==100 || chessboard[player1x][player1y]->givemetheplayer()==200)
            {
            while(2){
            cout<<"enter \n1:move  2:attack  3:enpass \n";
            cin>>choice;
            if(choice==1)
            {

                chessboard[player1x][player1y]->move();
                break;
            }
            else if(choice==2)
            {
                chessboard[player1x][player1y]->attack();
                break;
            }
                    }
            if(wk.getcheckbit()==1)
                {
                    int x;int y;
                    wk.getposition(x,y);
                    if(wk.ischeckisstillon(x,y))
                    {
                        cout<<"black wins\n";
                        exit(0);
                    }
                    else
                    {
                        wk.resetcheckbit();
                    }
                }
                    break;//to give another player chance
            }
        else
        {
             while(2){
            cout<<"enter \n1:move  2:attack \n";
            cin>>choice;
            if(choice==1)
            {
                chessboard[player1x][player1y]->move();
                break;
            }
            else if(choice==2)
            {
                chessboard[player1x][player1y]->attack();
                break;
            }
            else
            continue;
                    }

                if(wk.getcheckbit()==1)
                {
                    int x;int y;
                    wk.getposition(x,y);
                    if(wk.ischeckisstillon(x,y))
                    {
                        cout<<"black wins\n";
                        exit(0);
                    }
                    else
                    wk.resetcheckbit();
                }
                     break;//to give another player chance
        }

    }
    else if(chessboard[player1x][player1y]->noofattackpos)
    {
        while(2){
        cout<<"1:attack\n";
        cin>>choice;
        if(choice==1)
        {
            chessboard[player1x][player1y]->attack();
            break;
        }
        else
        continue;
        }
         if(wk.getcheckbit()==1)
                {
                    int x;int y;
                    wk.getposition(x,y);
                    if(wk.ischeckisstillon(x,y))
                    {
                        cout<<"black wins\n";
                        exit(0);
                    }
                    else
                    wk.resetcheckbit();
                }
         break;//to give another player chance
    }
    else if(chessboard[player1x][player1y]->noofmovepos)
Esempio n. 14
0
File: Menu.C Progetto: bbidulock/wmx
Menu::Menu(WindowManager *manager, XEvent *e)
    : m_items(0), m_nItems(0), m_nHidden(0),
      m_hasSubmenus(False),
      m_windowManager(manager),
      m_event(e)
{
    if (!m_initialised)
    {
	XGCValues *values;
	XSetWindowAttributes *attr;

        m_menuGC = (GC *) malloc(m_windowManager->screensTotal() * sizeof(GC));
        m_window = (Window *) malloc(m_windowManager->screensTotal() *
				     sizeof(Window));
#ifdef CONFIG_USE_XFT
	char *fi = strdup(CONFIG_MENU_FONT);
	char *ffi = fi, *tokstr = fi;
	while ((fi = strtok(tokstr, ","))) {
		
	    fprintf(stderr, "fi = \"%s\"\n", fi);
	    tokstr = 0;
	    
	    FcPattern *pattern = FcPatternCreate();
	    FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)fi);
	    FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);

#ifndef FC_WEIGHT_REGULAR
#define FC_WEIGHT_REGULAR FC_WEIGHT_MEDIUM
#endif
	    FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_REGULAR);
	    FcPatternAddInteger(pattern, FC_PIXEL_SIZE, CONFIG_MENU_FONT_SIZE);
	    FcConfigSubstitute(FcConfigGetCurrent(), pattern, FcMatchPattern);

	    FcResult result = FcResultMatch;
	    FcPattern *match = FcFontMatch(FcConfigGetCurrent(), pattern, &result);
	    FcPatternDestroy(pattern);

	    if (!match || result != FcResultMatch) {
		if (match) FcPatternDestroy(match);
		continue;
	    }

	    m_font = XftFontOpenPattern(display(), match);
	    if (m_font) break;
	    FcPatternDestroy(match);
	}
	free(ffi);
	if (!m_font) {
	    m_windowManager->fatal("couldn't load menu Xft font");
	}
	m_xftColour = (XftColor *) malloc(m_windowManager->screensTotal() *
					  sizeof(XftColor));
	m_xftDraw = (XftDraw **) malloc(m_windowManager->screensTotal() *
					sizeof(XftDraw *));
#else
	m_font = (XFontStruct **) malloc(m_windowManager->screensTotal() *
					 sizeof(XFontStruct *));
#endif
	values = (XGCValues *) malloc(m_windowManager->screensTotal() *
				      sizeof(XGCValues));
	attr = (XSetWindowAttributes *) malloc(m_windowManager->screensTotal() *
				      sizeof(XSetWindowAttributes));
	
        for (int i = 0; i < m_windowManager->screensTotal(); i++)
	{
	    m_foreground = m_windowManager->allocateColour
	      (i, CONFIG_MENU_FOREGROUND, "menu foreground");
	    m_background = m_windowManager->allocateColour
	      (i, CONFIG_MENU_BACKGROUND, "menu background");
	    m_border = m_windowManager->allocateColour
	      (i, CONFIG_MENU_BORDERS, "menu border");

#ifndef CONFIG_USE_XFT
	    char **ml;
	    int mc;
	    char *ds;
	    
	    m_fontset = XCreateFontSet(display(), CONFIG_NICE_MENU_FONT,
				       &ml, &mc, &ds);
	    if (!m_fontset)
	      m_fontset = XCreateFontSet(display(), CONFIG_NASTY_FONT,
					 &ml, &mc, &ds);
	    if (m_fontset) {
		XFontStruct **fs_list;
		XFontsOfFontSet(m_fontset, &fs_list, &ml);
		m_font[i] = fs_list[0];
	    } else {
		m_font[i] = NULL;
	    }
#define XDrawString(t,u,v,w,x,y,z) XmbDrawString(t,u,m_fontset,v,w,x,y,z)
	    if (!m_font[i]) m_windowManager->fatal("couldn't load menu font\n");
#endif
	    
	    values[i].background = m_background;
	    values[i].foreground = m_foreground ^ m_background;
	    values[i].function = GXxor;
	    values[i].line_width = 0;
	    values[i].subwindow_mode = IncludeInferiors;
#ifndef CONFIG_USE_XFT
	    values[i].font = m_font[i]->fid;
#endif
	    m_menuGC[i] = XCreateGC
	      (display(), m_windowManager->mroot(i),
	       GCForeground | GCBackground | GCFunction |
	       GCLineWidth | GCSubwindowMode, &values[i]);

#ifndef CONFIG_USE_XFT
	    XChangeGC(display(), Border::drawGC(m_windowManager, i),
		      GCFont, &values[i]);
#endif

	    m_window[i] = XCreateSimpleWindow
	      (display(), m_windowManager->mroot(i), 0, 0, 1, 1, 1,
	       m_border, m_background);

	    
#if ( CONFIG_USE_PIXMAPS != False ) && ( CONFIG_USE_PIXMAP_MENUS != False )
	    attr[i].background_pixmap = Border::backgroundPixmap(manager);
#endif
	    attr[i].save_under =
	      (DoesSaveUnders(ScreenOfDisplay(display(), i)) ?
	     True : False);

#if ( CONFIG_USE_PIXMAPS != False ) && ( CONFIG_USE_PIXMAP_MENUS != False )
	    XChangeWindowAttributes
	      (display(), m_window[i], CWBackPixmap, &attr[i]);
#endif
	    XChangeWindowAttributes
	      (display(), m_window[i], CWSaveUnder, &attr[i]);

#ifdef CONFIG_USE_XFT
	    XftColorAllocName
		(display(),
		 XDefaultVisual(display(), i),
		 XDefaultColormap(display(), i),
		 CONFIG_MENU_FOREGROUND,
		 &m_xftColour[i]);

	    m_xftDraw[i] = XftDrawCreate(display(), m_window[i],
					 XDefaultVisual(display(), i),
					 XDefaultColormap(display(), i));
#endif
	}
	m_initialised = True;
    }
}
Esempio n. 15
0
File: Menu.C Progetto: bbidulock/wmx
int Menu::getSelection()
{
    m_items = getItems(&m_nItems, &m_nHidden);
    XButtonEvent *xbev = (XButtonEvent *)m_event; // KeyEvent is similar enough

    if (xbev->window == m_window[screen()] || m_nItems == 0) return -1;

    int width, maxWidth = 10;
    for (int i = 0; i < m_nItems; i++) {
	width = getTextWidth(m_items[i], STRLEN_MITEMS(i));
	if (width > maxWidth) maxWidth = width;
    }
    maxWidth += 32;

    Boolean isKeyboardMenu = isKeyboardMenuEvent(m_event);
    int selecting = isKeyboardMenu ? 0 : -1, prev = -1;
#ifdef CONFIG_USE_XFT
    int entryHeight = m_font->ascent + m_font->descent + 4;
#else
    int entryHeight = m_font[screen()]->ascent + m_font[screen()]->descent + 4;
#endif
    int totalHeight = entryHeight * m_nItems + 13;

    int mx = DisplayWidth (display(), screen()) - 1;
    int my = DisplayHeight(display(), screen()) - 1;

    int x, y;

    if (isKeyboardMenu) {
	x = mx / 2 - maxWidth / 2;
	y = my / 2 - totalHeight / 2;
    } else {

	x = xbev->x - maxWidth/2;
	y = xbev->y - 2;

	Boolean warp = False;

	if (x < 0) {
	    xbev->x -= x;
	    x = 0;
	    warp = True;
	} else if (x + maxWidth >= mx) {
	    xbev->x -= x + maxWidth - mx;
	    x = mx - maxWidth;
	    warp = True;
	}
    
	if (y < 0) {
	    xbev->y -= y;
	    y = 0;
	    warp = True;
	} else if (y + totalHeight >= my) {
	    xbev->y -= y + totalHeight - my;
	    y = my - totalHeight;
	    warp = True;
	}

	if (warp) XWarpPointer(display(), None, root(), None, None,
			       None, None, xbev->x, xbev->y);
    }

    XMoveResizeWindow(display(), m_window[screen()], x, y, maxWidth, totalHeight);
    XSelectInput(display(), m_window[screen()], MenuMask);
    XMapRaised(display(), m_window[screen()]);

    if (m_windowManager->attemptGrab(m_window[screen()], None,
				     MenuGrabMask, xbev->time)
	!= GrabSuccess) {
	XUnmapWindow(display(), m_window[screen()]);
	return -1;
    }
    
    if (isKeyboardMenu) {
	if (m_windowManager->attemptGrabKey(m_window[screen()], xbev->time)
	    != GrabSuccess) {
	    XUnmapWindow(display(), m_window[screen()]);
	    return -1;
	}
    }	    

    Boolean done = False;
    Boolean drawn = False;
    XEvent event;
    struct timeval sleepval;
    unsigned long tdiff = 0L;
    Boolean speculating = False;
    Boolean foundEvent;

    while (!done)
    {
	int i;
	foundEvent = False;

	if (CONFIG_FEEDBACK_DELAY >= 0 &&
	    tdiff > (unsigned long)CONFIG_FEEDBACK_DELAY &&
	    !isKeyboardMenu && // removeFeedback didn't seem to work for it
	    !speculating) {

	    if (selecting >= 0 && selecting < m_nItems) {
		raiseFeedbackLevel(selecting);
		XRaiseWindow(display(), m_window[screen()]);
	    }

	    speculating = True;
	}

	//!!! MenuMask | ??? suggests MenuMask is wrong
	while (XCheckMaskEvent
	       (display(), MenuMask | StructureNotifyMask |
		KeyPressMask | KeyReleaseMask, &event)) {
	    foundEvent = True;
	    if (event.type != MotionNotify) break;
	}

	if (!foundEvent) {
	    sleepval.tv_sec = 0;
	    sleepval.tv_usec = 10000;
	    select(0, 0, 0, 0, &sleepval);
	    tdiff += 10;
	    continue;
	}
	
	switch (event.type)
	{
	case ButtonPress:
	    break;
	    
	case ButtonRelease:
	    if (isKeyboardMenu) break;

	    if (drawn) {

		if (event.xbutton.button != xbev->button) break;
		x = event.xbutton.x;
		y = event.xbutton.y - 11;
		i = y / entryHeight;
		
		if (selecting >= 0 && y >= selecting * entryHeight - 3 &&
		    y <= (selecting + 1) * entryHeight - 3) i = selecting;

		if (m_hasSubmenus && (i >= 0 && i < m_nHidden)) i = -i;
		
		if (x < 0 || x > maxWidth || y < -3) i = -1;
		else if (i < 0 || i >= m_nItems) i = -1;
		
	    } else {
		i = -1;
	    }
	    
	    if (!nobuttons(&event.xbutton)) i = -1;
	    m_windowManager->releaseGrab(&event.xbutton);
	    XUnmapWindow(display(), m_window[screen()]);
	    selecting = i;
	    done = True;
	    break;

	case MotionNotify:
	    if (!drawn || isKeyboardMenu) break;

	    x = event.xbutton.x;
	    y = event.xbutton.y - 11;
	    prev = selecting;
	    selecting = y / entryHeight;

	    if (prev >= 0 && y >= prev * entryHeight - 3 &&
		y <= (prev+1) * entryHeight - 3) selecting = prev;

	    if (m_hasSubmenus && (selecting >= 0 && selecting < m_nHidden) &&
		x >= maxWidth-32 && x < maxWidth)
	    {
		xbev->x += event.xbutton.x - 32;
		xbev->y += event.xbutton.y;
		
		createSubmenu ((XEvent *)xbev, selecting);
		done = True;
		break;
	    }
	    
	    if (x < 0 || x > maxWidth || y < -3) selecting = -1;
	    else if (selecting < 0 || selecting > m_nItems) selecting = -1;

	    if (selecting == prev) break;
	    tdiff = 0; speculating = False;

	    if (prev >= 0 && prev < m_nItems) {
		removeFeedback(prev, speculating);
		XFillRectangle(display(), m_window[screen()], m_menuGC[screen()],
			       4, prev * entryHeight + 9,
			       maxWidth - 8, entryHeight);
	    }

	    if (selecting >= 0 && selecting < m_nItems) {
		showFeedback(selecting);
		XRaiseWindow(display(), m_window[screen()]);
		XFillRectangle(display(), m_window[screen()], m_menuGC[screen()],
			       4, selecting * entryHeight + 9,
			       maxWidth - 8, entryHeight);
	    }
	    
	    break;
			
	case Expose:

	    if (CONFIG_MAD_FEEDBACK && event.xexpose.window != m_window[screen()]) {
		m_windowManager->dispatchEvent(&event);
		break;
	    }

	    XClearWindow(display(), m_window[screen()]);
			
	    XDrawRectangle(display(), m_window[screen()], m_menuGC[screen()], 2, 7,
			   maxWidth - 5, totalHeight - 10);

	    for (i = 0; i < m_nItems; i++) {

		int dx = getTextWidth(m_items[i], STRLEN_MITEMS(i));
#ifdef CONFIG_USE_XFT
		int dy = i * entryHeight + m_font->ascent + 10;
#else
		int dy = i * entryHeight + m_font[screen()]->ascent + 10;
#endif

		if (i >= m_nHidden) {
#ifdef CONFIG_USE_XFT
		    XftDrawStringUtf8(m_xftDraw[screen()],
				      &m_xftColour[screen()],
				      m_font,
				      maxWidth - 8 - dx, dy,
				      (FcChar8 *)m_items[i], STRLEN_MITEMS(i));
#else
		    XDrawString(display(), m_window[screen()],
				Border::drawGC(m_windowManager,screen()),
				maxWidth - 8 - dx, dy,
				m_items[i], STRLEN_MITEMS(i));
#endif
		} else {
#ifdef CONFIG_USE_XFT
		    XftDrawStringUtf8(m_xftDraw[screen()],
				      &m_xftColour[screen()],
				      m_font,
				      8, dy,
				      (FcChar8 *)m_items[i], STRLEN_MITEMS(i));
#else
		    XDrawString(display(), m_window[screen()],
				Border::drawGC(m_windowManager,screen()),
				8, dy, m_items[i], STRLEN_MITEMS(i));
#endif
		}
	    }

	    if (selecting >= 0 && selecting < m_nItems) {
		XFillRectangle(display(), m_window[screen()], m_menuGC[screen()],
			       4, selecting * entryHeight + 9,
			       maxWidth - 8, entryHeight);
	    }

	    drawn = True;
	    break;

	case KeyPress:
	{
	    if (!isKeyboardMenu) break;

	    KeySym key = XKeycodeToKeysym(display(), event.xkey.keycode, 0);

	    if (key == CONFIG_MENU_SELECT_KEY) {

		if (!drawn) selecting = -1;

		if (m_hasSubmenus && selecting >= 0 && selecting < m_nHidden)
		{
		    createSubmenu((XEvent *)xbev, selecting);
		    selecting = -1;
		}
		m_windowManager->releaseGrabKeyMode(&event.xkey);
		XUnmapWindow(display(), m_window[screen()]);
		done = True;
		break;

	    } else if (key == CONFIG_MENU_CANCEL_KEY) {

		m_windowManager->releaseGrabKeyMode(&event.xkey);
		XUnmapWindow(display(), m_window[screen()]);
		if (selecting >= 0) removeFeedback(selecting, speculating);
		selecting = -1;
		done = True;
		break;

	    } else if (key != CONFIG_MENU_UP_KEY &&
		       key != CONFIG_MENU_DOWN_KEY) {
		break;
	    }

	    if (!drawn) break;
	    prev = selecting;

	    if (key == CONFIG_MENU_UP_KEY) {

		if (prev <= 0) selecting = m_nItems - 1;
		else selecting = prev - 1;

	    } else {

		if (prev == m_nItems - 1 || prev < 0) selecting = 0;
		else selecting = prev + 1;
	    }

	    tdiff = 0; speculating = False;
	    
	    if (prev >= 0 && prev < m_nItems) {
	    	removeFeedback(prev, speculating);
		XFillRectangle(display(), m_window[screen()], m_menuGC[screen()],
			       4, prev * entryHeight + 9,
			       maxWidth - 8, entryHeight);
	    }

	    if (selecting >= 0 && selecting < m_nItems) {
		showFeedback(selecting);
		XRaiseWindow(display(), m_window[screen()]);
		XFillRectangle(display(), m_window[screen()], m_menuGC[screen()],
			       4, selecting * entryHeight + 9,
			       maxWidth - 8, entryHeight);
	    }

	    break;
	}

	case KeyRelease:
	    break;

	default:
	    if (event.xmap.window == m_window[screen()]) break;
	    m_windowManager->dispatchEvent(&event);
	}
    }

    if (selecting >= 0) removeFeedback(selecting, speculating);
    return selecting;
}
/*-----------------------------------------------------------------------------------------------
 * Function: begin
 * Description: Initialize lcd columns, rows and dot size
 * Ins: Integer value for col, row and dotsize.
 * Outs: none
 * ----------------------------------------------------------------------------------------------*/
void LCD::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
	// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
	// according to datasheet, we need at least 40ms after power rises above 2.7V
	// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
	delay(50);

	Wire.begin();
	// first thing we do is get the GPIO expander's head working straight, 
  // with a boatload of junk data.
	Wire.beginTransmission(MCP23008_ADDRESS | lcd_i2cAddr);
#if ARDUINO >= 100
	Wire.write((byte)MCP23008_IODIR);
	Wire.write((byte)0xFF);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
	Wire.write((byte)0x00);
#else
	Wire.send(MCP23008_IODIR);
	Wire.send(0xFF);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.send(0x00);
#endif
	Wire.endTransmission();

	// now we set the GPIO expander's I/O direction to output since it's soldered to an LCD output.
	Wire.beginTransmission(MCP23008_ADDRESS | lcd_i2cAddr);
#if ARDUINO >= 100
	Wire.write((byte)MCP23008_IODIR);
	Wire.write((byte)0x00); // all output: 00000000 for pins 1...8
#else
	Wire.send(MCP23008_IODIR);
	Wire.send(0x00); // all output: 00000000 for pins 1...8
#endif
	Wire.endTransmission();

	if (lines > 1) {
		_displayfunction |= LCD_2LINE;
	}
	_numlines = lines;
	_currline = 0;

	// for some 1 line displays you can select a 10 pixel high font
	if ((dotsize != 0) && (lines == 1)) {
		_displayfunction |= LCD_5x10DOTS;
	}

	//put the LCD into 4 bit mode
	// start with a non-standard command to make it realize we're speaking 4-bit here
	// per LCD datasheet, first command is a single 4-bit burst, 0011.
        //-----
        //  we cannot assume that the LCD panel is powered at the same time as
        //  the arduino, so we have to perform a software reset as per page 45
        //  of the HD44780 datasheet - (kch)
        //-----
        // bit pattern for the burstBits function is
        //
        //  7   6   5   4   3   2   1   0
        // LT  D7  D6  D5  D4  EN  RS  n/c
        //-----
        lcd_burstBits(B10011100); // send LITE D4 D5 high with enable
        lcd_burstBits(B10011000); // send LITE D4 D5 high with !enable
        lcd_burstBits(B10011100); //
        lcd_burstBits(B10011000); //
        lcd_burstBits(B10011100); // repeat twice more
        lcd_burstBits(B10011000); //
        lcd_burstBits(B10010100); // send D4 low and LITE D5 high with enable
        lcd_burstBits(B10010000); // send D4 low and LITE D5 high with !enable
	delay(5); // this shouldn't be necessary, but sometimes 16MHz is stupid-fast.
	
	command(LCD_FUNCTIONSET | _displayfunction); // then send 0010NF00 (N=lines, F=font)
	delay(5); // for safe keeping...
	command(LCD_FUNCTIONSET | _displayfunction); // ... twice.
	delay(5); // done!

	// turn on the LCD with our defaults. since these libs seem to use personal preference, 
  // I like a cursor.
	_displaycontrol = LCD_DISPLAYON;  
	display();
	// clear it off
	clear();

	_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
	// set the entry mode
	command(LCD_ENTRYMODESET | _displaymode);

	setBacklight(HIGH); // turn the backlight on if so equipped.
}
Esempio n. 17
0
BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
{
	switch (message) 
	{
		case WM_INITDIALOG :
		{
			switchTo(activeText);
			::SendDlgItemMessage(_hSelf, IDC_COL_DEC_RADIO, BM_SETCHECK, TRUE, 0);
			goToCenter();

			NppParameters *pNppParam = NppParameters::getInstance();
			ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture();
			if (enableDlgTheme)
			{
				enableDlgTheme(_hSelf, ETDT_ENABLETAB);
				redraw();
			}
			return TRUE;
		}
		case WM_COMMAND : 
		{
			switch (wParam)
			{
				case IDCANCEL : // Close
					display(false);
					return TRUE;

				case IDOK :
                {
					(*_ppEditView)->execute(SCI_BEGINUNDOACTION);
					
					const int stringSize = 1024;
					TCHAR str[stringSize];
					
					bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0));
					
					if (isTextMode)
					{
						::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, stringSize, (LPARAM)str);

						display(false);
						
						if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE) || (*_ppEditView)->execute(SCI_GETSELECTIONS) > 1)
						{
							ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
							std::sort(colInfos.begin(), colInfos.end(), SortInPositionOrder());
							(*_ppEditView)->columnReplace(colInfos, str);
							std::sort(colInfos.begin(), colInfos.end(), SortInSelectOrder());
							(*_ppEditView)->setMultiSelections(colInfos);
						}
						else
						{
							int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS);
							int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos);
							int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos);
							int endPos = (*_ppEditView)->execute(SCI_GETLENGTH);
							int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos);

							int lineAllocatedLen = 1024;
							TCHAR *line = new TCHAR[lineAllocatedLen];

							for (int i = cursorLine ; i <= endLine ; i++)
							{
								int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i);
								int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i);

								int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd);
								int lineLen = lineEnd - lineBegin + 1;

								if (lineLen > lineAllocatedLen)
								{
									delete [] line;
									line = new TCHAR[lineLen];
								}
								(*_ppEditView)->getGenericText(line, lineLen, lineBegin, lineEnd);
								generic_string s2r(line);

								if (lineEndCol < cursorCol)
								{
									generic_string s_space(cursorCol - lineEndCol, ' ');
									s2r.append(s_space);
									s2r.append(str);
								}
								else
								{
									int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol);
									int posRelative2Start = posAbs2Start - lineBegin;
									s2r.insert(posRelative2Start, str);
								}
								(*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd);
							}
							delete [] line;
						}
					}
					else
					{
						int initialNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INITNUM_EDIT, NULL, TRUE);
						int increaseNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INCREASENUM_EDIT, NULL, TRUE);
						UCHAR format = getFormat();
						display(false);
						
						if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE) || (*_ppEditView)->execute(SCI_GETSELECTIONS) > 1)
						{
							ColumnModeInfos colInfos = (*_ppEditView)->getColumnModeSelectInfo();
							std::sort(colInfos.begin(), colInfos.end(), SortInPositionOrder());
							(*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format);
							std::sort(colInfos.begin(), colInfos.end(), SortInSelectOrder());
							(*_ppEditView)->setMultiSelections(colInfos);
						}
						else
						{
							int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS);
							int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos);
							int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos);
							int endPos = (*_ppEditView)->execute(SCI_GETLENGTH);
							int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos);

							int lineAllocatedLen = 1024;
							TCHAR *line = new TCHAR[lineAllocatedLen];


							UCHAR f = format & MASK_FORMAT;
							bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0;
							
							int base = 10;
							if (f == BASE_16)
								base = 16;
							else if (f == BASE_08)
								base = 8;
							else if (f == BASE_02)
								base = 2;

							int nbLine = endLine - cursorLine + 1;
							int endNumber = initialNumber + increaseNumber * (nbLine - 1);
							int nbEnd = getNbDigits(endNumber, base);
							int nbInit = getNbDigits(initialNumber, base);
							int nb = max(nbInit, nbEnd);


							for (int i = cursorLine ; i <= endLine ; i++)
							{
								int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i);
								int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i);

								int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd);
								int lineLen = lineEnd - lineBegin + 1;

								if (lineLen > lineAllocatedLen)
								{
									delete [] line;
									line = new TCHAR[lineLen];
								}
								(*_ppEditView)->getGenericText(line, lineLen, lineBegin, lineEnd);
								generic_string s2r(line);

								//
								// Calcule generic_string
								//
								int2str(str, stringSize, initialNumber, base, nb, isZeroLeading);
								initialNumber += increaseNumber;

								if (lineEndCol < cursorCol)
								{
									generic_string s_space(cursorCol - lineEndCol, ' ');
									s2r.append(s_space);
									s2r.append(str);
								}
								else
								{
									int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol);
									int posRelative2Start = posAbs2Start - lineBegin;
									s2r.insert(posRelative2Start, str);
								}

								(*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd);
							}
							delete [] line;
						}
					}
					(*_ppEditView)->execute(SCI_ENDUNDOACTION);
                    (*_ppEditView)->getFocus();
                    return TRUE;
                }
				case IDC_COL_TEXT_RADIO :
				case IDC_COL_NUM_RADIO :
				{
					switchTo((wParam == IDC_COL_TEXT_RADIO)? activeText : activeNumeric);
					return TRUE;
				}

				default :
				{
					switch (HIWORD(wParam))
					{
						case EN_SETFOCUS :
						case BN_SETFOCUS :
							//updateLinesNumbers();
							return TRUE;
						default :
							return TRUE;
					}
					break;
				}
			}
		}

		default :
			return FALSE;
	}
	//return FALSE;
}
Esempio n. 18
0
void timer(int = 0)
{
  game.tick();
  display();
  glutTimerFunc(300, timer, 0);
}
Esempio n. 19
0
File: query.c Progetto: moben/pacman
int pacman_query(alpm_list_t *targets)
{
	int ret = 0;
	int match = 0;
	alpm_list_t *i;
	alpm_pkg_t *pkg = NULL;
	alpm_db_t *db_local;

	/* First: operations that do not require targets */

	/* search for a package */
	if(config->op_q_search) {
		ret = query_search(targets);
		return ret;
	}

	/* looking for groups */
	if(config->group) {
		ret = query_group(targets);
		return ret;
	}

	if(config->op_q_foreign || config->op_q_upgrade) {
		if(check_syncdbs(1, 1)) {
			return 1;
		}
	}

	db_local = alpm_option_get_localdb(config->handle);

	/* operations on all packages in the local DB
	 * valid: no-op (plain -Q), list, info, check
	 * invalid: isfile, owns */
	if(targets == NULL) {
		if(config->op_q_isfile || config->op_q_owns) {
			pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
			return 1;
		}

		for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
			pkg = alpm_list_getdata(i);
			if(filter(pkg)) {
				int value = display(pkg);
				if(value != 0) {
					ret = 1;
				}
				match = 1;
			}
		}
		if(!match) {
			ret = 1;
		}
		return ret;
	}

	/* Second: operations that require target(s) */

	/* determine the owner of a file */
	if(config->op_q_owns) {
		ret = query_fileowner(targets);
		return ret;
	}

	/* operations on named packages in the local DB
	 * valid: no-op (plain -Q), list, info, check */
	for(i = targets; i; i = alpm_list_next(i)) {
		char *strname = alpm_list_getdata(i);

		if(config->op_q_isfile) {
			alpm_pkg_load(config->handle, strname, 1, 0, &pkg);
		} else {
			pkg = alpm_db_get_pkg(db_local, strname);
		}

		if(pkg == NULL) {
			switch(alpm_errno(config->handle)) {
				case ALPM_ERR_PKG_NOT_FOUND:
					pm_fprintf(stderr, ALPM_LOG_ERROR,
							_("package '%s' was not found\n"), strname);
					if(!config->op_q_isfile && access(strname, R_OK) == 0) {
						pm_fprintf(stderr, ALPM_LOG_WARNING,
								_("'%s' is a file, you might want to use %s.\n"),
								strname, "-p/--file");
					}
					break;
				default:
					pm_fprintf(stderr, ALPM_LOG_ERROR,
							_("could not load package '%s': %s\n"), strname,
							alpm_strerror(alpm_errno(config->handle)));
					break;
			}
			ret = 1;
			continue;
		}

		if(filter(pkg)) {
			int value = display(pkg);
			if(value != 0) {
				ret = 1;
			}
			match = 1;
		}

		if(config->op_q_isfile) {
			alpm_pkg_free(pkg);
			pkg = NULL;
		}
	}

	if(!match) {
		ret = 1;
	}

	return ret;
}
Esempio n. 20
0
//input values into element
void input(point *p)
{
	printf("enter values for x and y (e.g. 1 2): ");
	scanf("%d %d", &p->x, &p->y);
	display(p);
}
Esempio n. 21
0
int main(void) {
	int width = 0;
	int height = 0;
	int diagonal = 0;
	char nom[FILENAME_MAX+1] = "";
	int len = 0;
	Image mask = init_mask();

	/**
	 * Demande à l'utilisateur :
	 *  - le nom du fichier
	 *  - la hauteur de l'image
	 *  - la largueur de l'image
	 *  - la longueur de la diagonal du losange
	 */
	do {
		printf("Entrez un nomn de fichier : ");
		fgets(nom, FILENAME_MAX+1, stdin);
		len = strlen(nom) - 1;
		if ((len >= 0) && nom[len] == '\n') {
			nom[len] = '\0';
		} else {
			while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n');
		}
	} while ((len < 1) && !feof(stdin) && !ferror(stdin));
	
	char c_par = ' ';

	// si c_par != '\n', cela veut dire que l'utilisateur a entré des lettres et des chiffres
	while(height <= 0 || height > MAX_IMAGE_HEIGHT || c_par != '\n') {
		printf("Hauteur de l'image (max : %d) : ", MAX_IMAGE_HEIGHT);
		scanf("%d%c", &height, &c_par);
		if(c_par != '\n') {
			fprintf(stderr, "Erreur: entrez seulement des nombres !\n");
			while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n');
		}
	}

	while(width <= 0 || width > MAX_IMAGE_WIDTH || c_par != '\n') {
		printf("Largeur de l'image (max : %d) : ", MAX_IMAGE_WIDTH);
		scanf("%d%c", &width, &c_par);
		if(c_par != '\n') {
			fprintf(stderr, "Erreur: entrez seulement des nombres !\n");
			while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n');
		}
	}

	if(width % 2 == 0 || height % 2 == 0) {
		if (width == 100) { // si la dimension = 100, elle sera corrigée vers le bas
			width = 99;
		}

		if(height == 100) {
			height = 99;
		}

		width |= 1; //force les valeurs à être impaires
		height |= 1;
		printf("Les dimmensions ont été ajustées à des valeurs impaires. \n");
		printf("Hauteur : %d, Largeur : %d\n", height, width);
	}

	do {
		printf("Diagonal du losange : ");
		scanf("%d%c", &diagonal, &c_par);
		if(c_par != '\n') {
			fprintf(stderr, "Erreur: entrez seulement des nombres !\n");
			while(!feof(stdin) && !ferror(stdin) && getc(stdin) != '\n');
		}
	} while(diagonal < 0 || (diagonal > height && diagonal > width) || c_par != '\n');

	if(diagonal % 2 == 0 && (diagonal == height + 1 || diagonal == width + 1)) {
		// si la diagonale est égale à une des dimensions entrées (avant ajustement), elle sera corrigée
		diagonal = diagonal - 1; 
	}

	/**
	 * dessin du losange et affichage de l'image
	 */
	Image i = diamond(height, width, diagonal);
	display(stdout, i);

	/**
	 * écriture de l'image dans un fichier puis lecture du fichier
	 */
	write_to_file(nom, i);
	Image r = read_from_file(nom);
	display(stdout, r);

	/**
	 * application du filtre et affichage du résultat
	 */
	Image res = filter(i, mask);
	display(stdout, res);
	
	return 0;
}
void GLCanvas::keyboard(unsigned char key, int x, int y) {
  args->raytracing_animation = false;
  switch (key) {
    // RAYTRACING STUFF
  case 'r':  case 'R':
    // animate raytracing of the scene
    args->gather_indirect=false;
    args->raytracing_animation = !args->raytracing_animation;
    if (args->raytracing_animation) {
      raytracing_skip = my_max(args->width,args->height) / 10;
      if (raytracing_skip % 2 == 0) raytracing_skip++;
      assert (raytracing_skip >= 1);
      raytracing_x = raytracing_skip/2;
      raytracing_y = raytracing_skip/2;
      display(); // clear out any old rendering
      printf ("raytracing animation started, press 'R' to stop\n");
    } else
      printf ("raytracing animation stopped, press 'R' to start\n");    
    break;
  case 't':  case 'T': {
    // visualize the ray tree for the pixel at the current mouse position
    int i = x;
    int j = glutGet(GLUT_WINDOW_HEIGHT)-y;
    RayTree::Activate();
    raytracing_skip = 1;
    TraceRay(i,j);
    RayTree::Deactivate();
    // redraw
  RayTree::setupVBOs();
  radiosity->setupVBOs();
  photon_mapping->setupVBOs();


  glutPostRedisplay();
    break; }

  case 'l':  case 'L': { 
    // toggle photon rendering
    args->render_photons = !args->render_photons;
    glutPostRedisplay();
    break; }
  case 'k':  case 'K': { 
    // toggle photon rendering
    args->render_kdtree = !args->render_kdtree;
    glutPostRedisplay();
    break; }
  case 'p':  case 'P': { 
    // toggle photon rendering
    photon_mapping->TracePhotons();
    photon_mapping->setupVBOs();
    glutPostRedisplay();
    break; }
  case 'g':  case 'G': { 
    args->gather_indirect = true;
    args->raytracing_animation = !args->raytracing_animation;
    if (args->raytracing_animation) {
      raytracing_skip = my_max(args->width,args->height) / 10;
      if (raytracing_skip % 2 == 0) raytracing_skip++;
      assert (raytracing_skip >= 1);
      raytracing_x = raytracing_skip/2;
      raytracing_y = raytracing_skip/2;
      display(); // clear out any old rendering
      printf ("photon mapping animation started, press 'G' to stop\n");
    } else
      printf ("photon mapping animation stopped, press 'G' to start\n");    
    break; 
  }
    
    // RADIOSITY STUFF
  case ' ': 
    // a single step of radiosity
    radiosity->Iterate();
    radiosity->setupVBOs();
    glutPostRedisplay();
    break;
  case 'a': case 'A':
    // animate radiosity solution
    args->radiosity_animation = !args->radiosity_animation;
    if (args->radiosity_animation) 
      printf ("radiosity animation started, press 'A' to stop\n");
    else
      printf ("radiosity animation stopped, press 'A' to start\n");
    break;
  case 's': case 'S':
    // subdivide the mesh for radiosity
    radiosity->Cleanup();
    radiosity->getMesh()->Subdivision();
    radiosity->Reset();
    radiosity->setupVBOs();
    glutPostRedisplay();
    break;
  case 'c': case 'C':
    // clear the radiosity solution
    radiosity->Reset();
    radiosity->setupVBOs();
    glutPostRedisplay();
    break;

    // VISUALIZATIONS
  case 'w':  case 'W':
    // render wireframe mode
    args->wireframe = !args->wireframe;
    glutPostRedisplay();
    break;
  case 'v': case 'V':
    // toggle the different visualization modes
    args->render_mode = RENDER_MODE((args->render_mode+1)%NUM_RENDER_MODES);
    switch (args->render_mode) {
    case RENDER_MATERIALS: std::cout << "RENDER_MATERIALS\n"; fflush(stdout); break;
    case RENDER_LIGHTS: std::cout << "RENDER_LIGHTS\n"; fflush(stdout); break;
    case RENDER_UNDISTRIBUTED: std::cout << "RENDER_UNDISTRIBUTED\n"; fflush(stdout); break;
    case RENDER_ABSORBED: std::cout << "RENDER_ABSORBED\n"; fflush(stdout); break;
    case RENDER_RADIANCE: std::cout << "RENDER_RADIANCE\n"; fflush(stdout); break;
    case RENDER_FORM_FACTORS: std::cout << "RENDER_FORM_FACTORS\n"; fflush(stdout); break;
    default: assert(0); }
    radiosity->setupVBOs();
    glutPostRedisplay();
    break;
  case 'i':  case 'I':
    // interpolate patch illumination values
    args->interpolate = !args->interpolate;
    radiosity->setupVBOs();
    glutPostRedisplay();
    break;
  case 'b':  case 'B':
    // interpolate patch illumination values
    args->intersect_backfacing = !args->intersect_backfacing;
    glutPostRedisplay();
    break;

  case 'q':  case 'Q':
    // quit
    delete GLCanvas::photon_mapping;
    delete GLCanvas::raytracer;
    delete GLCanvas::radiosity;
    delete GLCanvas::mesh;
    exit(0);
    break;
  default:
    printf("UNKNOWN KEYBOARD INPUT  '%c'\n", key);
  }
}
Esempio n. 23
0
main (int argc, char *argv[])
{
FILE *f;
int l, c;
int ch;

	if (argc != 2)
	{
		printf ("Usage: LIFE filename\n");
		return;
	}

	for (l=0; l<NL; l++)
		for (c=0; c<NC; c++)
		{
			space[l][c] = 0;
			space1[l][c] = 0;
		}

	f = fopen (argv[1], "r");
	if (f == NULL)
	{
		perror (argv[1]);
	}
	else
	{
		l = 1;
		c = 1;
		for (;;)
		{
			ch = getc (f);
			if (feof(f))
				break;
			if (ch == '\n')
			{
				l++;
				c = 1;
			}
			else if (ch == '.' || ch == ' ')
			{
				space[l][c++] = 0;
			}
			else
			{
				space[l][c++] = 1;
			}
		}

		clrscr ();

		for (;;)
		{
			display (space);

			while (!kbhit());
			getch();

			step (space);
		}

	}


}
Esempio n. 24
0
void Character::display_all() const 
{
    display(left);
    display();
    display(right);
}
int main() {
display();
getch();
return 0;
}
Esempio n. 26
0
void DrawingAreaImpl::displayTimerFired()
{
    display();
}
Esempio n. 27
0
void wxSFMLCanvas::OnPaint(wxPaintEvent&) {
  wxPaintDC dc(this);
  OnUpdate();
  display();
}
Esempio n. 28
0
void Client::manage(Boolean mapped)
{
    Boolean shouldHide, reshape;
    XWMHints *hints;
    Display *d = display();
    long mSize;
    int state;

    XSelectInput(d, m_window, ColormapChangeMask | EnterWindowMask |
		 PropertyChangeMask | FocusChangeMask);

    m_iconName = getProperty(XA_WM_ICON_NAME);
    m_name = getProperty(XA_WM_NAME);
    setLabel();

    getColormaps();
    getProtocols();
    getTransient();

    hints = XGetWMHints(d, m_window);

    if (!getState(&state)) {
	state = hints ? hints->initial_state : NormalState;
    }

    shouldHide = (state == IconicState);
    if (hints) XFree(hints);

    if (XGetWMNormalHints(d, m_window, &m_sizeHints, &mSize) == 0 ||
	m_sizeHints.flags == 0) {
	m_sizeHints.flags = PSize;
    }

    m_fixedSize = False;
//    if ((m_sizeHints.flags & (USSize | PSize))) m_fixedSize = True;
    if ((m_sizeHints.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) &&
	(m_sizeHints.min_width  == m_sizeHints.max_width &&
	 m_sizeHints.min_height == m_sizeHints.max_height)) m_fixedSize = True;

    reshape = !mapped;

    if (m_fixedSize) {
	if ((m_sizeHints.flags & USPosition)) reshape = False;
	if ((m_sizeHints.flags & PPosition) && shouldHide) reshape = False;
	if ((m_transient != None)) reshape = False;
    }

    if ((m_sizeHints.flags & PBaseSize)) {
	m_minWidth  = m_sizeHints.base_width;
	m_minHeight = m_sizeHints.base_height;
    } else if ((m_sizeHints.flags & PMinSize)) {
	m_minWidth  = m_sizeHints.min_width;
	m_minHeight = m_sizeHints.min_height;
    } else {
	m_minWidth = m_minHeight = 50;
    }

    // act

    gravitate(False);

    // zeros are iffy, should be calling some Manager method
    int dw = DisplayWidth(display(), 0), dh = DisplayHeight(display(), 0);

    if (m_w < m_minWidth) {
	m_w = m_minWidth; m_fixedSize = False; reshape = True;
    }
    if (m_h < m_minHeight) {
	m_h = m_minHeight; m_fixedSize = False; reshape = True;
    }

    if (m_w > dw - 8) m_w = dw - 8;
    if (m_h > dh - 8) m_h = dh - 8;

    if (m_x > dw - m_border->xIndent()) {
	m_x = dw - m_border->xIndent();
    }

    if (m_y > dh - m_border->yIndent()) {
	m_y = dh - m_border->yIndent();
    }

    if (m_x < m_border->xIndent()) m_x = m_border->xIndent();
    if (m_y < m_border->yIndent()) m_y = m_border->yIndent();
    
    m_border->configure(m_x, m_y, m_w, m_h, 0L, Above);

    if (mapped) m_reparenting = True;
    if (reshape && !m_fixedSize) XResizeWindow(d, m_window, m_w, m_h);
    XSetWindowBorderWidth(d, m_window, 0);

    m_border->reparent();

    // (support for shaped windows absent)

    XAddToSaveSet(d, m_window);
    m_managed = True;

    if (shouldHide) hide();
    else {
	XMapWindow(d, m_window);
	m_border->map();
	setState(NormalState);

	if (CONFIG_CLICK_TO_FOCUS ||
	    (m_transient != None && activeClient() &&
	    activeClient()->m_window == m_transient)) {
	    activate();
	    mapRaised();
	} else {
	    deactivate();
	}
    }
    
    if (activeClient() && !isActive()) {
	activeClient()->installColormap();
    }

    if (CONFIG_AUTO_RAISE) {
	m_windowManager->stopConsideringFocus();
	focusIfAppropriate(False);
    }
}
Esempio n. 29
0
//----------------------------------------------------------------------------------------------
void LoggerWidget::logInfo (const QString & info)
{
    _logConsole->setTextColor (Qt::black);
    display (info);
}
Esempio n. 30
0
main()
{
	struct list *root=NULL;
	int choice,pos,val;
	printf("MENU : \n1.create\n2.insert at begin\n3.insert at end\n4.insert at pos\n5.delete at begin\n6.delete at end\n7.delete at pos\n8.display\n9.exit\n");
	while(1)
	{
		printf("enter ur choice\n");
		scanf("%d",&choice);
		switch(choice)
		{
		case 1:
			if(root!=NULL)
			printf("list is already created\n");
			else
			{
				printf("enter value\n");
				scanf("%d",&val);
				root=insert_at_end(root,val);
				printf("list is created\n");
			}
			break;
		case 2:
			printf("enter value\n");
			scanf("%d",&val);
			root=insert_at_begin(root,val);
			printf("value is inserted at begin\n");
			break;
		case 3:
			printf("enter the value\n");
			scanf("%d",&val);
			root=insert_at_end(root,val);
			printf("val is inserted at end\n");
			break;
		case 4:
			printf("enter val\n");
			scanf("%d",&val);
			printf("enter pos\n");
			scanf("%d",&pos);
			root=insert_at_pos(root,val,pos);
			break;
		case 5:
			if(root==NULL)
				printf("nothing to delete\n");
			else
			{
				root=delete_at_begin(root);
				printf("node is deleted at begin\n");
			}
				break;
		case 6:
			if(root==NULL)
				printf("nothing to delete\n");
			else
			{
				root=delete_at_end(root);
				printf("node is deleted at end\n");
				
			}
			break;
		case 7:
			printf("enter pos\n");
			scanf("%d",&pos);
			root=delete_at_pos(root,pos);
			break;
		case 8:
			display(root);
			break;
		case 9:
			exit(0);

		}

	}

}