home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / sdu / dubsamp.c < prev    next >
C/C++ Source or Header  |  1997-03-19  |  69KB  |  1,402 lines

  1. /**************************************************************************
  2. ****************************  DUBSAMP.C  **********************************
  3. ***************************************************************************
  4. *
  5. *                              Record Level I/O
  6. *
  7. * Module Name: DUBSAMP.C
  8. *   This module demonstrates some basic record level I/O functions.
  9. *
  10. * RLIO (program no. 5648-02011)
  11. *
  12. * Version: 1.0
  13. * Release: 1.0
  14. *
  15. * Copyright (C)
  16. * International Business Machines Corporation 1992
  17. *
  18. * DISCLAIMER OF WARRANTIES: The following (enclosed) code is sample code
  19. * created by the IBM Corporation.  This sample code is not a part of any
  20. * IBM product and is provided to you solely for the purpose of assisting
  21. * you in the development of your applications.  The code is provided
  22. * "AS IS", without warranty of any kind.  IBM shall not be liable for any
  23. * damages arising out of your use of the sample code, even if they have
  24. * been advised of the possibility of such damages.
  25. *
  26. * The sample program does the following:
  27. *
  28. * 1) Create a sequential file
  29. * 2) Try to create the same sequential file again in order to get a reply
  30. *    message.
  31. * 3) Set path information for sequential file
  32. *    (i.e. DDM_TITLE attribute is set to "USER_NAME")
  33. * 4) Query the sequential file to see if it is a record file
  34. *    (i.e. DDM_FILCLS attribute = SEQFIL, DIRFIL, or KEYFIL)
  35. * 5) Open the sequential file
  36. * 6) Insert a record into the sequential file
  37. * 7) Get a record from the sequential file
  38. * 8) Close the sequential file
  39. * 9) Delete the sequential file
  40. *
  41. * The following operations are done on both direct and keyed files:
  42. *
  43. * 10) Create the file
  44. * 11) Open the file
  45. * 12) Insert a record into file
  46. * 13) Get a record from the file
  47. * 14) Close the file
  48. * 15) Delete the file
  49. *
  50. * The following operations are done on an alternate index file and its
  51. * base file:
  52. *
  53. * 16) Create a base keyed file
  54. * 17) Create an alternate index file
  55. * 18) Open the alternate index file
  56. * 19) Close the alternate index file
  57. * 20) Delete the alternate index file
  58. * 21) Delete the base keyed file
  59. *
  60. * COMMAND LINE INVOCATION:
  61. *
  62. *   DUBSAMP [pathname] [filenamesuffix]
  63. *
  64. *   Examples:
  65. *
  66. *     ENTERED                   RESULT
  67. *
  68. *     dubsamp                   uses predefined filenames with the current path
  69. *
  70. *     dubsamp d:\rlio\          prefixes predefined filenames with the
  71. *                               specified path:
  72. *                                    d:\rlio\dubsamp.seq
  73. *
  74. *     dubsamp d:\rlio\ test1    prefixes predefined file class names with
  75. *                               the first parameter and suffixes the result
  76. *                               with the second parameter:
  77. *                                    d:\rlio\SEQtest1
  78. *
  79. ***************************************************************************
  80. ***************************************************************************
  81. * CHANGE ACTIVITY
  82. * ===============
  83. * $L0=dfm_win_rlse1,EA sample,3/19/97, TML: 1. Add missing RM table entries.
  84. *
  85. ***************************************************************************/
  86.  
  87.  
  88. #include  <os2.h>                       /* required for RLIO applications */
  89. #include  <stdio.h>
  90. #include  <string.h>
  91. #include  <memory.h>
  92. #include  <malloc.h>
  93. #include  "dub.h"        /* required master include for RLIO applications */
  94.  
  95. /*-------------------------------------------------------------------------
  96. --                       SYMBOLIC CONSTANTS
  97. --------------------------------------------------------------------------*/
  98. #define FILCLS_SIZE sizeof(OBJLENGTH) + (2 * sizeof(CODEPOINT))
  99. #define FILCLS_NAME ".DDM_FILCLS"
  100. #define RECDATALEN  100
  101. #define RPYMSBFLN   546                    /* reply message buffer length */
  102. #define PATHLEN     100
  103.  
  104. /*-------------------------------------------------------------------------
  105. --                     LOCAL FUNCTION DECLARATIONS
  106. --------------------------------------------------------------------------*/
  107. VOID DumpBuffer(PDDMOBJECT pAttribute, USHORT Count);
  108.  
  109. VOID ReplyMsg(VOID);
  110.  
  111. VOID CleanUp(CHAR *File1, CHAR *File2, CHAR *File3, CHAR *File4, CHAR *File5);
  112.  
  113. /*-------------------------------------------------------------------------
  114. --                             DUBSAMP
  115. --------------------------------------------------------------------------*/
  116. main(int argc, char* argv[])
  117. {
  118.     APIRET SevCode;              /* RLIO severity code */
  119.  
  120.     PDDMRECORD pRecord;
  121.     RECLENGTH  RecordSize;
  122.     PDDMRECAL  pRecAL;
  123.     PDDMRECALK  pRecALK;
  124.     RECLENGTH  RecALSize;
  125.     PBYTE      pData;
  126.  
  127.     HDDMFILE FileHandle;
  128.  
  129.     /* OS/2 extended attribute structures */
  130.     EAOP2 Eaop;
  131.     EAOP2 Eaop2;
  132.     PFEA2 pFEA;
  133.     INT   FEASize;
  134.     ULONG FEA2Size;
  135.     INT   GEASize;
  136.  
  137.     PSZ   TitleName = ".DDM_TITLE\0";      /* extended attribute name for title */
  138.     PSZ   TitleString  = "Title String\0";
  139.     ULONG TitleObjectSize = sizeof(OBJLENGTH) + sizeof(CODEPOINT) + strlen(TitleString);
  140.  
  141.     /* Filenames of files to be operated on */
  142.     CHAR SeqFN[PATHLEN];
  143.     CHAR DirFN[PATHLEN];
  144.     CHAR KeyFN[PATHLEN];
  145.     CHAR AltFN[PATHLEN];
  146.     CHAR KeyFN2[PATHLEN];
  147.  
  148.     #pragma pack(2)
  149.  
  150.     typedef struct _MYKEYDEFBUF     /* key definition buffer */
  151.     {  ULONG     cbKeyDefBuf;
  152.        CODEPOINT cpKeyDefBuf;
  153.        KEYFLDDEF KeyFldDef[1];
  154.     } MYKEYDEFBUF;
  155.  
  156.     MYKEYDEFBUF KeyDefBuf;
  157.  
  158.     /*---------------------------------------------------------------------
  159.     -- Construct file specifications from input parameters
  160.     ----------------------------------------------------------------------*/
  161.     switch (argc)
  162.     {  case 1: /* no user arguments */
  163.           strcpy(SeqFN,"dubsamp.seq");
  164.           strcpy(DirFN,"dubsamp.dir");
  165.           strcpy(KeyFN,"dubsamp.key");
  166.           strcpy(AltFN,"dubsamp.alt");
  167.           strcpy(KeyFN2,"dubsamp.ky2");
  168.           break;
  169.        case 2: /* 1 user argument: pathname */
  170.           strcpy(SeqFN,argv[1]);
  171.           strcpy(DirFN,argv[1]);
  172.           strcpy(KeyFN,argv[1]);
  173.           strcpy(AltFN,argv[1]);
  174.           strcpy(KeyFN2,argv[1]);
  175.           strcat(SeqFN,"dubsamp.seq");
  176.           strcat(DirFN,"dubsamp.dir");
  177.           strcat(KeyFN,"dubsamp.key");
  178.           strcat(AltFN,"dubsamp.alt");
  179.           strcat(KeyFN2,"dubsamp.ky2");
  180.           break;
  181.        case 3: /* 2 user arguments: pathname filenamesuffix */
  182.           strcpy(SeqFN,argv[1]);
  183.           strcpy(DirFN,argv[1]);
  184.           strcpy(KeyFN,argv[1]);
  185.           strcpy(AltFN,argv[1]);
  186.           strcpy(KeyFN2,argv[1]);
  187.           strcat(SeqFN,"SEQ");
  188.           strcat(DirFN,"DIR");
  189.           strcat(KeyFN,"KEY");
  190.           strcat(AltFN,"ALT");
  191.           strcat(KeyFN2,"KY2");
  192.           strcat(SeqFN,argv[2]);
  193.           strcat(DirFN,argv[2]);
  194.           strcat(KeyFN,argv[2]);
  195.           strcat(AltFN,argv[2]);
  196.           strcat(KeyFN2,argv[2]);
  197.           break;
  198.        default: /* > 2 user arguments */
  199.           printf("Incorrect command line syntax.\n\n");
  200.           printf("Correct syntax: dubsamp [pathname] [filenamesuffix]\n\n");
  201.           printf("     where pathname and filenamesuffix are optional\n");
  202.           printf("           When filenamesuffix is specified, the prefixes are:\n");
  203.           printf("             SEQ, DIR, KEY, ALT, and KY2\n\n");
  204.           printf("Example: dubsamp g:\\dir1\\dir2\\ test1 produces:\n\n");
  205.           printf("                 g:\\dir1\\dir2\\SEQtest1\n");
  206.           printf("                 g:\\dir1\\dir2\\DIRtest1\n");
  207.           printf("                    and so on ... \n");
  208.           return;
  209.     }
  210.  
  211.     /*---------------------------------------------------------------------
  212.     -- Create a sequential file with get, insert, modify, and delete capability
  213.     ----------------------------------------------------------------------*/
  214.     SevCode = DDMCreateRecFile
  215.               (SeqFN,                      /* FileName        */
  216.                DDM_GETCP | DDM_INSCP |     /* CreateFlags     */
  217.                DDM_MODCP | DDM_DELCP,
  218.                (ULONG)RECDATALEN,          /* RecLen          */
  219.                RECFIX,                     /* RecLenCls       */
  220.                NULL,                       /* KeyDefBuf       */
  221.                0UL,                        /* InitFilSiz      */
  222.                -1L,                        /* MaxFileSiz      */
  223.                DUPFILDO,                   /* DupFilOpt       */
  224.                NIL,                        /* DftRecOp        */
  225.                0UL,                        /* RecCnt          */
  226.                NULL,                       /* EABuf           */
  227.                SEQFIL,                     /* FileClass       */
  228.                NULL                        /* DftRecBuf       */
  229.               );
  230.     if (SevCode == SC_NO_ERROR)
  231.        printf("\nSuccessfully created sequential file %s\n",SeqFN);
  232.     else
  233.     {  printf("Error creating sequential file %s\n",SeqFN);
  234.        printf("Severity code = %u\n",SevCode);
  235.        ReplyMsg();
  236.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  237.        return(SevCode);
  238.     }
  239.  
  240.     /*---------------------------------------------------------------------
  241.     -- Try to create the same sequential file as before (this should be rejected)
  242.     ----------------------------------------------------------------------*/
  243.     SevCode = DDMCreateRecFile
  244.               (SeqFN,                      /* FileName        */
  245.                DDM_GETCP | DDM_INSCP |     /* CreateFlags     */
  246.                DDM_MODCP | DDM_DELCP,
  247.                (ULONG)RECDATALEN,          /* RecLen          */
  248.                RECFIX,                     /* RecLenCls       */
  249.                NULL,                       /* KeyDefBuf       */
  250.                0UL,                        /* InitFilSiz      */
  251.                -1L,                        /* MaxFileSiz      */
  252.                DUPFILDO,                   /* DupFilOpt       */
  253.                NIL,                        /* DftRecOp        */
  254.                0UL,                        /* RecCnt          */
  255.                NULL,                       /* EABuf           */
  256.                SEQFIL,                     /* FileClass       */
  257.                NULL                        /* DftRecBuf       */
  258.               );
  259.     if (SevCode == SC_NO_ERROR)
  260.     {  printf("\nUnsuccessful in rejecting creation of sequential file %s\n",SeqFN);
  261.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  262.        return(SevCode);
  263.     }
  264.     else
  265.     {  printf("\nSuccessful in rejecting the creation of sequential file %s\n",SeqFN);
  266.        printf("Severity code = %u\n",SevCode);
  267.        ReplyMsg();
  268.     }
  269.  
  270.     /*---------------------------------------------------------------------
  271.     -- Set up for DDMSetPathInfo:
  272.     --
  273.     -- Build an extended attribute structure with a FEA list containing
  274.     -- the TITLE extended attribute.
  275.     ----------------------------------------------------------------------*/
  276.     FEA2Size = sizeof(Eaop2.fpFEA2List->list[0].oNextEntryOffset)
  277.              + sizeof(Eaop2.fpFEA2List->list[0].fEA)
  278.              + sizeof(Eaop2.fpFEA2List->list[0].cbName)
  279.              + sizeof(Eaop2.fpFEA2List->list[0].cbValue)
  280.              + sizeof(Eaop2.fpFEA2List->cbList)
  281.              + strlen(TitleName) + 1
  282.              + TitleObjectSize;
  283.     if ((Eaop2.fpFEA2List = (PFEA2LIST)malloc(FEA2Size)) == NULL)
  284.     {  printf("Out of memory\n");
  285.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  286.        return(1);
  287.     }
  288.     Eaop2.fpFEA2List->cbList = FEA2Size;
  289.     pFEA = Eaop2.fpFEA2List->list;
  290.     pFEA->oNextEntryOffset = 0l;
  291.     pFEA->fEA = 0;
  292.     pFEA->cbName = LOBYTE(strlen(TitleName));
  293.     pFEA->cbValue = TitleObjectSize;
  294.     pData = (PBYTE)&pFEA->cbValue + sizeof(pFEA->cbValue);
  295.     strcpy(pData,TitleName);
  296.     pData+= pFEA->cbName + 1;
  297.     *(PULONG)pData = TitleObjectSize;
  298.     pData+= sizeof(ULONG);
  299.     *(PUSHORT)pData = TITLE;
  300.     pData+= sizeof(USHORT);
  301.     strcpy((PBYTE)pData,TitleString);
  302.  
  303.     Eaop2.fpGEA2List = NULL;
  304.     Eaop2.oError = 0l;
  305.  
  306.     SevCode = DDMSetPathInfo
  307.               (SeqFN,                      /* PathName        */
  308.                1UL,                        /* PathInfoLevel   */
  309.                (PBYTE)&Eaop2,              /* PathInfoBuf     */
  310.                (ULONG)sizeof(EAOP2)        /* PathInfoBufSize */
  311.               );
  312.     if (SevCode == SC_NO_ERROR)
  313.        printf("\nSuccessful DDMSetPathInfo call to file %s\n",SeqFN);
  314.     else
  315.     {  printf("Error in DDMSetPathInfo call to file %s\n",SeqFN);
  316.        printf("Severity code = %u\n",SevCode);
  317.        ReplyMsg();
  318.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  319.        return(SevCode);
  320.     }
  321.  
  322.     /*---------------------------------------------------------------------
  323.     -- Set up for DDMQueryPathInfo:
  324.     --
  325.     -- Build an extended attribute structure with a GEA list defining
  326.     -- the attribute name for FILCLS.
  327.     --
  328.     ----------------------------------------------------------------------*/
  329.     FEASize = sizeof(Eaop.fpFEA2List->list[0].oNextEntryOffset)
  330.             + sizeof(Eaop.fpFEA2List->list[0].fEA)
  331.             + sizeof(Eaop.fpFEA2List->list[0].cbName)
  332.             + sizeof(Eaop.fpFEA2List->list[0].cbValue)
  333.             + sizeof(Eaop.fpFEA2List->cbList)
  334.             + FILCLS_SIZE
  335.             + strlen(FILCLS_NAME)
  336.             + 1;
  337.     GEASize = sizeof(Eaop.fpGEA2List->list[0].oNextEntryOffset)
  338.             + sizeof(Eaop.fpGEA2List->list[0].cbName)
  339.             + sizeof(Eaop.fpGEA2List->cbList)
  340.             + strlen(FILCLS_NAME)
  341.             + 1;
  342.     if ((Eaop.fpFEA2List = (PFEA2LIST)malloc(FEASize)) == NULL)
  343.     {  printf("Out of memory\n");
  344.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  345.        return(1);
  346.     }
  347.     if ((Eaop.fpGEA2List = (PGEA2LIST)malloc(GEASize)) == NULL)
  348.     {  printf("Out of memory\n");
  349.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  350.        return(1);
  351.     }
  352.     pFEA = Eaop.fpFEA2List->list;
  353.     Eaop.fpFEA2List->cbList = FEASize;
  354.     Eaop.fpGEA2List->cbList = GEASize;
  355.     Eaop.fpGEA2List->list->cbName = LOBYTE(strlen(FILCLS_NAME));
  356.     Eaop.fpGEA2List->list->oNextEntryOffset = 0;
  357.     Eaop.fpGEA2List->list->oNextEntryOffset =
  358.                       sizeof(Eaop.fpGEA2List->list->oNextEntryOffset)
  359.                     + sizeof(Eaop.fpGEA2List->list->cbName)
  360.                     + Eaop.fpGEA2List->list->cbName +1;
  361.     strcpy(Eaop.fpGEA2List->list->szName, FILCLS_NAME);
  362.     Eaop.oError = 0L;
  363.  
  364.     /*---------------------------------------------------------------------
  365.     -- Query a file to get DDM_FILCLS EA.
  366.     -- Display its file class.
  367.     ----------------------------------------------------------------------*/
  368.     SevCode = DDMQueryPathInfo
  369.               (SeqFN,                           /* PathName        */
  370.                1UL,                             /* PathInfoLevel   */
  371.                (PBYTE)&Eaop,                    /* PathInfoBuf     */
  372.                (ULONG)sizeof(EAOP2)             /* PathInfoBufSize */
  373.               );
  374.     if (SevCode == SC_NO_ERROR)
  375.     {  printf("\n\nSuccessful DDMQueryPathInfo call to file %s\n",SeqFN);
  376.        pData = (PBYTE)&pFEA->szName + pFEA->cbName + 1;
  377.        switch (*(PCODEPOINT)((PDDMOBJECT)pData)->pData)
  378.        {  case SEQFIL:  printf("%s is a sequential file\n",SeqFN);
  379.                         break;
  380.           case DIRFIL:  printf("%s is a direct file\n",SeqFN);
  381.                         break;
  382.           case KEYFIL:  printf("%s is a keyed file\n",SeqFN);
  383.                         break;
  384.           case ALTINDF: printf("%s is a alternate index file\n",SeqFN);
  385.                         break;
  386.           default:      printf("%s is an invalid record file\n",SeqFN);
  387.                         break;
  388.        }
  389.     }
  390.     else
  391.     {  printf("Error in DDMQueryPathInfo call to file %s\n",SeqFN);
  392.        printf("Severity code = %u\n",SevCode);
  393.        ReplyMsg();
  394.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  395.        return(SevCode);
  396.     }
  397.     free(Eaop.fpFEA2List);
  398.     free(Eaop.fpGEA2List);
  399.  
  400.     /*---------------------------------------------------------------------
  401.     -- Open the sequential file
  402.     ----------------------------------------------------------------------*/
  403.     SevCode = DDMOpen
  404.               (SeqFN,                           /* FileName        */
  405.                &FileHandle,                     /* FileHandle      */
  406.                CMBRNBAM,                        /* AccessMethod    */
  407.                DDM_GETAI | DDM_INSAI,           /* AccIntList      */
  408.                DDM_NOSHARE,                     /* FileShare       */
  409.                NULL,                            /* EABuf           */
  410.                NULL                             /* reserved        */
  411.               );
  412.     if (SevCode == SC_NO_ERROR)
  413.        printf("Successfully opened file %s\n",SeqFN);
  414.     else
  415.     {  printf("Error opening file %s\n",SeqFN);
  416.        printf("Severity code = %u\n",SevCode);
  417.        ReplyMsg();
  418.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  419.        return(SevCode);
  420.     }
  421.  
  422.     /*---------------------------------------------------------------------
  423.     -- Build a record
  424.     ----------------------------------------------------------------------*/
  425.     RecordSize = sizeof(RECLENGTH) + sizeof(CODEPOINT) + RECDATALEN;
  426.     if ((pRecord = (PDDMRECORD)malloc(RecordSize)) == NULL)
  427.     {  printf("Out of memory\n");
  428.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  429.        return(1);
  430.     }
  431.     pRecord->cbRecord = RecordSize;
  432.     pRecord->cpRecord = RECORD;
  433.     memset(pRecord->pRecord, 'N', RECDATALEN);
  434.  
  435.     /*---------------------------------------------------------------------
  436.     -- Insert a record into the sequential file
  437.     ----------------------------------------------------------------------*/
  438.     SevCode = DDMInsertRecEOF
  439.               (FileHandle,                      /* FileHandle      */
  440.                DDM_UPDCSR,                      /* AccessFlags     */
  441.                pRecord,                         /* RecordBuf       */
  442.                1UL,                             /* RecCount        */
  443.                NULL,                            /* FdbkBuf         */
  444.                0UL                              /* FdbkBufLen      */
  445.               );
  446.     if (SevCode == SC_NO_ERROR)
  447.        printf("Successfully inserted record in %s\n",SeqFN);
  448.     else
  449.     {  printf("Error inserting record in %s\n",SeqFN);
  450.        printf("Severity code = %u\n",SevCode);
  451.        ReplyMsg();
  452.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  453.        return(SevCode);
  454.     }
  455.     free(pRecord);
  456.  
  457.     /*---------------------------------------------------------------------
  458.     -- Get a record from the sequential file
  459.     ----------------------------------------------------------------------*/
  460.     RecALSize = RecordSize + sizeof(DDMRECAL);
  461.     if ((pRecAL = (PDDMRECAL)malloc(RecALSize)) == NULL)
  462.     {  printf("Out of memory\n");
  463.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  464.        return(1);
  465.     }
  466.     SevCode = DDMGetRec
  467.               (FileHandle,                      /* FileHandle      */
  468.                DDM_RECNBRFB,                    /* AccessFlags     */
  469.                (PDDMRECORD)pRecAL,              /* RecordBuf       */
  470.                (ULONG)RecALSize                 /* RecordBufLen    */
  471.               );
  472.     if (SevCode == SC_NO_ERROR)
  473.     {  printf("Successfully retrieved record from %s\n",SeqFN);
  474.        printf("LL = %ld\n",pRecAL->cbRecAL);
  475.        printf("CP = 0x%X\n",pRecAL->cpRecAL);
  476.        printf("L1 = %ld\n",pRecAL->cbRecNum);
  477.        printf("CP = 0x%X\n",pRecAL->cpRecNum);
  478.        printf("Record Number = %lu\n",pRecAL->RecNum);
  479.     }
  480.     else
  481.     {  printf("Error getting record in %s\n",SeqFN);
  482.        printf("Severity code = %u\n",SevCode);
  483.        ReplyMsg();
  484.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  485.        return(SevCode);
  486.     }
  487.     free(pRecAL);
  488.  
  489.     /*---------------------------------------------------------------------
  490.     -- Close the sequential file
  491.     ----------------------------------------------------------------------*/
  492.     SevCode = DDMClose
  493.               (FileHandle             /* FileHandle      */
  494.               );
  495.     if (SevCode == SC_NO_ERROR)
  496.        printf("Successfully closed file %s\n",SeqFN);
  497.     else
  498.     {  printf("Error closing file %s\n",SeqFN);
  499.        printf("Severity code = %u\n",SevCode);
  500.        ReplyMsg();
  501.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  502.        return(SevCode);
  503.     }
  504.  
  505.     /*---------------------------------------------------------------------
  506.     -- Delete the sequential file
  507.     ----------------------------------------------------------------------*/
  508.     SevCode = DDMDelete
  509.               (SeqFN,                  /* File Name       */
  510.                0UL                     /* Flags           */
  511.               );
  512.     if (SevCode == SC_NO_ERROR)
  513.        printf("Successfully deleted file %s\n",SeqFN);
  514.     else
  515.     {  printf("Error deleting file %s\n",SeqFN);
  516.        printf("Severity code = %u\n",SevCode);
  517.        ReplyMsg();
  518.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  519.        return(SevCode);
  520.     }
  521.  
  522.     /*---------------------------------------------------------------------
  523.     -- Create a direct file with get, insert, modify, and delete capability
  524.     ----------------------------------------------------------------------*/
  525.     SevCode = DDMCreateRecFile
  526.               (DirFN,                           /* FileName        */
  527.                DDM_GETCP | DDM_INSCP |          /* CreateFlags     */
  528.                DDM_MODCP | DDM_DELCP,
  529.                (ULONG)RECDATALEN,               /* RecLen          */
  530.                RECFIX,                          /* RecLenCls       */
  531.                NULL,                            /* KeyDefBuf       */
  532.                0UL,                             /* InitFilSiz      */
  533.                -1L,                             /* MaxFileSiz      */
  534.                DUPFILDO,                        /* DupFilOpt       */
  535.                NIL,                             /* DftRecOp        */
  536.                0UL,                             /* RecCnt          */
  537.                NULL,                            /* EABuf           */
  538.                DIRFIL,                          /* FileClass       */
  539.                NULL                             /* DftRecBuf       */
  540.               );
  541.     if (SevCode == SC_NO_ERROR)
  542.        printf("\n\nSuccessfully created direct file %s\n",DirFN);
  543.     else
  544.     {  printf("Error creating direct file %s\n",DirFN);
  545.        printf("Severity code = %u\n",SevCode);
  546.        ReplyMsg();
  547.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  548.        return(SevCode);
  549.     }
  550.  
  551.     /*---------------------------------------------------------------------
  552.     -- Open the direct file
  553.     ----------------------------------------------------------------------*/
  554.     SevCode = DDMOpen
  555.               (DirFN,                           /* FileName        */
  556.                &FileHandle,                     /* FileHandle      */
  557.                CMBRNBAM,                        /* AccessMethod    */
  558.                DDM_GETAI | DDM_INSAI,           /* AccIntList      */
  559.                DDM_NOSHARE,                     /* FileShare       */
  560.                NULL,                            /* EABuf           */
  561.                NULL                             /* reserved        */
  562.               );
  563.     if (SevCode == SC_NO_ERROR)
  564.        printf("Successfully opened file %s\n",DirFN);
  565.     else
  566.     {  printf("Error opening file %s\n",DirFN);
  567.        printf("Severity code = %u\n",SevCode);
  568.        ReplyMsg();
  569.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  570.        return(SevCode);
  571.     }
  572.  
  573.     /*---------------------------------------------------------------------
  574.     -- Build a record
  575.     ----------------------------------------------------------------------*/
  576.     RecordSize = sizeof(RECLENGTH) + sizeof(CODEPOINT) + RECDATALEN;
  577.     if ((pRecord = (PDDMRECORD)malloc(RecordSize)) == NULL)
  578.     {  printf("Out of memory\n");
  579.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  580.        return(1);
  581.     }
  582.     pRecord->cbRecord = RecordSize;
  583.     pRecord->cpRecord = RECORD;
  584.     memset(pRecord->pRecord, 'N', RECDATALEN);
  585.  
  586.     /*---------------------------------------------------------------------
  587.     -- Insert a record into the direct file
  588.     ----------------------------------------------------------------------*/
  589.     SevCode = DDMInsertRecEOF
  590.               (FileHandle,                      /* FileHandle      */
  591.                DDM_UPDCSR,                      /* AccessFlags     */
  592.                pRecord,                         /* RecordBuf       */
  593.                1UL,                             /* RecCount        */
  594.                NULL,                            /* FdbkBuf         */
  595.                0UL                              /* FdbkBufLen      */
  596.               );
  597.     if (SevCode == SC_NO_ERROR)
  598.        printf("Successfully inserted record in %s\n",DirFN);
  599.     else
  600.     {  printf("Error inserting record in %s\n",DirFN);
  601.        printf("Severity code = %u\n",SevCode);
  602.        ReplyMsg();
  603.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  604.        return(SevCode);
  605.     }
  606.     free(pRecord);
  607.  
  608.     /*---------------------------------------------------------------------
  609.     -- Get a record from the direct file
  610.     ----------------------------------------------------------------------*/
  611.     RecALSize = RecordSize + sizeof(DDMRECAL);
  612.     if ((pRecAL = (PDDMRECAL)malloc(RecALSize)) == NULL)
  613.     {  printf("Out of memory\n");
  614.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  615.        return(1);
  616.     }
  617.     SevCode = DDMGetRec
  618.               (FileHandle,                      /* FileHandle      */
  619.                DDM_RECNBRFB,                    /* AccessFlags     */
  620.                (PDDMRECORD)pRecAL,              /* RecordBuf       */
  621.                (ULONG)RecALSize                 /* RecordBufLen    */
  622.               );
  623.     if (SevCode == SC_NO_ERROR)
  624.     {  printf("Successfully retrieved record from %s\n",DirFN);
  625.        printf("LL = %ld\n",pRecAL->cbRecAL);
  626.        printf("CP = 0x%X\n",pRecAL->cpRecAL);
  627.        printf("L1 = %ld\n",pRecAL->cbRecNum);
  628.        printf("CP = 0x%X\n",pRecAL->cpRecNum);
  629.        printf("Record Number = %lu\n",pRecAL->RecNum);
  630.     }
  631.     else
  632.     {  printf("Error getting record in %s\n",DirFN);
  633.        printf("Severity code = %u\n",SevCode);
  634.        ReplyMsg();
  635.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  636.        return(SevCode);
  637.     }
  638.     free(pRecAL);
  639.  
  640.     /*---------------------------------------------------------------------
  641.     -- Close the direct file
  642.     ----------------------------------------------------------------------*/
  643.     SevCode = DDMClose
  644.               (FileHandle              /* FileHandle      */
  645.               );
  646.     if (SevCode == SC_NO_ERROR)
  647.        printf("Successfully closed file %s\n",DirFN);
  648.     else
  649.     {  printf("Error closing file %s\n",DirFN);
  650.        printf("Severity code = %u\n",SevCode);
  651.        ReplyMsg();
  652.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  653.        return(SevCode);
  654.     }
  655.  
  656.     /*---------------------------------------------------------------------
  657.     -- Delete the direct file
  658.     ----------------------------------------------------------------------*/
  659.     SevCode = DDMDelete
  660.               (DirFN,                /* File Name       */
  661.                0UL                   /* Flags           */
  662.               );
  663.     if (SevCode == SC_NO_ERROR)
  664.        printf("Successfully deleted file %s\n",DirFN);
  665.     else
  666.     {  printf("Error deleting file %s\n",DirFN);
  667.        printf("Severity code = %u\n",SevCode);
  668.        ReplyMsg();
  669.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  670.        return(SevCode);
  671.     }
  672.  
  673.     /*---------------------------------------------------------------------
  674.     -- Create a keyed file with get, insert, and modify capability
  675.     ----------------------------------------------------------------------*/
  676.     KeyDefBuf.cbKeyDefBuf = (ULONG)sizeof(MYKEYDEFBUF);
  677.     KeyDefBuf.cpKeyDefBuf = KEYDEF;
  678.     KeyDefBuf.KeyFldDef[0].cbKeyFldDef = (ULONG)sizeof(KEYFLDDEF);
  679.     KeyDefBuf.KeyFldDef[0].cpKeyFldDef = KEYFLDDF;
  680.     KeyDefBuf.KeyFldDef[0].cpSequence  = SEQASC;
  681.     KeyDefBuf.KeyFldDef[0].cpKeyClass  = BYTSTRDR;
  682.     KeyDefBuf.KeyFldDef[0].cbKeyField  = (USHORT)19;
  683.     KeyDefBuf.KeyFldDef[0].oKeyField   = (ULONG)4;
  684.  
  685.     SevCode = DDMCreateRecFile
  686.               (KeyFN,                           /* FileName        */
  687.                DDM_GETCP | DDM_INSCP |          /* CreateFlags     */
  688.                DDM_MODCP,
  689.                (ULONG)RECDATALEN,               /* RecLen          */
  690.                RECFIX,                          /* RecLenCls       */
  691.                (PKEYDEFBUF)&KeyDefBuf,          /* KeyDefBuf       */
  692.                0UL,                             /* InitFilSiz      */
  693.                -1L,                             /* MaxFileSiz      */
  694.                DUPFILDO,                        /* DupFilOpt       */
  695.                NIL,                             /* DftRecOp        */
  696.                0UL,                             /* RecCnt          */
  697.                NULL,                            /* EABuf           */
  698.                KEYFIL,                          /* FileClass       */
  699.                NULL                             /* DftRecBuf       */
  700.               );
  701.     if (SevCode == SC_NO_ERROR)
  702.        printf("\n\nSuccessfully created keyed file %s\n",KeyFN);
  703.     else
  704.     {  printf("Error creating keyed file %s\n",KeyFN);
  705.        printf("Severity code = %u\n",SevCode);
  706.        ReplyMsg();
  707.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  708.        return(SevCode);
  709.     }
  710.  
  711.     /*---------------------------------------------------------------------
  712.     -- Open the keyed file
  713.     ----------------------------------------------------------------------*/
  714.     SevCode = DDMOpen
  715.               (KeyFN,                           /* FileName        */
  716.                &FileHandle,                     /* FileHandle      */
  717.                CMBKEYAM,                        /* AccessMethod    */
  718.                DDM_GETAI | DDM_INSAI,           /* AccIntList      */
  719.                DDM_NOSHARE,                     /* FileShare       */
  720.                NULL,                            /* EABuf           */
  721.                NULL                             /* reserved        */
  722.               );
  723.     if (SevCode == SC_NO_ERROR)
  724.        printf("Successfully opened file %s\n",KeyFN);
  725.     else
  726.     {  printf("Error opening file %s\n",KeyFN);
  727.        printf("Severity code = %u\n",SevCode);
  728.        ReplyMsg();
  729.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  730.        return(SevCode);
  731.     }
  732.  
  733.     /*---------------------------------------------------------------------
  734.     -- Build a record
  735.     ----------------------------------------------------------------------*/
  736.     RecordSize = sizeof(RECLENGTH) + sizeof(CODEPOINT) + RECDATALEN;
  737.     if ((pRecord = (PDDMRECORD)malloc(RecordSize)) == NULL)
  738.     {  printf("Out of memory\n");
  739.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  740.        return(1);
  741.     }
  742.     pRecord->cbRecord = RecordSize;
  743.     pRecord->cpRecord = RECORD;
  744.     memset(pRecord->pRecord, 'N', RECDATALEN);
  745.  
  746.     /*---------------------------------------------------------------------
  747.     -- Insert a record into the keyed file
  748.     ----------------------------------------------------------------------*/
  749.     SevCode = DDMInsertRecKey
  750.               (FileHandle,                      /* FileHandle      */
  751.                DDM_UPDCSR,                      /* AccessFlags     */
  752.                pRecord,                         /* RecordBuf       */
  753.                NULL,                             /* RecordNumber    */
  754.                1UL                            /* RecCount        */
  755.                
  756.               );
  757.     if (SevCode == SC_NO_ERROR)
  758.        printf("Successfully inserted record in %s\n",KeyFN);
  759.     else
  760.     {  printf("Error inserting record in %s\n",KeyFN);
  761.        printf("Severity code = %u\n",SevCode);
  762.        ReplyMsg();
  763.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  764.        return(SevCode);
  765.     }
  766.     free(pRecord);
  767.  
  768.     /*---------------------------------------------------------------------
  769.     -- Get a record from the keyed file
  770.     ----------------------------------------------------------------------*/
  771.     RecALSize = RecordSize + sizeof(DDMRECALK) + 18; /* 18 is len. of key -1 */
  772.     if ((pRecALK = (PDDMRECALK)malloc(RecALSize)) == NULL)
  773.     {  printf("Out of memory\n");
  774.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  775.        return(1);
  776.     }
  777.     SevCode = DDMGetRec
  778.               (FileHandle,                      /* FileHandle      */
  779.                DDM_KEYVALFB,                    /* AccessFlags     */
  780.                (PDDMRECORD)pRecALK,              /* RecordBuf       */
  781.                (ULONG)RecALSize                 /* RecordBufLen */
  782.               );
  783.     if (SevCode == SC_NO_ERROR)
  784.     {  printf("Successfully retrieved record from %s\n",KeyFN);
  785.        printf("LL = %ld\n",pRecALK->cbRecAL);
  786.        printf("CP = 0x%X\n",pRecALK->cpRecAL);
  787.        printf("L1 = %ld\n",pRecALK->cbKeyVal);
  788.        printf("CP = 0x%X\n",pRecALK->cpKeyVal);
  789.        printf("Record Key Value Feed Back = %.19s\n",pRecALK->pKeyVal);
  790.     }
  791.     else
  792.     {  printf("Error getting record in KeyFN\n");
  793.        printf("Severity code = %u\n",SevCode);
  794.        ReplyMsg();
  795.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  796.        return(SevCode);
  797.     }
  798.     free(pRecALK);
  799.  
  800.     /*---------------------------------------------------------------------
  801.     -- Close the keyed file
  802.     ----------------------------------------------------------------------*/
  803.     SevCode = DDMClose
  804.               (FileHandle               /* FileHandle      */
  805.               );
  806.     if (SevCode == SC_NO_ERROR)
  807.        printf("Successfully closed file %s\n",KeyFN);
  808.     else
  809.     {  printf("Error closing file %s\n",KeyFN);
  810.        printf("Severity code = %u\n",SevCode);
  811.        ReplyMsg();
  812.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  813.        return(SevCode);
  814.     }
  815.  
  816.     /*---------------------------------------------------------------------
  817.     -- Delete the keyed file
  818.     ----------------------------------------------------------------------*/
  819.     SevCode = DDMDelete
  820.               (KeyFN,                 /* File Name       */
  821.                0UL                    /* Flags           */
  822.               );
  823.     if (SevCode == SC_NO_ERROR)
  824.        printf("Successfully deleted file %s\n",KeyFN);
  825.     else
  826.     {  printf("Error deleting file %s\n",KeyFN);
  827.        printf("Severity code = %u\n",SevCode);
  828.        ReplyMsg();
  829.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  830.        return(SevCode);
  831.     }
  832.  
  833.     /*---------------------------------------------------------------------
  834.     -- Create a base file (keyed) with get, insert, modify, and delete
  835.     -- capability
  836.     ----------------------------------------------------------------------*/
  837.     SevCode = DDMCreateRecFile
  838.               (KeyFN2,                          /* FileName        */
  839.                DDM_GETCP | DDM_INSCP |          /* CreateFlags     */
  840.                DDM_MODCP | DDM_DELCP,
  841.                (ULONG)RECDATALEN,               /* RecLen          */
  842.                RECFIX,                          /* RecLenCls       */
  843.                (PKEYDEFBUF)&KeyDefBuf,          /* KeyDefBuf       */
  844.                0UL,                             /* InitFilSiz      */
  845.                -1L,                             /* MaxFileSiz      */
  846.                DUPFILDO,                        /* DupFilOpt       */
  847.                NIL,                             /* DftRecOp        */
  848.                0UL,                             /* RecCnt          */
  849.                NULL,                            /* EABuf           */
  850.                KEYFIL,                          /* FileClass       */
  851.                NULL                             /* DftRecBuf       */
  852.               );
  853.     if (SevCode == SC_NO_ERROR)
  854.        printf("\n\nSuccessfully created keyed file %s\n",KeyFN2);
  855.     else
  856.     {  printf("Error creating keyed file %s\n",KeyFN2);
  857.        printf("Severity code = %u\n",SevCode);
  858.        ReplyMsg();
  859.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  860.        return(SevCode);
  861.     }
  862.  
  863.  /*---------------------------------------------------------------------                
  864.  -- Open the keyed file                                                                 
  865.  ----------------------------------------------------------------------*/               
  866.  SevCode = DDMOpen                                                                      
  867.            (KeyFN2,                           /* FileName        */
  868.             &FileHandle,                     /* FileHandle      */                      
  869.             CMBKEYAM,                        /* AccessMethod    */                      
  870.             DDM_GETAI | DDM_INSAI,           /* AccIntList      */                      
  871.             DDM_NOSHARE,                     /* FileShare       */                      
  872.             NULL,                            /* EABuf           */                      
  873.             NULL                             /* reserved        */                      
  874.            );                                                                           
  875.  if (SevCode == SC_NO_ERROR)                                                            
  876.     printf("Successfully opened file %s\n",KeyFN2);
  877.  else                                                                                   
  878.  {  printf("Error opening file %s\n",KeyFN2);
  879.     printf("Severity code = %u\n",SevCode);                                             
  880.     ReplyMsg();                                                                         
  881.     CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);                                            
  882.     return(SevCode);                                                                    
  883.  }                                                                                      
  884.                                                                                         
  885.  /*---------------------------------------------------------------------                
  886.  -- Build a record                                                                      
  887.  ----------------------------------------------------------------------*/               
  888.  RecordSize = sizeof(RECLENGTH) + sizeof(CODEPOINT) + RECDATALEN;                       
  889.  if ((pRecord = (PDDMRECORD)malloc(RecordSize)) == NULL)                                
  890.  {  printf("Out of memory\n");                                                          
  891.     CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);                                            
  892.     return(1);                                                                          
  893.  }                                                                                      
  894.  pRecord->cbRecord = RecordSize;                                                        
  895.  pRecord->cpRecord = RECORD;                                                            
  896.  memset(pRecord->pRecord, 'N', RECDATALEN);                                             
  897.                                                                                         
  898.  /*---------------------------------------------------------------------                
  899.  -- Insert a record into the keyed file                                                 
  900.  ----------------------------------------------------------------------*/               
  901.  SevCode = DDMInsertRecKey                                                              
  902.            (FileHandle,                      /* FileHandle      */                      
  903.             DDM_UPDCSR,                      /* AccessFlags     */                      
  904.             pRecord,                         /* RecordBuf       */                      
  905.             NULL,                            /* ReccordNumbr   */
  906.             1UL                            /* RecCount        */
  907.                              
  908.            );                                                                           
  909.  if (SevCode == SC_NO_ERROR)                                                            
  910.     printf("Successfully inserted record in %s\n",KeyFN2);
  911.  else                                                                                   
  912.  {  printf("Error inserting record in %s\n",KeyFN2);
  913.     printf("Severity code = %u\n",SevCode);                                             
  914.     ReplyMsg();                                                                         
  915.     CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);                                            
  916.     return(SevCode);                                                                    
  917.  }                                                                                      
  918.  free(pRecord);                                                                         
  919.                                                                                         
  920.  /*---------------------------------------------------------------------                                                  
  921.  -- Close the keyed file                                                                                                  
  922.  ----------------------------------------------------------------------*/                                                 
  923.  SevCode = DDMClose                                                                                                       
  924.            (FileHandle               /* FileHandle      */                                                                
  925.            );                                                                                                             
  926.  if (SevCode == SC_NO_ERROR)                                                                                              
  927.     printf("Successfully closed file %s\n",KeyFN2);
  928.  else                                                                                                                     
  929.  {  printf("Error closing file %s\n",KeyFN);                                                                              
  930.     printf("Severity code = %u\n",SevCode);                                                                               
  931.     ReplyMsg();                                                                                                           
  932.     CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);                                                                              
  933.     return(SevCode);                                                                                                      
  934.  }                                                                                                                        
  935.                                                                                                                           
  936.  
  937.         
  938.  
  939.  
  940.     /*---------------------------------------------------------------------
  941.     -- Create an alternate index file
  942.     ----------------------------------------------------------------------*/
  943.     SevCode = DDMCreateAltIndex
  944.               (AltFN,                           /* FileName        */
  945.                KeyFN2,                          /* BaseName    */
  946.                0UL,                             /* CreateFlags     */
  947.                (PKEYDEFBUF)&KeyDefBuf,          /* KeyDefBuf       */
  948.                DUPFILDO,                        /* DupFilOpt       */
  949.                NULL                             /* DftRecBuf       */
  950.               );
  951.     if (SevCode == SC_NO_ERROR)
  952.        printf("\n\nSuccessfully created alternate index file %s\n",AltFN);
  953.     else
  954.     {  printf("Error creating alternate index file %s\n",AltFN);
  955.        printf("Severity code = %u\n",SevCode);
  956.        ReplyMsg();
  957.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  958.        return(SevCode);
  959.     }
  960.  
  961.     /*---------------------------------------------------------------------
  962.     -- Open the alternate index file
  963.     ----------------------------------------------------------------------*/
  964.     SevCode = DDMOpen
  965.               (AltFN,                           /* FileName        */
  966.                &FileHandle,                     /* FileHandle      */
  967.                CMBKEYAM,                        /* AccessMethod    */
  968.                DDM_GETAI | DDM_INSAI,           /* AccIntList      */
  969.                DDM_NOSHARE,                     /* FileShare       */
  970.                NULL,                            /* EABuf           */
  971.                NULL                             /* reserved        */
  972.               );
  973.     if (SevCode == SC_NO_ERROR)
  974.        printf("Successfully opened file %s\n",AltFN);
  975.     else
  976.     {  printf("Error opening file %s\n",AltFN);
  977.        printf("Severity code = %u\n",SevCode);
  978.        ReplyMsg();
  979.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  980.        return(SevCode);
  981.     }
  982.  
  983.     /*---------------------------------------------------------------------
  984.     -- Close the alternate index file
  985.     ----------------------------------------------------------------------*/
  986.     SevCode = DDMClose
  987.               (FileHandle              /* FileHandle      */
  988.               );
  989.     if (SevCode == SC_NO_ERROR)
  990.        printf("Successfully closed file %s\n",AltFN);
  991.     else
  992.     {  printf("Error closing file %s\n",AltFN);
  993.        printf("Severity code = %u\n",SevCode);
  994.        ReplyMsg();
  995.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  996.        return(SevCode);
  997.     }
  998.  
  999.     /*---------------------------------------------------------------------
  1000.     -- Delete the alternate index file
  1001.     ----------------------------------------------------------------------*/
  1002.     SevCode = DDMDelete
  1003.               (AltFN,                   /* File Name   */
  1004.                0UL                      /* Flags       */
  1005.               );
  1006.     if (SevCode == SC_NO_ERROR)
  1007.        printf("Successfully deleted file %s\n",AltFN);
  1008.     else
  1009.     {  printf("Error deleting file %s\n",AltFN);
  1010.        printf("Severity code = %u\n",SevCode);
  1011.        ReplyMsg();
  1012.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  1013.        return(SevCode);
  1014.     }
  1015.  
  1016.     /*---------------------------------------------------------------------
  1017.     -- Delete the base file
  1018.     ----------------------------------------------------------------------*/
  1019.     SevCode = DDMDelete
  1020.               (KeyFN2,               /* File Name */
  1021.                0UL                   /* Flags     */
  1022.               );
  1023.     if (SevCode == SC_NO_ERROR)
  1024.        printf("Successfully deleted file %s\n",KeyFN2);
  1025.     else
  1026.     {  printf("Error deleting file %s\n",KeyFN2);
  1027.        printf("Severity code = %u\n",SevCode);
  1028.        ReplyMsg();
  1029.        CleanUp(SeqFN,DirFN,KeyFN,AltFN,KeyFN2);
  1030.        return(SevCode);
  1031.     }
  1032.  
  1033.     printf("*****************TEST CASE DUBSAMP WAS SUCCESSFUL**************\n");
  1034.     return(SC_NO_ERROR);
  1035.  
  1036. } /* sample main */
  1037.  
  1038.  
  1039. /**************************************************************************
  1040. ****************************  ReplyMsg  ***********************************
  1041. ***************************************************************************
  1042. *   Process the reply message if there is a Severity Code other than
  1043. *   SC_NO_ERROR;
  1044. *
  1045. ***************************************************************************/
  1046. VOID ReplyMsg(VOID)
  1047. {
  1048.     static BYTE pRpyMsgBuf[RPYMSBFLN];
  1049.  
  1050.     APIRET     rc;
  1051.     CODEPOINT  CodePoint;
  1052.     PDDMOBJECT pReplyObject;
  1053.     USHORT     index;
  1054.  
  1055.     /*---------------------------------------------------------------------
  1056.     --  The following table contains the count for the number of parameters
  1057.     --  expected for each reply message (1st column), and it also contains
  1058.     --  the expanded error messages
  1059.     --
  1060.     -- The first message in the table, KEYUDIRM, has the lowest
  1061.     -- code point value.  It is also the first message in a block of
  1062.     -- message code points that ends with RECNAVRM.
  1063.     --
  1064.     -- The next block of message code points (in ascending code point order)
  1065.     -- begins with OS2ERRRM and ends with FILERRRM.
  1066.     -- The low-order byte is used as the index into this block.
  1067.     ----------------------------------------------------------------------*/
  1068.     static struct
  1069.     {  USHORT   Count;
  1070.        BYTE     msg[52];
  1071.     } ErrorMsgBuffer[] =
  1072.       { 6, "Key Update Not Allowed by Different Index         \0",   /* KEYUDIRM */
  1073.         0, "                                                  \0",
  1074.         3, "System Command Reply Message                      \0",   /* SYSCMDRM */ /*@L0C*/
  1075.         0, "Default Record Error                              \0",   /* DFTRECRM */
  1076.         5, "Cursor Not Selecting a Record Position            \0",   /* CSRNSARM */
  1077.         7, "Invalid Data Record                               \0",   /* DTARECRM */
  1078.         3, "Duplicate File Name                               \0",   /* DUPFILRM */
  1079.         8, "Duplicate Key Different Index                     \0",   /* DUPKDIRM */
  1080.         7, "Duplicate Key Same Index                          \0",   /* DUPKSIRM */
  1081.         7, "Duplicate Record Number                           \0",   /* DUPRNBRM */
  1082.         3, "End of File                                       \0",   /* ENDFILRM */
  1083.         7, "File is Full                                      \0",   /* FILFULRM */
  1084.         4, "File in Use                                       \0",   /* FILIUSRM */
  1085.         3, "File Not Found                                    \0",   /* FILNFNRM */
  1086.         6, "File Space Not Available                          \0",   /* FILSNARM */
  1087.         3, "Manager Level Conflict                            \0",   /* MGRLVLRM */ /*@L0C*/
  1088.         4, "File Not Opened                                   \0",   /* FILNOPRM */ /*@L0C*/
  1089.         3, "Invalid File Name                                 \0",   /* FILNAMRM */
  1090.         0, "                                                  \0",
  1091.         3, "Shadow Exists                                     \0",   /* SHDEXSRM */ /*@L0C*/
  1092.         7, "Record Length Mismatch                            \0",   /* RECLENRM */
  1093.         3, "Storage Class Not Found                           \0",   /* STGNFNRM */ /*@L0C*/
  1094.         3, "Management Class Not Found                        \0",   /* MGMNFNRM */ /*@L0C*/
  1095.         4, "Manager Dependency Error                          \0",   /* MGRDEPRM */ /*@L0C*/
  1096.         0, "                                                  \0",
  1097.         3, "Not Authorized to Storage Class                   \0",   /* STGATHRM */ /*@L0C*/
  1098.         3, "Not Authorized to Management Class                \0",   /* MGMATHRM */ /*@L0C*/
  1099.         2, "Not Authorized to Function                        \0",   /* FUNATHRM */
  1100.         4, "File Open Lock Option Changed                     \0",   /* FILOLORM */ /*@L0C*/
  1101.         4, "File Temporarily Not Available                    \0",   /* FILTNARM */
  1102.         0, "                                                  \0",
  1103.         2, "Declare Conflict                                  \0",   /* DCLCNFRM */ /*@L0C*/
  1104.         3, "Directory is Temporarily Not Available            \0",   /* DRCTNARM */ /*@L0C*/
  1105.         0, "                                                  \0",
  1106.         0, "                                                  \0",
  1107.         7, "Record Number Out of Bounds                       \0",   /* RECNBRRM */
  1108.         5, "Record Not Found                                  \0",   /* RECNFNRM */
  1109.         0, "                                                  \0",
  1110.         0, "                                                  \0",
  1111.         0, "                                                  \0",
  1112.         0, "                                                  \0",
  1113.         0, "                                                  \0",
  1114.         0, "                                                  \0",
  1115.         3, "Data Class Not Found                              \0",   /* DTANFNRM */ /*@L0C*/
  1116.         3, "Invalid Key Length                                \0",   /* KEYLENRM */
  1117.         0, "                                                  \0",
  1118.         0, "                                                  \0",
  1119.         3, "Not Authorized to Access Method                   \0",   /* ACCATHRM */
  1120.         0, "Invalid Access Method                             \0",   /* ACCMTHRM */
  1121.         3, "Permanent Agent Error                             \0",   /* AGNPRMRM */
  1122.         6, "Resource Limits Reached on Target System          \0",   /* RSCLMTRM */
  1123.         3, "Invalid Base File Name                            \0",   /* BASNAMRM */
  1124.         0, "                                                  \0",
  1125.         0, "                                                  \0",
  1126.         2, "Not Authorized to Directory                       \0",   /* DRCATHRM */
  1127.         0, "Management Class Conflict                         \0",   /* MGMCNFRM */
  1128.         0, "Storage Class Conflict                            \0",   /* STGCNFRM */
  1129.         3, "Existing Condition                                \0",   /* EXSCNDRM */
  1130.         4, "Not Authorized to File                            \0",   /* FILATHRM */
  1131.         6, "Invalid Request                                   \0",   /* INVRQSRM */
  1132.         4, "Invalid Key Definition                            \0",   /* KEYDEFRM */
  1133.         0, "                                                  \0",
  1134.         5, "Key Update Not Allowed by Same Index              \0",   /* KEYUSIRM */
  1135.         8, "Invalid Key Value                                 \0",   /* KEYVALRM */
  1136.         3, "Invalid User                                      \0",   /* INVUSRRM */ /*@L0C*/
  1137.         3, "Open Conflict Error                               \0",   /* OPNCNFRM */ /*@L0C*/
  1138.         3, "Open Exclusive by Same User                       \0",   /* OPNEXCRM */
  1139.         4, "Concurrent Open Exceeds Maximum                   \0",   /* OPNMAXRM */
  1140.         4, "Conversational Protocol Error                     \0",   /* PRCCNVRM */
  1141.         0, "                                                  \0",
  1142.         0, "                                                  \0",
  1143.         0, "                                                  \0",
  1144.         7, "Record Damaged                                    \0",   /* RECDMGRM */
  1145.         7, "Record in Use                                     \0",   /* RECIUSRM */
  1146.         2, "Command Processing Completed                      \0",   /* CMDCMPRM */ /*@L0C*/
  1147.         5, "Data Stream Syntax Error                          \0",   /* SYNTAXRM */
  1148.         7, "Update Cursor Error                               \0",   /* UPDCSRRM */
  1149.         5, "No Update Intent on Record                        \0",   /* UPDINTRM */
  1150.         3, "Invalid New File Name                             \0",   /* NEWNAMRM */
  1151.         3, "Function Not Supported                            \0",   /* FUNNSPRM */
  1152.         3, "Parameter Not Supported                           \0",   /* PRMNSPRM */
  1153.         4, "Parameter Value Not Supported                     \0",   /* VALNSPRM */
  1154.         4, "Object Not Supported                              \0",   /* OBJNSPRM */
  1155.         5, "Command Check                                     \0",   /* CMDCHKRM */
  1156.         2, "Duplicate Declared Name                           \0",   /* DUPDCLRM */ /*@L0C*/
  1157.         2, "Invalid Declared Name                             \0",   /* DCLNAMRM */ /*@L0C*/
  1158.         2, "File Handle Not Found                             \0",   /* HDLNFNRM */
  1159.         3, "Directory Full                                    \0",   /* DRCFULRM */
  1160.         3, "Record Inactive                                   \0",   /* RECINARM */
  1161.         7, "File Damaged                                      \0",   /* FILDMGRM */
  1162.         4, "Load Records Count Mismatch                       \0",   /* LODRECRM */
  1163.         3, "Not Authorized to Open Intent for Named File      \0",   /* INTATHRM */
  1164.         5, "User Attribute Error                              \0",   /* USRATTRM */ /*@L0C*/
  1165.         3, "File Closed with Damage                           \0",   /* CLSDMGRM */
  1166.         2, "Target Not Supported                              \0",   /* TRGNSPRM */
  1167.         5, "Key Value Modified after Cursor was Last Set      \0",   /* KEYMODRM */
  1168.         4, "Change File Attributes Rejected                   \0",   /* CHGFATRM */ /*@L0C*/
  1169.         3, "Invalid Directory Name                            \0",   /* DRCNAMRM */ /*@L0C*/
  1170.         3, "Directory Not Found                               \0",   /* DRCNFNRM */ /*@L0C*/
  1171.         5, "Stream In Use Error                               \0",   /* STRIUSRM */ /*@L0C*/
  1172.         7, "Invalid Substream                                 \0",   /* SUBSTRRM */ /*@L0C*/
  1173.         0, "Access Intent List Error                          \0",   /* ACCINTRM */
  1174.         3, "Directory In Use                                  \0",   /* DRCIUSRM */ /*@L0C*/
  1175.         7, "Stream Damaged                                    \0",   /* STRDMGRM */ /*@L0C*/
  1176.         3, "Invalid Directory Entry                           \0",   /* DRCENTRM */ /*@L0C*/
  1177.         3, "Duplicate Directory Name                          \0",   /* DUPDRCRM */ /*@L0C*/
  1178.         3, "Directory Space Not Available                     \0",   /* DRCSNARM */ /*@L0C*/
  1179.         7, "Data Mapping Error                                \0",   /* DTAMAPRM */ /*@L0C*/
  1180.         0, "                                                  \0",
  1181.         4, "Load Stream Count Mismatch                        \0",   /* LODSTRRM */ /*@L0C*/
  1182.         5, "Record Not Available                              \0",   /* RECNAVRM */
  1183.  
  1184.      /************ START OF SECOND CODE POINT RANGE *************/
  1185.         0, "OS/2 Error                                        \0",   /* OS2ERRRM */
  1186.         0, "Data Description File Not Found                   \0",   /* DDFNFNRM */
  1187.         0, "Conversion Table Not Found                        \0",   /* CVTNFNRM */
  1188.         2, "Translation Error                                 \0",   /* XLATERM  */
  1189.         0, "                                                  \0",
  1190.         2, "Invalid Flag                                      \0",   /* INVFLGRM */
  1191.         0, "                                                  \0",
  1192.         2, "Communications Error                              \0",   /* COMMRM   */
  1193.         0, "                                                  \0",
  1194.         0, "                                                  \0",
  1195.         0, "                                                  \0",
  1196.         0, "                                                  \0",
  1197.         0, "                                                  \0",
  1198.         0, "                                                  \0",
  1199.         0, "                                                  \0",
  1200.         0, "                                                  \0",
  1201.         2, "Resource Limit Reached in OS/2 V2.0 Source Syste  \0",   /* SRCLMTRM */
  1202.         2, "Field Length Error                                \0",   /* LENGTHRM */
  1203.         2, "Address Error                                     \0",   /* ADDRRM   */
  1204.         0, "                                                  \0",
  1205.         2, "Function Continuation Error                       \0",   /* CONTRM   */
  1206.         0, "                                                  \0",
  1207.         2, "File Error                                        \0"    /* FILERRRM */
  1208.       };
  1209.  
  1210.     /*---------------------------------------------------------------------
  1211.     -- For each reply message available, retrieve and display it.
  1212.     ----------------------------------------------------------------------*/
  1213.     do
  1214.     {  /*------------------------------------------------------------------
  1215.        -- Get the reply message
  1216.        -------------------------------------------------------------------*/
  1217.        rc = DDMGetReplyMessage(pRpyMsgBuf, (ULONG)RPYMSBFLN, (ULONG)1);
  1218.  
  1219.        switch (rc)
  1220.        {  case SC_NO_ERROR:      /* All reply messages have been received */
  1221.           case SC_WARNING: /* There are more reply messages to be received */
  1222.              break;
  1223.           case SC_ERROR:
  1224.              printf("   ReplyMsg: reply message buffer is too small -\n");
  1225.              printf("              enlarge and recompile ...\n");
  1226.              return;
  1227.              break;
  1228.           case SC_SEVERE:
  1229.              printf("   ReplyMsg: Warning: A reply message was requested,\n");
  1230.              printf("              but there are none available ...\n");
  1231.              return;
  1232.              break;
  1233.           case SC_ACCESSDAMAGE:
  1234.              printf("   ReplyMsg: Error: An invalid reply message buffer\n");
  1235.              printf("              address was specified ...\n");
  1236.              return;
  1237.              break;
  1238.           case SC_PERMDAMAGE:
  1239.              printf("   ReplyMsg: Severe Error: An unarchitected reply message\n");
  1240.              printf("              object was encountered ...\n");
  1241.              return;
  1242.              break;
  1243.           default:
  1244.              printf("   ReplyMsg: Unknown return code from DDMGetReplyMessage\n");
  1245.              return;
  1246.              break;
  1247.        } /* endswitch */
  1248.  
  1249.        /*------------------------------------------------------------------
  1250.        -- Get the reply message
  1251.        -------------------------------------------------------------------*/
  1252.        pReplyObject = (PDDMOBJECT)pRpyMsgBuf;
  1253.  
  1254.        CodePoint = pReplyObject->cpObject;              /* get code point */
  1255.  
  1256.        /* reset pointer to first parm base */
  1257.        pReplyObject = (PDDMOBJECT)((PBYTE)pReplyObject
  1258.                                    + (sizeof(CODEPOINT)
  1259.                                       + sizeof(OBJLENGTH))
  1260.                                   );
  1261.  
  1262.        /*------------------------------------------------------------------
  1263.        -- Calculate the index into the parameter/msg table based on
  1264.        -- the codepoint.
  1265.        -------------------------------------------------------------------*/
  1266.        if (CodePoint <= RECNAVRM)         /* if code point in first block */
  1267.           index = (USHORT)(CodePoint - KEYUDIRM);
  1268.        else                               /* code point in second block */
  1269.           index = (USHORT)
  1270.                   ((RECNAVRM - KEYUDIRM + 1) /* number of entries in
  1271.                                                 first block */
  1272.                    + (CodePoint % 0x0100UL) /* index into second block */
  1273.                   );
  1274.  
  1275.        /*------------------------------------------------------------------
  1276.        -- Begin dissecting the reply message buffer
  1277.        -------------------------------------------------------------------*/
  1278.        if (ErrorMsgBuffer[index].Count > 0)
  1279.        {  printf("RPYMSG: %s\n",ErrorMsgBuffer[index].msg);
  1280.           DumpBuffer(pReplyObject, ErrorMsgBuffer[index].Count);
  1281.           printf("\n");
  1282.        }
  1283.  
  1284.     } while (rc == SC_WARNING); /* enddo */
  1285.  
  1286. } /* ReplyMsg */
  1287.  
  1288. /**************************************************************************
  1289. **************************  DumpBuffer  ***********************************
  1290. ***************************************************************************
  1291. *
  1292. *   For each object in the reply message buffer, print out its contents.
  1293. *
  1294. ***************************************************************************/
  1295. VOID DumpBuffer(PDDMOBJECT  pAttribute,
  1296.                 USHORT      Count)
  1297. {
  1298.     do
  1299.     {  if (pAttribute->cbObject == (sizeof(CODEPOINT) + sizeof(OBJLENGTH)))
  1300.        {  printf("Null object returned = %x\n",pAttribute->cbObject);
  1301.           pAttribute->cpObject = 0;
  1302.        }
  1303.        else
  1304.        {  switch(pAttribute->cpObject)
  1305.           {  case ACCMTHCL:                 /* Access Method Class */
  1306.                 printf("ACCMTHCL = 0x%X\n", *(PCODEPOINT)(pAttribute->pData));
  1307.                 break;
  1308.              case BASFILNM:                 /* Base File Name */
  1309.                printf("BASFILNM = %s\n", pAttribute->pData);
  1310.                 break;
  1311.              case CODPNT:                   /* Code Point */
  1312.                 printf("CODPNT = 0x%X\n", *(PCODEPOINT)(pAttribute->pData));
  1313.                 break;
  1314.              case CSRPOSST:                 /* Cursor Position Status */
  1315.                 printf("CSRPOSST = 0x%hX\n", *(PBYTE)(pAttribute->pData));
  1316.                 break;
  1317.              case DTALCKST:                 /* Data Lock Status */
  1318.                 printf("DTALCKST = 0x%hX\n", *(PBYTE)(pAttribute->pData));
  1319.                 break;
  1320.              case ERRFILNM:                 /* Error File Name */
  1321.                 printf("ERRFILNM = %s\n", pAttribute->pData);
  1322.                 break;
  1323.              case FILNAM:                   /* File Name */
  1324.                 printf("FILNAM = %s\n", pAttribute->pData);
  1325.                 break;
  1326.              case KEYDEFCD:                 /* Key Definition Error Code */
  1327.                 printf("KEYDEFCD = 0x%hX\n", *(PBYTE)(pAttribute->pData));
  1328.                 break;
  1329.              case MAXOPN:                   /* Maximum Number of File Extents
  1330.                                                 Concurrent Opens Allowed */
  1331.                 printf("MAXOPN = %d\n", *(PUSHORT)(pAttribute->pData));
  1332.                 break;
  1333.              case NEWFILNM:                 /* New File Name */
  1334.                 printf("NEWFILNM = %s\n", pAttribute->pData);
  1335.                 break;
  1336.              case PRCCNVCD:         /* Conversational Protocol Error Code */
  1337.                 printf("PRCCNVCD = 0x%hX\n", *(PBYTE)(pAttribute->pData));
  1338.                 break;
  1339.              case RECCNT:                   /* Record Count */
  1340.                 printf("RECCNT = %ld\n", *(PULONG)(pAttribute->pData));
  1341.                 break;
  1342.              case RECNBR:                   /* Record Number */
  1343.                 printf("RECNBR = %ld\n", *(PRECNUM)(pAttribute->pData));
  1344.                 break;
  1345.              case SRVDGN:      {            /* Server Diagnostic Information */
  1346.                 int i;
  1347.                 printf("SRVDGN = 0x\n");
  1348.                 for (i=1; i < (pAttribute->cbObject-5); i++) /* 2 byte len, 2 byte codept*/
  1349.                     { if (i % 16 ==0)
  1350.                                   printf("%02X\n", *(PBYTE)(pAttribute->pData+i-1));
  1351.                        else
  1352.                        if (i % 4 ==0) 
  1353.                                   printf("%02X ", *(PBYTE)(pAttribute->pData+i-1));
  1354.                        else
  1355.                            printf("%02X", *(PBYTE)(pAttribute->pData+i-1));
  1356.                      }
  1357.                }
  1358.  
  1359.     
  1360.     
  1361.                 
  1362.                 break;
  1363.              case SVRCOD:                   /* Severity Code */
  1364.                 printf("SVRCOD = 0x%X\n", *(PCODEPOINT)(pAttribute->pData));
  1365.                 break;
  1366.              case SYNERRCD:                 /* Syntax Error Code */
  1367.                 printf("SYNERRCD = 0x%hX\n", *(PBYTE)(pAttribute->pData));
  1368.                 break;
  1369.              default:
  1370.                 printf("Unknown code point - 0x%X\n",
  1371.                        *(PCODEPOINT)(pAttribute->pData));
  1372.                 break;
  1373.           } /* endswitch */
  1374.        } /* endif */
  1375.  
  1376.        /* go to next object */
  1377.        pAttribute = (PDDMOBJECT)((PBYTE)pAttribute + pAttribute->cbObject);
  1378.  
  1379.     } while(--Count > 0);
  1380.  
  1381. } /* DumpBuffer */
  1382.  
  1383. /**************************************************************************
  1384. ****************************  CleanUp *************************************
  1385. ***************************************************************************
  1386. *   Delete all files if any error occurs during processing
  1387. *
  1388. ***************************************************************************/
  1389. VOID CleanUp(CHAR *File1,
  1390.              CHAR *File2,
  1391.              CHAR *File3,
  1392.              CHAR *File4,
  1393.              CHAR *File5)
  1394. {
  1395.    DDMDelete(File1, 0);
  1396.    DDMDelete(File2, 0);
  1397.    DDMDelete(File3, 0);
  1398.    DDMDelete(File4, 0);
  1399.    DDMDelete(File5, 0);
  1400. } /* CleanUp */
  1401.  
  1402.