2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Avail CLI command
9 /******************************************************************************
14 Avail [CHIP | FAST | TOTAL | FLUSH] [H | HUMAN]
18 CHIP/S, FAST/S, TOTAL/S, FLUSH/S, H=HUMAN/S
26 Give a summary of the memory usage and availability in the system.
27 To free up unused memory that still may be allocated (libraries,
28 devices, fonts and such present in memory but whcih are currently
29 not in use), use the FLUSH option.
33 CHIP -- show only "chip" memory
34 FAST -- show only "fast" memory
35 TOTAL -- show information on memory regardless of type
36 FLUSH -- remove unnecessary things residing in memory
37 HUMAN -- display more human-readable values (gigabytes as "G",
38 megabytes as "M", kilobytes as "K")
44 "Chip" and "fast" memory are associated with the Amiga computer
45 and may not be applicable on your hardware platform.
57 ******************************************************************************/
59 #include <exec/execbase.h>
60 #include <exec/memory.h>
61 #include <proto/exec.h>
63 #include <proto/dos.h>
64 #include <utility/tagitem.h>
67 static const char version
[] = "$VER: Avail 42.0 (13.9.2005)\n";
70 #define ARG_TEMPLATE "CHIP/S,FAST/S,TOTAL/S,FLUSH/S,H=HUMAN/S"
82 LONG
printm(CONST_STRPTR head
, ULONG
*array
, LONG num
);
84 int __nocommandline
= 1;
90 IPTR args
[NOOFARGS
] = { (IPTR
)FALSE
,
97 BOOL bPrintErr
= TRUE
;
98 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
103 BOOL aChip
= (BOOL
)args
[ARG_CHIP
];
104 BOOL aFast
= (BOOL
)args
[ARG_FAST
];
105 BOOL aTotal
= (BOOL
)args
[ARG_TOTAL
];
106 BOOL aFlush
= (BOOL
)args
[ARG_FLUSH
];
107 aHuman
= (BOOL
)args
[ARG_HUMAN
];
122 ULONG chip
[4], fast
[4], total
[4];
126 FPuts(Output(), "Only one of CHIP, FAST or TOTAL allowed\n");
138 Mem
= AllocMem(0x7ffffff0, MEMF_PUBLIC
);
140 FreeMem(Mem
, 0x7ffffff0);
146 chip
[0] = AvailMem(MEMF_CHIP
);
148 if (printm(NULL
, chip
, 1) < 0)
150 error
= RETURN_ERROR
;
155 fast
[0] = AvailMem(MEMF_FAST
);
157 if (printm(NULL
, fast
, 1) < 0)
159 error
= RETURN_ERROR
;
164 total
[0] = AvailMem(MEMF_ANY
);
166 if (printm(NULL
, total
, 1) < 0)
168 error
= RETURN_ERROR
;
175 chip
[0] = AvailMem(MEMF_CHIP
);
176 chip
[2] = AvailMem(MEMF_CHIP
| MEMF_TOTAL
);
177 chip
[3] = AvailMem(MEMF_CHIP
| MEMF_LARGEST
);
178 chip
[1] = chip
[2] - chip
[0];
179 fast
[0] = AvailMem(MEMF_FAST
);
180 fast
[2] = AvailMem(MEMF_FAST
| MEMF_TOTAL
);
181 fast
[3] = AvailMem(MEMF_FAST
| MEMF_LARGEST
);
182 fast
[1] = fast
[2] - fast
[0];
183 total
[0] = AvailMem(MEMF_ANY
);
184 total
[2] = AvailMem(MEMF_ANY
| MEMF_TOTAL
);
185 total
[3] = AvailMem(MEMF_ANY
| MEMF_LARGEST
);
186 total
[1] = total
[2] - total
[0];
190 if (PutStr("Type Available In-Use Maximum Largest\n") < 0 ||
191 printm("chip", chip
, 4) < 0 ||
192 printm("fast", fast
, 4) < 0 ||
193 printm("total", total
, 4) < 0)
195 error
= RETURN_ERROR
;
207 if(error
!= RETURN_OK
&& bPrintErr
)
209 PrintFault(IoErr(), "Avail");
216 void fmtlarge(UBYTE
*buf
, ULONG num
)
230 if (num
>= 1073741824)
232 array
.val
= num
>> 30;
233 d
= ((UQUAD
)num
* 10 + 536870912) / 1073741824;
237 else if (num
>= 1048576)
239 array
.val
= num
>> 20;
240 d
= ((UQUAD
)num
* 10 + 524288) / 1048576;
244 else if (num
>= 1024)
246 array
.val
= num
>> 10;
247 d
= (num
* 10 + 512) / 1024;
259 if (!array
.dec
&& (d
> array
.val
* 10))
264 RawDoFmt(array
.dec
? "%lu.%lu" : "%lu", &array
, NULL
, buf
);
265 while (*buf
) { buf
++; }
270 LONG
printm(CONST_STRPTR head
, ULONG
*array
, LONG num
)
278 LONG len
= 16 - strlen(head
);
279 RawDoFmt(aHuman
? "%%%lds" : "%%%ldlu", &len
, NULL
, buf
);
285 fmt
= aHuman
? "%9s" : "%9lu";
292 fmtlarge(buf
, *array
);
301 fmtlarge(tmp
, *array
);
302 res
= Printf(fmt
, (ULONG
) tmp
);
315 res
= VPrintf("%lu", array
);
321 res
= VPrintf(fmt
, array
);