Esempio n. 1
0
static char
BIOSgetch()
{
    unsigned char scan, shift, ch;
    const struct pad *kpad;

    KBDKEYINFO CharData;
    USHORT IOWait = 0;
    HKBD KbdHandle = 0;

    KbdCharIn(&CharData, IOWait, KbdHandle);
    ch = CharData.chChar;
    scan = CharData.chScan;
    shift = CharData.fsState;

    /* Translate keypad keys */
    if (iskeypad(scan)) {
        kpad = iflags.num_pad ? numpad : keypad;
        if (shift & SHIFT_KEY)
            ch = kpad[scan - KEYPADLO].shift;
        else if (shift & CTRL_KEY)
            ch = kpad[scan - KEYPADLO].cntrl;
        else
            ch = kpad[scan - KEYPADLO].normal;
    }
    /* Translate unassigned Alt-letters */
    if ((shift & ALT_KEY) && !ch) {
        if (inmap(scan))
            ch = scanmap[scan - SCANLO];
        return (isprint(ch) ? M(ch) : ch);
    }
    return ch;
}
Esempio n. 2
0
File *getfinaltarget(File *file)
{
    Map *linkmap = newmap();
    if (!linkmap) {
        errorf("Out of memory?\n");
        return NULL;
    }
    File *target = NULL;
    while (isstat(file) && islink(file)) {
        target = gettarget(file);
        if (!target) {
            errorf("Cannot determine target of %s for %s\n", getname(file));
            break;
        }
        if (inmap(linkmap, getinode(target))) {
            errorf("Symlink loop in %s\n", getname(file));
            /* no file to stat, but want to print the name field */
            target = NULL;
            break;
        } else {
            set(linkmap, (uintmax_t)getinode(target), NULL);
        }
        file = target;
    }
    freemap(linkmap);
    return target;
}
Esempio n. 3
0
int __stdcall NHkbhit(
    HANDLE hConIn,
    INPUT_RECORD *ir)
{
	int done = 0;	/* true =  "stop searching"        */
	int retval;	/* true =  "we had a match"        */
	DWORD count;
	unsigned short int scan;
	unsigned char ch;
	unsigned long shiftstate;
	int altseq = 0, keycode, vk;
	done = 0;
	retval = 0;
	while (!done)
	{
	    count = 0;
	    PeekConsoleInput(hConIn,ir,1,&count);
	    if (count > 0) {
		if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
			ch    = ir->Event.KeyEvent.uChar.AsciiChar;
			scan  = ir->Event.KeyEvent.wVirtualScanCode;
			shiftstate = ir->Event.KeyEvent.dwControlKeyState;
			vk = ir->Event.KeyEvent.wVirtualKeyCode;
			keycode = MapVirtualKey(vk, 2);
			if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
				if  (ch || inmap(keycode,vk)) altseq = 1;
				else altseq = -1;	/* invalid altseq */
			}
			if (ch || iskeypad(scan) || altseq) {
				done = 1;	    /* Stop looking         */
				retval = 1;         /* Found what we sought */
			} else {
				/* Strange Key event; let's purge it to avoid trouble */
				ReadConsoleInput(hConIn,ir,1,&count);
			}

		}
		else if ((ir->EventType == MOUSE_EVENT &&
		  (ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) {
			done = 1;
			retval = 1;
		}

		else /* Discard it, it's an insignificant event */
			ReadConsoleInput(hConIn,ir,1,&count);
		} else  /* There are no events in console event queue */ {
		done = 1;	  /* Stop looking               */
		retval = 0;
	    }
	}
	return retval;
}
Esempio n. 4
0
int main()
{
	freopen("ttwo.in","r",stdin);
	freopen("ttwo.out","w",stdout);
	for(int i=0;i<n;i++)
	{
		scanf("%s",&cap[i]);
		for(int j=0;j<n;j++)
		{
			if(cap[i][j]=='C') cow=(Point){i,j};
			if(cap[i][j]=='F') far=(Point){i,j};
		}
	}
	int step=0;
	while(1)
	{
		if(++vis[cow.x][cow.y] > 100) {step=0;break;}
		if(++vis[far.x][far.y] > 100) {step=0;break;}
		if(cow.x==far.x && cow.y==far.y) break;
		
		int cx=cow.x+dx[dir_c],cy=cow.y+dy[dir_c];
		if(!inmap(cx,cy) || cap[cx][cy]=='*')
		{
			dir_c=(dir_c+1)%4;
			cx=cow.x; cy=cow.y;
		}
		int fx=far.x+dx[dir_f],fy=far.y+dy[dir_f];
		if(!inmap(fx,fy) || cap[fx][fy]=='*')
		{
			dir_f=(dir_f+1)%4; 
			fx=far.x; fy=far.y;
		}
		step++;
		cow=(Point){cx,cy};
		far=(Point){fx,fy};
	}
	printf("%d\n",step);
}
Esempio n. 5
0
void makeaMapForRule(const string& filename, map<string, int>& mapName, int mapValue)
{
	ifstream inmap(filename.c_str());

	string strIn;

	while (getline(inmap, strIn))
	{
		if (!strIn.empty())
		{
			mapName[strIn] = mapValue;
		}		
	}

	inmap.close();
}
Esempio n. 6
0
int __stdcall ProcessKeystroke(
    HANDLE hConIn,
    INPUT_RECORD *ir,
    boolean *valid,
    boolean numberpad,
    int portdebug)
{
	int metaflags = 0, k = 0;
	int keycode, vk;
	unsigned char ch, pre_ch, mk = 0;
	unsigned short int scan;
	unsigned long shiftstate;
	int altseq = 0;
	const struct pad *kpad;

	shiftstate = 0L;
	ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
	scan  = ir->Event.KeyEvent.wVirtualScanCode;
	vk    = ir->Event.KeyEvent.wVirtualKeyCode;
	keycode = MapVirtualKey(vk, 2);
	shiftstate = ir->Event.KeyEvent.dwControlKeyState;
	KeyState[VK_SHIFT]   = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0;
	KeyState[VK_CONTROL] = (shiftstate & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) ?
				0x81 : 0;
	KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0;

	if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
		if (ch || inmap(keycode,vk)) altseq = 1;
		else altseq = -1;	/* invalid altseq */
	}
	if (ch || (iskeypad(scan)) || (altseq > 0))
		*valid = TRUE;
	/* if (!valid) return 0; */
    	/*
	 * shiftstate can be checked to see if various special
         * keys were pressed at the same time as the key.
         * Currently we are using the ALT & SHIFT & CONTROLS.
         *
         *           RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
         *           RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
         *           SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
         *           CAPSLOCK_ON, ENHANCED_KEY
         *
         * are all valid bit masks to use on shiftstate.
         * eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
         *      left control key was pressed with the keystroke.
         */
        if (iskeypad(scan)) {
            kpad = numberpad ? numpad : keypad;
            if (shiftstate & SHIFT_PRESSED) {
                ch = kpad[scan - KEYPADLO].shift;
            }
            else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
                ch = kpad[scan - KEYPADLO].cntrl;
            }
            else {
                ch = kpad[scan - KEYPADLO].normal;
            }
        }
        else if (altseq > 0) { /* ALT sequence */
		if (vk == 0xBF) ch = M('?');
		else ch = M(tolower(keycode));
        }
	/* Attempt to work better with international keyboards. */
	else {
		WORD chr[2];
		k = ToAscii(vk, scan, KeyState, chr, 0);
		if (k <= 2)
		    switch(k) {
			case 2:  /* two characters */
				ch = (unsigned char)chr[1];
				*valid = TRUE;
				break;
			case 1:  /* one character */
				ch = (unsigned char)chr[0];
				*valid = TRUE;
				break;
			case 0:  /* no translation */
			default: /* negative */
				*valid = FALSE;
		    }
	}
	if (ch == '\r') ch = '\n';
#ifdef PORT_DEBUG
	if (portdebug) {
		char buf[BUFSZ];
		Sprintf(buf,
	"PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, ta=%d (ESC to end)",
			"ws_nhdefkey", ch, scan, vk, pre_ch, shiftstate, k);
		fprintf(stdout, "\n%s", buf);
	}
#endif
	return ch;
}