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.

135 lines
2.6 KiB

  1. /**
  2. * StripLines - strips a text file (usually a Makefile) of
  3. * Microsoft-proprietary or other specialized parts
  4. *
  5. * Programmed by Steve Salisbury, Thu 18 May 1995
  6. *
  7. * Fri 19 May 1995 -- add code to skips lines containing STRIPLIN!
  8. * Add line numbers to diagnostic messages
  9. * Flag redundant STRIPLIN= directives (which are an error)
  10. *
  11. * This program just copies stdin to stdout. Depending on the
  12. * value of a global state variable, some lines may be ignored.
  13. *
  14. * ... STRIPLIN=0 ...
  15. * turns off line-by-line copying until STRIPLIN=1 or STRIPLIN=2
  16. * is encountered, at which point lines will be copied again.
  17. * ... STRIPLIN=1 ...
  18. * turns on line-by-line copying (initial state)
  19. * ... STRIPLIN=2 ...
  20. * turns on line-by-line copying with deletion of
  21. * initial # on each line (if there is one). If
  22. * an input line has no initial #, it is copied as-is.
  23. * ... STRIPLIN! ...
  24. * this single line is not copied (regardless of the 0/1/2 state)
  25. **/
  26. /**
  27. *
  28. * Header Files
  29. *
  30. **/
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. /**
  35. *
  36. * Global Constants
  37. *
  38. **/
  39. #define MAXLINELEN 4096
  40. /**
  41. *
  42. * Global Variables
  43. *
  44. **/
  45. char InputLine [ MAXLINELEN ] ;
  46. char ControlString[ ] = "STRIPLIN=" ;
  47. char DeleteString[ ] = "STRIPLIN!" ;
  48. /**
  49. *
  50. * Function Declarations (Prototypes)
  51. *
  52. **/
  53. int main ( int argc , char * argv [ ] ) ;
  54. /**
  55. *
  56. * Function Definitions (Implementations)
  57. *
  58. **/
  59. int main ( int argc , char * argv [ ] )
  60. {
  61. int StateFlag = 1 ;
  62. int LineNumber = 0 ;
  63. while ( fgets ( InputLine , sizeof ( InputLine ) , stdin ) )
  64. {
  65. char * pString ;
  66. ++ LineNumber ;
  67. if ( pString = strstr ( InputLine , ControlString ) )
  68. {
  69. int NewStateFlag ;
  70. NewStateFlag = pString [ strlen ( ControlString ) ] - '0' ;
  71. if ( NewStateFlag < 0 || 2 < NewStateFlag )
  72. {
  73. fprintf ( stderr , "striplin: invalid directive:\n%d:\t%s\n" ,
  74. LineNumber , InputLine ) ;
  75. exit ( 1 ) ;
  76. }
  77. if ( NewStateFlag == StateFlag )
  78. {
  79. fprintf ( stderr , "striplin: redundant directive:\n%d:\t%s\n" ,
  80. LineNumber , InputLine ) ;
  81. exit ( 1 ) ;
  82. }
  83. StateFlag = NewStateFlag ;
  84. }
  85. else if ( StateFlag != 0 )
  86. {
  87. char * start = InputLine ;
  88. /*-
  89. * If StateFlag is 2 and the line begins with #, skip the #
  90. -*/
  91. if ( StateFlag == 2 && * start == '#' )
  92. start ++ ;
  93. /*-
  94. * Echo lines that do not contain the delete string
  95. -*/
  96. if ( ! strstr ( start , DeleteString ) )
  97. fputs ( start , stdout ) ;
  98. }
  99. }
  100. if ( fflush ( stdout ) )
  101. {
  102. fprintf ( stderr , "striplin: Error flushing standard output\n" ) ;
  103. exit ( 1 ) ;
  104. }
  105. return 0 ;
  106. }