Build various tools as native versions
[AROS.git] / workbench / c / DevList.c
blob88eedfbbf1645b062b62a82114ccae844c844967
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 /******************************************************************************
12 NAME
14 DevList
16 SYNOPSIS
18 (N/A)
20 LOCATION
24 FUNCTION
26 Prints a list of all devices.
28 INPUTS
30 RESULT
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 HISTORY
44 ******************************************************************************/
46 #include <exec/memory.h>
47 #include <exec/tasks.h>
48 #include <exec/execbase.h>
49 #include <exec/devices.h>
50 #include <proto/exec.h>
51 #include <dos/dosextens.h>
52 #include <proto/dos.h>
54 const TEXT version[] = "$VER: DevList 41.1 (14.3.1997)\n";
56 struct dev
58 STRPTR name;
59 APTR address;
60 WORD version;
61 WORD revision;
62 ULONG flags;
63 WORD opencnt;
66 static int adddev(struct Device *dev, struct dev **l, STRPTR *e)
68 STRPTR s1, s2;
70 (*l)->address = dev;
71 (*l)->version = dev->dd_Library.lib_Version;
72 (*l)->revision = dev->dd_Library.lib_Revision;
73 (*l)->opencnt = dev->dd_Library.lib_OpenCnt;
74 (*l)->flags = dev->dd_Library.lib_Flags;
76 s1 = dev->dd_Library.lib_Node.ln_Name;
78 if(s1!=NULL)
80 s2=s1;
81 while(*s2++)
83 while(s2>s1)
85 if(*e<=(STRPTR)(*l+2))
86 return 0;
87 *--(*e)=*--s2;
90 if((STRPTR)(*l+2)>*e)
91 return 0;
93 (*l)->name=*e;
94 ++*l;
96 return 1;
99 static int fillbuffer(struct dev **buffer, IPTR size)
101 STRPTR end=(STRPTR)*buffer+size;
102 struct Device *dev;
103 Forbid();
104 for(dev=(struct Device *)SysBase->DeviceList.lh_Head;
105 dev->dd_Library.lib_Node.ln_Succ!=NULL;
106 dev=(struct Device *)dev->dd_Library.lib_Node.ln_Succ)
107 if(!adddev(dev,buffer,&end))
109 Permit();
110 return 0;
112 Permit();
113 return 1;
116 int __nocommandline = 1;
118 int main(void)
120 IPTR size;
121 struct dev *buffer,*devs,*devs2;
122 LONG error=RETURN_OK;
124 for(size=2048;;size+=2048)
126 buffer=AllocVec(size,MEMF_ANY);
127 if(buffer==NULL)
129 FPuts(Output(),"Not Enough memory for device buffer\n");
130 return 20;
132 devs=buffer;
133 if(fillbuffer(&devs,size))
135 FPuts(Output(),"address\t\tversion\trev\topencnt\tflags\tname\n"
136 "------------------------------------------------------------\n");
137 for(devs2=buffer;devs2<devs;devs2++)
139 IPTR args[6];
140 args[0] = (IPTR)devs2->address;
141 args[1] = (IPTR)devs2->version;
142 args[2] = (IPTR)devs2->revision;
143 args[3] = (IPTR)devs2->opencnt;
144 args[4] = (IPTR)devs2->flags;
145 args[5] = (IPTR)devs2->name;
147 VPrintf("0x%08.lx\t%ld\t%ld\t%ld\t0x%lx\t%s\n", args);
148 if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
150 error = RETURN_FAIL;
151 SetIoErr(ERROR_BREAK);
152 break;
155 FreeVec(buffer);
156 break;
158 FreeVec(buffer);
160 if (error != RETURN_OK)
162 PrintFault(IoErr(), NULL);
164 return(error);