home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
RXPRIO.ZIP
/
REXXPRIO.C
next >
Wrap
Text File
|
1992-11-02
|
6KB
|
104 lines
#define INCL_DOS
#define INCL_REXXSAA
#include <os2.h>
#include <rexxsaa.h>
#include <string.h>
#include <stdio.h>
#define MAX_DIGITS 9 /* maximum digits in numeric arg */
#define INVALID_ROUTINE 40 /* Raise Rexx error */
#define VALID_ROUTINE 0 /* Successful completion */
/********************************************************************
* Function: string2long(string, number) *
* *
* Purpose: Validates and converts an ASCII-Z string from string *
* form to an unsigned long. Returns FALSE if the number *
* is not valid, TRUE if the number was successfully *
* converted. *
* *
* RC: TRUE - Good number converted *
* FALSE - Invalid number supplied. *
*********************************************************************/
BOOL string2long(PSZ string, LONG *number)
{
ULONG accumulator; /* converted number */
INT length; /* length of number */
INT sign; /* sign of number */
sign = 1; /* set default sign */
if (*string == '-') { /* negative?
sign = -1; /* change sign */
string++; /* step past sign */
}
length = strlen(string); /* get length of string */
if (length == 0 || /* if null string */
length > MAX_DIGITS) /* or too long */
return FALSE; /* not valid */
accumulator = 0; /* start with zero */
while (length) { /* while more digits */
if (!isdigit(*string)) /* not a digit? */
return FALSE; /* tell caller */
/* add to accumulator */
accumulator = accumulator *10 + (*string - '0');
length--; /* reduce length */
string++; /* step pointer */
}
*number = accumulator * sign; /* return the value */
return TRUE; /* good number */
}
/*************************************************************************
* Function: SysSetPriority *
* *
* Syntax: result = SysSetPriority(Class, Level) *
* *
* Params: Class - The priority class (0-4) *
* Level - Amount to change (-31 to +31) *
* *
* Return: result - return code from DosSetPriority *
*************************************************************************/
#define INCL_DOS
#define INCL_REXXSAA
#include <os2.h>
#include <rexxsaa.h>
#include <string.h>
#include <stdio.h>
#define INVALID_ROUTINE 40 /* Raise Rexx error */
#define VALID_ROUTINE 0 /* Successful completion */
LONG APIENTRY SysSetPriority(
PSZ name, /* Function name */
LONG numargs, /* Number of arguments */
RXSTRING args[], /* Argument array */
PSZ queuename, /* Current queue */
PRXSTRING retstr ) /* Return RXSTRING */
{
LONG class; /* priority class */
LONG level; /* priority level */
APIRET rc; /* creation return code */
if (numargs != 2 || /* must have two */
!RXVALIDSTRING(args[0])) /* first is omitted */
return INVALID_ROUTINE; /* raise error condition */
/* get class of change */
if (!string2long(args[0].strptr, &class) ||
class < PRTYC_NOCHANGE || class > PRTYC_FOREGROUNDSERVER)
return INVALID_ROUTINE; /* raise error condition */
/* get class of change */
if (!string2long(args[1].strptr, &level) ||
level < PRTYD_MINIMUM || level > PRTYD_MAXIMUM)
return INVALID_ROUTINE; /* raise error condition */
/* change the priority */
rc = DosSetPrty(PRTYS_THREAD, (ULONG)class, level, 0);
sprintf(retstr->strptr, "%d", rc); /* format the return code */
retstr->strlength = strlen(retstr->strptr);
return VALID_ROUTINE; /* good completion */
}