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.

102 lines
1.5 KiB

  1. /*
  2. stripper: strips asm comments, blanks lines, and spurious spaces
  3. (except spaces following the exception strings, listed below.)
  4. */
  5. #include <stdio.h>
  6. char *
  7. ScanWhite( ps )
  8. char **ps;
  9. {
  10. char *s = *ps;
  11. while (*s != ' ' && *s != '\t' && *s)
  12. s++;
  13. *ps = s;
  14. if (*s)
  15. return s;
  16. else
  17. return NULL;
  18. }
  19. char *
  20. SkipWhite( ps )
  21. char **ps;
  22. {
  23. char *s = *ps;
  24. while (*s == ' ' || *s == '\t')
  25. s++;
  26. *ps = s;
  27. if (*s)
  28. return s;
  29. else
  30. return NULL;
  31. }
  32. char inBuf[ 256 ];
  33. char outBuf[ 256 ];
  34. main()
  35. {
  36. char
  37. *inStr,
  38. *outStr,
  39. *str;
  40. int inLen,
  41. outLen,
  42. tabcnt;
  43. long totSaved = 0L;
  44. unlink( "cmacros.bak" ); /* */
  45. rename( "cmacros.bak", "cmacros.inc" ); /* */
  46. freopen( "cmacros.mas", "r", stdin ); /* */
  47. freopen( "cmacros.inc", "w", stdout ); /* */
  48. fprintf( stderr, "cmacros.mas => cmacros.inc" );
  49. fflush( stderr );
  50. while (inStr = gets( inBuf ))
  51. {
  52. inLen = strlen( inBuf );
  53. outStr = outBuf;
  54. tabcnt=0;
  55. if (inBuf[inLen-1] == '@')
  56. tabcnt=1;
  57. while (SkipWhite( &inStr ))
  58. {
  59. if (*inStr == ';')
  60. break;
  61. str = inStr;
  62. ScanWhite( &inStr );
  63. if (tabcnt > 0 && tabcnt < 3)
  64. {
  65. *outStr++ = '\t';
  66. tabcnt++;
  67. }
  68. else
  69. {
  70. if (outStr != outBuf)
  71. *outStr++ = ' ';
  72. }
  73. while (str != inStr)
  74. *outStr++ = *str++;
  75. }
  76. if (outLen = outStr - outBuf)
  77. {
  78. *outStr++ = 0;
  79. puts( outBuf );
  80. }
  81. totSaved += (inLen - outLen);
  82. }
  83. fprintf( stderr, " [OK] %ld blanks stripped\n", totSaved );
  84. exit( 0 );
  85. }