grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / LibList.c
blob0a6a085627328a42e5e6ab230057e94147047928
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 Printf("0x%08.ix\t%ld\t%ld\t%ld\t0x%lx\t%s\n",
143 libs2->address, (ULONG)libs2->version,
144 (ULONG)libs2->revision,
145 (ULONG)libs2->opencnt,
146 (ULONG)libs2->flags,
147 libs2->name);
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);
161 if (error != RETURN_OK)
163 PrintFault(IoErr(), NULL);
166 return error;