|
|
1.1 ! root 1: #include "mk.h" ! 2: ! 3: #define FOLD 65 ! 4: ! 5: static char *first = 0; ! 6: static didit; ! 7: ! 8: maketarget(s) ! 9: char *s; ! 10: { ! 11: if(first == 0) ! 12: first = s; ! 13: } ! 14: ! 15: addmake(n) ! 16: Node *n; ! 17: { ! 18: symlook(n->name, S_MAKEFILE, (char *)n); ! 19: } ! 20: ! 21: static ! 22: fold(s, sep) ! 23: char *s; ! 24: { ! 25: int i = 0; ! 26: ! 27: while(*s){ ! 28: i++; ! 29: if((*s == ' ') && (i > FOLD)){ ! 30: Fprint(1, "\\\n%c", sep); ! 31: i = 0; ! 32: } else ! 33: Fputc(1, *s++); ! 34: } ! 35: } ! 36: ! 37: static void ! 38: vd(s) ! 39: register Symtab *s; ! 40: { ! 41: Fprint(1, "%s=", s->name); ! 42: fold(symlook(s->name, S_VAR, (char *)0)->value, ' '); ! 43: Fputc(1, '\n'); ! 44: } ! 45: ! 46: #define SUB(s) { register char *ss = s; while(*dest++ = *ss++); dest--; copy = 0; } ! 47: ! 48: static char * ! 49: vexpand(ww, dest, j) ! 50: char **ww, *dest; ! 51: Job *j; ! 52: { ! 53: register char *s, *w = *ww; ! 54: char carry, *q; ! 55: int copy; ! 56: ! 57: assert("vexpand no $", *w == '$'); ! 58: if(*++w == '{'){ ! 59: for(s = ++w; *s != '}'; s++) ! 60: if(*s == 0) break; ! 61: } else ! 62: s = shname(w); ! 63: carry = *s; ! 64: *s = 0; ! 65: copy = 1; ! 66: if(!symlook(w, S_MAKEVAR, (char *)0)){ ! 67: if(strcmp(w, "target") == 0){ ! 68: SUB("$?") ! 69: } else if(strcmp(w, "stem") == 0){ ! 70: SUB(j->stem) ! 71: } else if(strcmp(w, "prereq") == 0){ ! 72: SUB("$@") ! 73: } else if(strcmp(w, "pid") == 0){ ! 74: SUB("$$$$") ! 75: } else if(strcmp(w, "newprereq") == 0){ ! 76: SUB(wtos(j->np)) ! 77: } else if(strcmp(w, "alltarget") == 0){ ! 78: SUB(wtos(j->at)) ! 79: Fprint(2, "Warning; $alltarget expanded to '%s'\n", wtos(j->at)); ! 80: } else if((strncmp(w, "stem", 4) == 0) && (w[4] >= '0') && (w[4] <= '9')){ ! 81: int i = w[4] - '0'; ! 82: int nb = j->match[i].ep - j->match[i].sp; ! 83: ! 84: memcpy(dest, j->match[i].sp, nb); ! 85: dest += nb; ! 86: } else { ! 87: SUB("1"); ! 88: Fprint(2, "Warning; $%s expanded to 1\n", w); ! 89: } ! 90: } ! 91: if(copy){ ! 92: *dest++ = '$'; ! 93: *dest++ = '{'; ! 94: for(q = w; q != s;) ! 95: *dest++ = *q++; ! 96: *dest++ = '}'; ! 97: } ! 98: *s = carry; ! 99: if(carry == '}') ! 100: s++; ! 101: *ww = s; ! 102: return(dest); ! 103: } ! 104: ! 105: static ! 106: recipepr(s, j) ! 107: char *s; ! 108: Job *j; ! 109: { ! 110: char buf[BIGBLOCK]; ! 111: register char *q = buf; ! 112: ! 113: while(*s) ! 114: switch(*s) ! 115: { ! 116: case '\\': ! 117: *q++ = *s++; ! 118: *q++ = *s++; ! 119: break; ! 120: case '$': ! 121: q = vexpand(&s, q, j); ! 122: break; ! 123: case '\n': ! 124: *q = 0; ! 125: Fprint(1, "\t%s\n", buf); ! 126: q = buf; ! 127: s++; ! 128: break; ! 129: default: ! 130: *q++ = *s++; ! 131: break; ! 132: } ! 133: *q = 0; ! 134: if(q != buf) ! 135: Fprint(1, "\t%s\n", buf); ! 136: } ! 137: ! 138: static void ! 139: nd(s) ! 140: Symtab *s; ! 141: { ! 142: Job *j = (Job *)s->value; ! 143: register Node *n = j->n; ! 144: Arc *a; ! 145: int i; ! 146: char *ss, *s, c; ! 147: ! 148: if(strcmp(n->name, first) == 0){ ! 149: if(didit) ! 150: return; ! 151: didit = 1; ! 152: } ! 153: Fprint(1, "\n%s:", n->name); ! 154: fold(wtos(j->p), ' '); ! 155: Fputc(1, '\n'); ! 156: recipepr(j->r->recipe, j); ! 157: } ! 158: ! 159: makefile() ! 160: { ! 161: symtraverse(S_MAKEVAR, vd); ! 162: didit = 0; ! 163: nd(symlook(first, S_MAKEFILE, (char *)0)); ! 164: symtraverse(S_MAKEFILE, nd); ! 165: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.