2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
30 #import "kernBootStruct.h"
31 #import "stringConstants.h"
32 #import <driverkit/configTablePrivate.h>
34 extern KERNBOOTSTRUCT
*kernBootStruct
;
35 extern char *Language
;
36 extern char *LoadableFamilies
;
44 register char *str
= *string_p
;
75 * <non_space_non_semicolon>*
90 r
= getachar(string_p
);
91 } while (r
.c
&& isspace(r
.c
));
93 if (!r
.quoted
&& r
.c
== '\"') {
96 r
= getachar(string_p
);
97 } while (r
.c
&& !r
.quoted
&& r
.c
!= '\"');
99 begin
= *string_p
- 1;
101 r
= getachar(string_p
);
102 } while (r
.c
&& !r
.quoted
&& r
.c
!= ';' && !isspace(r
.c
));
104 len
= *string_p
- begin
- 1;
105 newstr
= (char *)malloc(len
+ 1);
106 strncpy(newstr
, begin
, len
);
118 char *begin
= *list
, *end
;
122 while (*begin
&& newsize
&& isspace(*begin
)) {
127 while (*end
&& newsize
&& !isspace(*end
)) {
133 newstr
= malloc(end
- begin
+ 1);
134 strncpy(newstr
, begin
, end
- begin
);
141 valueForStringTableKey(
161 token
= get_token(&table
);
164 if (strcmp(token
, key
) == 0)
166 if (strncmp(token
, "/*", 2) == 0)
172 if (strcmp(token
, "=") == 0) {
183 if (strcmp(token
, ";") == 0) {
189 if (len
>= 2 && strncmp(token
+ len
- 2, "*/", 2) == 0)
216 token
= get_token(&line
);
225 char *str
= valueForKey(key
);
228 if (str
&& (str
[0] == 'Y' || str
[1] == 'y'))
242 char *str
= valueForKey(key
), *ptr
= str
;
247 for (sum
= 0; size
> 0; size
--) {
248 sum
= (sum
* 10) + (*ptr
++ - '0');
264 char *str
= valueForBootKey(kernBootStruct
->bootString
, key
);;
269 return valueForStringTableKey(kernBootStruct
->config
, key
);
272 #define LOCALIZABLE_PATH \
273 "%s/%s.config/%s.lproj/%s.strings"
275 loadLocalizableStrings(
280 char buf
[256], *config
;
281 register int i
, count
, fd
= -1;
289 for (i
=0; i
<2; i
++) {
290 for (path
= paths
; *path
; path
++) {
291 sprintf(buf
, LOCALIZABLE_PATH
, *path
, name
,
292 (i
== 0) ? Language
: "English", tableName
);
293 if ((fd
= open(buf
, 0)) >= 0) {
301 count
= file_size(fd
);
302 config
= malloc(count
);
303 count
= read(fd
, config
, count
);
318 char *table
, *name
, *val
;
321 table
= loadLocalizableStrings(bundleName
,
322 tableName
? tableName
: "Localizable");
324 getValueForStringTableKey(table
,"Long Name", &val
, &size
) == YES
) {
325 name
= malloc(size
+1);
326 strncpy(name
, val
, size
);
329 name
= newString(bundleName
);
341 char *configPtr
= kernBootStruct
->configEnd
;
342 int len
= strlen(config
);
344 if ((configPtr
- kernBootStruct
->config
) > CONFIG_SIZE
) {
345 error("No room in memory for config files\n");
348 strcpy(configPtr
, config
);
349 configPtr
+= (len
+ 1);
351 kernBootStruct
->configEnd
= configPtr
;
355 * Returns 0 if file loaded OK,
356 * -1 if file was not loaded
357 * Does not print error messages.
358 * Returns pointer to table in memory in *table.
361 loadConfigFile( char *configFile
, char **table
, BOOL allocTable
)
363 char *configPtr
= kernBootStruct
->configEnd
;
366 /* Read config file into memory */
367 if ((fd
= open(configFile
, 0)) >= 0)
370 configPtr
= malloc(file_size(fd
)+2);
372 if ((configPtr
- kernBootStruct
->config
) > CONFIG_SIZE
) {
373 error("No room in memory for config files\n");
377 verbose("Reading configuration file '%s'.\n",configFile
);
379 if (table
) *table
= configPtr
;
380 count
= read(fd
, configPtr
, IO_CONFIG_DATA_SIZE
);
387 kernBootStruct
->configEnd
= configPtr
;
395 /* Returns 0 if requested config files were loaded,
396 * 1 if default files were loaded,
397 * -1 if no files were loaded.
398 * Prints error message if files cannot be loaded.
403 char *bundleName
, // bundle directory name (e.g. "System")
404 BOOL useDefault
, // use Default.table instead of instance tables
405 char **table
, // returns pointer to config table
406 BOOL allocTable
// malloc the table and return in *table
411 BOOL archConfig
= dirExists(ARCH_DEVICES
);
416 // load up to 99 instance tables
417 for (i
=0; i
< 99; i
++) {
418 sprintf(buf
, "%s/%s.config/Instance%d.table",
419 archConfig
? ARCH_DEVICES
: USR_DEVICES
,
421 if (useDefault
|| (loadConfigFile(buf
, table
, allocTable
) != 0)) {
423 // couldn't load first instance table;
424 // try the default table
425 sprintf(buf
, "%s/%s.config/%s",
426 archConfig
? ARCH_DEVICES
: USR_DEVICES
,
428 IO_DEFAULT_TABLE_FILENAME
);
429 if (loadConfigFile(buf
, table
, allocTable
) == 0) {
433 error("Config file \"%s\" not found\n", buf
);
446 #define USR_SYSTEM_CONFIG \
447 USR_DEVICES "/System.config"
448 #define USR_SYSTEM_DEFAULT_FILE \
449 USR_SYSTEM_CONFIG "/Default.table"
450 #define ARCH_SYSTEM_CONFIG \
451 ARCH_DEVICES "/System.config"
452 #define ARCH_SYSTEM_DEFAULT_FILE \
453 ARCH_SYSTEM_CONFIG "/Default.table"
454 #define SYSTEM_CONFIG "System"
458 /* Returns 0 if requested config files were loaded,
459 * 1 if default files were loaded,
460 * -1 if no files were loaded.
461 * Prints error message if files cannot be loaded.
470 int ret
, len
, doDefault
=0;
471 BOOL archConfig
= dirExists(ARCH_DEVICES
);
473 buf
= bp
= malloc(256);
476 for(cp
= which
, len
= size
; len
&& *cp
&& *cp
!= LP
; cp
++, len
--) ;
478 while (len
-- && *cp
&& *cp
++ != RP
) ;
479 /* cp now points past device */
480 strncpy(buf
,which
,cp
- which
);
487 strcpy(bp
, archConfig
?
488 ARCH_SYSTEM_CONFIG
: USR_SYSTEM_CONFIG
);
490 strncat(bp
, cp
, len
);
491 if (strncmp(cp
+ len
- strlen(IO_TABLE_EXTENSION
),
492 IO_TABLE_EXTENSION
, strlen(IO_TABLE_EXTENSION
)) != 0)
493 strcat(bp
, IO_TABLE_EXTENSION
);
495 strncpy(bp
, cp
, len
);
498 if ((strcmp(bp
, USR_SYSTEM_DEFAULT_FILE
) == 0) ||
499 (strcmp(bp
, ARCH_SYSTEM_DEFAULT_FILE
) == 0))
501 ret
= loadConfigFile(bp
= buf
, 0, 0);
503 ret
= loadConfigDir((bp
= SYSTEM_CONFIG
), 0, 0, 0);
506 error("System config file '%s' not found\n", bp
);
510 return (ret
< 0 ? ret
: doDefault
);
524 if (getValueForKey( "Boot Drivers", &val
, &count
))
526 while (string
= stringFromList(&val
, &count
)) {
527 ret
= loadConfigDir(string
, useDefault
, &table
, 0);
529 if ((fd
= openDriverReloc(string
)) >= 0) {
530 verbose("Loading binary for %s device driver.\n",string
);
531 if (loadDriver(string
, fd
) < 0)
532 error("Error loading %s device driver.\n",string
);
535 driverWasLoaded(string
, table
, NULL
);
538 driverIsMissing(string
);
542 error("Warning: No active drivers specified in system config.\n");
545 kernBootStruct
->first_addr0
=
546 (int)kernBootStruct
->configEnd
+ 1024;
551 dirExists(char *path
)
555 if ((fd
= open(path
, 0)) < 0) {