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.

151 lines
3.4 KiB

  1. /*++
  2. SUBLIST.C
  3. Code for parsing a suboption list
  4. DavidCHR 6/6/1997
  5. --*/
  6. #include "private.h"
  7. /*
  8. ParseSublist:
  9. Handler code for parsing a sublist entry.
  10. */
  11. BOOL
  12. ParseSublist( POPTU Option,
  13. PCHAR *argv,
  14. int argc,
  15. int theIndex,
  16. int *argsused,
  17. ULONG flags,
  18. PBOOL pbDoneParsing,
  19. PSAVEQUEUE pQueue ) {
  20. PCHAR TheOption;
  21. ULONG i;
  22. ASSERT( Option != NULL );
  23. ASSERT( argv != NULL );
  24. ASSERT( argc != 0 );
  25. ASSERT( theIndex < argc );
  26. OPTIONS_DEBUG( "ParseSublist: Option = 0x%x, argv=0x%x, "
  27. "argc=%d, theIndex=%d",
  28. Option, argv, argc, theIndex );
  29. TheOption = argv[ theIndex ];
  30. OPTIONS_DEBUG( "TheOption = [%d] %s... ", theIndex, TheOption );
  31. for ( i = 0 ; TheOption[i] != ':' ; i++ ) {
  32. if ( TheOption[i] == '\0' ) {
  33. fprintf( stderr,
  34. "ParseOptions: %s should be of the form "
  35. "%s:option (:option:option...)\n",
  36. TheOption, TheOption );
  37. return FALSE;
  38. }
  39. }
  40. ASSERT( TheOption[i] == ':' ); /* algorithm check */
  41. if ( !ISSWITCH( TheOption[0] ) ) {
  42. /* The easy side--
  43. just send the argc and argv structure in, MANGLING
  44. the first option */
  45. /* we do not deal with pbStopParsing in this branch, because it seems
  46. somehow unlikely that deep down in a nested substructure, someone
  47. would bury an option like this:
  48. opt:foo:bar:baz:terminate
  49. to stop the toplevel parser. */
  50. OPTIONS_DEBUG( "ISSWITCH: easy case (%c is not a switch)",
  51. TheOption[0] );
  52. ASSERT( argv[ theIndex ][i] == ':' );
  53. argv[ theIndex ] += i+1;
  54. ASSERT( argv[ theIndex ][0] != ':' );
  55. return ParseOptionsEx( argc-theIndex,
  56. argv+theIndex,
  57. Option->optStruct,
  58. flags | OPT_FLAG_MEMORYLIST_OK,
  59. &pQueue,
  60. NULL, NULL );
  61. } else {
  62. /* The Hard part--
  63. create a new vector of argv, pointing the first at the local buffer.
  64. Since the first buffer PROBABLY won't be used as a string
  65. (NOTE: if it's OPT_DEFAULT, it could be), it's safe to use this
  66. on the stack. */
  67. PCHAR *newargv;
  68. ULONG j;
  69. ULONG total; /* total elements in the new list */
  70. CHAR LocalBuffer[ 255 ];
  71. BOOL ret;
  72. int tmp;
  73. OPTIONS_DEBUG( "Hard case (%c is a switch): ", TheOption[0] );
  74. sprintf( LocalBuffer, "%c%s",
  75. TheOption[0],
  76. TheOption+i+1 );
  77. OPTIONS_DEBUG( "LocalBuffer = %s\n", LocalBuffer );
  78. total = argc - theIndex ; /* 2? */
  79. newargv = malloc( total * sizeof(PCHAR) );
  80. if (!newargv) {
  81. fprintf(stderr, "Failed to allocate memory in ParseOptions\n");
  82. return 0;
  83. }
  84. newargv[0] = LocalBuffer;
  85. for( j = 1 ; j < total ; j++ ) {
  86. OPTIONS_DEBUG( "j == %d, total == %d\n", j, total );
  87. ASSERT( argv[j] != NULL );
  88. ASSERT( (int)(j+theIndex) < argc );
  89. newargv[j] = argv[j+theIndex ];
  90. OPTIONS_DEBUG( "assign [%d] %s --> [%d] %s\n",
  91. j+theIndex, argv[j+theIndex],
  92. j, newargv[j] );
  93. }
  94. ret = ParseOneOption( total, newargv, 0 /* parse the first option */,
  95. flags, Option->optStruct, argsused, pbDoneParsing,
  96. pQueue );
  97. free( newargv );
  98. OPTIONS_DEBUG( "done. returning %d...\n", ret );
  99. return ret;
  100. }
  101. }