www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*--------------------------------------------------------------------+
|                                                                     |
|              Copyright 1996 (c), SAS Institute Inc.                 |
|                Unpublished - All Rights Reserved                    |
|                                                                     |
|                     S A S / C  S A M P L E                          |
|                                                                     |
|       Name: SUBCMD                                                  |
|                                                                     |
|   Language: C                                                       |
|                                                                     |
| EntryPoint: MAIN                                                    |
|                                                                     |
| EntryType : OS Entry Linkage                                        |
|                                                                     |
| Files Note: 'prefix' is the installation defined high level         |
|             qualifier for the SAS/C product.                        |
|                                                                     |
|    Purpose: Demonstrate SUBCOM interface to CMS and TSO using       |
|             facilities provided by SAS/C.                           |
|                                                                     |
|             Three commands will be accepted by SUBCOM:              |
|                                                                     |
|              ECHO    - display information provided                 |
|              SETRC   - set return code and return with that code    |
|              EXEC    - invoke a TSO CLIST or CMS EXEC               |
|                                                                     |
|                                                                     |
| MVS -                                                               |
|                                                                     |
|                                                                     |
|    Compile: global maclib lc370                                     |
|             lc370 subcmd                                            |
|                                                                     |
|       Link: global txtlib lc370bas lc370std                         |
|             clink subcmd (genmod subcmd                             |
|                                                                     |
|                                                                     |
| CMS -                                                               |
|     Source: SAMPLC   MACLIB (RXLOCFN)                               |
|                                                                     |
|    Compile: global maclib lc370                                     |
|             lc370 subcmd                                            |
|                                                                     |
|       Link: global txtlib lc370bas lc370std                         |
|             clink subcmd (genmod subcmd                             |
|                                                                     |
|    Execute: Interactive   : SUBCMD I                                |
|             Non-Interacive: SUBCMD                                  |
|      Notes:                                                         |
|             - See 'SUBCOM' in SAS/C Library Reference Vol 2         |
|               for additional information on using the SAS/C         |
|               SUBCOM interface.                                     |
|                                                                     |
+--------------------------------------------------------------------*/
#eject
#include <exec.h>
#include <ctype.h>
#include <string.h>
#include<stdio.h>

               /******************************************************/
               /* This is a sample SUBCOM application.  Its purpose  */
               /* to demonstrate the SUBCOM functionality, rather    */
               /* than to do anything terribly useful.               */
               /******************************************************/

main(argc,argv)
   int argc;
   char **argv;
   {
      int interact;                  /* if 0, next input expected    */
                                     /* from EXEC, if non-0, next    */
                                     /* input expected from terminal */
      char *input, *cmdname, *operands;
      int maxrc = 0;
      int thisrc;
      char msgbuff[120];

      interact = (argc > 1 && tolower(*argv[1]) == 'i');
                                     /* if first argument starts with*/
                                     /* 'i', use interactive mode    */
      execinit("EXAMPLE", interact);

      for(;;)
         {
            operands = input = execget();
                                     /* obtain next input line       */
            if (!input) break;
            cmdname = execid(&operands);
                                     /* obtain command name          */
            if (!cmdname)            /* if error in execid           */
               {
                  interact = 1;      /* expect CLIST input next      */
                  continue;
               }

            if (!*cmdname) continue; /* check for null input         */

            else if (strcmp(cmdname, "*EXEC") == 0)
               {                     /* if execid did an EXEC for us */
                  interact = 0;      /* note this and continue       */
                  continue;
               }

            else if (strcmp(cmdname, "*ENDEXEC") == 0)
               {                     /* if we just switched from EXEC*/
                                     /* to the terminal              */
                  interact = 1;      /* note this                    */
                  thisrc = atoi(operands);
                                     /* extract EXEC return code     */
                  if (operands)      /* remember it might be missing */
                     sprintf(msgbuff, "EXEC return code %d", thisrc);
                  else
                     strcpy(msgbuff, "EXEC return code unavailable");
                  execmsg("EXAM001I", msgbuff);
                                     /* inform user of return code   */
               }

            else if (strcmp(cmdname, "END") == 0)
               break;                /* terminate if END received    */

            else if (strcmp(cmdname, "EXEC") == 0)
               {                     /* call EXEC for EXEC SUBCOMmand*/
                  thisrc = execcall(input);
                  interact = 0;      /* expect input from it         */
                  if (thisrc != 0)
                     {
                        sprintf(msgbuff,
                                "EXEC failed with return code %d",
                                thisrc);
                        execmsg("EXAM005E", msgbuff);
                     }
               }

            else if (strcmp(cmdname, "ECHO") == 0)
               {                     /* if command is ECHO, repeat   */
                                     /* its operands                 */
                  execmsg(0, operands);
                  thisrc = 0;
               }

            else if (strcmp(cmdname, "SETRC") == 0)
                                     /* if command is SETRC, set     */
                                     /* return code as requested     */
               {
                  char *number_end;
                  thisrc = strtol(operands, &number_end, 10);
                  if (!number_end)
                     {
                        sprintf(msgbuff, "Invalid return code: %s",
                                operands);
                        execmsg("EXAM002E", msgbuff);
                        thisrc = 12;
                     }
                  else
                     {
                        sprintf(msgbuff, "Return code set to %d",
                                thisrc);
                        execmsg("EXAM003I", msgbuff);
                     }
               }

            else                     /* if unknown command name, try */
               {                     /* to EXEC it                   */
                  thisrc = execcall(input);
                  interact = 0;
               }

            maxrc = execrc(thisrc);  /* inform EXEC of return code   */
         }

      sprintf(msgbuff, "Maximum return code was %d", maxrc);
      execmsg("EXAM004I", msgbuff);  /* announce max return code     */
      execend();                     /* cancel SUBCOM connection     */
      return maxrc;                  /* return max return code       */
   }

Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement