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.

132 lines
2.6 KiB

  1. /***
  2. *NMKtoBAT.C - convert NMAKE.EXE output into a Windows 9x batch file
  3. *
  4. * Copyright (c) 1995-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * The makefiles provided with the Microsoft Visual C++ (C/C++) Run-Time
  8. * Library Sources generate commands with multiple commands per line,
  9. * separated by ampersands (&). This program will convert such a
  10. * text file into a batch file which can be executed by the Windows 9x
  11. * command interpreter (COMMAND.COM) which does not recognize multiple
  12. * commands on a single line.
  13. *
  14. *******************************************************************************/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. int main(int argc, char **argv);
  19. #define MAXLINE 4096
  20. char InBuf [ MAXLINE ] ;
  21. int main(int argc, char **argv)
  22. {
  23. /*
  24. * If any arguments are given, print a usage message and exit
  25. */
  26. if ( argc != 1 || argv [ 1 ] )
  27. {
  28. fprintf ( stderr , "Usage: nmk2bat < input > output\n"
  29. "This program takes no arguments\n" ) ;
  30. exit ( 1 ) ;
  31. }
  32. /*
  33. * Batch file should be terse
  34. */
  35. printf ( "@echo off\n" ) ;
  36. /*
  37. * Process each input line
  38. */
  39. while ( fgets ( InBuf , sizeof ( InBuf ) , stdin ) )
  40. {
  41. char * pStart ;
  42. char * pFinish ;
  43. char * pNextPart ;
  44. pStart = InBuf ;
  45. pFinish = pStart + strlen ( pStart ) ;
  46. /*
  47. * Remove the trailing newline character from the
  48. * input buffer. This simplifies the line processing.
  49. */
  50. if ( pFinish > pStart && pFinish [ -1 ] == '\n' )
  51. pFinish [ -1 ] = '\0' ;
  52. /*
  53. * Process each part of the line. Parts are delimited
  54. * by ampersand characters with optional whitespace.
  55. */
  56. do
  57. {
  58. /*
  59. * Skip initial whitespace
  60. */
  61. while ( * pStart == ' ' || * pStart == '\t' )
  62. ++ pStart ;
  63. /*
  64. * Find the next command separator or
  65. * the end of line, whichever comes first
  66. */
  67. pNextPart = strchr ( pStart , '&' ) ;
  68. if ( ! pNextPart )
  69. pNextPart = pStart + strlen ( pStart ) ;
  70. pFinish = pNextPart ;
  71. /*
  72. * Skip blank lines and blank parts of lines
  73. */
  74. if ( pStart == pNextPart )
  75. break ;
  76. /*
  77. * Skip the trailing whitespace
  78. */
  79. while ( pFinish > pStart
  80. && ( pFinish [ -1 ] == ' ' || pFinish [ -1 ] == '\t' ) )
  81. -- pFinish ;
  82. /*
  83. * Copy to stdout the characters between
  84. * the skipped initial whitespace and
  85. * the skipped trailing whitespace
  86. */
  87. while ( pStart < pFinish )
  88. putchar ( * pStart ++ ) ;
  89. putchar ( '\n' ) ;
  90. /*
  91. * We are done with this line when pNextPart
  92. * points to a null character (rather than a '&').
  93. */
  94. pStart = pNextPart ;
  95. } while ( * pStart ++ ) ;
  96. }
  97. return 0 ;
  98. }