2 Copyright (C) 1995-2010, The AROS Development Team. All rights reserved.
9 #include <aros/debug.h>
11 #include <exec/resident.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/utility.h> /* For Stricmp */
16 #include <aros/symbolsets.h>
17 #include <aros/shcommands.h>
19 #include "shellcommands_intern.h"
21 THIS_PROGRAM_HANDLES_SYMBOLSET(SHCOMMANDS
)
22 DECLARESET(SHCOMMANDS
)
24 #include LC_LIBDEFS_FILE
26 static int GM_UNIQUENAME(Init
)(LIBBASETYPEPTR LIBBASE
)
32 D(bug("[ShellCommands] Init\n"));
34 D(bug("[ShellCommands] shset = %p\n", SETNAME(SHCOMMANDS
)));
35 ForeachElementInSet(SETNAME(SHCOMMANDS
), 1, pos
, sh
) {
36 D(bug("[ShellCommands] SYSTEM:%s\n", sh
->sh_Name
));
40 D(bug("[ShellCommands] %d commands\n", pos
));
45 UtilityBase
= OpenLibrary("utility.library", 0);
46 if (UtilityBase
== NULL
) {
47 D(bug("[ShellCommands] Can't open utility.library?\n"));
51 DOSBase
= OpenLibrary("dos.library", 0);
52 if ( DOSBase
== NULL
) {
53 D(bug("[ShellCommands] What? No dos.library?\n"));
54 CloseLibrary(UtilityBase
);
58 LIBBASE
->sc_Commands
= pos
;
59 LIBBASE
->sc_Command
= AllocMem(sizeof(LIBBASE
->sc_Command
[0])*pos
, 0);
60 if (LIBBASE
->sc_Command
== NULL
) {
61 CloseLibrary(DOSBase
);
62 CloseLibrary(UtilityBase
);
66 ForeachElementInSet(SETNAME(SHCOMMANDS
), 1, pos
, sh
) {
67 struct ShellCommandSeg
*scs
= &LIBBASE
->sc_Command
[pos
-1];
69 scs
->scs_Size
= 0; // Must be 0 to prevent UnLoadSeg
70 scs
->scs_Next
= 0; // from killing us after CLI[1] exits
71 scs
->scs_Name
= sh
->sh_Name
;
72 __AROS_SET_FULLJMP(&scs
->scs_Code
, sh
->sh_Command
);
73 #ifdef __AROS_USE_FULLJMP
74 CacheClearE(&scs
->scs_Code
, sizeof(struct FullJumpVec
), CACRF_ClearI
| CACRF_ClearD
);
76 AddSegment(sh
->sh_Name
, MKBADDR(&scs
->scs_Next
), CMD_INTERNAL
);
77 if (Stricmp(sh
->sh_Name
, "NewShell") == 0)
78 AddSegment("NewCLI", MKBADDR(&scs
->scs_Next
), CMD_INTERNAL
);
81 CloseLibrary(UtilityBase
);
86 ADD2INITLIB(GM_UNIQUENAME(Init
), 0);