2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
9 #include <dos/rdargs.h>
10 #include <exec/lists.h>
11 #include <exec/memory.h>
20 #include "hdtoolbox_support.h"
23 struct List tabletypelist
;
25 struct TableTypeNode
*findTableTypeNodeName(STRPTR name
) {
26 struct TableTypeNode
*ttn
;
28 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
29 while (ttn
->ln
.ln_Succ
)
31 if (strcmp(ttn
->pti
->pti_Name
, name
) == 0)
33 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
38 struct TableTypeNode
*findTableTypeNode(ULONG tabletype
) {
39 struct TableTypeNode
*ttn
;
41 ttn
= (struct TableTypeNode
*)tabletypelist
.lh_Head
;
42 while (ttn
->ln
.ln_Succ
)
44 if (ttn
->pti
->pti_Type
== tabletype
)
46 ttn
= (struct TableTypeNode
*)ttn
->ln
.ln_Succ
;
51 struct TypeNode
*findPartitionType(struct PartitionType
*type
, ULONG tabletype
) {
52 struct TableTypeNode
*ttn
;
55 if (tabletype
== PHPTT_EBR
)
56 tabletype
= PHPTT_MBR
; // EBR uses same types as MBR
57 ttn
= findTableTypeNode(tabletype
);
60 tn
= (struct TypeNode
*)ttn
->typelist
.lh_Head
;
61 while (tn
->ln
.ln_Succ
)
63 if (tn
->type
.id_len
== type
->id_len
)
65 if (memcmp(tn
->type
.id
, type
->id
, type
->id_len
) == 0)
68 tn
= (struct TypeNode
*)tn
->ln
.ln_Succ
;
74 void getTableTypeList(struct List
*list
) {
75 struct TableTypeNode
*ttn
;
78 NEWLIST(&tabletypelist
);
79 for (i
=0;PartitionBase
->tables
[i
];i
++)
81 ttn
= AllocMem(sizeof(struct TableTypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
84 ttn
->pti
= PartitionBase
->tables
[i
];
85 NEWLIST(&ttn
->typelist
);
86 AddTail(list
, &ttn
->ln
);
91 LONG
parsePrefs(char *buffer
, LONG size
) {
92 struct TableTypeNode
*ttn
=NULL
;
94 struct CSource csrc
= {buffer
, size
, 0};
101 while (csrc
.CS_CurChr
< csrc
.CS_Length
)
103 res
= ReadItem(ident
, 256, &csrc
);
109 if (strcasecmp(ident
, "[Devices]") == 0)
111 else if (strcasecmp(ident
, "[TableIDs]") == 0)
120 addDeviceName(ident
);
121 else if (current
== 2)
123 if (strcasecmp(ident
, "TableType") == 0)
125 res
= ReadItem(ident
, 256, &csrc
);
126 if (res
== ITEM_ERROR
)
128 else if (res
== ITEM_EQUAL
)
130 res
= ReadItem(ident
, 256, &csrc
);
131 if (res
== ITEM_ERROR
)
133 else if (res
== ITEM_QUOTED
)
134 ttn
= findTableTypeNodeName(ident
);
135 else if (res
== ITEM_UNQUOTED
)
136 ttn
= findTableTypeNode(strtoul(ident
, NULL
, 0));
139 printf("LINE %d: Unexpected item in TableType\n", line
);
144 printf("LINE %d: Unknown Table %s\n", line
, ident
);
150 printf("LINE %d: Unexpected item after TableType\n", line
);
154 else if (strcasecmp(ident
, "IDLen") == 0)
156 res
= ReadItem(ident
, 256, &csrc
);
157 if (res
== ITEM_ERROR
)
159 else if (res
== ITEM_EQUAL
)
161 res
= ReadItem(ident
, 256, &csrc
);
162 if (res
== ITEM_ERROR
)
164 else if (res
== ITEM_UNQUOTED
)
166 id_len
= strtoul(ident
, NULL
, 0);
169 printf("LINE %d: Illegal value of IDLen\n", line
);
175 printf("LINE %d: Value in IDLen expected\n", line
);
181 printf("LINE %d: Unexpected item after IDLen\n", line
);
185 else if (strcasecmp(ident
, "Default") == 0)
189 res
= ReadItem(ident
, 256, &csrc
);
190 if (res
== ITEM_ERROR
)
192 else if (res
== ITEM_EQUAL
)
194 res
= ReadItem(ident
, 256, &csrc
);
195 if (res
== ITEM_ERROR
)
197 else if (res
== ITEM_QUOTED
)
199 ttn
->defaulttype
.id_len
= id_len
;
200 strcpyESC(ttn
->defaulttype
.id
, ident
);
204 printf("LINE %d: Unexpected expression after Default\n", line
);
210 printf("LINE %d: Unexpected item after IDLen\n", line
);
216 printf("LINE %d: Unknown option '%s'\n", line
, ident
);
222 printf("LINE %d: Missing partition table type or IDLen\n", line
);
228 printf("LINE %d: Unexpected item '%s' in prefs\n", line
, ident
);
236 tn
= AllocMem(sizeof(struct TypeNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
238 return ERROR_NO_FREE_STORE
;
239 tn
->type
.id_len
= id_len
;
240 strcpyESC(tn
->type
.id
, ident
);
241 res
= ReadItem(ident
, 256, &csrc
);
242 if (res
== ITEM_ERROR
)
244 if (res
== ITEM_EQUAL
)
246 res
= ReadItem(ident
, 256, &csrc
);
247 if (res
== ITEM_ERROR
)
249 else if (res
== ITEM_QUOTED
)
251 tn
->ln
.ln_Name
= AllocVec(strlen(ident
)+1, MEMF_PUBLIC
| MEMF_CLEAR
);
252 if (tn
->ln
.ln_Name
== NULL
)
253 return ERROR_NO_FREE_STORE
;
254 strcpy(tn
->ln
.ln_Name
, ident
);
258 printf("LINE %d: Quoted expression expected\n", line
);
264 printf("LINE %d: Unexpected item after table id\n", line
);
267 AddTail(&ttn
->typelist
, &tn
->ln
);
271 printf("LINE %d: Missing partition table type or IDLen\n", line
);
283 void LoadPrefs(STRPTR filename
) {
284 struct FileInfoBlock fib
;
290 getTableTypeList(&tabletypelist
);
291 fh
= Open(filename
, MODE_OLDFILE
);
294 if (ExamineFH(fh
, &fib
))
298 buffer
= AllocMem(fib
.fib_Size
, MEMF_PUBLIC
| MEMF_CLEAR
);
301 size
= Read(fh
, buffer
, fib
.fib_Size
);
302 if (size
== fib
.fib_Size
)
304 retval
= parsePrefs(buffer
, size
);
306 PrintFault(retval
, filename
);
308 FreeMem(buffer
, fib
.fib_Size
);
311 PrintFault(ERROR_NO_FREE_STORE
, filename
);
317 PrintFault(IoErr(), filename
);