home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / nmktobat.c < prev    next >
C/C++ Source or Header  |  1998-06-16  |  3KB  |  133 lines

  1. /***
  2. *NMKtoBAT.C - convert NMAKE.EXE output into a Windows 95 batch file
  3. *
  4. *       Copyright (c) 1995, 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 95
  11. *    command interpreter (COMMAND.COM) which does not recognize multiple
  12. *    commands on a single line.
  13. *
  14. *******************************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20.  
  21. int main(int argc, char **argv);
  22.  
  23.  
  24. #define MAXLINE    4096
  25.  
  26. char InBuf [ MAXLINE ] ;
  27.  
  28.  
  29. int main(int argc, char **argv)
  30. {
  31.     /*
  32.      * If any arguments are given, print a usage message and exit
  33.      */
  34.  
  35.     if ( argc != 1 || argv [ 1 ] )
  36.     {
  37.         fprintf ( stderr , "Usage: nmk2bat < input > output\n"
  38.             "This program takes no arguments\n" ) ;
  39.         exit ( 1 ) ;
  40.     }
  41.  
  42.     /*
  43.      * Batch file should be terse
  44.      */
  45.  
  46.     printf ( "@echo off\n" ) ;
  47.  
  48.     /*
  49.      * Process each input line
  50.      */
  51.  
  52.     while ( fgets ( InBuf , sizeof ( InBuf ) , stdin ) )
  53.     {
  54.         char * pStart ;
  55.         char * pFinish ;
  56.         char * pNextPart ;
  57.  
  58.         pStart = InBuf ;
  59.     
  60.         pFinish = pStart + strlen ( pStart ) ;
  61.  
  62.         /*
  63.          * Remove the trailing newline character from the
  64.          * input buffer.  This simplifies the line processing.
  65.          */
  66.  
  67.         if ( pFinish > pStart && pFinish [ -1 ] == '\n' )
  68.             pFinish [ -1 ] = '\0' ;
  69.  
  70.         /*
  71.          * Process each part of the line.  Parts are delimited
  72.          * by ampersand characters with optional whitespace.
  73.          */
  74.  
  75.         do
  76.         {
  77.             /*
  78.              * Skip initial whitespace
  79.              */
  80.  
  81.             while ( * pStart == ' ' || * pStart == '\t' )
  82.                 ++ pStart ;
  83.  
  84.             /*
  85.              * Find the next command separator or
  86.              * the end of line, whichever comes first
  87.              */
  88.  
  89.             pNextPart = strchr ( pStart , '&' ) ;
  90.  
  91.             if ( ! pNextPart )
  92.                 pNextPart = pStart + strlen ( pStart ) ;
  93.         
  94.             pFinish = pNextPart ;
  95.  
  96.             /*
  97.              * Skip blank lines and blank parts of lines
  98.              */
  99.  
  100.             if ( pStart == pNextPart )
  101.                 break ;
  102.             /*
  103.              * Skip the trailing whitespace
  104.              */
  105.  
  106.             while ( pFinish > pStart
  107.             && ( pFinish [ -1 ] == ' ' || pFinish [ -1 ] == '\t' ) )
  108.                 -- pFinish ;
  109.  
  110.             /*
  111.              * Copy to stdout the characters between
  112.              * the skipped initial whitespace and
  113.              * the skipped trailing whitespace
  114.              */
  115.  
  116.             while ( pStart < pFinish )
  117.                 putchar ( * pStart ++ ) ;
  118.  
  119.             putchar ( '\n' ) ;
  120.  
  121.             /*
  122.              * We are done with this line when pNextPart
  123.              * points to a null character (rather than a '&').
  124.              */
  125.  
  126.             pStart = pNextPart ;
  127.  
  128.         } while ( * pStart ++ ) ;
  129.     }
  130.  
  131.     return 0 ;
  132. }
  133.