Hint added.
[AROS.git] / workbench / c / DevList.c
blob3beb9d8fd667473e3f1436d4fe18958982695d3c
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 Printf("0x%08.lx\t%ld\t%ld\t%ld\t0x%lx\t%s\n",
140 devs2->address, devs2->version,
141 devs2->revision, devs2->opencnt,
142 devs2->flags, devs2->name);
143 if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
145 error = RETURN_FAIL;
146 SetIoErr(ERROR_BREAK);
147 break;
150 FreeVec(buffer);
151 break;
153 FreeVec(buffer);
155 if (error != RETURN_OK)
157 PrintFault(IoErr(), NULL);
159 return(error);