;/*
sc parms=register nostackcheck commentnest opttime SetIntPri.c
slink lib:c.o SetIntPri.o to SetIntPri lib lib:sc.lib lib:scm.lib sc sd
quit 0

¥ø, ©Øø£ - Ð¡Ç ¦Z /\/\ÆÐE ß¥ §¦£¦çØn §µ®fE®

*/

#define __USE_SYSBASE   1

#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/tasks.h>
#include <exec/execbase.h>
#include <proto/exec.h>
#include <dos/dosextens.h>
#include <dos.h>
#include <proto/dos.h>
#include <string.h>


int SetIntPri(char *name,long);


const char * VERSTAG = "$VER: SetIntPri 1.0 ("__DATE__") (c) SiliconSurfer/Phantasm";


int main (void)
{
	LONG pri=0;
   LONG Quiet = 0;
   struct RDArgs *rda;
   LONG vec[3]={0,0,0};
   char *IntName = NULL;

	if (rda = ReadArgs("NAME/A,PRIORITY/A/N,Q=QUIET/S", vec, NULL) )
	{
   	IntName = (char *)(vec[0]);
   	pri = *(LONG *)(vec[1]);
   	Quiet = vec[2];

		if (!Quiet) Printf("%s\n\n",&VERSTAG[6]);

   	if (pri <-128 || pri >127)
   	{
   		if (!Quiet)
   			PutStr("Requested priority out of range\n");
   		FreeArgs(rda);
   		return 10;
   	}

      Forbid();

		if (!SetIntPri(IntName,pri))
		{
			Permit();
			if (!Quiet)
				Printf("%s not found\n", IntName);
			FreeArgs(rda);
			return 20;
		}
		else
		{
   		Permit();
   		if (!Quiet)
   		{
  				Printf("%s priority changed to %ld\n",IntName,pri);
   		}
   		FreeArgs(rda);
   		return 0;
   	}
   }
   else
	{
		Printf("%s\n\n",&VERSTAG[6]);
   	PrintFault(IoErr(), "ReadArgs() error");
	}
   return 5;
}

int SetIntPri(char *name,long pri)
{
	struct Node *node;
   struct List *plist;
	ULONG  i;


   for (i=0;i<16;i++)
   {

	   Disable();

		if (plist=(struct List *)SysBase->IntVects[i].iv_Data)
		{

			node=FindName(plist,name);

			if (node)
			{
				Remove(node);
				node->ln_Pri=pri;
				Enqueue(plist,node);
		   	Enable();
				return(-1);
			}

		}

	   Enable();

   }
   return (NULL);
}

