home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / sp.zip / SP.C < prev    next >
C/C++ Source or Header  |  1993-09-17  |  3KB  |  135 lines

  1. /* SetPriority (SP)                                                        */
  2. /* Angepaßt an OS/2 Version 2.x von Jens Glathe, 3.9.1993                  */
  3. /* Erweiterung für das Beeinflussen von DOS-Boxen: 6.9.1993,16/17.9.1993   */
  4.  
  5. #define INCL_DOSSESMGR
  6. #define INCL_DOSPROCESS
  7. #define INCL_NOPM
  8.  
  9. #include <os2.h>
  10. #include <string.h>
  11. #include <direct.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #define PATHLEN 256
  16.  
  17. static struct _pt                                            /*Structure for Class info           */
  18. {
  19.   char ch;
  20.   USHORT usClass;
  21. } pt[]=
  22. {
  23.   {'i', PRTYC_IDLETIME},
  24.   {'n', PRTYC_NOCHANGE},
  25.   {'r', PRTYC_REGULAR},
  26.   {'t', PRTYC_TIMECRITICAL},
  27.   {'f', PRTYC_FOREGROUNDSERVER},
  28.   {0,   0}
  29. };
  30.  
  31. static struct _st                     /*Structure for Session type         */
  32. {
  33.     char ch;
  34.     USHORT Class;
  35. } st[]=
  36. {
  37.     {'o', SSF_TYPE_WINDOWABLEVIO},
  38.     {'D', SSF_TYPE_VDM},
  39.     {'d', SSF_TYPE_WINDOWEDVDM},
  40.     {0, SSF_TYPE_DEFAULT}
  41. };
  42.  
  43. char *prior[]={"no change in", "idle", "regular", "time critical", "foreground"};
  44.  
  45. char        args[255];
  46. ULONG        usClass=PRTYC_NOCHANGE;
  47. ULONG        rc;
  48. LONG        sDelta=0;
  49. struct    _pt *ppt;
  50. char        **p;
  51. struct  _st *pst;
  52. ULONG     ulSitzungsTyp=SSF_TYPE_DEFAULT;
  53.  
  54. PPIB        myPIB;
  55. PTIB        myTIB;
  56.  
  57. int main(int argc, char *argv[])
  58. {
  59.   if (argc < 3)
  60.   {
  61.     printf("Usage:\n\n");
  62.  
  63.         printf("SP <class>[delta] <sessiontype> <program> [args...]\n\n");
  64.  
  65.     printf("<class>:  n=no change, i=idle, r=regular, f=foreground, t=time critical\n");
  66.         printf("[delta]:  Any number from -31 to 31, 0 to 31 for DOS sessions\n");
  67.         printf("<sessiontype>:  o=OS/2 Window or PM App, d=DOS-Window, D=DOS-Fullscreen\n");
  68.         printf("\nThe driver \"VDOSPRIO.SYS\" must have been loaded to change the priority\n");
  69.         printf("of a DOS session.\n");
  70.         return 1;
  71.     }
  72.  
  73.     *argv[1]=(char)tolower(*argv[1]);
  74.  
  75.     for (ppt=pt; ppt->ch; ppt++)        /* Prioritätsklasse bestimmen        */
  76.         if (ppt->ch==*argv[1])
  77.         {
  78.             usClass=ppt->usClass;
  79.             break;
  80.         }
  81.  
  82.     for (pst=st; pst->ch; pst++)        /* Sitzungstyp bestimmen             */
  83.         if (pst->ch==*argv[2])
  84.         {
  85.             ulSitzungsTyp=pst->Class;
  86.             break;
  87.     }
  88.  
  89.     sDelta=atoi(argv[1] + !!islower(*argv[1]));
  90.  
  91.     *args='\0';
  92.  
  93.  
  94.   if (args[strlen(args)-1]==' ')
  95.     args[strlen(args)-1]='\0';
  96.  
  97.   printf("SP: running %s, %s priority, delta %d\n",
  98.                  argv[3], prior[usClass], sDelta);
  99.  
  100.     if (ulSitzungsTyp!=SSF_TYPE_WINDOWABLEVIO){
  101.  
  102.         strcat(args,"SPDOS.EXE ");
  103.         strcat(args,*(argv+1));
  104.         strcat(args," ");
  105.  
  106.         for (p=argv+3; *p; p++)                        /* Argumenteliste zusammenstellen    */
  107.         {
  108.             strcat(args, *p);
  109.             strcat(args, " ");
  110.         }
  111.         system(args);
  112.  
  113.     } else{
  114.         for (p=argv+3; *p; p++)                        /* Argumenteliste zusammenstellen    */
  115.         {
  116.             strcat(args, *p);
  117.             strcat(args, " ");
  118.         }
  119.  
  120.         if (rc=DosGetInfoBlocks(&myTIB,&myPIB))
  121.             {printf("SP: DosGetInfoBlocks() rc=%ld",rc);
  122.             }
  123.  
  124.         if ((rc=DosSetPriority(
  125.                 PRTYS_PROCESSTREE,
  126.                 usClass,
  127.                 sDelta,
  128.                 myPIB->pib_ulpid)) != 0)
  129.             printf("DosSetPriority() rc=%u\n", rc);
  130.  
  131.         system(args);
  132.     }
  133.     return rc;
  134. }
  135.