home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / sdu / sample1.c < prev    next >
Text File  |  1997-03-14  |  17KB  |  307 lines

  1. #pragma title ("SAMPLE1")
  2. /******************************************************************************/
  3. /*                                                                            */
  4. /* PRODUCT   = Data Description and Conversion for OS/2                       */
  5. /*                                                                            */
  6. /* SOURCE FILE NAME = Sample1.C                                               */
  7. /*                                                                            */
  8. /* DESCRIPTIVE NAME = ADL Declaration Translator and CPB sample               */
  9. /*                                                                            */
  10. /* FUNCTION =  This sample program calls the parse function of the ADL        */
  11. /*             declaration translator to compile ADL source text SAMPLE.ADL   */
  12. /*             into the appropriate ADL declare and plan spaces, calls        */
  13. /*             the generate function of the ADL declaration translator        */
  14. /*             to reproduce the ADL source file SAMPLE.GEN. The               */
  15. /*             parse function's output is also used to call                   */
  16. /*             the conversion plan builder to create conversion plans         */
  17. /*             from the encoded descriptions.                                 */
  18. /*             The conversion plan builder output generated conversion plan   */
  19. /*             space is stored in the file SAMPLE.SPC.                        */
  20. /*                                                                            */
  21. /* NOTES =                                                                    */
  22. /*                                                                            */
  23. /*   DEPENDENCIES = OS/2 Release 2.0 or later                                 */
  24. /*                                                                            */
  25. /*   RESTRICTIONS = None                                                      */
  26. /*                                                                            */
  27. /* ENTRY POINTS = main()                                                      */
  28. /*                                                                            */
  29. /*                                                                            */
  30. /******************************************************************************/
  31. #pragma page ()
  32. /******************************************************************************/
  33. /* Header Files.                                                              */
  34. /******************************************************************************/
  35.  
  36. /*---------------- OS/2 Base Header ------------------------------------------*/
  37.  
  38. #define INCL_BASE                      /* all of OS/2 Base                    */
  39. #define INCL_NOPMAPI                   /* no presentation manager functions   */
  40. #include <os2.h>
  41.  
  42. /*---------------- C Library Header ------------------------------------------*/
  43.  
  44. #include <stdio.h>
  45. #include <memory.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48. #include <ctype.h>
  49.  
  50. #pragma page ()
  51. /******************************************************************************/
  52. /* DDC/2 global header file                                                   */
  53. /******************************************************************************/
  54. #define FMT_NO_LCF   FMT_NO_LCF        /* exclude the Low Level Conversion
  55.                                           Functions function prototypes and
  56.                                           their declarations                  */
  57. #define FMT_NO_CPEX  FMT_NO_CPEX       /* exclude the Conversion Plan
  58.                                           Executor function prototypes and
  59.                                           their declarations                  */
  60.  
  61. #include  "FMT.H"
  62.  
  63. /******************************************************************************/
  64. /* Define ADLDCLSPC and ADLPLNSPC buffer length                               */
  65. /******************************************************************************/
  66. #define  BUFLEN_ADLDCLSPC  64000
  67. #define  BUFLEN_ADLPLNSPC  64000
  68. #define  BUFLEN_CNVPLNSPC   5000
  69.  
  70.  
  71. /******************************************************************************/
  72. /*  MAIN function                                                             */
  73. /******************************************************************************/
  74. int main( )
  75. {
  76.   FMTCTOK     FeedBack;
  77.   PBYTE       pAdlDclSpc;
  78.   PBYTE       pAdlPlnSpc;
  79.   PBYTE       *ppAdlDclSpcList = 0;
  80.   PBYTE       *ppDefaultAdlPlnSpcList = 0;
  81.   PVOID       pCnvPlnSpc = 0;
  82.   FMTCNSTKN   Cnstkn;
  83.   FMTADLCA    MyIsInfo;
  84.   FILE        *CnvPlnSpcHandle;
  85.   ULONG       ulSpcLen;
  86.  
  87.   /****************************************************************************/
  88.   /* Get space for ADLDCLSPC and ADLPLNSPC.                                   */
  89.   /****************************************************************************/
  90.   pAdlDclSpc     = (PBYTE) malloc(BUFLEN_ADLDCLSPC);
  91.   pAdlPlnSpc     = (PBYTE) malloc(BUFLEN_ADLPLNSPC);
  92.  
  93.   /****************************************************************************/
  94.   /* Call PARSE function of ADL Declaration Translator for ADL source text    */
  95.   /* to get ADLDCLSPC and ADLPLNSPC.                                          */
  96.   /* Type Manager id is set to ADL.                                           */
  97.   /* Note: Currently all CCSID's should be zero.                              */
  98.   /****************************************************************************/
  99.  
  100.   FMTPRS (  ADLDECLTRANSLATOR,             // PBYTE    pbDclXlrId
  101.             0,                             // FMTCCSID lParameterCCSID
  102.             10,                            // LONG     lSrcFilNamLength
  103.             "SAMPLE.ADL",                  // PCHAR    pchSrcFilNam
  104.             0,                             // FMTCCSID lSrcFilCCSID
  105.             8,                             // LONG     lDclXlrOptLength
  106.             "AUTOSKIP",                    // PCHAR    pchDclXlrOpt
  107.             4,                             // LONG     lLstOptLength
  108.             "LIST",                        // PCHAR    pchLstOpt
  109.             12,                            // LONG     lLstFilNamLength
  110.             "SAMPLE_P.LST",                // PCHAR    pchLstFilNam
  111.             BUFLEN_ADLDCLSPC,              // LONG     lADLDclSpcLength
  112.             pAdlDclSpc,                    // PBYTE    pbADLDclSpc
  113.             0,                             // FMTCCSID lADLDclSpcCCSID
  114.             &Cnstkn,                       // PFMTCNSTKN pbADLDclSpcCNSTKN
  115.             BUFLEN_ADLPLNSPC,              // LONG     lADLPlnSpcLength
  116.             pAdlPlnSpc,                    // PBYTE    pbADLPlnSpc
  117.             &FeedBack );                   // PFMTCTOK pFeedBack
  118.  
  119.   /****************************************************************************/
  120.   /* Check the Condition Token                                                */
  121.   /****************************************************************************/
  122.  
  123.   if ( FeedBack.Condition_ID.usMsgNo != PRS_NO_ERROR )
  124.    {
  125.      printf("Error in PARSE function.\n");
  126.      printf("The Condition Token has the following contents:\n");
  127.  
  128.      printf("Message Severity %d Number %d\n", FeedBack.Condition_ID.usMsgSev,
  129.                                                FeedBack.Condition_ID.usMsgNo);
  130.      printf("Service Condition Case %d\n",     FeedBack.fCase);
  131.      printf("Condition Severity     %d\n",     FeedBack.fSeverity);
  132.      printf("Control                %d\n",     FeedBack.fControl);
  133.      printf("Facility ID            %c%c%c\n", FeedBack.uchFacility_ID[0],
  134.                                                FeedBack.uchFacility_ID[1],
  135.                                                FeedBack.uchFacility_ID[2]);
  136.      printf("Instance Specific      %d\n\n",   FeedBack.pI_S_Info.ulAdlExId);
  137.  
  138.    } /* endif */
  139.   else
  140.    {
  141.      /*************************************************************************/
  142.      /* Call GENERATE function of ADL Declaration Translator for ADLDCLSPC    */
  143.      /* to get ADL Source text.                                               */
  144.      /* This call is not necessary to create a conversion plan, it is mainly  */
  145.      /* done for debugging of the PARSE function.                             */
  146.      /* Type Manager id is set to ADL.                                        */
  147.      /* Note: Currently all CCSID's should be zero.                           */
  148.      /*************************************************************************/
  149.      FMTGEN (  ADLDECLTRANSLATOR,             // PBYTE    pbDclXlrId
  150.                0,                             // FMTCCSID lParameterCCSID
  151.                0,                             // LONG     lDclXlrOptLength
  152.                "",                            // PCHAR    pchDclXlrOpt
  153.                pAdlDclSpc,                    // PBYTE    pbAdlSpc
  154.                0,                             // FMTCCSID lAdlSpcCCSID
  155.                10,                            // LONG     lSrcFilNamLength
  156.                "SAMPLE.GEN",                  // PCHAR    pchSrcFilNam
  157.                0,                             // FMTCCSID lSrcFilCCSID
  158.                12,                            // LONG     lLstOptLength
  159.                "LIST FLAG(I)",                // PCHAR    pchLstOpt
  160.                12,                            // LONG     lLstFilNamLength
  161.                "SAMPLE_G.LST",                // PCHAR    pchLstFilNam
  162.                0,                             // FMTCCSID lLstFilCCSID
  163.                &FeedBack);                    // PFMTCTOK pFeedback
  164.  
  165.      /*************************************************************************/
  166.      /* Check the Condition Token                                             */
  167.      /*************************************************************************/
  168.  
  169.      if ( FeedBack.Condition_ID.usMsgNo != GEN_NO_ERROR )
  170.       {
  171.         printf("Error in GENERATE function.\n");
  172.         printf("The Condition Token has the following contents:\n");
  173.  
  174.         printf("Message Severity %d Number %d\n",FeedBack.Condition_ID.usMsgSev,
  175.                                                  FeedBack.Condition_ID.usMsgNo);
  176.         printf("Service Condition Case %d\n",    FeedBack.fCase);
  177.         printf("Condition Severity     %d\n",    FeedBack.fSeverity);
  178.         printf("Control                %d\n",    FeedBack.fControl);
  179.         printf("Facility ID            %c%c%c\n",FeedBack.uchFacility_ID[0],
  180.                                                  FeedBack.uchFacility_ID[1],
  181.                                                  FeedBack.uchFacility_ID[2]);
  182.         printf("Instance Specific      %d\n\n",  FeedBack.pI_S_Info.ulAdlExId);
  183.  
  184.       } /* endif */
  185.  
  186.      /*************************************************************************/
  187.      /* Get space for conversion plan space (CNVPLNSPC )                      */
  188.      /*************************************************************************/
  189.      pCnvPlnSpc     = malloc( BUFLEN_CNVPLNSPC );
  190.      memset( pCnvPlnSpc, '0', BUFLEN_CNVPLNSPC );
  191.  
  192.      /*************************************************************************/
  193.      /* Initialize ADL Communication Area                                     */
  194.      /*************************************************************************/
  195.      FeedBack.pI_S_Info.pAdlCommArea = &MyIsInfo;
  196.  
  197.      /*************************************************************************/
  198.      /* Call Conversion Plan Builder                                          */
  199.      /*************************************************************************/
  200.      ppAdlDclSpcList = malloc( sizeof( PBYTE ) );
  201.      ppAdlDclSpcList[0] = pAdlDclSpc;
  202.  
  203.      ppDefaultAdlPlnSpcList = malloc( sizeof(PBYTE) );
  204.      ppDefaultAdlPlnSpcList[0] = pAdlPlnSpc;
  205.  
  206.      FMTCRCP(
  207.               1,                       // ULONG    ulAdlDclSpcCount
  208.               ppAdlDclSpcList,         // PBYTE    *ppAdlDclSpcList
  209.               0,                       // ULONG    ulUserAdlPlnSpcCount
  210.               NULL,                    // PBYTE    *ppUserAdlPlnSpcList
  211.               1,                       // ULONG    ulDefaultAdlPlnSpcCount
  212.               ppDefaultAdlPlnSpcList,  // PBYTE    *ppDefaultAdlPlnSpcList
  213.               BUFLEN_CNVPLNSPC,        // ULONG    ulCnvPlnSpcLength
  214.               pCnvPlnSpc,              // PVOID    pCnvPlnSpc
  215.               0,                       // ULONG    ulFlagList
  216.               &FeedBack );             // PFMTCTOK pFeedback
  217.  
  218.      /*************************************************************************/
  219.      /* Check the Condition Token                                             */
  220.      /*************************************************************************/
  221.  
  222.      if ( FeedBack.Condition_ID.usMsgNo != CPB_NO_ERROR )
  223.       {
  224.         printf("Error in Conversion Plan Builder.\n");
  225.         printf("The Condition Token has the following contents:\n");
  226.  
  227.         printf("Message Severity %d Number %d\n",FeedBack.Condition_ID.usMsgSev,
  228.                                                  FeedBack.Condition_ID.usMsgNo);
  229.         printf("Service Condition Case %d\n",    FeedBack.fCase);
  230.         printf("Condition Severity     %d\n",    FeedBack.fSeverity);
  231.         printf("Control                %d\n",    FeedBack.fControl);
  232.         printf("Facility ID            %c%c%c\n",FeedBack.uchFacility_ID[0],
  233.                                                  FeedBack.uchFacility_ID[1],
  234.                                                  FeedBack.uchFacility_ID[2]);
  235.  
  236.         /**********************************************************************/
  237.         /* Check whether an ADL exception occurred. If ADL exception the ADL  */
  238.         /* communication area is filled.                                      */
  239.         /**********************************************************************/
  240.         if ( FeedBack.Condition_ID.usMsgNo == CPB_ADL_EXCEPTION_SEV2 ||
  241.              FeedBack.Condition_ID.usMsgNo == CPB_ADL_EXCEPTION_SEV3 )
  242.          {
  243.            printf("The ADL communication area has the following contents:\n" );
  244.  
  245.            printf("ADL exception:             %d\n", MyIsInfo.lExId );
  246.            printf("Severity of ADL exception: %d\n", MyIsInfo.usSevCod );
  247.                                           /* The Severity of the ADL          */
  248.                                           /* exception has the same value as  */
  249.                                           /* the message severity             */
  250.                                           /* ( Feedback.Condition_ID.usMsgSev */
  251.  
  252.            printf("Name of processed plan:    %.255s\n",
  253.                                                      MyIsInfo.PlanId.uchData );
  254.            printf("Number of processed PLAN statement: %d\n",
  255.                                                      MyIsInfo.lPlanStmt );
  256.            printf("Source identifier of processed assignment statement: %.255s\n"
  257.                   , MyIsInfo.SrcFldId.uchData );
  258.            printf("Target identifier of processed assignment statement: %.255s\n"
  259.                   , MyIsInfo.TrgFldId.uchData );
  260.  
  261.  
  262.          } /* endif */
  263.  
  264.       } /* endif */
  265.      else
  266.       {
  267.         /**********************************************************************/
  268.         /* Write conversion plan space into file                              */
  269.         /**********************************************************************/
  270.         CnvPlnSpcHandle = fopen( "SAMPLE.SPC","wb");
  271.  
  272.         ulSpcLen = *((PULONG)pCnvPlnSpc);  /* Get length of the space out of  */
  273.                                            /* the first 4 Byte                */
  274.  
  275.         fwrite( pCnvPlnSpc, sizeof(CHAR), ulSpcLen , CnvPlnSpcHandle );
  276.         fclose( CnvPlnSpcHandle );
  277.  
  278.       } /* endelse */
  279.  
  280.    } /* endelse */
  281.  
  282.   /****************************************************************************/
  283.   /* Free allocated resources                                                 */
  284.   /****************************************************************************/
  285.   if ( pAdlDclSpc != NULL ) {
  286.     free( pAdlDclSpc );
  287.   } /* endif */
  288.  
  289.   if ( pAdlPlnSpc != NULL ) {
  290.     free( pAdlPlnSpc );
  291.   } /* endif */
  292.  
  293.   if ( pCnvPlnSpc != NULL ) {
  294.     free( pCnvPlnSpc );
  295.   } /* endif */
  296.  
  297.   if ( ppAdlDclSpcList != NULL) {
  298.     free( ppAdlDclSpcList );
  299.   } /* endif */
  300.  
  301.   if ( ppDefaultAdlPlnSpcList != NULL ) {
  302.     free( ppDefaultAdlPlnSpcList );
  303.   } /* endif */
  304.  
  305.   return 0;
  306. }
  307.