2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
8 #include <proto/icon.h>
11 #include <dos/rdargs.h>
12 #include <exec/lists.h>
13 #include <exec/memory.h>
14 #include <workbench/icon.h>
25 #include "hdtoolbox_support.h"
28 struct List tabletypelist
;
30 struct TableTypeNode
*findTableTypeNodeName(STRPTR name
)
32 struct TableTypeNode
*ttn
;
34 D(bug("[HDToolBox] findTableTypeNodeName('%s')\n", name
));
36 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
37 while (ttn
->ln
.ln_Succ
)
39 if (strcmp(ttn
->pti
->pti_Name
, name
) == 0)
41 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
46 struct TableTypeNode
*findTableTypeNode(ULONG tabletype
)
48 struct TableTypeNode
*ttn
;
50 D(bug("[HDToolBox] findTableTypeNode()\n"));
52 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
53 while (ttn
->ln
.ln_Succ
)
55 if (ttn
->pti
->pti_Type
== tabletype
)
57 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
62 struct TypeNode
*findPartitionType(struct PartitionType
*type
, ULONG tabletype
)
64 struct TableTypeNode
*ttn
;
67 D(bug("[HDToolBox] findPartitionType()\n"));
69 ttn
= findTableTypeNode(tabletype
);
72 tn
= (struct TypeNode
*)ttn
->typelist
->lh_Head
;
73 while (tn
->ln
.ln_Succ
)
75 if (tn
->type
.id_len
== type
->id_len
)
77 if (memcmp(tn
->type
.id
, type
->id
, type
->id_len
) == 0)
80 tn
= (struct TypeNode
*)tn
->ln
.ln_Succ
;
86 void getTableTypeList(struct List
*list
)
88 struct TableTypeNode
*ttn
;
91 D(bug("[HDToolBox] getTableTypeList()\n"));
93 NEWLIST(&tabletypelist
);
94 for (i
=0;PartitionBase
->tables
[i
];i
++)
96 ttn
= AllocMem(sizeof(struct TableTypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
100 AllocMem(sizeof(struct List
), MEMF_PUBLIC
| MEMF_CLEAR
);
101 if (ttn
->typelist
!= NULL
)
103 ttn
->pti
= PartitionBase
->tables
[i
];
104 NEWLIST(ttn
->typelist
);
105 AddTail(list
, &ttn
->ln
);
109 FreeMem(ttn
, sizeof(struct TableTypeNode
));
116 LONG
parsePrefs(char *buffer
, LONG size
)
118 struct TableTypeNode
*ttn
=NULL
;
120 struct CSource csrc
= {buffer
, size
, 0};
121 struct DiskObject
*hdtbicon
=NULL
;
128 D(bug("[HDToolBox] parsePrefs()\n"));
130 while (csrc
.CS_CurChr
< csrc
.CS_Length
)
132 res
= ReadItem(ident
, 256, &csrc
);
138 if (strcasecmp(ident
, "[Devices]") == 0)
140 else if (strcasecmp(ident
, "[TableIDs]") == 0)
149 addDeviceName(ident
);
150 else if (current
== 2)
152 if (strcasecmp(ident
, "TableType") == 0)
154 res
= ReadItem(ident
, 256, &csrc
);
155 if (res
== ITEM_ERROR
)
157 else if (res
== ITEM_EQUAL
)
159 res
= ReadItem(ident
, 256, &csrc
);
160 if (res
== ITEM_ERROR
)
162 else if (res
== ITEM_QUOTED
)
163 ttn
= findTableTypeNodeName(ident
);
164 else if (res
== ITEM_UNQUOTED
)
165 ttn
= findTableTypeNode(strtoul(ident
, NULL
, 0));
168 printf("LINE %d: Unexpected item in TableType\n", line
);
173 printf("LINE %d: Unknown Table %s\n", line
, ident
);
179 printf("LINE %d: Unexpected item after TableType\n", line
);
183 else if (strcasecmp(ident
, "IDLen") == 0)
185 res
= ReadItem(ident
, 256, &csrc
);
186 if (res
== ITEM_ERROR
)
188 else if (res
== ITEM_EQUAL
)
190 res
= ReadItem(ident
, 256, &csrc
);
191 if (res
== ITEM_ERROR
)
193 else if (res
== ITEM_UNQUOTED
)
195 id_len
= strtoul(ident
, NULL
, 0);
198 printf("LINE %d: Illegal value of IDLen\n", line
);
204 printf("LINE %d: Value in IDLen expected\n", line
);
210 printf("LINE %d: Unexpected item after IDLen\n", line
);
214 else if (strcasecmp(ident
, "Default") == 0)
218 res
= ReadItem(ident
, 256, &csrc
);
219 if (res
== ITEM_ERROR
)
221 else if (res
== ITEM_EQUAL
)
223 res
= ReadItem(ident
, 256, &csrc
);
224 if (res
== ITEM_ERROR
)
226 else if (res
== ITEM_QUOTED
)
228 ttn
->defaulttype
.id_len
= id_len
;
229 strcpyESC(ttn
->defaulttype
.id
, ident
);
233 printf("LINE %d: Unexpected expression after Default\n", line
);
239 printf("LINE %d: Unexpected item after IDLen\n", line
);
245 printf("LINE %d: Unknown option '%s'\n", line
, ident
);
251 printf("LINE %d: Missing partition table type or IDLen\n", line
);
257 printf("LINE %d: Unexpected item '%s' in prefs\n", line
, ident
);
265 tn
= AllocMem(sizeof(struct TypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
267 return ERROR_NO_FREE_STORE
;
268 tn
->type
.id_len
= id_len
;
269 strcpyESC(tn
->type
.id
, ident
);
270 res
= ReadItem(ident
, 256, &csrc
);
271 if (res
== ITEM_ERROR
)
273 if (res
== ITEM_EQUAL
)
275 res
= ReadItem(ident
, 256, &csrc
);
276 if (res
== ITEM_ERROR
)
278 else if (res
== ITEM_QUOTED
)
280 tn
->ln
.ln_Name
= AllocVec(strlen(ident
)+1, MEMF_PUBLIC
| MEMF_CLEAR
);
281 if (tn
->ln
.ln_Name
== NULL
)
282 return ERROR_NO_FREE_STORE
;
283 strcpy(tn
->ln
.ln_Name
, ident
);
287 printf("LINE %d: Quoted expression expected\n", line
);
293 printf("LINE %d: Unexpected item after table id\n", line
);
296 AddTail(ttn
->typelist
, &tn
->ln
);
300 printf("LINE %d: Missing partition table type or IDLen\n", line
);
310 hdtbicon
= GetIconTags("HDToolBox",
311 ICONGETA_FailIfUnavailable
, TRUE
,
312 ICONGETA_IsDefaultIcon
, FALSE
,
315 if (hdtbicon
!= NULL
)
317 D(bug("[HDToolBox] Got our Icon..\n"));
318 if (hdtbicon
->do_ToolTypes
)
320 char *tt
= NULL
, *devicename
;
322 D(bug("[HDToolBox] Icon has tooltypes..\n"));
324 while ((tt
= hdtbicon
->do_ToolTypes
[i
]) != NULL
)
326 if (strncmp(hdtbicon
->do_ToolTypes
[i
], "DEVICE=", 7) == 0)
328 devicename
= hdtbicon
->do_ToolTypes
[i
] + 7;
329 D(bug("[HDToolBox] Adding Device '%s' from ToolType\n", devicename
));
330 addDeviceName(devicename
);
337 // EBR uses same types as MBR
338 findTableTypeNode(PHPTT_EBR
)->typelist
=
339 findTableTypeNode(PHPTT_MBR
)->typelist
;
344 void LoadPrefs(STRPTR filename
)
346 struct FileInfoBlock fib
;
352 D(bug("[HDToolBox] LoadPrefs('%s')\n", filename
));
354 getTableTypeList(&tabletypelist
);
355 fh
= Open(filename
, MODE_OLDFILE
);
358 if (ExamineFH(fh
, &fib
))
362 buffer
= AllocMem(fib
.fib_Size
, MEMF_PUBLIC
| MEMF_CLEAR
);
365 size
= Read(fh
, buffer
, fib
.fib_Size
);
366 if (size
== fib
.fib_Size
)
368 retval
= parsePrefs(buffer
, size
);
370 PrintFault(retval
, filename
);
372 FreeMem(buffer
, fib
.fib_Size
);
375 PrintFault(ERROR_NO_FREE_STORE
, filename
);
381 PrintFault(IoErr(), filename
);