Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / utilities / Snoopy / patches.c
blobd0d6fbe420ee7c0e6fbd496e759989d181af1d0f
1 /*
2 Copyright © 2006-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
8 #include <aros/debug.h>
9 #include <proto/dos.h>
10 #include <proto/exec.h>
11 #include <proto/icon.h>
12 #include <proto/intuition.h>
13 #include <proto/graphics.h>
15 #include <dos/filesystem.h>
17 #include "main.h"
18 #include "patches.h"
19 #include "setup.h"
20 #include "locale.h"
23 #define MAX_LOCK_LEN 100 /* Max. length of a lock string */
24 #define MAX_STR_LEN 200 /* Max. string length for misc stuff */
26 #define MAX(x,y) ((x) > (y) ? (x) : (y))
27 #define MIN(x,y) ((x) < (y) ? (x) : (y))
29 // dos.library
30 #define LVO_CreateDir ( -20 * LIB_VECTSIZE)
31 #define LVO_CurrentDir ( -21 * LIB_VECTSIZE)
32 #define LVO_DeleteFile ( -12 * LIB_VECTSIZE)
33 #define LVO_DeleteVar ( -152 * LIB_VECTSIZE)
34 #define LVO_Execute ( -37 * LIB_VECTSIZE)
35 #define LVO_FindVar ( -153 * LIB_VECTSIZE)
36 #define LVO_GetVar ( -151 * LIB_VECTSIZE)
37 #define LVO_LoadSeg ( -25 * LIB_VECTSIZE)
38 #define LVO_Lock ( -14 * LIB_VECTSIZE)
39 #define LVO_MakeLink ( -74 * LIB_VECTSIZE)
40 #define LVO_NewLoadSeg ( -128 * LIB_VECTSIZE)
41 #define LVO_Open ( -5 * LIB_VECTSIZE)
42 #define LVO_Rename ( -13 * LIB_VECTSIZE)
43 #define LVO_RunCommand ( -84 * LIB_VECTSIZE)
44 #define LVO_SetVar ( -150 * LIB_VECTSIZE)
45 #define LVO_SystemTagList ( -101 * LIB_VECTSIZE)
47 // exec.library
48 #define LVO_FindPort ( -65 * LIB_VECTSIZE)
49 #define LVO_FindResident ( -16 * LIB_VECTSIZE)
50 #define LVO_FindSemaphore ( -99 * LIB_VECTSIZE)
51 #define LVO_FindTask ( -49 * LIB_VECTSIZE)
52 #define LVO_OpenDevice ( -74 * LIB_VECTSIZE)
53 #define LVO_OpenLibrary ( -92 * LIB_VECTSIZE)
54 #define LVO_OpenResource ( -83 * LIB_VECTSIZE)
56 // intuition.library
57 #define LVO_LockPubScreen ( -85 * LIB_VECTSIZE)
59 // graphics.library
60 #define LVO_OpenFont ( -12 * LIB_VECTSIZE)
62 // icon.library
63 #define LVO_FindToolType ( -16 * LIB_VECTSIZE)
64 #define LVO_MatchToolValue ( -17 * LIB_VECTSIZE)
66 struct Library *libbases[LIB_last];
68 typedef LONG (*FP)();
70 struct Patches
72 LONG (*oldfunc)();
73 LONG (*newfunc)();
74 LONG libidx;
75 struct Library *lib;
76 LONG lvo;
77 BOOL enabled;
78 } patches[PATCH_last] =
80 // must be in same order as in enum in patches.h
81 {NULL, NULL, LIB_Dos, 0, LVO_CreateDir, FALSE},
82 {NULL, NULL, LIB_Dos, 0, LVO_CurrentDir, FALSE},
83 {NULL, NULL, LIB_Dos, 0, LVO_DeleteFile, FALSE},
84 {NULL, NULL, LIB_Dos, 0, LVO_DeleteVar, FALSE},
85 {NULL, NULL, LIB_Dos, 0, LVO_Execute, FALSE},
86 {NULL, NULL, LIB_Dos, 0, LVO_FindVar, FALSE},
87 {NULL, NULL, LIB_Dos, 0, LVO_GetVar, FALSE},
88 {NULL, NULL, LIB_Dos, 0, LVO_LoadSeg, FALSE},
89 {NULL, NULL, LIB_Dos, 0, LVO_Lock, FALSE},
90 {NULL, NULL, LIB_Dos, 0, LVO_MakeLink, FALSE},
91 {NULL, NULL, LIB_Dos, 0, LVO_NewLoadSeg, FALSE},
92 {NULL, NULL, LIB_Dos, 0, LVO_Open, FALSE},
93 {NULL, NULL, LIB_Dos, 0, LVO_Rename, FALSE},
94 {NULL, NULL, LIB_Dos, 0, LVO_RunCommand, FALSE},
95 {NULL, NULL, LIB_Dos, 0, LVO_SetVar, FALSE},
96 {NULL, NULL, LIB_Dos, 0, LVO_SystemTagList, FALSE},
97 {NULL, NULL, LIB_Exec, 0, LVO_FindPort, FALSE},
98 {NULL, NULL, LIB_Exec, 0, LVO_FindResident, FALSE},
99 {NULL, NULL, LIB_Exec, 0, LVO_FindSemaphore, FALSE},
100 {NULL, NULL, LIB_Exec, 0, LVO_FindTask, FALSE},
101 {NULL, NULL, LIB_Exec, 0, LVO_OpenDevice, FALSE},
102 {NULL, NULL, LIB_Exec, 0, LVO_OpenLibrary, FALSE},
103 {NULL, NULL, LIB_Exec, 0, LVO_OpenResource, FALSE},
104 {NULL, NULL, LIB_Intuition, 0, LVO_LockPubScreen, FALSE},
105 {NULL, NULL, LIB_Graphics, 0, LVO_OpenFont, FALSE},
106 {NULL, NULL, LIB_Icon, 0, LVO_FindToolType, FALSE},
107 {NULL, NULL, LIB_Icon, 0, LVO_MatchToolValue, FALSE},
110 //static char *MyNameFromLock(BPTR lock, char *filename, char *buf, int maxlen);
111 //static void GetVolName(BPTR lock, char *buf, int maxlen);
113 // ----------------------------------------------------------------------------------
115 AROS_UFH2(BPTR, New_CreateDir,
116 AROS_UFHA(CONST_STRPTR, name, D1),
117 AROS_UFHA(APTR, libbase, A6)
120 AROS_USERFUNC_INIT
122 // result is exclusive lock or NULL
123 BPTR result = AROS_UFC2(BPTR, patches[PATCH_CreateDir].oldfunc,
124 AROS_UFCA(CONST_STRPTR, name, D1),
125 AROS_UFCA(APTR, libbase, A6));
127 if (patches[PATCH_CreateDir].enabled)
129 main_output("CreateDir", name, 0, (LONG)result, TRUE);
132 return result;
134 AROS_USERFUNC_EXIT
137 // ----------------------------------------------------------------------------------
139 AROS_UFH2(BPTR, New_CurrentDir,
140 AROS_UFHA(BPTR, lock, D1),
141 AROS_UFHA(APTR, libbase, A6))
143 AROS_USERFUNC_INIT
144 //char lockbuf[MAX_LOCK_LEN+1];
145 char *lockpath = "?";
147 // returns lock to old directory, 0 means boot filesystem
148 BPTR result = AROS_UFC2(BPTR, patches[PATCH_CurrentDir].oldfunc,
149 AROS_UFCA(BPTR, lock, D1),
150 AROS_UFCA(APTR, libbase, A6));
152 if (patches[PATCH_CurrentDir].enabled)
154 LONG err = IoErr();
155 struct FileInfoBlock *fib = NULL;
156 if (lock)
158 fib = AllocDosObject(DOS_FIB, NULL);
159 if (fib)
161 if (Examine(lock, fib))
163 lockpath = fib->fib_FileName;
167 main_output("CurrentDir", lockpath, 0, TRUE, TRUE);
169 if (fib) FreeDosObject(DOS_FIB, fib);
170 SetIoErr(err);
173 return result;
175 AROS_USERFUNC_EXIT
178 // ----------------------------------------------------------------------------------
180 AROS_UFH2(BOOL, New_DeleteFile,
181 AROS_UFHA(CONST_STRPTR, name, D1),
182 AROS_UFHA(APTR, libbase, A6))
184 AROS_USERFUNC_INIT
186 // true means deleting was OK
187 BOOL result = AROS_UFC2(BOOL, patches[PATCH_DeleteFile].oldfunc,
188 AROS_UFCA(CONST_STRPTR, name, D1),
189 AROS_UFCA(APTR, libbase, A6));
191 if (patches[PATCH_DeleteFile].enabled)
193 main_output("Delete", name, 0, result, TRUE);
196 return result;
198 AROS_USERFUNC_EXIT
201 // ----------------------------------------------------------------------------------
203 AROS_UFH3(LONG, New_DeleteVar,
204 AROS_UFHA(CONST_STRPTR, name, D1),
205 AROS_UFHA(ULONG , flags, D2),
206 AROS_UFHA(APTR, libbase, A6))
208 AROS_USERFUNC_INIT
210 // true means variable was deleted
211 LONG result = AROS_UFC3(LONG, patches[PATCH_DeleteVar].oldfunc,
212 AROS_UFCA(CONST_STRPTR, name, D1),
213 AROS_UFCA(ULONG , flags, D2),
214 AROS_UFCA(APTR, libbase, A6));
216 if (patches[PATCH_DeleteVar].enabled)
218 CONST_STRPTR opt;
219 if (flags & GVF_GLOBAL_ONLY) opt = MSG(MSG_GLOBAL);
220 else if ((flags & 7) == LV_VAR) opt = MSG(MSG_LOCAL);
221 else if ((flags & 7) == LV_ALIAS) opt = MSG(MSG_ALIAS);
222 else opt = MSG(MSG_UNKNOWN);
224 main_output("DeleteVar", name, opt, result, TRUE);
227 return result;
229 AROS_USERFUNC_EXIT
232 // ----------------------------------------------------------------------------------
234 AROS_UFH4(LONG, New_Execute,
235 AROS_UFHA(STRPTR, string, D1),
236 AROS_UFHA(BPTR, input , D2),
237 AROS_UFHA(BPTR, output, D3),
238 AROS_UFHA(APTR, libbase, A6))
240 AROS_USERFUNC_INIT
242 // true means command could be started
243 LONG result = AROS_UFC4(LONG, patches[PATCH_Execute].oldfunc,
244 AROS_UFCA(STRPTR, string, D1),
245 AROS_UFCA(BPTR, input , D2),
246 AROS_UFCA(BPTR, output, D3),
247 AROS_UFCA(APTR, libbase, A6));
249 if (patches[PATCH_Execute].enabled)
251 main_output("Execute", string ,0 , result, TRUE);
254 return result;
256 AROS_USERFUNC_EXIT
259 // ----------------------------------------------------------------------------------
261 AROS_UFH3(struct LocalVar *, New_FindVar,
262 AROS_UFHA(CONST_STRPTR, name, D1),
263 AROS_UFHA(ULONG, type, D2),
264 AROS_UFHA(APTR, libbase, A6))
266 AROS_USERFUNC_INIT
268 // NULL means variable not found
269 struct LocalVar *result = AROS_UFC3(struct LocalVar *, patches[PATCH_FindVar].oldfunc,
270 AROS_UFCA(CONST_STRPTR, name, D1),
271 AROS_UFCA(ULONG, type, D2),
272 AROS_UFCA(APTR, libbase, A6));
274 if (patches[PATCH_FindVar].enabled)
276 CONST_STRPTR opt;
277 if ((type & 7) == LV_VAR) opt = MSG(MSG_LOCAL);
278 else if ((type & 7) == LV_ALIAS) opt = MSG(MSG_ALIAS);
279 else opt = MSG(MSG_UNKNOWN);
281 main_output("FindVar", name, opt, (LONG)result, TRUE);
284 return result;
286 AROS_USERFUNC_EXIT
289 // ----------------------------------------------------------------------------------
291 AROS_UFH5(LONG, New_GetVar,
292 AROS_UFHA(CONST_STRPTR, name, D1),
293 AROS_UFHA(STRPTR, buffer, D2),
294 AROS_UFHA(LONG, size, D3),
295 AROS_UFHA(LONG, flags, D4),
296 AROS_UFHA(APTR, libbase, A6))
298 AROS_USERFUNC_INIT
300 // -1 means variable not defined
301 LONG result = AROS_UFC5(LONG, patches[PATCH_GetVar].oldfunc,
302 AROS_UFCA(CONST_STRPTR, name, D1),
303 AROS_UFCA(STRPTR, buffer, D2),
304 AROS_UFCA(LONG, size, D3),
305 AROS_UFCA(LONG, flags, D4),
306 AROS_UFCA(APTR, libbase, A6));
308 if (patches[PATCH_GetVar].enabled)
310 CONST_STRPTR opt;
311 if (flags & GVF_GLOBAL_ONLY) opt = MSG(MSG_GLOBAL);
312 else if ((flags & 7) == LV_ALIAS) opt = MSG(MSG_ALIAS);
313 else if (flags & GVF_LOCAL_ONLY) opt = MSG(MSG_LOCAL);
314 else opt = MSG(MSG_ANY);
316 main_output("GetVar", name, opt, result != -1, TRUE);
319 return result;
321 AROS_USERFUNC_EXIT
324 // ----------------------------------------------------------------------------------
326 AROS_UFH2(BPTR, New_LoadSeg,
327 AROS_UFHA(CONST_STRPTR, name, D1),
328 AROS_UFHA(APTR, libbase, A6))
330 AROS_USERFUNC_INIT
332 // 0 means load failed
333 BPTR result = AROS_UFC2(BPTR, patches[PATCH_LoadSeg].oldfunc,
334 AROS_UFCA(CONST_STRPTR, name, D1),
335 AROS_UFCA(APTR, libbase, A6));
337 if (patches[PATCH_LoadSeg].enabled)
339 main_output("LoadSeg", name, 0, (LONG)result, TRUE);
342 return result;
344 AROS_USERFUNC_EXIT
347 // ----------------------------------------------------------------------------------
349 AROS_UFH3(BPTR, New_Lock,
350 AROS_UFHA(CONST_STRPTR, name, D1),
351 AROS_UFHA(LONG, accessMode, D2),
352 AROS_UFHA(APTR, libbase, A6))
354 AROS_USERFUNC_INIT
356 // 0 means error
357 BPTR result = AROS_UFC3(BPTR, patches[PATCH_Lock].oldfunc,
358 AROS_UFCA(CONST_STRPTR, name, D1),
359 AROS_UFCA(LONG, accessMode, D2),
360 AROS_UFCA(APTR, libbase, A6));
362 if (patches[PATCH_Lock].enabled)
364 CONST_STRPTR opt;
365 if (accessMode == ACCESS_READ) opt = MSG(MSG_READ);
366 else if (accessMode == ACCESS_WRITE) opt = MSG(MSG_WRITE);
367 else opt = MSG(MSG_READ_ASK);
369 CONST_STRPTR curname = name;
370 if ( ! curname)
372 curname="NULL";
374 else if ( ! setup.showPaths && *curname == '\0')
376 curname = "\"\"";
379 main_output("Lock", curname, opt, (LONG)result, TRUE);
382 return result;
384 AROS_USERFUNC_EXIT
387 // ----------------------------------------------------------------------------------
389 AROS_UFH4(LONG, New_MakeLink,
390 AROS_UFHA(STRPTR, name, D1),
391 AROS_UFHA(APTR, dest, D2),
392 AROS_UFHA(LONG, soft, D3),
393 AROS_UFHA(APTR, libbase, A6))
395 AROS_USERFUNC_INIT
397 // result is boolean
398 LONG result = AROS_UFC4(LONG, patches[PATCH_MakeLink].oldfunc,
399 AROS_UFCA(STRPTR, name, D1),
400 AROS_UFCA(APTR, dest, D2),
401 AROS_UFCA(LONG, soft, D3),
402 AROS_UFCA(APTR, libbase, A6));
404 if (patches[PATCH_MakeLink].enabled)
406 //struct Process *myproc = (struct Process *)SysBase->ThisTask;
408 CONST_STRPTR opt;
409 if (soft) opt = "Softlink";
410 else opt = "Hardlink";
412 //FIXME: MyNameFromLock crashes
413 #if 0
415 int len = strlen(name);
416 char namestr[MAX_STR_LEN + 1];
417 if (len >= MAX_STR_LEN) {
418 strncpy(namestr, name, MAX_STR_LEN);
419 namestr[MAX_STR_LEN] = 0;
420 } else {
421 if (setup.showPaths) {
422 strcpy(namestr, MyNameFromLock(myproc->pr_CurrentDir,
423 name, namestr, MAX_STR_LEN-2));
424 len = strlen(namestr);
425 } else
426 strcpy(namestr, name);
428 strcat(namestr, " --> ");
429 if (soft) {
430 strncat(namestr, (char *)dest, MAX_STR_LEN - len - 1);
431 namestr[MAX_STR_LEN] = 0;
432 } else {
433 strcat(namestr, MyNameFromLock((BPTR)dest, NULL, namestr+len+1,
434 MAX_STR_LEN-len-1));
437 #endif
438 main_output("MakeLink", name /*namestr */, opt, result, TRUE);
441 return result;
443 AROS_USERFUNC_EXIT
446 // ----------------------------------------------------------------------------------
448 AROS_UFH3(BPTR, New_NewLoadSeg,
449 AROS_UFHA(STRPTR, file, D1),
450 AROS_UFHA(struct TagItem *, tags, D2),
451 AROS_UFHA(APTR, libbase, A6))
453 AROS_USERFUNC_INIT
455 // 0 means load failed
456 BPTR result = AROS_UFC3(BPTR, patches[PATCH_NewLoadSeg].oldfunc,
457 AROS_UFCA(STRPTR, file, D1),
458 AROS_UFCA(struct TagItem *, tags, D2),
459 AROS_UFCA(APTR, libbase, A6));
461 if (patches[PATCH_NewLoadSeg].enabled)
463 main_output("NewLoadSeg", file, 0, (LONG)result, TRUE);
466 return result;
468 AROS_USERFUNC_EXIT
471 // ----------------------------------------------------------------------------------
473 AROS_UFH3 (BPTR, New_Open,
474 AROS_UFHA (CONST_STRPTR, name, D1),
475 AROS_UFHA (LONG, accessMode, D2),
476 AROS_UFHA (APTR, libbase, A6))
479 AROS_USERFUNC_INIT
481 // 0 means error
482 BPTR result = AROS_UFC3(BPTR, patches[PATCH_Open].oldfunc,
483 AROS_UFCA (CONST_STRPTR, name, D1),
484 AROS_UFCA (LONG, accessMode, D2),
485 AROS_UFCA (APTR, libbase, A6));
487 if (patches[PATCH_Open].enabled)
489 CONST_STRPTR opt = NULL;
490 char optstr[10];
491 if (accessMode == MODE_OLDFILE) opt = MSG(MSG_READ);
492 else if (accessMode == MODE_NEWFILE) opt = MSG(MSG_WRITE);
493 else if (accessMode == MODE_READWRITE) opt = MSG(MSG_MODIFY);
494 else if (accessMode & (FMF_READ|FMF_WRITE|FMF_APPEND|FMF_CREATE))
496 sprintf(optstr, "FMF %c%c%c%c",
497 (accessMode & FMF_READ) ? 'R' : '_',
498 (accessMode & FMF_WRITE) ? 'W' : '_',
499 (accessMode & FMF_APPEND) ? 'A' : '_',
500 (accessMode & FMF_CREATE) ? 'C' : '_');
502 else opt = MSG(MSG_UNKNOWN);
504 main_output("Open", name, opt ? opt : (STRPTR)optstr, (LONG)result, TRUE);
507 return result;
509 AROS_USERFUNC_EXIT
512 // ----------------------------------------------------------------------------------
514 AROS_UFH3(LONG, New_Rename,
515 AROS_UFHA(CONST_STRPTR, oldName, D1),
516 AROS_UFHA(CONST_STRPTR, newName, D2),
517 AROS_UFHA(APTR, libbase, A6))
519 AROS_USERFUNC_INIT
521 // bool
522 LONG result = AROS_UFC3(LONG, patches[PATCH_Rename].oldfunc,
523 AROS_UFCA(CONST_STRPTR, oldName, D1),
524 AROS_UFCA(CONST_STRPTR, newName, D2),
525 AROS_UFCA(APTR, libbase, A6));
527 if (patches[PATCH_Rename].enabled)
529 main_output("Rename", oldName, 0, result, FALSE);
530 main_output("to -->", newName, 0, result, TRUE);
533 return result;
535 AROS_USERFUNC_EXIT
538 // ----------------------------------------------------------------------------------
540 AROS_UFH5(LONG, New_RunCommand,
541 AROS_UFHA(BPTR, segList, D1),
542 AROS_UFHA(ULONG, stacksize, D2),
543 AROS_UFHA(STRPTR, argptr, D3),
544 AROS_UFHA(ULONG, argsize, D4),
545 AROS_UFHA(APTR, libbase, A6))
547 AROS_USERFUNC_INIT
549 // -1 means error
550 LONG result = AROS_UFC5(LONG, patches[PATCH_RunCommand].oldfunc,
551 AROS_UFCA(BPTR, segList, D1),
552 AROS_UFCA(ULONG, stacksize, D2),
553 AROS_UFCA(STRPTR, argptr, D3),
554 AROS_UFCA(ULONG, argsize, D4),
555 AROS_UFCA(APTR, libbase, A6));
557 if (patches[PATCH_RunCommand].enabled)
559 char argstr[MAX_STR_LEN + 1];
560 int pos;
561 for (pos = 0; pos < MAX_STR_LEN && argptr[pos] != 0 ; pos++)
563 if (argptr[pos] == '\n')
564 argstr[pos] = ' ';
565 else
566 argstr[pos] = argptr[pos];
569 argstr[pos] = 0;
570 main_output("RunCommand", argstr, 0, result != -1, TRUE);
573 return result;
575 AROS_USERFUNC_EXIT
578 // ----------------------------------------------------------------------------------
580 AROS_UFH5(BOOL, New_SetVar,
581 AROS_UFHA(CONST_STRPTR, name, D1),
582 AROS_UFHA(CONST_STRPTR, buffer, D2),
583 AROS_UFHA(LONG, size, D3),
584 AROS_UFHA(LONG, flags, D4),
585 AROS_UFHA(void*, libbase, A6))
587 AROS_USERFUNC_INIT
589 BOOL result = AROS_UFC5(BOOL, patches[PATCH_SetVar].oldfunc,
590 AROS_UFCA(CONST_STRPTR, name, D1),
591 AROS_UFCA(CONST_STRPTR, buffer, D2),
592 AROS_UFCA(LONG, size, D3),
593 AROS_UFCA(LONG, flags, D4),
594 AROS_UFCA(void*, libbase, A6));
596 if (patches[PATCH_SetVar].enabled)
598 CONST_STRPTR opt;
599 char varstr[MAX_STR_LEN + 1];
600 int vlen;
602 if (flags & GVF_GLOBAL_ONLY) opt = MSG(MSG_GLOBAL);
603 else if ((flags & 7) == LV_VAR) opt = MSG(MSG_LOCAL);
604 else if ((flags & 7) == LV_ALIAS) opt = MSG(MSG_ALIAS);
605 else opt = MSG(MSG_UNKNOWN);
608 * Now create a string that looks like "Variable=Value"
610 * We go to some pains to ensure we don't overwrite our
611 * string length
613 vlen = strlen(name);
614 if (vlen > (MAX_STR_LEN-1)) {
615 strncpy(varstr, name, MAX_STR_LEN);
616 varstr[MAX_STR_LEN] = 0;
617 } else {
618 strcpy(varstr, name);
619 strcat(varstr, "=");
620 vlen = 98 - vlen;
621 if (size != -1)
622 vlen = MIN(vlen, size);
624 strncat(varstr, buffer, vlen);
625 varstr[MAX_STR_LEN] = 0;
627 main_output("SetVar", varstr, opt, result, TRUE);
630 return result;
632 AROS_USERFUNC_EXIT
635 // ----------------------------------------------------------------------------------
637 AROS_UFH3(LONG, New_SystemTagList,
638 AROS_UFHA(CONST_STRPTR, command, D1),
639 AROS_UFHA(struct TagItem *, tags, D2),
640 AROS_UFHA(APTR, libbase, A6))
642 AROS_USERFUNC_INIT
644 // -1 means error
645 LONG result = AROS_UFC3(LONG, patches[PATCH_SystemTagList].oldfunc,
646 AROS_UFCA(CONST_STRPTR, command, D1),
647 AROS_UFCA(struct TagItem *, tags, D2),
648 AROS_UFCA(APTR, libbase, A6));
650 if (patches[PATCH_SystemTagList].enabled)
652 char optstr[20];
653 sprintf(optstr, "%d", result);
654 main_output("SystemTagList", command, optstr, result != -1, TRUE);
657 return result;
659 AROS_USERFUNC_EXIT
662 // ----------------------------------------------------------------------------------
664 AROS_UFH2(struct MsgPort *, New_FindPort,
665 AROS_UFHA(STRPTR, name, A1),
666 AROS_UFHA(APTR, libbase, A6))
668 AROS_USERFUNC_INIT
670 // NULL means error
671 struct MsgPort *result = AROS_UFC2(struct MsgPort *, patches[PATCH_FindPort].oldfunc,
672 AROS_UFCA(STRPTR, name, A1),
673 AROS_UFCA(APTR, libbase, A6));
675 if (patches[PATCH_FindPort].enabled)
677 main_output("FindPort", name, 0, (LONG)result, TRUE);
680 return result;
682 AROS_USERFUNC_EXIT
685 // ----------------------------------------------------------------------------------
687 AROS_UFH2(struct Resident *, New_FindResident,
688 AROS_UFHA(const UBYTE *, name, A1),
689 AROS_UFHA(APTR, libbase, A6))
691 AROS_USERFUNC_INIT
693 // NULL means error
694 struct Resident *result = AROS_UFC2(struct Resident *, patches[PATCH_FindResident].oldfunc,
695 AROS_UFCA(const UBYTE *, name, A1),
696 AROS_UFCA(APTR, libbase, A6));
698 if (patches[PATCH_FindResident].enabled)
700 main_output("FindResident", name, 0, (LONG)result, TRUE);
703 return result;
705 AROS_USERFUNC_EXIT
708 // ----------------------------------------------------------------------------------
710 AROS_UFH2(struct SignalSemaphore *, New_FindSemaphore,
711 AROS_UFHA(STRPTR, name, A1),
712 AROS_UFHA(APTR, libbase, A6))
714 AROS_USERFUNC_INIT
716 // NULL means error
717 struct SignalSemaphore *result = AROS_UFC2(struct SignalSemaphore *, patches[PATCH_FindSemaphore].oldfunc,
718 AROS_UFCA(STRPTR, name, A1),
719 AROS_UFCA(APTR, libbase, A6));
721 if (patches[PATCH_FindSemaphore].enabled)
723 main_output("FindSemaphore", name, 0, (LONG)result, TRUE);
726 return result;
728 AROS_USERFUNC_EXIT
731 // ----------------------------------------------------------------------------------
733 AROS_UFH2(struct Task *, New_FindTask,
734 AROS_UFHA(STRPTR, name, A1),
735 AROS_UFHA(APTR, libbase, A6))
737 AROS_USERFUNC_INIT
739 // NULL means error
740 struct Task *result = AROS_UFC2(struct Task *, patches[PATCH_FindTask].oldfunc,
741 AROS_UFCA(STRPTR, name, A1),
742 AROS_UFCA(APTR, libbase, A6));
744 if (patches[PATCH_FindTask].enabled)
746 main_output("FindTask", name, 0, (LONG)result, TRUE);
749 return result;
751 AROS_USERFUNC_EXIT
754 // ----------------------------------------------------------------------------------
756 AROS_UFH5(BYTE, New_OpenDevice,
757 AROS_UFHA(CONST_STRPTR, devName, A0),
758 AROS_UFHA(ULONG, unitNumber, D0),
759 AROS_UFHA(struct IORequest *, iORequest, A1),
760 AROS_UFHA(ULONG, flags, D1),
761 AROS_UFHA(APTR, libbase, A6))
763 AROS_USERFUNC_INIT
765 // 0 means OK
766 BYTE result = AROS_UFC5(BYTE, patches[PATCH_OpenDevice].oldfunc,
767 AROS_UFCA(CONST_STRPTR, devName, A0),
768 AROS_UFCA(ULONG, unitNumber, D0),
769 AROS_UFCA(struct IORequest *, iORequest, A1),
770 AROS_UFCA(ULONG, flags, D1),
771 AROS_UFCA(APTR, libbase, A6));
773 if (patches[PATCH_OpenDevice].enabled)
775 char unitstr[20];
776 sprintf(unitstr, "Unit %d", unitNumber);
777 main_output("OpenDevice", devName, unitstr, !result, TRUE);
780 return result;
782 AROS_USERFUNC_EXIT
785 // ----------------------------------------------------------------------------------
787 AROS_UFH3(struct Library *, New_OpenLibrary,
788 AROS_UFHA(CONST_STRPTR, libName, A1),
789 AROS_UFHA(ULONG, version, D0),
790 AROS_UFHA(APTR, libbase, A6))
792 AROS_USERFUNC_INIT
794 // 0 means error
795 struct Library *result = AROS_UFC3(struct Library *, patches[PATCH_OpenLibrary].oldfunc,
796 AROS_UFCA(CONST_STRPTR, libName, A1),
797 AROS_UFCA(ULONG, version, D0),
798 AROS_UFCA(APTR, libbase, A6));
800 if (patches[PATCH_OpenLibrary].enabled)
802 char verstr[20];
803 sprintf(verstr, MSG(MSG_VERSION), version);
804 main_output("OpenLibrary", libName, verstr, (LONG)result, TRUE);
807 return result;
809 AROS_USERFUNC_EXIT
812 // ----------------------------------------------------------------------------------
814 AROS_UFH2(APTR, New_OpenResource,
815 AROS_UFHA(CONST_STRPTR, resName, A1),
816 AROS_UFHA(APTR, libbase, A6))
818 AROS_USERFUNC_INIT
820 // 0 means error
821 APTR result = AROS_UFC2(APTR, patches[PATCH_OpenResource].oldfunc,
822 AROS_UFCA(CONST_STRPTR, resName, A1),
823 AROS_UFCA(APTR, libbase, A6));
825 if (patches[PATCH_OpenResource].enabled)
827 main_output("OpenLibrary", resName, 0, (LONG)result, TRUE);
830 return result;
832 AROS_USERFUNC_EXIT
835 // ----------------------------------------------------------------------------------
837 AROS_UFH2(struct Screen *, New_LockPubScreen,
838 AROS_UFHA(CONST_STRPTR, name, A0),
839 AROS_UFHA(APTR, libbase, A6))
841 AROS_USERFUNC_INIT
843 // 0 means error
844 struct Screen *result = AROS_UFC2(struct Screen *, patches[PATCH_LockPubScreen].oldfunc,
845 AROS_UFCA(CONST_STRPTR, name, A0),
846 AROS_UFCA(APTR, libbase, A6));
848 if (patches[PATCH_LockPubScreen].enabled)
850 main_output("LockPubScreen", name, 0, (LONG)result, TRUE);
853 return result;
855 AROS_USERFUNC_EXIT
858 // ----------------------------------------------------------------------------------
860 AROS_UFH2(struct TextFont *, New_OpenFont,
861 AROS_UFHA(struct TextAttr *, textAttr, A0),
862 AROS_UFHA(APTR, libbase, A6))
864 AROS_USERFUNC_INIT
866 // 0 means error
867 struct TextFont *result = AROS_UFC2(struct TextFont *, patches[PATCH_OpenFont].oldfunc,
868 AROS_UFCA(struct TextAttr *, textAttr, A0),
869 AROS_UFCA(APTR, libbase, A6));
871 if (patches[PATCH_OpenFont].enabled)
873 char *name;
874 char sizestr[20];
876 if (textAttr) {
877 sprintf(sizestr, MSG(MSG_SIZE), textAttr->ta_YSize);
878 name = textAttr->ta_Name;
879 } else {
880 *sizestr = '\0';
881 name = "\"\"";
883 main_output("OpenFont", name, sizestr, (LONG)result, TRUE);
886 return result;
888 AROS_USERFUNC_EXIT
891 // ----------------------------------------------------------------------------------
893 AROS_UFH3(UBYTE *, New_FindToolType,
894 AROS_UFHA(CONST STRPTR *, toolTypeArray, A0),
895 AROS_UFHA(CONST STRPTR, typeName, A1),
896 AROS_UFHA(APTR, libbase, A6))
898 AROS_USERFUNC_INIT
900 // 0 means error
901 UBYTE *result = AROS_UFC3(UBYTE *, patches[PATCH_FindToolType].oldfunc,
902 AROS_UFCA(CONST STRPTR *, toolTypeArray, A0),
903 AROS_UFCA(CONST STRPTR, typeName, A1),
904 AROS_UFCA(APTR, libbase, A6));
906 if (patches[PATCH_FindToolType].enabled)
908 main_output("FindToolType", typeName, 0, (LONG)result, TRUE);
911 return result;
913 AROS_USERFUNC_EXIT
916 // ----------------------------------------------------------------------------------
918 AROS_UFH3(BOOL, New_MatchToolValue,
919 AROS_UFHA(UBYTE *, typeString, A0),
920 AROS_UFHA(UBYTE *, value, A1),
921 AROS_UFHA(APTR, libbase, A6))
923 AROS_USERFUNC_INIT
925 BOOL result = AROS_UFC3(BOOL, patches[PATCH_MatchToolValue].oldfunc,
926 AROS_UFCA(UBYTE *, typeString, A0),
927 AROS_UFCA(UBYTE *, value, A1),
928 AROS_UFCA(APTR, libbase, A6));
930 if (patches[PATCH_MatchToolValue].enabled)
932 main_output("MatchToolValue", typeString, value, result, TRUE);
935 return result;
937 AROS_USERFUNC_EXIT
940 // ----------------------------------------------------------------------------------
942 void patches_init(void)
944 libbases[LIB_Exec] = (struct Library*)SysBase;
945 libbases[LIB_Dos] = (struct Library*)DOSBase;
946 libbases[LIB_Icon] = IconBase;
947 libbases[LIB_Intuition] = (struct Library*)IntuitionBase;
948 libbases[LIB_Graphics] = (struct Library*)GfxBase;
950 patches[PATCH_CreateDir].newfunc = (FP)&New_CreateDir;
951 patches[PATCH_CurrentDir].newfunc = (FP)&New_CurrentDir;
952 patches[PATCH_DeleteFile].newfunc = (FP)&New_DeleteFile;
953 patches[PATCH_DeleteVar].newfunc = (FP)&New_DeleteVar;
954 patches[PATCH_Execute].newfunc = (FP)&New_Execute;
955 patches[PATCH_FindVar].newfunc = (FP)&New_FindVar;
956 patches[PATCH_GetVar].newfunc = (FP)&New_GetVar;
957 patches[PATCH_LoadSeg].newfunc = (FP)&New_LoadSeg;
958 patches[PATCH_Lock].newfunc = (FP)&New_Lock;
959 patches[PATCH_MakeLink].newfunc = (FP)&New_MakeLink;
960 patches[PATCH_NewLoadSeg].newfunc = (FP)&New_NewLoadSeg;
961 patches[PATCH_Open].newfunc = (FP)&New_Open;
962 patches[PATCH_Rename].newfunc = (FP)&New_Rename;
963 patches[PATCH_RunCommand].newfunc = (FP)&New_RunCommand;
964 patches[PATCH_SetVar].newfunc = (FP)&New_SetVar;
965 patches[PATCH_SystemTagList].newfunc = (FP)&New_SystemTagList;
966 patches[PATCH_FindPort].newfunc = (FP)&New_FindPort;
967 patches[PATCH_FindResident].newfunc = (FP)&New_FindResident;
968 patches[PATCH_FindSemaphore].newfunc = (FP)&New_FindSemaphore;
969 patches[PATCH_FindTask].newfunc = (FP)&New_FindTask;
970 patches[PATCH_OpenDevice].newfunc = (FP)&New_OpenDevice;
971 patches[PATCH_OpenLibrary].newfunc = (FP)&New_OpenLibrary;
972 patches[PATCH_OpenResource].newfunc = (FP)&New_OpenResource;
973 patches[PATCH_LockPubScreen].newfunc = (FP)&New_LockPubScreen;
974 patches[PATCH_OpenFont].newfunc = (FP)&New_OpenFont;
975 patches[PATCH_FindToolType].newfunc = (FP)&New_FindToolType;
976 patches[PATCH_MatchToolValue].newfunc = (FP)&New_MatchToolValue;
978 patches_set();
980 int i;
981 for (i=0; i<PATCH_last; i++)
983 if (patches[i].newfunc);
985 Forbid();
986 patches[i].oldfunc = SetFunction(libbases[patches[i].libidx], patches[i].lvo, patches[i].newfunc);
987 Permit();
992 // ----------------------------------------------------------------------------------
994 void patches_set(void)
996 patches[PATCH_CreateDir].enabled = setup.enableMakeDir;
997 patches[PATCH_CurrentDir].enabled = setup.enableChangeDir;
998 patches[PATCH_DeleteFile].enabled = setup.enableDelete;
999 patches[PATCH_DeleteVar].enabled = setup.enableSetVar;
1000 patches[PATCH_Execute].enabled = setup.enableExecute;
1001 patches[PATCH_FindVar].enabled = setup.enableGetVar;
1002 patches[PATCH_GetVar].enabled = setup.enableGetVar;
1003 patches[PATCH_LoadSeg].enabled = setup.enableLoadSeg;
1004 patches[PATCH_Lock].enabled = setup.enableLock;
1005 patches[PATCH_MakeLink].enabled = setup.enableMakeLink;
1006 patches[PATCH_NewLoadSeg].enabled = setup.enableLoadSeg;
1007 patches[PATCH_Open].enabled = setup.enableOpen;
1008 patches[PATCH_Rename].enabled = setup.enableRename;
1009 patches[PATCH_RunCommand].enabled = setup.enableRunCommand;
1010 patches[PATCH_SetVar].enabled = setup.enableSetVar;
1011 patches[PATCH_SystemTagList].enabled = setup.enableSystem;
1012 patches[PATCH_FindPort].enabled = setup.enableFindPort;
1013 patches[PATCH_FindResident].enabled = setup.enableFindResident;
1014 patches[PATCH_FindSemaphore].enabled = setup.enableFindSemaphore;
1015 patches[PATCH_FindTask].enabled = setup.enableFindTask;
1016 patches[PATCH_OpenDevice].enabled = setup.enableOpenDevice;
1017 patches[PATCH_OpenLibrary].enabled = setup.enableOpenLibrary;
1018 patches[PATCH_OpenResource].enabled = setup.enableOpenResource;
1019 patches[PATCH_LockPubScreen].enabled = setup.enableLockScreen;
1020 patches[PATCH_OpenFont].enabled = setup.enableOpenFont;
1021 patches[PATCH_FindToolType].enabled = setup.enableReadToolTypes;
1022 patches[PATCH_MatchToolValue].enabled = setup.enableReadToolTypes;
1026 // ----------------------------------------------------------------------------------
1028 void patches_reset(void)
1030 int i;
1032 for (i=0; i<PATCH_last; i++)
1034 patches[i].enabled = FALSE;
1037 for (i=0; i<PATCH_last; i++)
1039 if (patches[i].oldfunc)
1041 Forbid();
1042 SetFunction(libbases[patches[i].libidx], patches[i].lvo, patches[i].oldfunc);
1043 Permit();
1044 patches[i].oldfunc = NULL;