Ejemplo n.º 1
0
/* Read edges of graph  */
void read_graph(int G[MAX][MAX],int V){
    int i,j;
    char ch;
    printf("\nEnter 'y' or 'n' for 'yes' or 'no', respectively, if there is an edge(u,v) or not.\n");
    flush_input();  //For removing unwanted input characters that may be residing in stdin
    for(i=0;i<V;i++)
    {
        for(j=0;j<V;j++){
            if(i == j){  //To prevent from a loop edge or edge to itself
                G[i][j] = 0;
                continue;
            }
            printf("Edge(%d,%d): ",i,j);
            ch = getchar();
            if(ch=='y' || ch=='Y')
                G[i][j] = 1;
            else if (ch=='n' || ch=='N')
                G[i][j] = 0;
            else{
                printf("\n\tWrong option!\n");
                j--;
            }
            flush_input();
        }
    }
}
Ejemplo n.º 2
0
void getinput_with_fgets() {
  char firstname[5];
  char lastname[5];
  printf("Enter your firstname :");
  fgets(firstname,5,stdin);
  printf("Enter your lastname :");
  // fflush(stdin); //This may not work
  flush_input();
  fgets(lastname,5,stdin);
  flush_input();
  printf("Hello, %s %s \n",firstname,lastname);

}
Ejemplo n.º 3
0
void rogue_escape(mob_t * m)
{
  int dir;
  int i;
  char line[DEFLEN];
  int stolen;

  if (game->player_gold == 0)
    return;

  if (m->x < player->x)
  {
    dir = -2;
    m->flip = true;
  }
  else
  {
    dir = +2;
    m->flip = false;
  }

  for (i = 0; i < 2; i++)
  {
    m->flags = GFX_HUMAN_FALL1;
    draw_board(); mpause();
    m->flags = GFX_HUMAN_FALL2;
    draw_board(); mpause();
  }

  m->flags = 0;

  while (m->x > view_x - 2 && m->x <= view_x + BOARD_W + 2)
  {
    m->x += dir;
    draw_board(); spause();
  }

  m->type = MOB_NONE;

  if (game->player_gold)
  {
    if (has_eq(EQ_SHADES) && rand() % 10 == 0)
    {
      game->equipment[EQ_SHADES] = false;
      snprintf(line, DEFLEN, "ROGUE STOLE YOUR SHADES AND RAN AWAY!\n\n(WHAT A JERK)");
    }
    else
    {
      stolen = 1 + rand() % ROGUE_STEAL_GOLD;
      game->player_gold -= stolen;
      snprintf(line, DEFLEN, "ROGUE STOLE %d GOLD AND RAN AWAY!", stolen);
    }

    draw_stats();
    flush_input();
    pwait(line);
  }

  return;
}
Ejemplo n.º 4
0
size_t receive_until( char *dst, char delim, size_t max )
{
    size_t len = 0;
    size_t rx = 0;
    char c = 0;

    while( len < max ) {
        dst[len] = 0x00;

        if ( receive( STDIN, &c, 1, &rx ) != 0 ) {
            len = 0;
            goto end;
        }

        if ( c == delim ) {

            goto end;
        }

        dst[len] = c;
        len++;
    }
end:

    if (len == max)
        flush_input(STDIN);

    return len;
}
Ejemplo n.º 5
0
/*
 * This implements the "Secure Attention Key" ---  the idea is to
 * prevent trojan horses by killing all processes associated with this
 * tty when the user hits the "Secure Attention Key".  Required for
 * super-paranoid applications --- see the Orange Book for more details.
 * 
 * This code could be nicer; ideally it should send a HUP, wait a few
 * seconds, then send a INT, and then a KILL signal.  But you then
 * have to coordinate with the init process, since all processes associated
 * with the current tty must be dead before the new getty is allowed
 * to spawn.
 */
void do_SAK( struct tty_struct *tty)
{
#ifdef TTY_SOFT_SAK
	tty_hangup(tty);
#else
	struct task_struct **p;
	int line = tty->line;
	int session = tty->session;
	int		i;
	struct file	*filp;
	
	flush_input(tty);
	flush_output(tty);
 	for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) {
		if (!(*p))
			continue;
		if (((*p)->tty == line) ||
		    ((session > 0) && ((*p)->session == session)))
			send_sig(SIGKILL, *p, 1);
		else {
			for (i=0; i < NR_OPEN; i++) {
				filp = (*p)->filp[i];
				if (filp && (filp->f_op == &tty_fops) &&
				    (MINOR(filp->f_rdev) == line)) {
					send_sig(SIGKILL, *p, 1);
					break;
				}
			}
		}
	}
#endif
}
Ejemplo n.º 6
0
/*
**	funkey_local(test_list, status, ch)
**
**	Test program local function keys (pfloc)
*/
static void
funkey_local(
		TestList * t,
		int *state,
		int *ch)
{
    if (pkey_local) {
	int fk = 1;

	/* test local function key */
	sprintf(temp,
		"(pfloc) Set function key %d to execute a clear and print \"Done!\"", fk);
	ptextln(temp);
	sprintf(temp, "%sDone!", liberated(clear_screen));
	tc_putp(TPARM_2(pkey_local, fk, temp));
	sprintf(temp, "Hit function key %d.  Then hit return.", fk);
	ptextln(temp);
	(void) wait_here();
	flush_input();
	if (key_f1 && pkey_xmit) {
	    tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
	}
    } else {
	ptextln("Function key execute local (pfloc), not present.");
    }

    generic_done_message(t, state, ch);
}
Ejemplo n.º 7
0
static void isig(int sig, struct tty_struct *tty)
{
	kill_pg(tty->pgrp, sig, 1);
	if (!L_NOFLSH(tty)) {
		flush_input(tty);
		flush_output(tty);
	}
}
Ejemplo n.º 8
0
static void request_done(struct request_ctx *req, struct bufferevent *bev)
{
	/* Force the remaining bytes down our consumer's throat. */
	flush_input(req, bufferevent_get_input(bev));

	req->cb_ops->done(req->error, req->cb_arg);
	conn_stash_put_bev(req->conn_stash, bev);
	free(req->status_line);
	free(req->request_body);
	free(req);
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    	int sockfd = 0, n = 0;
		char input[1];
	char internalInput [2];
    	char recvBuff[20];
	char sendBuff[1025];
    	struct sockaddr_in serv_addr; 

    	if(argc != 3){
        	printf("\n Usage: %s <ip of server> \n",argv[0]);
        	return 1;
    	} 
		strcpy(input,argv[2]);
    	memset(recvBuff, '0',sizeof(recvBuff));
    	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
        	printf("\n Error : Could not create socket \n");
        	return 1;
    	} 

    	memset(&serv_addr, '0', sizeof(serv_addr)); 

    	serv_addr.sin_family = AF_INET;
    	serv_addr.sin_port = htons(1194); //port number

    	if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0){
        	printf("\n inet_pton error occured\n");
		return 1;
    	}

    	if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){
       		printf("\n Error : Connect Failed \n");
       		return 1;
    	}

	printf("Connection established, awaiting input...\n");
	while( atoi(internalInput) == 1 || atoi(internalInput) == 0){

		//printf("What is the input? ");
		//fgets(internalInput, 2, stdin);

		n = write(sockfd, input, 1);
		n = read(sockfd,recvBuff,22);
		printf("incoming message: %s\n",recvBuff);
		if(n < 0){
			error("Error writing to socket");
		}
		flush_input();
	}
    	return 0;
}
Ejemplo n.º 10
0
static void pty_close(struct tty_struct * tty, struct file * filp)
{
	if (!tty || (tty->count > 1))
		return;
	wake_up_interruptible(&tty->read_q.proc_list);
	if (!tty->link)
		return;
	wake_up_interruptible(&tty->link->write_q.proc_list);
	if (IS_A_PTY_MASTER(tty->line)) {
		tty_hangup(tty->link);
		flush_input(tty);
		flush_output(tty);
	}
}
Ejemplo n.º 11
0
Archivo: cmds.c Proyecto: hankem/jed
int jed_spawn_fg_process (int (*f)(VOID_STAR), VOID_STAR cd)
{
   int status;
   int inited;

   if ((Jed_Secure_Mode)
       || (Jed_Suspension_Not_Allowed))
     {
	msg_error ("Access to shell denied.");
	return -1;
     }

   /* FIXME: X_Suspend_Hook should not be here.  Currently, this hook is
    * used only by GUI jed, where suspension makes no sense.  Of course in
    * this case, spawning a foreground process also does not make sense.
    */
   if (Batch || (X_Suspend_Hook != NULL))
     return (*f) (cd);

   SLsig_block_signals ();
   inited = Jed_Display_Initialized;
   SLsig_unblock_signals ();

   jed_reset_display();
#if !defined(IBMPC_SYSTEM) && !defined(VMS)
   jed_reset_signals ();
#endif
   reset_tty();

   status = (*f) (cd);

   if (inited)
     {
#if !defined(IBMPC_SYSTEM) && !defined(VMS)
	init_signals();
#endif
	if (-1 == init_tty())
	  {
	     exit_error ("Unable to initialize terminal.", 0);
	  }

	flush_input ();
	jed_init_display ();
     }

   check_buffers();
   return status;
}
Ejemplo n.º 12
0
Archivo: screen.c Proyecto: hankem/jed
static void do_dialog(char *b)
{
   char *quit = "Quit!";

   if (Batch) return;
#ifdef FIX_CHAR_WIDTH
   FIX_CHAR_WIDTH;
#endif
   if (! *b)
     {
	if(!SLKeyBoard_Quit) return;
	b = quit;
     }

   if ((b == Error_Buffer) || (b == quit))
     {
	SLsmg_set_color (JERROR_COLOR);
	touch_screen();
     }
   else
     SLsmg_set_color (JMESSAGE_COLOR);

   SLsmg_Newline_Behavior = SLSMG_NEWLINE_PRINTABLE;
   SLsmg_gotorc (Jed_Num_Screen_Rows - 1, 0);
   SLsmg_write_string (b);
   SLsmg_set_color (0);
   SLsmg_erase_eol ();
   SLsmg_Newline_Behavior = 0;

   if ((b == Error_Buffer) || (SLKeyBoard_Quit))
     {
	jed_beep();
	flush_input();
     }

   if (*b)
     {
	if (MiniBuffer != NULL)
	  {
	     SLsmg_refresh ();
	     (void) input_pending(&Number_Ten);
	  }
	Mini_Ghost = -1;
     }
   else Mini_Ghost = 0;
}
Ejemplo n.º 13
0
/*
**	funkey_prog(test_list, status, ch)
**
**	Test program function keys (pfx)
*/
static void
funkey_prog(
	       TestList * t,
	       int *state,
	       int *ch)
{
    if (pkey_xmit) {
	int i;
	int fk = 1;
	char mm[256];

	/* test program function key */
	sprintf(temp,
		"(pfx) Set function key %d to transmit abc\\n", fk);
	ptextln(temp);
	tc_putp(TPARM_2(pkey_xmit, fk, "abc\n"));
	sprintf(temp, "Hit function key %d\n", fk);
	ptextln(temp);

	memset(mm, 0, (size_t) 4);
	for (i = 0; i < 4; ++i) {
	    int cc = getchp(STRIP_PARITY);
	    if (cc == EOF)
		break;
	    mm[i] = (char) cc;
	}
	mm[i] = '\0';

	put_crlf();
	if (mm[0] != 'a' || mm[1] != 'b' || mm[2] != 'c') {
	    sprintf(temp, "Error string received was: %s", expand(mm));
	    ptextln(temp);
	} else {
	    putln("Thank you\n");
	}
	flush_input();
	if (key_f1) {
	    tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
	}
    } else {
	ptextln("Function key transmit (pfx), not present.");
    }
    generic_done_message(t, state, ch);
}
Ejemplo n.º 14
0
/* Set the discipline of a tty line. */
static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
{
	if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS) ||
	    !(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED))
		return -EINVAL;

	if (tty->disc == ldisc)
		return 0;	/* We are already in the desired discipline */

	/* Shutdown the current discipline. */
	wait_until_sent(tty);
	flush_input(tty);
	if (ldiscs[tty->disc].close)
		ldiscs[tty->disc].close(tty);

	/* Now set up the new line discipline. */
	tty->disc = ldisc;
	if (ldiscs[tty->disc].open)
		return(ldiscs[tty->disc].open(tty));
	else
		return 0;
}
Ejemplo n.º 15
0
void do_tty_hangup(struct tty_struct * tty, struct file_operations *fops)
{
	int i;
	struct file * filp;
	struct task_struct *p;
	int dev;

	if (!tty)
		return;
	dev = MKDEV(TTY_MAJOR,tty->line);
	for (filp = first_file, i=0; i<nr_files; i++, filp = filp->f_next) {
		if (!filp->f_count)
			continue;
		if (filp->f_rdev != dev)
			continue;
		if (filp->f_inode && filp->f_inode->i_rdev == CONSOLE_DEV)
			continue;
		if (filp->f_op != &tty_fops)
			continue;
		filp->f_op = fops;
	}
	flush_input(tty);
	flush_output(tty);
	wake_up_interruptible(&tty->secondary.proc_list);
	if (tty->session > 0) {
		kill_sl(tty->session,SIGHUP,1);
		kill_sl(tty->session,SIGCONT,1);
	}
	tty->session = 0;
	tty->pgrp = -1;
 	for_each_task(p) {
		if (p->tty == tty->line)
			p->tty = -1;
	}
	if (tty->hangup)
		(tty->hangup)(tty);
}
Ejemplo n.º 16
0
/*
**	funkey_prog(test_list, status, ch)
**
**	Test program function keys (pfx)
*/
static void
funkey_prog(
	struct test_list *t,
	int *state,
	int *ch)
{
	int i, fk;
	char mm[256];

	fk = 1;	/* use function key 1 for now */
	if (pkey_xmit) {
		/* test program function key */
		sprintf(temp,
			"(pfx) Set function key %d to transmit abc\\n", fk);
		ptextln(temp);
		tc_putp(TPARM_2(pkey_xmit, fk, "abc\n"));
		sprintf(temp, "Hit function key %d\n", fk);
		ptextln(temp);
		for (i = 0; i < 4; ++i)
			mm[i] = (char) getchp(STRIP_PARITY);
		mm[i] = '\0';
		put_crlf();
		if (mm[0] != 'a' || mm[1] != 'b' || mm[2] != 'c') {
			sprintf(temp, "Error string received was: %s", expand(mm));
			ptextln(temp);
		} else {
			putln("Thank you\n");
		}
		flush_input();
		if (key_f1) {
			tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
		}
	} else {
		ptextln("Function key transmit (pfx), not present.");
	}
	generic_done_message(t, state, ch);
}
Ejemplo n.º 17
0
Archivo: radio.c Proyecto: nysan/alpine
/*----------------------------------------------------------------------
    Prompt user for a choice among alternatives

Args --  utf8prompt:    The prompt for the question/selection
         line:      The line to prompt on, if negative then relative to bottom
         esc_list:  ESC_KEY_S list of keys
         dflt:	    The selection when the <CR> is pressed (should probably
		      be one of the chars in esc_list)
         on_ctrl_C: The selection when ^C is pressed
         help_text: Text to be displayed on bottom two lines
	 flags:     Logically OR'd flags modifying our behavior to:
		RB_FLUSH_IN    - Discard any pending input chars.
		RB_ONE_TRY     - Only give one chance to answer.  Returns
				 on_ctrl_C value if not answered acceptably
				 on first try.
		RB_NO_NEWMAIL  - Quell the usual newmail check.
		RB_SEQ_SENSITIVE - The caller is sensitive to sequence number
				   changes so return on_ctrl_C if an
				   unsolicited expunge happens while we're
				   viewing a message.
		RB_RET_HELP    - Instead of the regular internal handling
				 way of handling help_text, this just causes
				 radio_buttons to return 3 when help is
				 asked for, so that the caller handles it
				 instead.
	
	 Note: If there are enough keys in the esc_list to need a second
	       screen, and there is no help, then the 13th key will be
	       put in the help position.

Result -- Returns the letter pressed. Will be one of the characters in the
          esc_list argument, or dflt, or on_ctrl_C, or SEQ_EXCEPTION.

This will pause for any new status message to be seen and then prompt the user.
The prompt will be truncated to fit on the screen. Redraw and resize are
handled along with ^Z suspension. Typing ^G will toggle the help text on and
off. Character types that are not buttons will result in a beep (unless one_try
is set).
  ----*/
int
radio_buttons(char *utf8prompt, int line, ESCKEY_S *esc_list, int dflt,
	      int on_ctrl_C, HelpType help_text, int flags)
{
    UCS              ucs;
    register int     ch, real_line;
    char            *q, *ds = NULL;
    unsigned         maxcol;
    int              max_label, i, start, fkey_table[12];
    int		     km_popped = 0;
    struct key	     rb_keys[12];
    struct key_menu  rb_keymenu;
    bitmap_t	     bitmap;
    struct variable *vars = ps_global->vars;
    COLOR_PAIR      *lastc = NULL, *promptc = NULL;

#ifdef	_WINDOWS
    int		     cursor_shown;

    if (mswin_usedialog()){
	MDlgButton button_list[25];
	LPTSTR     free_names[25];
	LPTSTR     free_labels[25];
	int        b, i, ret;
	char     **help;

	memset(&free_names, 0, sizeof(LPTSTR) * 25);
	memset(&free_labels, 0, sizeof(LPTSTR) * 25);
	memset(&button_list, 0, sizeof (MDlgButton) * 25);
	b = 0;

	if(flags & RB_RET_HELP){
	    if(help_text != NO_HELP)
	      alpine_panic("RET_HELP and help in radio_buttons!");

	    button_list[b].ch = '?';
	    button_list[b].rval = 3;
	    button_list[b].name = TEXT("?");
	    free_labels[b] = utf8_to_lptstr(N_("Help"));
	    button_list[b].label = free_labels[b];
	    ++b;
	}

	for(i = 0; esc_list && esc_list[i].ch != -1 && i < 23; ++i){
	  if(esc_list[i].ch != -2){
	    button_list[b].ch = esc_list[i].ch;
	    button_list[b].rval = esc_list[i].rval;
	    free_names[b] = utf8_to_lptstr(esc_list[i].name);
	    button_list[b].name = free_names[b];
	    free_labels[b] = utf8_to_lptstr(esc_list[i].label);
	    button_list[b].label = free_labels[b];
	    ++b;
	  }
	}

	button_list[b].ch = -1;
	
	/* assumption here is that HelpType is char **  */
	help = help_text;

	ret = mswin_select(utf8prompt, button_list, dflt, on_ctrl_C, help, flags);
	for(i = 0; i < 25; i++){
	    if(free_names[i])
	      fs_give((void **) &free_names[i]);
	    if(free_labels[i])
	      fs_give((void **) &free_labels[i]);
	}

	return (ret);
    }

#endif /* _WINDOWS */

    suspend_busy_cue();
    flush_ordered_messages();		/* show user previous status msgs */
    mark_status_dirty();		/* clear message next display call */
    real_line = line > 0 ? line : ps_global->ttyo->screen_rows + line;
    MoveCursor(real_line, RAD_BUT_COL);
    CleartoEOLN();

    /*---- Find widest label ----*/
    max_label = 0;
    for(i = 0; esc_list && esc_list[i].ch != -1 && i < 11; i++){
      if(esc_list[i].ch == -2) /* -2 means to skip this key and leave blank */
	continue;
      if(esc_list[i].name)
        max_label = MAX(max_label, utf8_width(esc_list[i].name));
    }

    if(ps_global->ttyo->screen_cols - max_label - 1 > 0)
      maxcol = ps_global->ttyo->screen_cols - max_label - 1;
    else
      maxcol = 0;

    /*
     * We need to be able to truncate q, so copy it in case it is
     * a readonly string.
     */
    q = cpystr(utf8prompt);

    /*---- Init structs for keymenu ----*/
    for(i = 0; i < 12; i++)
      memset((void *)&rb_keys[i], 0, sizeof(struct key));

    memset((void *)&rb_keymenu, 0, sizeof(struct key_menu));
    rb_keymenu.how_many = 1;
    rb_keymenu.keys     = rb_keys;

    /*---- Setup key menu ----*/
    start = 0;
    clrbitmap(bitmap);
    memset(fkey_table, NO_OP_COMMAND, 12 * sizeof(int));
    if(flags & RB_RET_HELP && help_text != NO_HELP)
      alpine_panic("RET_HELP and help in radio_buttons!");

    /* if shown, always at position 0 */
    if(help_text != NO_HELP || flags & RB_RET_HELP){
	rb_keymenu.keys[0].name  = "?";
	rb_keymenu.keys[0].label = N_("Help");
	setbitn(0, bitmap);
	fkey_table[0] = ctrl('G');
	start++;
    }

    if(on_ctrl_C){
	rb_keymenu.keys[1].name  = "^C";
	rb_keymenu.keys[1].label = N_("Cancel");
	setbitn(1, bitmap);
	fkey_table[1] = ctrl('C');
	start++;
    }

    start = start ? 2 : 0;
    /*---- Show the usual possible keys ----*/
    for(i=start; esc_list && esc_list[i-start].ch != -1; i++){
	/*
	 * If we have an esc_list item we'd like to put in the non-existent
	 * 13th slot, and there is no help, we put it in the help slot
	 * instead.  We're hacking now...!
	 *
	 * We may also have invisible esc_list items that don't show up
	 * on the screen.  We use this when we have two different keys
	 * which are synonyms, like ^P and KEY_UP.  If all the slots are
	 * already full we can still fit invisible keys off the screen to
	 * the right.  A key is invisible if it's label is "".
	 */
	if(i >= 12){
	    if(esc_list[i-start].label
	       && esc_list[i-start].label[0] != '\0'){  /* visible */
		if(i == 12){  /* special case where we put it in help slot */
		    if(help_text != NO_HELP)
		  alpine_panic("Programming botch in radio_buttons(): too many keys");

		    if(esc_list[i-start].ch != -2)
		      setbitn(0, bitmap); /* the help slot */

		    fkey_table[0] = esc_list[i-start].ch;
		    rb_keymenu.keys[0].name  = esc_list[i-start].name;
		    if(esc_list[i-start].ch != -2
		       && esc_list[i-start].rval == dflt
		       && esc_list[i-start].label){
		        size_t l;

			l = strlen(esc_list[i-start].label) + 2;
			ds = (char *)fs_get((l+1) * sizeof(char));
			snprintf(ds, l+1, "[%s]", esc_list[i-start].label);
			ds[l] = '\0';
			rb_keymenu.keys[0].label = ds;
		    }
		    else
		      rb_keymenu.keys[0].label = esc_list[i-start].label;
		}
		else
		  alpine_panic("Botch in radio_buttons(): too many keys");
	    }
	}
	else{
	    if(esc_list[i-start].ch != -2)
	      setbitn(i, bitmap);

	    fkey_table[i] = esc_list[i-start].ch;
	    rb_keymenu.keys[i].name  = esc_list[i-start].name;
	    if(esc_list[i-start].ch != -2
	       && esc_list[i-start].rval == dflt
	       && esc_list[i-start].label){
	        size_t l;

		l = strlen(esc_list[i-start].label) + 2;
		ds = (char *)fs_get((l+1) * sizeof(char));
		snprintf(ds, l+1, "[%s]", esc_list[i-start].label);
		ds[l] = '\0';
		rb_keymenu.keys[i].label = ds;
	    }
	    else
	      rb_keymenu.keys[i].label = esc_list[i-start].label;
	}
    }

    for(; i < 12; i++)
      rb_keymenu.keys[i].name = NULL;

    ps_global->mangled_footer = 1;

#ifdef	_WINDOWS
    cursor_shown = mswin_showcaret(1);
#endif

    if(pico_usingcolor() && VAR_PROMPT_FORE_COLOR &&
       VAR_PROMPT_BACK_COLOR &&
       pico_is_good_color(VAR_PROMPT_FORE_COLOR) &&
       pico_is_good_color(VAR_PROMPT_BACK_COLOR)){
	lastc = pico_get_cur_color();
	if(lastc){
	    promptc = new_color_pair(VAR_PROMPT_FORE_COLOR,
				     VAR_PROMPT_BACK_COLOR);
	    (void)pico_set_colorp(promptc, PSC_NONE);
	}
    }
    else
      StartInverse();

    draw_radio_prompt(real_line, RAD_BUT_COL, maxcol, q);

    while(1){
        fflush(stdout);

	/*---- Paint the keymenu ----*/
	if(lastc)
	  (void)pico_set_colorp(lastc, PSC_NONE);
	else
	  EndInverse();

	draw_keymenu(&rb_keymenu, bitmap, ps_global->ttyo->screen_cols,
		     1 - FOOTER_ROWS(ps_global), 0, FirstMenu);
	if(promptc)
	  (void)pico_set_colorp(promptc, PSC_NONE);
	else
	  StartInverse();

	MoveCursor(real_line, MIN(RAD_BUT_COL+utf8_width(q), maxcol+1));

	if(flags & RB_FLUSH_IN)
	  flush_input();

  newcmd:
	/* Timeout 5 min to keep imap mail stream alive */
        ucs = read_char(600);
        dprint((2,
                   "Want_to read: %s (0x%x)\n", pretty_command(ucs), ucs));
	if((ucs < 0x80) && isupper((unsigned char) ucs))
	  ucs = tolower((unsigned char) ucs);

	if(F_ON(F_USE_FK,ps_global)
	   && (((ucs < 0x80) && isalpha((unsigned char) ucs) && !strchr("YyNn",(int) ucs))
	       || ((ucs >= PF1 && ucs <= PF12)
		   && (ucs = fkey_table[ucs - PF1]) == NO_OP_COMMAND))){
	    /*
	     * The funky test above does two things.  It maps
	     * esc_list character commands to function keys, *and* prevents
	     * character commands from input while in function key mode.
	     * NOTE: this breaks if we ever need more than the first
	     * twelve function keys...
	     */
	    if(flags & RB_ONE_TRY){
		ch = ucs = on_ctrl_C;
	        goto out_of_loop;
	    }

	    Writechar(BELL, 0);
	    continue;
	}

        switch(ucs){

          default:
	    for(i = 0; esc_list && esc_list[i].ch != -1; i++)
	      if(ucs == esc_list[i].ch){
		  int len, n;

		  MoveCursor(real_line,len=MIN(RAD_BUT_COL+utf8_width(q),maxcol+1));
		  for(n = 0, len = ps_global->ttyo->screen_cols - len;
		      esc_list[i].label && esc_list[i].label[n] && len > 0;
		      n++, len--)
		    Writechar(esc_list[i].label[n], 0);

		  ch = esc_list[i].rval;
		  goto out_of_loop;
	      }

	    if(flags & RB_ONE_TRY){
		ch = on_ctrl_C;
	        goto out_of_loop;
	    }

	    Writechar(BELL, 0);
	    break;

          case ctrl('M'):
          case ctrl('J'):
            ch = dflt;
	    for(i = 0; esc_list && esc_list[i].ch != -1; i++)
	      if(ch == esc_list[i].rval){
		  int len, n;

		  MoveCursor(real_line,len=MIN(RAD_BUT_COL+utf8_width(q),maxcol+1));
		  for(n = 0, len = ps_global->ttyo->screen_cols - len;
		      esc_list[i].label && esc_list[i].label[n] && len > 0;
		      n++, len--)
		    Writechar(esc_list[i].label[n], 0);
		  break;
	      }

            goto out_of_loop;

          case ctrl('C'):
	    if(on_ctrl_C || (flags & RB_ONE_TRY)){
		ch = on_ctrl_C;
		goto out_of_loop;
	    }

	    Writechar(BELL, 0);
	    break;


          case '?':
          case ctrl('G'):
	    if(FOOTER_ROWS(ps_global) == 1 && km_popped == 0){
		km_popped++;
		FOOTER_ROWS(ps_global) = 3;
		line = -3;
		real_line = ps_global->ttyo->screen_rows + line;
		if(lastc)
		  (void)pico_set_colorp(lastc, PSC_NONE);
		else
		  EndInverse();

		clearfooter(ps_global);
		if(promptc)
		  (void)pico_set_colorp(promptc, PSC_NONE);
		else
		  StartInverse();

		draw_radio_prompt(real_line, RAD_BUT_COL, maxcol, q);
		break;
	    }

	    if(flags & RB_RET_HELP){
		ch = 3;
		goto out_of_loop;
	    }
	    else if(help_text != NO_HELP && FOOTER_ROWS(ps_global) > 1){
		mark_keymenu_dirty();
		if(lastc)
		  (void)pico_set_colorp(lastc, PSC_NONE);
		else
		  EndInverse();

		MoveCursor(real_line + 1, RAD_BUT_COL);
		CleartoEOLN();
		MoveCursor(real_line + 2, RAD_BUT_COL);
		CleartoEOLN();
		radio_help(real_line, RAD_BUT_COL, help_text);
		sleep(5);
		MoveCursor(real_line, MIN(RAD_BUT_COL+utf8_width(q), maxcol+1));
		if(promptc)
		  (void)pico_set_colorp(promptc, PSC_NONE);
		else
		  StartInverse();
	    }
	    else
	      Writechar(BELL, 0);

            break;
            

          case NO_OP_COMMAND:
	    goto newcmd;		/* misunderstood escape? */

          case NO_OP_IDLE:		/* UNODIR, keep the stream alive */
	    if(flags & RB_NO_NEWMAIL)
	      goto newcmd;

	    i = new_mail(0, VeryBadTime, NM_DEFER_SORT);
	    if(sp_expunge_count(ps_global->mail_stream)
	       && flags & RB_SEQ_SENSITIVE){
		if(on_ctrl_C)
		  ch = on_ctrl_C;
		else
		  ch = SEQ_EXCEPTION;

		goto out_of_loop;
	    }

	    if(i < 0)
	      break;		/* no changes, get on with life */
            /* Else fall into redraw to adjust displayed numbers and such */


          case KEY_RESIZE:
          case ctrl('L'):
            real_line = line > 0 ? line : ps_global->ttyo->screen_rows + line;
	    if(lastc)
	      (void)pico_set_colorp(lastc, PSC_NONE);
	    else
	      EndInverse();

            ClearScreen();
            redraw_titlebar();
            if(ps_global->redrawer != NULL)
              (*ps_global->redrawer)();
	    if(FOOTER_ROWS(ps_global) == 3 || km_popped)
              redraw_keymenu();

	    if(ps_global->ttyo->screen_cols - max_label - 1 > 0)
	      maxcol = ps_global->ttyo->screen_cols - max_label - 1;
	    else
	      maxcol = 0;

	    if(promptc)
	      (void)pico_set_colorp(promptc, PSC_NONE);
	    else
	      StartInverse();

	    draw_radio_prompt(real_line, RAD_BUT_COL, maxcol, q);
            break;

        } /* switch */
    }

  out_of_loop:

#ifdef	_WINDOWS
    if(!cursor_shown)
      mswin_showcaret(0);
#endif

    fs_give((void **) &q);
    if(ds)
      fs_give((void **) &ds);

    if(lastc){
	(void) pico_set_colorp(lastc, PSC_NONE);
	free_color_pair(&lastc);
	if(promptc)
	  free_color_pair(&promptc);
    }
    else
      EndInverse();

    fflush(stdout);
    resume_busy_cue(0);
    if(km_popped){
	FOOTER_ROWS(ps_global) = 1;
	clearfooter(ps_global);
	ps_global->mangled_body = 1;
    }

    return(ch);
}
Ejemplo n.º 18
0
static int board_shift_wd(PLAYER *player, int dirw1, int dird1)
{
	int	 wleft, wright, wcomes, wgoes;
	int  dback, dfront, dcomes, dgoes;
	int  hlow,  hhigh, dirw, dird;
	int  i, j, h;
	int  turn;
  char *board;
  short code;

	turn = player->type ? 0 : player->board_turn;

	switch(turn)
	{ case 0:
			dirw = dirw1; dird = dird1;
			break;

	 case 1:
			dirw = dird1; dird = -dirw1; 
			break;

	 case 2:
			dird = -dird1; dirw = -dirw1;
			break;

	 default:
			dirw = -dird1; dird = dirw1; 
			break;
	}

	wleft = player->tile_pos[0];
  wright = wleft + player->tile_size[0];   
	dback = player->tile_pos[1];
  dfront = dback + player->tile_size[1];   
	hlow = player->tile_pos[2];
	hhigh = hlow + player->tile_size[2];

	/* Check boundaries */
  if (dirw > 0)
	{  wgoes = wleft;  wcomes = wright;
     if (wcomes >= BoardWidth) goto Stopper;
	}
	else
  if (dirw < 0)
	{  wgoes = wright-1; wcomes = wleft-1;
	   if (wcomes < 0) goto Stopper;	
  }	
	else
	   wcomes = wgoes = -1;
	
    if (dird > 0)
	{  dgoes = dback;  dcomes = dfront;
       if (dcomes >= BoardDepth) goto Stopper;
	}
	else
    if (dird < 0)
	{  dgoes = dfront-1; dcomes = dback-1;
	   if (dcomes < 0) goto Stopper;	
  }	
	else
	   dcomes = dgoes = -1;

	
	board = player->board;

  /* Justify shift in width direction */
  if (wcomes != wgoes)
  {	j = dfront + dird;
   	for (i = dback+dird; i<j; i++)
	  for (h=hlow; h<hhigh; h++)
		if (BoardCubie(board, wcomes, i, h) != 0) return 0;
	}

  /* Justify shift in depth direction */
  if (dcomes != dgoes)
  {	j = wright + dirw;
   	for (i = wleft+dirw; i<j; i++)
	  for (h=hlow; h<hhigh; h++)
  	if (BoardCubie(board, i, dcomes, h) != 0) return 0;
	}

	/* Now shift! */
  code = player->tile_code;

  if (wcomes != wgoes)
  {	for (i=dback; i<dfront; i++)
		for (h=hlow; h<hhigh; h++)
	  {  BoardCubie(board, wcomes, i+dird, h) = code;
	     BoardCubie(board, wgoes, i, h) = 0;
	  }
  }

  if (dcomes != dgoes)
  {	for (i=wleft; i<wright; i++)
		for (h=hlow; h<hhigh; h++)
	  {   BoardCubie(board, i+dirw, dcomes, h) = code;
	      BoardCubie(board, i, dgoes, h) = 0;
	  }
	}

  player->tile_pos[0] += dirw; 
  player->tile_pos[1] += dird; 
  player->status |= PLST_CHANGED;
  player->status &= ~PLST_DROPPED;
  return 1;

Stopper:
	flush_input();
	return 0;

}
Ejemplo n.º 19
0
void kbd_handler(regs_pt *regs)
{
    static int max_len;
    static int cur_len;
    if(input.s == 1)
    {
        max_len = 0;
        cur_len = 0;
        input.s = 2;
    } 

    if(input.s != 2)
        return;
    
    int ch = kbdgetc();
    if(!ch)
        return;
    switch(ch)
    {
        case KEY_LF:
            if(cur_len > 0) {
                cursor_left();
                cur_len--;
            }
            return;
        case KEY_RT:
            if(cur_len < max_len) {
                cursor_right();
                cur_len++;
            }
            return;
        case '\b':
            if(cur_len <= 0)
                return;
            cur_len--;
            max_len--;
            for(int i = (input.r+cur_len)%256; i != input.w; i=(i+1)%256)
            {
                input.buf[i] = input.buf[(i+1)%256];
            }
            input.w=(input.w-1)%256;
            for(int i = cur_len; i < max_len; i++)
                    cursor_right();
            flush_input(max_len+1, max_len, &input.buf[input.r]);
            for(int i = cur_len; i < max_len; i++)
                    cursor_left();
            return;
        case '\n':
            input.w=(input.w+1)%256;
            for(int i = cur_len; i < max_len; i++)
                    cursor_right();
            putchar_normal('\n');
            wakeup(&input.r);
            return;
    }

    // queue is full.
    if((input.w + 1)%256 == input.r)
    {
        wakeup(&input.r);
        return;
    }
        
    int i;
    for(i = input.w; i != (input.r+cur_len)%256; i=(i-1)%256)
        input.buf[i] = input.buf[(i-1)%256];
    input.buf[i] = ch;

    max_len++;
    cur_len++;
    for(i = cur_len-1; i < max_len-1; i++)
        cursor_right();
    flush_input(max_len-1, max_len, &input.buf[input.r]);
    for(i = cur_len; i < max_len; i++)
        cursor_left();
    input.w=(input.w+1)%256;
    input.w%=256;

}
Ejemplo n.º 20
0
/*
**	keys_tested(first-time, show-help, hex-output)
**
**	Display a list of the keys not tested.
*/
static void
keys_tested(
	       int first_time,
	       int show_help,
	       int hex_output)
{
    int i, l;
    char outbuf[256];

    alloc_strings();
    put_clear();
    tty_set();
    flush_input();
    if (got_labels) {
	putln("Function key labels:");
	for (i = 0; i < key_count; ++i) {
	    if (fk_label[i]) {
		sprintf(outbuf, "%s %s",
			fk_name[i] ? fk_name[i] : "??", fk_label[i]);
		put_columns(outbuf, (int) strlen(outbuf), 16);
	    }
	}
	put_newlines(2);
    }
    if (funk) {
	putln("The following keys are not defined:");
	for (i = 0; i < funk; ++i) {
	    put_columns(fk_unknown[i], fk_length[i], 16);
	}
	put_mode(exit_attribute_mode);
	put_newlines(2);
    }
    if (first_time) {
	putln("The following keys are defined:");
    } else {
	putln("The following keys have not been tested:");
    }
    if (scan_mode) {
	for (i = 0; scan_down[i]; i++) {
	    if (!scan_tested[i]) {
		if (hex_output) {
		    strcpy(outbuf, hex_expand_to(scan_down[i], 3));
		} else {
		    strcpy(outbuf, expand(scan_down[i]));
		}
		l = expand_chars;
		if (hex_output) {
		    strcat(outbuf, hex_expand_to(scan_up[i], 3));
		} else {
		    strcat(outbuf, expand(scan_up[i]));
		}
		expand_chars += l;
		l = (int) strlen(scan_name[i]);
		if (((char_count + 16) & ~15) +
		    ((expand_chars + 7) & ~7) + l >= columns) {
		    put_crlf();
		} else if (char_count + 24 > columns) {
		    put_crlf();
		} else if (char_count) {
		    putchp(' ');
		}
		put_columns(outbuf, expand_chars, 16);
		put_columns(scan_name[i], l, 8);
	    }
	}
    } else {
	for (i = 0; i < key_count; i++) {
	    if (!fk_tested[i] && fk_name[i] != 0) {
		if (hex_output) {
		    strcpy(outbuf, hex_expand_to(fkval[i], 3));
		} else {
		    strcpy(outbuf, expand(fkval[i]));
		}
		l = (int) strlen(fk_name[i]);
		if (((char_count + 16) & ~15) +
		    ((expand_chars + 7) & ~7) + l >= columns) {
		    put_crlf();
		} else if (char_count + 24 > columns) {
		    put_crlf();
		} else if (char_count) {
		    putchp(' ');
		}
		put_columns(outbuf, expand_chars, 16);
		put_columns(fk_name[i], l, 8);
	    }
	}
    }
    put_newlines(2);
    if (show_help) {
	ptextln("Hit any function key.  Type 'end' to quit.  Type ? to update the display.");
	put_crlf();
    }
}
Ejemplo n.º 21
0
void
do_login(void)
{
register int i;
register int users;
register char *name;
register struct tm *ltm;
register struct user *tmpuser = 0;
register int wrong = 0;
register char *bbsname;
char pas[9];
char temp[128];
char myname[MAXALIAS + 1];

  printf("\nDOC (Dave's Own version of Citadel) Version 1.71\n\nWelcome to the ISCA BBS.\n\n%s", (bbsname = getenv("BBSNAME")) ? "" : "\nLogin as 'Guest' to just look around, or 'New' to create a new account.\n\n");

  for (;;)
  {
    guest = 0;

    if (!bbsname)
      name = get_name("Name: ", 1);
    else
      strcpy(name = myname, bbsname);

    if (strcmp(name, "New"))
    {
      if ((tmpuser = getuser(name)))
        freeuser(tmpuser);
      if (tmpuser && (!bbsname || tty) && strcmp(name, "Guest"))
        get_string("Password: "******"Incorrect login.\n");
	else
	  printf("There is no user %s on this BBS.\n", name);
        if (++wrong > 3 || bbsname)
        {
	  if (!bbsname)
            printf("\n\nToo many attempts.  Goodbye.\n");
          my_exit(3);
        }
        flush_input(wrong);
        continue;
      }
      else
      {
        xinit();
	if (ouruser->keytime)
	{     
	  printf("\n\n\nYou have not yet registered your validation key...\n\n");
	  dokey(ouruser);
	  if (ouruser->keytime && ouruser->f_trouble)
	  {
	    printf("\n\nYou will need to enter your validation key before you may gain access to the\nBBS.  If you have not yet received your key and think you should, you may send\nE-mail to [email protected].  Please include your BBS username in this\nE-mail so the sysop who receives it knows who you are.  Remember that it can\ntake several days from the time your account was originally created for the\nsysops to validate the information you have provided, if it has been less than\nfour days since you created your account please do not send E-mail yet, as it\nlikely they haven't finished with your account yet.  Impatience won't make them\nwork any faster, and quite likely will make them decide to make you a special\ncase and work slower!  Remember, this BBS is a privilege, not a right.\n\n\n");
	    my_exit(15);
	  }
	}

	printf("\nIowa Student Computer Association BBS.\n");

	if (ouruser->f_deleted)
        {
	  if (ouruser->f_namechanged)
	    printf("\a\nThis account has been marked for deletion because of a request to change the\nusername from '%s' to '%s'.\n\nYou may login as '%s' using the same password.\n\n", ouruser->name, ouruser->reminder, ouruser->reminder);
          else
            printf("\a\nThis account has been marked for deletion, either through your choice or\nbecause you violated ISCA BBS rules by doing something such as providing\nobviously bogus profile info.  You will be logged off.\n\n");
          my_exit(10);
        }
	else if (ouruser->f_inactive)
        {
          printf("You seem to have been denied access to the message system.\n");
          printf("Please contact ISCA (e-mail address [email protected]) for more.\n");
          my_exit(10);
        }


	i = ouruser->time;
        ltm = localtime(&ouruser->time);
        users = add_loggedin(ouruser);

        if (!guest && ouruser->time)
        {
	  printf("Last on: %d/%d/%d %d:%02d ", ltm->tm_mon + 1,
                 ltm->tm_mday, 1900 + ltm->tm_year, ltm->tm_hour, ltm->tm_min);
          ltm = localtime(&ouruser->timeoff);
	  if (ouruser->timeoff >= i)
            printf("until %d:%02d from %s\n", ltm->tm_hour, ltm->tm_min, ouruser->remote);
	  else
	    printf("from %s\n", ouruser->remote);
        }

        strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
        strncpy(ouruser->remote, ARGV[1] ? ARGV[1] : "local", sizeof ouruser->remote - 1);

        if (ouruser->f_noclient)
	{
	  printf("\n\nYou have been disallowed use of the BBS client, you must login using telnet.\n\n");
	  my_exit(10);
	}

	sprintf(temp, "%s %s%s%s/%d", client ? "CLIENT" : "LOGIN", ARGV[1] && ARGV[2] ? ARGV[2] : "", ARGV[1] && ARGV[2] ? "@" : "", ouruser->remote, mybtmp->remport);
	logevent(temp);

	++ouruser->timescalled;

	if (!guest)
	  printf("This is call %d.  There are %d users.\n", ouruser->timescalled, users);
        if (ouruser->f_aide)
           validate_users(0);

	/*
	 * Turn off expresses and tell the user this was done if user is
	 * configured for this 
	 */
	if (!guest && mybtmp->xstat)
	  printf("\nNOTE:  You have eXpress messages turned OFF as a default!\n");
        if (mybtmp->elf)
          printf("\nYou are marked as available to help others.\n");

	checkmail(FALSE);

	termset();

        if (*ouruser->reminder)
        {
          printf("\n\aREMINDER:\n%s\n\n", ouruser->reminder);
          printf("Please hit 'Y' to acknowledge having seen this reminder -> ");
          get_single_quiet("yY");
        }

	if (ouruser->f_badinfo || ouruser->f_duplicate)
	{
	  help("badinfo", NO);
	  mysleep(300);
	}

	if (guest)
	{
	  help("guestwelcome", NO);
	  hit_return_now();
	}
	return;
      }
    }
    else
      if (!(i = new_user()))
      {
	printf("\n\nSorry, there was some problem setting up your BBS account.\n\nPlease try again later.\n\n");
        my_exit(10);
      }
      else if (i > 0)
        return;
  }
}
Ejemplo n.º 22
0
int main(int argc, char **argv)
{
  cairo_surface_t *surface;
  cairo_t *context;
  int x, y, i,
      width, height, depth,
      screen, pressed_key,
      png;
  double r, b, v;
  QTnode *tree;
  bool rendering;
  struct XWin **xwin;

  /* Get the arguments */
  if(argc != 3) {
    printf("Usage: nbody rendering resultsdir\n");
    exit(1);
  }
  if(*argv[1] == '0') {
    rendering = false;
  } else {
    rendering = true;
  }
  char buf[strlen(argv[2]) + 10];

  /* Set window size */
  width = 1024;
  height = 1024;
  depth = 32;

  tree = init_tree(10, NULL);
  for (i = 0; i < 100000; i++) {
    tree->insert(phys_gen_particle());
    if (i % 10000 == 0)
      printf("%d\n", i);
  }

  /* Create the drawing surface */
  if(rendering) {
    /* Create the X11 window */
    xwin = (struct XWin **)calloc(sizeof(struct XWin *), 1);
    xwindow_init(width, height, depth, xwin);
    surface = cairo_xlib_surface_create((*xwin)->dsp, (*xwin)->win, DefaultVisual((*xwin)->dsp, screen), width, height);
    cairo_xlib_surface_set_size(surface, width, height);
  } else {
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); 
  }
  context = cairo_create(surface);
  cairo_scale(context, width, height);

  png = 0;
  while(1) {
    if(rendering) {
      if((*xwin)->should_close) {
        break;
      }
      /* Wait on the input (also sync up to disable flickering) */
      if(input_ready(xwin)) {
        pressed_key = get_key(xwin);
      }
    }

    /* Clear the surface with black */
    cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
    cairo_paint(context);

    std::queue <QTnode *> nodes;
    QTnode *t;

    nodes.push(tree);

    while (!nodes.empty()) {
      t = nodes.front();
      nodes.pop();

      if (!t->children.empty()) {
        for (i = 0; i < t->children.size(); i++) {
          nodes.push(t->children[i]);
        }
      } else {
        for (std::list <Particle>::iterator p = t->particles.begin(); p != t->particles.end(); p++) {

          v = f2_norm((*p).vel);
          if(v >= 0.4) {
            r = 1.0; b = 0.0;
          } else if(v < 0.5) {
            b = 1.0; r = 0.0;
          }
          cairo_set_source_rgba(context, (double)r, 0.0, (double)b, 1.0);
          cairo_rectangle(context, (*p).pos.x,
              (*p).pos.y, 2e-3, 2e-3);
          cairo_fill(context);
          cairo_set_source_rgba(context, (double)r, 0.0, (double)b, 0.2);
          cairo_rectangle(context, (*p).pos.x - 1e-3,
              (*p).pos.y - 1e-3, 4e-3, 4e-3);
          cairo_fill(context);
        }
      }
    }

    if(rendering) {
      /* Flush the X window */
      flush_input(xwin);
      update_screen(xwin);
    } else {
      mkdir(argv[2], S_IRWXU | S_IRWXG);
      sprintf(buf, "%s/%05d.png", argv[2], png++);
      printf("Making %s\n", buf);
      cairo_surface_write_to_png (surface, buf);
    }

    /* Get the new particles */
    timing(
        tree->calc_global_accel();
        tree->move_shit();
        );
  }
Ejemplo n.º 23
0
void stone_tablet()
{
  char line[DEFLEN];
  int seq[15];
  int inp_seq[15];
  int i;
  int states = 7;
  int exp;

  pwait("YOU FIND A MYSTERIOUS STONE TABLET");

  stile(player->y, player->x, TL_VOID);
  stile(player->y - 1, player->x, TL_VOID);
  
  states = game->tablet_diff;
  
  draw_tablet(-1);

  pwait("REPEAT THE SEQUENCE\n"
	"USING THE DIRECTIONAL KEYS");

  draw_tablet(-1);

  for (i = 0; i < states; i++)
  {
    opause();
    seq[i] = rand() % 4;
    draw_tablet(seq[i]);
    opause();
    draw_tablet(-1);
  }

  for (i = 0; i < states; i++)
  {
    int gk;

    gk = getch();
    
    if (gk == KEY_UP)
      inp_seq[i] = 0;
    else if (gk == KEY_RIGHT)
      inp_seq[i] = 1;
    else if (gk == KEY_DOWN)
      inp_seq[i] = 2;
    else if (gk == KEY_LEFT)
      inp_seq[i] = 3;
    else
    {
      snprintf(lowmsg, DEFLEN, "INVALID INPUT");
      draw_lowmsg();
      continue;
    }

    if (inp_seq[i] != seq[i])
    {
      lpause();
      board_attr(A_REVERSE | A_BOLD, PAIR_RED);
      wrefresh(board);
      pwait("SHIT");
      draw_board();
      return;
    }
    else
    {
      draw_tablet(seq[i]);
      opause();
      draw_tablet(-1);
      flush_input();
    }
  }

  draw_board();

  switch (states)
  {
  case 7:  exp = 1000; break;
  case 8:  exp = 2000; break;
  case 9:  exp = 3000; break;
  default: exp = 1000; break;
  }
    
  snprintf(line, DEFLEN,
	   "YOU HAVE DECODED THE MYSTIC RUNES\n"
	   "\nYOU GET %d EXP",
	   exp);

  pwait(line);
  draw_board();
  
  give_exp(exp);
  draw_stats();

  // Make it harder next time
  game->tablet_diff += 1;
  
  draw_stats();
  
  return;
}
Ejemplo n.º 24
0
char   *
get_name(register char *prompt, register int quit_priv)
{
register char *p;
register int c;
register int upflag;
register int fflag;
register int invalid = 0;

  for (;;)
  {
    printf("%s", prompt);
    if (client)
    {
      putchar(IAC);
      putchar(G_NAME);
      putchar(quit_priv);
      putc((byte >> 16) & 255, stdout);
      putc((byte >> 8) & 255, stdout);
      putc(byte & 255, stdout);
      block = 1;
    }

    upflag = fflag = 1;
    p = pbuf;
    for (;;)
    {
      c = inkey();
      if (c == NL)
	break;
      if (c == CTRL_D && quit_priv == 1)
      {
	putchar('\n');
	my_exit(1);
      }
      if (c == '_')
        c = ' ';
      if (c == SP && (fflag || upflag))
	continue;
      if (c == BS || c == CTRL_X || c == CTRL_W || c == CTRL_R || c == SP || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9' && quit_priv == 3))
        invalid = 0;
      else
      {
	if (invalid++)
	  flush_input(invalid < 6 ? (invalid / 2) : 3);
	continue;
      }
      if (c == CTRL_R)
      {
	*p = 0;
	printf("\n%s", pbuf);
	continue;
      }
      do
        if ((c == BS || c == CTRL_X || c == CTRL_W) && p > pbuf)
        {
          putchar(BS);
          putchar(SP);
          putchar(BS);
          --p;
          upflag = (p == pbuf || *(p - 1) == SP);
	  if (upflag && c == CTRL_W)
	    break;
          if (p == pbuf)
            fflag = 1;
        }
        else
	  if (p < &pbuf[!quit_priv || quit_priv == 3 ? MAXNAME : MAXALIAS] && c != BS && c != CTRL_X && c != CTRL_W)
	  {
	    fflag = 0;
	    if (upflag && c >= 'a')
	      c -= 32;
	    if (c >= '0')
	      upflag = 0;
	    else if (c == SP)
	      upflag = 1;
	    *p++ = c;
            if (!client)
	      putchar(c);
	  }
      while ((c == CTRL_X || c == CTRL_W) && p > pbuf);
    }
    *p = 0;
    if (p > pbuf || quit_priv >= 2)
      break;
    if (quit_priv)
      printf("\nPress CTRL-D to quit.\n");
    else
      printf("\nThis really isn't optional!\n");
  }
  if (!client)
    putchar(NL);

  if (p > pbuf && p[-1] == ' ')
    p[-1] = 0;

  /* After every request for a name, give a CR */
  putchar('\r');

  return (pbuf);
}
Ejemplo n.º 25
0
int shoot_missile(mob_t * attacker, int dir)
{
  char line[DEFLEN];
  mob_t * target;
  int m_y; int m_x;
  int sc_y; int sc_x;
  int count;
  int m_type;
  int adjust_y;
  int passes;
  int pass;
  int xbow;
  chtype color;
  chtype missile;

//   attacker = &game->mob[mi];

  xbow = false;
  passes = 1;

  adjust_y = water_offset(attacker);
  m_y = attacker->y;
  sc_y = m_y - view_y - 1;

  m_x = attacker->x +
    (attacker->flip ? -attacker->pack_w + 2 : attacker->pack_w - 2) +
    dir * 2;

  if (attacker->type == MOB_EYE)
  {
    m_type = MIS_DISINT;
    sc_y -= 1;
    m_x = attacker->x;
  }
  else if (attacker->type == MOB_LICH)
  {
    m_type = MIS_FIREBALL;
    sc_y -= 1;
  }
  else if (attacker == player)
  {
    if (game->weapon == WPN_BOW)
      m_type = MIS_ARROW;
    else if (game->weapon == WPN_3XBOW)
    {
      xbow = true;
      m_type = MIS_ARROW;

      if (water_offset(attacker))
	passes = 2;
      else
	passes = 3;
    }
    else if (game->weapon == WPN_BLASTER)
    {
      m_type = MIS_BLASTER;
      adjust_y -= 1;
    }
  }
  else
  {
    m_type = MIS_ARROW;
  }

  draw_board();
  
  for (pass = 0; pass < passes; pass++)
  {
    count = 0;
    
    if (xbow)
    {
      m_x = attacker->x +
	(attacker->flip ? -attacker->pack_w + 2 : attacker->pack_w - 2) +
	dir * 2;
      
      if (pass == 0)
	adjust_y = water_offset(attacker) - 1;
      else if (pass == 1)
	adjust_y = water_offset(attacker);
      else if (pass == 2)
	adjust_y = water_offset(attacker) + 1;
    }

    while (1)
    {
      m_x += dir;
      sc_x = m_x - view_x;
      count++;

      if (sc_x < 0 || sc_x >= BOARD_W)
	goto end_pass;//break;//return 0;
      
      target = find_enemy(attacker, m_y, m_x + dir);
      
      if (target == NULL)
      {
	if (game->blinded)
	  continue;
	
	if (m_type != MIS_BLASTER && count % 2 == 1)
	  continue;
	
	// Skip the length of the barrel
	if (m_type == MIS_BLASTER && count < 4)
	  continue;
	
	missile = '?';
	color = COLOR_PAIR(PAIR_GREEN);
	
	if (m_type == MIS_ARROW)
	{
	  missile = '-';
	  color = COLOR_PAIR(PAIR_MAGENTA);
	}
	if (m_type == MIS_BLASTER)
	{
	  missile = '=';
	  color = COLOR_PAIR(PAIR_MAGENTA);
	}
	else if (m_type == MIS_FIREBALL)
	{
	  missile = '*';
	  color = COLOR_PAIR(PAIR_RED);
	}
	else if (m_type == MIS_DISINT)
	{
	  missile = (dir > 0 ? '>' : '<');
	  color = COLOR_PAIR(PAIR_RED);
	}
	
	if (water_join(gtile(m_y - 1, m_x)))
	{
	  color = COLOR_PAIR(PAIR_BLACK_ON_CYAN);
	}
	
	if (m_type == MIS_BLASTER)
	{
	  mvwaddch(board, sc_y + adjust_y, sc_x, '_' | color);
/*	if (count % 2)
	mvwaddch(board, sc_y, sc_x, (dir > 0 ? ')' : '(') | color);
	else
	mvwaddch(board, sc_y - 1, sc_x, (dir > 0 ? ')' : '(') | color);*/
	}
	else
	  mvwaddch(board, sc_y + adjust_y, sc_x, missile | color);
	
	
	wrefresh(board);
	spause();
	
	continue;
      }
      
      if (target->shd_up &&
	  ((!target->flip && dir < 0) ||
	   (target->flip && dir > 0)) )
      {
	if (target == player &&
	    m_type == MIS_DISINT &&
	    target->shd_type != SHD_NONE &&
	    target->shd_type != SHD_MAGIC)
	{
	  flush_input();
	  snprintf(line, DEFLEN,
		   "DISINTEGRATION BEAM!!\n\nYOUR %s\nCRUMBLES TO DUST!",
		   armor_name[target->shd_type]);
	  pwait(line);
	  target->shd_type = SHD_NONE;
	  target->shd_up = false;
	  goto end_pass;//return true;
	}
	
	if (m_type != MIS_BLASTER && shield_block(target))
	{
	  mob_text(target, "BLOCK");
	  damage_shield(target);
	  goto end_pass; //return true;
	}
      }
      
      if (target == player && m_type == MIS_DISINT)
      {
	if (target->armor_type != ARMOR_NONE &&
	    target->armor_type != ARMOR_MAGIC)
	{
	  flush_input();
	  snprintf(line, DEFLEN,
		   "DISINTEGRATION BEAM!!\n\nYOUR %s\nCRUMBLES TO DUST!",
		   armor_name[target->armor_type]);
	  pwait(line);
	  target->armor_type = ARMOR_NONE;
	  goto end_pass;// return true;
	}
	
	if (game->weapon != WPN_UNARMED)
	{
	  flush_input();
	  snprintf(line, DEFLEN,
		   "DISINTEGRATION BEAM!!\n\nYOUR %s\nCRUMBLES TO DUST!",
		   weapon_name[game->weapon]);
	  pwait(line);
	  give_weapon(WPN_UNARMED);
	  goto end_pass; //return true;
	}
      }
      
      damage(attacker, target);
      
      if (m_type == MIS_ARROW)
      {
	target->flags = GFX_HURT;
	draw_board(); lpause();
	target->flags = 0;
      }
      else if (m_type == MIS_BLASTER)
      {
	target->flags = GFX_HURT;
	draw_board(); lpause();
	target->flags = 0;
      }
      else if (m_type == MIS_FIREBALL)
      {
	explosion(sc_y, sc_x + dir);
      }
      
      if (target == player)
      {
	draw_bars();
      }
      
      if (target->hp <= 0)
      {
	if (target == player)
	{
	  snprintf(line, DEFLEN,
		   "YOU WERE %s\n"
		   "BY %s%s",
		   (m_type == MIS_FIREBALL ? "FRIED" :
		    (m_type == MIS_DISINT ? "DISINTEGRATED" : "SHOT")),
		   article[attacker->article],
		   mob_name[attacker->type]);
	  draw_board();
	  game_over(line, false);
	}
	else
	{
	  if (!xbow || pass == passes - 1)
	    kill_enemy(target);

	  goto end_pass;
	}
      }
      else if (target != player)
      {
	enemy_bar = target->index;
	enemy_bar_time = BAR_TIMEOUT;
	draw_bars();
	
	// update the number of eyes it has
	if (target->type == MOB_BIGSPIDER)
	  draw_board();//	  draw_board();
      }

      damage_armor(target);
      goto end_pass;
    }

  end_pass:
    continue;
  }
  
//      return 1;
//    }
    
  return 1;
}
Ejemplo n.º 26
0
/*
 * Display a new user or new version message.
 */
void
new_user_or_version(struct pine *ps)
{
    char	  **shown_text;
    int		    cmd = MC_NONE;
    int             first_time_alpine_user = 0;
    char	   *error = NULL;
    HelpType	    text;
    SCROLL_S	    sargs;
    STORE_S	   *store;
    HANDLE_S	   *handles = NULL, *htmp;
    gf_io_t	    pc;
    char           *vers = ps->vers_internal;

    first_time_alpine_user = (ps->first_time_user
			      || (ps->pine_pre_vers
				  && isdigit((unsigned char) ps->pine_pre_vers[0])
				  && ps->pine_pre_vers[1] == '.'
				  && isdigit((unsigned char) vers[0])
				  && vers[1] == '.'
				  && ps->pine_pre_vers[0] < '5'	/* it was Pine */
				  && vers[0] >= '5'));		/* Alpine */

    text = ps->first_time_user    ? new_user_greeting :
            first_time_alpine_user ? new_alpine_user_greeting : new_version_greeting;

    shown_text = text;

    /*
     * Set it if the major revision number
     * (the first after the dot) has changed.
     */
    ps->phone_home = (first_time_alpine_user
		      || (ps->pine_pre_vers
			  && isdigit((unsigned char) ps->pine_pre_vers[0])
			  && ps->pine_pre_vers[1] == '.'
			  && isdigit((unsigned char) ps->pine_pre_vers[2])
			  && isdigit((unsigned char) vers[0])
			  && vers[1] == '.'
			  && isdigit((unsigned char) vers[2])
			  && strncmp(ps->pine_pre_vers, vers, 3) < 0));

    /*
     * At this point, shown_text is a charstarstar with html
     * Turn it into a charstar with digested html
     */
    do{
	init_helper_getc(shown_text);
	init_handles(&handles);

	if((store = so_get(CharStar, NULL, EDIT_ACCESS)) != NULL){
	    gf_set_so_writec(&pc, store);
	    gf_filter_init();

	    gf_link_filter(gf_html2plain,
			   gf_html2plain_opt("x-alpine-help:",
					     ps->ttyo->screen_cols, non_messageview_margin(),
					     &handles, NULL, GFHP_LOCAL_HANDLES));

	    error = gf_pipe(helper_getc, pc);

	    gf_clear_so_writec(store);

	    if(!error){
		struct key_menu km;
		struct key	keys[24];

		for(htmp = handles; htmp; htmp = htmp->next)
		  if(htmp->type == URL
		     && htmp->h.url.path
		     && (htmp->h.url.path[0] == 'x'
			 || htmp->h.url.path[0] == '#'))
		    htmp->force_display = 1;

		/* This is mostly here to get the curses variables
		 * for line and column in sync with where the
		 * cursor is on the screen. This gets warped when
		 * the composer is called because it does it's own
		 * stuff
		 */
		ClearScreen();

		memset(&sargs, 0, sizeof(SCROLL_S));
		sargs.text.text	   = so_text(store);
		sargs.text.src	   = CharStar;
		sargs.text.desc	   = "greeting text";
		sargs.text.handles = handles;
		sargs.bar.title	   = "GREETING TEXT";
		sargs.bar.style	   = TextPercent;
		sargs.proc.tool	   = nuov_processor;
		sargs.help.text	   = main_menu_tx;
		sargs.help.title   = "MAIN PINE HELP";
		sargs.resize_exit  = 1;
		sargs.keys.menu	   = &km;
		km		   = nuov_keymenu;
		km.keys		   = keys;
		memcpy(&keys[0], nuov_keymenu.keys,
		       (nuov_keymenu.how_many * 12) * sizeof(struct key));
		setbitmap(sargs.keys.bitmap);

		if(ps->phone_home){
		    km.keys[NUOV_EXIT].label = "Exit this greeting";
		    km.keys[NUOV_EXIT].bind.nch = 1;
		}
		else{
		    km.keys[NUOV_EXIT].label	= "[Exit this greeting]";
		    km.keys[NUOV_EXIT].bind.nch = 3;
		    clrbitn(NUOV_VIEW, sargs.keys.bitmap);
		}

		if(ps->first_time_user)
		  clrbitn(NUOV_RELNOTES, sargs.keys.bitmap);

		cmd = scrolltool(&sargs);

		flush_input();

		if(F_ON(F_BLANK_KEYMENU,ps_global))
		  FOOTER_ROWS(ps_global) = 1;

		ClearScreen();
	    }

	    so_give(&store);
	}

	free_handles(&handles);
    }
    while(cmd == MC_RESIZE);
}
Ejemplo n.º 27
0
int tty_ioctl(struct inode * inode, struct file * file,
	unsigned int cmd, unsigned long arg)
{
	struct tty_struct * tty;
	struct tty_struct * other_tty;
	struct tty_struct * termios_tty;
	pid_t pgrp;
	int dev;
	int termios_dev;
	int retval;

	if (MAJOR(file->f_rdev) != TTY_MAJOR) {
		printk("tty_ioctl: tty pseudo-major != TTY_MAJOR\n");
		return -EINVAL;
	}
	dev = MINOR(file->f_rdev);
	tty = TTY_TABLE(dev);
	if (!tty)
		return -EINVAL;
	if (IS_A_PTY(dev))
		other_tty = tty_table[PTY_OTHER(dev)];
	else
		other_tty = NULL;
	if (IS_A_PTY_MASTER(dev)) {
		termios_tty = other_tty;
		termios_dev = PTY_OTHER(dev);
	} else {
		termios_tty = tty;
		termios_dev = dev;
	}
	switch (cmd) {
		case TCGETS:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (struct termios));
			if (retval)
				return retval;
			memcpy_tofs((struct termios *) arg,
				    termios_tty->termios,
				    sizeof (struct termios));
			return 0;
		case TCSETSF:
		case TCSETSW:
		case TCSETS:
			retval = check_change(termios_tty, termios_dev);
			if (retval)
				return retval;
			if (cmd == TCSETSF || cmd == TCSETSW) {
				if (cmd == TCSETSF)
					flush_input(termios_tty);
				wait_until_sent(termios_tty, 0);
			}
			return set_termios(termios_tty, (struct termios *) arg,
					   termios_dev);
		case TCGETA:
			return get_termio(termios_tty,(struct termio *) arg);
		case TCSETAF:
		case TCSETAW:
		case TCSETA:
			retval = check_change(termios_tty, termios_dev);
			if (retval)
				return retval;
			if (cmd == TCSETAF || cmd == TCSETAW) {
				if (cmd == TCSETAF)
					flush_input(termios_tty);
				wait_until_sent(termios_tty, 0);
			}
			return set_termio(termios_tty, (struct termio *) arg,
					  termios_dev);
		case TCXONC:
			retval = check_change(tty, dev);
			if (retval)
				return retval;
			switch (arg) {
			case TCOOFF:
				stop_tty(tty);
				break;
			case TCOON:
				start_tty(tty);
				break;
			case TCIOFF:
				if (STOP_CHAR(tty) != __DISABLED_CHAR)
					put_tty_queue(STOP_CHAR(tty),
						      &tty->write_q);
				break;
			case TCION:
				if (START_CHAR(tty) != __DISABLED_CHAR)
					put_tty_queue(START_CHAR(tty),
						      &tty->write_q);
				break;
			default:
				return -EINVAL;
			}
			return 0;
		case TCFLSH:
			retval = check_change(tty, dev);
			if (retval)
				return retval;
			switch (arg) {
			case TCIFLUSH:
				flush_input(tty);
				break;
			case TCIOFLUSH:
				flush_input(tty);
				/* fall through */
			case TCOFLUSH:
				flush_output(tty);
				break;
			default:
				return -EINVAL;
			}
			return 0;
		case TIOCEXCL:
			set_bit(TTY_EXCLUSIVE, &tty->flags);
			return 0;
		case TIOCNXCL:
			clear_bit(TTY_EXCLUSIVE, &tty->flags);
			return 0;
		case TIOCSCTTY:
			if (current->leader &&
			    (current->session == tty->session))
				return 0;
			/*
			 * The process must be a session leader and
			 * not have a controlling tty already.
			 */
			if (!current->leader || (current->tty >= 0))
				return -EPERM;
			if (tty->session > 0) {
				/*
				 * This tty is already the controlling
				 * tty for another session group!
				 */
				if ((arg == 1) && suser()) {
					/*
					 * Steal it away
					 */
					struct task_struct *p;

					for_each_task(p)
						if (p->tty == dev)
							p->tty = -1;
				} else
					return -EPERM;
			}
			current->tty = dev;
			tty->session = current->session;
			tty->pgrp = current->pgrp;
			return 0;
		case TIOCGPGRP:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (pid_t));
			if (retval)
				return retval;
			if (current->tty != termios_dev)
				return -ENOTTY;
			put_fs_long(termios_tty->pgrp, (pid_t *) arg);
			return 0;
		case TIOCSPGRP:
			retval = check_change(termios_tty, termios_dev);
			if (retval)
				return retval;
			if ((current->tty < 0) ||
			    (current->tty != termios_dev) ||
			    (termios_tty->session != current->session))
				return -ENOTTY;
			pgrp = get_fs_long((pid_t *) arg);
			if (pgrp < 0)
				return -EINVAL;
			if (session_of_pgrp(pgrp) != current->session)
				return -EPERM;
			termios_tty->pgrp = pgrp;
			return 0;
		case TIOCOUTQ:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (unsigned long));
			if (retval)
				return retval;
			put_fs_long(CHARS(&tty->write_q),
				    (unsigned long *) arg);
			return 0;
		case TIOCINQ:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (unsigned long));
			if (retval)
				return retval;
			if (L_ICANON(tty))
				put_fs_long(inq_canon(tty),
					(unsigned long *) arg);
			else
				put_fs_long(CHARS(&tty->secondary),
					(unsigned long *) arg);
			return 0;
		case TIOCSTI:
			if ((current->tty != dev) && !suser())
				return -EPERM;
			retval = verify_area(VERIFY_READ, (void *) arg, 1);
			if (retval)
				return retval;
			put_tty_queue(get_fs_byte((char *) arg), &tty->read_q);
			TTY_READ_FLUSH(tty);
			return 0;
		case TIOCGWINSZ:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (struct winsize));
			if (retval)
				return retval;
			memcpy_tofs((struct winsize *) arg, &tty->winsize,
				    sizeof (struct winsize));
			return 0;
		case TIOCSWINSZ:
			if (IS_A_PTY_MASTER(dev))
				set_window_size(other_tty,(struct winsize *) arg);
			return set_window_size(tty,(struct winsize *) arg);
		case TIOCLINUX:
			switch (get_fs_byte((char *)arg))
			{
				case 0: 
					return do_screendump(arg);
				case 1: 
					return do_get_ps_info(arg);
#ifdef CONFIG_SELECTION
				case 2:
					return set_selection(arg);
				case 3:
					return paste_selection(tty);
				case 4:
					unblank_screen();
					return 0;
#endif /* CONFIG_SELECTION */
				default: 
					return -EINVAL;
			}
		case TIOCCONS:
			if (IS_A_CONSOLE(dev)) {
				if (!suser())
					return -EPERM;
				redirect = NULL;
				return 0;
			}
			if (redirect)
				return -EBUSY;
			if (!suser())
				return -EPERM;
			if (IS_A_PTY_MASTER(dev))
				redirect = other_tty;
			else if (IS_A_PTY_SLAVE(dev))
				redirect = tty;
			else
				return -ENOTTY;
			return 0;
		case FIONBIO:
			arg = get_fs_long((unsigned long *) arg);
			if (arg)
				file->f_flags |= O_NONBLOCK;
			else
				file->f_flags &= ~O_NONBLOCK;
			return 0;
		case TIOCNOTTY:
			if (current->tty != dev)
				return -ENOTTY;
			if (current->leader)
				disassociate_ctty(0);
			current->tty = -1;
			return 0;
		case TIOCGETD:
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (unsigned long));
			if (retval)
				return retval;
			put_fs_long(tty->disc, (unsigned long *) arg);
			return 0;
		case TIOCSETD:
			retval = check_change(tty, dev);
			if (retval)
				return retval;
			arg = get_fs_long((unsigned long *) arg);
			return tty_set_ldisc(tty, arg);
		case TIOCGLCKTRMIOS:
			arg = get_fs_long((unsigned long *) arg);
			retval = verify_area(VERIFY_WRITE, (void *) arg,
					     sizeof (struct termios));
			if (retval)
				return retval;
			memcpy_tofs((struct termios *) arg,
				    &termios_locked[termios_dev],
				    sizeof (struct termios));
			return 0;
		case TIOCSLCKTRMIOS:
			if (!suser())
				return -EPERM;
			arg = get_fs_long((unsigned long *) arg);
			memcpy_fromfs(&termios_locked[termios_dev],
				      (struct termios *) arg,
				      sizeof (struct termios));
			return 0;
		case TIOCPKT:
			if (!IS_A_PTY_MASTER(dev))
				return -ENOTTY;
			retval = verify_area(VERIFY_READ, (void *) arg,
					     sizeof (unsigned long));
			if (retval)
				return retval;
			if (get_fs_long(arg)) {
				if (!tty->packet) {
					tty->packet = 1;
					tty->link->ctrl_status = 0;
				}
			} else
				tty->packet = 0;
			return 0;
		case TCSBRK: case TCSBRKP:
			retval = check_change(tty, dev);
			if (retval)
				return retval;
			wait_until_sent(tty, 0);
			if (!tty->ioctl)
				return 0;
			tty->ioctl(tty, file, cmd, arg);
			return 0;
		default:
			if (tty->ioctl) {
				retval = (tty->ioctl)(tty, file, cmd, arg);
				if (retval != -EINVAL)
					return retval;
			}
			if (ldiscs[tty->disc].ioctl) {
				retval = (ldiscs[tty->disc].ioctl)
					(tty, file, cmd, arg);
				return retval;
			}
			return -EINVAL;
	}
Ejemplo n.º 28
0
int main(int args, char* argv[]){

    signal(SIGINT,interrupt);

    printf("OCZEKIWANIE NA DRUGIEGO GRACZA\n");

    /* SPRAWDZANIE POPRAWNOSCI ARGUMENTOW */

    if(args<4){
        printf("NIEWLASCIWA LICZBA ARGUMENTOW\n");
        exit(1);
    }

    int init_queue_key=atoi(argv[1]);
    int id_gracza=atoi(argv[2]);

    int init_queue_id=msgget(init_queue_key,IPC_CREAT|0664);
    if(init_queue_id==-1){
        perror("BLAD STWORZENIA KOLEJKI INIT");
        exit(1);
    }



    Init_message init_message;
    init_message.mtype=ROZPOCZNIJ;
    init_message.init_data.id_gracza=id_gracza;
    msgsnd(init_queue_id,&init_message,sizeof(init_message.init_data),0);

    msgrcv(init_queue_id,&init_message, sizeof(init_message.init_data),AKCEPTUJ,0);

    int game_queue_key=init_message.init_data.id_kolejki_kom;

    game_queue_id=msgget(game_queue_key,IPC_CREAT|0664);
    if(game_queue_id==-1){
        perror("Blad przy otwarciu kolejki do komunikacji");
        exit(1);
    }


    int output_queue_key=atoi(argv[3]);
    output_queue_id=msgget(output_queue_key,IPC_CREAT|0664);
    if(output_queue_id==-1){
        perror("Blad przy tworzeniu kolejki output");
        exit(1);
    }

    init_message.mtype=ID;
    init_message.init_data.id_gracza=id_gracza;
    msgsnd(output_queue_id,&init_message, sizeof(init_message.init_data),0);

    if(fork()==0){

        Game_message train_message;
        train_message.mtype=TWORZ;

        Game_message battle_message;
        battle_message.mtype=ATAK;

        Game_message surrender_message;
        surrender_message.mtype=PODDAJSIE;

        Game_data_struct train_list;
        Game_data_struct battle_list;

        char decyzja;

        char buffer[MAX]="";


        while(1){
            printf("\033[2J\033[1;1H");
            printf("ID GRACZA TO: %d\n",id_gracza);
            printf("WYBIERZ AKCJE:\n1-trening jednostek\n2-atak\n3-poddaj sie\n\n");

            /* Pobranie komendy */
            decyzja=fgetc (stdin);
            /* Usuniecie pozostalosci w stdin */
            flush_input(stdin);

            if(decyzja=='1') {

                printf("Wybierz liczbe jednostek lekkiej piechoty\n");
                fgets (buffer, MAX, stdin);
                train_list.light_infantry=(int)strtol(buffer,NULL,0);

                printf("Wybierz liczbe jednostek ciezkiej piechoty\n");
                fgets (buffer, MAX, stdin);
                train_list.heavy_infantry=(int)strtol(buffer,NULL,0);

                printf("Wybierz liczbe jednostek jazdy\n");
                fgets (buffer, MAX, stdin);
                train_list.cavalry=(int)strtol(buffer,NULL,0);

                printf("Wybierz liczbe robotnikow\n");
                fgets (buffer, MAX, stdin);
                train_list.workers=(int)strtol(buffer,NULL,0);

                train_message.game_data=train_list;
                msgsnd(game_queue_id,&train_message, sizeof(train_message.game_data),0);
                printf("WYSLANO POLECENIE TRENINGU\n");
            }

            else if(decyzja=='2') {
                printf("Wybierz liczbe jednostek lekkiej piechoty\n");
                fgets (buffer, MAX, stdin);
                battle_list.light_infantry=(int)strtol(buffer,NULL,0);

                printf("Wybierz liczbe jednostek ciezkiej piechoty\n");
                fgets (buffer, MAX, stdin);
                battle_list.heavy_infantry=(int)strtol(buffer,NULL,0);

                printf("Wybierz liczbe jednostek jazdy\n");
                fgets (buffer, MAX, stdin);
                battle_list.cavalry=(int)strtol(buffer,NULL,0);

                battle_message.game_data=battle_list;

                msgsnd(game_queue_id,&battle_message, sizeof(battle_message.game_data),0);
                printf("WYSLANO POLECENIE ATAKU\n");
            }
            else if(decyzja=='3'){
                printf("Poddales sie\n");
                msgsnd(game_queue_id,&surrender_message, sizeof(surrender_message.game_data),0);
                msgsnd(output_queue_id,&surrender_message,sizeof(surrender_message.game_data),0);

                kill(0,SIGKILL);

            }
            else {
                printf("NIE MA TAKIEJ KOMENDY\n");
            }

        }

    }
    else {

        Game_message message;
        Game_message response_message;
        response_message.mtype=ODPOWIEDZ;

        msgsnd(output_queue_id, &message, sizeof(message.game_data), 0);



        while (1) {
            msgrcv(game_queue_id, &message, sizeof(message.game_data), 0, 0);
            if (message.mtype == KONIEC || message.mtype == ZAKONCZ) {
                msgsnd(output_queue_id, &message, sizeof(message.game_data), 0);

                sleep(1);

                msgctl(game_queue_id,IPC_RMID,0);
                msgctl(output_queue_id,IPC_RMID,0);

                kill(0, SIGKILL);
            }
            else if (message.mtype == ATAK || message.mtype == TWORZ || message.mtype == PODDAJSIE) {
                msgsnd(game_queue_id, &message, sizeof(message.game_data), 0);
            }
                else if(message.mtype==ZAPYTANIE){
                msgsnd(game_queue_id,&response_message, sizeof(response_message.game_data),0);
            }
            else {
                msgsnd(output_queue_id, &message, sizeof(message.game_data), 0);
            }

        }

    }
}
Ejemplo n.º 29
0
int tty_ioctl(struct inode * inode, struct file * file,
	unsigned int cmd, unsigned int arg)
{
	struct tty_struct * tty;
	struct tty_struct * other_tty;
	int pgrp;
	int dev;

	if (MAJOR(file->f_rdev) != 4) {
		printk("tty_ioctl: tty pseudo-major != 4\n");
		return -EINVAL;
	}
	dev = MINOR(file->f_rdev);
	tty = TTY_TABLE(dev);
	if (!tty)
		return -EINVAL;

	if (IS_A_PTY(dev))
		other_tty = tty_table[PTY_OTHER(dev)];
	else
		other_tty = NULL;
		
	switch (cmd) {
		case TCGETS:
			return get_termios(tty,(struct termios *) arg);
		case TCSETSF:
			flush_input(tty);
		/* fallthrough */
		case TCSETSW:
			wait_until_sent(tty);
		/* fallthrough */
		case TCSETS:
			return set_termios(tty,(struct termios *) arg, dev);
		case TCGETA:
			return get_termio(tty,(struct termio *) arg);
		case TCSETAF:
			flush_input(tty);
		/* fallthrough */
		case TCSETAW:
			wait_until_sent(tty); /* fallthrough */
		case TCSETA:
			return set_termio(tty,(struct termio *) arg, dev);
		case TCXONC:
			switch (arg) {
			case TCOOFF:
				tty->stopped = 1;
				TTY_WRITE_FLUSH(tty);
				return 0;
			case TCOON:
				tty->stopped = 0;
				TTY_WRITE_FLUSH(tty);
				return 0;
			case TCIOFF:
				if (STOP_CHAR(tty))
					put_tty_queue(STOP_CHAR(tty),
						      &tty->write_q);
				return 0;
			case TCION:
				if (START_CHAR(tty))
					put_tty_queue(START_CHAR(tty),
						      &tty->write_q);
				return 0;
			}
			return -EINVAL; /* not implemented */
		case TCFLSH:
			if (arg==0)
				flush_input(tty);
			else if (arg==1)
				flush_output(tty);
			else if (arg==2) {
				flush_input(tty);
				flush_output(tty);
			} else
				return -EINVAL;
			return 0;
		case TIOCEXCL:
			return -EINVAL; /* not implemented */
		case TIOCNXCL:
			return -EINVAL; /* not implemented */
		case TIOCSCTTY:
			return -EINVAL; /* set controlling term NI */
		case TIOCGPGRP:
			verify_area((void *) arg,4);
			put_fs_long(tty->pgrp,(unsigned long *) arg);
			return 0;
		case TIOCSPGRP:
			if ((current->tty < 0) ||
			    (current->tty != dev) ||
			    (tty->session != current->session))
				return -ENOTTY;
			pgrp=get_fs_long((unsigned long *) arg);
			if (pgrp < 0)
				return -EINVAL;
			if (session_of_pgrp(pgrp) != current->session)
				return -EPERM;
			tty->pgrp = pgrp;			
			return 0;
		case TIOCOUTQ:
			verify_area((void *) arg,4);
			put_fs_long(CHARS(&tty->write_q),
				    (unsigned long *) arg);
			return 0;
		case TIOCINQ:
			verify_area((void *) arg,4);
			if (L_CANON(tty) && !tty->secondary.data)
				put_fs_long(0, (unsigned long *) arg);
			else
				put_fs_long(CHARS(&tty->secondary),
					(unsigned long *) arg);
			return 0;
		case TIOCSTI:
			return -EINVAL; /* not implemented */
		case TIOCGWINSZ:
			return get_window_size(tty,(struct winsize *) arg);
		case TIOCSWINSZ:
			if (IS_A_PTY_MASTER(dev))
				set_window_size(other_tty,(struct winsize *) arg);
			return set_window_size(tty,(struct winsize *) arg);
		case TIOCGSOFTCAR:
			return -EINVAL; /* not implemented */
		case TIOCSSOFTCAR:
			return -EINVAL; /* not implemented */
		case TIOCLINUX:
			switch (get_fs_byte((char *)arg))
			{
				case 0: 
					return do_screendump(arg);
				case 1: 
					return do_get_ps_info(arg);
				default: 
					return -EINVAL;
			}
		case TIOCCONS:
			if (!IS_A_PTY(dev))
				return -EINVAL;
			if (redirect)
				return -EBUSY;
			if (!suser())
				return -EPERM;
			if (IS_A_PTY_MASTER(dev))
				redirect = other_tty;
			else
				redirect = tty;
			return 0;
		case FIONBIO:
			if (arg)
				file->f_flags |= O_NONBLOCK;
			else
				file->f_flags &= ~O_NONBLOCK;
			return 0;
		case TIOCNOTTY:
			if (MINOR(file->f_rdev) != current->tty)
				return -EINVAL;
			current->tty = -1;
			if (current->leader) {
				if (tty->pgrp > 0)
					kill_pg(tty->pgrp, SIGHUP, 0);
				tty->pgrp = -1;
				tty->session = 0;
			}
			return 0;

	       case TIOCPKT:
			{
			   int on;
			   if (!IS_A_PTY_MASTER(dev))
			     return (-EINVAL);
			   verify_area ((unsigned long *)arg, sizeof (int));
			   on=get_fs_long ((unsigned long *)arg);
			   if (on )
			     tty->packet = 1;
			   else
			     tty->packet = 0;
			   return (0);
			}

		default:
			if (tty->ioctl)
				return (tty->ioctl)(tty, file, cmd, arg);
			else
				return -EINVAL;
	}
}
Ejemplo n.º 30
0
/*
 * We handle the console-specific ioctl's here.  We allow the
 * capability to modify any console, not just the fg_console. 
 */
int vt_ioctl(struct tty_struct *tty, struct file * file,
	     unsigned int cmd, unsigned int arg)
{
	int console;
	unsigned char ucval;

	console = tty->line - 1;

	if (console < 0 || console >= NR_CONSOLES)
		return -EINVAL;

	switch (cmd) {
	case KIOCSOUND:
		return kiocsound((unsigned int)arg);

	case KDGKBTYPE:
		/*
		 * this is naive.
		 */
		verify_area((void *) arg, sizeof(unsigned char));
		put_fs_byte(KB_101, (unsigned char *) arg);
		return 0;

	case KDADDIO:
	case KDDELIO:
		/*
		 * KDADDIO and KDDELIO may be able to add ports beyond what
		 * we reject here, but to be safe...
		 */
		if (arg < GPFIRST || arg > GPLAST)
			return -EINVAL;
		return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;

	case KDENABIO:
	case KDDISABIO:
		return sys_ioperm(GPFIRST, GPNUM,
				  (cmd == KDENABIO)) ? -ENXIO : 0;

	case KDSETMODE:
		/*
		 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
		 * doesn't do a whole lot. i'm not sure if it should do any
		 * restoration of modes or what...
		 */
		switch (arg) {
		case KD_GRAPHICS:
			break;
		case KD_TEXT0:
		case KD_TEXT1:
			arg = KD_TEXT;
		case KD_TEXT:
			break;
		default:
			return -EINVAL;
		}
		if (vt_cons[console].vt_mode == (unsigned char) arg)
			return 0;
		vt_cons[console].vt_mode = (unsigned char) arg;
		if (console != fg_console)
			return 0;
		if (arg == KD_TEXT)
			unblank_screen();
		else {
			timer_active &= 1<<BLANK_TIMER;
			blank_screen();
		}
		return 0;
	case KDGETMODE:
		verify_area((void *) arg, sizeof(unsigned long));
		put_fs_long(vt_cons[console].vt_mode, (unsigned long *) arg);
		return 0;

	case KDMAPDISP:
	case KDUNMAPDISP:
		/*
		 * these work like a combination of mmap and KDENABIO.
		 * this could be easily finished.
		 */
		return -EINVAL;

	case KDSKBMODE:
		if (arg == K_RAW) {
			if (console == fg_console) {
				kraw = 1;
				ke0 = 0;
			} else {
				vt_cons[console].vc_kbdraw = 1;
				vt_cons[console].vc_kbde0 = 0;
			}
		}
		else if (arg == K_XLATE) {
			if (console == fg_console)
				kraw = 0;
			else
				vt_cons[console].vc_kbdraw = 0;
		}
		else
			return -EINVAL;
		flush_input(tty);
		return 0;
	case KDGKBMODE:
		verify_area((void *) arg, sizeof(unsigned long));
		ucval = (console == fg_console) ? kraw :
			vt_cons[console].vc_kbdraw;
		put_fs_long(ucval ? K_RAW : K_XLATE, (unsigned long *) arg);
		return 0;

	case KDGETLED:
		verify_area((void *) arg, sizeof(unsigned char));
		ucval = (console == fg_console) ? kleds :
			vt_cons[console].vc_kbdleds;
		put_fs_byte((((ucval & 1) ? LED_SCR : 0) |
			     ((ucval & 2) ? LED_NUM : 0) |
			     ((ucval & 4) ? LED_CAP : 0)),
			    (unsigned char *) arg);
		return 0;
	case KDSETLED:
		if (arg & ~7)
			return -EINVAL;
		ucval = (((arg & LED_SCR) ? 1 : 0) |
			 ((arg & LED_NUM) ? 2 : 0) |
			 ((arg & LED_CAP) ? 4 : 0));
		if (console == fg_console) {
			kleds = ucval;
			set_leds();
		}
		else
			vt_cons[console].vc_kbdleds = ucval;
		return 0;

	default:
		return -EINVAL;
	}
}