home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / LOAD.ZIP / LOAD.C < prev    next >
C/C++ Source or Header  |  1989-07-19  |  8KB  |  158 lines

  1. /****************************************************************************
  2.  * LOAD                                                                     *
  3.  * ------------------------------------------------------------------------ *
  4.  * Purpose:     Loads an OS/2 program as a presentation manager icon.       *
  5.  * ------------------------------------------------------------------------ *
  6.  * Type:        External command, used in the OS/2 session only.            *
  7.  * ------------------------------------------------------------------------ *
  8.  * Syntax:      LOAD "session title" /FS|/WIN|/PM [/I] [/ICON=iconName]     *
  9.  *                   command [options]                                      *
  10.  * ------------------------------------------------------------------------ *
  11.  * Parameters:  session title                                               *
  12.  *              This variable specifies the title of the new session as it  *
  13.  *              will appear in the Task Manager. The session title may be   *
  14.  *              up to 31 characters long and must be surrounded by          *
  15.  *              quotation marks.                                            *
  16.  *                                                                          *
  17.  *              /FS                                                         *
  18.  *              This parameter tells MS OS/2 that the application is        *
  19.  *              not window compatible and must be run in a full-screen      *
  20.  *              session.                                                    *
  21.  *                                                                          *
  22.  *              /WIN                                                        *
  23.  *              This parameter tells MS OS/2 that the application is to be  *
  24.  *              run in a presentation manager window.                       *
  25.  *                                                                          *
  26.  *              /PM                                                         *
  27.  *              This parameter tells MS OS/2 that the application is a      *
  28.  *              Presentation Manager application.                           *
  29.  *                                                                          *
  30.  *              /I                                                          *
  31.  *              This parameter causes the program being loaded to inherit   *
  32.  *              the environment set in the CONFIG.SYS file.                 *
  33.  *                                                                          *
  34.  *              /ICON=iconName                                              *
  35.  *              This parameter is used to specify the path and file name    *
  36.  *              of the icon file associated with the application.           *
  37.  *              If the icon file is not in the current directory, the       *
  38.  *              full pathname of the icon file is required.                 *
  39.  *                                                                          *
  40.  *              command                                                     *
  41.  *              This variable specifies the name and extension of the       *
  42.  *              program to be loaded.                                       *
  43.  *                                                                          *
  44.  *              options                                                     *
  45.  *              This variable specifies any command line arguments that     *
  46.  *              are to be passed to the program being loaded.               *
  47.  * ------------------------------------------------------------------------ *
  48.  *  Program written by: Rick Yoder                                          *
  49.  *                      CIS 73457,521                                       *
  50.  ****************************************************************************/
  51.  
  52.     #define INCL_DOSSESMGR
  53.     #include <os2.h>
  54.     #include <stdio.h>
  55.     #include <string.h>
  56.     #include <malloc.h>
  57.     #include <qfn.h>
  58.  
  59. /****************************************************************************/
  60.     void main( int argc, char *argv[] )
  61.     {
  62.         static char *msg = "Usage: LOAD \"session title\" /FS|/WIN|/PM [/I] [/ICON=iconName]\n            command [options]\n";
  63.  
  64.         STARTDATA   stdata;
  65.         USHORT      idSession,pid;
  66.         USHORT      code;
  67.  
  68.         char        *options;
  69.         int         n,m,len;
  70.  
  71.  
  72.     /* Check for illegal number of command line arguments */
  73.         if ( argc < 4 )
  74.             {
  75.             printf( msg );
  76.             return;
  77.             }
  78.  
  79.     /* Get session title */
  80.         if ( strlen(argv[1]) > 31 )
  81.             {
  82.             printf( "ERROR: Session title too long (max = 31 chars).\n" );
  83.             return;
  84.             }
  85.         stdata.PgmTitle = argv[1];
  86.  
  87.     /* Get session type */
  88.     /* Note: stdata.SessionType cannot be 0 due to the fact that
  89.      *       a general protection fault may occur if the program
  90.      *       being loaded is a presentation manager program.
  91.      */
  92.         if      ( 0 == stricmp(argv[2],"/FS") )  stdata.SessionType = 1;
  93.         else if ( 0 == stricmp(argv[2],"/WIN") ) stdata.SessionType = 2;
  94.         else if ( 0 == stricmp(argv[2],"/PM") )  stdata.SessionType = 3;
  95.         else                                     { printf(msg); return; }
  96.  
  97.     /* Get inheritance method */
  98.         if ( 0 == stricmp(argv[3],"/I") )
  99.             {
  100.             stdata.InheritOpt = 0;  // Get environment from CONFIG.SYS
  101.             n = 4;
  102.             }
  103.         else
  104.             {
  105.             stdata.InheritOpt = 1;  // Inherit environment from LOAD process
  106.             n = 3;
  107.             }
  108.  
  109.     /* Get icon file name */
  110.         if ( 0 == strnicmp(argv[n],"/ICON=",6) )
  111.             {
  112.             stdata.IconFile = qfn(&argv[n][6]);
  113.             if ( stdata.IconFile == NULL )
  114.                 {
  115.                 printf( "ERROR: Illegal drive or dir in icon filename\n" );
  116.                 return;
  117.                 }
  118.             n++;
  119.             }
  120.         else
  121.             stdata.IconFile = NULL;
  122.  
  123.     /* Get program file name */
  124.         stdata.PgmName = argv[n++];
  125.  
  126.     /* Get program arguments */
  127.         for ( m = n,len = 0; m < argc; m++ ) len += strlen(argv[n]);
  128.         if ( NULL == (options = calloc(len+1,sizeof(char))) )
  129.             {
  130.             printf( "ERROR: Insufficient memory\n" );
  131.             return;
  132.             }
  133.         for ( ; n < argc; n++ ) strcat( options,argv[n] );
  134.         stdata.PgmInputs = options;
  135.  
  136.     /* Fill in remaining fields in STARTDATA structure */
  137.         stdata.Length       = 50;       // length of structure
  138.         stdata.Related      = FALSE;    // start new independent session
  139.         stdata.FgBg         = TRUE;     // start new session in background
  140.         stdata.TraceOpt     = 0;        // program not being traced
  141.         stdata.TermQ        = NULL;     // not used
  142.         stdata.Environment  = NULL;     // not used
  143.         stdata.PgmHandle    = NULL;     // don't know what this parm. does
  144.         stdata.PgmControl   = 4;        // start session as PM icon
  145.         stdata.InitXPos     = 0;        // position values not used,
  146.         stdata.InitYPos     = 0;        //  initialized to zero.
  147.         stdata.InitXSize    = 0;
  148.         stdata.InitYSize    = 0;
  149.  
  150.     /* Start new program */
  151.         code = DosStartSession( &stdata,&idSession,&pid );
  152.         if ( code != 0 ) printf( "Error %#04x while starting session \"%s\"\n",
  153.                                   code,argv[1] );
  154.  
  155.         return;
  156.     }
  157. /****************************************************************************/
  158.