home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / gened10.zip / SAMPLE0.C < prev    next >
Text File  |  1996-04-03  |  65KB  |  1,799 lines

  1. /*
  2.  *      Created 1993  IBM Corp.                                            *
  3.  *                                                                         *
  4.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  5.  *      sample code created by IBM Corporation. This sample code is not    *
  6.  *      part of any standard or IBM product and is provided to you solely  *
  7.  *      for  the purpose of assisting you in the development of your       *
  8.  *      applications.  The code is provided "AS IS", without               *
  9.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  10.  *      arising out of your use of the sample code, even if they have been *
  11.  *      advised of the possibility of such damages.                        *
  12.  */
  13. /**************************************************************************
  14.  * encode/decode sample program for the ASN.1 specification of TEST0.asn.
  15.  * This sample uses:
  16.  * 1.GDSD encoding
  17.  * 2.contents user-exit
  18.  * 3.contents-array
  19.  * 4.decoding user-exit
  20.  *
  21.  * It tests also an error situation in decoding: the SIZE constraint of
  22.  * cmd2 of Req3 of DDM0 is not matched.
  23.  * Arguments:
  24.  *            .DAT file,
  25.  *            input buffer length,
  26.  *            output buffer length,
  27.  *            only decoding (ENC or NOENC)
  28.  *****************************************************************************
  29.  */
  30.  
  31. /*
  32.  * The following are needed to compile this program. Note that the
  33.  * order of the header files is important.
  34.  */
  35.  
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <ctype.h>
  39. #include <string.h>
  40. #include "gdstypes.h"
  41. #include "gdsrcods.h"
  42. #include "gdsproto.h"
  43. #include "test0ndx.h"
  44. #include "sample0.h"
  45.  
  46.  
  47. main(int argc, char **argv)
  48. {
  49.    int                   rc, onlydec;
  50.    void                 *Mod, *env;
  51.    unsigned short        Typ;
  52.    long                  l;
  53.    char                  savmodname[50], *ModName, modname[50];
  54.    unsigned long         EncBytes, inbuflen, outbuflen, DecBytes;
  55.    enum TypOfEnc         enctype;
  56.    struct gds           *p1;
  57.    FILE                 *trace_enc;
  58.    FILE                 *trace_dec;
  59.    FILE                 *EncStream;    /* input-output file */
  60.    FILE                 *usrdecfile;   /* file written by decoding user-exit */
  61.    static char          *dummy = "dummy";
  62.  
  63.    if (argc < 5) {
  64.       exit(0);
  65.    }   /* endif */
  66.  
  67.  /*
  68.   * only decoding?
  69.   */
  70.    if (!strcmp(argv[4],"ENC")) {
  71.     onlydec = 0;
  72.    } else {
  73.      if (!strcmp(argv[4],"NOENC")) {
  74.        onlydec = 1;
  75.      } else {
  76.        printf("invalid encoding YES/NO parameter\n");
  77.        exit(-1);
  78.      } /* endif */
  79.    } /* endif */
  80.  
  81. /*
  82.  * set the type of encoding indicator
  83.  */
  84.    enctype = gdsd;
  85.  
  86.  
  87.    inbuflen = atol(argv[2]);     /* set the length of the input buffer */
  88.    outbuflen = atol(argv[3]);    /* set the length of output buffer */
  89.  
  90.  
  91. /*
  92.  * open the trace file for encoded gds tree
  93.  */
  94.    trace_enc = fopen("enctrace0.out","w");
  95.    if (trace_enc == NULL) { /* open file failed */
  96.      printf("open enc trace file failed\n");
  97.      exit(-1);
  98.    } /* endif */
  99.  
  100. /*
  101.  * open the trace file for decoded gds tree
  102.  */
  103.    trace_dec = fopen("dectrace0.out","w");
  104.    if (trace_dec == NULL) { /* open file failed */
  105.      printf("open dec trace file failed\n");
  106.      exit(-1);
  107.    } /* endif */
  108.  
  109. /*
  110.  * open the decoding user-exit output file
  111.  */
  112.    usrdecfile = fopen("usrdec0.out","w");
  113.    if (usrdecfile == NULL) { /* open file failed */
  114.      printf("open decoding user-exit output file failed\n");
  115.      exit(-1);
  116.    } /* endif */
  117.  
  118. /*****************************
  119.  * INITIALIZATION
  120.  *****************************
  121.  */
  122.  
  123. /*
  124.  * Call the library routine, GDSinitEnvironment, to initialize the environment.
  125.  * Each application program has to do this before calling any routine to
  126.  * read .dat files, encode or decode GDSs.
  127.  */
  128.    rc = GDSinitEnvironment(&env);
  129.  
  130.    if (rc != INIT_ENV_OK) {
  131.      printf("GDSinitEnvironment return code: %i\n", rc);
  132.      exit(rc);
  133.    }
  134.  
  135. /*
  136.  * Call the library routine, GDSsetUsrWrite, to set the user exit routine for
  137.  * writing buffer.
  138.  */
  139.    GDSsetUsrWrite(mywrite, env);
  140.  
  141. /*
  142.  * Call the library routine, GDSsetUsrRead, to set the user exit routine for
  143.  * reading buffer.
  144.  */
  145.    GDSsetUsrRead(myread, env);
  146.  
  147. /*
  148.  * Call the library routine, GDSsetUsrDec, to set the decoding user exit
  149.  */
  150.    GDSsetUsrDec(mydec, env);
  151.  
  152.  
  153. /*
  154.  * Call the library routine, GDSreaddatfile, to read a .dat file containing
  155.  * the metatables and symbol tables for one or more ASN.1 module.  Note that
  156.  * references between ASN.1 modules (imported and exported symbols) are *not*
  157.  * resolved by GDSreaddatfile.
  158.  */
  159.    rc = GDSreaddatfile(argv[1], env); /* first parm should be a readable data file */
  160.  
  161.    if (rc != READ_DAT_OK) {
  162.      printf("GDSreaddatfile return code: %i\n", rc);
  163.      exit(rc);
  164.    }
  165.  
  166. /*
  167.  * Call the library routine, GDSresolveallimports, to resolve imports and
  168.  * exports in the .dat file.  Note that if more than one .dat file had
  169.  * been read in with multiple calls to GDSreaddatfile, this call should be
  170.  * deferred as late as possible to maximize performance.  Multiple calls
  171.  * to GDSresolveallimports are allowed, however.
  172.  */
  173.    rc = GDSresolveallimports(env);
  174.  
  175.    if (rc != RESOLVE_IMPORTS_OK) {
  176.      printf("GDSresolveallimports return code: %i\n", rc);
  177.  
  178.     /* Call the library routine, GDSPrintUnresolvedImports, to print the
  179.      * unresolved imports */
  180.      GDSPrintUnresolvedImports(stdout, env);
  181.      exit(rc);
  182.    }
  183.  
  184. /*
  185.  * Call the library routine, fGDSirstmodule, to get pointers to the first
  186.  * module structure and the module name string in the current chain of modules.
  187.  * This is done in this program to obtain the default module name for
  188.  * querying the user for module to encode and decode.
  189.  */
  190.    GDSfirstmodule(&Mod,         /* return ptr to a moddef structure */
  191.                   &ModName,     /* return ptr to the module name string */
  192.                   env
  193.                  );
  194.  
  195.    strcpy(savmodname, ModName);
  196.    ModName = savmodname;
  197.  
  198. /*
  199.  * This loop repeatedly asks the user to enter a module and type name.
  200.  * It terminates upon user request or when an error is detected.
  201.  */
  202.  
  203.    for (;;) {
  204.  
  205.       char                  *readmod, readbuf[100], cont1[2], cont2[2];
  206.       unsigned char         *cont;
  207.       long                   lencont;
  208.       struct contents_str   *ContArrayPtr;
  209.       struct content_str    *cont_list;
  210.       struct errdata         errinfo;
  211.  
  212.       if (!onlydec) {
  213.         printf("\n[%s.]Module (or stop): ", savmodname);
  214.         fflush(NULL);
  215.  
  216.      /*
  217.       * ask user for module name
  218.       */
  219.         strcpy(modname, savmodname);
  220.         readmodtype(readbuf, sizeof(readbuf), &readmod);
  221.         if (readmod != NULL) {         /* if user typed in a module name */
  222.           if (!strcmp(readmod, "stop")) {
  223.             break;
  224.           } /* endif */
  225.           strcpy(modname, readmod);    /* use the module name the user typed
  226.                                         * in */
  227.         } /* endif */
  228.  
  229. /*
  230.  * Call the library routine, GDSfindmodule, to find the moddef structure
  231.  * corresponding to the name in the modname string.
  232.  */
  233.         Mod = GDSfindmodule(modname, env);
  234.         if (Mod == NULL) {        /* if module not found */
  235.           printf("\nModule not found\n");
  236.           continue;               /* allow more attempts */
  237.         }                         /* endif */
  238.  
  239. /*
  240.  * Call the library routine, GDSfindtype, to find the metatable index in
  241.  * the Mod module corresponding to the type name "Req".  Note that
  242.  * the .H files created by the ASN.1 compiler contain symbol names for
  243.  * the type and value metatable indices.  When the type or value name
  244.  * is known at application compile-time, these symbolic names can be
  245.  * used directly instead of searching through the metatables at
  246.  * runtime.
  247.  */
  248.         rc = GDSfindtype(Mod,     /* module where type is to be found */
  249.                          "Req",   /* type name string */
  250.                          &Typ     /* returned metatable index */
  251.                       );
  252.         if (rc != FIND_TYPE_OK) {        /* if type not found */
  253.           printf("\nType not found; rc = %i\n", rc);
  254.           continue;                      /* allow more attempts */
  255.         }                      /* endif */
  256.  
  257. /********************************
  258.  * ENCODING
  259.  ********************************
  260.  */
  261.  
  262. /*
  263.  * Call the library routine GDSallocateContentsArray to allocate
  264.  * the array of contents pointers for the specified module.
  265.  * This function returns a pointer to the first location of the array
  266.  */
  267.  
  268.         rc = GDSallocateContentsArray(Mod, &ContArrayPtr);
  269.         if (rc == ALLOCATECONT_NO_ENOUGH_STORAGE) {
  270.           printf("no enough storage for contents pointers array\n");
  271.           return(-1);
  272.         } /* endif */
  273.  
  274. /*
  275.  * Load the Contents Array
  276.  */
  277.  
  278.  
  279.        (ContArrayPtr[DDM1_Req0_SET_OF]).len = 2; /* number of items of SET OF */
  280.  
  281. /*
  282.  * Call the library routine GDSallocateContListArray to allocate
  283.  * the array of contents pointers for SET OF type.
  284.  * This function returns a pointer to the first location of the array
  285.  */
  286.  
  287.         (ContArrayPtr[DDM1_Req1_SET]).content = dummy;
  288.  
  289.         rc = GDSallocateContListArray(2, &cont_list);
  290.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  291.           printf("no enough storage for contents list pointers array\n");
  292.           return(-1);
  293.         } /* endif */
  294.  
  295.         cont = (unsigned char *) NEW(long);
  296.         GDSlongtoINTEGER(1L, cont, &lencont);
  297.         (cont_list[0]).content = cont;
  298.         (cont_list[0]).len = lencont;
  299.         (cont_list[0]).contstg = allocd;
  300.         cont = (unsigned char *) NEW(long);
  301.         GDSlongtoINTEGER(0L, cont, &lencont);
  302.         (cont_list[1]).content = cont;
  303.         (cont_list[1]).len = lencont;
  304.         (cont_list[1]).contstg = allocd;
  305.         (ContArrayPtr[DDM1_Req1_SET_cmd1_ENUMERATED]).contlist = cont_list;
  306.         (ContArrayPtr[DDM1_Req1_SET_cmd1_ENUMERATED]).len = 2;
  307.  
  308.         rc = GDSallocateContListArray(2, &cont_list);
  309.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  310.           printf("no enough storage for contents list pointers array\n");
  311.           return(-1);
  312.         } /* endif */
  313.  
  314.         cont = (unsigned char *) NEW(long);
  315.         GDSlongtoINTEGER(5L, cont, &lencont);
  316.         (cont_list[0]).content = cont;
  317.         (cont_list[0]).len = lencont;
  318.         (cont_list[0]).contstg = allocd;
  319.         cont = (unsigned char *) NEW(long);
  320.         GDSlongtoINTEGER(10L, cont, &lencont);
  321.         (cont_list[1]).content = cont;
  322.         (cont_list[1]).len = lencont;
  323.         (cont_list[1]).contstg = allocd;
  324.         (ContArrayPtr[DDM1_Req1_SET_cmd2_INTEGER]).contlist = cont_list;
  325.         (ContArrayPtr[DDM1_Req1_SET_cmd2_INTEGER]).len = 2;
  326.  
  327.  
  328.         rc = GDSallocateContListArray(2, &cont_list);
  329.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  330.           printf("no enough storage for contents list pointers array\n");
  331.           return(-1);
  332.         } /* endif */
  333.  
  334.         cont = (unsigned char *) NEW2(10,unsigned char);
  335.         GDSstr2hex(cont, 10, "00112233445566778899", 20);
  336.         (cont_list[0]).content = cont;
  337.         (cont_list[0]).len = 10;
  338.         (cont_list[0]).contstg = allocd;
  339.         cont = (unsigned char *) NEW2(5,unsigned char);
  340.         GDSstr2hex(cont, 5, "0011223344", 10);
  341.         (cont_list[1]).content = cont;
  342.         (cont_list[1]).len = 5;
  343.         (cont_list[1]).contstg = allocd;
  344.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd1_OCTET_STRING]).contlist = cont_list;
  345.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd1_OCTET_STRING]).len = 2;
  346.  
  347.         rc = GDSallocateContListArray(2, &cont_list);
  348.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  349.           printf("no enough storage for contents list pointers array\n");
  350.           return(-1);
  351.         } /* endif */
  352.  
  353.         cont = (unsigned char *) NEW2(20,unsigned char);
  354.         memcpy(cont, "Caro amico ti scrivo",20);
  355.         (cont_list[0]).content = cont;
  356.         (cont_list[0]).len = 20;
  357.         (cont_list[0]).contstg = allocd;
  358.         cont = (unsigned char *) NEW2(25,unsigned char);
  359.         memcpy(cont, "cosi' mi distraggo un po'",25);
  360.         (cont_list[1]).content = cont;
  361.         (cont_list[1]).len = 25;
  362.         (cont_list[1]).contstg = allocd;
  363.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd2_CharacterString]).contlist = cont_list;
  364.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd2_CharacterString]).len = 2;
  365.  
  366.         rc = GDSallocateContListArray(2, &cont_list);
  367.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  368.           printf("no enough storage for contents list pointers array\n");
  369.           return(-1);
  370.         } /* endif */
  371.  
  372.         cont = (unsigned char *) NEW2(4,unsigned char);
  373.         GDSstr2hex(cont, 4, "00112233", 8);
  374.         (cont_list[0]).content = cont;
  375.         (cont_list[0]).len = 4;
  376.         (cont_list[0]).contstg = allocd;
  377.         cont = (unsigned char *) NEW2(4,unsigned char);
  378.         GDSstr2hex(cont, 4, "44556677", 8);
  379.         (cont_list[1]).content = cont;
  380.         (cont_list[1]).len = 4;
  381.         (cont_list[1]).contstg = allocd;
  382.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd5_OCTET_STRING]).contlist = cont_list;
  383.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd5_OCTET_STRING]).len = 2;
  384.  
  385.         rc = GDSallocateContListArray(2, &cont_list);
  386.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  387.           printf("no enough storage for contents list pointers array\n");
  388.           return(-1);
  389.         } /* endif */
  390.  
  391.         cont = (unsigned char *) NEW2(27,unsigned char);
  392.         memcpy(cont, "e siccome sei molto lontano",27);
  393.         (cont_list[0]).content = cont;
  394.         (cont_list[0]).len = 27;
  395.         (cont_list[0]).contstg = allocd;
  396.         cont = (unsigned char *) NEW2(22,unsigned char);
  397.         memcpy(cont, "piu' forte ti scrivero",22);
  398.         (cont_list[1]).content = cont;
  399.         (cont_list[1]).len = 22;
  400.         (cont_list[1]).contstg = allocd;
  401.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd6_CharacterString]).contlist = cont_list;
  402.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd6_CharacterString]).len = 2;
  403.  
  404.  
  405.         rc = GDSallocateContListArray(2, &cont_list);
  406.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  407.           printf("no enough storage for contents list pointers array\n");
  408.           return(-1);
  409.         } /* endif */
  410.  
  411.         cont = (unsigned char *) NEW2(2,unsigned char);
  412.         GDSstr2hex(cont, 2, "0011", 4);
  413.         (cont_list[0]).content = cont;
  414.         (cont_list[0]).len = 2;
  415.         (cont_list[0]).contstg = allocd;
  416.         cont = (unsigned char *) NEW2(2,unsigned char);
  417.         GDSstr2hex(cont, 2, "4455", 4);
  418.         (cont_list[1]).content = cont;
  419.         (cont_list[1]).len = 2;
  420.         (cont_list[1]).contstg = allocd;
  421.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd7_OCTET_STRING]).contlist = cont_list;
  422.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd7_OCTET_STRING]).len = 2;
  423.  
  424.         rc = GDSallocateContListArray(2, &cont_list);
  425.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  426.           printf("no enough storage for contents list pointers array\n");
  427.           return(-1);
  428.         } /* endif */
  429.  
  430.         cont = (unsigned char *) NEW2(1,unsigned char);
  431.         memcpy(cont, "d",1);
  432.         (cont_list[0]).content = cont;
  433.         (cont_list[0]).len = 1;
  434.         (cont_list[0]).contstg = allocd;
  435.         cont = (unsigned char *) NEW2(1,unsigned char);
  436.         memcpy(cont, "a",1);
  437.         (cont_list[1]).content = cont;
  438.         (cont_list[1]).len = 1;
  439.         (cont_list[1]).contstg = allocd;
  440.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd8_CharacterString]).contlist = cont_list;
  441.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd8_CharacterString]).len = 2;
  442.  
  443.         rc = GDSallocateContListArray(2, &cont_list);
  444.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  445.           printf("no enough storage for contents list pointers array\n");
  446.           return(-1);
  447.         } /* endif */
  448.  
  449.         cont = (unsigned char *) NEW2(4,unsigned char);
  450.         memcpy(cont, "ciao",4);
  451.         (cont_list[0]).content = cont;
  452.         (cont_list[0]).len = 4;
  453.         (cont_list[0]).contstg = allocd;
  454.         cont = (unsigned char *) NEW2(4,unsigned char);
  455.         memcpy(cont, "ciao",4);
  456.         (cont_list[1]).content = cont;
  457.         (cont_list[1]).len = 4;
  458.         (cont_list[1]).contstg = allocd;
  459.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd9_CharacterString]).contlist = cont_list;
  460.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd9_CharacterString]).len = 2;
  461.  
  462.         rc = GDSallocateContListArray(2, &cont_list);
  463.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  464.           printf("no enough storage for contents list pointers array\n");
  465.           return(-1);
  466.         } /* endif */
  467.  
  468.         cont = (unsigned char *) NEW2(6,unsigned char);
  469.         GDSstr2hex(cont, 6, "001122334455", 12);
  470.         (cont_list[0]).content = cont;
  471.         (cont_list[0]).len = 6;
  472.         (cont_list[0]).contstg = allocd;
  473.         cont = (unsigned char *) NEW2(6,unsigned char);
  474.         GDSstr2hex(cont, 6, "001122334455", 12);
  475.         (cont_list[1]).content = cont;
  476.         (cont_list[1]).len = 6;
  477.         (cont_list[1]).contstg = allocd;
  478.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd10_OCTET_STRING]).contlist = cont_list;
  479.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd10_OCTET_STRING]).len = 2;
  480.  
  481.         rc = GDSallocateContListArray(2, &cont_list);
  482.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  483.           printf("no enough storage for contents list pointers array\n");
  484.           return(-1);
  485.         } /* endif */
  486.  
  487.         cont = (unsigned char *) NEW(long);
  488.         GDSlongtoINTEGER(55L, cont, &lencont);
  489.         (cont_list[0]).content = cont;
  490.         (cont_list[0]).len = lencont;
  491.         (cont_list[0]).contstg = allocd;
  492.         cont = (unsigned char *) NEW(long);
  493.         GDSlongtoINTEGER(100L, cont, &lencont);
  494.         (cont_list[1]).content = cont;
  495.         (cont_list[1]).len = lencont;
  496.         (cont_list[1]).contstg = allocd;
  497.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd11_INTEGER]).contlist = cont_list;
  498.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd11_INTEGER]).len = 2;
  499.  
  500.  
  501.         rc = GDSallocateContListArray(2, &cont_list);
  502.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  503.           printf("no enough storage for contents list pointers array\n");
  504.           return(-1);
  505.         } /* endif */
  506.  
  507.         cont = (unsigned char *) NEW(long);
  508.         GDSlongtoINTEGER(355L, cont, &lencont);
  509.         (cont_list[0]).content = cont;
  510.         (cont_list[0]).len = lencont;
  511.         (cont_list[0]).contstg = allocd;
  512.         cont = (unsigned char *) NEW(long);
  513.         GDSlongtoINTEGER(310L, cont, &lencont);
  514.         (cont_list[1]).content = cont;
  515.         (cont_list[1]).len = lencont;
  516.         (cont_list[1]).contstg = allocd;
  517.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd12_INTEGER]).contlist = cont_list;
  518.         (ContArrayPtr[DDM1_Req3_SEQUENCE_cmd12_INTEGER]).len = 2;
  519.  
  520.         rc = GDSallocateContListArray(2, &cont_list);
  521.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  522.           printf("no enough storage for contents list pointers array\n");
  523.           return(-1);
  524.         } /* endif */
  525.  
  526.         cont = dummy;                        /* dummy pointer */
  527.         (cont_list[0]).content = cont;       /* encode the first */
  528.         (cont_list[1]).content = cont;       /* encode the second */
  529.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd1_NULL]).contlist = cont_list;
  530.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd1_NULL]).len = 2;
  531.  
  532.         rc = GDSallocateContListArray(2, &cont_list);
  533.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  534.           printf("no enough storage for contents list pointers array\n");
  535.           return(-1);
  536.         } /* endif */
  537.  
  538.         cont = (unsigned char *) NEW2(1,unsigned char);
  539.         *cont = 1;
  540.         (cont_list[0]).content = cont;
  541.         (cont_list[0]).len = 1;
  542.         (cont_list[0]).contstg = allocd;
  543.         cont = (unsigned char *) NEW2(1,unsigned char);
  544.         *cont = 0;
  545.         (cont_list[1]).content = cont;
  546.         (cont_list[1]).len = 1;
  547.         (cont_list[1]).contstg = allocd;
  548.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd2_BOOLEAN]).contlist = cont_list;
  549.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd2_BOOLEAN]).len = 2;
  550.  
  551.         rc = GDSallocateContListArray(2, &cont_list);
  552.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  553.           printf("no enough storage for contents list pointers array\n");
  554.           return(-1);
  555.         } /* endif */
  556.  
  557.         cont = dummy;                        /* dummy pointer */
  558.         (cont_list[0]).content = cont;       /* encode the first */
  559.         (cont_list[1]).content = NULL;       /* skip the second */
  560.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd4_NULL]).contlist = cont_list;
  561.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd4_NULL]).len = 2;
  562.  
  563.         rc = GDSallocateContListArray(2, &cont_list);
  564.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  565.           printf("no enough storage for contents list pointers array\n");
  566.           return(-1);
  567.         } /* endif */
  568.  
  569.         cont = (unsigned char *) NEW2(1,unsigned char);
  570.         *cont = 1;
  571.         (cont_list[0]).content = cont;
  572.         (cont_list[0]).len = 1;
  573.         (cont_list[0]).contstg = allocd;
  574.         cont = (unsigned char *) NEW2(1,unsigned char);
  575.         *cont = 0;
  576.         (cont_list[1]).content = cont;
  577.         (cont_list[1]).len = 1;
  578.         (cont_list[1]).contstg = allocd;
  579.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd7_BOOLEAN]).contlist = cont_list;
  580.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd7_BOOLEAN]).len = 2;
  581.  
  582.         rc = GDSallocateContListArray(2, &cont_list);
  583.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  584.           printf("no enough storage for contents list pointers array\n");
  585.           return(-1);
  586.         } /* endif */
  587.  
  588.         cont = dummy;                        /* dummy pointer */
  589.         (cont_list[0]).content = cont;       /* encode the first */
  590.         (cont_list[1]).content = cont;       /* encode the second */
  591.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd8_NULL]).contlist = cont_list;
  592.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd8_NULL]).len = 2;
  593.  
  594.         rc = GDSallocateContListArray(2, &cont_list);
  595.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  596.           printf("no enough storage for contents list pointers array\n");
  597.           return(-1);
  598.         } /* endif */
  599.  
  600.         cont = (unsigned char *) NEW2(1,unsigned char);
  601.         *cont = 1;
  602.         (cont_list[0]).content = cont;
  603.         (cont_list[0]).len = 1;
  604.         (cont_list[0]).contstg = allocd;
  605.         cont = (unsigned char *) NEW2(1,unsigned char);
  606.         *cont = 0;
  607.         (cont_list[1]).content = cont;
  608.         (cont_list[1]).len = 1;
  609.         (cont_list[1]).contstg = allocd;
  610.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd9_BOOLEAN]).contlist = cont_list;
  611.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd9_BOOLEAN]).len = 2;
  612.  
  613.         rc = GDSallocateContListArray(2, &cont_list);
  614.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  615.           printf("no enough storage for contents list pointers array\n");
  616.           return(-1);
  617.         } /* endif */
  618.  
  619.         cont = dummy;                        /* dummy pointer */
  620.         (cont_list[0]).content = NULL;       /* skip the first */
  621.         (cont_list[1]).content = cont;       /* encode the second */
  622.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd10_NULL]).contlist = cont_list;
  623.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd10_NULL]).len = 2;
  624.  
  625.         rc = GDSallocateContListArray(2, &cont_list);
  626.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  627.           printf("no enough storage for contents list pointers array\n");
  628.           return(-1);
  629.         } /* endif */
  630.  
  631.         cont = (unsigned char *) NEW2(1,unsigned char);
  632.         *cont = 1;
  633.         (cont_list[0]).content = cont;
  634.         (cont_list[0]).len = 1;
  635.         (cont_list[0]).contstg = allocd;
  636.         cont = (unsigned char *) NEW2(1,unsigned char);
  637.         *cont = 0;
  638.         (cont_list[1]).content = cont;
  639.         (cont_list[1]).len = 1;
  640.         (cont_list[1]).contstg = allocd;
  641.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd11_BOOLEAN]).contlist = cont_list;
  642.         (ContArrayPtr[DDM1_Req5_SEQUENCE_cmd11_BOOLEAN]).len = 2;
  643.  
  644.         (ContArrayPtr[DDM1_Req6_SET_cmd1_SEQUENCE]).content = dummy;
  645.  
  646.         rc = GDSallocateContListArray(2, &cont_list);
  647.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  648.           printf("no enough storage for contents list pointers array\n");
  649.           return(-1);
  650.         } /* endif */
  651.  
  652.         cont = (unsigned char *) NEW2(2,unsigned char);
  653.         GDSstr2hex(cont, 2, "6677", 4);
  654.         (cont_list[0]).content = cont;
  655.         (cont_list[0]).len = 2;
  656.         (cont_list[0]).contstg = allocd;
  657.         cont = (unsigned char *) NEW2(2,unsigned char);
  658.         GDSstr2hex(cont, 2, "8899", 4);
  659.         (cont_list[1]).content = cont;
  660.         (cont_list[1]).len = 2;
  661.         (cont_list[1]).contstg = allocd;
  662.         (ContArrayPtr[DDM1_Req6_SET_cmd1_SEQUENCE_cmd1_OCTET_STRING]).contlist = cont_list;
  663.         (ContArrayPtr[DDM1_Req6_SET_cmd1_SEQUENCE_cmd1_OCTET_STRING]).len = 2;
  664.  
  665.         rc = GDSallocateContListArray(2, &cont_list);
  666.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  667.           printf("no enough storage for contents list pointers array\n");
  668.           return(-1);
  669.         } /* endif */
  670.  
  671.         cont = (unsigned char *) NEW2(9,unsigned char);
  672.         memcpy(cont, "quando se",9);
  673.         (cont_list[0]).content = cont;
  674.         (cont_list[0]).len = 9;
  675.         (cont_list[0]).contstg = allocd;
  676.         cont = (unsigned char *) NEW2(8,unsigned char);
  677.         memcpy(cont, "partito ",8);
  678.         (cont_list[1]).content = cont;
  679.         (cont_list[1]).len = 8;
  680.         (cont_list[1]).contstg = allocd;
  681.         (ContArrayPtr[DDM1_Req6_SET_cmd1_SEQUENCE_cmd2_CharacterString]).contlist = cont_list;
  682.         (ContArrayPtr[DDM1_Req6_SET_cmd1_SEQUENCE_cmd2_CharacterString]).len = 2;
  683.  
  684.         rc = GDSallocateContListArray(2, &cont_list);
  685.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  686.           printf("no enough storage for contents list pointers array\n");
  687.           return(-1);
  688.         } /* endif */
  689.  
  690.         cont = (unsigned char *) NEW2(8,unsigned char);
  691.         memcpy(cont, "c'e' una",8);
  692.         (cont_list[0]).content = cont;
  693.         (cont_list[0]).len = 8;
  694.         (cont_list[0]).contstg = allocd;
  695.         cont = (unsigned char *) NEW2(9,unsigned char);
  696.         memcpy(cont, "grossa no",9);
  697.         (cont_list[1]).content = cont;
  698.         (cont_list[1]).len = 9;
  699.         (cont_list[1]).contstg = allocd;
  700.         (ContArrayPtr[DDM1_Req8_CHOICE_cmd1_CharacterString]).contlist = cont_list;
  701.         (ContArrayPtr[DDM1_Req8_CHOICE_cmd1_CharacterString]).len = 2;
  702.  
  703.         (ContArrayPtr[DDM1_Req7_SEQUENCE]).content = dummy;
  704.  
  705.         rc = GDSallocateContListArray(2, &cont_list);
  706.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  707.           printf("no enough storage for contents list pointers array\n");
  708.           return(-1);
  709.         } /* endif */
  710.  
  711.         (cont_list[0]).usrcontent = mycontent;
  712.         (cont_list[0]).len = 88;
  713.         (cont_list[0]).contstg = stat;
  714.         cont = (unsigned char *) NEW2(24,unsigned char);
  715.         memcpy(cont, "compreso quando e' festa",24);
  716.         (cont_list[1]).content = cont;
  717.         (cont_list[1]).len = 24;
  718.         (cont_list[1]).contstg = allocd;
  719.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd1_CharacterString]).contlist = cont_list;
  720.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd1_CharacterString]).len = 2;
  721.  
  722.         rc = GDSallocateContListArray(2, &cont_list);
  723.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  724.           printf("no enough storage for contents list pointers array\n");
  725.           return(-1);
  726.         } /* endif */
  727.  
  728.         cont = (unsigned char *) NEW2(2,unsigned char);
  729.         GDSstr2hex(cont, 2, "AABB", 4);
  730.         (cont_list[0]).content = cont;
  731.         (cont_list[0]).len = 2;
  732.         (cont_list[0]).contstg = allocd;
  733.         cont = (unsigned char *) NEW2(2,unsigned char);
  734.         GDSstr2hex(cont, 2, "CCDD", 4);
  735.         (cont_list[1]).content = cont;
  736.         (cont_list[1]).len = 2;
  737.         (cont_list[1]).contstg = allocd;
  738.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd3_SEQUENCE_cmd1_OCTET_STRING]).contlist = cont_list;
  739.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd3_SEQUENCE_cmd1_OCTET_STRING]).len = 2;
  740.  
  741.         rc = GDSallocateContListArray(2, &cont_list);
  742.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  743.           printf("no enough storage for contents list pointers array\n");
  744.           return(-1);
  745.         } /* endif */
  746.  
  747.         cont = (unsigned char *) NEW2(20,unsigned char);
  748.         memcpy(cont, "si esce poco la sera",20);
  749.         (cont_list[0]).content = cont;
  750.         (cont_list[0]).len = 20;
  751.         (cont_list[0]).contstg = allocd;
  752.         cont = (unsigned char *) NEW2(24,unsigned char);
  753.         memcpy(cont, "compreso quando e' festa",24);
  754.         (cont_list[1]).content = cont;
  755.         (cont_list[1]).len = 24;
  756.         (cont_list[1]).contstg = allocd;
  757.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd3_SEQUENCE_cmd2_CharacterString]).contlist = cont_list;
  758.         (ContArrayPtr[DDM1_Req7_SEQUENCE_cmd3_SEQUENCE_cmd2_CharacterString]).len = 2;
  759.  
  760.         rc = GDSallocateContListArray(2, &cont_list);
  761.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  762.           printf("no enough storage for contents list pointers array\n");
  763.           return(-1);
  764.         } /* endif */
  765.  
  766.         cont = (unsigned char *) NEW2(3,unsigned char);
  767.         memcpy(cont, "ole",3);
  768.         (cont_list[0]).content = cont;
  769.         (cont_list[0]).len = 3;
  770.         (cont_list[0]).contstg = allocd;
  771.         cont = (unsigned char *) NEW2(3,unsigned char);
  772.         memcpy(cont, "ole",3);
  773.         (cont_list[1]).content = cont;
  774.         (cont_list[1]).len = 3;
  775.         (cont_list[1]).contstg = allocd;
  776.         (ContArrayPtr[DDM0_Req10_SEQUENCE_cmd1_CharacterString]).contlist = cont_list;
  777.         (ContArrayPtr[DDM0_Req10_SEQUENCE_cmd1_CharacterString]).len = 2;
  778.  
  779.         rc = GDSallocateContListArray(2, &cont_list);
  780.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  781.           printf("no enough storage for contents list pointers array\n");
  782.           return(-1);
  783.         } /* endif */
  784.  
  785.         cont = (unsigned char *) NEW2(2,unsigned char);
  786.         GDSstr2hex(cont, 2, "0011", 4);
  787.         (cont_list[0]).content = cont;
  788.         (cont_list[0]).len = 2;
  789.         (cont_list[0]).contstg = allocd;
  790.         cont = (unsigned char *) NEW2(2,unsigned char);
  791.         GDSstr2hex(cont, 2, "2233", 4);
  792.         (cont_list[1]).content = cont;
  793.         (cont_list[1]).len = 2;
  794.         (cont_list[1]).contstg = allocd;
  795.         (ContArrayPtr[DDM0_Req10_SEQUENCE_cmd2_OCTET_STRING]).contlist = cont_list;
  796.         (ContArrayPtr[DDM0_Req10_SEQUENCE_cmd2_OCTET_STRING]).len = 2;
  797.  
  798.         rc = GDSallocateContListArray(2, &cont_list);
  799.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  800.           printf("no enough storage for contents list pointers array\n");
  801.           return(-1);
  802.         } /* endif */
  803.  
  804.         cont = (unsigned char *) NEW2(3,unsigned char);
  805.         memcpy(cont, "ole",3);
  806.         (cont_list[0]).content = cont;
  807.         (cont_list[0]).len = 3;
  808.         (cont_list[0]).contstg = allocd;
  809.         cont = (unsigned char *) NEW2(3,unsigned char);
  810.         memcpy(cont, "ole",3);
  811.         (cont_list[1]).content = cont;
  812.         (cont_list[1]).len = 3;
  813.         (cont_list[1]).contstg = allocd;
  814.         (ContArrayPtr[DDM1_Req11_SEQUENCE_cmd1_CharacterString]).contlist = cont_list;
  815.         (ContArrayPtr[DDM1_Req11_SEQUENCE_cmd1_CharacterString]).len = 2;
  816.  
  817.         rc = GDSallocateContListArray(2, &cont_list);
  818.         if (rc == ALLOCATECONTLIST_NO_ENOUGH_STORAGE) {
  819.           printf("no enough storage for contents list pointers array\n");
  820.           return(-1);
  821.         } /* endif */
  822.  
  823.         cont = (unsigned char *) NEW2(2,unsigned char);
  824.         GDSstr2hex(cont, 2, "0011", 4);
  825.         (cont_list[0]).content = cont;
  826.         (cont_list[0]).len = 2;
  827.         (cont_list[0]).contstg = allocd;
  828.         cont = (unsigned char *) NEW2(2,unsigned char);
  829.         GDSstr2hex(cont, 2, "2233", 4);
  830.         (cont_list[1]).content = cont;
  831.         (cont_list[1]).len = 2;
  832.         (cont_list[1]).contstg = allocd;
  833.         (ContArrayPtr[DDM1_Req11_SEQUENCE_cmd2_OCTET_STRING]).contlist = cont_list;
  834.         (ContArrayPtr[DDM1_Req11_SEQUENCE_cmd2_OCTET_STRING]).len = 2;
  835.  
  836.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd2_CharacterString]).usrcontent = mycontent2;
  837.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd2_CharacterString]).len = UNDEFLENGTH;
  838.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd2_CharacterString]).contstg = stat;
  839.  
  840.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd3_CharacterString]).usrcontent = mycontent3;
  841.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd3_CharacterString]).len = UNDEFLENGTH;
  842.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd3_CharacterString]).contstg = stat;
  843.  
  844.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd4_CharacterString]).usrcontent = mycontent4;
  845.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd4_CharacterString]).len = UNDEFLENGTH;
  846.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd4_CharacterString]).contstg = stat;
  847.  
  848.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd5_CharacterString]).usrcontent = mycontent5;
  849.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd5_CharacterString]).len = UNDEFLENGTH;
  850.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd5_CharacterString]).contstg = stat;
  851.  
  852.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd6_OCTET_STRING]).usrcontent = mycontent6;
  853.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd6_OCTET_STRING]).len = UNDEFLENGTH;
  854.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd6_OCTET_STRING]).contstg = stat;
  855.  
  856.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd7_OCTET_STRING]).usrcontent = mycontent7;
  857.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd7_OCTET_STRING]).len = UNDEFLENGTH;
  858.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd7_OCTET_STRING]).contstg = stat;
  859.  
  860.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd8_OCTET_STRING]).usrcontent = mycontent8;
  861.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd8_OCTET_STRING]).len = UNDEFLENGTH;
  862.         (ContArrayPtr[DDM1_Req_SEQUENCE_cmd8_OCTET_STRING]).contstg = stat;
  863.  
  864.  
  865. /*
  866.  * Call the library routine, GDSencode, to create one or more GDS structures
  867.  * that represent a value for Mod and Typ. The user encode exit is called
  868.  * during this process to provide the necessary values for the
  869.  * ASN.1 type. The last parm is the addr of a structure with data
  870.  * to be passed to the user encode exit. Applications
  871.  * use this to pass local parameters to the user encode routine.  This is
  872.  * useful when the the user appl (this routine) and the exit routine
  873.  * must share data. The alternative is to make the
  874.  * shared data global -- usually an undesirable programming practice.
  875.  *
  876.  * Note that the GDSencode function does *not* create the GDSD encoded
  877.  * data. The GDS structures contain the information needed to
  878.  * encode the data, but the actual encoding is a secondary step.
  879.  */
  880.  
  881.         rc = GDSencode(Mod,      /* moddef module where type occurs */
  882.                        &Typ,     /* metatable index where type occurs */
  883.                        ContArrayPtr, /* pointer to Contents Array */
  884.                        &p1,      /* returned GDS structure */
  885.                        enctype,  /* type of encoding */
  886.                        env,      /* environment */
  887.                        NULL      /* parms to pass to the user encode routine
  888.                                   * not used in this case */
  889.                       );
  890.  
  891.  
  892.         if (rc != ENCODE_MATCH) { /* if the encoding failed */
  893.           printf("\nGDSencode return code: %i\n", rc);
  894.           printf("\nmetatable type index where error occurred: %i\n", Typ);
  895.         }    /* endif */
  896.  
  897.         l = p1->loc;           /* get the length of enctype-encoded data */
  898.         printf("\nlength of encoded data: %ld\n", l);
  899.  
  900. /*
  901.  * Call the library routine, GDSprintgds, to print the structure and
  902.  * content of the encoded GDS.
  903.  */
  904.         rc = GDSprintgds(p1,           /* ptr to root GDS structure */
  905.                          0,            /* number of spaces to indent */
  906.                          300,          /* max content length */
  907.                          79,           /* number of characters for row */
  908.                          trace_enc,    /* gds tree trace file */
  909.                          enctype       /* type of encoding */
  910.                         );
  911.  
  912.         if (rc != PRINT_GDS_OK) { /* if the printing failed */
  913.           printf("\nGDSprintgds return code: %i\n", rc);
  914.           GDSfreegds(p1, env);   /* reclaim space for encoded GDS struct */
  915.           continue;              /* terminate the query loop */
  916.         }    /* endif */
  917.  
  918.         fclose(trace_enc);
  919.  
  920. /*
  921.  * open the output file that will contain the encoded data stream
  922.  */
  923.         EncStream = fopen("stream0.out","wb");
  924.         if (EncStream == NULL) { /* open file failed */
  925.           printf("open output file failed\n");
  926.           exit(-1);
  927.         } /* endif */
  928. /*
  929.  * Call the library routine, GDSencgdsd, to encode the GDS using GDSD rules.
  930.  */
  931.         rc = GDSencgdsd(&p1,          /* the GDS structure to be encoded */
  932.                         outbuflen,    /* the length of the output buffer */
  933.                         &EncBytes,    /* the number of encoded bytes */
  934.                         use,          /* use LLIDFISS segmentation */
  935.                         env,          /* environment */
  936.                         (void *) EncStream /* output file pointer */
  937.                         );
  938.  
  939.         if (rc != ENCGDSD_OK) {       /* if encoding was unsuccessful */
  940.           printf("\nGDSencgdsd return code: %i\n", rc);
  941.         }  /* endif */
  942.  
  943.         printf("\nnumber of encoded bytes: %lu\n", EncBytes);
  944.  
  945.  
  946. /*
  947.  * Call the library routine, GDSfreegds, to reclaim the storage occupied by
  948.  * the GDS structures headed by p1 which are marked as allocated.  Note
  949.  * that some GDSs may be marked as static, which prevents them from
  950.  * being freed.
  951.  */
  952.  
  953.         GDSfreegds(p1, env);
  954.  
  955.         printf("GDSfreegds OK\n");
  956.  
  957. /*
  958.  * Call the library routine, GDSfreeContentsArray, to reclaim the storage
  959.  * allocated for the contents-array.
  960.  */
  961.         GDSfreeContentsArray(Mod, ContArrayPtr);
  962.  
  963.       } /* endif */
  964.  
  965. /********************************
  966.  * DECODING
  967.  ********************************
  968.  */
  969.  
  970.       fclose(EncStream);
  971.  
  972. /*
  973.  * open the inputput file that will contain the encoded data stream
  974.  */
  975.       EncStream = fopen("stream0.out","rb");
  976.       if (EncStream == NULL) { /* open file failed */
  977.         printf("open output file failed\n");
  978.         exit(-1);
  979.       } /* endif */
  980.  
  981. /*
  982.  * ask to the user the name of the decoding module
  983.  */
  984.  
  985.       printf("\n[%s.]Module for decoding (or stop): ", savmodname);
  986.       fflush(NULL);
  987.  
  988.    /*
  989.     * ask user for module name
  990.     */
  991.       strcpy(modname, savmodname);
  992.       readmodtype(readbuf, sizeof(readbuf), &readmod);
  993.       if (readmod != NULL) {    /* if user typed in a module name */
  994.         if (!strcmp(readmod, "stop")) {
  995.            break;
  996.         } /* endif */
  997.         strcpy(modname, readmod); /* use the module name the user typed in */
  998.       } /* endif */
  999.  
  1000. /*
  1001.  * Call the library routine, GDSfindmodule, to find the moddef structure
  1002.  * corresponding to the name in the modname string.
  1003.  */
  1004.       Mod = GDSfindmodule(modname, env);
  1005.       if (Mod == NULL) {        /* if module not found */
  1006.         printf("\nModule not found\n");
  1007.         continue;              /* allow more attempts */
  1008.       }                         /* endif */
  1009.  
  1010. /*
  1011.  * Call the library routine, GDSfindtype, to find the metatable index in
  1012.  * the Mod module corresponding to the type name in readtype.  Note that
  1013.  * the .H files created by the ASN.1 compiler contain symbol names for
  1014.  * the type and value metatable indices.  When the type or value name
  1015.  * is known at application compile-time, these symbolic names can be
  1016.  * used directly instead of searching through the metatables at
  1017.  * runtime.  Since this application does not know the type
  1018.  * definitions beforehand, we have to use findtype to locate them.
  1019.  */
  1020.       rc = GDSfindtype(Mod,     /* module where type is to be found */
  1021.                        "Req",   /* type name string */
  1022.                        &Typ     /* returned metatable index */
  1023.                       );
  1024.       if (rc != FIND_TYPE_OK) {            /* if type not found */
  1025.          printf("\nType not found; rc = %i\n", rc);
  1026.          continue;           /* allow more attempts */
  1027.       }                      /* endif */
  1028.  
  1029.  
  1030. /*
  1031.  * Call the library routine, GDSdecgdsd, to decode encoded data in the
  1032.  * buffer we just built. The result should be a tree of GDS structures
  1033.  * topped by p1 which matches the original structure created by the
  1034.  * encode library routine.
  1035.  */
  1036.       rc = GDSdecgdsd(&p1,       /* GDS structure which will be the root
  1037.                                   * of the GDS tree */
  1038.                       inbuflen,  /* the length of the input buffer */
  1039.                       &DecBytes, /* number of decoded bytes */
  1040.                       Mod,       /* moddef module where type occurs */
  1041.                       &Typ,      /* metatable index where type occurs */
  1042.                       NULL,      /* pointer to array of pointers to GDS tree */
  1043.                       &errinfo,  /* error information */
  1044.                       env,       /* environment */
  1045.                       (void *) usrdecfile, /* dec user-exit file pointer */
  1046.                       (void *) EncStream   /* input file pointer */
  1047.                      );
  1048.  
  1049.       if (rc != DECGDSD_MATCH) {    /* if decoding didn't go ok */
  1050.         printf("\nGDSdecgdsd return code: %i\n", rc);
  1051.         printf("metatable type index where error occurred: %i\n", Typ);
  1052.         switch (rc) {
  1053.         case DECGDSD_INVALID_ID:
  1054.         case DECGDSD_INVALID_UNIQUE_ITEM:
  1055.         case DECGDSD_INVALID_SEG_IDF_PREFIX:
  1056.         case DECGDSD_INVALID_SEG_ID_PREFIX:
  1057.         {
  1058.           char errval[8];
  1059.  
  1060.           GDShex2str(errval, sizeof(errval),(char *) errinfo.err_item,
  1061.                      errinfo.err_item_len);
  1062.           printf("item in error: %s\n", errval);
  1063.           break;
  1064.         }
  1065.         case DECGDSD_INVALID_LENGTH:
  1066.         case DECGDSD_INVALID_SEG_SEQ_NUM:
  1067.           printf("item in error: %lu\n", *((long *) (errinfo.err_item)));
  1068.          break;
  1069.         default:
  1070.          break;
  1071.         } /* endswitch */
  1072.       }   /* endif */
  1073.  
  1074.       printf("\nnumber of decoded bytes: %u\n", DecBytes);
  1075.  
  1076. /*
  1077.  * Call the library routine, GDSprintgds, to print the structure and
  1078.  * content of the decoded GDS.
  1079.  */
  1080.       rc = GDSprintgds(p1,           /* ptr to root GDS structure */
  1081.                        0,            /* number of spaces to indent */
  1082.                        300,          /* max content length */
  1083.                        79,           /* number of characters for row */
  1084.                        trace_dec,    /* gds tree trace file */
  1085.                        enctype       /* type of encoding */
  1086.                       );
  1087.  
  1088.       if (rc != PRINT_GDS_OK) { /* if the printing failed */
  1089.         printf("\nGDSprintgds return code: %i\n", rc);
  1090.         GDSfreegds(p1, env);
  1091.         continue;              /* terminate the query loop */
  1092.       }    /* endif */
  1093.  
  1094.       fclose(trace_dec);
  1095.  
  1096.       fclose(EncStream);
  1097.  
  1098. /*
  1099.  * Call the library routine to free the GDS structures in the tree rooted
  1100.  * by *p1.
  1101.  */
  1102.       GDSfreegds(p1, env);
  1103.  
  1104.       freopen("","rb",EncStream); /* flush the output file buffer
  1105.                                    * and reopen the file for reading */
  1106.       if (EncStream == NULL) {    /* open file failed */
  1107.         printf("\nopen file failed\n");
  1108.         exit(-1);
  1109.       } /* endif */
  1110.    }        /* endfor */
  1111.  
  1112.    printf("\nout of loop\n");
  1113. /*******************************************
  1114.  * TERMINATION
  1115.  *******************************************
  1116.  */
  1117.  
  1118. /*
  1119.  * Clean up the environment by unloading all modules by calling
  1120.  * GDSunloadmodule for each module in the environment.  NOTE:
  1121.  * the GDSunloadmodule function should only be called for modules which
  1122.  * were loaded by the GDSreaddatfile function or which have allocated
  1123.  * storage in the heap like the GDSreaddatfile function.
  1124.  */
  1125.  
  1126.    for (GDSfirstmodule(&Mod, &ModName, env); Mod != NULL;
  1127.         GDSfirstmodule(&Mod, &ModName, env)) {
  1128.       GDSunloadmodule(Mod, env);
  1129.    } /* endfor */
  1130.  
  1131.    printf("\nGDSunloadmodule loop OK\n");
  1132.  
  1133.  /*
  1134.   * call the library routine GDSfreeEnvironment to free the
  1135.   * environment storage
  1136.   */
  1137.    GDSfreeEnvironment(env);
  1138.  
  1139.    return 0;
  1140. }  /* end main */
  1141.  
  1142. static
  1143. char *readline(char *buf)
  1144. {
  1145.    char *r;
  1146.  
  1147.    *buf = '\0';                 /* init */
  1148.    r = gets(buf);
  1149.    if (r == NULL) {
  1150.       return(0);
  1151.    } /* endif */
  1152.    return r;
  1153. }
  1154.  
  1155. static
  1156. void readmodtype(char *readbuf, int buflen, char **readmod)
  1157. {
  1158.  
  1159.    /*  Read from standard input to get a modulename.
  1160.     *  Skip over white space before name strings and
  1161.     *  consider newline the end of the string.
  1162.     */
  1163.  
  1164.    char *cp, *cp2;
  1165.    int len;
  1166.    char foo[200];
  1167.  
  1168.    readline(foo);
  1169.    cp2 = strtok(foo, " ");
  1170.  
  1171.    if (cp2 == NULL) {
  1172.      *readmod = NULL;
  1173.      return;
  1174.    } /* endif */
  1175.    /* Now read characters up to a newline or the end of the buffer */
  1176.    for (cp = readbuf, len = 0; len < buflen-1; cp++, cp2++, len++) {
  1177.       *cp = *cp2;
  1178.       if (*cp == '\0') {
  1179.          break;
  1180.       } /* endif */
  1181.    } /* endfor */
  1182.    *cp = '\0';               /* terminate the string with a null */
  1183.    *readmod = readbuf;       /* the module name starts at 1st char in str */
  1184. }
  1185.  
  1186. /*
  1187.  * writing user-exit
  1188.  */
  1189. unsigned long mywrite(char *buf, unsigned long buflen, void *usrparms)
  1190. {
  1191.   FILE *EncStream;
  1192.  
  1193.   EncStream = (FILE *) usrparms;
  1194.   return (unsigned long) (fwrite(buf,sizeof(unsigned char),buflen,EncStream));
  1195. }
  1196.  
  1197. /*
  1198.  * reading user-exit
  1199.  */
  1200. unsigned long myread(char *buf, unsigned long buflen, void *usrparms)
  1201. {
  1202.   FILE *EncStream;
  1203.  
  1204.   EncStream = (FILE *) usrparms;
  1205.   return (unsigned long) (fread(buf,sizeof(unsigned char),buflen,EncStream));
  1206. }
  1207.  
  1208. /*
  1209.  * content user-exit
  1210.  */
  1211. int mycontent (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1212. {
  1213.   char *data1 = "vita', l'anno vecchio e' finito ormai ma qualcosa";
  1214.   char *data2 = " ancora qui non va,";
  1215.   char *data3 = " si esce poco la ser";
  1216.   static int pass = 0;
  1217.   int rc = 0;
  1218.  
  1219.   switch (pass) {
  1220.   case 0:
  1221.     *buff = data1;
  1222.     *buflen = strlen(data1);
  1223.     *lastf = NO;
  1224.     break;
  1225.   case 1:
  1226.     *buff = data2;
  1227.     *buflen = strlen(data2);
  1228.     *lastf = NO;
  1229.     break;
  1230.   case 2:
  1231.     *buff = data3;
  1232.     *buflen = strlen(data3);
  1233.     *lastf = YES;
  1234.     break;
  1235.   } /* endswitch */
  1236.   pass++;
  1237.   return rc;
  1238. }
  1239.  
  1240. /*
  1241.  * content user-exit
  1242.  */
  1243. int mycontent2 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1244. {
  1245.   char *data1 = "BEGIN-cmd2:2222222222222222222";
  1246.   char *data2 = "222222222222222222222222222222";
  1247.   char *data3 = "2222222222222222222222END-cmd2";
  1248.   static int pass = 0;
  1249.   int rc = 0;
  1250.  
  1251.   switch (pass) {
  1252.   case 0:
  1253.     *buff = data1;
  1254.     *buflen = strlen(data1);
  1255.     *lastf = NO;
  1256.     break;
  1257.   case 1:
  1258.     *buff = data2;
  1259.     *buflen = strlen(data2);
  1260.     *lastf = NO;
  1261.     break;
  1262.   case 2:
  1263.     *buff = data3;
  1264.     *buflen = strlen(data3);
  1265.     *lastf = YES;
  1266.     break;
  1267.   } /* endswitch */
  1268.   pass++;
  1269.   return rc;
  1270. }
  1271.  
  1272. /*
  1273.  * content user-exit
  1274.  */
  1275. int mycontent3 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1276. {
  1277.   char *data1 = "BEGIN-cmd3:3333333333333333333";
  1278.   char *data2 = "333333333333333333333333333333";
  1279.   char *data3 = "3333333333333333333333END-cmd3";
  1280.   static int pass = 0;
  1281.   int rc = 0;
  1282.  
  1283.   switch (pass) {
  1284.   case 0:
  1285.     *buff = data1;
  1286.     *buflen = strlen(data1);
  1287.     *lastf = NO;
  1288.     break;
  1289.   case 1:
  1290.     *buff = data2;
  1291.     *buflen = strlen(data2);
  1292.     *lastf = NO;
  1293.     break;
  1294.   case 2:
  1295.     *buff = data3;
  1296.     *buflen = strlen(data3);
  1297.     *lastf = YES;
  1298.     break;
  1299.   } /* endswitch */
  1300.   pass++;
  1301.   return rc;
  1302. }
  1303.  
  1304. /*
  1305.  * content user-exit
  1306.  */
  1307. int mycontent4 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1308. {
  1309.   char *data1 = "BEGIN-cmd4:4444444444444444444";
  1310.   char *data2 = "444444444444444444444444444444";
  1311.   char *data3 = "4444444444444444444444END-cmd4";
  1312.   static int pass = 0;
  1313.   int rc = 0;
  1314.  
  1315.   switch (pass) {
  1316.   case 0:
  1317.     *buff = data1;
  1318.     *buflen = strlen(data1);
  1319.     *lastf = NO;
  1320.     break;
  1321.   case 1:
  1322.     *buff = data2;
  1323.     *buflen = strlen(data2);
  1324.     *lastf = NO;
  1325.     break;
  1326.   case 2:
  1327.     *buff = data3;
  1328.     *buflen = strlen(data3);
  1329.     *lastf = YES;
  1330.     break;
  1331.   } /* endswitch */
  1332.   pass++;
  1333.   return rc;
  1334. }
  1335.  
  1336. /*
  1337.  * content user-exit
  1338.  */
  1339. int mycontent5 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1340. {
  1341.   char *data1 = "BEGIN-cmd5:5555555555555555555";
  1342.   char *data2 = "555555555555555555555555555555";
  1343.   char *data3 = "5555555555555555555555END-cmd5";
  1344.   static int pass = 0;
  1345.   int rc = 0;
  1346.  
  1347.   switch (pass) {
  1348.   case 0:
  1349.     *buff = data1;
  1350.     *buflen = strlen(data1);
  1351.     *lastf = NO;
  1352.     break;
  1353.   case 1:
  1354.     *buff = data2;
  1355.     *buflen = strlen(data2);
  1356.     *lastf = NO;
  1357.     break;
  1358.   case 2:
  1359.     *buff = data3;
  1360.     *buflen = strlen(data3);
  1361.     *lastf = YES;
  1362.     break;
  1363.   } /* endswitch */
  1364.   pass++;
  1365.   return rc;
  1366. }
  1367.  
  1368. /*
  1369.  * content user-exit
  1370.  */
  1371. int mycontent6 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1372. {
  1373.   char *data;
  1374.   static int pass = 0;
  1375.   int rc = 0;
  1376.  
  1377.   switch (pass) {
  1378.   case 0:
  1379.     data = (unsigned char *) NEW2(15,unsigned char);
  1380.     GDSstr2hex(data, 15, "666666666666666666666666666666", 30);
  1381.     *buff = data;
  1382.     *buflen = 15;
  1383.     *lastf = NO;
  1384.     break;
  1385.   case 1:
  1386.     data = (unsigned char *) NEW2(15,unsigned char);
  1387.     GDSstr2hex(data, 15, "777777777777777777777777777777", 30);
  1388.     *buff = data;
  1389.     *buflen = 15;
  1390.     *lastf = NO;
  1391.     break;
  1392.   case 2:
  1393.     data = (unsigned char *) NEW2(15,unsigned char);
  1394.     GDSstr2hex(data, 15, "888888888888888888888888888888", 30);
  1395.     *buff = data;
  1396.     *buflen = 15;
  1397.     *lastf = YES;
  1398.     break;
  1399.   } /* endswitch */
  1400.   pass++;
  1401.   return rc;
  1402. }
  1403.  
  1404. /*
  1405.  * content user-exit
  1406.  */
  1407. int mycontent7 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1408. {
  1409.   char *data;
  1410.   static int pass = 0;
  1411.   int rc = 0;
  1412.  
  1413.   switch (pass) {
  1414.   case 0:
  1415.     data = (unsigned char *) NEW2(15,unsigned char);
  1416.     GDSstr2hex(data, 15, "777777777777777777777777777777", 30);
  1417.     *buff = data;
  1418.     *buflen = 15;
  1419.     *lastf = NO;
  1420.     break;
  1421.   case 1:
  1422.     data = (unsigned char *) NEW2(15,unsigned char);
  1423.     GDSstr2hex(data, 15, "888888888888888888888888888888", 30);
  1424.     *buff = data;
  1425.     *buflen = 15;
  1426.     *lastf = NO;
  1427.     break;
  1428.   case 2:
  1429.     data = (unsigned char *) NEW2(15,unsigned char);
  1430.     GDSstr2hex(data, 15, "999999999999999999999999999999", 30);
  1431.     *buff = data;
  1432.     *buflen = 15;
  1433.     *lastf = YES;
  1434.     break;
  1435.   } /* endswitch */
  1436.   pass++;
  1437.   return rc;
  1438. }
  1439.  
  1440. /*
  1441.  * content user-exit
  1442.  */
  1443. int mycontent8 (char **buff, unsigned long *buflen, enum lastflag *lastf)
  1444. {
  1445.   char *data;
  1446.   static int pass = 0;
  1447.   int rc = 0;
  1448.  
  1449.   switch (pass) {
  1450.   case 0:
  1451.     data = (unsigned char *) NEW2(15,unsigned char);
  1452.     GDSstr2hex(data, 15, "888888888888888888888888888888", 30);
  1453.     *buff = data;
  1454.     *buflen = 15;
  1455.     *lastf = NO;
  1456.     break;
  1457.   case 1:
  1458.     data = (unsigned char *) NEW2(15,unsigned char);
  1459.     GDSstr2hex(data, 15, "999999999999999999999999999999", 30);
  1460.     *buff = data;
  1461.     *buflen = 15;
  1462.     *lastf = NO;
  1463.     break;
  1464.   case 2:
  1465.     data = (unsigned char *) NEW2(15,unsigned char);
  1466.     GDSstr2hex(data, 15, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 30);
  1467.     *buff = data;
  1468.     *buflen = 15;
  1469.     *lastf = YES;
  1470.     break;
  1471.   } /* endswitch */
  1472.   pass++;
  1473.   return rc;
  1474. }
  1475.  
  1476.  
  1477. /*
  1478.  * decoding user-exit
  1479.  */
  1480. int mydec(unsigned short ndx, struct gds *p, char *content,
  1481.           unsigned long contlen, void *usrparms)
  1482. {
  1483.   long   foolong;
  1484.   char   foo[300];
  1485.   FILE  *usrdecfile;
  1486.  
  1487.   usrdecfile = (FILE *) usrparms;
  1488.   if (content != NULL) {
  1489.     switch (ndx) {
  1490.     case DDM0_Req1_SET_cmd1_ENUMERATED:
  1491.       fprintf(usrdecfile,"DDM0_Req1_SET_cmd1_ENUMERATED\n");
  1492.       GDSINTEGERtolong(content, contlen, &foolong);
  1493.       GDShex2str(foo, 300, content, contlen);
  1494.       fprintf(usrdecfile,"%ld (\'%s\'H)\n", foolong, foo);
  1495.       break;
  1496.     case DDM0_Req1_SET_cmd2_INTEGER:
  1497.       fprintf(usrdecfile,"DDM0_Req1_SET_cmd2_INTEGER\n");
  1498.       GDSINTEGERtolong(content, contlen, &foolong);
  1499.       GDShex2str(foo, 300, content, contlen);
  1500.       fprintf(usrdecfile,"%ld (\'%s\'H)\n", foolong, foo);
  1501.       break;
  1502.     case DDM0_Req3_SEQUENCE_cmd1_OCTET_STRING:
  1503.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd1_OCTET_STRING\n");
  1504.       GDShex2str(foo, 300, content, contlen);
  1505.       fprintf(usrdecfile,"'%s'H\n", foo);
  1506.       break;
  1507.     case DDM0_Req3_SEQUENCE_cmd2_CharacterString:
  1508.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd2_CharacterString\n");
  1509.       strncpy(foo, content, contlen);
  1510.       foo[contlen] = '\0';
  1511.       fprintf(usrdecfile,"\"%s\" ", foo);
  1512.       GDShex2str(foo, 300, content, contlen);
  1513.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1514.       break;
  1515.     case DDM0_Req3_SEQUENCE_cmd3_OCTET_STRING:
  1516.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd3_OCTET_STRING\n");
  1517.       break;
  1518.     case DDM0_Req3_SEQUENCE_cmd4_CharacterString:
  1519.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd4_CharacterString\n");
  1520.       strncpy(foo, content, contlen);
  1521.       foo[contlen] = '\0';
  1522.       fprintf(usrdecfile,"\"%s\" ", foo);
  1523.       GDShex2str(foo, 300, content, contlen);
  1524.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1525.       break;
  1526.     case DDM0_Req3_SEQUENCE_cmd5_OCTET_STRING:
  1527.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd5_OCTET_STRING\n");
  1528.       GDShex2str(foo, 300, content, contlen);
  1529.       fprintf(usrdecfile,"'%s'H\n", foo);
  1530.       break;
  1531.     case DDM0_Req3_SEQUENCE_cmd6_CharacterString:
  1532.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd6_CharacterString\n");
  1533.       strncpy(foo, content, contlen);
  1534.       foo[contlen] = '\0';
  1535.       fprintf(usrdecfile,"\"%s\" ", foo);
  1536.       GDShex2str(foo, 300, content, contlen);
  1537.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1538.       break;
  1539.     case DDM0_Req3_SEQUENCE_cmd7_OCTET_STRING:
  1540.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd7_OCTET_STRING\n");
  1541.       GDShex2str(foo, 300, content, contlen);
  1542.       fprintf(usrdecfile,"'%s'H\n", foo);
  1543.       break;
  1544.     case DDM0_Req3_SEQUENCE_cmd8_CharacterString:
  1545.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd8_CharacterString\n");
  1546.       strncpy(foo, content, contlen);
  1547.       foo[contlen] = '\0';
  1548.       fprintf(usrdecfile,"\"%s\" ", foo);
  1549.       GDShex2str(foo, 300, content, contlen);
  1550.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1551.       break;
  1552.     case DDM0_Req3_SEQUENCE_cmd9_CharacterString:
  1553.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd9_CharacterString\n");
  1554.       strncpy(foo, content, contlen);
  1555.       foo[contlen] = '\0';
  1556.       fprintf(usrdecfile,"\"%s\" ", foo);
  1557.       GDShex2str(foo, 300, content, contlen);
  1558.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1559.       break;
  1560.     case DDM0_Req3_SEQUENCE_cmd10_OCTET_STRING:
  1561.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd10_OCTET_STRING\n");
  1562.       GDShex2str(foo, 300, content, contlen);
  1563.       fprintf(usrdecfile,"'%s'H\n", foo);
  1564.       break;
  1565.     case DDM0_Req3_SEQUENCE_cmd11_INTEGER:
  1566.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd11_INTEGER\n");
  1567.       GDSINTEGERtolong(content, contlen, &foolong);
  1568.       GDShex2str(foo, 300, content, contlen);
  1569.       fprintf(usrdecfile,"%ld (\'%s\'H)\n", foolong, foo);
  1570.       break;
  1571.     case DDM0_Req3_SEQUENCE_cmd12_INTEGER:
  1572.       fprintf(usrdecfile,"DDM0_Req3_SEQUENCE_cmd12_INTEGER\n");
  1573.       GDSINTEGERtolong(content, contlen, &foolong);
  1574.       GDShex2str(foo, 300, content, contlen);
  1575.       fprintf(usrdecfile,"%ld (\'%s\'H)\n", foolong, foo);
  1576.       break;
  1577.     case DDM0_Req5_SEQUENCE_cmd1_NULL:
  1578.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd1_NULL\n");
  1579.       break;
  1580.     case DDM0_Req5_SEQUENCE_cmd2_BOOLEAN:
  1581.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd2_BOOLEAN\n");
  1582.       GDShex2str(foo, 300, content, contlen);
  1583.       if (*content) {
  1584.          fprintf(usrdecfile,"TRUE ('%s'H)\n", foo);
  1585.       } else {
  1586.          fprintf(usrdecfile,"FALSE ('%s'H)\n", foo);
  1587.       }                   /* endif */
  1588.       break;
  1589.     case DDM0_Req5_SEQUENCE_cmd3_BOOLEAN:
  1590.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd3_BOOLEAN\n");
  1591.       break;
  1592.     case DDM0_Req5_SEQUENCE_cmd4_NULL:
  1593.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd4_NULL\n");
  1594.       break;
  1595.     case DDM0_Req5_SEQUENCE_cmd7_BOOLEAN:
  1596.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd7_BOOLEAN\n");
  1597.       GDShex2str(foo, 300, content, contlen);
  1598.       if (*content) {
  1599.          fprintf(usrdecfile,"TRUE ('%s'H)\n", foo);
  1600.       } else {
  1601.          fprintf(usrdecfile,"FALSE ('%s'H)\n", foo);
  1602.       }                   /* endif */
  1603.       break;
  1604.     case DDM0_Req5_SEQUENCE_cmd8_NULL:
  1605.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd8_NULL\n");
  1606.       break;
  1607.     case DDM0_Req5_SEQUENCE_cmd9_BOOLEAN:
  1608.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd9_BOOLEAN\n");
  1609.       GDShex2str(foo, 300, content, contlen);
  1610.       if (*content) {
  1611.          fprintf(usrdecfile,"TRUE ('%s'H)\n", foo);
  1612.       } else {
  1613.          fprintf(usrdecfile,"FALSE ('%s'H)\n", foo);
  1614.       }                   /* endif */
  1615.       break;
  1616.     case DDM0_Req5_SEQUENCE_cmd10_NULL:
  1617.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd10_NULL\n");
  1618.       break;
  1619.     case DDM0_Req5_SEQUENCE_cmd11_BOOLEAN:
  1620.       fprintf(usrdecfile,"DDM0_Req5_SEQUENCE_cmd11_BOOLEAN\n");
  1621.       GDShex2str(foo, 300, content, contlen);
  1622.       if (*content) {
  1623.          fprintf(usrdecfile,"TRUE ('%s'H)\n", foo);
  1624.       } else {
  1625.          fprintf(usrdecfile,"FALSE ('%s'H)\n", foo);
  1626.       }                   /* endif */
  1627.       break;
  1628.     case DDM0_Req6_SET_cmd1_SEQUENCE_cmd1_OCTET_STRING:
  1629.       fprintf(usrdecfile,"DDM0_Req6_SET_cmd1_SEQUENCE_cmd1_OCTET_STRING\n");
  1630.       GDShex2str(foo, 300, content, contlen);
  1631.       fprintf(usrdecfile,"'%s'H\n", foo);
  1632.       break;
  1633.     case DDM0_Req6_SET_cmd1_SEQUENCE_cmd2_CharacterString:
  1634.       fprintf(usrdecfile,"DDM0_Req6_SET_cmd1_SEQUENCE_cmd2_CharacterString\n");
  1635.       strncpy(foo, content, contlen);
  1636.       foo[contlen] = '\0';
  1637.       fprintf(usrdecfile,"\"%s\" ", foo);
  1638.       GDShex2str(foo, 300, content, contlen);
  1639.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1640.       break;
  1641.     case DDM0_Req7_SEQUENCE_cmd1_CharacterString:
  1642.       fprintf(usrdecfile,"DDM0_Req7_SEQUENCE_cmd1_CharacterString\n");
  1643.       strncpy(foo, content, contlen);
  1644.       foo[contlen] = '\0';
  1645.       fprintf(usrdecfile,"\"%s\" ", foo);
  1646.       GDShex2str(foo, 300, content, contlen);
  1647.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1648.       break;
  1649.     case DDM0_Req7_SEQUENCE_cmd2_OCTET_STRING:
  1650.       fprintf(usrdecfile,"DDM0_Req7_SEQUENCE_cmd2_OCTET_STRING\n");
  1651.       break;
  1652.     case DDM0_Req7_SEQUENCE_cmd3_SEQUENCE_cmd1_OCTET_STRING:
  1653.       fprintf(usrdecfile,"DDM0_Req7_SEQUENCE_cmd3_SEQUENCE_cmd1_OCTET_STRING\n");
  1654.       GDShex2str(foo, 300, content, contlen);
  1655.       fprintf(usrdecfile,"'%s'H\n", foo);
  1656.       break;
  1657.     case DDM0_Req7_SEQUENCE_cmd3_SEQUENCE_cmd2_CharacterString:
  1658.       fprintf(usrdecfile,"DDM0_Req7_SEQUENCE_cmd3_SEQUENCE_cmd2_CharacterString\n");
  1659.       strncpy(foo, content, contlen);
  1660.       foo[contlen] = '\0';
  1661.       fprintf(usrdecfile,"\"%s\" ", foo);
  1662.       GDShex2str(foo, 300, content, contlen);
  1663.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1664.       break;
  1665.     case DDM0_Req8_CHOICE_cmd1_CharacterString:
  1666.       fprintf(usrdecfile,"DDM0_Req8_CHOICE_cmd1_CharacterString\n");
  1667.       strncpy(foo, content, contlen);
  1668.       foo[contlen] = '\0';
  1669.       fprintf(usrdecfile,"\"%s\" ", foo);
  1670.       GDShex2str(foo, 300, content, contlen);
  1671.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1672.       break;
  1673.     case DDM0_Req8_CHOICE_cmd2_NULL:
  1674.       fprintf(usrdecfile,"DDM0_Req8_CHOICE_cmd2_NULL\n");
  1675.       break;
  1676.     case DDM1_Req9_SEQUENCE_cmd1_CharacterString:
  1677.       fprintf(usrdecfile,"DDM1_Req9_SEQUENCE_cmd1_CharacterString\n");
  1678.       strncpy(foo, content, contlen);
  1679.       foo[contlen] = '\0';
  1680.       fprintf(usrdecfile,"\"%s\" ", foo);
  1681.       GDShex2str(foo, 300, content, contlen);
  1682.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1683.       break;
  1684.     case DDM1_Req9_SEQUENCE_cmd2_OCTET_STRING:
  1685.       fprintf(usrdecfile,"DDM1_Req9_SEQUENCE_cmd2_OCTET_STRING\n");
  1686.       GDShex2str(foo, 300, content, contlen);
  1687.       fprintf(usrdecfile,"'%s'H\n", foo);
  1688.       break;
  1689.     case DDM0_Req11_SEQUENCE_cmd1_CharacterString:
  1690.       fprintf(usrdecfile,"DDM0_Req11_SEQUENCE_cmd1_CharacterString\n");
  1691.       strncpy(foo, content, contlen);
  1692.       foo[contlen] = '\0';
  1693.       fprintf(usrdecfile,"\"%s\" ", foo);
  1694.       GDShex2str(foo, 300, content, contlen);
  1695.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1696.       break;
  1697.     case DDM0_Req11_SEQUENCE_cmd2_OCTET_STRING:
  1698.       fprintf(usrdecfile,"DDM0_Req11_SEQUENCE_cmd2_OCTET_STRING\n");
  1699.       GDShex2str(foo, 300, content, contlen);
  1700.       fprintf(usrdecfile,"'%s'H\n", foo);
  1701.       break;
  1702.     case DDM0_Req_SEQUENCE_cmd2_CharacterString: {
  1703.       static char pass = 0;
  1704.  
  1705.       if (!pass)
  1706.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd2_CharacterString\n");
  1707.       strncpy(foo, content, contlen);
  1708.       foo[contlen] = '\0';
  1709.       fprintf(usrdecfile,"\"%s\" ", foo);
  1710.       GDShex2str(foo, 300, content, contlen);
  1711.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1712.       pass++;
  1713.       break;
  1714.       }
  1715.     case DDM0_Req_SEQUENCE_cmd3_CharacterString: {
  1716.       static char pass = 0;
  1717.  
  1718.       if (!pass)
  1719.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd3_CharacterString\n");
  1720.       strncpy(foo, content, contlen);
  1721.       foo[contlen] = '\0';
  1722.       fprintf(usrdecfile,"\"%s\" ", foo);
  1723.       GDShex2str(foo, 300, content, contlen);
  1724.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1725.       pass++;
  1726.       break;
  1727.       }
  1728.     case DDM0_Req_SEQUENCE_cmd4_CharacterString: {
  1729.       static char pass = 0;
  1730.  
  1731.       if (!pass)
  1732.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd4_CharacterString\n");
  1733.       strncpy(foo, content, contlen);
  1734.       foo[contlen] = '\0';
  1735.       fprintf(usrdecfile,"\"%s\" ", foo);
  1736.       GDShex2str(foo, 300, content, contlen);
  1737.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1738.       pass++;
  1739.       break;
  1740.       }
  1741.     case DDM0_Req_SEQUENCE_cmd5_CharacterString: {
  1742.       static char pass = 0;
  1743.  
  1744.       if (!pass)
  1745.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd5_CharacterString\n");
  1746.       strncpy(foo, content, contlen);
  1747.       foo[contlen] = '\0';
  1748.       fprintf(usrdecfile,"\"%s\" ", foo);
  1749.       GDShex2str(foo, 300, content, contlen);
  1750.       fprintf(usrdecfile,"(\'%s\'H)\n", foo);
  1751.       pass++;
  1752.       break;
  1753.       }
  1754.     case DDM0_Req_SEQUENCE_cmd6_OCTET_STRING: {
  1755.       static char pass = 0;
  1756.  
  1757.       if (!pass)
  1758.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd6_OCTET_STRING\n");
  1759.       GDShex2str(foo, 300, content, contlen);
  1760.       fprintf(usrdecfile,"'%s'H\n", foo);
  1761.       pass++;
  1762.       break;
  1763.       }
  1764.     case DDM0_Req_SEQUENCE_cmd7_OCTET_STRING: {
  1765.       static char pass = 0;
  1766.  
  1767.       if (!pass)
  1768.         fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd7_OCTET_STRING\n");
  1769.       GDShex2str(foo, 300, content, contlen);
  1770.       fprintf(usrdecfile,"'%s'H\n", foo);
  1771.       pass++;
  1772.       break;
  1773.       }
  1774.     case DDM0_Req_SEQUENCE_cmd8_OCTET_STRING: {
  1775.       static char pass = 0;
  1776.  
  1777.       if (!pass)
  1778.       fprintf(usrdecfile,"DDM0_Req_SEQUENCE_cmd8_OCTET_STRING\n");
  1779.       GDShex2str(foo, 300, content, contlen);
  1780.       fprintf(usrdecfile,"'%s'H\n", foo);
  1781.       pass++;
  1782.       break;
  1783.       }
  1784.     default:
  1785.      break;
  1786.     } /* endswitch */
  1787.   } /* endif */
  1788.   return 0;
  1789. }
  1790.  
  1791. static char *
  1792. mallocate(unsigned n)
  1793. {
  1794.    register char  *block = NULL;
  1795.  
  1796.    block = calloc(n, 1);
  1797.    return (block);
  1798. }
  1799.