Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / tools / HDToolBox / main.c
blob0a5fec0a9110323c045a6ed04f54a725fd57f9d6
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/alib.h>
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/intuition.h>
11 #include <exec/memory.h>
12 #include <exec/nodes.h>
14 #include <stdio.h>
15 #include <stdlib.h>
17 #include "devices.h"
18 #include "error.h"
19 #include "gui.h"
20 #include "hdtoolbox_support.h"
21 #include "locale.h"
22 #include "partitions.h"
23 #include "partitiontables.h"
24 #include "platform.h"
25 #include "ptclass.h"
26 #include "prefs.h"
28 #include "debug.h"
30 extern struct ListNode root;
32 struct IntuitionBase *IntuitionBase = NULL;
33 struct GfxBase *GfxBase = NULL;
34 struct PartitionBase *PartitionBase = NULL;
36 LONG initEnv(char *device)
38 LONG retval;
40 D(bug("[HDToolBox] initEnv('%s')\n", device));
42 if (!InitListNode(&root, NULL))
43 return ERR_MEMORY;
44 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
45 if (!IntuitionBase)
46 return ERR_INTUI;
47 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37);
48 if (!GfxBase)
49 return ERR_GFX;
50 PartitionBase = (struct PartitionBase *)OpenLibrary("partition.library", 1);
51 if (!PartitionBase)
52 return ERR_PARTITION;
54 retval = initGUI();
55 if (retval != ERR_NONE)
56 return retval;
57 LoadPrefs("ENV:hdtoolbox.prefs");
58 return ERR_NONE;
61 void uninitEnv()
63 D(bug("[HDToolBox] uninitEnv()\n"));
65 deinitGUI();
66 if (PartitionBase)
67 CloseLibrary((struct Library *)PartitionBase);
68 if (GfxBase)
69 CloseLibrary((struct Library *)GfxBase);
70 if (IntuitionBase)
71 CloseLibrary((struct Library *)IntuitionBase);
72 freeDeviceList();
75 void waitMessage()
77 ULONG sigs = 0;
79 D(bug("[HDToolBox] waitMessage()\n"));
81 while (!QuitGUI(&sigs))
83 if (sigs)
85 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
86 if (sigs & SIGBREAKF_CTRL_C)
87 break;
88 if (sigs & SIGBREAKF_CTRL_D)
89 break;
94 int main(int argc, char **argv)
96 ULONG error;
97 char *device;
99 D(bug("[HDToolBox] main()\n"));
101 InitLocale("System/Tools/HDToolBox.catalog", 1);
102 device = argc > 1 ? argv[1] : NULL;
103 if ((error=initEnv(device))==ERR_NONE)
105 waitMessage();
107 else
108 printf("Error %ld\n", error);
110 uninitEnv();
111 CleanupLocale();
112 return 0;