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.

155 lines
3.0 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /*
  4. This program reads NT SETUP INF files and removes:
  5. o blank lines
  6. o lines whose first non-white-space character is ';'
  7. o all data after and including a non-quoted ';'
  8. character in a line
  9. Command line:
  10. stripinf <input INF name> <output INF name>
  11. */
  12. #define MAX_CHARACTERS_PER_LINE 1000
  13. #if !defined(TRUE)
  14. #define TRUE 1
  15. #define FALSE 0
  16. #endif
  17. typedef int bool ;
  18. void die ( char * pszMsg )
  19. {
  20. fprintf( stderr, "STRIPINF error: %s", pszMsg ) ;
  21. exit(3);
  22. }
  23. int processInf ( FILE * fIn, FILE * fOut )
  24. {
  25. char chLine [ MAX_CHARACTERS_PER_LINE ] ;
  26. char * pch,
  27. * pchComment ;
  28. bool bKeep,
  29. bQuote,
  30. bStop ;
  31. for ( ; (! feof(fIn)) && (pch = fgets( chLine, sizeof chLine, fIn )) ; )
  32. {
  33. bStop = bQuote = bKeep = FALSE ;
  34. pchComment = NULL ;
  35. for ( ; *pch && (! bStop) ; pch++ )
  36. {
  37. switch ( *pch )
  38. {
  39. case '\n':
  40. bStop = TRUE ;
  41. break ;
  42. case '\0':
  43. die( "input line longer than 1000 characters" ) ;
  44. break ;
  45. case '\"':
  46. bQuote = ! bQuote ;
  47. bKeep = TRUE ;
  48. break ;
  49. case ' ':
  50. case '\t':
  51. break ;
  52. case ';':
  53. if ( bQuote )
  54. break ;
  55. if ( bKeep )
  56. {
  57. *pch++ = '\n' ;
  58. *pch = '\0' ;
  59. }
  60. bStop = TRUE ;
  61. break ;
  62. case 0x1a: /* control-Z */
  63. *pch = '\0';
  64. break;
  65. default:
  66. bKeep = TRUE ;
  67. break ;
  68. }
  69. }
  70. if ( bKeep )
  71. {
  72. if ( fputs( chLine, fOut ) == EOF )
  73. die("failure writing output file") ;
  74. }
  75. }
  76. return TRUE ;
  77. }
  78. int
  79. __cdecl
  80. main ( int argc, char * argv[], char * envp[] )
  81. {
  82. int i ;
  83. char * pchIn = NULL,
  84. * pchOut = NULL,
  85. chOpt ;
  86. FILE * fIn, * fOut ;
  87. for ( i = 1 ; argv[i] ; i++ )
  88. {
  89. switch ( chOpt = argv[i][0] )
  90. {
  91. case '-':
  92. case '/':
  93. die( "invalid option" ) ;
  94. break;
  95. default:
  96. if ( pchIn == NULL )
  97. pchIn = argv[i] ;
  98. else
  99. if ( pchOut == NULL )
  100. pchOut = argv[i] ;
  101. else
  102. die( "too many file specifications" ) ;
  103. break;
  104. }
  105. }
  106. if ( pchIn == NULL || pchOut == NULL )
  107. die( "too few file specifications" ) ;
  108. fIn = fopen( pchIn, "r" ) ;
  109. if ( ! fIn )
  110. die( "input file failed to open" ) ;
  111. fOut = fopen( pchOut, "w" );
  112. if ( ! fOut )
  113. die( "output file failed to open" );
  114. if ( ! processInf( fIn, fOut ) )
  115. die( "internal failure in processing" );
  116. fclose( fOut ) ;
  117. fclose( fIn ) ;
  118. return 0 ;
  119. }
  120. // End of STRIPINF.C