Some fix for scrolling with lasso.
[tangerine.git] / workbench / c / ChangeTaskPri.c
blobf283ef2069b1693a1c78bcc2165b106623670133
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Change the priority of a task.
6 Lang: english
7 */
9 /**************************************************************************
11 NAME
12 ChangeTaskPri
14 FORMAT
15 ChangeTaskPri <priority> [ PROCESS <process number> ]
17 SYNOPSIS
18 PRI=PRIORITY/A/N,PROCESS/K/N
20 LOCATION
21 Workbench:c
23 FUNCTION
24 The ChangeTaskPri command is used to change the current run
25 priority of a Task. As AROS is a multitasking operating
26 system, you can determine which tasks receive more CPU time
27 by changing their priorities.
29 The value of |priority| can be from -128 to 127, however values
30 greater than 4 are not recommended as they can interfere with
31 vital system processes. Higher values will give tasks a higher
32 CPU priority.
34 You can use the Status command to examine the list of Tasks that
35 are running and their process numbers.
37 EXAMPLE
39 1.SYS:> ChangeTaskPri 1 Process 1
41 Set the priority of the current process to 1.
43 1.SYS:> ChangeTaskPri 1
45 Also sets the priority of the current process to 1.
47 SEE ALSO
48 Status
50 **************************************************************************/
52 #include <exec/types.h>
53 #include <exec/tasks.h>
54 #include <dos/dosextens.h>
55 #include <dos/rdargs.h>
56 #include <proto/exec.h>
57 #include <proto/dos.h>
58 #include <utility/tagitem.h>
60 #define ARG_TEMPLATE "PRI=PRIORITY/A/N,PROCESS/N"
61 #define ARG_PRI 0
62 #define ARG_PROCESS 1
63 #define TOTAL_ARGS 2
65 static const char version[] = "$VER: ChangeTaskPri 41.2 (13.09.2005)";
66 static const char exthelp[] =
67 "ChangeTaskPri : Change the priority of a CLI task\n"
68 "\tPRI=PRIORITY/A/N New priority of task\n"
69 "\tPROCESS/K Optional process number of change\n";
71 int __nocommandline = 1;
73 int main(void)
75 struct Process *pr = NULL;
76 struct RDArgs *rda = NULL, *rdargs;
77 IPTR args[TOTAL_ARGS] = { 0, 0 };
78 int error = 0;
80 rda = AllocDosObject(DOS_RDARGS, NULL);
81 if( rda != NULL )
83 rda->RDA_ExtHelp = (STRPTR)exthelp;
85 rdargs = ReadArgs(ARG_TEMPLATE, (IPTR *)args, rda);
86 if( rdargs != NULL )
88 Forbid();
89 if( args[ARG_PROCESS] != 0 ) {
90 // Printf("PROCESS = %ld\n", *(LONG *)args[ARG_PROCESS]);
91 pr = FindCliProc(*(LONG *)args[ARG_PROCESS]);
93 else
94 pr = (struct Process *)FindTask(NULL);
95 // Printf("pr = 0x%08lx\n", pr);
96 if( pr != NULL )
98 LONG pri = (LONG)(*(IPTR *)args[ARG_PRI]);
100 /* Check the bounds on the priority */
101 if(pri < -128 || pri > 127 )
102 error = ERROR_OBJECT_TOO_LARGE;
103 else
104 /* Set the priority */
105 SetTaskPri( (struct Task *)pr, pri);
106 Permit();
108 else
110 BPTR errStream;
111 Permit();
112 errStream = Output();
114 pr = (struct Process *)FindTask(NULL);
115 if( pr->pr_CES != NULL )
116 errStream = pr->pr_CES;
118 FPuts(errStream, "ChangeTaskPri: Process does not exist.\n");
119 SetIoErr(0);
120 error = -1;
122 FreeArgs(rdargs);
123 } /* ReadArgs() ok */
124 else
125 error = IoErr();
126 FreeDosObject(DOS_RDARGS, rda);
127 } /* Got a RDArgs * */
128 else
129 error = IoErr();
130 if( error != -1 && error != 0 )
132 PrintFault(error, "ChangeTaskPri");
133 return RETURN_FAIL;
135 SetIoErr(0);
136 return 0;