1$AWK ' 2BEGIN{ 3 if (ARGC < 2) 4 exit "usage"; 5 6 conf = ARGV[1]; 7 infernoroot = ENVIRON["ROOT"]; 8 init = ENVIRON["INIT"]; 9 data2s = ENVIRON["DATA2S"]; 10 nroot = 0; 11} 12/^$/{ 13 next; 14} 15/^#/{ 16 next; 17} 18collect && /^[^ \t]/{ 19 collect = 0; 20} 21collect && section ~ "root"{ 22 dst[nroot] = $1; 23 if (NF > 1) 24 src[nroot] = infernoroot $2; 25 else if (dst[nroot] == "/osinit.dis") 26 src[nroot] = infernoroot "/os/init/" init ".dis"; 27 else 28 src[nroot] = infernoroot $1; 29 for(i=0; i<nroot; i++) 30 if(dst[i] == dst[nroot]) 31 break; 32 if(i == nroot) 33 nroot++; 34} 35$0 ~ /^[^ \t]/{ 36 if($0 ~ "(code|dev|ether|ip|lib|link|mod|misc|port|root|vga)"){ 37 section = $0; 38 collect = 1; 39 } 40 next; 41} 42END{ 43 rootdata = conf ".root.s"; 44 system("rm -f " rootdata); 45 print("/* Generated by /os/port/mkroot */") >rootdata; 46 close(rootdata); 47 isdir[0] = 1; 48 dotdot[0] = 0; 49 qid = 1; 50 for (i = 0; i < nroot; i++) { 51 ncomp = split(dst[i], comp, "/"); 52 if (comp[1] != "" || ncomp < 2) 53 continue; 54 q = 0; 55 for (j = 2; j <= ncomp; j++) { 56 key = q "/" comp[j]; 57 if (walk[key] == 0) { 58 walk[key] = qid; 59 dotdot[qid] = q; 60 q = qid++; 61 name[q] = comp[j]; 62 if (j < ncomp) 63 isdir[q] = 1; 64 } 65 else 66 q = walk[key]; 67 } 68 if (system("test -d " src[i]) == 0) 69 isdir[q] = 1; 70 else { 71 if (system(data2s " root" q " <" src[i] " >>" rootdata) != 0) 72 exit 1; 73 print("extern unsigned char root" q "code[];"); 74 print("extern int root" q "len;"); 75 } 76 } 77 78 x = 1; 79 sort[0] = 0; 80 unsort[0] = 0; 81 for (q = 0; q < qid; q++) { 82 if (isdir[q]) { 83 nchild[q] = 0; 84 for (q2 = 1; q2 < qid; q2++) { 85 if (dotdot[q2] == q) { 86 if (nchild[q]++ == 0) 87 child0[q] = x; 88 sort[q2] = x++; 89 unsort[sort[q2]] = q2; 90 } 91 } 92 } 93 } 94 95 print("int rootmaxq = " qid ";"); 96 97 print("Dirtab roottab[" qid "] = {"); 98 for (oq = 0; oq < qid; oq++) { 99 q = unsort[oq]; 100 if (!isdir[q]) 101 print("\t\"" name[q] "\",\t{" oq ", 0, QTFILE},\t", "0,\t0444,"); 102 else 103 print("\t\"" name[q] "\",\t{" oq ", 0, QTDIR},\t", "0,\t0555,"); 104 } 105 print("};"); 106 107 print("Rootdata rootdata[" qid "] = {"); 108 for (oq = 0; oq < qid; oq++) { 109 q = unsort[oq]; 110 if (!isdir[q]) 111 print("\t" sort[dotdot[q]] ",\t", "root" q "code,\t", "0,\t", "&root" q "len,"); 112 else if (nchild[q]) 113 print("\t" sort[dotdot[q]] ",\t", "&roottab[" child0[q] "],\t", nchild[q] ",\tnil,"); 114 else 115 print("\t" sort[dotdot[q]] ",\t", "nil,\t", "0,\t", "nil,"); 116 } 117 print("};"); 118} 119' $1 >$1.root.h 120