compiler/clib: Refactoring code for C99/POSIX.1-2008 separation.
[AROS.git] / workbench / utilities / Snoopy / main.c
blob846628b5bf4026f4a66f9a380619103229765dc8
1 /*
2 Copyright © 2006-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/config.h>
7 #include <aros/debug.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include <proto/dos.h>
12 #include <proto/arossupport.h>
13 #include <proto/exec.h>
15 #include "main.h"
16 #include "gui.h"
17 #include "patches.h"
18 #include "setup.h"
19 #include "locale.h"
21 int main(void)
23 Locale_Initialize();
24 setup_init();
25 gui_init();
26 patches_init();
27 gui_handleevents();
28 clean_exit(NULL);
29 Locale_Deinitialize();
30 return RETURN_OK;
33 static void prettyprint(CONST_STRPTR str, LONG minlen)
35 if ( ! str) str = "";
36 LONG len = strlen(str);
37 RawPutChars("| ", 2);
38 RawPutChars(str, len);
39 LONG i;
40 for (i = len ; i < minlen ; i++)
42 RawPutChar(' ');
47 // eye-catching function name because this is what we'd see in the debugger
48 static void SNOOPY_breakpoint(void)
50 // interrupting makes only sense on "hosted" where we have a debugger
51 #if (AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
52 #if defined(__i386__) || defined(__x86_64__)
53 asm("int3");
54 #elif defined(__powerpc__)
55 asm("trap");
56 #else
57 // TODO: other platforms
58 kprintf("[SNOOP] interrupt not supported on this platform\n");
59 #endif
60 #endif
64 void main_output(CONST_STRPTR action, CONST_STRPTR target, CONST_STRPTR option, IPTR result, BOOL canInterrupt)
66 struct Task *thistask = SysBase->ThisTask;
67 STRPTR name = thistask->tc_Node.ln_Name;
69 if (setup.onlyShowFails && result) return;
70 if (setup.ignoreWB)
72 if ( ! stricmp(name, "wanderer:wanderer")) return;
73 if ( ! stricmp(name, "new shell")) return;
74 if ( ! stricmp(name, "newshell")) return;
75 if ( ! stricmp(name, "boot shell")) return;
76 if ( ! stricmp(name, "background cli")) return;
79 if (setup.match && ! MatchPatternNoCase(setup.parsedpattern, name))
81 // pattern doesn't fit
82 return;
85 // FIXME: Can Forbid/Permit cause locks?
86 Forbid();
88 RawPutChars("SNOOP ", 7);
90 prettyprint(name, setup.nameLen);
92 if (setup.showCliNr)
94 int clinum = 0;
95 if (thistask->tc_Node.ln_Type == NT_PROCESS && ((struct Process *)thistask)->pr_CLI)
97 clinum = ((struct Process *)thistask)->pr_TaskNum;
100 kprintf(" [%d]", clinum);
103 prettyprint(action, setup.actionLen);
104 prettyprint(target, setup.targetLen);
105 prettyprint(option, setup.optionLen);
106 prettyprint(result ? MSG(MSG_OK) : MSG(MSG_FAIL), 0);
107 RawPutChar('\n');
108 Permit();
110 // We're calling the breakpoint function from the output function
111 // so that we don't have to check the setup parameters again.
112 // canInterrupt is for cases where a patch prints multiple lines.
113 if (canInterrupt && setup.breakPoint) SNOOPY_breakpoint();
117 void main_parsepattern(void)
119 setup.match = FALSE;
121 if (!setup.pattern) return;
122 if (setup.pattern[0] == '\0') return;
124 Forbid(); // avoid that parsed pattern is used while we change it
125 setup.parsedpattern[0] = '\0';
126 if (ParsePatternNoCase(setup.pattern, setup.parsedpattern, PARSEDPATTERNLEN) != -1)
128 setup.match = TRUE;
130 Permit();
134 void clean_exit(char *s)
136 gui_cleanup();
137 if (s)
139 puts(s);
140 exit(RETURN_FAIL);
142 exit(RETURN_OK);