Snoopy: tabs->spaces
[AROS.git] / workbench / system / Snoopy / main.c
blobf1d424d7055c650222bfeaf008f288197466e19f
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,
65 IPTR result, BOOL canInterrupt, BOOL expand)
67 char pathbuf[MAX_STR_LEN+1];
69 struct Task *thistask = SysBase->ThisTask;
70 STRPTR name = thistask->tc_Node.ln_Name;
72 if (setup.onlyShowFails && result) return;
73 if (setup.ignoreWB)
75 if ( ! stricmp(name, "wanderer:wanderer")) return;
76 if ( ! stricmp(name, "new shell")) return;
77 if ( ! stricmp(name, "newshell")) return;
78 if ( ! stricmp(name, "boot shell")) return;
79 if ( ! stricmp(name, "background cli")) return;
82 if (setup.match && ! MatchPatternNoCase(setup.parsedpattern, name))
84 // pattern doesn't fit
85 return;
88 // FIXME: Can Forbid/Permit cause locks?
89 Forbid();
91 RawPutChars("SNOOP ", 7);
93 prettyprint(name, setup.nameLen);
95 if (setup.showCliNr)
97 int clinum = 0;
98 if (thistask->tc_Node.ln_Type == NT_PROCESS && ((struct Process *)thistask)->pr_CLI)
100 clinum = ((struct Process *)thistask)->pr_TaskNum;
103 kprintf(" [%d]", clinum);
106 prettyprint(action, setup.actionLen);
108 if (setup.showPaths && target != NULL)
110 if (expand)
112 //Expand filename to full path
113 target = MyNameFromLock(((struct Process *)thistask)->pr_CurrentDir,
114 (char *)target, pathbuf, MAX_STR_LEN);
117 prettyprint(target, setup.targetLen);
119 prettyprint(option, setup.optionLen);
120 prettyprint(result ? MSG(MSG_OK) : MSG(MSG_FAIL), 0);
121 RawPutChar('\n');
122 Permit();
124 // We're calling the breakpoint function from the output function
125 // so that we don't have to check the setup parameters again.
126 // canInterrupt is for cases where a patch prints multiple lines.
127 if (canInterrupt && setup.breakPoint) SNOOPY_breakpoint();
131 void main_parsepattern(void)
133 setup.match = FALSE;
135 if (!setup.pattern) return;
136 if (setup.pattern[0] == '\0') return;
138 Forbid(); // avoid that parsed pattern is used while we change it
139 setup.parsedpattern[0] = '\0';
140 if (ParsePatternNoCase(setup.pattern, setup.parsedpattern, PARSEDPATTERNLEN) != -1)
142 setup.match = TRUE;
144 Permit();
148 void clean_exit(char *s)
150 gui_cleanup();
151 if (s)
153 puts(s);
154 exit(RETURN_FAIL);
156 exit(RETURN_OK);