home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / iwftech.zip / samples / SOMopt / somtgt.c < prev    next >
Text File  |  1994-07-21  |  11KB  |  329 lines

  1. /*+--------------------------------------------------------------------------+*/
  2. /*| SOMOPT - WorkFrame/2-enabled SOM actions support (Options DLL)           |*/
  3. /*|--------------------------------------------------------------------------|*/
  4. /*|                                                                          |*/
  5. /*| PROGRAM NAME: SOMOPT                                                     |*/
  6. /*| -------------                                                            |*/
  7. /*|                                                                          |*/
  8. /*| COPYRIGHT:                                                               |*/
  9. /*| ----------                                                               |*/
  10. /*| Copyright (C) International Business Machines Corp., 1991,1992,1993,1994 |*/
  11. /*|                                                                          |*/
  12. /*| DISCLAIMER OF WARRANTIES:                                                |*/
  13. /*| -------------------------                                                |*/
  14. /*| The following [enclosed] code is sample code created by IBM              |*/
  15. /*| Corporation.  This sample code is not part of any standard IBM product   |*/
  16. /*| and is provided to you solely for the purpose of assisting you in the    |*/
  17. /*| development of your applications.  The code is provided "AS IS",         |*/
  18. /*| without warranty of any kind.  IBM shall not be liable for any damages   |*/
  19. /*| arising out of your use of the sample code, even if they have been       |*/
  20. /*| advised of the possibility of such damages.                              |*/
  21. /*|                                                                          |*/
  22. /*| REVISION LEVEL: 2.1                                                      |*/
  23. /*| -------------------                                                      |*/
  24. /*|                                                                          |*/
  25. /*| This program demonstrates providing WorkFrame/2 actions support (i.e.    |*/
  26. /*| Options DLL) for the SOM compiler.                                       |*/
  27. /*+--------------------------------------------------------------------------+*/
  28.  
  29. #pragma title("IBM WorkFrame/2 Ver 2.1")
  30. #pragma strings(readonly)
  31.  
  32.  
  33. #define INCL_PM
  34. #define INCL_WIN
  35. #define INCL_DOS
  36. #define INCL_DOSERRORS
  37. #include <os2.h>
  38.  
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42.  
  43. #define  INCL_WKFOPT
  44. #include <wkf.h>
  45.  
  46. #include "somopt.h"
  47.  
  48.  
  49.  
  50. APIRET APIENTRY WKFQUERYCOMPILETARGET(
  51.                              VOID           **ppvToolBuffer,
  52.                              HWND             hwndWorkFrame,
  53.                              HMODULE          hModHandle,
  54.                              PSZ              pszProject,  
  55.                              PSZ              pszTitle,
  56.                              PWKF_ACTION      pwkfAction,   
  57.                              ULONG            ulOptionsLength,
  58.                              VOID            *pvOptions,
  59.                              ULONG            ulCmdLineLength,
  60.                              PSZ              pszCmdLine,
  61.                              ULONG            ulSearchPath,
  62.                              PSZ              pszSearchPath,
  63.                              LIST_OF_SOURCE  *pstSourceObjects,
  64.                              LIST_OF_TARGET  *pstTargetObjects,
  65.                              LIST_OF_DEPEND  *pstDependObjects,
  66.                              WKF_REALLOC     *pWkf_Realloc,
  67.                              WKF_PRT_STATUS  *pWkf_PrtStatus,
  68.                              BOOL             bFileScope ) 
  69. {
  70.    ULONG        ulTargetBufferNeeded = 0;
  71.    ULONG        ulCmdLengthNeeded;
  72.    SOM_OPTIONS *pOptions;
  73.    ULONG        ulEmitFiles = 0;
  74.    CHAR         szEmitFiles[ 100 ];   /* Enough to emit all types */
  75.  
  76.  
  77.    szEmitFiles[0] = '\0';
  78.  
  79.    pOptions = (SOM_OPTIONS*)pvOptions;
  80.  
  81.  
  82.    /*
  83.    ** OK, the structures are all setup, now: do we need to initialize to the default?
  84.    */
  85.    if ( ulOptionsLength < sizeof(SOM_OPTIONS) ||
  86.         strncmp( pOptions->szSignature,
  87.                  SOM_OPTIONS_SIGNATURE,
  88.                  sizeof(SOM_OPTIONS_SIGNATURE) ) )
  89.    {
  90.       /*
  91.       ** Do we need to increase the size of the options block?
  92.       */
  93.       if ( ulOptionsLength < sizeof(SOM_OPTIONS) )
  94.       {
  95.          pOptions = (*pWkf_Realloc)( pOptions, 
  96.                                      sizeof(SOM_OPTIONS) );
  97.    
  98.          if (!pOptions)
  99.             return( ERROR_NOT_ENOUGH_MEMORY );
  100.       }
  101.  
  102.       /*
  103.       ** Use the default options
  104.       */
  105.       SetDefaultOptions( pOptions );
  106.    }
  107.  
  108.  
  109.  
  110.    /*
  111.    ** Mark the first file passed as used.
  112.    */
  113.    pstSourceObjects->ulNumUsed = 1;
  114.    pstSourceObjects->stObject[0].fUsed = WKF_QT_FILE_USED;
  115.  
  116.  
  117.    /*
  118.    ** Now, make sure the buffers are big enough
  119.    */
  120.    ulCmdLengthNeeded = sizeof( DEFAULT_CMD_LINE );
  121.  
  122.    /*
  123.    ** Was an output directory specified?
  124.    */
  125.    if( pOptions->szOutputDir[0] )
  126.       ulCmdLengthNeeded += strlen( pOptions->szOutputDir ) + 
  127.                            sizeof( SZ_OUTPUTDIR );
  128.  
  129.    if( pOptions->bVerifyRelease )
  130.       ulCmdLengthNeeded += sizeof( SZ_VERIFYRELEASE );
  131.  
  132.    if( !pOptions->bDisplayWarnings )   /* Default is on */
  133.       ulCmdLengthNeeded += sizeof( SZ_DISPLAYWARNINGS );
  134.  
  135.    if( pOptions->cCommentStyle != COMMENT_S ) /* default == s */
  136.       ulCmdLengthNeeded += sizeof( SZ_COMMENTSTYLE )+1; 
  137.  
  138.       
  139.    if( pOptions->bEmitFileDEF )
  140.       { strcat( szEmitFiles, SZ_EMITFILEDEF ); ulEmitFiles++; } 
  141.  
  142.    if( pOptions->bEmitFileSC )
  143.       { strcat( szEmitFiles, SZ_EMITFILESC ); ulEmitFiles++; } 
  144.  
  145.    if( pOptions->bEmitFilePSC )
  146.       { strcat( szEmitFiles, SZ_EMITFILEPSC ); ulEmitFiles++; } 
  147.  
  148.    if( pOptions->bEmitFileCS2 )
  149.       { strcat( szEmitFiles, SZ_EMITFILECS2 ); ulEmitFiles++; } 
  150.  
  151.    if( pOptions->bEmitFileC )
  152.       { strcat( szEmitFiles, SZ_EMITFILEC ); ulEmitFiles++; } 
  153.  
  154.    if( pOptions->bEmitFileH )
  155.       { strcat( szEmitFiles, SZ_EMITFILEH ); ulEmitFiles++; } 
  156.  
  157.    if( pOptions->bEmitFileIH )
  158.       { strcat( szEmitFiles, SZ_EMITFILEIH ); ulEmitFiles++; } 
  159.  
  160.    if( pOptions->bEmitFilePH )
  161.       { strcat( szEmitFiles, SZ_EMITFILEPH ); ulEmitFiles++; } 
  162.  
  163.    if( pOptions->bEmitFileCPP )
  164.       { strcat( szEmitFiles, SZ_EMITFILECPP ); ulEmitFiles++; } 
  165.  
  166.    if( pOptions->bEmitFileXH )
  167.       { strcat( szEmitFiles, SZ_EMITFILEXH ); ulEmitFiles++; } 
  168.  
  169.    if( pOptions->bEmitFileXIH )
  170.       { strcat( szEmitFiles, SZ_EMITFILEXIH ); ulEmitFiles++; } 
  171.  
  172.    if( pOptions->bEmitFileXPH )
  173.       { strcat( szEmitFiles, SZ_EMITFILEXPH ); ulEmitFiles++; } 
  174.  
  175.    if( ulEmitFiles )
  176.       ulCmdLengthNeeded += strlen( szEmitFiles ) + 
  177.                            sizeof( SZ_EMITFILE ) + 2;  /* +2 == quotes */
  178.  
  179.    if( ulCmdLineLength < (ulCmdLengthNeeded + 1) )   /* +1 == space for null */
  180.    {
  181.       pszCmdLine = (*pWkf_Realloc)( pszCmdLine, ulCmdLengthNeeded + 1 );    /* +1 == space for null */
  182.  
  183.       if( !pszCmdLine )
  184.          return( ERROR_NOT_ENOUGH_MEMORY );
  185.    }
  186.  
  187.  
  188.    if ( pstTargetObjects )
  189.    {
  190.       /*
  191.       ** The format we'll use in the output buffer is %n.XXX
  192.       */
  193.       ulTargetBufferNeeded = sizeof( "%n." ) * ulEmitFiles +   
  194.                              strlen( szEmitFiles ) + 1;       /* +1 == null */
  195.    
  196.       if( pstTargetObjects->ulBufferSize < ulTargetBufferNeeded )
  197.       {
  198.          pstTargetObjects = (*pWkf_Realloc)( pstTargetObjects, ulTargetBufferNeeded );
  199.    
  200.          if( !pstTargetObjects )
  201.             return( ERROR_NOT_ENOUGH_MEMORY );
  202.    
  203.          pstTargetObjects->ulBufferSize = ulTargetBufferNeeded;
  204.       }
  205.    }
  206.    
  207.  
  208.    if( !ulSearchPath )                                      
  209.    {                                                             
  210.       pszSearchPath = (*pWkf_Realloc)( pszSearchPath, 1 );     
  211.                                                                  
  212.       if( !pszSearchPath )                                
  213.          return( ERROR_NOT_ENOUGH_MEMORY );                      
  214.    }                                                             
  215.  
  216.  
  217.  
  218.    /*
  219.    ** Now start filling things in
  220.    */
  221.  
  222.  
  223.    /*
  224.    ** Set the search path to NULL -- we are not parsing for dependencies.
  225.    */
  226.    pszSearchPath[0] = '\0';
  227.  
  228.    /*
  229.    ** Set the dependencies (if we were passed a buffer) -- none.
  230.    */
  231.    if (pstDependObjects)
  232.       pstDependObjects->ulNumOfEntries = 0;
  233.  
  234.  
  235.    /*
  236.    ** Set the command line
  237.    */
  238.    pszCmdLine[0] = '\0';
  239.  
  240.    if( pOptions->szOutputDir[0] )
  241.       strcat( pszCmdLine, SZ_OUTPUTDIR );
  242.  
  243.    if( pOptions->bVerifyRelease )
  244.       strcat( pszCmdLine, SZ_VERIFYRELEASE );
  245.  
  246.    if( !pOptions->bDisplayWarnings )   /* Default is on */
  247.       strcat( pszCmdLine, SZ_DISPLAYWARNINGS );
  248.  
  249.    if( pOptions->cCommentStyle == COMMENT_C ) 
  250.       strcat( pszCmdLine, SZ_COMMENTSTYLE SZ_COMMENT_C );
  251.    else 
  252.    if( pOptions->cCommentStyle == COMMENT_CPP ) 
  253.       strcat( pszCmdLine, SZ_COMMENTSTYLE SZ_COMMENT_CPP );
  254.  
  255.    if( ulEmitFiles )
  256.    {
  257.       strcat( pszCmdLine, SZ_EMITFILE "\"" );
  258.       strcat( pszCmdLine, &szEmitFiles[1] );      /* Skip the leading ; */
  259.       strcat( pszCmdLine, "\"" );
  260.    }
  261.  
  262.  
  263.    /*
  264.    ** Finally add the %f, signifying the source file
  265.    */
  266.    strcat( pszCmdLine, DEFAULT_CMD_LINE );
  267.  
  268.  
  269.  
  270.    /*
  271.    ** Set the targets (if we were passed a buffer),
  272.    */
  273.    if( pstTargetObjects )
  274.    {
  275.       /*
  276.       ** The target buffer should take the form
  277.       **
  278.       **      (filename_1)(filename_2)...(filename_n)\0   
  279.       **                                                  
  280.       ** where each filename_x is a null delimited string 
  281.       */
  282.       pstTargetObjects->cBuffer[0] = '\0';
  283.  
  284.       if( ulEmitFiles )
  285.       {
  286.          PSZ pszNextExt;
  287.          PSZ pszTarget;
  288.  
  289.          pszNextExt = strtok( szEmitFiles, ";" );
  290.          pszTarget = pstTargetObjects->cBuffer;
  291.  
  292.          while( pszNextExt )
  293.          {
  294.             /*
  295.             ** Most of the extensions that are generated are
  296.             ** the same as the command line option.  Rather
  297.             ** than generate a seperate table, we'll use the 
  298.             ** command line options, and adjust the one case
  299.             ** that's different  (xc -> cpp)
  300.             */
  301.             if( !strcmp( "xc", pszNextExt ) )
  302.                pszNextExt = "cpp";
  303.  
  304.             strcpy( pszTarget, "%n." );
  305.             strcat( pszTarget, pszNextExt );
  306.  
  307.             pstTargetObjects->ulNumOfEntries++;
  308.  
  309.             /*
  310.             ** Now setup for the next filename.
  311.             */
  312.             pszTarget += strlen( pszTarget ) +1;
  313.  
  314.             pszNextExt = strtok( NULL, ";" );
  315.          } /* endwhile */
  316.  
  317.          /*
  318.          ** Finally, append the extra (trailing) null
  319.          */
  320.          pszTarget[0] = '\0';
  321.       }
  322.       else
  323.          pstTargetObjects->ulNumOfEntries = 0;
  324.    }
  325.  
  326.    return( NO_ERROR );
  327. }
  328.  
  329.