Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / utilities / Snoopy / main.c
blob8c5f00be8d2bb1aa8840e92f71c80d99b4cb43c1
1 /*
2 Copyright © 2006-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <stdio.h>
8 #include <stdlib.h>
10 #include <proto/dos.h>
11 #include <proto/arossupport.h>
12 #include <proto/exec.h>
14 #include "main.h"
15 #include "gui.h"
16 #include "patches.h"
17 #include "setup.h"
18 #include "locale.h"
20 int main(void)
22 Locale_Initialize();
23 setup_init();
24 gui_init();
25 patches_init();
26 gui_handleevents();
27 clean_exit(NULL);
28 Locale_Deinitialize();
29 return RETURN_OK;
32 static void prettyprint(CONST_STRPTR str, LONG minlen)
34 if ( ! str) str = "";
35 LONG len = strlen(str);
36 RawPutChars("| ", 2);
37 RawPutChars(str, len);
38 LONG i;
39 for (i = len ; i < minlen ; i++)
41 RawPutChar(' ');
46 // eye-catching function name because this is what we'd see in the debugger
47 static void SNOOPY_breakpoint(void)
49 // interrupting makes only sense on "hosted" where we have a debugger
50 #if (AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
51 #if defined(__i386__) || defined(__x86_64__)
52 asm("int3");
53 #elif defined(__powerpc__)
54 asm("trap");
55 #else
56 // TODO: other platforms
57 kprintf("[SNOOP] interrupt not supported on this platform\n");
58 #endif
59 #endif
63 void main_output(CONST_STRPTR action, CONST_STRPTR target, CONST_STRPTR option, LONG result, BOOL canInterrupt)
65 struct Task *thistask = SysBase->ThisTask;
66 STRPTR name = thistask->tc_Node.ln_Name;
68 if (setup.onlyShowFails && result) return;
69 if (setup.ignoreWB)
71 if ( ! stricmp(name, "wanderer:wanderer")) return;
72 if ( ! stricmp(name, "new shell")) return;
73 if ( ! stricmp(name, "newshell")) return;
74 if ( ! stricmp(name, "boot shell")) return;
75 if ( ! stricmp(name, "background cli")) return;
78 if (setup.match && ! MatchPatternNoCase(setup.parsedpattern, name))
80 // pattern doesn't fit
81 return;
84 // FIXME: Can Forbid/Permit cause locks?
85 Forbid();
87 RawPutChars("SNOOP ", 7);
89 prettyprint(name, setup.nameLen);
91 if (setup.showCliNr)
93 int clinum = 0;
94 if (thistask->tc_Node.ln_Type == NT_PROCESS && ((struct Process *)thistask)->pr_CLI)
96 clinum = ((struct Process *)thistask)->pr_TaskNum;
99 kprintf(" [%d]", clinum);
102 prettyprint(action, setup.actionLen);
103 prettyprint(target, setup.targetLen);
104 prettyprint(option, setup.optionLen);
105 prettyprint(result ? MSG(MSG_OK) : MSG(MSG_FAIL), 0);
106 RawPutChar('\n');
107 Permit();
109 // We're calling the breakpoint function from the output function
110 // so that we don't have to check the setup parameters again.
111 // canInterrupt is for cases where a patch prints multiple lines.
112 if (canInterrupt && setup.breakPoint) SNOOPY_breakpoint();
116 void main_parsepattern(void)
118 setup.match = FALSE;
120 if (!setup.pattern) return;
121 if (setup.pattern[0] == '\0') return;
123 Forbid(); // avoid that parsed pattern is used while we change it
124 setup.parsedpattern[0] = '\0';
125 if (ParsePatternNoCase(setup.pattern, setup.parsedpattern, PARSEDPATTERNLEN) != -1)
127 setup.match = TRUE;
129 Permit();
133 void clean_exit(char *s)
135 gui_cleanup();
136 if (s)
138 puts(s);
139 exit(RETURN_FAIL);
141 exit(RETURN_OK);