prism2.device: Compiler delint
[AROS.git] / workbench / c / DevList.c
blobeec9ccdc7f79a28e5c1846c4d324d61e8dd120dc
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <exec/memory.h>
10 #include <exec/tasks.h>
11 #include <exec/execbase.h>
12 #include <exec/devices.h>
13 #include <proto/exec.h>
14 #include <dos/dosextens.h>
15 #include <proto/dos.h>
17 const TEXT version[] = "$VER: DevList 41.1 (14.3.1997)\n";
19 struct dev
21 STRPTR name;
22 APTR address;
23 WORD version;
24 WORD revision;
25 ULONG flags;
26 WORD opencnt;
29 static int adddev(struct Device *dev, struct dev **l, STRPTR *e)
31 STRPTR s1, s2;
33 (*l)->address = dev;
34 (*l)->version = dev->dd_Library.lib_Version;
35 (*l)->revision = dev->dd_Library.lib_Revision;
36 (*l)->opencnt = dev->dd_Library.lib_OpenCnt;
37 (*l)->flags = dev->dd_Library.lib_Flags;
39 s1 = dev->dd_Library.lib_Node.ln_Name;
41 if(s1!=NULL)
43 s2=s1;
44 while(*s2++)
46 while(s2>s1)
48 if(*e<=(STRPTR)(*l+2))
49 return 0;
50 *--(*e)=*--s2;
53 if((STRPTR)(*l+2)>*e)
54 return 0;
56 (*l)->name=*e;
57 ++*l;
59 return 1;
62 static int fillbuffer(struct dev **buffer, IPTR size)
64 STRPTR end=(STRPTR)*buffer+size;
65 struct Device *dev;
66 Forbid();
67 for(dev=(struct Device *)SysBase->DeviceList.lh_Head;
68 dev->dd_Library.lib_Node.ln_Succ!=NULL;
69 dev=(struct Device *)dev->dd_Library.lib_Node.ln_Succ)
70 if(!adddev(dev,buffer,&end))
72 Permit();
73 return 0;
75 Permit();
76 return 1;
79 int __nocommandline = 1;
81 int main(void)
83 IPTR size;
84 struct dev *buffer,*devs,*devs2;
85 LONG error=RETURN_OK;
87 for(size=2048;;size+=2048)
89 buffer=AllocVec(size,MEMF_ANY);
90 if(buffer==NULL)
92 FPuts(Output(),"Not Enough memory for device buffer\n");
93 return 20;
95 devs=buffer;
96 if(fillbuffer(&devs,size))
98 FPuts(Output(),"address\t\tversion\trev\topencnt\tflags\tname\n"
99 "------------------------------------------------------------\n");
100 for(devs2=buffer;devs2<devs;devs2++)
102 IPTR args[6];
103 args[0] = (IPTR)devs2->address;
104 args[1] = (IPTR)devs2->version;
105 args[2] = (IPTR)devs2->revision;
106 args[3] = (IPTR)devs2->opencnt;
107 args[4] = (IPTR)devs2->flags;
108 args[5] = (IPTR)devs2->name;
110 VPrintf("0x%08.lx\t%ld\t%ld\t%ld\t0x%lx\t%s\n", args);
111 if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
113 error = RETURN_FAIL;
114 SetIoErr(ERROR_BREAK);
115 break;
118 FreeVec(buffer);
119 break;
121 FreeVec(buffer);
123 if (error != RETURN_OK)
125 PrintFault(IoErr(), NULL);
127 return(error);