use disable/enable and add a suitable comment as to why.
[AROS.git] / workbench / c / LibList.c
blob5db38aaf305044e12d5af8d1d029f718c71203e1
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 /******************************************************************************
12 NAME
14 LibList
16 SYNOPSIS
18 (N/A)
20 LOCATION
24 FUNCTION
26 Print list of all libraries.
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 <proto/exec.h>
50 #include <dos/dosextens.h>
51 #include <proto/dos.h>
53 const TEXT version[] = "$VER: LibList 41.3 (11.3.2015)\n";
55 struct lib
57 STRPTR name;
58 APTR address;
59 WORD version;
60 WORD revision;
61 WORD opencnt;
62 UBYTE flags;
65 static int addlib(struct Library *lib, struct lib **l, STRPTR *e)
67 STRPTR s1, s2;
69 (*l)->address = lib;
70 (*l)->version = lib->lib_Version;
71 (*l)->revision = lib->lib_Revision;
72 (*l)->opencnt = lib->lib_OpenCnt;
73 (*l)->flags = lib->lib_Flags;
75 s1 = lib->lib_Node.ln_Name;
77 if(s1!=NULL)
79 s2=s1;
80 while(*s2++)
82 while(s2>s1)
84 if(*e<=(STRPTR)*l)
85 return 0;
86 *--(*e)=*--s2;
89 if((STRPTR)(*l+1)>*e)
90 return 0;
92 (*l)->name=*e;
93 ++*l;
95 return 1;
98 static int fillbuffer(struct lib **buffer, IPTR size)
100 STRPTR end=(STRPTR)*buffer+size;
101 struct Library *lib;
102 Forbid();
103 for(lib=(struct Library *)SysBase->LibList.lh_Head;
104 lib->lib_Node.ln_Succ!=NULL;
105 lib=(struct Library *)lib->lib_Node.ln_Succ)
107 if(!addlib(lib,buffer,&end))
109 Permit();
110 return 0;
113 Permit();
114 return 1;
117 int __nocommandline;
119 int main(void)
121 IPTR size;
122 struct lib *buffer,*libs,*libs2;
123 LONG error=RETURN_OK;
125 for(size=2048;;size+=2048)
127 buffer=AllocVec(size,MEMF_ANY);
128 if(buffer==NULL)
130 FPuts(Output(),"Not Enough memory for library buffer\n");
131 SetIoErr(ERROR_NO_FREE_STORE);
132 error = RETURN_FAIL;
133 break;
135 libs=buffer;
136 if(fillbuffer(&libs,size))
138 FPuts(Output(),"address\t\tversion\trev\topencnt\tflags\tname\n"
139 "------------------------------------------------------------\n");
140 for(libs2=buffer;libs2<libs;libs2++)
142 IPTR args[6];
143 args[0] = (IPTR)libs2->address;
144 args[1] = (IPTR)libs2->version;
145 args[2] = (IPTR)libs2->revision;
146 args[3] = (IPTR)libs2->opencnt;
147 args[4] = (IPTR)libs2->flags;
148 args[5] = (IPTR)libs2->name;
150 VPrintf("0x%08.lx\t%ld\t%ld\t%ld\t0x%lx\t%s\n", args);
151 if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
153 error = RETURN_FAIL;
154 SetIoErr(ERROR_BREAK);
155 break;
158 FreeVec(buffer);
159 break;
161 FreeVec(buffer);
164 if (error != RETURN_OK)
166 PrintFault(IoErr(), NULL);
169 return error;