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.

148 lines
2.9 KiB

  1. /*++
  2. NONNULL.C
  3. Code for finding unused OPT_NONNULLs
  4. Copyright (C) 1997 Microsoft Corporation
  5. Created, 6/10/1997 by DavidCHR
  6. --*/
  7. #include "private.h"
  8. BOOL
  9. FindUnusedOptions( optionStruct *options,
  10. ULONG flags,
  11. /* OPTIONAL */ PCHAR prefix,
  12. PSAVEQUEUE pQueue ) {
  13. PCHAR newprefix;
  14. BOOL freeprefix;
  15. BOOL ret = TRUE;
  16. ULONG i;
  17. for ( i = 0 ; !ARRAY_TERMINATED( options+i ); i++ ) {
  18. if ( ( options[i].flags & OPT_MUTEX_MASK ) == OPT_SUBOPTION ) {
  19. OPTIONS_DEBUG( "%s: OPT_SUBSTRUCT. ", options[i].cmd );
  20. if (options[i].flags & OPT_RECURSE ) {
  21. /* suboptions must be reparsed. we recurse on this structure,
  22. copying the prefix into a newly allocated buffer. */
  23. OPTIONS_DEBUG( "descending into substructure.\n" );
  24. /* allocate the new prefix */
  25. if ( prefix ) {
  26. /* oldprefix:optionname = newprefix */
  27. newprefix = (PCHAR) malloc( ( strlen( prefix ) +
  28. strlen( options[i].cmd ) +
  29. 2 /* : and \0 */ ) *
  30. sizeof( CHAR ) );
  31. if ( !newprefix ) {
  32. fprintf( stderr, "Failed to allocate new prefix-- cannot "
  33. "parse suboption %s:%s.\n", prefix, options[i].cmd );
  34. return FALSE;
  35. }
  36. sprintf( newprefix, "%s:%s", prefix, options[i].cmd );
  37. freeprefix = TRUE;
  38. } else {
  39. /* optionname = prefix */
  40. newprefix = options[i].cmd;
  41. freeprefix = FALSE;
  42. }
  43. ASSERT( newprefix != NULL );
  44. if ( !FindUnusedOptions( POPTU_CAST( options[i] )->optStruct,
  45. flags,
  46. newprefix,
  47. pQueue ) ) {
  48. ret = FALSE;
  49. }
  50. if ( freeprefix ) {
  51. free( newprefix );
  52. }
  53. } else {
  54. OPTIONS_DEBUG( "!OPT_RECURSE, so not descending.\n" );
  55. }
  56. continue;
  57. }
  58. if ( ( options[i].flags & OPT_NONNULL ) ||
  59. ( options [i].flags & OPT_ENVIRONMENT ) ) {
  60. OPTIONS_DEBUG( "%s: OPT_NONNULL or OPT_ENV. pointer is 0x%x, ",
  61. options[i].cmd,
  62. POPTU_CAST( options[i] )->raw_data );
  63. if ( *(POPTU_CAST( options[i] )->raw_data) == NULL ) {
  64. OPTIONS_DEBUG( " *= NULL.\n" );
  65. if ( ( options[i].flags & OPT_ENVIRONMENT ) &&
  66. StoreEnvironmentOption( options+i, flags, pQueue ) ) {
  67. OPTIONS_DEBUG( "found environment variable for %s...",
  68. options[i].cmd );
  69. } else if ( options[i].flags & OPT_NONNULL ) {
  70. if ( prefix ) {
  71. fprintf( stderr,
  72. "option %s:%s must be specified and is missing.\n",
  73. prefix, options[i].cmd );
  74. } else {
  75. fprintf( stderr,
  76. "option %s must be specified and is missing.\n",
  77. options[i].cmd );
  78. }
  79. ret = FALSE;
  80. }
  81. } else {
  82. OPTIONS_DEBUG( "data is not null.\n" );
  83. }
  84. }
  85. #if 0 // not really necessary debug info.
  86. else if ( options[i].cmd ) {
  87. OPTIONS_DEBUG( "%s is ok.\n", options[i].cmd );
  88. }
  89. #endif
  90. }
  91. return ret;
  92. }