Annotation of Examples/DriverKit/S3/S3_reloc.tproj/S3ConfigTable.m, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1993 by NeXT Computer, Inc.
                      2:  * All rights reserved.
                      3:  *
                      4:  * S3.m -- driver for S3 86C805 and 86C928 Graphics Accelerators
                      5:  *
                      6:  * Created:
                      7:  *  7 July 1993                Derek B Clegg
                      8:  */
                      9: #import <string.h>
                     10: #import "S3.h"
                     11: 
                     12: /* The `ConfigTable' category of `S3'. */
                     13: 
                     14: @implementation S3 (ConfigTable)
                     15: 
                     16: - (const char *)valueForStringKey:(const char *)key
                     17: {
                     18:     IOConfigTable *configTable;
                     19:     configTable = [[self deviceDescription] configTable];
                     20:     if (configTable == nil)
                     21:        return 0;
                     22:     return [configTable valueForStringKey:key];
                     23: }
                     24: 
                     25: static inline int 
                     26: isWhiteSpace(int c)
                     27: {
                     28:     return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
                     29: }
                     30: 
                     31: static int
                     32: readHexValue(const char **s)
                     33: {
                     34:     int c, value;
                     35:     const char *string;
                     36: 
                     37:     string = *s;
                     38:     while ((c = *string) != '\0' && isWhiteSpace(c))
                     39:        string++;
                     40:     if (c == '\0') {
                     41:        *s = string;
                     42:        return -1;
                     43:     }
                     44:     value = 0;
                     45:     while ((c = *string) != '\0' && !isWhiteSpace(c)) {
                     46:        if (c >= '0' && c <= '9')
                     47:            value = (value << 4) | (c - '0');
                     48:        else if (c >= 'A' && c <= 'F')
                     49:            value = (value << 4) | (c - 'A' + 10);
                     50:        else if (c >= 'a' && c <= 'f')
                     51:            value = (value << 4) | (c - 'a' + 10);
                     52:        else
                     53:            break;
                     54:        string++;
                     55:     }
                     56:     *s = string;
                     57:     return (value & 0xFF);
                     58: }
                     59: 
                     60: - (int)parametersForMode:(const char *)modeName
                     61:        forStringKey:(const char *)key
                     62:        parameters:(char *)parameters
                     63:        count:(int)count
                     64: {
                     65:     int k, value;
                     66:     const char *s;
                     67:     char modeKey[strlen(modeName) + 1 + strlen(key) + 1];
                     68: 
                     69:     strcpy(modeKey, modeName);
                     70:     strcat(modeKey, " ");
                     71:     strcat(modeKey, key);
                     72:     s = [self valueForStringKey:modeKey];
                     73:     if (s == 0)
                     74:        return -1;
                     75: 
                     76:     k = 0;
                     77:     for (k = 0; k < count; k++) {
                     78:        value = readHexValue(&s);
                     79:        if (value == -1)
                     80:            break;
                     81:        parameters[k] = value;
                     82:     }
                     83:     return k;
                     84: }
                     85: 
                     86: - (BOOL)booleanForStringKey:(const char *)key withDefault:(BOOL)defaultValue
                     87: {
                     88:     const char *value;
                     89: 
                     90:     value = [self valueForStringKey:key];
                     91:     if (value == 0)
                     92:        return defaultValue;
                     93:     
                     94:     if (value[0] == 'Y' || value[0] == 'y') {
                     95:        if (value[1] == '\0'
                     96:            || ((value[1] == 'E' || value[1] == 'e')
                     97:                && (value[2] == 'S' || value[2] == 's')
                     98:                && value[3] == '\0')) {
                     99:            return YES;
                    100:        }
                    101:     } else if (value[0] == 'N' || value[0] == 'n') {
                    102:        if (value[1] == '\0'
                    103:            || ((value[1] == 'O' || value[1] == 'o')
                    104:                && value[2] == '\0')) {
                    105:            return NO;
                    106:        }
                    107:     }
                    108:     IOLog("%s: Unrecognized value for key `%s': `%s'.\n",
                    109:          [self name], key, value);
                    110:     return defaultValue;
                    111: }
                    112: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.