示例#1
0
int
tty_setup()
{
	WINDOW *tt_win, *newwin();
	char message[80], *str, *get_str();
	int num, i, j, ret_code;
	void disp_tty(), create_modem(), del_modem(), error_win();
	void del_tty();

	tt_win = newwin(23, 80, 0, 0);

	horizontal(tt_win, 0, 0, 34);
	mvwattrstr(tt_win, 0, 35, A_BOLD, "TTY Setup");
	horizontal(tt_win, 0, 45, 34);
	mvwaddstr(tt_win, 2, 22, "TTY name");
	mvwaddstr(tt_win, 2, 37, "Modem name");
	mvwaddstr(tt_win, 2, 51, "Init speed");
					/* display the current TTY list */
	disp_tty(tt_win);
					/* prompt for options */
	mvwaddstr(tt_win, 15, 20, "A) Add a TTY entry");
	mvwaddstr(tt_win, 16, 20, "D) Delete a TTY entry");
	horizontal(tt_win, 19, 0, 80);
	mvwattrstr(tt_win, 20, 0, A_BOLD, "OPTION ==> ");
	mvwaddstr(tt_win, 20, 58, "Press <ESC> to return");
	wmove(tt_win, 20, 12);
	touchwin(tt_win);
	wrefresh(tt_win);
					/* get the option */
	ret_code = 0;
	while ((str = get_str(tt_win, 2, "01234356789AaDd", "")) != NULL) {
		switch(*str) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				i = atoi(str);
					/* if beyond t_entries */
				if (i > modem->t_entries) {
					beep();
					break;
				}

					/* change the entry  */
				if (tty_prompt(tt_win, i-1)) {

					/* requires modem update? */
					create_modem(modem->tname[i-1]);
					del_modem();
					ret_code++;
				}
				break;
			case 'a':
			case 'A':	/* add an entry */
				if (modem->t_entries == NUM_TTY) {
					sprintf(message, "\"%s\"", modem->m_path);
					error_win(0, "No empty TTY slots in modem/TTY database", message);
					break;
				}
					/* prompt for info */
				j = modem->t_entries;
				if (tty_prompt(tt_win, j)) {

					/* add modem entry? */
					modem->t_entries++;
					create_modem(modem->tname[j]);
					ret_code++;
				}
				break;
			case 'd':
			case 'D':	/* delete an entry */
				mvwaddstr(tt_win, 21, 0, "Entry number to delete: ");
				wrefresh(tt_win);
				while ((num = get_num(tt_win, 4)) != -1) {
					/* valid range */
					if (!num || num>modem->t_entries) {
						beep();
						mvwaddstr(tt_win, 21, 24, "   ");
						wmove(tt_win, 21, 24);
						wrefresh(tt_win);
						continue;
					}
					del_tty(num-1);
					del_modem();

					/* show the new list */
					disp_tty(tt_win);
					ret_code++;
					break;
				}
				break;
			default:
				beep();
				break;
		}
		mvwaddstr(tt_win, 20, 12, "  ");
		clear_line(tt_win, 21, 0, FALSE);
		clear_line(tt_win, 22, 0, FALSE);
		wmove(tt_win, 20, 12);
		wrefresh(tt_win);
	}
	delwin(tt_win);
	return(ret_code);
}
示例#2
0
文件: inserts.c 项目: ysleu/RTL8685
static void
test_inserts(int level)
{
    static bool first = TRUE;

    int ch;
    int limit;
    int row = 1;
    int col;
    int row2, col2;
    int length;
    char buffer[BUFSIZ];
    WINDOW *look = 0;
    WINDOW *work = 0;
    WINDOW *show = 0;
    int margin = (2 * MY_TABSIZE) - 1;
    Options option = (Options) ((unsigned) (m_opt
					    ? oMove
					    : oDefault)
				| (unsigned) ((w_opt || (level > 0))
					      ? oWindow
					      : oDefault));

    if (first) {
	static char cmd[80];
	setlocale(LC_ALL, "");

	putenv(strcpy(cmd, "TABSIZE=8"));

	initscr();
	(void) cbreak();	/* take input chars one at a time, no wait for \n */
	(void) noecho();	/* don't echo input */
	keypad(stdscr, TRUE);
    }

    limit = LINES - 5;
    if (level > 0) {
	look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1);
	work = newwin(limit - 2, COLS - (2 * level), 1, level);
	show = newwin(4, COLS, limit + 1, 0);
	box(look, 0, 0);
	wnoutrefresh(look);
	limit -= 2;
    } else {
	work = stdscr;
	show = derwin(stdscr, 4, COLS, limit + 1, 0);
    }
    keypad(work, TRUE);

    for (col = margin + 1; col < COLS; col += MY_TABSIZE)
	MvWVLine(work, row, col, '.', limit - 2);

    MvWVLine(work, row, margin, ACS_VLINE, limit - 2);
    MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2);
    limit /= 2;

    MvWAddStr(work, 1, 2, "String");
    MvWAddStr(work, limit + 1, 2, "Chars");
    wnoutrefresh(work);

    buffer[length = 0] = '\0';
    legend(show, level, option, buffer, length);
    wnoutrefresh(show);

    doupdate();

    /*
     * Show the characters inserted in color, to distinguish from those that
     * are shifted.
     */
    if (has_colors()) {
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLUE);
	wbkgdset(work, COLOR_PAIR(1) | ' ');
    }

    while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) {
	wmove(work, row, margin + 1);
	switch (ch) {
	case key_RECUR:
	    test_inserts(level + 1);

	    touchwin(look);
	    touchwin(work);
	    touchwin(show);

	    wnoutrefresh(look);
	    wnoutrefresh(work);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	case key_NEWLINE:
	    if (row < limit) {
		++row;
		/* put the whole string in, all at once */
		col2 = margin + 1;
		switch (option) {
		case oDefault:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (move(row, col2) != ERR) {
				InsNStr(buffer + col, LEN(col));
			    }
			}
		    } else {
			if (move(row, col2) != ERR) {
			    InsStr(buffer);
			}
		    }
		    break;
		case oMove:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvInsNStr(row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvInsStr(row, col2, buffer);
		    }
		    break;
		case oWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (wmove(work, row, col2) != ERR) {
				WInsNStr(work, buffer + col, LEN(col));
			    }
			}
		    } else {
			if (wmove(work, row, col2) != ERR) {
			    WInsStr(work, buffer);
			}
		    }
		    break;
		case oMoveWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvWInsNStr(work, row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvWInsStr(work, row, col2, buffer);
		    }
		    break;
		}

		/* do the corresponding single-character insertion */
		row2 = limit + row;
		for (col = 0; col < length; ++col) {
		    col2 = ColOf(buffer, col, margin);
		    switch (option) {
		    case oDefault:
			if (move(row2, col2) != ERR) {
			    InsCh(UChar(buffer[col]));
			}
			break;
		    case oMove:
			MvInsCh(row2, col2, UChar(buffer[col]));
			break;
		    case oWindow:
			if (wmove(work, row2, col2) != ERR) {
			    WInsCh(work, UChar(buffer[col]));
			}
			break;
		    case oMoveWindow:
			MvWInsCh(work, row2, col2, UChar(buffer[col]));
			break;
		    }
		}
	    } else {
		beep();
	    }
	    break;
	default:
	    if (ch <= 0 || ch > 255) {
		beep();
		break;
	    }
	    buffer[length++] = (char) ch;
	    buffer[length] = '\0';

	    /* put the string in, one character at a time */
	    col = ColOf(buffer, length - 1, margin);
	    switch (option) {
	    case oDefault:
		if (move(row, col) != ERR) {
		    InsStr(buffer + length - 1);
		}
		break;
	    case oMove:
		MvInsStr(row, col, buffer + length - 1);
		break;
	    case oWindow:
		if (wmove(work, row, col) != ERR) {
		    WInsStr(work, buffer + length - 1);
		}
		break;
	    case oMoveWindow:
		MvWInsStr(work, row, col, buffer + length - 1);
		break;
	    }

	    /* do the corresponding single-character insertion */
	    switch (option) {
	    case oDefault:
		if (move(limit + row, col) != ERR) {
		    InsCh(UChar(ch));
		}
		break;
	    case oMove:
		MvInsCh(limit + row, col, UChar(ch));
		break;
	    case oWindow:
		if (wmove(work, limit + row, col) != ERR) {
		    WInsCh(work, UChar(ch));
		}
		break;
	    case oMoveWindow:
		MvWInsCh(work, limit + row, col, UChar(ch));
		break;
	    }

	    wnoutrefresh(work);

	    legend(show, level, option, buffer, length);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	}
    }
    if (level > 0) {
	delwin(show);
	delwin(work);
	delwin(look);
    }
}
示例#3
0
文件: object.c 项目: ethandicks/ularn
/*
	***************
	LOOK_FOR_OBJECT
	***************

	subroutine to look for an object and give the player his options
	if an object was found.
 */
lookforobject()
{
	int i,j;

	/* can't find objects is time is stopped*/
	if (c[TIMESTOP])  return;	

	i=item[playerx][playery];	
	if (i==0) return;

	showcell(playerx,playery);  
	cursors();  
	yrepcount=0;

	switch(i) {
	case OGOLDPILE:	
	case OMAXGOLD:
	case OKGOLD:	
	case ODGOLD:	
		ogold(i);	
		break;

	case OPOTION:	
		lprcat("\n\nYou find a magic potion");
		i = iarg[playerx][playery];
		if (potionknown[i]) lprintf(" of %s",&potionname[i][1]);
		lprcat(".");
		opotion(i);  
		break;

	case OSCROLL:	
		lprcat("\n\nYou find a magic scroll");
		i = iarg[playerx][playery];
		if (scrollknown[i]) lprintf(" of %s",&scrollname[i][1]);
		lprcat(".");
		oscroll(i);  
		break;

	case OALTAR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a holy altar here.");
		oaltar(); 
		break;

	case OBOOK:	
		lprcat("\n\nYou find a book.");
		obook(); 
		break;

	case OCOOKIE:	
		lprcat("\n\nYou find a fortune cookie.");
		ocookie(); 
		break;

	case OTHRONE:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(0); 
		break;

	case OTHRONE2:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(1); 
		break;

	case ODEADTHRONE: 
		lprintf("\n\nThere is %s here.",objectname[i]);
		odeadthrone(); 
		break;

	case OORB:	
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OBRASSLAMP: 
		lprcat("\nYou find a brass lamp.");
	lprcat("\nDo you want to (r) rub it, (t) take it, or (i) ignore it? ");
		i=0;
		while ((i!='r') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='r') {
			i=rnd(100);
			if (i>90) {
		lprcat("\nThe magic genie was very upset at being disturbed!");
				lastnum = 286;
				losehp((int)c[HP]/2+1);
				beep();
			}
			/* higher level, better chance of spell */
			else if ( (rnd(100)+c[LEVEL]/2) > 80) {
				int a,b,d;
				lprcat("\nA magic genie appears!");
				cursors();
				lprcat("\n  What spell would you like? : ");
				while ((a=getcharacter())=='D') { 	
					seemagic(99);
					cursors();  
					lprcat("\n  What spell would you like? : ");
				}
				/* to escape casting a spell	*/
				if (a==ESC) goto over; 	
				if ((b=getcharacter())==ESC) 
					goto over;
				if ((d=getcharacter())==ESC) { 
over: 
					lprcat("aborted"); 
					return;
				}
				lprc('\n');
				for (i=0; i<SPNUM; i++)
					if ((spelcode[i][0]==a) 
					    && (spelcode[i][1]==b) 
					    && (spelcode[i][2]==d)) {
						spelknow[i]=1;
						lprintf("\nSpell \"%s\":  %s\n%s",spelcode[i],
								spelname[i],speldescript[i]); 
						lprcat("\nThe genie prefers not to be disturbed "
							   "again.");
						forget();
						bottomline();
						return;
					}
				lprcat("\nThe genie has never heard of such a spell!");
				lprcat("\nThe genie prefers not to be disturbed again.");
				forget();
				bottomline();
				return;
			}
			else lprcat("\nnothing happened.");
			if (rnd(100) < 15) {
				lprcat("\nThe genie prefers not to be disturbed again!");
				forget();
				c[LAMP]=0;  /* chance of finding lamp again */
			}
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OBRASSLAMP,0)==0) 
				forget();
		}
		else lprcat("ignore.");
		return;

	case OWWAND:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OHANDofFEAR:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OPIT:	
		lprcat("\n\nYou're standing at the top of a pit."); 
		opit(); 
		break;

	case OSTAIRSUP:	
		lprcat("\n\nThere is a circular staircase here."); 
		ostairs(1);  /* up */
		break;

	case OELEVATORUP:
		lprcat("\n\nYou have found an express elevator going up.");
		oelevator(1);  /*  up  */
		break;

	case OELEVATORDOWN:	
		lprcat("\n\nYou have found an express elevator going down.");
		oelevator(-1);	/*	down	*/
		break;

	case OFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a fountain here."); 
		ofountain(); 
		break;

	case OSTATUE:	
		if (nearbymonst()) return;
		lprcat("\n\nYou stand before a statue."); 
		ostatue(); 
		break;

	case OCHEST:	
		lprcat("\n\nThere is a chest here.");  
		ochest();  
		break;

	case OIVTELETRAP:	
		if (rnd(11)<6) return;
		item[playerx][playery] = OTELEPORTER;
		know[playerx][playery] = 1;

	case OTELEPORTER:
		lprcat("\nZaaaappp!  You've been teleported!\n");
		beep(); 
		nap(3000); 
		oteleport(0);
		break; 

	case OSCHOOL:	
		if (nearbymonst()) return;
		lprcat("\n\nYou have found the College of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g') { 
			oschool();  /*	the college of larn	*/
		}
		else	lprcat(" stay here.");
		break;

	case OMIRROR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a mirror here.");
		omirror();	
		break;

	case OBANK2:
	case OBANK:	
		if (nearbymonst()) return;
		if (i==OBANK) 
			lprcat("\n\nYou have found the bank of Ularn.");
		else 
		    lprcat("\n\nYou have found a branch office of the bank of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		j=0; 
		while ((j!='g') && (j!='i') && (j!=ESC)) 
			j=getcharacter();
		if (j == 'g') {  
			if (i==OBANK) 
				obank(); 
			else 
			    obank2(); /*  the bank of larn  */

		}
		else   
			lprcat(" stay here.");
		break;

	case ODEADFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a dead fountain here.");
		break;

	case ODNDSTORE:	
		if (nearbymonst()) 
			return;
		lprcat("\n\nThere is a DND store here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			dndstore();  /*  the dnd adventurers store  */
		else  
			lprcat(" stay here.");
		break;

	case OSTAIRSDOWN:
		lprcat("\n\nThere is a circular staircase here.");
		ostairs(-1); /* down */
		break;

	case OOPENDOOR:		
		lprcat("\nThere is an open door here.");
		break;


	case OCLOSEDDOOR:
		if (dropflag)
			return;
		lprintf("\n\nYou find %s",objectname[i]);
		lprcat("\nDo you (o) try to open it"); 
		iopts();
		i=0; 
		while ((i!='o') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			playerx = lastpx;
			playery = lastpy; 
			break; 
		}
		else {
			lprcat("open.");
			if (rnd(11)<7) {
				switch(iarg[playerx][playery]) {
				case 6: 
					c[AGGRAVATE] += rnd(400);	
					break;

				case 7:	
				case 8:
					lprcat("\nYou are jolted by an electric shock!");
					lastnum=274; 
					losehp(rnd(20));  
					bottomline();  
					break;

/* Losing a level is just too harsh... */
/*				case 8:	
					loselevel();  
					break;
*/
				case 9:	
					lprcat("\nYou suddenly feel weaker!");
					if (c[STRENGTH]>3) c[STRENGTH]--;
					bottomline();  
					break;

				default:	
					break;
				}
				playerx = lastpx;  
				playery = lastpy;
			}
			else {
				forget();  
				item[playerx][playery]=OOPENDOOR;
			}
		}
		break;

	case OENTRANCE:	
		lprcat("\nYou have found ");
		lprcat(objectname[OENTRANCE]);
		lprcat("\nDo you (g) go inside"); 
		iopts();
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
		{
			newcavelevel(1); 
			playerx=33; 
			playery=MAXY-2;
			item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1].mon=0;
			draws(0,MAXX,0,MAXY); 
			bot_linex(); 
			return;
		}
		else   ignore();
		break;

	case OVOLDOWN:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLDOWN]);
		lprcat("\nDo you (c) climb down"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
		if (level!=0) { 
			lprcat("\nThe shaft only extends 5 feet downward!"); 
			return; 
		}
		if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275;  
			losehp(30+rnd(20)); 
			bottomhp(); 
		}
		else lprcat("climb down.");
		nap(3000); 
		newcavelevel(DBOTTOM+1); /* down to V1 */
		playerx = rnd(MAXX-2);
		playery = rnd(MAXY-2);
		positionplayer(); 
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OVOLUP:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLUP]);
		lprcat("\nDo you (c) climb up"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
	if (packweight() > 40+5*(c[DEXTERITY]+c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275; 
			losehp(15+rnd(20)); 
			bottomhp(); 
			return; 
		}
		lprcat("climb up.");
		lflush(); 
		nap(3000); 
		newcavelevel(0);
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
			if (item[j][i]==OVOLDOWN) { 
				playerx=j; 
				playery=i; 
				j=MAXX; 
				i=MAXY; 
				positionplayer(); 
			}
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OTRAPARROWIV:	
		if (rnd(17)<13) return;	/* for an arrow trap */
		item[playerx][playery] = OTRAPARROW;
		know[playerx][playery] = 0;
	case OTRAPARROW:	
		lprcat("\nYou are hit by an arrow!");
		beep();	/* for an arrow trap */
		lastnum=259;	
		losehp(rnd(10)+level);
		bottomhp();	
		return;

	case OIVDARTRAP:	
		if (rnd(17)<13) 
			return;		/* for a dart trap */
		item[playerx][playery] = ODARTRAP;
		know[playerx][playery] = 0;
	case ODARTRAP:		
		lprcat("\nYou are hit by a dart!");
		beep();	/* for a dart trap */
		lastnum=260;	
		losehp(rnd(5));
		if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
		bottomline();	
		return;

	case OIVTRAPDOOR:	
		if (rnd(17)<13) 
			return;		/* for a trap door */
		item[playerx][playery] = OTRAPDOOR;
		know[playerx][playery] = 1;
	case OTRAPDOOR:		
		lastnum = 272; /* a trap door */
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OWWAND) {
				lprcat("\nYou escape a trap door.");
				return;
			}
		if ((level==DBOTTOM)||(level==VBOTTOM)) { 
			lprcat("\nYou fall through a trap door leading straight to HELL!");
			beep();
			lflush();
			nap(3000);
			died(271); 
		}
		lprcat("\nYou fall through a trap door!");
		beep();	
		lflush();
		losehp(rnd(5+level));
		nap(2000);
		newcavelevel(level+1);  
		draws(0,MAXX,0,MAXY); 
		bot_linex();
		return;

	case OTRADEPOST:
		if (nearbymonst()) return;
		lprcat("\nYou have found the Ularn trading Post.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')  otradepost();  
		else  lprcat("stay here.");
		return;

	case OHOME:	
		if (nearbymonst()) return;
		lprcat("\nYou have found your way home.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'g')  
			ohome();  
		else  lprcat("stay here.");
		return;
	case OPAD:	
		if (nearbymonst()) return;
		lprcat("\nYou have found Dealer McDope's Hideout!");
		lprcat("\nDo you (c) check it out, or (i) ignore it? ");
		i=0;
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'c')  
			opad();
		else  lprcat("forget it.");
		return;

	case OSPEED:   	
		lprcat("\nYou find some speed.");
		lprcat("\nDo you (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nOhwowmanlikethingstotallyseemtoslowdown!");
			c[HASTESELF] += 200 + c[LEVEL];
			c[HALFDAM] += 300 + rnd(200);
			if ((c[INTELLIGENCE]-=2) < 3)
				c[INTELLIGENCE]=3;
			if ((c[WISDOM]-=2) < 3)
				c[WISDOM]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[STRENGTH]-=2) <3)
				c[STRENGTH]=3;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSPEED,0)==0) forget();
		} 
		else 
		    lprcat("ignore.");
		break;

	case OSHROOMS:	
		lprcat("\nYou find some magic mushrooms.");
		lprcat("\nDo you (e) eat them, (t) take them, or (i) ignore them? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nThings start to get real spacey...");
			c[HASTEMONST] += rnd(75) + 25;
			c[CONFUSE] += 30+rnd(10);
			c[WISDOM]+=2;
			c[CHARISMA]+=2;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSHROOMS,0)==0) forget();
		} 
		else
			lprcat("ignore.");
		break;

	case OACID:	
		lprcat("\nYou find some LSD.");
		lprcat("\nDo you (e) eat it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nYou are now frying your ass off!");
			c[CONFUSE]+=30+rnd(10);
			c[WISDOM]+=2;
			c[INTELLIGENCE]+=2;
			c[AWARENESS]+=1500;
			c[AGGRAVATE]+=1500;
			{ 	
				int j,k;	/* heal monsters */
				for(j=0;j<MAXY;j++)
					for(k=0;k<MAXX;k++)
						if (mitem[k][j].mon)
							hitp[k][j]=monster[mitem[k][j].mon].hitpoints;
			}
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OACID,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OHASH:	
		lprcat("\nYou find some hashish.");
		lprcat("\nDo you (s) smoke it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("smoke!");
			lprcat("\nWOW! You feel stooooooned...");
			c[HASTEMONST]+=rnd(75)+25;
			c[INTELLIGENCE]+=2;
			c[WISDOM]+=2;
			if( (c[CONSTITUTION]-=2) < 3) 
				c[CONSTITUTION]=3;
			if( (c[DEXTERITY]-=2) < 3) 
				c[DEXTERITY]=3;
			c[HALFDAM]+=300+rnd(200);
			c[CLUMSINESS]+=rnd(1800)+200;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OHASH,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OCOKE:	
		lprcat("\nYou find some cocaine.");
		lprcat("\nDo you want to (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nYour nose begins to bleed!");
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			c[CHARISMA]+=3;
			for(i=0;i<6;i++)
				c[i]+=33;
			c[COKED]+=10;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OCOKE,0)==0) forget();
		}
		else lprcat("ignore.");
		break;	

	case OWALL:	
		break;

	case OANNIHILATION:
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OSPHTALISMAN) {
				lprcat("\nThe Talisman of the Sphere protects you from "
					   "annihilation!");
				return;
			}
		/* annihilated by sphere of annihilation */	
		died(283);
		return;

	case OLRS:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is an LRS office here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			olrs();  /*  the larn revenue service */
		else  lprcat(" stay here.");
		break;
	default:	
		finditem(i); 
		break;
	};
}
示例#4
0
static int
test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int j;
    int txt_x = 0, txt_y = 0;
    int base_y;
    int limit;
    cchar_t ch;
    cchar_t text[MAX_COLS];

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((j = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(j)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
	switch (j) {
	case KEY_DOWN:
	case 'j':
	    if (txt_y < getmaxy(txtwin) - 1)
		txt_y++;
	    else
		beep();
	    break;
	case KEY_UP:
	case 'k':
	    if (txt_y > base_y)
		txt_y--;
	    else
		beep();
	    break;
	case KEY_LEFT:
	case 'h':
	    if (txt_x > 0)
		txt_x--;
	    else
		beep();
	    break;
	case KEY_RIGHT:
	case 'l':
	    if (txt_x < getmaxx(txtwin) - 1)
		txt_x++;
	    else
		beep();
	    break;
	case 'w':
	    test_inchs(level + 1, argv, chrwin, strwin);
	    if (txtbox != 0) {
		touchwin(txtbox);
		wnoutrefresh(txtbox);
	    } else {
		touchwin(txtwin);
		wnoutrefresh(txtwin);
	    }
	    break;
	default:
	    beep();
	    break;
	}

	MvWPrintw(chrwin, 0, 0, "char:");
	wclrtoeol(chrwin);

	if (txtwin != stdscr) {
	    wmove(txtwin, txt_y, txt_x);
	    if (win_wch(txtwin, &ch) != ERR) {
		if (wadd_wch(chrwin, &ch) != ERR) {
		    for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
			if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
			    if (wadd_wch(chrwin, &ch) == ERR) {
				break;
			    }
			} else {
			    break;
			}
		    }
		}
	    }
	} else {
	    move(txt_y, txt_x);
	    if (in_wch(&ch) != ERR) {
		if (wadd_wch(chrwin, &ch) != ERR) {
		    for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
			if (mvin_wch(txt_y, j, &ch) != ERR) {
			    if (wadd_wch(chrwin, &ch) == ERR) {
				break;
			    }
			} else {
			    break;
			}
		    }
		}
	    }
	}
	wnoutrefresh(chrwin);

	MvWPrintw(strwin, 0, 0, "text:");
	wclrtobot(strwin);

	limit = getmaxx(strwin) - 5;

	if (txtwin != stdscr) {
	    wmove(txtwin, txt_y, txt_x);
	    if (win_wchstr(txtwin, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 0, 5, text);
	    }

	    wmove(txtwin, txt_y, txt_x);
	    if (win_wchnstr(txtwin, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 1, 5, text);
	    }

	    if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 2, 5, text);
	    }

	    if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 3, 5, text);
	    }
	} else {
	    move(txt_y, txt_x);
	    if (in_wchstr(text) != ERR) {
		(void) mvwadd_wchstr(strwin, 0, 5, text);
	    }

	    move(txt_y, txt_x);
	    if (in_wchnstr(text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 1, 5, text);
	    }

	    if (mvin_wchstr(txt_y, txt_x, text) != ERR) {
		(void) mvwadd_wchstr(strwin, 2, 5, text);
	    }

	    if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) {
		(void) mvwadd_wchstr(strwin, 3, 5, text);
	    }
	}

	wnoutrefresh(strwin);
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}
示例#5
0
文件: client.c 项目: gz818/melted
mvcp_error_code client_add_unit( client demo )
{
	mvcp_error_code error = mvcp_ok;
	mvcp_nodes nodes = mvcp_nodes_init( demo->dv );
	mvcp_units units = mvcp_units_init( demo->dv );

	if ( mvcp_nodes_count( nodes ) != -1 && mvcp_units_count( units ) != -1 )
	{
		char pressed;
		mvcp_node_entry_t node;
		mvcp_unit_entry_t unit;
		int node_index = 0;
		int unit_index = 0;

		printf( "Select a Node\n\n" );

		for ( node_index = 0; node_index < mvcp_nodes_count( nodes ); node_index ++ )
		{
			mvcp_nodes_get( nodes, node_index, &node );
			printf( "%d: %s - %s ", node_index + 1, node.guid, node.name );
			for ( unit_index = 0; unit_index < mvcp_units_count( units ); unit_index ++ )
			{
				mvcp_units_get( units, unit_index, &unit );
				if ( !strcmp( unit.guid, node.guid ) )
					printf( "[U%d] ", unit.unit );
			}
			printf( "\n" );
		}

		printf( "0. Exit\n\n" );

		printf( "Node: " );

		while ( ( pressed = get_keypress( ) ) != '0' )
		{
			node_index = pressed - '1';
			if ( node_index >= 0 && node_index < mvcp_nodes_count( nodes ) )
			{
				int unit;
				printf( "%c\n\n", pressed );
				mvcp_nodes_get( nodes, node_index, &node );
				if ( mvcp_unit_add( demo->dv, node.guid, &unit ) == mvcp_ok )
				{
					printf( "Unit added as U%d\n", unit );
					demo->selected_unit = unit;
				}
				else
				{
					int index = 0;
					mvcp_response response = mvcp_get_last_response( demo->dv );
					printf( "Failed to add unit:\n\n" );
					for( index = 1; index < mvcp_response_count( response ) - 1; index ++ )
						printf( "%s\n", mvcp_response_get_line( response, index ) );
				}
				printf( "\n" );
				wait_for_any_key( NULL );
				break;
			}
			else
			{
				beep( );
			}
		}
	}
	else
	{
		printf( "Invalid response from the server.\n\n" );
		wait_for_any_key( NULL );
	}

	mvcp_nodes_close( nodes );
	mvcp_units_close( units );

	return error;
}
示例#6
0
/* ------------ KEYBOARD Message ------------- */
static void KeyboardMsg(WINDOW wnd, PARAM p1)
{
    MENU *mnu;
	int sel;
    if (mwnd == NULL)    {
        /* ----- search for menu bar shortcut keys ---- */
        int c = tolower((int)p1);
        int a = AltConvert((int)p1);
        int j;
        for (j = 0; j < mctr; j++)    {
            if ((inFocus == wnd && menu[j].sc == c) ||
                    (a && menu[j].sc == a))    {
				SendMessage(wnd, SETFOCUS, TRUE, 0);
                SendMessage(wnd, MB_SELECTION, j, 0);
                return;
            }
        }
    }
    /* -------- search for accelerator keys -------- */
    mnu = ActiveMenu;
    while (mnu->Title != (void *)-1)    {
        struct PopDown *pd = mnu->Selections;
        if (mnu->PrepMenu)
            (*(mnu->PrepMenu))(GetDocFocus(), mnu);
        while (pd->SelectionTitle != NULL)    {
            if (pd->Accelerator == (int) p1)    {
                if (pd->Attrib & INACTIVE)
                    beep();
                else    {
                    if (pd->Attrib & TOGGLE)
                        pd->Attrib ^= CHECKED;
                    SendMessage(GetDocFocus(),
                        SETFOCUS, TRUE, 0);
                    PostMessage(GetParent(wnd),
                        COMMAND, pd->ActionId, 0);
                }
                return;
            }
            pd++;
        }
        mnu++;
    }
    switch ((int)p1)    {
        case F1:
            if (ActiveMenu == NULL || ActiveMenuBar == NULL)
				break;
			sel = ActiveMenuBar->ActiveSelection;
			if (sel == -1)	{
	    		BaseWndProc(MENUBAR, wnd, KEYBOARD, F1, 0);
				return;
			}
			mnu = ActiveMenu+sel;
			if (mwnd == NULL ||
					mnu->Selections[0].SelectionTitle == NULL) {
               	DisplayHelp(wnd,mnu->Title+1);
            	return;
			}
            break;
        case '\r':
            if (mwnd == NULL &&
                    ActiveMenuBar->ActiveSelection != -1)
                SendMessage(wnd, MB_SELECTION,
                    ActiveMenuBar->ActiveSelection, 0);
            break;
        case F10:
            if (wnd != inFocus && mwnd == NULL)    {
                SendMessage(wnd, SETFOCUS, TRUE, 0);
			    if ( ActiveMenuBar->ActiveSelection == -1)
			        ActiveMenuBar->ActiveSelection = 0;
			    SendMessage(wnd, PAINT, 0, 0);
                break;
            }
            /* ------- fall through ------- */
        case ESC:
            if (inFocus == wnd && mwnd == NULL)    {
                ActiveMenuBar->ActiveSelection = -1;
                SendMessage(GetDocFocus(),SETFOCUS,TRUE,0);
                SendMessage(wnd, PAINT, 0, 0);
            }
            break;
        case FWD:
            ActiveMenuBar->ActiveSelection++;
            if (ActiveMenuBar->ActiveSelection == mctr)
                ActiveMenuBar->ActiveSelection = 0;
            if (mwnd != NULL)
                SendMessage(wnd, MB_SELECTION,
                    ActiveMenuBar->ActiveSelection, 0);
            else 
                SendMessage(wnd, PAINT, 0, 0);
            break;
        case BS:
            if (ActiveMenuBar->ActiveSelection == 0 ||
					ActiveMenuBar->ActiveSelection == -1)
                ActiveMenuBar->ActiveSelection = mctr;
            --ActiveMenuBar->ActiveSelection;
            if (mwnd != NULL)
                SendMessage(wnd, MB_SELECTION,
                    ActiveMenuBar->ActiveSelection, 0);
            else 
                SendMessage(wnd, PAINT, 0, 0);
            break;
        default:
            break;
    }
}
示例#7
0
/*
 * Get a line into genbuf after gcursor.
 * Cnt limits the number of input characters
 * accepted and is used for handling the replace
 * single character command.  Aescaped is the location
 * where we stick a termination indicator (whether we
 * ended with an ESCAPE or a newline/return.
 *
 * We do erase-kill type processing here and also
 * are careful about the way we do this so that it is
 * repeatable.  (I.e. so that your kill doesn't happen,
 * when you repeat an insert if it was escaped with \ the
 * first time you did it.  commch is the command character
 * involved, including the prompt for readline.
 */
char *
vgetline(int cnt, char *gcursor, bool *aescaped, int commch)
{
	register int c, ch;
	register char *cp;
	int x, y, iwhite, backsl=0;
	cell *iglobp;
	char cstr[2];
	int (*OO)(int) = Outchar;

	/*
	 * Clear the output state and counters
	 * for autoindent backwards motion (counts of ^D, etc.)
	 * Remember how much white space at beginning of line so
	 * as not to allow backspace over autoindent.
	 */
	*aescaped = 0;
	ogcursor = gcursor;
	flusho();
	CDCNT = 0;
	HADUP = 0;
	HADZERO = 0;
	gobbled = 0;
	iwhite = whitecnt(genbuf);
	iglobp = vglobp;

	/*
	 * Carefully avoid using vinschar in the echo area.
	 */
	if (splitw)
		Outchar = vputchar;
	else {
		Outchar = vinschar;
		vprepins();
	}
	for (;;) {
		backsl = 0;
		if (gobblebl)
			gobblebl--;
		if (cnt != 0) {
			cnt--;
			if (cnt == 0)
				goto vadone;
		}
		c = getkey();
		if (c != ATTN)
			c &= (QUOTE|TRIM);
		ch = c;
		maphopcnt = 0;
		if (vglobp == 0 && Peekkey == 0 && commch != 'r')
			while ((ch = map(c, immacs)) != c) {
				c = ch;
				if (!value(REMAP))
					break;
				if (++maphopcnt > 256)
					error(catgets(catd, 1, 234,
						"Infinite macro loop"));
			}
		if (!iglobp) {

			/*
			 * Erase-kill type processing.
			 * Only happens if we were not reading
			 * from untyped input when we started.
			 * Map users erase to ^H, kill to -1 for switch.
			 */
			if (c == tty.c_cc[VERASE])
				c = CTRL('h');
			else if (c == tty.c_cc[VKILL])
				c = -1;
			if (c == ATTN)
				goto case_ATTN;
			switch (c) {

			/*
			 * ^?		Interrupt drops you back to visual
			 *		command mode with an unread interrupt
			 *		still in the input buffer.
			 *
			 * ^\		Quit does the same as interrupt.
			 *		If you are a ex command rather than
			 *		a vi command this will drop you
			 *		back to command mode for sure.
			 */
			case QUIT:
case_ATTN:
				ungetkey(c);
				goto vadone;

			/*
			 * ^H		Backs up a character in the input.
			 *
			 * BUG:		Can't back around line boundaries.
			 *		This is hard because stuff has
			 *		already been saved for repeat.
			 */
			case CTRL('h'):
bakchar:
				cp = gcursor + skipleft(ogcursor, gcursor);
				if (cp < ogcursor) {
					if (splitw) {
						/*
						 * Backspacing over readecho
						 * prompt. Pretend delete but
						 * don't beep.
						 */
						ungetkey(c);
						goto vadone;
					}
					beep();
					continue;
				}
				goto vbackup;

			/*
			 * ^W		Back up a white/non-white word.
			 */
			case CTRL('w'):
				wdkind = 1;
				for (cp = gcursor; cp > ogcursor
						&& isspace(cp[-1]&0377); cp--)
					continue;
				for (c = wordch(cp - 1);
				    cp > ogcursor && wordof(c, cp - 1); cp--)
					continue;
				goto vbackup;

			/*
			 * users kill	Kill input on this line, back to
			 *		the autoindent.
			 */
			case -1:
				cp = ogcursor;
vbackup:
				if (cp == gcursor) {
					beep();
					continue;
				}
				endim();
				*cp = 0;
				c = cindent();
				vgotoCL(qcolumn(cursor +
					skipleft(linebuf, cursor), genbuf));
				if (doomed >= 0)
					doomed += c - cindent();
				gcursor = cp;
				continue;

			/*
			 * \		Followed by erase or kill
			 *		maps to just the erase or kill.
			 */
			case '\\':
				x = destcol, y = destline;
				putchar('\\');
				vcsync();
				c = getkey();
				if (c == tty.c_cc[VERASE]
				    || c == tty.c_cc[VKILL])
				{
					vgoto(y, x);
					if (doomed >= 0)
						doomed++;
					goto def;
				}
				ungetkey(c), c = '\\';
				backsl = 1;
				break;

			/*
			 * ^Q		Super quote following character
			 *		Only ^@ is verboten (trapped at
			 *		a lower level) and \n forces a line
			 *		split so doesn't really go in.
			 *
			 * ^V		Synonym for ^Q
			 */
			case CTRL('q'):
			case CTRL('v'):
				x = destcol, y = destline;
				putchar('^');
				vgoto(y, x);
				c = getkey();
				if (c != NL) {
					if (doomed >= 0)
						doomed++;
					goto def;
				}
				break;
			}
		}

		/*
		 * If we get a blank not in the echo area
		 * consider splitting the window in the wrapmargin.
		 */
		if (c != NL && !splitw) {
			if (c == ' ' && gobblebl) {
				gobbled = 1;
				continue;
			}
			if (value(WRAPMARGIN) &&
				(outcol >= OCOLUMNS - value(WRAPMARGIN) ||
				 (backsl && outcol == 0)) &&
				commch != 'r') {
				/*
				 * At end of word and hit wrapmargin.
				 * Move the word to next line and keep going.
				 */
				wdkind = 1;
				gappend(c);
				if (backsl)
					gappend(getkey());
				*gcursor = 0;
				/*
				 * Find end of previous word if we are past it.
				 */
				for (cp=gcursor; cp>ogcursor
						&& isspace(cp[-1]&0377); cp--)
					;
				if (outcol+(backsl?OCOLUMNS:0) - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) {
					/*
					 * Find beginning of previous word.
					 */
					for (; cp>ogcursor && !isspace(cp[-1]&0377); cp--)
						;
					if (cp <= ogcursor) {
						/*
						 * There is a single word that
						 * is too long to fit.  Just
						 * let it pass, but beep for
						 * each new letter to warn
						 * the luser.
						 */
						c = *--gcursor;
						*gcursor = 0;
						beep();
						goto dontbreak;
					}
					/*
					 * Save it for next line.
					 */
					macpush(cp, 0);
					cp--;
				}
				macpush("\n", 0);
				/*
				 * Erase white space before the word.
				 */
				while (cp > ogcursor && isspace(cp[-1]&0377))
					cp--;	/* skip blank */
				gobblebl = 3;
				goto vbackup;
			}
		dontbreak:;
		}

		/*
		 * Word abbreviation mode.
		 */
		cstr[0] = c;
		if (anyabbrs && gcursor > ogcursor && !wordch(cstr) && wordch(gcursor-1)) {
				int wdtype, abno;

				cstr[1] = 0;
				wdkind = 1;
				cp = gcursor + skipleft(ogcursor, gcursor);
				for (wdtype = wordch(cp - 1);
				    cp > ogcursor && wordof(wdtype, cp - 1); cp--)
					;
				*gcursor = 0;
				for (abno=0; abbrevs[abno].mapto; abno++) {
					if (!abbrevs[abno].hadthis &&
						eq(cp, abbrevs[abno].cap)) {
						abbrevs[abno].hadthis++;
						macpush(cstr, 0);
						macpush(abbrevs[abno].mapto, 0);
						goto vbackup;
					}
				}
		}

#ifdef	BIT8
		if (c == OVERBUF)
			goto btrp;
#endif
		switch (c) {

		/*
		 * ^M		Except in repeat maps to \n.
		 */
		case CR:
			if (vglobp)
				goto def;
			c = '\n';
			/* presto chango ... */

		/*
		 * \n		Start new line.
		 */
		case NL:
			*aescaped = c;
			goto vadone;

		/*
		 * escape	End insert unless repeat and more to repeat.
		 */
		case ESCAPE:
			if (lastvgk)
				goto def;
			goto vadone;

		/*
		 * ^D		Backtab.
		 * ^T		Software forward tab.
		 *
		 *		Unless in repeat where this means these
		 *		were superquoted in.
		 */
		case CTRL('d'):
		case CTRL('t'):
			if (vglobp)
				goto def;
			/* fall into ... */

		/*
		 * ^D|QUOTE	Is a backtab (in a repeated command).
		 */
#ifndef	BIT8
		case CTRL('d') | QUOTE:
#else
btrp:
#endif
			*gcursor = 0;
			cp = vpastwh(genbuf);
			c = whitecnt(genbuf);
			if (ch == CTRL('t')) {
				/*
				 * ^t just generates new indent replacing
				 * current white space rounded up to soft
				 * tab stop increment.
				 */
				if (cp != gcursor)
					/*
					 * BUG:		Don't hack ^T except
					 *		right after initial
					 *		white space.
					 */
					continue;
				cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1));
				ogcursor = cp;
				goto vbackup;
			}
			/*
			 * ^D works only if we are at the (end of) the
			 * generated autoindent.  We count the ^D for repeat
			 * purposes.
			 */
			if (c == iwhite && c != 0) {
				if (cp == gcursor) {
					iwhite = backtab(c);
					CDCNT++;
					ogcursor = cp = genindent(iwhite);
					goto vbackup;
				} else if (&cp[1] == gcursor &&
				    (*cp == '^' || *cp == '0')) {
					/*
					 * ^^D moves to margin, then back
					 * to current indent on next line.
					 *
					 * 0^D moves to margin and then
					 * stays there.
					 */
					HADZERO = *cp == '0';
					ogcursor = cp = genbuf;
					HADUP = 1 - HADZERO;
					CDCNT = 1;
					endim();
					back1();
					vputchar(' ');
					goto vbackup;
				}
			}
			if (vglobp && vglobp - iglobp >= 2 &&
			    (vglobp[-2] == '^' || vglobp[-2] == '0')
			    && gcursor == ogcursor + 1)
				goto bakchar;
			continue;

		default:
			/*
			 * Possibly discard control inputs.
			 */
			if (!vglobp && junk(c)) {
				beep();
				continue;
			}
def:
			if (!backsl) {
				/* int cnt; */
				putchar(c);
				flush();
			}
			if (gcursor > &genbuf[LBSIZE - 2])
				error(catgets(catd, 1, 235, "Line too long"));
			gappend(c & TRIM);
			vcsync();
			if (value(SHOWMATCH) && !iglobp)
				if (c == ')' || c == '}')
					lsmatch(gcursor);
			continue;
		}
	}
vadone:
	*gcursor = 0;
	if (Outchar != termchar)
		Outchar = OO;
	endim();
	return (gcursor);
}
示例#8
0
//implemetation of functions
int start_finding(int start_x, int start_y)
{
	int inter = 0;
	int token = 0;
	int cur_x = start_x, cur_y = start_y;
	int dir = SOUTH;
	int ppath = -1;
	int npop = 0;	//how many points should be poped
	struct POINT *cur_p = NULL;
	struct POINT *tmp_p = NULL;
	int ret = 0;

	#ifdef DEBUG
	inter = Robot_GetIntersections();
	#else
	inter = get_intersection();
	#endif

	cur_p = mark_point(cur_x, cur_y, inter);
	dir = get_direction(cur_p);

	#ifdef DEBUG
	printf("start point: ");
	print_point(cur_p);
	printf("\n");
	#endif

	while(token < TOKEN_COUNT)
	{
		#ifdef DEBUG
		//inter = Robot_GetIntersections();
		//print_intersection(inter);
		#endif

		if(points[cur_x][cur_y].detected == 0)
			cur_p = mark_point(cur_x, cur_y, inter);
		else
			cur_p = &points[cur_x][cur_y];
		push(cur_p);
		//print_stack();

		if(dir = get_direction(cur_p))
		{
			//update current point
			switch(dir)
			{
				case EAST:
					cur_x += 1;
					break;
				case SOUTH:
					cur_y -= 1;
					break;
				case WEST:
					cur_x -= 1;
					break;
				case NORTH:
					cur_y += 1;
					break;
			}

			#ifdef DEBUG
			print_direction(cur_p, dir);
			ret = aud_move(cur_p, dir);
			#else
			//move one step
			display_clear(0);
			display_goto_xy(0, 0);
			display_int(cur_p->x, 2);
			display_goto_xy(3, 0);
			display_int(cur_p->y, 2);
			display_goto_xy(7, 0);
			display_int(cur_x, 2);
			display_goto_xy(10, 0);
			display_int(cur_y, 2);
			display_goto_xy(0, 1);
			display_int(g_dir, 3);
			display_goto_xy(5, 1);
			display_int(dir, 3);
			display_goto_xy(0, 2);
			display_int(cur_p->inter&0xF0, 3);
			display_update();

			ret = move(cur_x, cur_y);
			#endif

			#ifdef DEBUG
			inter = Robot_GetIntersections();
			#else
			inter = get_intersection();
			#endif

			cur_p = mark_point(cur_x, cur_y, inter);

			#ifdef DEBUG
			print_point(cur_p);
			#endif

			if(ret == ROBOT_SUCCESS)
			{
				#ifndef DEBUG
				#endif
			}
			else if(ret == ROBOT_TOKENFOUND)
			{
				tmp_p = &points[cur_x][cur_y];
				if(tmp_p->has_token == 0)
				{
					tmp_p->has_token = 1;
					token++;
					#ifdef DEBUG
					printf("[%d. token]\n", token);
					#endif
				}
				else
				{
					#ifdef DEBUG
					printf("[not a new token]\n");
					#endif
				}

				if(token == TOKEN_COUNT)
				{
					//all token were found, go back to start point
					#ifdef DEBUG
					printf("going back to start point......\n");
					#endif
					push(cur_p);
					ppath = find_shortest_path(cur_p->x, cur_p->y, START_X, START_Y);
					if(ppath)
					{
						//going back to last open point
						ppath--;

						while(ppath >= 0)
						{
							tmp_p = shortest_path[ppath];
							dir = calc_direction(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y);
							#ifdef DEBUG
							print_point(tmp_p);
							printf("\n");
							ROBOT_MOVE(tmp_p->x, tmp_p->y);
							#else
							display_clear(0);
							display_goto_xy(0, 0);
							display_int(cur_p->x, 2);
							display_goto_xy(3, 0);
							display_int(cur_p->y, 2);
							display_goto_xy(7, 0);
							display_int(tmp_p->x, 2);
							display_goto_xy(10, 0);
							display_int(tmp_p->y, 2);
							display_goto_xy(0, 1);
							display_int(g_dir, 3);
							display_goto_xy(5, 1);
							display_int(dir, 3);
							display_goto_xy(0, 2);
							display_int(cur_p->inter&0xF0, 3);
							display_update();

							move(tmp_p->x, tmp_p->y);
							#endif
							cur_p = tmp_p;
							ppath--;
						}

						//delete the path in stack
						pop(npop + 1);
						cur_p = tmp_p;
						cur_x = cur_p->x;
						cur_y = cur_p->y;
					}
					#ifdef DEBUG
					printf("task finished!\n");
					#else
					beep();
					#endif

					break;
				}
			}
			else
			{
				#ifdef DEBUG
				printf("move failed!\n");
				#endif
			}
		}
		else
		{
			//there is no ways forward, go back to nearest open point
			tmp_p = get_last_open_point();
			npop = stack_pointer - get_stack_index(tmp_p->x, tmp_p->y);
			#ifdef DEBUG
			printf("going back to (%d, %d)\n", tmp_p->x, tmp_p->y);
			#endif

			if(tmp_p)
			{
				if((tmp_p->x == START_X) && (tmp_p->y == START_Y) && !IS_OPEN_POINT(points[tmp_p->x][tmp_p->y]))
				{
					#ifdef DEBUG
					return 0;
					#else
					stop_robot();
					beep();
					return 0;
					#endif
				}
				ppath = find_shortest_path(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y);

				if(ppath)
				{
					//going back to last open point
					ppath--;

					while(ppath >= 0)
					{
						tmp_p = shortest_path[ppath];
						dir = calc_direction(cur_p->x, cur_p->y, tmp_p->x, tmp_p->y);
						#ifdef DEBUG
						ROBOT_MOVE(tmp_p->x, tmp_p->y);
						#else
						display_clear(0);
						display_goto_xy(0, 0);
						display_int(cur_p->x, 2);
						display_goto_xy(3, 0);
						display_int(cur_p->y, 2);
						display_goto_xy(7, 0);
						display_int(tmp_p->x, 2);
						display_goto_xy(10, 0);
						display_int(tmp_p->y, 2);
						display_goto_xy(0, 1);
						display_int(g_dir, 3);
						display_goto_xy(5, 1);
						display_int(dir, 3);
						display_goto_xy(0, 2);
						display_int(cur_p->inter&0xF0, 3);
						display_update();

						move(tmp_p->x, tmp_p->y);
						#endif
						cur_p = tmp_p;
						ppath--;
					}

					//delete the path in stack
					pop(npop + 1);
					cur_p = tmp_p;
					cur_x = cur_p->x;
					cur_y = cur_p->y;
				}
				else
				{
					//was already at every point and back to start point
					//task should be ended
					//that means, not enough token can be found
					#ifdef DEBUG
					printf("task ended without enough token were found.\n");
					#endif
					break;
				}
			}
		}
		#ifdef DEBUG
		printf("\n");
		#endif
	}

	return 0;
}
示例#9
0
文件: edit.c 项目: kindy/vim0
void
edit()
{
        int c;
        char *p, *q;

        Prenum = 0;

        /* position the display and the cursor at the top of the file. */
        *Topchar = *Filemem;
        *Curschar = *Filemem;
        Cursrow = Curscol = 0;

        for ( ;; ) {

        /* Figure out where the cursor is based on Curschar. */
        cursupdate();

        windgoto(Cursrow,Curscol);

        c = vgetc();

        if (State == NORMAL) {

                /* We're in the normal (non-insert) mode. */

                /* Pick up any leading digits and compute 'Prenum' */
                if ( (Prenum>0 && isdigit(c)) || (isdigit(c) && c!='0') ){
                        Prenum = Prenum*10 + (c-'0');
                        continue;
                }
                /* execute the command */
                normal(c);
                Prenum = 0;

        } else {

                switch (c) {        /* We're in insert mode */

                case ESC:        /* an escape ends input mode */

                        set_want_col = TRUE;

                        /* Don't end up on a '\n' if you can help it. */
                        if (gchar(Curschar) == NUL && Curschar->index != 0)
                                dec(Curschar);

                        /*
                         * The cursor should end up on the last inserted
                         * character. This is an attempt to match the real
                         * 'vi', but it may not be quite right yet.
                         */
                        if (Curschar->index != 0 && !endofline(Curschar))
                                dec(Curschar);

                        State = NORMAL;
                        msg("");
                        *Uncurschar = *Insstart;
                        Undelchars = Ninsert;
                        /* Undobuff[0] = '\0'; */
                        /* construct the Redo buffer */
                        p=Redobuff;
                        q=Insbuff;
                        while ( q < Insptr )
                                *p++ = *q++;
                        *p++ = ESC;
                        *p = NUL;
                        updatescreen();
                        break;

                case CTRL('D'):
                        /*
                         * Control-D is treated as a backspace in insert
                         * mode to make auto-indent easier. This isn't
                         * completely compatible with vi, but it's a lot
                         * easier than doing it exactly right, and the
                         * difference isn't very noticeable.
                         */
                case BS:
                        /* can't backup past starting point */
                        if (Curschar->linep == Insstart->linep &&
                            Curschar->index <= Insstart->index) {
                                beep();
                                break;
                        }

                        /* can't backup to a previous line */
                        if (Curschar->linep != Insstart->linep &&
                            Curschar->index <= 0) {
                                beep();
                                break;
                        }

                        did_ai = FALSE;
                        dec(Curschar);
                        delchar(TRUE);
                        Insptr--;
                        Ninsert--;
                        cursupdate();
                        updateline();
                        break;

                case CR:
                case NL:
                        *Insptr++ = NL;
                        Ninsert++;
                        opencmd(FORWARD, TRUE);                /* open a new line */
                        cursupdate();
                        updatescreen();
                        break;

                default:
                        did_ai = FALSE;
                        insertchar(c);
                        break;
                }
        }
        }
}
示例#10
0
void errormsg(char *msg)
{
    beep();
    mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3));
    wrefresh(wstat);
}
示例#11
0
static void
pounce_cb(PurplePounce *pounce, PurplePounceEvent events, void *data)
{
	PurpleConversation *conv;
	PurpleAccount *account;
	PurpleBuddy *buddy;
	const char *pouncee;
	const char *alias;

	pouncee = purple_pounce_get_pouncee(pounce);
	account = purple_pounce_get_pouncer(pounce);

	buddy = purple_find_buddy(account, pouncee);
	if (buddy != NULL)
	{
		alias = purple_buddy_get_alias(buddy);
		if (alias == NULL)
			alias = pouncee;
	}
	else
		alias = pouncee;

	if (purple_pounce_action_is_enabled(pounce, "open-window"))
	{
		if (!purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account))
			purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee);
	}

	if (purple_pounce_action_is_enabled(pounce, "popup-notify"))
	{
		char *tmp = NULL;
		const char *name_shown;
		const char *reason;
		struct {
			PurplePounceEvent event;
			const char *format;
		} messages[] = {
			{PURPLE_POUNCE_TYPING, _("%s has started typing to you (%s)")},
			{PURPLE_POUNCE_TYPED, _("%s has paused while typing to you (%s)")},
			{PURPLE_POUNCE_SIGNON, _("%s has signed on (%s)")},
			{PURPLE_POUNCE_IDLE_RETURN, _("%s has returned from being idle (%s)")},
			{PURPLE_POUNCE_AWAY_RETURN, _("%s has returned from being away (%s)")},
			{PURPLE_POUNCE_TYPING_STOPPED, _("%s has stopped typing to you (%s)")},
			{PURPLE_POUNCE_SIGNOFF, _("%s has signed off (%s)")},
			{PURPLE_POUNCE_IDLE, _("%s has become idle (%s)")},
			{PURPLE_POUNCE_AWAY, _("%s has gone away. (%s)")},
			{PURPLE_POUNCE_MESSAGE_RECEIVED, _("%s has sent you a message. (%s)")},
			{0, NULL}
		};
		int i;
		reason = purple_pounce_action_get_attribute(pounce, "popup-notify",
				"reason");

		/*
		 * Here we place the protocol name in the pounce dialog to lessen
		 * confusion about what protocol a pounce is for.
		 */
		for (i = 0; messages[i].format != NULL; i++) {
			if (messages[i].event & events) {
				tmp = g_strdup_printf(messages[i].format, alias,
						purple_account_get_protocol_name(account));
				break;
			}
		}
		if (tmp == NULL)
			tmp = g_strdup(_("Unknown pounce event. Please report this!"));

		/*
		 * Ok here is where I change the second argument, title, from
		 * NULL to the account alias if we have it or the account
		 * name if that's all we have
		 */
		if ((name_shown = purple_account_get_alias(account)) == NULL)
			name_shown = purple_account_get_username(account);

		if (reason == NULL)
		{
			purple_notify_info(NULL, name_shown, tmp, purple_date_format_full(NULL));
		}
		else
		{
			char *tmp2 = g_strdup_printf("%s\n\n%s", reason, purple_date_format_full(NULL));
			purple_notify_info(NULL, name_shown, tmp, tmp2);
			g_free(tmp2);
		}
		g_free(tmp);
	}

	if (purple_pounce_action_is_enabled(pounce, "send-message"))
	{
		const char *message;

		message = purple_pounce_action_get_attribute(pounce, "send-message",
												   "message");

		if (message != NULL)
		{
			conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, pouncee, account);

			if (conv == NULL)
				conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, pouncee);

			purple_conversation_write(conv, NULL, message,
									PURPLE_MESSAGE_SEND, time(NULL));

			serv_send_im(purple_account_get_connection(account), (char *)pouncee, (char *)message, 0);
		}
	}

	if (purple_pounce_action_is_enabled(pounce, "execute-command"))
	{
		const char *command;

		command = purple_pounce_action_get_attribute(pounce,
				"execute-command", "command");

		if (command != NULL)
		{
			char *localecmd = g_locale_from_utf8(command, -1, NULL,
					NULL, NULL);

			if (localecmd != NULL)
			{
				int pid = fork();

				if (pid == 0) {
					char *args[4];

					args[0] = "sh";
					args[1] = "-c";
					args[2] = (char *)localecmd;
					args[3] = NULL;

					execvp(args[0], args);

					_exit(0);
				}
				g_free(localecmd);
			}
		}
	}

	if (purple_pounce_action_is_enabled(pounce, "play-beep"))
	{
		beep();
	}
}
示例#12
0
static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
{
    PromptBuf *prt = self->promptbuf;

    int x, y, y2, x2;
    getyx(self->window, y, x);
    getmaxyx(self->window, y2, x2);

    /* BACKSPACE key: Remove one character from line */
    if (key == 0x107 || key == 0x8 || key == 0x7f) {
        if (prt->pos > 0) {
            del_char_buf_bck(prt->line, &prt->pos, &prt->len);
            wmove(self->window, y, x-1);    /* not necessary but fixes a display glitch */
            prt->scroll = false;
        } else {
            beep();
        }
    }

    else if (key == KEY_DC) {      /* DEL key: Remove character at pos */
        if (prt->pos != prt->len) {
            del_char_buf_frnt(prt->line, &prt->pos, &prt->len);
            prt->scroll = false;
        } else {
            beep();
        }
    }

    else if (key == T_KEY_DISCARD) {    /* CTRL-U: Delete entire line behind pos */
        if (prt->pos > 0) {
            wmove(self->window, prt->orig_y, X_OFST);
            wclrtobot(self->window);
            discard_buf(prt->line, &prt->pos, &prt->len);
        } else {
            beep();
        }
    }

    else if (key == T_KEY_KILL) {    /* CTRL-K: Delete entire line in front of pos */
        if (prt->len != prt->pos)
            kill_buf(prt->line, &prt->pos, &prt->len);
        else
            beep();
    }

    else if (key == KEY_HOME || key == T_KEY_C_A) {  /* HOME/C-a key: Move cursor to start of line */
        if (prt->pos != 0)
            prt->pos = 0;
    }

    else if (key == KEY_END || key == T_KEY_C_E) {   /* END/C-e key: move cursor to end of line */
        if (prt->pos != prt->len)
            prt->pos = prt->len;
    }

    else if (key == KEY_LEFT) {
        if (prt->pos > 0)
            --prt->pos;
        else
            beep();
    } 

    else if (key == KEY_RIGHT) {
        if (prt->pos < prt->len)
            ++prt->pos;
        else 
            beep();
    } 

    else if (key == KEY_UP) {     /* fetches previous item in history */
        wmove(self->window, prt->orig_y, X_OFST);
        fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
                        &prt->hst_pos, LN_HIST_MV_UP);

        /* adjust line y origin appropriately when window scrolls down */
        if (prt->at_bottom && prt->len >= x2 - X_OFST) {
            int px2 = prt->len >= x2 ? x2 : x2 - X_OFST;
            int p_ofst = px2 != x2 ? 0 : X_OFST;

            if (px2 <= 0)
                return;

            int k = prt->orig_y + ((prt->len + p_ofst) / px2);

            if (k >= y2) {
                wprintw(self->window, "\n");
                --prt->orig_y;
            }
        }
    }

    else if (key == KEY_DOWN) {    /* fetches next item in history */
        wmove(self->window, prt->orig_y, X_OFST);
        fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
                        &prt->hst_pos, LN_HIST_MV_DWN);
    }

    else if (key == '\t') {    /* TAB key: completes command */
        if (prt->len > 1 && prt->line[0] == '/') {
            if (complete_line(prt->line, &prt->pos, &prt->len, glob_cmd_list, AC_NUM_GLOB_COMMANDS,
                              MAX_CMDNAME_SIZE) == -1) 
                beep();
        } else {
            beep();
        }
    }

    else
#if HAVE_WIDECHAR
    if (iswprint(key))
#else
    if (isprint(key))
#endif
    {
        if (prt->len < (MAX_STR_SIZE-1)) {
            add_char_to_buf(prt->line, &prt->pos, &prt->len, key);
            prt->scroll = true;
        }
    }
    /* RETURN key: execute command */
    else if (key == '\n') {
        wprintw(self->window, "\n");
        uint8_t line[MAX_STR_SIZE];

        if (wcs_to_mbs_buf(line, prt->line, MAX_STR_SIZE) == -1)
            memset(&line, 0, sizeof(line));

        if (!string_is_empty(line))
            add_line_to_hist(prt->line, prt->len, prt->ln_history, &prt->hst_tot, &prt->hst_pos);

        execute(self->window, self, m, line, GLOBAL_COMMAND_MODE);
        reset_buf(prt->line, &prt->pos, &prt->len);
    }
}
示例#13
0
static void
update_status(WINDOW *win, STATUS * sp)
{
    switch (sp->ch) {
    case ' ':			/* next test-iteration */
	if (has_colors()) {
	    if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
		sp->c_msg = color_params(sp->c = 0, &(sp->pair));
		if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
		    sp->v_msg = video_params(sp->v = 0, &(sp->attr));
		}
	    }
	} else {
	    if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
		sp->v_msg = video_params(sp->v = 0, &(sp->attr));
	    }
	}
	sp->count = 0;
	show_status(win, sp);
	break;
    case KEY_LEFT:
    case 'h':
	if (sp->x_val > 0)
	    wmove(win, sp->y_val, --(sp->x_val));
	break;
    case KEY_DOWN:
    case 'j':
	if (sp->y_val < sp->y_max)
	    wmove(win, ++(sp->y_val), sp->x_val);
	break;
    case KEY_UP:
    case 'k':
	if (sp->y_val > 0)
	    wmove(win, --(sp->y_val), sp->x_val);
	break;
    case KEY_RIGHT:
    case 'l':
	if (sp->x_val < sp->x_max)
	    wmove(win, sp->y_val, ++(sp->x_val));
	break;
    case 't':
	touchline(win, sp->y_val, 1);
	break;
    case '=':
	sp->count = 0;
	show_status(win, sp);
	break;
    case '-':
	sp->count = -(sp->count);
	show_status(win, sp);
	break;
    case '?':
	do_subwindow(win, sp, show_help);
	break;
    default:
	if (isdigit(sp->ch)) {
	    sp->count = (sp->count * 10) + (sp->ch - '0');
	    show_status(win, sp);
	} else {
	    beep();
	}
	break;
    }
}
示例#14
0
文件: commands.c 项目: sahne/vitunes
int
user_getstr(const char *prompt, char **response)
{
   const int MAX_INPUT_SIZE = 1000; /* TODO remove this limit */
   char *input;
   int  pos, ch, ret;

   /* display the prompt */
   werase(ui.command);
   mvwprintw(ui.command, 0, 0, "%s", prompt);

   /* position the cursor */
   curs_set(1);
   wmove(ui.command, 0, strlen(prompt));
   wrefresh(ui.command);

   /* allocate input space and clear */
   if ((input = calloc(MAX_INPUT_SIZE, sizeof(char))) == NULL)
      err(1, "user_getstr: calloc(3) failed for input string");

   bzero(input, MAX_INPUT_SIZE);

   /* start getting input */
   ret = 0;
   pos = 0;
   while ((ch = getch()) && !VSIG_QUIT) {

      /*
       * Handle any signals.  Note that the use of curs_set, wmvoe, and
       * wrefresh here are all necessary to ensure that the cursor does
       * not show anywhere outside of the command window.
       */
      curs_set(0);
      process_signals();
      curs_set(1);
      wmove(ui.command, 0, strlen(prompt) + pos);
      wrefresh(ui.command);

      if (ch == ERR)
         continue;

      if (ch == '\n' || ch == 13)
         break;

      /* handle 'escape' */
      if (ch == 27) {
         ret = 1;
         goto end;
      }

      /* handle 'backspace' / left-arrow, etc. */
      if (ch == 127    || ch == KEY_BACKSPACE || ch == KEY_LEFT
       || ch == KEY_DC || ch == KEY_SDC) {
         if (pos == 0) {
            if (ch == KEY_BACKSPACE) {
               ret = 1;
               goto end;
            }
            beep();
         } else {
            mvwaddch(ui.command, 0, strlen(prompt) + pos - 1, ' ');
            wmove(ui.command, 0, strlen(prompt) + pos - 1);
            wrefresh(ui.command);
            pos--;
         }
         continue;
      }

      /* got regular input.  add to buffer. */
      input[pos] = ch;
      mvwaddch(ui.command, 0, strlen(prompt) + pos, ch);
      wrefresh(ui.command);
      pos++;

      /* see todo above - realloc input buffer here if position reaches max */
      if (pos >= MAX_INPUT_SIZE)
         errx(1, "user_getstr: shamefull limit reached");
   }

   /* For lack of input, bail out */
   if (pos == 0) {
      ret = 1;
      goto end;
   }

   /* NULL-terminate and trim off trailing whitespace */
   input[pos--] = '\0';
   for (; input[pos] == ' ' && pos >= 0; pos--)
      input[pos] = '\0';

   /* trim the fat */
   if ((*response = calloc(strlen(input) + 1, sizeof(char))) == NULL)
      err(1, "user_getstr: calloc(3) failed for result");

   snprintf(*response, strlen(input) + 1, "%s", input);

end:
   free(input);
   curs_set(0);
   return ret;
}
示例#15
0
/*
 * quit:
 *	Handle the end of the game when the player dies
 */
int
quit(int old_status)
{
	bool explain;
	int ch;

	if (Last_player)
		return Q_QUIT;
#ifdef OTTO
	if (Otto_mode)
		return Q_CLOAK;
#endif
	move(HEIGHT, 0);
	addstr("Re-enter game [ynwo]? ");
	clrtoeol();
	explain = false;
	for (;;) {
		refresh();
		if (isupper(ch = getchar()))
			ch = tolower(ch);
		if (ch == 'y')
			return old_status;
		else if (ch == 'o')
			break;
		else if (ch == 'n') {
#ifndef INTERNET
			return Q_QUIT;
#else
			move(HEIGHT, 0);
			addstr("Write a parting message [yn]? ");
			clrtoeol();
			refresh();
			for (;;) {
				if (isupper(ch = getchar()))
					ch = tolower(ch);
				if (ch == 'y')
					goto get_message;
				if (ch == 'n')
					return Q_QUIT;
			}
#endif
		}
#ifdef INTERNET
		else if (ch == 'w') {
			static char buf[WIDTH + WIDTH % 2];
			char *cp, c;

get_message:
			c = ch;		/* save how we got here */
			move(HEIGHT, 0);
			addstr("Message: ");
			clrtoeol();
			refresh();
			cp = buf;
			for (;;) {
				refresh();
				if ((ch = getchar()) == '\n' || ch == '\r')
					break;
				if (ch == erasechar()) {
					if (cp > buf) {
						int y, x;
						getyx(stdscr, y, x);
						move(y, x - 1);
						cp -= 1;
						clrtoeol();
					}
					continue;
				}
				else if (ch == killchar()) {
					int y, x;
					getyx(stdscr, y, x);
					move(y, x - (cp - buf));
					cp = buf;
					clrtoeol();
					continue;
				} else if (!isprint(ch)) {
					beep();
					continue;
				}
				addch(ch);
				*cp++ = ch;
				if (cp + 1 >= buf + sizeof buf)
					break;
			}
			*cp = '\0';
			Send_message = buf;
			return (c == 'w') ? old_status : Q_MESSAGE;
		}
#endif
		beep();
		if (!explain) {
			addstr("(Yes, No, Write message, or Options) ");
			explain = true;
		}
	}

	move(HEIGHT, 0);
#ifdef FLY
	addstr("Scan, Cloak, Flying, or Quit? ");
#else
	addstr("Scan, Cloak, or Quit? ");
#endif
	clrtoeol();
	refresh();
	explain = false;
	for (;;) {
		if (isupper(ch = getchar()))
			ch = tolower(ch);
		if (ch == 's')
			return Q_SCAN;
		else if (ch == 'c')
			return Q_CLOAK;
#ifdef FLY
		else if (ch == 'f')
			return Q_FLY;
#endif
		else if (ch == 'q')
			return Q_QUIT;
		beep();
		if (!explain) {
#ifdef FLY
			addstr("[SCFQ] ");
#else
			addstr("[SCQ] ");
#endif
			explain = true;
		}
		refresh();
	}
}
示例#16
0
int
gen_setup()
{
	extern char *v_yes[];
	WINDOW *g_win, *newwin();
	int i, num, ret_code;
	char c, *ans, *str_prompt(), *menu_prompt(), chr_prompt();
	char *str_rep();
	void line_set();
	static char *v_abort[3] = {"KEEP", "DELETE", NULL};

	g_win = newwin(23, 80, 0, 0);

	horizontal(g_win, 0, 0, 32);
	mvwattrstr(g_win, 0, 33, A_BOLD, "General Setup");
	horizontal(g_win, 0, 47, 32);
	mvwprintw(g_win, 3, 22, "1) Default log file ....... %s", param->logfile);
	mvwprintw(g_win, 4, 22, "2) Screen dump file ....... %s", param->dumpfile);
	mvwprintw(g_win, 6, 22, "3) Strip high bit  ........ %s", param->strip);
	mvwprintw(g_win, 8, 22, "4) Pause character ........ %c", param->pause_char);
	mvwprintw(g_win, 9, 22, "5) CR character ........... %c", param->cr_char);
	mvwprintw(g_win, 10, 22, "6) CTRL character ......... %c", param->ctrl_char);
	mvwprintw(g_win, 11, 22, "7) ESC character .......... %c", param->esc_char);
	mvwprintw(g_win, 12, 22, "8) Break character ........ %c", param->brk_char);
	mvwprintw(g_win, 14, 22, "9) Aborted downloads ...... %s", param->abort);
	mvwprintw(g_win, 16, 21, "10) Connect delay (sec) .... %d", param->c_delay);
	mvwprintw(g_win, 17, 21, "11) Redial delay (sec) ..... %d", param->r_delay);
	horizontal(g_win, 19, 0, 80);
	mvwattrstr(g_win, 20, 0, A_BOLD, "OPTION ==> ");
	mvwaddstr(g_win, 20, 58, "Press <ESC> to return");
	wmove(g_win, 20, 12);
	touchwin(g_win);
	wrefresh(g_win);
					/* get the option number */
	ret_code = 0;
	while ((i = get_num(g_win, 2)) != -1) {
		switch (i) {
			case 1:
				if ((ans = str_prompt(g_win, 3, 50, "Default log file", "")) != NULL) {
					param->logfile = str_rep(param->logfile, ans);
					ret_code++;
				}
				break;
			case 2:
				if ((ans = str_prompt(g_win, 4, 50, "Default screen dump file", "")) != NULL) {
					param->dumpfile = str_rep(param->dumpfile, ans);
					ret_code++;
				}
				break;
			case 3:
				if ((ans = menu_prompt(g_win, 6, 50, "Strip high bit?", v_yes)) != NULL) {
					param->strip = str_rep(param->strip, ans);
					line_set();
					ret_code++;
				}
				break;
			case 4:
				if ((c = chr_prompt(g_win, 8, 50, "Pause character", "1 second")) != '\0') {
					param->pause_char = c;
					ret_code++;
				}
				break;
			case 5:
				if ((c = chr_prompt(g_win, 9, 50, "CR character", "(carriage return)")) != '\0') {
					param->cr_char = c;
					ret_code++;
				}
				break;
			case 6:
				if ((c = chr_prompt(g_win, 10, 50, "CTRL character", "(control)")) != '\0') {
					param->ctrl_char = c;
					ret_code++;
				}
				break;
			case 7:
				if ((c = chr_prompt(g_win, 11, 50, "ESC character", "(escape)")) != '\0') {
					param->esc_char = c;
					ret_code++;
				}
				break;
			case 8:
				if ((c = chr_prompt(g_win, 12, 50, "Break character", "")) != '\0') {
					param->brk_char = c;
					ret_code++;
				}
			case 9:
				if ((ans = menu_prompt(g_win, 14, 50, "Aborted downloads", v_abort)) != NULL) {
					param->abort = str_rep(param->abort, ans);
					ret_code++;
				}
				break;
			case 10:
				if ((num = num_prompt(g_win, 16, 50, "Connect delay time", "(in seconds)")) != -1) {
					if (num > MAX_CDELAY || num < MIN_CDELAY) {
						beep();
					/* some reasonable range of values */
						if (num < MIN_CDELAY)
							num = MIN_CDELAY;
						else
							num = MAX_CDELAY;
						mvwaddstr(g_win, 16, 50, "   ");
						wrefresh(g_win);
						mvwattrnum(g_win, 16, 50, A_BOLD, num);
						wrefresh(g_win);
					}
					param->c_delay = num;
					ret_code++;
				}
				break;
			case 11:
				if ((num = num_prompt(g_win, 17, 50, "Redial delay time", "(in seconds)")) != -1) {
					if (num > MAX_PAUSE || num < MIN_PAUSE) {
						beep();
					/* some reasonable range */
						if (num < MIN_PAUSE)
							num = MIN_PAUSE;
						else
							num = MAX_PAUSE;
						mvwaddstr(g_win, 17, 50, "    ");
						wrefresh(g_win);
						mvwattrnum(g_win, 17, 50, A_BOLD, num);
						wrefresh(g_win);
					}
					param->r_delay = num;
					ret_code++;
				}
				break;
			default:
				beep();
		}
		mvwaddstr(g_win, 20, 12, "  ");
		clear_line(g_win, 21, 0, FALSE);
		clear_line(g_win, 22, 0, FALSE);
		wmove(g_win, 20, 12);
		wrefresh(g_win);
	}
	delwin(g_win);
	return(ret_code);
}
示例#17
0
/*
 * playit:
 *	Play a given game, handling all the curses commands from
 *	the driver.
 */
void
playit(void)
{
	int ch;
	int y, x;
	uint32_t version;
	ssize_t result;

	result = read(huntsocket, &version, sizeof(version));
	if (result != (ssize_t)sizeof(version)) {
		bad_con();
		/* NOTREACHED */
	}
	if (ntohl(version) != (uint32_t)HUNT_VERSION) {
		bad_ver();
		/* NOTREACHED */
	}
	errno = 0;
#ifdef OTTO
	Otto_count = 0;
#endif
	nchar_send = MAX_SEND;
	while ((ch = GETCHR()) != EOF) {
#ifdef DEBUG
		fputc(ch, stderr);
#endif
		switch (ch & 0377) {
		  case MOVE:
			y = GETCHR();
			x = GETCHR();
			move(y, x);
			break;
		  case ADDCH:
			ch = GETCHR();
#ifdef OTTO
			switch (ch) {

			case '<':
			case '>':
			case '^':
			case 'v':
				otto_face = ch;
				getyx(stdscr, otto_y, otto_x);
				break;
			}
#endif
			addch(ch);
			break;
		  case CLRTOEOL:
			clrtoeol();
			break;
		  case CLEAR:
			clear_the_screen();
			break;
		  case REFRESH:
			refresh();
			break;
		  case REDRAW:
			redraw_screen();
			refresh();
			break;
		  case ENDWIN:
			refresh();
			if ((ch = GETCHR()) == LAST_PLAYER)
				Last_player = true;
			ch = EOF;
			goto out;
		  case BELL:
			beep();
			break;
		  case READY:
			refresh();
			if (nchar_send < 0)
				tcflush(STDIN_FILENO, TCIFLUSH);
			nchar_send = MAX_SEND;
#ifndef OTTO
			(void) GETCHR();
#else
			Otto_count -= (GETCHR() & 0xff);
			if (!Am_monitor) {
#ifdef DEBUG
				fputc('0' + Otto_count, stderr);
#endif
				if (Otto_count == 0 && Otto_mode)
					otto(otto_y, otto_x, otto_face);
			}
#endif
			break;
		  default:
#ifdef OTTO
			switch (ch) {

			case '<':
			case '>':
			case '^':
			case 'v':
				otto_face = ch;
				getyx(stdscr, otto_y, otto_x);
				break;
			}
#endif
			addch(ch);
			break;
		}
	}
out:
	(void) close(huntsocket);
}
示例#18
0
void CCellView::MouseDown(BPoint where)
{
	StPenState save(this);
	
	try
	{
		bool optional = IsOptionalClick(Window()->CurrentMessage());
		
		if (!IsFocus() && !fEntering)
			MakeFocus();

		ResetOffset(-1);
	
		BRect myRect, bounds(Bounds());
		cell myCell = cell(fFrozen.h ? 1 : fPosition.h, fFrozen.v ? 1 : fPosition.v);

		if (fFirstGraphic)
		{
			if (fFirstGraphic->HandleMouseDown(where))
				return;
			else if (fFirstGraphic->HasFocus())
				fFirstGraphic->MakeFocus(false);
		}
	
		if (fCellBounds.Contains(where))
		{
			if ((PointIsInSelection(where) &&
				!fEntering) &&
				(optional ||
				WaitMouseMoved(where, false)))
			{
				StartDrag(where, optional);
			}
			else if (optional)
				GridMenu(where);
			else
				SelectCell(where);
		}
		
		if (!fShowBorders)
			return;
		
		myRect = bounds;
		myRect.top = fBorderHeight;
		myRect.left = 0.0;
		myRect.right = fBorderWidth;
	
		if (myRect.Contains(where))
		{
			if (optional)
				BorderMenu(where);
			else
			{
				do
				{
					myCell.v++;
					GetCellRect(myCell, myRect);
				}
				while (myRect.top + 2.0 <= where.y);
		
				if (where.y >= myRect.top - 2.0 && where.y <= myRect.top + 2.0)
					ResizeRow(where, myCell.v - 1);
				else
					SelectRow(where, myCell.v - 1);
			}
			return;
		}
	
		myRect.Set(fBorderWidth, 0.0, bounds.right, fBorderHeight);
	
		if (myRect.Contains(where))
		{
			if (optional)
				BorderMenu(where);
			else
			{
				do
				{
					myCell.h++;
					GetCellRect(myCell, myRect);
				}
				while (myRect.left + 2.0 <= where.x);
		
				if (where.x >= myRect.left - 2.0 && where.x <= myRect.left + 2.0)
					ResizeCol(where, myCell.h - 1);
				else
					SelectCol(where, myCell.h - 1);
			}
			return;
		}
	
		myRect.Set(0.0, 0.0, fBorderWidth, fBorderHeight);
	
		if (myRect.Contains(where))
		{
			if (!fEntering)
				SetSelection(range(1, 1, kColCount, kRowCount));
			else
				beep();
		}
	}
	
	catch(CErr& e)
	{
		CATCHED;
		e.DoError();
		return;
	}
	
	catch(...)
	{
		CATCHED;
		ASSERT(FALSE);
	}
}
示例#19
0
void
vappend(int ch, int cnt, int indent)
/*	int ch;		/\* mjm: char --> int */
{
	register int i = 0;
	register char *gcursor;
	bool escape;
	int repcnt, savedoomed;
	short oldhold = hold;
#ifdef	SIGWINCH
	sigset_t set, oset;
#endif

	/*
	 * Before a move in hardopen when the line is dirty
	 * or we are in the middle of the printed representation,
	 * we retype the line to the left of the cursor so the
	 * insert looks clean.
	 */
	if (ch != 'o' && state == HARDOPEN && (rubble || !ateopr())) {
		rubble = 1;
		gcursor = cursor;
		i = *gcursor;
		*gcursor = ' ';
		wcursor = gcursor;
		vmove(0);
		*gcursor = i;
	}
	vaifirst = indent == 0;

	showmode(ch);

	/*
	 * Handle replace character by (eventually)
	 * limiting the number of input characters allowed
	 * in the vgetline routine.
	 */
	if (ch == 'r')
		repcnt = 2;
	else
		repcnt = 0;

	/*
	 * If an autoindent is specified, then
	 * generate a mixture of blanks to tabs to implement
	 * it and place the cursor after the indent.
	 * Text read by the vgetline routine will be placed in genbuf,
	 * so the indent is generated there.
	 */
	if (value(AUTOINDENT) && indent != 0) {
		gcursor = genindent(indent);
		*gcursor = 0;
		vgotoCL(qcolumn(cursor + skipright(cursor, linebuf), genbuf));
	} else {
		gcursor = genbuf;
		*gcursor = 0;
		if (ch == 'o')
			vfixcurs();
	}

	/*
	 * Prepare for undo.  Pointers delimit inserted portion of line.
	 */
	vUA1 = vUA2 = cursor;

	/*
	 * If we are not in a repeated command and a ^@ comes in
	 * then this means the previous inserted text.
	 * If there is none or it was too long to be saved,
	 * then beep() and also arrange to undo any damage done
	 * so far (e.g. if we are a change.)
	 */
	if ((vglobp && *vglobp == 0) || peekbr()) {
		if ((INS[0] & (QUOTE|TRIM)) == OVERBUF) {
			beep();
			if (!splitw)
				ungetkey('u');
			doomed = 0;
			hold = oldhold;
			showmode(0);
			return;
		}
		/*
		 * Unread input from INS.
		 * An escape will be generated at end of string.
		 * Hold off n^^2 type update on dumb terminals.
		 */
		vglobp = INS;
		hold |= HOLDQIK;
	} else if (vglobp == 0)
		/*
		 * Not a repeated command, get
		 * a new inserted text for repeat.
		 */
		INS[0] = 0;

	/*
	 * For wrapmargin to hack away second space after a '.'
	 * when the first space caused a line break we keep
	 * track that this happened in gobblebl, which says
	 * to gobble up a blank silently.
	 */
	gobblebl = 0;

#ifdef	SIGWINCH
	sigemptyset(&set);
	sigaddset(&set, SIGWINCH);
	sigprocmask(SIG_BLOCK, &set, &oset);
#endif
	/*
	 * Text gathering loop.
	 * New text goes into genbuf starting at gcursor.
	 * cursor preserves place in linebuf where text will eventually go.
	 */
	if (*cursor == 0 || state == CRTOPEN)
		hold |= HOLDROL;
	for (;;) {
		if (ch == 'r' && repcnt == 0)
			escape = 0;
		else {
			gcursor = vgetline(repcnt, gcursor, &escape, ch);

			/*
			 * After an append, stick information
			 * about the ^D's and ^^D's and 0^D's in
			 * the repeated text buffer so repeated
			 * inserts of stuff indented with ^D as backtab's
			 * can work.
			 */
			if (HADUP)
				addc('^');
			else if (HADZERO)
				addc('0');
			while (CDCNT > 0)
#ifndef	BIT8
				addc('\204'), CDCNT--;
#else
				addc(OVERBUF), CDCNT--;
#endif
			
			if (gobbled)
				addc(' ');
			addtext(ogcursor);
		}
		repcnt = 0;

		/*
		 * Smash the generated and preexisting indents together
		 * and generate one cleanly made out of tabs and spaces
		 * if we are using autoindent.
		 */
		if (!vaifirst && value(AUTOINDENT)) {
			i = fixindent(indent);
			if (!HADUP)
				indent = i;
			gcursor = strend(genbuf);
		}

		/*
		 * Limit the repetition count based on maximum
		 * possible line length; do output implied
		 * by further count (> 1) and cons up the new line
		 * in linebuf.
		 */
		cnt = vmaxrep(ch, cnt);
		CP(gcursor + skipright(ogcursor, gcursor), cursor);
		do {
			CP(cursor, genbuf);
			if (cnt > 1) {
				int oldhold = hold;

				Outchar = vinschar;
				hold |= HOLDQIK;
				ex_printf("%s", genbuf);
				hold = oldhold;
				Outchar = vputchar;
			}
			cursor += gcursor - genbuf;
		} while (--cnt > 0);
		endim();
		vUA2 = cursor;
		if (escape != '\n')
			CP(cursor, gcursor + skipright(ogcursor, gcursor));

		/*
		 * If doomed characters remain, clobber them,
		 * and reopen the line to get the display exact.
		 */
		if (state != HARDOPEN) {
			DEPTH(vcline) = 0;
			savedoomed = doomed;
			if (doomed > 0) {
				register int cind = cindent();

				physdc(cind, cind + doomed);
				doomed = 0;
			}
			i = vreopen(LINE(vcline), lineDOT(), vcline);
#ifdef TRACE
			if (trace)
				fprintf(trace, "restoring doomed from %d to %d\n", doomed, savedoomed);
#endif
			if (ch == 'R')
				doomed = savedoomed;
		}

		/*
		 * All done unless we are continuing on to another line.
		 */
		if (escape != '\n')
			break;

		/*
		 * Set up for the new line.
		 * First save the current line, then construct a new
		 * first image for the continuation line consisting
		 * of any new autoindent plus the pushed ahead text.
		 */
		showmode(0);
		killU();
		addc(gobblebl ? ' ' : '\n');
		vsave();
		cnt = 1;
		if (value(AUTOINDENT)) {
#ifdef LISPCODE
			if (value(LISP))
				indent = lindent(dot + 1);
			else
#endif
			     if (!HADUP && vaifirst)
				indent = whitecnt(linebuf);
			vaifirst = 0;
			strcLIN(vpastwh(gcursor + 1));
			gcursor = genindent(indent);
			*gcursor = 0;
			if (gcursor + strlen(linebuf) > &genbuf[LBSIZE - 2])
				gcursor = genbuf;
			CP(gcursor, linebuf);
		} else {
			CP(genbuf, gcursor + skipright(ogcursor, gcursor));
			gcursor = genbuf;
		}

		/*
		 * If we started out as a single line operation and are now
		 * turning into a multi-line change, then we had better yank
		 * out dot before it changes so that undo will work
		 * correctly later.
		 */
		if (FIXUNDO && vundkind == VCHNG) {
			vremote(1, yank, 0);
			undap1--;
		}

		/*
		 * Now do the append of the new line in the buffer,
		 * and update the display.  If slowopen
		 * we don't do very much.
		 */
		vdoappend(genbuf);
		vundkind = VMANYINS;
		vcline++;
		if (state != VISUAL)
			vshow(dot, NOLINE);
		else {
			i += LINE(vcline - 1);
			vopen(dot, i);
			if (value(SLOWOPEN))
				vscrap();
			else
				vsync1(LINE(vcline));
		}
		strcLIN(gcursor);
		*gcursor = 0;
		cursor = linebuf;
		vgotoCL(qcolumn(cursor + skipleft(ogcursor, cursor), genbuf));
		showmode(ch);
	}

	/*
	 * All done with insertion, position the cursor
	 * and sync the screen.
	 */
	showmode(0);
	hold = oldhold;
	if (cursor > linebuf)
		cursor += skipleft(linebuf, cursor);
	if (state != HARDOPEN)
		vsyncCL();
	else if (cursor > linebuf)
		back1();
	doomed = 0;
	wcursor = cursor;
	vmove(0);
#ifdef	SIGWINCH
	sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
}
示例#20
0
uint8_t	Menu_SelectOnlyEx ( const struct uMenu * menu, uint8_t item, void ( *pHook ) ( void ),BOOL Direction )
{
	//TRUE 改纵向  FALSE 改横向
	uint8_t	mlen, mlen_row, mlen_col;
	uint16_t gray  = Configure.DisplayGray;
	BOOL graychanged = FALSE;
	BOOL Flag = FALSE;
	mlen_row = HIBYTE ( menu[0].yx );
	mlen_col = LOBYTE ( menu[0].yx );

	if ( 0u == mlen_row )
	{
		mlen = mlen_col;
	}
	else
	{
		mlen = mlen_row * mlen_col;
	}

	if ( ( item < 1u ) || ( item > mlen ) )
	{
		item = 1u;
	}

	for ( ; ; )
	{
		LcmMask ( menu[item].yx, strlen ( menu[item].sz ), menu[item].sz );

		do
		{
			if ( NULL != pHook )
			{
				pHook();
			}
		}
		while ( ! hitKey ( 50u ) );

		Lputs ( menu[item].yx, menu[item].sz );

		switch ( getKey() )
		{

			case K_RIGHT:

				if((!Direction) && (!Flag))
				{
					item += mlen_col;

					if ( item > mlen )
					{
						item -= mlen;
					}
				}
				else
				{
					if ( 0 == ( item % mlen_col ) )
					{
						item -= mlen_col;
					}

					++item;
				}

				break;

			case K_LEFT:

				if((!Direction) && (!Flag))
				{
					if ( item <= mlen_col )
					{
						item += mlen;
					}

					item -= mlen_col;
				}
				else
				{
					--item;

					if ( 0 == ( item % mlen_col ) )
					{
						item += mlen_col;
					}
				}

				break;

			case K_DOWN:

				if( Direction && (!Flag) )
				{
					if ( 0 == ( item % mlen_col ) )
					{
						item -= mlen_col;
					}

					++item;
				}
				else
				{
					item += mlen_col;

					if ( item > mlen )
					{
						item -= mlen;
					}
				}

				break;
			case K_UP:

				if( Direction && (!Flag) )
				{
					--item;

					if ( 0 == ( item % mlen_col ) )
					{
						item += mlen_col;
					}
				}
				else
				{
					if ( item <= mlen_col )
					{
						item += mlen;
					}

					item -= mlen_col;
				}

				break;

			case K_OK:
				Flag = TRUE;
				return	item;

			case K_ESC:
				Flag = FALSE;
				return	enumSelectESC;

			case K_SHIFT:
				return	enumSelectXCH;
			case K_OK_UP:

				if ( gray < 999 )
				{
					++gray;
				}

				if( ! releaseKey( K_OK_UP,100 ))
				{
					while( ! releaseKey( K_OK_UP, 1 ))
					{
						++gray;
						DisplaySetGrayVolt( gray * 0.022f );
					}
				}

				graychanged = true;
				break;
			case K_OK_DOWN:

				if ( gray >  10u )
				{
					--gray;
				}

				if( ! releaseKey( K_OK_DOWN, 100 ))
				{
					while( ! releaseKey( K_OK_DOWN, 1 ))
					{
						--gray;
						DisplaySetGrayVolt( gray * 0.022f );
					}
				}

				graychanged = true;
				break;

			case K_OK_RIGHT:

				if ( gray < ( 1000u - 50u ))
				{
					gray += 50u;
				}

				graychanged = true;
				break;
			case K_OK_LEFT:

				if ( gray > ( 10 + 50u ))
				{
					gray -= 50u;
				}

				graychanged = true;
				break;
			case K_ESC_SHIFT:

				if ( ! releaseKey( K_ESC_SHIFT, 200 ))
				{
					item = enumSelectESC;
					beep();
					delay( 100u );
					beep();
					cls();
					Lputs( 0x0608u, "请输入出厂编号:" );
					ConfigureLoad();

					if( EditI32U( 0x0C0Cu, &Configure.ExNum, 0x0700u ))
					{
						if( vbYes == MsgBox("是否保存编号?",vbYesNo) )
							ConfigureSave();
						else
							ConfigureLoad();
					}

					return	enumSelectESC;
				}

			default:
				break;
		}

		if( graychanged == true )
		{
			DisplaySetGrayVolt( gray * 0.022f );
			Configure.DisplayGray = gray;
			ConfigureSave();
			graychanged = FALSE;
		}
	}
}
示例#21
0
文件: rtttl.c 项目: ZigZagJoe/68k
void play_rtttl(char *p)
{
  // Absolutely no error checking in here

  byte default_dur = 4;
  byte default_oct = 6;
  int bpm = 63;
  int num;
  long wholenote;
  long duration;
  byte note;
  byte scale;

  // format: d=N,o=N,b=NNN:
  // find the start (skip name, etc)

  puts("Playing: ");
  lcd_clear();
  lcd_cursor(0,0);
  lcd_puts("Playing: ");
  lcd_cursor(0,1);
  
  while(*p != ':') {
  	putc(*p);
  	lcd_data(*p);
  	p++;    // ignore name
  }
  putc('\n');
  
  p++;                     // skip ':'

  // get default duration
  if(*p == 'd') {
    p++; p++;              // skip "d="
    num = 0;
    while(isdigit(*p))
    {
      num = (num * 10) + (*p++ - '0');
    }
    if(num > 0) default_dur = num;
    p++;                   // skip comma
  }

  // get default octave
  if(*p == 'o') {
    p++; p++;              // skip "o="
    num = *p++ - '0';
    if(num >= 3 && num <=7) default_oct = num;
    p++;                   // skip comma
  }

  // get BPM
  if(*p == 'b') {
    p++; p++;              // skip "b="
    num = 0;
    while(isdigit(*p)) {
      num = (num * 10) + (*p++ - '0');
    }
    bpm = num;
    p++;                   // skip colon
  }

  // BPM usually expresses the number of quarter notes per minute
  wholenote = (60 * 1000L / bpm) * 4;  // this is the time for whole note (in milliseconds)

  // now begin note loop
  while(*p) {
    // first, get note duration, if available
    num = 0;
    while(isdigit(*p)) {
      num = (num * 10) + (*p++ - '0');
    }
   
    if(num) duration = wholenote / num;
    else duration = wholenote / default_dur;  // we will need to check if we are a dotted note after

    // now get the note
    note = 0;

    switch(*p) {
      case 'c':
        note = 1;
        break;
      case 'd':
        note = 3;
        break;
      case 'e':
        note = 5;
        break;
      case 'f':
        note = 6;
        break;
      case 'g':
        note = 8;
        break;
      case 'a':
        note = 10;
        break;
      case 'b':
        note = 12;
        break;
      case 'p':
      default:
        note = 0;
    }
    p++;

    // now, get optional '#' sharp
    if(*p == '#') {
      note++;
      p++;
    }

    // now, get optional '.' dotted note
    if(*p == '.') {
      duration += duration/2;
      p++;
    }
 
    // now, get scale
    if(isdigit(*p)) {
      scale = *p - '0';
      p++;
    } else {
      scale = default_oct;
    }

    scale += OCTAVE_OFFSET;

    if(*p == ',')
      p++;       // skip comma for next note (or we may be at the end)

    // now play the note

    if(note) {
      beep(notes[(scale - 4) * 12 + note],duration);
    } else {
      _delay_ms(duration);
    }
  }
}
示例#22
0
static int
get_position(NCURSES_CONST char *text,
	     NCURSES_CONST char *also,
	     int which,
	     int *xpos,
	     int *ypos)
{
    int result = 0;
    int x1, y1;
    char cmd;

    getyx(stdscr, y1, x1);
    (void) statusline();

    show_position(text, also, which, y1, x1);

    if (log_in != 0) {
	if (fscanf(log_in, "%c%d,%d\n", &cmd, &y1, &x1) == 3) {
	    switch (cmd) {
	    case LAST_POS:
		result = 1;
		(void) wgetch(stdscr);
		break;
	    case TEMP_POS:
		result = 0;
		wrefresh(stdscr);
		napms(100);
		break;
	    default:
		result = -1;
		break;
	    }
	} else {
	    result = -1;
	}
    } else {

	switch (wgetch(stdscr)) {
	case QUIT:
	case ESCAPE:
	case ERR:
	    result = -1;
	    break;
	case ' ':
	    result = 1;
	    break;
	case KEY_UP:
	    if (y1 > 0) {
		--y1;
	    } else {
		beep();
	    }
	    break;
	case KEY_DOWN:
	    if (y1 < getmaxy(stdscr)) {
		++y1;
	    } else {
		beep();
	    }
	    break;
	case KEY_LEFT:
	    if (x1 > 0) {
		--x1;
	    } else {
		beep();
	    }
	    break;
	case KEY_RIGHT:
	    if (x1 < getmaxx(stdscr)) {
		++x1;
	    } else {
		beep();
	    }
	    break;
	}
    }

    wmove(stdscr, y1, x1);
    *ypos = y1;
    *xpos = x1;

    if (result >= 0) {
	if (log_out)
	    fprintf(log_out, "%c%d,%d\n",
		    ((result > 0)
		     ? LAST_POS
		     : TEMP_POS),
		    y1, x1);
    }
    return result;
}
int window_new_identity_run_command(gui_t* gui, int c)
{
    ogmp_curses_t* ocui = gui->topui;

    int max = 5;

    switch (c)
    {
    case KEY_DC:
    {
        editline_remove_char(newid_edit[cursor_newid]);

        delch();

        break;
    }
    case '\b':
    {
        if (editline_move_pos(newid_edit[cursor_newid], -1) >= 0)
            editline_remove_char(newid_edit[cursor_newid]);
        else
            beep();

        break;
    }
    case '\n':
    case '\r':
    case KEY_ENTER:
    case KEY_DOWN:
    {
        cursor_newid++;
        cursor_newid %= max;

        break;
    }
    case KEY_UP:
    {
        cursor_newid += max-1;
        cursor_newid %= max;

        break;
    }
    case KEY_RIGHT:
    {
        if (editline_move_pos(newid_edit[cursor_newid], 1) < 0)
            beep();

        break;
    }
    case KEY_LEFT:
    {
        if (editline_move_pos(newid_edit[cursor_newid], -1) < 0)
            beep();

        break;
    }
    case 1:  /* Ctrl-A */
    {
        int sec = 0;

        if(newid_regsec[0])
            sec = strtol(newid_regsec, NULL, 10);

        if(sec <= 0)
            break;

        if(newid_fullname[0] && newid_registary[0] && newid_regname[0])
        {
            if(!ocui->edit_profile)
                user_add_profile(ocui->user, newid_fullname, strlen(newid_fullname),
                                 newid_bookloc, newid_registary, newid_regname, sec);
            else
                user_set_profile(ocui->user, ocui->edit_profile, newid_fullname, strlen(newid_fullname),
                                 newid_bookloc, newid_registary, newid_regname, sec);

            gui_hide_window(gui);
        }

        break;
    }
    case 3:  /* Ctrl-C */
    {
        gui_hide_window(gui);

        break;
    }
    case 4:  /* Ctrl-D */
    {
        editline_clear(newid_edit[cursor_newid]);

        break;
    }
    default:
    {
        if(editline_append(newid_edit[cursor_newid], (char*)&c, 1) == 0)
        {
            beep();

            return -1;
        }
    }
    }

    gui_update(gui);

    return 0;
}
示例#24
0
/*
 * A command consists of one or more letter/digit pairs separated by a space.
 * Digits are limited to 1..MAX_PANELS.
 *
 * End the command with a newline.  Reject other characters.
 */
static bool
get_command(PANEL * px[MAX_PANELS + 1], char *buffer, int limit)
{
    int length = 0;
    int y0, x0;
    int c0, ch;
    WINDOW *win;

    getyx(stdscr, y0, x0);
    win = statusline();
    waddstr(win, "Command:");
    buffer[length = 0] = '\0';

    if (log_in != 0) {
	if (fgets(buffer, limit - 3, log_in) != 0) {
	    length = (int) strlen(buffer);
	    while (length > 0 && isspace(UChar(buffer[length - 1])))
		buffer[--length] = '\0';
	    waddstr(win, buffer);
	} else {
	    close_input();
	}
	(void) wgetch(win);
    } else {
	c0 = 0;
	for (;;) {
	    ch = wgetch(win);
	    if (ch == ERR || ch == QUIT || ch == ESCAPE) {
		buffer[0] = '\0';
		break;
	    } else if (ch == CTRL('L')) {
		wrefresh(curscr);
	    } else if (ch == '\n' || ch == KEY_ENTER) {
		break;
	    } else if (ch == '?') {
		show_panels(px);
	    } else if (length + 3 < limit) {
		if (ch >= KEY_MIN) {
		    beep();
		} else if (ok_letter(UChar(ch))) {
		    if (isalpha(UChar(c0))) {
			beep();
		    } else if (isdigit(UChar(c0))) {
			wprintw(win, " %c", ch);
			buffer[length++] = ' ';
			buffer[length++] = (char) (c0 = ch);
		    } else {
			wprintw(win, "%c", ch);
			buffer[length++] = (char) (c0 = ch);
		    }
		} else if (ok_digit(ch)) {
		    if (isalpha(UChar(c0))) {
			wprintw(win, "%c", ch);
			buffer[length++] = (char) (c0 = ch);
		    } else {
			beep();
		    }
		} else if (ch == ' ') {
		    if (isdigit(UChar(c0))) {
			wprintw(win, "%c", ch);
			buffer[length++] = (char) (c0 = ch);
		    } else {
			beep();
		    }
		} else {
		    beep();
		}
	    } else {
		beep();
	    }
	}
    }

    wmove(stdscr, y0, x0);

    buffer[length] = '\0';
    if (log_out && length) {
	fprintf(log_out, "%s\n", buffer);
    }
    return (length != 0);
}
示例#25
0
文件: client.c 项目: gz818/melted
mvcp_error_code client_select_unit( client demo )
{
	int terminated = 0;
	int refresh = 1;

	while ( !terminated )
	{
		mvcp_units units = mvcp_units_init( demo->dv );

		if ( mvcp_units_count( units ) > 0 )
		{
			mvcp_unit_entry_t unit;
			int index = 0;
			char key = '\0';

			if ( refresh )
			{
				printf( "Select a Unit\n\n" );

				for ( index = 0; index < mvcp_units_count( units ); index ++ )
				{
					mvcp_units_get( units, index, &unit );
					printf( "%d: U%d - %s [%s]\n", index + 1, 
												   unit.unit, 
												   unit.guid, 
												   unit.online ? "online" : "offline" );
				}
				printf( "0: Exit\n\n" );

				printf( "Unit [%d]: ", demo->selected_unit + 1 );
				refresh = 0;
			}

			key = get_keypress( );

			if ( key == '\r' )
				key = demo->selected_unit + '1';

			if ( key != '0' )
			{
				if ( key >= '1' && key < '1' + mvcp_units_count( units ) )
				{
					demo->selected_unit = key - '1';
					printf( "%c\n\n", key );
					client_load( demo );
					refresh = 1;
				}
				else
				{
					beep( );
				}					
			}
			else
			{
				printf( "0\n\n" );
				terminated = 1;
			}
		}
		else if ( mvcp_units_count( units ) == 0 )
		{
			printf( "No units added - add a unit first\n\n" );
			client_add_unit( demo );
		}
		else
		{
			printf( "Unable to obtain Unit List.\n" );
			terminated = 1;
		}

		mvcp_units_close( units );
	}

	return mvcp_ok;
}
示例#26
0
int main(void)
{	
	
	set_fuses();
	init();
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | ( 1 << LED_LH) | (1 << LED_LV));
/*
	_delay_ms(1000);
*/
	unsigned char programm_step = 1;
	beep(2);
	
	
	PORT_LED &=~ ((1<< LED_RH) | ( 1 << LED_LH) | (1 << LED_LV));
	PORT_LED |= (1 << LED_RV);
	_delay_ms(500);
	PORT_LED &=~ ((1 << LED_RV) | ( 1 << LED_LH) | (1 << LED_LV));
	PORT_LED |= (1 << LED_RH);
	_delay_ms(500);
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | (1 << LED_LV));
	PORT_LED |= (1 << LED_LH);
	_delay_ms(500);
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | ( 1 << LED_LH) );
	PORT_LED |= (1 << LED_LV);
	_delay_ms(500);
/*
	while(!(status&(1<<STATUS_END)))
    {

		switch (programm_step)
		{
			case 1:
			{	
				if (!(status&(1<<STATUS_BUSY)))
				{
					drive_Robot(MOT_FORWARD,242,MOT_BACKWARD,254,ONE_TURN,ONE_TURN);
				}
				else
				{
					if(check_impulse()) 
					{
						programm_step++;
					}				
				}
			}
			break;
			
			case 2:
			{
				_delay_ms(1000);
				programm_step++;
			}
			break;
			
			case 3:
			{
				if (!(status&(1<<STATUS_BUSY)))
				{
					drive_Robot(MOT_BACKWARD,242,MOT_FORWARD,254,ONE_TURN,ONE_TURN);
				}
				else
				{
					if(check_impulse())
					{
						programm_step++;
					}
				}
			}
			break;

			case 4:
			{
				if (!(status&(1<<STATUS_BUSY)))
				{
					drive_Robot(MOT_FORWARD,242,MOT_FORWARD,254, (5*ONE_TURN),(5*ONE_TURN));
				}
				else
				{
					if(check_impulse())
					{
						programm_step++;
					}
				}
			}
			break;

			case 5:
			{
				if (!(status&(1<<STATUS_BUSY)))
				{
					drive_Robot(MOT_BACKWARD,242,MOT_FORWARD,254,ONE_TURN,ONE_TURN);
				}
				else
				{
					if(check_impulse())
					{
						programm_step++;
					}
				}
			}
			break;
			
			case 6:
			{
				if (!(status&(1<<STATUS_BUSY)))
				{
					drive_Robot(MOT_FORWARD,242,MOT_FORWARD,254,(5*ONE_TURN),(5*ONE_TURN));
				}
				else
				{
					if(check_impulse())
					{
						status |= (1<<STATUS_END);
					}
				}
			}
			break;
		}		
	}
*/
	PORT_DUAL |= (1 << LED_ROT);
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | ( 1 << LED_LH) | (1 << LED_LV));

	pwm_left = 250;
	pwm_right = 250;/*
	drive_Robot(MOT_BACKWARD,pwm_right,MOT_BACKWARD,pwm_left,3*ONE_TURN,3*ONE_TURN);
	while (!check_impulse()) {
		beep(1);
		PORT_LED ^= (1 << LED_RH) | (1 << LED_LH);
	}
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | ( 1 << LED_LH) | (1 << LED_LV));
	
	drive_Robot(MOT_FORWARD, pwm_right, MOT_FORWARD, pwm_left, 0, ONE_TURN);
	while (!check_impulse()) {
		PORT_LED ^= (1 << LED_RH) | (1 << LED_RV);
		_delay_ms(200);
	}*/
	
	
	/*
	PORT_LED &=~ ((1 << LED_RV) | (1<< LED_RH) | ( 1 << LED_LH) | (1 << LED_LV));
	drive_Robot(MOT_FORWARD, 185, MOT_FORWARD, 185, 300, 300);
	for (int i = 20; i > 0; i--) {
		OCR4B = 240 - i * 5;
		OCR4D = 240 - i * 5;
		_delay_ms(200);
	}
	while (!check_impulse());
	*/
	int co = 4;
/*	while (co--){
	drive_Robot(MOT_FORWARD, 250, MOT_FORWARD, 250, 3*ONE_TURN-3, 3*ONE_TURN-3);
	while (!check_impulse());
	drive_Robot(MOT_FORWARD, 250, MOT_FORWARD, 0, ONE_TURN, 0);
	while (!check_impulse());
	}*/
	co = 0;
	while (co--) {
		drive_Robot(MOT_FORWARD, 250, MOT_BACKWARD, 250, 30,30);
		while (!check_impulse());
	}
//	_delay_ms(20);
/*
	pwm_left = 0;
	pwm_right = pwm_left-(pwm_left/RATIO_Left_Right);
	drive_Robot(MOT_FAST_STOPP,pwm_right,MOT_FAST_STOPP,pwm_left,STOPP,STOPP);
//	_delay_ms(200);

	pwm_left = 200;
	pwm_right = pwm_left-(pwm_left/RATIO_Left_Right);
	drive_Robot(MOT_FORWARD,pwm_right,MOT_BACKWARD,pwm_left,ROT_180,ROT_180);
while(!check_impulse()) {}
//	_delay_ms(850);

	pwm_left = 0;
	pwm_right = pwm_left-(pwm_left/RATIO_Left_Right);
	drive_Robot(MOT_FAST_STOPP,pwm_right,MOT_FAST_STOPP,pwm_left,ONE_TURN,ONE_TURN);
//	_delay_ms(200);

	pwm_left = 200;
	pwm_right = pwm_left-(pwm_left/RATIO_Left_Right);
	drive_Robot(MOT_FORWARD,pwm_right,MOT_FORWARD,pwm_left,5*ONE_TURN,5*ONE_TURN);
while(!check_impulse()) {}
//	_delay_ms(10000);

	pwm_left = 0;
	pwm_right = pwm_left-(pwm_left/RATIO_Left_Right);
	drive_Robot(MOT_FAST_STOPP,pwm_right,MOT_FAST_STOPP,pwm_left,ONE_TURN,ONE_TURN);
*/
	
	/*char dot = 3;
	while(dot)
	{
		if(!check_impulse()) {}
		else
		{
			PORTD ^= (1<<LED_GRUEN);
			PORTB ^= (1<<LED_RH);
			PORTB ^= (1<<LED_RV);
			beep(3);
			_delay_ms(200);
			dot--;
		}
	}
	*/
	timer_beep_melodie();
//	beep(4);
	PORT_DUAL &=~ (1 << LED_ROT);
	PORT_DUAL |= (1 << LED_GRUEN);
	while (1)
	{
		PORT_DUAL &=~ (1 << LED_GRUEN);
		_delay_ms(500);
		PORT_DUAL |= (1 << LED_GRUEN);
		_delay_ms(2000);
	}
}
示例#27
0
void NotificationSound::beep()
{
    rho::Hashtable<rho::String, rho::String> propertyMap;
    beep(propertyMap);
}
示例#28
0
文件: hanoi.c 项目: kal444/xiang-qi
int
main(int argc, char **argv)
{
int NTiles, FromCol, ToCol;
unsigned char AutoFlag = 0;

	switch(argc) {
	case 1:
		NTiles = DEFAULTTILES;
		break;
	case 2:
		NTiles = atoi(argv[1]);
		if (NTiles > MAXTILES || NTiles < MINTILES) {
			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
			return EXIT_FAILURE;
		}
		break;
	case 3:
		if (strcmp(argv[2], "a")) {
			Usage();
			return EXIT_FAILURE;
		}
		NTiles = atoi(argv[1]);
		if (NTiles > MAXTILES || NTiles < MINTILES) {
			fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
			return EXIT_FAILURE;
		}
		AutoFlag = TRUE;
		break;
	default:
		Usage();
		return EXIT_FAILURE;
	}
#ifdef NCURSES_VERSION
	trace(TRACE_MAXIMUM);
#endif
	initscr();
	if (has_colors()) {
		int i;
		int bg = COLOR_BLACK;
		start_color();
#ifdef NCURSES_VERSION
		if (use_default_colors() == OK)
			bg = -1;
#endif
		for (i = 0; i < 9; i++)
			init_pair(i+1, bg, TileColour[i]);
	}
	cbreak();
	if (LINES < 24) {
		endwin();
		fprintf(stderr, "Min screen length 24 lines\n");
		return EXIT_FAILURE;
	}
	if(AutoFlag)
		leaveok(stdscr, TRUE);	/* Attempt to remove cursor */
	InitTiles(NTiles);
	DisplayTiles();
	if(AutoFlag) {
		do {
			noecho();
			AutoMove(0, 2, NTiles);
		} while(!Solved(NTiles));
		sleep(2);
	} else {
		echo();
		for(;;) {
			if(GetMove(&FromCol, &ToCol))
				break;
			if(InvalidMove(FromCol, ToCol)) {
				mvaddstr(STATUSLINE, 0, "Invalid Move !!");
				refresh();
				beep();
				continue;
			}
			MakeMove(FromCol, ToCol);
			if(Solved(NTiles)) {
				mvprintw(STATUSLINE, 0, "Well Done !! You did it in %d moves", NMoves);
				refresh();
				sleep(5);
				break;
			}
		}
	}
	curs_set(1);
	endwin();
	return EXIT_SUCCESS;
}
示例#29
0
文件: bxbasic.c 项目: tchandler48/c2z
void parser()
{
  int ab_code=4, x=line_ndx;
  int I;

  switch(token)
  {
    case 0:
      break;

    case 1:
      parse_let();
      break;
	
    case 2:
      cls();
      break;
    
    case 3:
      locate();
      break;
	
    case 4:
      xstring_array(); 
      get_prnstring(); 
      break;

    case 5:
      go_to();
      break;
	
    case 6:
      beep();
      break;
	
    case 7:
      cls();
      break;
	
    case 8:
      line_ndx = nrows;
      break;

    case 9:
      do_gs();
      break;

    case 10:
      do_ret();
      break;

    case 11:
      do_loop();
      break;

    case 12:
      do_next();
      break;

    case 13:
      do_iloop();
      break;

    case 14:
      do_iloop();
      break;
    
    case 15:
      return;
      break;

    case 16:
      return;
      break;

    case -1:
      break;

    default:
      printf("parser Inside DEFAULT\n");
      printf("p_string = %s\n",p_string);
      a_bort(ab_code, x);
      break;
  }
}
示例#30
0
/*
	lexical analyzer for larn
 */
int
yylex(void)
{
	char cc;
	int ic;
	if (hit2flag) {
		hit2flag = 0;
		yrepcount = 0;
		return (' ');
	}
	if (yrepcount > 0) {
		--yrepcount;
		return (lastok);
	} else
		yrepcount = 0;
	if (yrepcount == 0) {
		bottomdo();
		showplayer();
	}			/* show where the player is */
	lflush();
	while (1) {
		c[BYTESIN]++;
		/* check for periodic checkpointing */
		if (ckpflag)
			if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) {
#ifndef DOCHECKPOINTS
				savegame(ckpfile);
#else
				wait(0);	/* wait for other forks to finish */
				if (fork() == 0) {
					savegame(ckpfile);
					exit(0);
				}
#endif
#ifdef TIMECHECK
				if (dayplay == 0)
					if (playable()) {
						cursor(1, 19);
						lprcat("\nSorry, but it is now time for work.  Your game has been saved.\n");
						beep();
						lflush();
						savegame(savefilename);
						wizard = nomove = 1;
						sleep(4);
						died(-257);
					}
#endif /* TIMECHECK */
			}

		do {		/* if keyboard input buffer is too big, flush some of it */
			ioctl(0, FIONREAD, &ic);
			if (ic > flushno)
				read(0, &cc, 1);
		} while (ic > flushno);

		if (read(0, &cc, 1) != 1)
			return (lastok = -1);

		if (cc == 'Y' - 64) {	/* control Y -- shell escape */
			resetscroll();
			clear();	/* scrolling region, home, clear, no attributes */
			if ((ic = fork()) == 0) {	/* child */
				/* revoke */
				setgid(getgid());
				execl("/bin/csh", "csh", NULL);
				exit(1);
			}
			wait(0);
			if (ic < 0) {	/* error */
				write(2, "Can't fork off a shell!\n", 25);
				sleep(2);
			}

			setscroll();
			return (lastok = 'L' - 64);	/* redisplay screen */
		}

		if ((cc <= '9') && (cc >= '0')) {
			yrepcount = yrepcount * 10 + cc - '0';
		} else {
			if (yrepcount > 0)
				--yrepcount;
			return (lastok = cc);
		}
	}
}