Check for SYS/GL during library init. Reason is that
[AROS.git] / rom / usb / poseidon / AddUSBHardware.c
blob49fa629d3cb531ba4106946116e6c507ff6440e6
1 /*
2 ** AddUSBHardware by Chris Hodges <chrisly@platon42.de>
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
9 #include <exec/exec.h>
10 #include <dos/dosextens.h>
11 #include <dos/datetime.h>
12 #include <dos/exall.h>
13 #include <libraries/poseidon.h>
14 #include <proto/poseidon.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
18 #define ARGS_DEVICE 0
19 #define ARGS_UNIT 1
20 #define ARGS_QUIET 2
21 #define ARGS_REMOVE 3
22 #define ARGS_ALL 4
23 #define ARGS_SIZEOF 5
25 static const char *template = "DEVICE,UNIT/N,QUIET/S,REMOVE/S,ALL/S";
26 const char *version = "$VER: AddUSBHardware 1.7 (03.06.09) by Chris Hodges <chrisly@platon42.de>";
27 static IPTR ArgsArray[ARGS_SIZEOF];
28 static struct RDArgs *ArgsHook = NULL;
30 //extern struct DOSBase *DOSBase;
32 void fail(char *str)
34 if(ArgsHook)
36 FreeArgs(ArgsHook);
37 ArgsHook = NULL;
39 if(str)
41 PutStr(str);
42 exit(20);
44 exit(0);
47 int main(int argc, char *argv[])
49 struct Library *ps;
50 char *errmsg = NULL;
51 struct List *phwlist;
52 struct Node *phw;
53 struct Node *next;
54 ULONG unit;
55 STRPTR devname = NULL;
56 ULONG cmpunit;
57 STRPTR cmpdevname;
59 if(!(ArgsHook = ReadArgs(template, ArgsArray, NULL)))
61 fail("Wrong arguments!\n");
64 if((!ArgsArray[ARGS_DEVICE]) && (!(ArgsArray[ARGS_REMOVE] && ArgsArray[ARGS_ALL])))
66 fail("DEVICE argument is mandatory except for REMOVE ALL!\n");
69 if((ps = OpenLibrary("poseidon.library", 4)))
71 unit = 0;
72 if(ArgsArray[ARGS_DEVICE])
74 devname = (STRPTR) ArgsArray[ARGS_DEVICE];
76 if(ArgsArray[ARGS_UNIT])
78 unit = *((ULONG *) ArgsArray[ARGS_UNIT]);
80 if(ArgsArray[ARGS_REMOVE])
82 psdLockReadPBase();
85 psdGetAttrs(PGA_STACK, NULL, PA_HardwareList, &phwlist, TAG_END);
86 phw = phwlist->lh_Head;
87 while((next = phw->ln_Succ))
89 psdGetAttrs(PGA_HARDWARE, phw,
90 HA_DeviceName, &cmpdevname,
91 HA_DeviceUnit, &cmpunit,
92 TAG_END);
93 if(ArgsArray[ARGS_ALL] || ((!stricmp(FilePart(cmpdevname), FilePart(devname))) && (cmpunit == unit)))
95 if(!ArgsArray[ARGS_QUIET])
97 Printf("Removing hardware %s, unit %ld...\n", cmpdevname, cmpunit);
99 psdUnlockPBase();
100 psdRemHardware(phw);
101 psdLockReadPBase();
102 break;
104 phw = next;
106 } while(ArgsArray[ARGS_ALL] && next);
107 psdUnlockPBase();
108 } else {
111 if(!ArgsArray[ARGS_QUIET])
113 Printf("Adding hardware %s, unit %ld...", devname, unit);
115 if((phw = psdAddHardware(devname, unit)))
117 if(!ArgsArray[ARGS_QUIET])
119 if(psdEnumerateHardware(phw))
121 PutStr("okay!\n");
122 } else {
123 PutStr("enumeration failed!\n");
125 } else {
126 psdEnumerateHardware(phw);
128 } else {
129 if(!ArgsArray[ARGS_QUIET])
131 PutStr("failed!\n");
133 errmsg = "";
134 break;
136 unit++;
137 } while(ArgsArray[ARGS_ALL]);
138 psdClassScan();
140 CloseLibrary(ps);
141 } else {
142 errmsg = "Unable to open poseidon.library\n";
144 fail(errmsg);
145 return(0); // never gets here, just to shut the compiler up