Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Snoopy / main.c
blob69b35a680473ee6741fe3c8bdf9611f7791f8e13
1 /*
2 Copyright © 2006-2015, 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>
14 #include <proto/utility.h>
16 #include "main.h"
17 #include "gui.h"
18 #include "patches.h"
19 #include "setup.h"
20 #include "locale.h"
22 int main(void)
24 Locale_Initialize();
25 setup_init();
26 gui_init();
27 patches_init();
28 gui_handleevents();
29 clean_exit(NULL);
30 Locale_Deinitialize();
31 return RETURN_OK;
34 static void prettyprint(CONST_STRPTR str, LONG minlen)
36 if ( ! str) str = "";
37 LONG len = strlen(str);
38 RawPutChars("| ", 2);
39 RawPutChars(str, len);
40 LONG i;
41 for (i = len ; i < minlen ; i++)
43 RawPutChar(' ');
48 // eye-catching function name because this is what we'd see in the debugger
49 static void SNOOPY_breakpoint(void)
51 // interrupting makes only sense on "hosted" where we have a debugger
52 #if (AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
53 #if defined(__i386__) || defined(__x86_64__)
54 asm("int3");
55 #elif defined(__powerpc__)
56 asm("trap");
57 #else
58 // TODO: other platforms
59 kprintf("[SNOOP] interrupt not supported on this platform\n");
60 #endif
61 #endif
65 void main_output(CONST_STRPTR action, CONST_STRPTR target, CONST_STRPTR option,
66 IPTR result, BOOL canInterrupt, BOOL expand)
68 char pathbuf[MAX_STR_LEN+1];
70 struct Task *thistask = FindTask(NULL);
71 STRPTR name = thistask->tc_Node.ln_Name;
73 if (setup.onlyShowFails && result) return;
74 if (setup.ignoreWB)
76 if ( ! Stricmp(name, "wanderer:wanderer")) return;
77 if ( ! Stricmp(name, "Shell")) return;
78 if ( ! Stricmp(name, "new shell")) return;
79 if ( ! Stricmp(name, "newshell")) return;
80 if ( ! Stricmp(name, "boot shell")) return;
81 if ( ! Stricmp(name, "background cli")) return;
84 if (setup.match && ! MatchPatternNoCase(setup.parsedpattern, name))
86 // pattern doesn't fit
87 return;
90 // FIXME: Can Forbid/Permit cause locks?
91 Forbid();
93 RawPutChars("SNOOP ", 7);
95 prettyprint(name, setup.nameLen);
97 if (setup.showCliNr)
99 int clinum = 0;
100 if (thistask->tc_Node.ln_Type == NT_PROCESS && ((struct Process *)thistask)->pr_CLI)
102 clinum = ((struct Process *)thistask)->pr_TaskNum;
105 kprintf(" [%d]", clinum);
108 prettyprint(action, setup.actionLen);
110 if (setup.showPaths && target != NULL)
112 if (expand)
114 //Expand filename to full path
115 target = MyNameFromLock(((struct Process *)thistask)->pr_CurrentDir,
116 (char *)target, pathbuf, MAX_STR_LEN);
119 prettyprint(target, setup.targetLen);
121 prettyprint(option, setup.optionLen);
122 prettyprint(result ? MSG(MSG_OK) : MSG(MSG_FAIL), 0);
123 RawPutChar('\n');
124 Permit();
126 // We're calling the breakpoint function from the output function
127 // so that we don't have to check the setup parameters again.
128 // canInterrupt is for cases where a patch prints multiple lines.
129 if (canInterrupt && setup.breakPoint) SNOOPY_breakpoint();
133 void main_parsepattern(void)
135 setup.match = FALSE;
137 if (!setup.pattern) return;
138 if (setup.pattern[0] == '\0') return;
140 Forbid(); // avoid that parsed pattern is used while we change it
141 setup.parsedpattern[0] = '\0';
142 if (ParsePatternNoCase(setup.pattern, setup.parsedpattern, PARSEDPATTERNLEN) != -1)
144 setup.match = TRUE;
146 Permit();
150 void clean_exit(char *s)
152 gui_cleanup();
153 if (s)
155 puts(s);
156 exit(RETURN_FAIL);
158 exit(RETURN_OK);