Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ws.c
  5. Abstract:
  6. Utility program to set both the console window size and buffer size.
  7. Author:
  8. Steve Wood (stevewo) 01-Feb-1992
  9. Revision History:
  10. --*/
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <errno.h>
  15. #include <ctype.h>
  16. #include <string.h>
  17. void
  18. Usage()
  19. {
  20. printf("Usage: ws [-w WindowColumns,WindowRows][-b BufferColumns,BufferRows]\n");
  21. exit(1);
  22. }
  23. __cdecl main( argc, argv )
  24. int argc;
  25. char *argv[];
  26. {
  27. int i;
  28. char *s;
  29. HANDLE ScreenHandle;
  30. DWORD WindowRows,WindowColumns;
  31. DWORD BufferRows,BufferColumns;
  32. COORD BufferSize;
  33. CONSOLE_SCREEN_BUFFER_INFO sbi;
  34. SMALL_RECT WindowSize;
  35. COORD LargestScreenSize;
  36. USHORT MaxRows;
  37. USHORT MaxCols;
  38. ScreenHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  39. if (!GetConsoleScreenBufferInfo( ScreenHandle, &sbi )) {
  40. fprintf( stderr, "WS: Unable to read current console mode.\n" );
  41. exit( 1 );
  42. }
  43. BufferRows = sbi.dwSize.Y;
  44. BufferColumns = sbi.dwSize.X;
  45. WindowRows = sbi.srWindow.Bottom - sbi.srWindow.Top + 1;
  46. WindowColumns = sbi.srWindow.Right - sbi.srWindow.Left + 1;
  47. LargestScreenSize = GetLargestConsoleWindowSize( ScreenHandle );
  48. try {
  49. for (i=1; i<argc; i++) {
  50. s = argv[ i ];
  51. if (*s == '-' || *s == '/') {
  52. s++;
  53. switch( tolower( *s ) ) {
  54. //
  55. // Set window size
  56. //
  57. case 'w':
  58. if (sscanf( argv[++i], "%d,%d", &WindowColumns, &WindowRows ) != 2) {
  59. printf("Invalid usage\n");
  60. Usage();
  61. }
  62. break;
  63. //
  64. // Set buffer size
  65. //
  66. case 'b':
  67. if (sscanf( argv[++i], "%d,%d", &BufferColumns, &BufferRows ) != 2) {
  68. printf("Invalid usage\n");
  69. Usage();
  70. }
  71. break;
  72. default:
  73. Usage();
  74. }
  75. }
  76. else {
  77. printf( "Error - argv[ %u ]: %s\n", i, argv[ i ] );
  78. Usage();
  79. }
  80. }
  81. }
  82. except ( EXCEPTION_EXECUTE_HANDLER ) {
  83. Usage();
  84. }
  85. MaxRows = (USHORT)min( (int)WindowRows, (int)(sbi.dwSize.Y) );
  86. MaxRows = (USHORT)min( (int)MaxRows, (int)LargestScreenSize.Y );
  87. MaxCols = (USHORT)min( (int)WindowColumns, (int)(sbi.dwSize.X) );
  88. MaxCols = (USHORT)min( (int)MaxCols, (int)LargestScreenSize.X );
  89. WindowSize.Top = 0;
  90. WindowSize.Left = 0;
  91. WindowSize.Bottom = MaxRows - (SHORT)1;
  92. WindowSize.Right = MaxCols - (SHORT)1;
  93. SetConsoleWindowInfo( ScreenHandle, TRUE, &WindowSize );
  94. BufferSize.X = (SHORT)BufferColumns;
  95. BufferSize.Y = (SHORT)BufferRows;
  96. SetConsoleScreenBufferSize( ScreenHandle, BufferSize );
  97. printf( "WS -w %d,%d -b %d,%d\n", MaxCols, MaxRows, BufferColumns, BufferRows );
  98. return( 0 );
  99. }