revert commit 56204.
[AROS.git] / workbench / c / AROSMonDrvs.c
blob53b7ac883cba9e166af6faf62c899701d10720e9
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code that loads and initializes necessary HIDDs.
6 Lang: english
7 */
9 /******************************************************************************
12 NAME
14 AROSMonDrvs
16 SYNOPSIS
18 NOCOMPOSITION/S,ONLYCOMPOSITION/S
20 LOCATION
24 FUNCTION
26 This command does almost the same thing as C:LoadMonDrvs does on
27 other systems. However, additionally we support priority-based
28 sorting for display drivers. This is needed in order to make monitor
29 ID assignment more predictable.
31 INPUTS
33 NOCOMPOSITION -- Only load Monitors
34 ONLYCOMPOSITION -- Only load Compositor
36 RESULT
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 HISTORY
50 ******************************************************************************/
52 #define DEBUG 0
54 #include <aros/debug.h>
55 #include <dos/dosextens.h>
56 #include <workbench/icon.h>
57 #include <proto/alib.h>
58 #include <proto/exec.h>
59 #include <proto/dos.h>
60 #include <proto/icon.h>
62 #include <aros/shcommands.h>
64 #include <stdlib.h>
65 #include <string.h>
67 #define MONITORS_DIR "DEVS:Monitors"
68 #define COMPOSITING_NAME "Compositor"
70 /************************************************************************/
72 struct MonitorNode
74 struct Node n;
75 char Name[1];
78 static BYTE checkIcon(STRPTR name, struct Library *IconBase)
80 LONG pri = 0;
81 struct DiskObject *dobj = GetDiskObject(name);
83 if (dobj == NULL)
84 return 0;
86 if ((dobj->do_Type == WBTOOL) || (dobj->do_Type == WBPROJECT))
88 const STRPTR *toolarray = (const STRPTR *)dobj->do_ToolTypes;
89 STRPTR s;
91 if ((s = FindToolType(toolarray, "STARTPRI")))
93 pri = atol(s);
94 if (pri < -128)
95 pri = -128;
96 else if (pri > 127)
97 pri = 127;
99 FreeDiskObject(dobj);
101 return pri;
104 static BOOL findMonitors(struct List *monitorsList, struct DosLibrary *DOSBase, struct Library *IconBase, struct ExecBase *SysBase, APTR poolmem)
106 BOOL retvalue = TRUE;
107 LONG error;
108 struct AnchorPath *ap = AllocPooled(poolmem, sizeof(struct AnchorPath));
110 DB2(bug("[LoadMonDrvs] AnchorPath 0x%p\n", ap));
111 if (ap)
113 /* Initialize important fields in AnchorPath, especially
114 ap_Strlen (prevents memory trashing) */
115 ap->ap_Flags = 0;
116 ap->ap_Strlen = 0;
117 ap->ap_BreakBits = 0;
119 error = MatchFirst("~((#?.info)|(#?.dbg))", ap);
120 while (!error)
122 struct MonitorNode *newnode;
124 DB2(bug("[LoadMonDrvs] Found monitor name %s\n", ap->ap_Info.fib_FileName));
126 /* Software composition driver was loaded before */
127 if (strcmp(ap->ap_Info.fib_FileName, COMPOSITING_NAME))
129 newnode = AllocPooled(poolmem, sizeof(struct MonitorNode) + strlen(ap->ap_Info.fib_FileName));
130 DB2(bug("[LoadMonDrvs] Monitor node 0x%p\n", newnode));
131 if (newnode == NULL)
133 retvalue = FALSE;
134 break;
137 strcpy(newnode->Name, ap->ap_Info.fib_FileName);
138 if (IconBase)
139 newnode->n.ln_Pri = checkIcon(ap->ap_Info.fib_FileName, IconBase);
140 else
141 newnode->n.ln_Pri = 0;
142 Enqueue(monitorsList, &newnode->n);
145 error = MatchNext(ap);
148 if (error != ERROR_NO_MORE_ENTRIES)
150 retvalue = FALSE;
151 /* FIXME: Why no MatchEnd() in this case?
152 goto exit; */
154 MatchEnd(ap);
156 else
157 retvalue = FALSE;
159 return retvalue;
162 static void loadMonitors(struct List *monitorsList, struct DosLibrary *DOSBase,
163 struct ExecBase *SysBase)
165 struct MonitorNode *node;
167 D(bug("[LoadMonDrvs] Loading monitor drivers...\n"));
168 D(bug(" Pri Name\n"));
170 ForeachNode(monitorsList, node)
172 D(bug("%4d %s\n", node->n.ln_Pri, node->Name));
173 Execute(node->Name, BNULL, BNULL);
176 D(bug("--------------------------\n"));
179 AROS_SH2H(AROSMonDrvs, 1.0, "Load AROS Monitor and Compositor drivers",
180 AROS_SHAH(BOOL, , NOCOMPOSITION,/S,FALSE, "Only load Monitors"),
181 AROS_SHAH(BOOL, , ONLYCOMPOSITION,/S,FALSE, "Only load Compositor"))
183 AROS_SHCOMMAND_INIT
185 APTR pool;
186 struct Library *IconBase;
187 BPTR dir, olddir;
188 BOOL res = TRUE;
190 dir = Lock(MONITORS_DIR, SHARED_LOCK);
191 D(bug("[LoadMonDrvs] Monitors directory 0x%p\n", dir));
192 if (dir)
194 olddir = CurrentDir(dir);
196 if (!SHArg(NOCOMPOSITION))
198 /* Software composition driver is run first */
199 D(bug("[LoadMonDrvs] Loading composition driver...\n"));
200 Execute(COMPOSITING_NAME, BNULL, BNULL);
203 if (!SHArg(ONLYCOMPOSITION))
205 pool = CreatePool(MEMF_ANY, sizeof(struct MonitorNode) * 10, sizeof(struct MonitorNode) * 5);
206 DB2(bug("[LoadMonDrvs] Created pool 0x%p\n", pool));
207 if (pool)
209 struct List MonitorsList;
211 NewList(&MonitorsList);
212 IconBase = OpenLibrary("icon.library", 0);
213 if (IconBase)
215 findMonitors(&MonitorsList, DOSBase, IconBase, SysBase, pool);
216 loadMonitors(&MonitorsList, DOSBase, SysBase);
217 CloseLibrary(IconBase);
219 DeletePool(pool);
221 else
222 res = FALSE;
225 CurrentDir(olddir);
226 UnLock(dir);
229 return res;
231 AROS_SHCOMMAND_EXIT