update gcc 5 patch for 20150222 snapshot
[AROS.git] / rom / dos / shell_helper.c
blob50d3d8174e2c20980c048665f9ae6f6ff265c9b8
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include <utility/tagitem.h>
11 #include <dos/dostags.h>
12 #include <proto/utility.h>
13 #include <dos/dosextens.h>
14 #include <aros/asmcall.h>
15 #include <exec/ports.h>
17 #include "dos_intern.h"
19 #include <proto/dos.h>
21 static BPTR findseg_any(CONST_STRPTR res, CONST_STRPTR file, struct DosLibrary *DOSBase)
23 BPTR found = BNULL;
24 struct Segment *seg;
26 D(bug("[%s] Looking for shell %s (aka %s)\n", __func__, res, file));
28 Forbid();
29 seg = FindSegment(res, NULL, TRUE);
30 if (seg != NULL && seg->seg_UC <= 0) {
31 found = seg->seg_Seg;
32 D(bug("[%s] Found %s in DOS Resident list\n", __func__, res));
34 Permit();
36 /* Ok, *really* digging for it now.
38 if (!found) {
39 found = LoadSeg(file);
40 if (found) {
41 /* We're going to keep this around for a long while. */
42 D(bug("[%s] Found %s on disk\n", __func__, file));
43 AddSegment(res, found, CMD_SYSTEM);
44 } else {
45 D(bug("[%s] No such segment available\n", __func__));
49 return found;
52 BPTR findseg_cli(BOOL isBoot, struct DosLibrary *DOSBase)
54 BPTR seg = BNULL;
56 if (isBoot)
57 seg = DOSBase->dl_Root->rn_ConsoleSegment;
59 if (!seg) {
60 seg = findseg_any("CLI", "L:Shell-Seg", DOSBase);
61 if (seg)
62 DOSBase->dl_Root->rn_ConsoleSegment = seg;
65 return seg;
68 BPTR findseg_shell(BOOL isBoot, struct DosLibrary *DOSBase)
70 BPTR seg = BNULL;
72 if (isBoot)
73 seg = DOSBase->dl_Root->rn_ShellSegment;
75 if (!seg) {
76 seg = findseg_any("shell", "L:UserShell-Seg", DOSBase);
77 if (seg)
78 DOSBase->dl_Root->rn_ShellSegment = seg;
81 return seg;