New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Status.c
blob18ee92a9b477d3f0eb4db0a505f55cdaf2721183
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*****************************************************************************
8 NAME
10 Status
12 SYNOPSIS
14 PROCESS/N,FULL/S,TCB/S,CLI=ALL/S,COM=COMMAND/K
16 LOCATION
18 Workbench:c
20 FUNCTION
22 Display information about the processes that are executing
23 within Shells/CLIs.
25 INPUTS
27 PROCESS -- Process Identification number.
29 FULL -- Display all information about the processes.
31 TCB -- As for Full, except that this option omits the
32 process name.
34 CLI=ALL -- Default. Displays all processes.
36 COM=COMMAND -- Show the process id of the command given. Specify
37 the command name.
39 RESULT
41 Standard DOS error codes.
43 NOTES
45 EXAMPLE
47 Status
49 Process 2: Loaded as command: c:status
50 Process 3: Loaded as command: c:NewIcons
51 Process 4: Loaded as command: GG:Sys/L/fifo-handler
52 Process 5: Loaded as command: Workbench
53 Process 6: Loaded as command: ToolsDaemon
55 Status full
57 Process 2: stk 300000, pri 0 Loaded as command: c:status
58 Process 3: stk 4096, pri 0 Loaded as command: c:NewIcons
59 Process 4: stk 4096, pri 0 Loaded as command: GG:Sys/L/fifo-handler
60 Process 5: stk 6000, pri 1 Loaded as command: Workbench
61 Process 6: stk 4000, pri 2 Loaded as command: ToolsDaemon
63 BUGS
65 SEE ALSO
67 <dos/dosextens.h>
69 INTERNALS
71 ******************************************************************************/
73 #include <exec/lists.h>
75 #define DEBUG 0
76 #include <aros/debug.h>
78 #include <proto/dos.h>
79 #include <proto/exec.h>
81 #include <dos/dos.h>
82 #include <dos/dosextens.h>
83 #include <exec/types.h>
85 #include <strings.h>
86 #include <stdio.h>
88 #include <aros/shcommands.h>
90 static void printProcess(struct DosLibrary *DOSBase, BOOL full, BOOL tcb,
91 struct Process *process);
92 static void PrintF(struct DosLibrary *DOSBase, STRPTR format, ...);
94 AROS_SH5(Status,41.1,
95 AROS_SHA(LONG *, ,PROCESS,/N,NULL),
96 AROS_SHA(BOOL, , FULL,/S,FALSE),
97 AROS_SHA(BOOL, , TCB,/S,FALSE),
98 AROS_SHA(BOOL,CLI=,ALL,/S,FALSE),
99 AROS_SHA(STRPTR,COM=,COMMAND,/K,NULL))
101 AROS_SHCOMMAND_INIT
103 struct RootNode *root = ((struct DosLibrary *)DOSBase)->dl_Root;
104 int retval = RETURN_OK;
105 BOOL full = SHArg(FULL);
106 BOOL tcb = SHArg(TCB);
107 BOOL all = SHArg(ALL);
108 ULONG processNum = 0;
109 STRPTR command = SHArg(COMMAND);
112 if (SHArg(PROCESS) != NULL)
114 processNum = *SHArg(PROCESS);
117 if (!full && !tcb && processNum == 0 && command == NULL)
119 all = TRUE;
122 if (command != NULL)
124 struct List *cliList;
125 struct CLIInfo *ci;
127 D(bug("command != NULL in Status\n"));
129 /* Get access to the rootnode */
130 ObtainSemaphore(&root->rn_RootLock);
132 D(bug("Got RootLock\n"));
134 cliList = (struct List *)&root->rn_CliList;
135 ci = (struct CLIInfo *)FindName(cliList, command);
137 if (ci != NULL)
139 if (ci->ci_Process->pr_TaskNum != 0)
141 PrintF(DOSBase," %ld\n", ci->ci_Process->pr_TaskNum);
144 else
146 retval = RETURN_WARN;
149 ReleaseSemaphore(&root->rn_RootLock);
151 else if (processNum != 0)
153 struct Process *process;
155 ObtainSemaphore(&root->rn_RootLock);
157 /* This is a temporary construction until I've fixed the
158 implementation of FindCliProc() */
159 Forbid();
160 process = FindCliProc(processNum);
161 Permit();
163 ReleaseSemaphore(&root->rn_RootLock);
165 if (process != NULL)
167 printProcess(DOSBase, full, tcb, process);
169 else
171 PrintF(DOSBase,"Process %ld does not exist\n", (int)processNum);
174 else
176 struct List *cliList;
177 struct CLIInfo *ci;
179 ObtainSemaphore(&root->rn_RootLock);
181 D(bug("Got RootLock\n"));
183 cliList = (struct List *)&root->rn_CliList;
185 ForeachNode(cliList, ci)
187 printProcess(DOSBase, full, tcb, ci->ci_Process);
190 ReleaseSemaphore(&root->rn_RootLock);
193 return retval;
195 AROS_SHCOMMAND_EXIT
199 /* Print the information for a certain cli process */
200 static void printProcess(struct DosLibrary *DOSBase, BOOL full, BOOL tcb,
201 struct Process *process)
203 struct CommandLineInterface *cli = BADDR(process->pr_CLI);
205 /* This should never happen, I guess */
206 if (cli == NULL)
208 return;
211 PrintF(DOSBase,"Process %ld ", process->pr_TaskNum);
213 if (tcb || full)
215 PrintF(DOSBase,"stk %lu, pri %lu ",
216 (ULONG)cli->cli_DefaultStack * CLI_DEFAULTSTACK_UNIT,
217 (ULONG)process->pr_Task.tc_Node.ln_Pri);
220 if (!tcb || full)
222 STRPTR name;
224 /* Sort of a hack. We rely on the fact that binary compatibility
225 BSTR:s is ended with a 0 byte */
226 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
227 name = (STRPTR)cli->cli_CommandName + 1;
228 #else
229 name = (STRPTR)cli->cli_CommandName;
230 #endif
232 PrintF(DOSBase, "Loaded as command: %s", name);
235 PrintF(DOSBase,"\n");
238 static void PrintF(struct DosLibrary *DOSBase, STRPTR format, ...)
240 va_list args;
241 va_start(args, format);
243 VPrintf(format, (LONG *) args);
245 va_end(args);