home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / LICC.ZIP / LICC.C next >
C/C++ Source or Header  |  1993-03-03  |  4KB  |  145 lines

  1. // licc.c - load icc
  2. // Written by Matt Osborn 75230,1346
  3. // Suggested by Ian Ameline  70400,2356
  4.  
  5. // This program will load the major elements (maybe even all) of the
  6. // IBM C Set/2 compiler into memory for faster access times.
  7.  
  8. // This program has been generalized to accept a list of command line
  9. // arguments that specify which programs to load. If such a list is not
  10. // provided, a default list will be used.
  11.  
  12. // Not much out of the base
  13. #define INCL_DOSPROCESS
  14. #include <os2.h>
  15.  
  16. // Minimal C runtime also
  17. #include <stdio.h>
  18.  
  19. // A few magic cookies
  20. #define LICC_COUNT     4                // Default count of programs
  21. #define LICC_MAIN      "icc.exe"        // Programs to load
  22. #define LICC_DDE4BE    "dde4be.exe"
  23. #define LICC_DDE4BE0   "dde4be0.exe"
  24. #define LICC_DDE4FE    "dde4fe.exe"
  25. #define LICC_DEFAULT   "default"
  26. #define LICC_USER      "user"
  27.  
  28. // And a few error codes
  29. #define LICCERR_OK      0     // Everything is fine
  30. #define LICCERR_NOLOAD  1     // No programs loaded
  31.  
  32. // Function prototypes
  33. APIRET exec (PSZ pszName);
  34. int main (int argc, char *argv[]);
  35.  
  36. // The guy that runs the show
  37. int main (int argc, char *argv[])
  38. {
  39. int count = 0;              // Count of successfully loaded programs
  40. int total = argc -1;        // Total count of programs to load
  41. int args = argc;            // Copy of argument count
  42. char **argp;                // Copy of argument pointer
  43. char *pszList;              // Program list
  44.  
  45. char *argd [5] = {          // Default arguments
  46.   NULL,
  47.   LICC_MAIN,
  48.   LICC_DDE4BE,
  49.   LICC_DDE4BE0,
  50.   LICC_DDE4FE
  51. };
  52.  
  53.   // Any arguments?
  54.   if (argc > 1) {
  55.  
  56.     // Yes, use user supplied list
  57.     argp    = argv;
  58.     args    = argc;
  59.     pszList = LICC_USER;
  60.  
  61.   } else {
  62.  
  63.     // Use defaults
  64.     total   = LICC_COUNT;
  65.     args    = LICC_COUNT + 1;
  66.     pszList = LICC_DEFAULT;
  67.     argd[0] = argv[0];
  68.     argp    = argd;
  69.   }
  70.  
  71.  
  72.   // Sign on, just to be obnoxious
  73.   printf ("\n%s: loading %s program list\n", argp[0], pszList);
  74.  
  75.   // Loop for all arguments
  76.   while (args-- > 1) {
  77.  
  78.     // Try to load program (the guy that does the work)
  79.     if (!exec (argp[args])) {
  80.  
  81.        // Successful, bump count of loaded programs
  82.        count++;
  83.     }
  84.   }
  85.  
  86.   // Were any programs loaded?
  87.   if (count) {
  88.  
  89.     // We were successful (to some degree)
  90.     printf ("\n\n%d out of %d program(s) were successfully loaded.", count, total);
  91.  
  92.     // Notify user that we're sleeping
  93.     printf ("\n\nNow sleeping, type CTRL-C to end program\n\n");
  94.  
  95.     // Sleep for however long
  96.     DosSleep (-1);
  97.  
  98.   } else {
  99.  
  100.      // No programs loaded
  101.      printf ("\nNo programs successfully loaded\n");
  102.   }
  103.  
  104.   // This is for you batch file guys
  105.   return ((count) ? LICCERR_OK : LICCERR_NOLOAD);
  106. }
  107.  
  108.  
  109. // The guy that does the work
  110. APIRET exec (PSZ pszName)
  111. {
  112. RESULTCODES rcs;
  113. CHAR   achName [CCHMAXPATH];
  114. APIRET rc;
  115.  
  116.   // Inform user of program load (I like being obnoxious)
  117.   printf ("\nLoading program: %-32s - ", pszName);
  118.  
  119.   // Initialize failed module name buffer
  120.   *achName = '\0';
  121.  
  122.   // Now attempt the actual load
  123.   rc = DosExecPgm (achName, sizeof(achName), EXEC_LOAD, 0, 0, &rcs, pszName);
  124.  
  125.   // Any problem?
  126.   if (rc) {
  127.     // Problem of some sort, notify user
  128.     printf ("failed, error: %lx,", rc);
  129.  
  130.     // Any module name returned?
  131.     if (*achName) {
  132.       // Yes, print module name also
  133.       printf (" module: %s", achName);
  134.     }
  135.  
  136.   } else {
  137.  
  138.     // No problem loading program, let's brag about it
  139.     printf (" process id: %ld", rcs.codeTerminate);
  140.   }
  141.  
  142.   // Return results
  143.   return (rc);
  144. }
  145.