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