home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / sdu / ehnxnmp.c < prev    next >
Text File  |  1995-06-07  |  14KB  |  258 lines

  1. /******************************************************************************/
  2. /* SAMPLE PROGRAM: EHNXNMP   - Sample Name Mapping Exit for DFM/2.            */
  3. /*                                                                            */
  4. /* MODULE NAME:    EHNXNMP.C                                                  */
  5. /* DESCRIPTION:    Main File for the Name Mapping Exit EHNXNMP.DLL            */
  6. /*                                                                            */
  7. /*                                                                            */
  8. /* DFM/2 (program no. 5648-020)                                               */
  9. /* Version: 1.0                                                               */
  10. /* Release: 1.0                                                               */
  11. /* Level:   0.0                                                               */
  12. /*                                                                            */
  13. /* Copyright (C) International Business Machines Corporation 1993             */
  14. /*                                                                            */
  15. /* DISCLAIMER OF WARRANTIES:                                                  */
  16. /* The following [enclosed] code is sample code created by IBM                */
  17. /* Corporation.  This sample code is not part of any standard IBM product     */
  18. /* and is provided to you solely for the purpose of assisting you in the      */
  19. /* development of your applications.  The code is provided "AS IS",           */
  20. /* without warranty of any kind.  IBM shall not be liable for any damages     */
  21. /* arising out of your use of the sample code, even if they have been         */
  22. /* advised of the possibility of such damages.                                */
  23. /*                                                                            */
  24. /******************************************************************************/
  25. /* CHANGE ACTIVITY                                                            */
  26. /* Flag Reason      Level    Date   Origin    Comments                        */
  27. /* -------------------------------------------------------------------------- */
  28. /*                           930402 Mueller  : Initial Release                */
  29. /* IBM Deutschland Entwicklung GmbH, Boeblingen, Germany        GMU at SDFVM1 */
  30. /******************************************************************************/
  31.  
  32. /******************************************************************************/
  33. /*        This is a programming sample showing how to write a                 */
  34. /*                                                                            */
  35. /*                   Name Mapping Exit Program                                */
  36. /*                            for                                             */
  37. /*            IBM Distributed Filemanager (DFM/2) for OS/2.                   */
  38. /*                                                                            */
  39. /*                                                                            */
  40. /* The sample program does the following:                                     */
  41. /* If the file is for a MVS target, some conversions are done. They are       */
  42. /* described below.                                                           */
  43. /* If this module is compiled with PRINTLOG defined, then                     */
  44. /* the input file name and the corresponding output file name are logged      */
  45. /* in a file NAMEMAP.LOG in directory %EHNDIR%.                               */
  46. /* No further processing is done.                                             */
  47. /*                                                                            */
  48. /* Note: If you use the sample as is or with some modifications only,         */
  49. /*       make sure to delete the file NAME.LOG from time to time              */
  50. /*       before it becomes too large.                                         */
  51. /*                                                                            */
  52. /* Files belonging to this sample program:                                    */
  53. /*     EHNXNMP.C    C-language program, this file                             */
  54. /*     EHNXNMP.H    Prototype for the Name Mapping Exit and other definitions */
  55. /*     EHNXNMP.DEF  Module Definition File                                    */
  56. /*     EHNXNMP.MAK  Make File                                                 */
  57. /*                                                                            */
  58. /* You find these files in the following subdirectories of the                */
  59. /* RLIO/DFM product directory:                                                */
  60. /*     %ehndir%\H        contains EHNXNMP.H                                   */
  61. /*     %ehndir%\SAMPLE   contains EHNXNMP.C, .DEF, and .MAK                   */
  62. /*                                                                            */
  63. /* To compile the program, you need                                           */
  64. /*    a. The IBM C Set/2 compiler version 1.0 or later                        */
  65. /*    b. The Developer's Toolkit for OS/2 2.0 or later                        */
  66. /*       including the linker LINK386                                         */
  67. /*       and the make file utility NMAKE                                      */
  68. /*                                                                            */
  69. /******************************************************************************/
  70.  
  71. /******************************************************************************/
  72. /* OS/2 Include files                                                         */
  73. /******************************************************************************/
  74. #define INCL_BASE
  75. #include <os2.h>                         /* OS/2 base set of C functions      */
  76.  
  77. /******************************************************************************/
  78. /* C Library Includes                                                         */
  79. /******************************************************************************/
  80. #include <string.h>                      /* Include used for: memcpy, ...     */
  81. #include <stdlib.h>                      /* Include used for: getenv.         */
  82. #include <stdio.h>
  83.  
  84. #pragma pack()
  85.  
  86. /******************************************************************************/
  87. /* DFM/2 Includes                                                             */
  88. /******************************************************************************/
  89. #include "ehnxnmp.h"             /* Definitions and prototypes for the
  90.                                     Name Mapping Exit functions */
  91.  
  92. #define MAX8    255
  93.  
  94. /******************************************************************************/
  95. /* Name    : DFM_Map_to_Server                                                */
  96. /*                                                                            */
  97. /* Function: Name mapping exit routine on the way from OS/2 to the target.    */
  98. /*                                                                            */
  99. /*           This sample routine does the following conversion                */
  100. /*           when a file is sent to an MVS system:                            */
  101. /*           - A pattern "\(" is replaced by "(".                             */
  102. /*           - A pattern "\" not followed by a "(" is replaced by ".".        */
  103. /*           - The file name is converted to uppercase.                                                                 */
  104. /*           Otherwise no name mapping is done.                               */
  105. /*           Then the exit routine returns to DFM/2.                          */
  106. /*                                                                            */
  107. /* Input   : A pointer to the DFM/2 Name Mapping Exit interface control       */
  108. /*           block (defined in EHNXNMP.H).                                    */
  109. /* Output  : The mapped file name can be written to the OutFileName           */
  110. /*           buffer in the interface control block.                           */
  111. /******************************************************************************/
  112. extern void _System DFM_Map_to_Server(PDFM_NAME_MAP_CB pNameMapCB)
  113. {
  114.    FILE *printer;
  115.    char *ehndir;         /* pointer to the EHNDIR environment variable */
  116.    char pfilename[MAX8+1];  /* filename for printer */
  117.    char *ptr;
  118.    LONG incount, outcount;
  119.  
  120. #ifdef PRINTLOG
  121.    ehndir = getenv("EHNDIR");                   /* get environment var. EHNDIR */
  122.    if (ehndir != NULL)
  123.            { ptr = strcpy(pfilename, ehndir); } /* and build the file name     */
  124.       else { ptr = strcpy(pfilename, "."   ); }
  125.    ptr = strcat(pfilename, "\\NAMEMAP.LOG" );   /* %EHNDIR%\NAMEMAP.LOG        */
  126.  
  127.    printer = fopen(pfilename,"a");
  128.  
  129.    fprintf (printer,"\nDFM_Map_to_Server: ");
  130.    fprintf (printer,"%s",pNameMapCB->InFileName);
  131. #endif
  132.  
  133.    if(strcmp(pNameMapCB->SrvClsName,SRVCLSNM_MVS) == 0)
  134.                                        // Target is MVS.
  135.    {
  136.       for( incount=0, outcount=0 ;
  137.            incount<MAX8 && pNameMapCB->InFileName[incount];
  138.            incount++, outcount++ )
  139.       {
  140.          if( '\\' == pNameMapCB->InFileName[incount] )
  141.          {
  142.             if( '(' == pNameMapCB->InFileName[incount+1] )
  143.             {
  144.                                        // Convert "\(" to "("
  145.                incount++;
  146.                pNameMapCB->OutFileName[outcount] = '(';
  147.             }
  148.             else
  149.                                        // Convert "\" to "."
  150.                pNameMapCB->OutFileName[outcount] = '.';
  151.          }
  152.          else
  153.                                        // In all the other cases convert
  154.                                        // to uppercase and copy.
  155.             pNameMapCB->OutFileName[outcount] =
  156.                       toupper( pNameMapCB->InFileName[incount] );
  157.       }
  158.       pNameMapCB->OutFileName[outcount] = 0;
  159.    }
  160.    else
  161.    {
  162.      strcpy( pNameMapCB->OutFileName, pNameMapCB->InFileName );
  163.    }
  164.  
  165. #ifdef PRINTLOG
  166.    fprintf (printer," -> %s",pNameMapCB->OutFileName);
  167.    fprintf (printer," (Target: %s LU: %s)",
  168.                     pNameMapCB->SrvClsName,
  169.                     pNameMapCB->LU_Name );
  170.  
  171.    fclose(printer);
  172. #endif
  173.    return;
  174. }
  175.  
  176. /******************************************************************************/
  177. /* Name    : DFM_Map_to_Client                                                */
  178. /*                                                                            */
  179. /* Function: Name mapping exit routine on the way from the target to OS/2.    */
  180. /*                                                                            */
  181. /*           This sample routine does the following conversion                */
  182. /*           when a file is receved from an MVS system:                       */
  183. /*           - A pattern "(" is replaced by "\(".                             */
  184. /*           - A pattern "." is replaced by "\".                              */
  185. /*           Otherwise no name mapping is done.                               */
  186. /*           Then the exit routine returns to DFM/2.                          */
  187. /*                                                                            */
  188. /* Input   : A pointer to the DFM/2 Name Mapping Exit interface control       */
  189. /*           block (defined in EHNXNMP.H).                                    */
  190. /* Output  : The mapped file name can be written to the OutFileName           */
  191. /*           buffer in the interface control block.                           */
  192. /******************************************************************************/
  193. extern void _System DFM_Map_to_Client(PDFM_NAME_MAP_CB pNameMapCB)
  194. {
  195.    FILE *printer;
  196.    char *ehndir;         /* pointer to the EHNDIR environment variable */
  197.    char pfilename[MAX8+1];  /* filename for printer */
  198.    char *ptr;
  199.    LONG incount, outcount;
  200.  
  201. #ifdef PRINTLOG
  202.    ehndir = getenv("EHNDIR");                   /* get environment var. EHNDIR */
  203.    if (ehndir != NULL)
  204.            { ptr = strcpy(pfilename, ehndir); } /* and build the file name     */
  205.       else { ptr = strcpy(pfilename, "."   ); }
  206.    ptr = strcat(pfilename, "\\NAMEMAP.LOG" );   /* %EHNDIR%\NAMEMAP.LOG        */
  207.  
  208.    printer = fopen(pfilename,"a");
  209.  
  210.    fprintf (printer,"\nDFM_Map_to_Client: ");
  211.    fprintf (printer,"%s",pNameMapCB->InFileName);
  212. #endif
  213.  
  214.    if(strcmp(pNameMapCB->SrvClsName,SRVCLSNM_MVS) == 0)
  215.    {
  216.       for( incount=0, outcount=0 ;
  217.            outcount<MAX8 && pNameMapCB->InFileName[incount];
  218.            incount++, outcount++ )
  219.       {
  220.          switch( pNameMapCB->InFileName[incount] )
  221.          {
  222.          case '(':
  223.                                        // Convert "(" to "\("
  224.             pNameMapCB->OutFileName[outcount] = '\\';
  225.             outcount++;
  226.             pNameMapCB->OutFileName[outcount] = '(';
  227.             break;
  228.  
  229.          case '.':
  230.                                        // Convert "." to "\"
  231.             pNameMapCB->OutFileName[outcount] = '\\';
  232.             break;
  233.  
  234.          default:
  235.                                        // In all the other cases copy char.
  236.             pNameMapCB->OutFileName[outcount] =
  237.                       pNameMapCB->InFileName[incount];
  238.             break;
  239.          }
  240.       }
  241.       pNameMapCB->OutFileName[outcount] = 0;
  242.    }
  243.    else
  244.    {
  245.      strcpy( pNameMapCB->OutFileName, pNameMapCB->InFileName );
  246.    }
  247.  
  248. #ifdef PRINTLOG
  249.    fprintf (printer," -> %s",pNameMapCB->OutFileName);
  250.    fprintf (printer," (Target: %s LU: %s)",
  251.                      pNameMapCB->SrvClsName,
  252.                      pNameMapCB->LU_Name );
  253.    fclose(printer);
  254. #endif
  255.    return;
  256. }
  257. /**** end of file *************************************************************/
  258.