dropped in the dos stuff
[smouse] / src / device.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "device.h"
4
5 struct device *device_magellan(void);
6
7 static struct device *devlist;
8 static char *port;
9
10 void register_all(void)
11 {
12         struct device *dev;
13
14         if((dev = device_magellan()) && dev->init() != -1) {
15                 dev->next = devlist;
16                 devlist = dev;
17         }
18 }
19
20 struct device *dev_init(const char *name)
21 {
22         struct device *dev = devlist;
23
24         while(dev) {
25                 if(name) {
26                         if(strcmp(dev->name, name) == 0) {
27                                 return dev->detect() ? dev : 0;
28                         }
29                 } else {
30                         if(dev->detect()) {
31                                 return dev;
32                         }
33                 }
34                 dev = dev->next;
35         }
36         return 0;
37 }
38
39 void dev_destroy(void)
40 {
41         while(devlist) {
42                 struct device *dev = devlist;
43                 devlist = devlist->next;
44                 dev->destroy();
45         }
46         devlist = 0;
47 }
48
49 void set_port(const char *s)
50 {
51         free(port);
52         port = strdup(s);
53 }
54
55 const char *get_port(void)
56 {
57         return port;
58 }