Annotation of researchv10no/cmd/cfront/ptcfront/size.c, revision 1.1

1.1     ! root        1: /*ident        "@(#)ctrans:src/size.c  1.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: 
        !            52: int get_line(FILE* fp)
        !            53: {
        !            54:        char s[32];
        !            55:        char s2[32];
        !            56: 
        !            57:        if (fscanf(fp,"%s %s",s2,s) == EOF) return 0;
        !            58: 
        !            59:        if (strcmp("DLARGEST_INT",s) == 0) { 
        !            60:                if (fscanf(fp," %s",s2)==EOF) return 0;
        !            61: //// get rid of quotes
        !            62:                for(int i=0;i<=strlen(s2)+1;i++)
        !            63:                        if (s2[i]== '"') {
        !            64:                                for (int j=i;j<=strlen(s2)+1;j++)
        !            65:                                        s2[j]=s2[j+1];
        !            66:                        }
        !            67:                }
        !            68:        else 
        !            69:                if (fscanf(fp,"%d ",&arg1) == EOF) return 0;
        !            70: 
        !            71:        if (strcmp("DSZ_CHAR",s) == 0) {
        !            72:                SZ_CHAR = arg1;
        !            73:                return 1;
        !            74:        }
        !            75: 
        !            76:        if (strcmp("DAL_CHAR",s) == 0) {
        !            77:                AL_CHAR = arg1;
        !            78:                return 1;
        !            79:        }
        !            80: 
        !            81:        if (strcmp("DSZ_SHORT",s) == 0) {
        !            82:                SZ_SHORT = arg1;
        !            83:                return 1;
        !            84:        }
        !            85:        
        !            86:        if (strcmp("DAL_SHORT",s) == 0) {
        !            87:                AL_SHORT = arg1;
        !            88:                return 1;
        !            89:        }
        !            90: 
        !            91:        if (strcmp("DSZ_INT",s) == 0) {
        !            92:                SZ_INT = arg1;
        !            93:                return 1;
        !            94:        }
        !            95: 
        !            96:        if (strcmp("DAL_INT",s) == 0) {
        !            97:                AL_INT=arg1;
        !            98:                return 1;
        !            99:        }
        !           100: 
        !           101:        if (strcmp("DLARGEST_INT",s) == 0) {
        !           102:                LARGEST_INT = new char[strlen(s2)+1];
        !           103:                strcpy(LARGEST_INT,s2);
        !           104:                return 1;
        !           105:        }
        !           106: 
        !           107:        if (strcmp("DSZ_LONG",s) == 0) {
        !           108:                SZ_LONG = arg1;
        !           109:                return 1;
        !           110:        }
        !           111: 
        !           112:        if (strcmp("DAL_LONG",s) == 0) {
        !           113:                AL_LONG = arg1;
        !           114:                return 1;
        !           115:        }
        !           116: 
        !           117:        if (strcmp("DSZ_FLOAT",s) == 0) {
        !           118:                SZ_FLOAT = arg1;
        !           119:                return 1;
        !           120:        }
        !           121: 
        !           122:        if (strcmp("DAL_FLOAT",s) == 0) {
        !           123:                AL_FLOAT = arg1;
        !           124:                return 1;
        !           125:        }
        !           126: 
        !           127:        if (strcmp("DSZ_DOUBLE",s) == 0) {
        !           128:                SZ_DOUBLE = arg1;
        !           129:                return 1;
        !           130:        }
        !           131: 
        !           132:        if (strcmp("DAL_DOUBLE",s) == 0) {
        !           133:                AL_DOUBLE = arg1;
        !           134:                return 1;
        !           135:        }
        !           136:        
        !           137:        if (strcmp("DSZ_LDOUBLE",s) == 0) {
        !           138:                SZ_LDOUBLE = arg1;
        !           139:                return 1;
        !           140:        }
        !           141: 
        !           142:        if (strcmp("DAL_LDOUBLE",s) == 0) {
        !           143:                AL_LDOUBLE = arg1;
        !           144:                return 1;
        !           145:        }
        !           146: 
        !           147:        if (strcmp("DBI_IN_BYTE",s) == 0) {
        !           148:                BI_IN_BYTE = arg1;
        !           149:                return 1;
        !           150:        }
        !           151: 
        !           152:        if (strcmp("DBI_IN_WORD",s) == 0) {
        !           153:                BI_IN_WORD= arg1;
        !           154:                return 1;
        !           155:        }
        !           156: 
        !           157:        if (strcmp("DSZ_STRUCT",s) == 0) {
        !           158:                SZ_STRUCT = arg1;
        !           159:                return 1;
        !           160:        }
        !           161: 
        !           162:        if (strcmp("DAL_STRUCT",s) == 0) {
        !           163:                AL_STRUCT = arg1;
        !           164:                return 1;
        !           165:        }
        !           166: 
        !           167:        if (strcmp("DF_SENSITIVE",s) == 0) {
        !           168:                F_SENSITIVE = arg1;
        !           169:                return 1;
        !           170:        }
        !           171: 
        !           172:        if (strcmp("DF_OPTIMIZED",s) == 0) {
        !           173:                F_OPTIMIZED = arg1;
        !           174:                return 1;
        !           175:        }
        !           176: 
        !           177:        if (strcmp("frame",s) == 0) {
        !           178: //             SZ_FRAME = arg1;
        !           179: //             AL_FRAME = arg2;
        !           180:                return 1;
        !           181:        }
        !           182: 
        !           183:        if (strcmp("DSZ_WORD",s) == 0) {
        !           184:                SZ_WORD = arg1;
        !           185:                return 1;
        !           186:        }
        !           187: 
        !           188:        if (strcmp("DSZ_WPTR",s) == 0) {
        !           189:                SZ_WPTR = arg1;
        !           190:                return 1;
        !           191:        }
        !           192: 
        !           193:        if (strcmp("DAL_WPTR",s) == 0) {
        !           194:                AL_WPTR = arg1;
        !           195:                return 1;
        !           196:        }
        !           197: 
        !           198:        if (strcmp("DSZ_BPTR",s) == 0) {
        !           199:                SZ_BPTR = arg1;
        !           200:                return 1;
        !           201:        }
        !           202: 
        !           203:        if (strcmp("DAL_BPTR",s) == 0) {
        !           204:                AL_BPTR = arg1;
        !           205:                return 1;
        !           206:        }
        !           207: 
        !           208:        if (strcmp("top",s) == 0) {
        !           209: //             SZ_TOP = arg1;
        !           210: //             SZ_BOTTOM = arg2;
        !           211:                return 1;
        !           212:        }
        !           213:        return 0;
        !           214: }
        !           215: 
        !           216: int read_align(char* f)
        !           217: {
        !           218:        char* p = f;
        !           219:        if (*p == 0) {
        !           220:                fprintf(stderr,"size/align file missing\n");
        !           221:                ext(1);
        !           222:        }
        !           223:        FILE* fp = fopen(f,"r");
        !           224:        if (fp == 0) return 1;
        !           225:        while (get_line(fp)) ;
        !           226:        return 0;
        !           227: }
        !           228: /*
        !           229: print_align(char* s)
        !           230: {
        !           231:        fprintf(stderr,"%s sizes and alignments\n\n",s);
        !           232: 
        !           233:        fprintf(stderr,"        size    align   largest\n");
        !           234:        fprintf(stderr,"char    %d      %d\n",SZ_CHAR,AL_CHAR);
        !           235:        fprintf(stderr,"short   %d      %d\n",SZ_SHORT,AL_SHORT);
        !           236:        fprintf(stderr,"int     %d      %d      %s\n",SZ_INT,AL_INT,LARGEST_INT);
        !           237:        fprintf(stderr,"long    %d      %d\n",SZ_LONG,AL_LONG);
        !           238:        fprintf(stderr,"float   %d      %d\n",SZ_FLOAT,AL_FLOAT);
        !           239:        fprintf(stderr,"double  %d      %d\n",SZ_DOUBLE,AL_DOUBLE);
        !           240:        fprintf(stderr,"ldouble %d      %d\n",SZ_LDOUBLE,AL_LDOUBLE);
        !           241:        fprintf(stderr,"bptr    %d      %d\n",SZ_BPTR,AL_BPTR);
        !           242:        fprintf(stderr,"wptr    %d      %d\n",SZ_WPTR,AL_WPTR);
        !           243:        fprintf(stderr,"struct  %d      %d\n",SZ_STRUCT,AL_STRUCT);
        !           244:        fprintf(stderr,"struct2 %d      %d\n",F_SENSITIVE,F_OPTIMIZED);
        !           245: //     fprintf(stderr,"frame   %d      %d\n",SZ_FRAME,AL_FRAME);
        !           246: 
        !           247:        fprintf(stderr,"%d bits in a byte, %d bits in a word, %d bytes in a word\n",
        !           248:                        BI_IN_BYTE, BI_IN_WORD, SZ_WORD);
        !           249:        return 1;
        !           250: }
        !           251: */
        !           252: 
        !           253: int c_strlen(const char* s)
        !           254: /*
        !           255:        return sizeof(s) with escapes processed
        !           256:        sizeof("") == 1         the terminating 0
        !           257:        sizeof("a") == 2
        !           258:        sizeof("\0x") == 3      0 x 0
        !           259:        sizeof("\012") == 2     '\012'
        !           260:        sizeof("\01")           '\001'
        !           261:        sizeof("\x") == 2       \ ignored
        !           262: 
        !           263: */
        !           264: {
        !           265:        int i = 1;
        !           266:         for (const char* p = s; *p; i++,p++) {
        !           267:                if (*p == '\\') {                                       // '\?
        !           268:                        switch (*++p) {
        !           269:                        case '0':
        !           270:                                switch (p[1]) {         // '\01' or '\012'
        !           271:                                case '0': case '1': case '2': case '3':
        !           272:                                case '4': case '5': case '6': case '7':
        !           273:                                        break;
        !           274:                                default:
        !           275:                                        continue;       // '\0'
        !           276:                                }
        !           277:                                /* no break */
        !           278:                        case '1': case '2': case '3':
        !           279:                        case '4': case '5': case '6': case '7':         // '\123'
        !           280:                                switch (*++p) {
        !           281:                                case '0': case '1': case '2': case '3':
        !           282:                                case '4': case '5': case '6': case '7':
        !           283:                                        switch (*++p) {
        !           284:                                        case '0': case '1': case '2': case '3':
        !           285:                                        case '4': case '5': case '6': case '7':
        !           286:                                                break;
        !           287:                                        default:
        !           288:                                                --p;
        !           289:                                        }
        !           290:                                        break;
        !           291:                                default:
        !           292:                                        --p;
        !           293:                                        break;
        !           294:                                }
        !           295:                                break;
        !           296:                        case '\n':                      // \newline doesn't count
        !           297:                                i--;
        !           298:                                break;
        !           299:                        }
        !           300:                }
        !           301:        }
        !           302:        return i;
        !           303: }

unix.superglobalmegacorp.com

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