home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxtech07.zip / RXAWAR / VARPOOL / C / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  79 lines

  1. /*
  2.  * main.c -- Sample mainline showing how to call a REXX macro.
  3.  *
  4.  */
  5.  
  6. #define INCL_DOS
  7.  
  8. #include <os2.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. #include "func.h"
  15.  
  16. static void Usage( char *argv[] );
  17.  
  18. /*
  19.  * main -- Main entry point.  First argument is the name of the
  20.  *         macro file to run.
  21.  */
  22.  
  23. int main( int argc, char *argv[] )
  24.   {
  25.     PSZ  argstring = NULL;
  26.     PPIB pib;
  27.     PTIB tib;
  28.  
  29.     /* Need at least one argument! */
  30.  
  31.     if( argc < 2 ){
  32.         Usage( argv );
  33.     }
  34.  
  35.     /* Register the function before running the macro... */
  36.  
  37.     RegisterREXXFuncs();
  38.  
  39.     /* Get the argument string... because we're running the macro as
  40.        a command we only pass it a single argument, so we need to look
  41.        up the real command line stored in the process information
  42.        block */
  43.  
  44.     if( argc > 2 ){
  45.         DosGetInfoBlocks( &tib, &pib );
  46.  
  47.         argstring = pib->pib_pchcmd;
  48.  
  49.         /* Skip over command name and then the filename... */
  50.  
  51.         while( *argstring != '\0' ) ++argstring;
  52.         ++argstring;
  53.  
  54.         while( isspace( *argstring ) ) ++argstring;
  55.         while( *argstring != '\0' && !isspace( *argstring ) ) ++argstring;
  56.         while( isspace( *argstring ) ) ++argstring;
  57.     }
  58.  
  59.     /* Now run the macro... */
  60.  
  61.     RunMacro( argv[1], argstring, ( argstring ? strlen( argstring ) : 0 ) );
  62.  
  63.     DeregisterREXXFuncs();
  64.  
  65.     return( 0 );
  66.   }
  67.  
  68. /*
  69.  * Usage
  70.  */
  71.  
  72. static void Usage( char *argv[] )
  73.   {
  74.     printf( "Usage: %s macro [args...]\n", argv[0] );
  75.  
  76.     exit( -1 );
  77.   }
  78.  
  79.