revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / system / Wanderer / Tools / DiskInfo / support.c
blob68a1794c487e8f0a2dce848fb45c1f90c3969b1c
1 /*
2 Copyright © 2005-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/memory.h>
7 #include <dos/var.h>
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/muimaster.h>
13 #include <ctype.h>
15 #include "locale.h"
16 #include "support.h"
18 #include <stdio.h>
20 STRPTR GetENV(CONST_STRPTR name)
22 UBYTE dummy = 0;
23 STRPTR value = NULL;
25 /* Check that the variable exists, and get the length */
26 if (GetVar(name, &dummy, 1, GVF_GLOBAL_ONLY) != -1)
28 ULONG length = IoErr() + 1;
30 if ((value = AllocVec(length, MEMF_ANY)) != NULL)
32 if (GetVar(name, value, length, GVF_GLOBAL_ONLY) == -1)
34 FreeVec(value);
35 value = NULL;
40 return value;
43 BOOL SetENV(CONST_STRPTR name, CONST_STRPTR value)
45 return SetVar(name, value, -1, GVF_GLOBAL_ONLY);
48 VOID ShowError(Object *application, Object *window, CONST_STRPTR message, BOOL useIOError)
50 TEXT buffer[128];
51 STRPTR newline = "\n",
52 period = ".",
53 extra = buffer;
55 /* Never use IO error if it is 0 */
56 if (IoErr() == 0) useIOError = FALSE;
58 if (useIOError)
60 Fault(IoErr(), NULL, buffer, sizeof(buffer));
61 buffer[0] = toupper(buffer[0]);
63 else
65 newline = "";
66 period = "";
67 extra = "";
70 MUI_Request
72 application, window, 0, _(MSG_TITLE), _(MSG_ERROR_OK),
73 "%s:\n%s%s%s%s", _(MSG_ERROR_HEADER), message, newline, extra, period
77 ULONG FormatSize(STRPTR buffer, ULONG blocks, ULONG totalblocks, ULONG bytesperblock, BOOL showPercentage)
79 static STRPTR suffixes[] = {" bytes", "K", "M", "G", "T", "P"};
80 DOUBLE internalsize = (DOUBLE)((UQUAD)blocks * bytesperblock);
81 ULONG divcount = 0;
82 ULONG percentage;
84 if (totalblocks != 0)
85 percentage = 100 * blocks / totalblocks;
86 else
87 percentage = 100;
89 while (internalsize > 1024)
91 internalsize /= 1024;
92 divcount++;
95 if (!showPercentage)
96 sprintf(buffer, "%.1f%s (%d %s)", internalsize, suffixes[divcount], (int)blocks, _(MSG_BLOCKS) );
97 else
98 sprintf(buffer, "%.1f%s (%d %s, %d%%)", internalsize, suffixes[divcount], (int)blocks, _(MSG_BLOCKS), (int)percentage);
100 return percentage;