use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / shellcommands / shellcommands_init.c
blobd59fa0a21e947f5113bbd7404fbfaeba4e8f8c12
1 /*
2 Copyright (C) 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 The shell program.
6 */
8 #define DEBUG 0
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)
28 struct shcommand *sh;
29 APTR UtilityBase;
30 int pos;
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));
39 pos--;
40 D(bug("[ShellCommands] %d commands\n", pos));
42 if (pos <= 0)
43 return FALSE;
45 UtilityBase = OpenLibrary("utility.library", 0);
46 if (UtilityBase == NULL) {
47 D(bug("[ShellCommands] Can't open utility.library?\n"));
48 return FALSE;
51 DOSBase = OpenLibrary("dos.library", 0);
52 if ( DOSBase == NULL ) {
53 D(bug("[ShellCommands] What? No dos.library?\n"));
54 CloseLibrary(UtilityBase);
55 return FALSE;
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);
63 return FALSE;
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);
75 #endif
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);
83 return TRUE;
86 ADD2INITLIB(GM_UNIQUENAME(Init), 0);