home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / RXPRIO.ZIP / REXXPRIO.C next >
Text File  |  1992-11-02  |  6KB  |  104 lines

  1. #define  INCL_DOS
  2. #define  INCL_REXXSAA
  3. #include <os2.h>
  4. #include <rexxsaa.h>
  5. #include <string.h>
  6. #include <stdio.h>
  7.  
  8. #define  MAX_DIGITS     9          /* maximum digits in numeric arg  */
  9. #define  INVALID_ROUTINE 40            /* Raise Rexx error           */
  10. #define  VALID_ROUTINE    0            /* Successful completion      */
  11.  
  12. /********************************************************************
  13. * Function:  string2long(string, number)                            *
  14. *                                                                   *
  15. * Purpose:   Validates and converts an ASCII-Z string from string   *
  16. *            form to an unsigned long.  Returns FALSE if the number *
  17. *            is not valid, TRUE if the number was successfully      *
  18. *            converted.                                             *
  19. *                                                                   *
  20. * RC:        TRUE - Good number converted                           *
  21. *            FALSE - Invalid number supplied.                       *
  22. *********************************************************************/
  23.  
  24. BOOL string2long(PSZ string, LONG *number)
  25. {
  26.   ULONG    accumulator;                /* converted number           */
  27.   INT      length;                     /* length of number           */
  28.   INT      sign;                       /* sign of number             */
  29.  
  30.   sign = 1;                            /* set default sign           */
  31.   if (*string == '-') {                /* negative?
  32.     sign = -1;                         /* change sign                */
  33.     string++;                          /* step past sign             */
  34.   }
  35.  
  36.   length = strlen(string);             /* get length of string       */
  37.   if (length == 0 ||                   /* if null string             */
  38.       length > MAX_DIGITS)             /* or too long                */
  39.     return FALSE;                      /* not valid                  */
  40.  
  41.   accumulator = 0;                     /* start with zero            */
  42.  
  43.   while (length) {                     /* while more digits          */
  44.     if (!isdigit(*string))             /* not a digit?               */
  45.       return FALSE;                    /* tell caller                */
  46.                                        /* add to accumulator         */
  47.     accumulator = accumulator *10 + (*string - '0');
  48.     length--;                          /* reduce length              */
  49.     string++;                          /* step pointer               */
  50.   }
  51.   *number = accumulator * sign;        /* return the value           */
  52.   return TRUE;                         /* good number                */
  53. }
  54.  
  55. /*************************************************************************
  56. * Function:  SysSetPriority                                              *
  57. *                                                                        *
  58. * Syntax:    result = SysSetPriority(Class, Level)                       *
  59. *                                                                        *
  60. * Params:    Class  - The priority class (0-4)                           *
  61. *            Level  - Amount to change (-31 to +31)                      *
  62. *                                                                        *
  63. * Return:    result - return code from DosSetPriority                    *
  64. *************************************************************************/
  65.  
  66. #define  INCL_DOS
  67. #define  INCL_REXXSAA
  68. #include <os2.h>
  69. #include <rexxsaa.h>
  70. #include <string.h>
  71. #include <stdio.h>
  72.  
  73. #define  INVALID_ROUTINE 40            /* Raise Rexx error           */
  74. #define  VALID_ROUTINE    0            /* Successful completion      */
  75.                                                                           
  76. LONG APIENTRY SysSetPriority(
  77.   PSZ       name,                      /* Function name              */
  78.   LONG      numargs,                   /* Number of arguments        */
  79.   RXSTRING  args[],                    /* Argument array             */
  80.   PSZ       queuename,                 /* Current queue              */
  81.   PRXSTRING retstr )                   /* Return RXSTRING            */
  82. {
  83.   LONG      class;                     /* priority class             */   
  84.   LONG      level;                     /* priority level             */   
  85.   APIRET    rc;                        /* creation return code       */   
  86.  
  87.   if (numargs != 2 ||                  /* must have two              */   
  88.       !RXVALIDSTRING(args[0]))         /* first is omitted           */
  89.     return INVALID_ROUTINE;            /* raise error condition      */   
  90.                                        /* get class of change        */   
  91.   if (!string2long(args[0].strptr, &class) ||
  92.       class < PRTYC_NOCHANGE || class > PRTYC_FOREGROUNDSERVER)           
  93.     return INVALID_ROUTINE;            /* raise error condition      */   
  94.                                        /* get class of change        */   
  95.   if (!string2long(args[1].strptr, &level) ||
  96.       level < PRTYD_MINIMUM || level > PRTYD_MAXIMUM)                     
  97.     return INVALID_ROUTINE;            /* raise error condition      */   
  98.                                        /* change the priority        */   
  99.   rc = DosSetPrty(PRTYS_THREAD, (ULONG)class, level, 0);                  
  100.   sprintf(retstr->strptr, "%d", rc);   /* format the return code     */
  101.   retstr->strlength = strlen(retstr->strptr);                             
  102.   return VALID_ROUTINE;                /* good completion            */   
  103. }                                                                         
  104.