Esempio n. 1
0
// Password prompt
bool PasswordPrompt(char *password, UINT size)
{
	UINT wp;
	bool escape = false;
	void *console;
	// Validate arguments
	if (password == NULL || size <= 1)
	{
		if (size >= 1)
		{
			password[0] = 0;
		}
		return false;
	}

	wp = 0;

	Zero(password, size);

	console = SetConsoleRaw();

	while (true)
	{
		int c;

#ifdef	OS_WIN32
		c = getch();
#else	// OS_WIN32
		c = getc(stdin);
#endif	// OS_WIN32

		if (c >= 0x20 && c <= 0x7E)
		{
			// Character
			if ((wp + 1) < size)
			{
				password[wp++] = (char)c;
				putc('*', stdout);
			}
		}
		else if (c == 0x03)
		{
			// Break
			exit(0);
		}
		else if (c == 0x04 || c == 0x1a || c == 0x0D || c==0x0A)
		{
			// Exit
			if (c == 0x04 || c == 0x1a)
			{
				escape = true;
			}
			break;
		}
		else if (c == 0xE0)
		{
			// Read one more character
			c = getch();
			if (c == 0x4B || c == 0x53)
			{
				// Backspace
				goto BACKSPACE;
			}
		}
		else if (c == 0x08)
		{
BACKSPACE:
			// Backspace
			if (wp >= 1)
			{
				password[--wp] = 0;
				putc(0x08, stdout);
				putc(' ', stdout);
				putc(0x08, stdout);
			}
		}
	}
	Print("\n");

	RestoreConsole(console);

	return (escape ? false : true);
}
Esempio n. 2
0
int _tmain(int argc, char **argv)
{
	int i;
	TCHAR lpStr[80];

	for (i = 0; i < 80; i++)
		lpEmpty[i] = lpHeader[i] = _T(' ');
	lpEmpty[79] = _T('\0');

	/* Initialize global variables */
	hInst = 0 /* FIXME: which value? [used with LoadString(hInst, ..., ..., ...)] */;

	if (LoadString(hInst, IDS_COLUMN_NUMBER, lpStr, 80))
	{
		columnRightPositions[0] = _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[2], lpStr, _tcslen(lpStr));
	}
	if (LoadString(hInst, IDS_COLUMN_IMAGENAME, lpStr, 80))
	{
		columnRightPositions[1] = columnRightPositions[0] + _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[columnRightPositions[0] + 2], lpStr, _tcslen(lpStr));
	}
	if (LoadString(hInst, IDS_COLUMN_PID, lpStr, 80))
	{
		columnRightPositions[2] = columnRightPositions[1] + _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[columnRightPositions[1] + 2], lpStr, _tcslen(lpStr));
	}
	if (LoadString(hInst, IDS_COLUMN_CPU, lpStr, 80))
	{
		columnRightPositions[3] = columnRightPositions[2] + _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[columnRightPositions[2] + 2], lpStr, _tcslen(lpStr));
	}
	if (LoadString(hInst, IDS_COLUMN_MEM, lpStr, 80))
	{
		columnRightPositions[4] = columnRightPositions[3] + _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[columnRightPositions[3] + 2], lpStr, _tcslen(lpStr));
	}
	if (LoadString(hInst, IDS_COLUMN_PF, lpStr, 80))
	{
		columnRightPositions[5] = columnRightPositions[4] + _tcslen(lpStr) + 3;
		_tcsncpy(&lpHeader[columnRightPositions[4] + 2], lpStr, _tcslen(lpStr));
	}

	for (i = 0; i < columnRightPositions[5]; i++)
		lpSeparator[i] = _T('-');
	lpHeader[0] = _T('|');
	lpSeparator[0] = _T('+');
	for (i = 0; i < 6; i++)
	{
		lpHeader[columnRightPositions[i]] = _T('|');
		lpSeparator[columnRightPositions[i]] = _T('+');
	}
	lpSeparator[columnRightPositions[5] + 1] = _T('\0');
	lpHeader[columnRightPositions[5] + 1] = _T('\0');


	if (!LoadString(hInst, IDS_APP_TITLE, lpTitle, 80))
		lpTitle[0] = _T('\0');
	if (!LoadString(hInst, IDS_COLUMN_MEM_UNIT, lpMemUnit, 3))
		lpMemUnit[0] = _T('\0');
	if (!LoadString(hInst, IDS_MENU, lpMenu, 80))
		lpMenu[0] = _T('\0');
	if (!LoadString(hInst, IDS_IDLE_PROCESS, lpIdleProcess, 80))
		lpIdleProcess[0] = _T('\0');

	if (LoadString(hInst, IDS_MENU_QUIT, lpStr, 2))
		KEY_QUIT = lpStr[0];
	if (LoadString(hInst, IDS_MENU_KILL_PROCESS, lpStr, 2))
		KEY_KILL = lpStr[0];
	if (LoadString(hInst, IDS_YES, lpStr, 2))
		KEY_YES = lpStr[0];
	if (LoadString(hInst, IDS_NO, lpStr, 2))
		KEY_NO = lpStr[0];

	GetInputOutputHandles();

	if (hStdin == INVALID_HANDLE_VALUE || hStdout == INVALID_HANDLE_VALUE)
	{
		if (LoadString(hInst, IDS_CTM_GENERAL_ERR1, lpStr, 80))
			_tprintf(lpStr);
		return -1;
	}

	if (GetConsoleMode(hStdin, &inConMode) == 0)
	{
		if (LoadString(hInst, IDS_CTM_GENERAL_ERR2, lpStr, 80))
			_tprintf(lpStr);
		return -1;
	}

	if (GetConsoleMode(hStdout, &outConMode) == 0)
	{
		if (LoadString(hInst, IDS_CTM_GENERAL_ERR3, lpStr, 80))
			_tprintf(lpStr);
		return -1;
	}

	SetConsoleMode(hStdin, 0); //FIXME: Should check for error!
	SetConsoleMode(hStdout, 0); //FIXME: Should check for error!

	PerfInit();

	while (1)
	{
		DWORD numEvents;

		PerfDataRefresh();
		DisplayScreen();

		/* WaitForSingleObject for console handles is not implemented in ROS */
		WaitForSingleObject(hStdin, 1000);
		GetNumberOfConsoleInputEvents(hStdin, &numEvents);

		if (numEvents > 0)
		{
			if (ProcessKeys(numEvents) == TRUE)
				break;
		}
	}

	RestoreConsole();
	return 0;
}
Esempio n. 3
0
void doSameSession()
{
 char *arg;
 RESULTCODES rc;
 int i,j;

 if (progtitle)
  SetConsoleTitle(progtitle);

 if (fForegroundConsole)
  SelectConsole();

 if (fConsoleSize)
  SetConsoleSize(Console.W, Console.H, colSAME);

 if (fFontSet)
 {
  RECTL r;
  LockConsoleUpdate();
  SetConsoleFontSize(Font.H, Font.W);
  if (fResizeWindowToMax && !fExplicitSize)
   SetMaxConsoleSize();

  // Workaround: NPS WPS does not redraw window shadow when window grows :-(
  GetPixelConsoleSize((int *)&r.xLeft, (int *)&r.yBottom, (int *)&r.xRight, (int *)&r.yTop);
  r.xRight += r.xLeft + 8; r.yTop += r.yBottom + 8;
  r.xLeft -= 8; r.yBottom -= 8;
  WinInvalidateRect(HWND_DESKTOP, &r, FALSE);

  UnlockConsoleUpdate();
 } else
 if (fResizeWindowToMax && !fExplicitSize)
  SetMaxConsoleSize();

 if (fSetBorder)
  SetConsoleBorderSize(Border.W, Border.H);
 if (fSetFlash)
  FlashConsole(fFlashWindow);

 if (fMinimizeConsole)
  MinimizeConsole();
 else if (fMaximizeConsole)
  MaximizeConsole();

 if (GetWindowHWND())
 {
  if ((fExplicitPos || fExplicitSize))
   SetPixelConsoleSize(ConsolePos.X, ConsolePos.Y, ConsolePos.W, ConsolePos.H,
    (fExplicitPos ? SWP_MOVE : 0) | (fExplicitSize ? SWP_SIZE : 0));
  else if (fMaximizeConsole)
   SetPixelConsoleSize(ConsolePos.X, ConsolePos.Y, 0, 0, SWP_MOVE);
 }

 if (fHideConsole)
  ShowConsole(FALSE);
 else if (fShowConsole)
  ShowConsole(TRUE);

 if (fRestoreConsole)
  RestoreConsole();

 if (!progname) return;
 if (!progname[0]) progname = getenv("COMSPEC");
 if (progname) i = strlen(progname); else i = 0;
 j = i; i++;
 if (progargs) i+= strlen(progargs);
 arg = malloc(i);

 if (progname) strcpy(arg, progname); else arg[0] = 0;
 strcat(arg, "*");
 if (progargs) strcat(arg, progargs);
 arg[j] = 0;

 ReleaseINI();
 if (DosExecPgm(NULL, 0, EXEC_SYNC, arg, NULL, &rc, progname))
 {
  SetColor(colLRED, colSAME);
  printf("Error running command %s\n", progname);
  if (_isterm(1)) getch();
  return;
 }
}