Source code of Windows XP (NT5)
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.

217 lines
5.9 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*******************************************************************************
  3. *
  4. * OPTIONS.C
  5. * This module contains routines to parse the command line
  6. *
  7. * Copyright Citrix Systems Inc. 1992
  8. *
  9. * Author: Kurt Perry
  10. *
  11. *
  12. *******************************************************************************/
  13. /* Get the standard C includes */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include "options.h"
  18. /*=============================================================================
  19. == Functions Defined
  20. =============================================================================*/
  21. int OptionsParse( int, char * [] );
  22. static void OptionsHelp( char );
  23. /*=============================================================================
  24. == Functions Used
  25. =============================================================================*/
  26. /*=============================================================================
  27. == External data
  28. =============================================================================*/
  29. /******************************************************************************
  30. *
  31. * OptionsParse
  32. *
  33. * ENTRY:
  34. * argc (input)
  35. * number of arguments
  36. * argv (input)
  37. * pointer to arguments
  38. *
  39. * EXIT:
  40. * nothing
  41. *
  42. *****************************************************************************/
  43. int
  44. OptionsParse( int argc, char * argv[] )
  45. {
  46. int fBadParm = FALSE;
  47. int i, j;
  48. int len;
  49. char * p;
  50. int place = -1;
  51. unsigned int test;
  52. char foundq = FALSE; //found the /Q switch
  53. char foundother = FALSE; //found any of the integer switches
  54. char founddefaults = FALSE; //found the /Defaults switch
  55. char foundStartMon = FALSE; //found the /StartMonitor switch
  56. /*
  57. * Look for command line switches
  58. */
  59. for ( i=1; (i < argc) && !foundStartMon; i++ ) {
  60. /*
  61. * A command line switch?
  62. */
  63. switch ( argv[i][0] ) {
  64. case '-':
  65. case '/':
  66. ++argv[i];
  67. if ( place != -1 )
  68. fBadParm = TRUE;
  69. place = -1;
  70. for ( j=0; j<ARG_COUNT; j++ ) {
  71. p = options[j].option;
  72. len = strlen(p);
  73. if ( !strnicmp( argv[i], p, len ) ) {
  74. // if args separated by blanks hold place
  75. if ( strlen( &argv[i][len] ) == 0 )
  76. place = (options[j].optype & (OP_STRING|OP_UINT)) ? j : -1;
  77. // string option
  78. if ( (options[j].optype & OP_STRING) )
  79. *(options[j].string) = &argv[i][len];
  80. // boolean option
  81. //add code to check for /q, /defaults, and /startmonitor switch
  82. if ( (options[j].optype & OP_BOOL) ) {
  83. *(options[j].bool) = (char) TRUE;
  84. if (!strnicmp(p,"Q",len)) {
  85. foundq = TRUE;
  86. }
  87. else if (!strnicmp(p,"Defaults",len)) {
  88. founddefaults = TRUE;
  89. }
  90. else if (!strnicmp(p,"StartMonitor",len)) {
  91. foundStartMon = TRUE;
  92. }
  93. }
  94. // int option
  95. if ( (options[j].optype & OP_UINT) ) {
  96. //original code
  97. // *(options[j].unint) = (unsigned int) atoi(&argv[i][len]);
  98. //new code to check for out of bounds and to make sure
  99. //that don't only use /Q switch
  100. test = (unsigned int) atoi(&argv[i][len]);
  101. if (test > 32767) {
  102. fBadParm = TRUE;
  103. }
  104. *(options[j].unint) = test;
  105. foundother = TRUE;
  106. }
  107. goto ok;
  108. }
  109. }
  110. fBadParm = TRUE;
  111. ok:
  112. break;
  113. default:
  114. fBadParm = TRUE;
  115. #if 0
  116. // options separated by space
  117. if ( place != -1 ) {
  118. if ( (options[place].optype & OP_STRING) )
  119. *(options[place].string) = argv[i];
  120. else
  121. *(options[place].unint) = (unsigned int) atoi(argv[i]);
  122. place = -1;
  123. break;
  124. }
  125. // free( pOptionEntry->pLabel );
  126. // pOptionEntry->pLabel = strdup( argv[i] );
  127. #endif
  128. break;
  129. }
  130. }
  131. // printf("fHelp=%u,fBadParm=%u,place=%u\n",fHelp,fBadParm,place);
  132. /*
  133. * Check for help or any detected command line errors
  134. */
  135. //change code to check consistancy of /q and /defaults
  136. if ( fHelp || fBadParm || (place != -1) ||
  137. (founddefaults && foundother) ||
  138. (foundq && !foundother && !founddefaults ) ) {
  139. OptionsHelp(fHelp);
  140. return(1); //failure
  141. }
  142. return(0);
  143. }
  144. /******************************************************************************
  145. *
  146. * OptionsHelp
  147. *
  148. * Display help on command line options
  149. *
  150. * ENTRY:
  151. * nothing
  152. *
  153. * EXIT:
  154. * nothing
  155. *
  156. *****************************************************************************/
  157. static void
  158. OptionsHelp(char bVerbose)
  159. {
  160. int i;
  161. /*
  162. * Display help header
  163. */
  164. printf("DOSKBD is used to tune the DOS Keyboard Polling Detection Algorithm\n");
  165. printf(" for a specific DOS execution environment (window).\n");
  166. printf("DOSKBD\n");
  167. printf("DOSKBD /DEFAULTS [/Q]\n");
  168. printf("DOSKBD [/DETECTPROBATIONCOUNT:nnn] [/INPROBATIONCOUNT:nnn] [/MSALLOWED:nnn]\n");
  169. printf(" [/MSSLEEP:nnn] [/BUSYMSALLOWED:nnn] [/MSPROBATIONTRIAL:nnn]\n");
  170. printf(" [/MSGOODPROBATIONEND:nnn] [/DETECTIONINTERVAL:nnn]\n");
  171. printf(" [/STARTMONITOR [appname] | /STOPMONITOR] [/Q]\n\n");
  172. printf("DOSKBD displays new/current settings unless /Q is used.\n");
  173. printf("Valid range for all values (represented by nnn) is 0 to 32767.\n");
  174. if (bVerbose) {
  175. /*
  176. * Display help message, pausing each page
  177. */
  178. for ( i=0; i<ARG_COUNT; i++ ) {
  179. // message
  180. printf( "%s\n", options[i].help );
  181. }
  182. }
  183. }