Annotation of researchv10no/cmd/cfront/cfront2.00/size.c, revision 1.1.1.1

1.1       root        1: /*ident        "@(#)ctrans:src/size.c  1.1.4.3" */
                      2: /*********************************************************************
                      3: 
                      4:        C++ source for cfront, the C++ compiler front-end
                      5:        written in the computer science research center of Bell Labs
                      6: 
                      7:        Copyright (c) 1984 AT&T, Inc. All rigths Reserved
                      8:        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
                      9: 
                     10: size.c:
                     11: 
                     12:        initialize alignment and sizeof "constants"
                     13: 
                     14: **********************************************************************/
                     15: 
                     16: #include "cfront.h"
                     17: #include "size.h"
                     18: 
                     19: int BI_IN_WORD = DBI_IN_WORD;
                     20: int BI_IN_BYTE = DBI_IN_BYTE;
                     21: int SZ_CHAR = DSZ_CHAR;
                     22: int AL_CHAR = DAL_CHAR;
                     23: int SZ_SHORT = DSZ_SHORT;
                     24: int AL_SHORT = DAL_SHORT;
                     25: int SZ_INT = DSZ_INT;
                     26: int AL_INT = DAL_INT;
                     27: int SZ_LONG = DSZ_LONG;
                     28: int AL_LONG = DAL_LONG;
                     29: int SZ_FLOAT = DSZ_FLOAT;
                     30: int AL_FLOAT = DAL_FLOAT;
                     31: int SZ_DOUBLE = DSZ_DOUBLE;
                     32: int AL_DOUBLE = DAL_DOUBLE;
                     33: int SZ_LDOUBLE = DSZ_LDOUBLE;
                     34: int AL_LDOUBLE = DAL_LDOUBLE;
                     35: int SZ_STRUCT = DSZ_STRUCT;
                     36: int AL_STRUCT = DAL_STRUCT;
                     37: //int SZ_FRAME = DSZ_FRAME;
                     38: //int AL_FRAME = DAL_FRAME;
                     39: int SZ_WORD = DSZ_WORD;
                     40: int SZ_WPTR = DSZ_WPTR;
                     41: int AL_WPTR = DAL_WPTR;
                     42: int SZ_BPTR = DSZ_BPTR;
                     43: int AL_BPTR = DAL_BPTR;
                     44: //int SZ_TOP = DSZ_TOP;
                     45: //int SZ_BOTTOM = DSZ_BOTTOM;
                     46: char* LARGEST_INT = DLARGEST_INT;
                     47: int F_SENSITIVE = DF_SENSITIVE;
                     48: int F_OPTIMIZED =  DF_OPTIMIZED;
                     49: 
                     50: int arg1 = 0;
                     51: int arg2 = 0;
                     52: 
                     53: int get_line(FILE* fp)
                     54: {
                     55:        char s[32];
                     56: 
                     57:        if (fscanf(fp," %s %d %d",s,&arg1,&arg2) == EOF) return 0;
                     58: // fprintf(stderr,"xxx %s %d %d",s,arg1,arg2);
                     59:        if (strcmp("char",s) == 0) {
                     60:                SZ_CHAR = arg1;
                     61:                AL_CHAR = arg2;
                     62:                return 1;
                     63:        }
                     64:        if (strcmp("short",s) == 0) {
                     65:                SZ_SHORT = arg1;
                     66:                AL_SHORT = arg2;
                     67:                return 1;
                     68:        }
                     69:        if (strcmp("int",s) == 0) {
                     70:                SZ_INT = arg1;
                     71:                AL_INT = arg2;
                     72:                if (fscanf(fp," %s",s) == EOF) return 0;
                     73:                LARGEST_INT = new char[strlen(s)+1];
                     74:                strcpy(LARGEST_INT,s);
                     75:                return 1;
                     76:        }
                     77:        if (strcmp("long",s) == 0) {
                     78:                SZ_LONG = arg1;
                     79:                AL_LONG = arg2;
                     80:                return 1;
                     81:        }
                     82:        if (strcmp("float",s) == 0) {
                     83:                SZ_FLOAT = arg1;
                     84:                AL_FLOAT = arg2;
                     85:                return 1;
                     86:        }
                     87:        if (strcmp("double",s) == 0) {
                     88:                SZ_DOUBLE = arg1;
                     89:                AL_DOUBLE = arg2;
                     90:                return 1;
                     91:        }
                     92:        if (strcmp("ldouble",s) == 0) {
                     93:                SZ_LDOUBLE = arg1;
                     94:                AL_LDOUBLE = arg2;
                     95:                return 1;
                     96:        }
                     97:        if (strcmp("bit",s) == 0) {
                     98:                BI_IN_BYTE = arg1;
                     99:                BI_IN_WORD = arg2;
                    100:                return 1;
                    101:        }
                    102:        if (strcmp("struct",s) == 0) {
                    103:                SZ_STRUCT = arg1;
                    104:                AL_STRUCT = arg2;
                    105:                return 1;
                    106:        }
                    107:        if (strcmp("struct2",s) == 0) {
                    108:                F_SENSITIVE = arg1;
                    109:                F_OPTIMIZED = arg2;
                    110:                return 1;
                    111:        }
                    112:        if (strcmp("frame",s) == 0) {
                    113: //             SZ_FRAME = arg1;
                    114: //             AL_FRAME = arg2;
                    115:                return 1;
                    116:        }
                    117:        if (strcmp("word",s) == 0) {
                    118:                SZ_WORD = arg1;
                    119:                return 1;
                    120:        }
                    121:        if (strcmp("wptr",s) == 0) {
                    122:                SZ_WPTR = arg1;
                    123:                AL_WPTR = arg2;
                    124:                return 1;
                    125:        }
                    126:        if (strcmp("bptr",s) == 0) {
                    127:                SZ_BPTR = arg1;
                    128:                AL_BPTR = arg2;
                    129:                return 1;
                    130:        }
                    131:        if (strcmp("top",s) == 0) {
                    132: //             SZ_TOP = arg1;
                    133: //             SZ_BOTTOM = arg2;
                    134:                return 1;
                    135:        }
                    136:        return 0;
                    137: }
                    138: 
                    139: int read_align(char* f)
                    140: {
                    141:        char* p = f;
                    142:        if (*p == 0) {
                    143:                fprintf(stderr,"size/align file missing\n");
                    144:                ext(1);
                    145:        }
                    146:        FILE* fp = fopen(f,"r");
                    147:        if (fp == 0) return 1;
                    148:        while (get_line(fp)) ;
                    149:        return 0;
                    150: }
                    151: /*
                    152: print_align(char* s)
                    153: {
                    154:        fprintf(stderr,"%s sizes and alignments\n\n",s);
                    155: 
                    156:        fprintf(stderr,"        size    align   largest\n");
                    157:        fprintf(stderr,"char    %d      %d\n",SZ_CHAR,AL_CHAR);
                    158:        fprintf(stderr,"short   %d      %d\n",SZ_SHORT,AL_SHORT);
                    159:        fprintf(stderr,"int     %d      %d      %s\n",SZ_INT,AL_INT,LARGEST_INT);
                    160:        fprintf(stderr,"long    %d      %d\n",SZ_LONG,AL_LONG);
                    161:        fprintf(stderr,"float   %d      %d\n",SZ_FLOAT,AL_FLOAT);
                    162:        fprintf(stderr,"double  %d      %d\n",SZ_DOUBLE,AL_DOUBLE);
                    163:        fprintf(stderr,"ldouble %d      %d\n",SZ_LDOUBLE,AL_LDOUBLE);
                    164:        fprintf(stderr,"bptr    %d      %d\n",SZ_BPTR,AL_BPTR);
                    165:        fprintf(stderr,"wptr    %d      %d\n",SZ_WPTR,AL_WPTR);
                    166:        fprintf(stderr,"struct  %d      %d\n",SZ_STRUCT,AL_STRUCT);
                    167:        fprintf(stderr,"struct2 %d      %d\n",F_SENSITIVE,F_OPTIMIZED);
                    168: //     fprintf(stderr,"frame   %d      %d\n",SZ_FRAME,AL_FRAME);
                    169: 
                    170:        fprintf(stderr,"%d bits in a byte, %d bits in a word, %d bytes in a word\n",
                    171:                        BI_IN_BYTE, BI_IN_WORD, SZ_WORD);
                    172:        return 1;
                    173: }
                    174: */
                    175: 
                    176: int c_strlen(const char* s)
                    177: /*
                    178:        return sizeof(s) with escapes processed
                    179:        sizeof("") == 1         the terminating 0
                    180:        sizeof("a") == 2
                    181:        sizeof("\0x") == 3      0 x 0
                    182:        sizeof("\012") == 2     '\012'
                    183:        sizeof("\01")           '\001'
                    184:        sizeof("\x") == 2       \ ignored
                    185: 
                    186: */
                    187: {
                    188:        int i = 1;
                    189:         for (const char* p = s; *p; i++,p++) {
                    190:                if (*p == '\\') {                                       // '\?
                    191:                        switch (*++p) {
                    192:                        case '0':
                    193:                                switch (p[1]) {         // '\01' or '\012'
                    194:                                case '0': case '1': case '2': case '3':
                    195:                                case '4': case '5': case '6': case '7':
                    196:                                        break;
                    197:                                default:
                    198:                                        continue;       // '\0'
                    199:                                }
                    200:                                /* no break */
                    201:                        case '1': case '2': case '3':
                    202:                        case '4': case '5': case '6': case '7':         // '\123'
                    203:                                switch (*++p) {
                    204:                                case '0': case '1': case '2': case '3':
                    205:                                case '4': case '5': case '6': case '7':
                    206:                                        switch (*++p) {
                    207:                                        case '0': case '1': case '2': case '3':
                    208:                                        case '4': case '5': case '6': case '7':
                    209:                                                break;
                    210:                                        default:
                    211:                                                --p;
                    212:                                        }
                    213:                                        break;
                    214:                                default:
                    215:                                        --p;
                    216:                                }
                    217:                        }
                    218:                }
                    219:        }
                    220:        return i;
                    221: }

unix.superglobalmegacorp.com

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