|
|
1.1 ! root 1: /* ! 2: * 80386 assembler common functions. ! 3: */ ! 4: #include <asm.h> ! 5: ! 6: /* ! 7: * Open a file or die in the attempt. ! 8: */ ! 9: FILE * ! 10: xopen(fn, acs) ! 11: char *fn, *acs; ! 12: { ! 13: FILE *tmp; ! 14: ! 15: if (NULL == (tmp = fopen(fn, acs))) ! 16: fatal("Cannot fopen(%s, %s)", fn, acs); /**/ ! 17: return (tmp); ! 18: } ! 19: ! 20: /* ! 21: * Make a new copy of a string into tmp space. ! 22: * in temp space on a struct. ! 23: */ ! 24: char * ! 25: gcpy(id, disp) ! 26: register char *id; ! 27: register unsigned disp; ! 28: { ! 29: register char *tmp; ! 30: ! 31: tmp = galloc(strlen(id) + 1 + disp); ! 32: strcpy(tmp + disp, id); ! 33: return(tmp); ! 34: } ! 35: ! 36: /* ! 37: * Make a new copy of a string. ! 38: * in temp space on a struct. ! 39: */ ! 40: ! 41: char * ! 42: scpy(id, disp) ! 43: register char *id; ! 44: register unsigned disp; ! 45: { ! 46: register char *tmp; ! 47: ! 48: tmp = alloc(strlen(id) + 1 + disp); ! 49: strcpy(tmp + disp, id); ! 50: return(tmp); ! 51: } ! 52: ! 53: /* ! 54: * Trim surrounding spaces and tabs. ! 55: */ ! 56: char * ! 57: trim(s) ! 58: char *s; ! 59: { ! 60: register char *p, c; ! 61: ! 62: for(p = strchr(s, '\0'); --p > s; ) ! 63: if((' ' == (c = *p)) || ('\t' == c)) ! 64: *p = '\0'; ! 65: else ! 66: break; ! 67: ! 68: for(p = s; (' ' == (c = *p)) || ('\t' == c); p++) ! 69: ; ! 70: return(p); ! 71: } ! 72: ! 73: /* ! 74: * Count structs with a next or prev pointer as the first item. ! 75: */ ! 76: short ! 77: countList(p) ! 78: parm *p; ! 79: { ! 80: register short n; ! 81: ! 82: for(n = 0; NULL != p; p = p->next) ! 83: n++; ! 84: ! 85: return(n); ! 86: } ! 87: ! 88: /* ! 89: * Find a parm by name. Return it or NULL. ! 90: */ ! 91: char * ! 92: lookList(t) ! 93: char *t; ! 94: { ! 95: short n; ! 96: register parm *p; ! 97: ! 98: for((p = trueMac->names), (n = 0); NULL != p; p = p->next) { ! 99: if(!strcmp(t, p->str)) ! 100: return(parmFind(n, trueMac->parms)); ! 101: n++; ! 102: } ! 103: if(!strcmp(".macno", t)) { ! 104: static char buf[6]; ! 105: ! 106: sprintf(buf, "%d", trueMac->expno); ! 107: return(buf); ! 108: } ! 109: return(NULL); ! 110: } ! 111: ! 112: /* ! 113: * Find parm n. ! 114: */ ! 115: char * ! 116: parmFind(n, p) ! 117: short n; ! 118: register parm *p; ! 119: { ! 120: for(; NULL != p; p = p->next) ! 121: if(!n--) ! 122: return(p->str); ! 123: return(""); ! 124: } ! 125: ! 126: /* ! 127: * Do shift operation. ! 128: */ ! 129: void ! 130: doShift(n) ! 131: short n; ! 132: { ! 133: register parm *p, **pp; ! 134: short sav = n; ! 135: ! 136: if(NULL == trueMac) ! 137: yyerror(".shift not in macro"); ! 138: /* \fB.shift\fR shifts macro parameters. ! 139: * It has no meaning outside a macro. */ ! 140: for(pp = &(trueMac->parms); NULL != (p = *pp); pp = &(p->next)) { ! 141: if(--n == 0) { ! 142: *pp = p->next; ! 143: free((char *)p); ! 144: return; ! 145: } ! 146: } ! 147: yyerror("Parm %d not found", sav); ! 148: /* An attempt to \fB.shift\fR too far has been made. */ ! 149: } ! 150: ! 151: /* ! 152: * push a new logic level. ! 153: */ ! 154: void ! 155: newLevel(type) ! 156: { ! 157: macctl *mac; ! 158: ! 159: mac = new(macctl); ! 160: mac->type = type; ! 161: if(NULL != trueMac) ! 162: mac->expno = trueMac->expno; ! 163: mac->prev = logic; ! 164: logic = mac; ! 165: } ! 166: ! 167: /* ! 168: * Pop a logic level. ! 169: */ ! 170: void ! 171: freeLevel() ! 172: { ! 173: macctl *tmp; ! 174: ! 175: logic = (tmp = logic)->prev; ! 176: free((char *)tmp); ! 177: } ! 178: ! 179: /* ! 180: * Open a file ! 181: */ ! 182: void ! 183: fileOpen(fn) ! 184: char *fn; ! 185: { ! 186: inpctl *ip; ! 187: ! 188: /* ! 189: * NIGEL: Hack this up so that after the string is copied into the ! 190: * temp space we try and strip quote-marks. This job made a little ! 191: * harder because Charles was a perverse son-of-a-bitch and used ! 192: * flex-arrays. ! 193: */ ! 194: ! 195: ip = (inpctl *)scpy(fn, offset(inpctl, name)); ! 196: ! 197: if (* ip->name == '"') { ! 198: int len = strlen (ip->name); ! 199: ! 200: if (ip->name [len - 1] == '"') { ! 201: strncpy (ip->name, fn + 1, len - 2); ! 202: ip->name [len - 2] = 0; ! 203: } ! 204: } ! 205: ! 206: ip->fp = xopen (ip->name, "r"); ! 207: ip->prev = inpc; ! 208: inpc = ip; ! 209: } ! 210: ! 211: /* ! 212: * Check for no truncation to short. ! 213: */ ! 214: ck16(n) ! 215: register long n; ! 216: { ! 217: register short i; ! 218: ! 219: /* PMC: LINT: OK. Intentional Loss of accuracy. */ ! 220: i = n; ! 221: return(i != n); ! 222: } ! 223: ! 224: /* ! 225: * Build a label. ! 226: */ ! 227: void ! 228: buildlab(label) ! 229: parm *label; ! 230: { ! 231: if(NULL != label) ! 232: symLookUp(label->str, S_LOCAL, dot.loc, dot.sg); ! 233: } ! 234: ! 235: /* ! 236: * Label ignored message. ! 237: */ ! 238: void ! 239: labelIgnored(label) ! 240: parm *label; ! 241: { ! 242: if (NULL != label) ! 243: yyerror("Label ignored"); ! 244: /* This statement cannot take a label. */ ! 245: } ! 246: ! 247: /* ! 248: * Table error detected. ! 249: */ ! 250: kindErr(kind) ! 251: unsigned short kind; ! 252: { ! 253: fatal("Table error kind %x detected", kind); /* TECH */ ! 254: } ! 255: ! 256: /* ! 257: * Find a name on a char ** and return index. ! 258: */ ! 259: nameList(n, nl) ! 260: register char *n, **nl; ! 261: { ! 262: register i; ! 263: ! 264: for(i = 0; (NULL != *nl) && strcmp(n, *nl); i++, nl++) ! 265: ; ! 266: return(i); ! 267: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.