prism2.device: Compiler delint
[AROS.git] / workbench / c / AROSMonDrvs.c
blobd45818e799ec86905d32aab8a26e738285c05af5
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code that loads and initializes necessary HIDDs.
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
12 #include <dos/dosextens.h>
13 #include <workbench/icon.h>
14 #include <proto/alib.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/icon.h>
19 #include <aros/shcommands.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #define MONITORS_DIR "DEVS:Monitors"
25 #define COMPOSITING_NAME "Compositor"
27 /************************************************************************/
29 /* This code does almost the same thing as C:LoadMonDrvs does on other systems.
30 However, additionally we support priority-based sorting for display drivers.
31 This is needed in order to make monitor ID assignment more predictable */
33 struct MonitorNode
35 struct Node n;
36 char Name[1];
39 static BYTE checkIcon(STRPTR name, struct Library *IconBase)
41 LONG pri = 0;
42 struct DiskObject *dobj = GetDiskObject(name);
44 if (dobj == NULL)
45 return 0;
47 if ((dobj->do_Type == WBTOOL) || (dobj->do_Type == WBPROJECT))
49 const STRPTR *toolarray = (const STRPTR *)dobj->do_ToolTypes;
50 STRPTR s;
52 if ((s = FindToolType(toolarray, "STARTPRI")))
54 pri = atol(s);
55 if (pri < -128)
56 pri = -128;
57 else if (pri > 127)
58 pri = 127;
60 FreeDiskObject(dobj);
62 return pri;
65 static BOOL findMonitors(struct List *monitorsList, struct DosLibrary *DOSBase, struct Library *IconBase, struct ExecBase *SysBase, APTR poolmem)
67 BOOL retvalue = TRUE;
68 LONG error;
69 struct AnchorPath *ap = AllocPooled(poolmem, sizeof(struct AnchorPath));
71 DB2(bug("[LoadMonDrvs] AnchorPath 0x%p\n", ap));
72 if (ap)
74 /* Initialize important fields in AnchorPath, especially
75 ap_Strlen (prevents memory trashing) */
76 ap->ap_Flags = 0;
77 ap->ap_Strlen = 0;
78 ap->ap_BreakBits = 0;
80 error = MatchFirst("~(#?.info)", ap);
81 while (!error)
83 struct MonitorNode *newnode;
85 DB2(bug("[LoadMonDrvs] Found monitor name %s\n", ap->ap_Info.fib_FileName));
87 /* Software composition driver was loaded before */
88 if (strcmp(ap->ap_Info.fib_FileName, COMPOSITING_NAME))
90 newnode = AllocPooled(poolmem, sizeof(struct MonitorNode) + strlen(ap->ap_Info.fib_FileName));
91 DB2(bug("[LoadMonDrvs] Monitor node 0x%p\n", newnode));
92 if (newnode == NULL)
94 retvalue = FALSE;
95 break;
98 strcpy(newnode->Name, ap->ap_Info.fib_FileName);
99 if (IconBase)
100 newnode->n.ln_Pri = checkIcon(ap->ap_Info.fib_FileName, IconBase);
101 else
102 newnode->n.ln_Pri = 0;
103 Enqueue(monitorsList, &newnode->n);
106 error = MatchNext(ap);
109 if (error != ERROR_NO_MORE_ENTRIES)
111 retvalue = FALSE;
112 /* FIXME: Why no MatchEnd() in this case?
113 goto exit; */
115 MatchEnd(ap);
117 else
118 retvalue = FALSE;
120 return retvalue;
123 static void loadMonitors(struct List *monitorsList, struct DosLibrary *DOSBase)
125 struct MonitorNode *node;
127 D(bug("[LoadMonDrvs] Loading monitor drivers...\n"));
128 D(bug(" Pri Name\n"));
130 ForeachNode(monitorsList, node)
132 D(bug("%4d %s\n", node->n.ln_Pri, node->Name));
133 Execute(node->Name, BNULL, BNULL);
136 D(bug("--------------------------\n"));
139 AROS_SH2H(AROSMonDrvs, 1.0, "Load AROS Monitor and Compositor drivers",
140 AROS_SHAH(BOOL, , NOCOMPOSITION,/S,FALSE, "Only load Monitors"),
141 AROS_SHAH(BOOL, , ONLYCOMPOSITION,/S,FALSE, "Only load Compositor"))
143 AROS_SHCOMMAND_INIT
145 APTR pool;
146 struct Library *IconBase;
147 BPTR dir, olddir;
148 BOOL res = TRUE;
150 dir = Lock(MONITORS_DIR, SHARED_LOCK);
151 D(bug("[LoadMonDrvs] Monitors directory 0x%p\n", dir));
152 if (dir)
154 olddir = CurrentDir(dir);
156 if (!SHArg(NOCOMPOSITION))
158 /* Software composition driver is ran first */
159 D(bug("[LoadMonDrvs] Loading composition driver...\n"));
160 Execute(COMPOSITING_NAME, BNULL, BNULL);
163 if (!SHArg(ONLYCOMPOSITION))
165 pool = CreatePool(MEMF_ANY, sizeof(struct MonitorNode) * 10, sizeof(struct MonitorNode) * 5);
166 DB2(bug("[LoadMonDrvs] Created pool 0x%p\n", pool));
167 if (pool)
169 struct List MonitorsList;
171 NewList(&MonitorsList);
172 IconBase = OpenLibrary("icon.library", 0);
173 if (IconBase)
175 findMonitors(&MonitorsList, DOSBase, IconBase, SysBase, pool);
176 loadMonitors(&MonitorsList, DOSBase);
177 CloseLibrary(IconBase);
179 DeletePool(pool);
181 else
182 res = FALSE;
185 CurrentDir(olddir);
186 UnLock(dir);
189 return res;
191 AROS_SHCOMMAND_EXIT