1$AWK ' 2BEGIN{ 3 if(ARGC < 2) 4 exit 5} 6 7/^$/{ 8 next; 9} 10/^#/{ 11 next; 12} 13collect && /^[^ \t]/{ 14 collect = 0; 15} 16collect && section ~ "dev"{ 17 dev[ndev++] = $1; 18} 19collect && section ~ "ip"{ 20 ip[nip++] = $1; 21} 22collect && section ~ "link"{ 23 link[nlink++] = $1; 24} 25collect && section ~ "mod"{ 26 mod[nmod++] = $1; 27} 28collect && section ~ "misc"{ 29 misc[nmisc++] = $1; 30} 31collect && section ~ "port"{ 32 port[nport++] = $0; 33} 34collect && section ~ "code"{ 35 code[ncode++] = $0; 36} 37$0 ~ /^[^ \t]/{ 38 if($0 ~ "(code|dev|ip|lib|link|mod|misc|port|root)"){ 39 section = $0; 40 collect = 1; 41 } 42 next; 43} 44 45END{ 46 if(ARGC < 2) 47 exit "usage" 48 49 printf "#include \"dat.h\"\n" 50 printf "#include \"fns.h\"\n" 51 printf "#include \"error.h\"\n" 52 printf "#include \"interp.h\"\n\n\n" 53 printf "#include \"%s.root.h\"\n\n", ARGV[1]; 54 55 nildev = 8; 56 printf "ulong ndevs = %s;\n\n", ndev+nildev 57 for(i = 0; i < ndev; i++) 58 printf "extern Dev %sdevtab;\n", dev[i]; 59 printf "Dev* devtab[]={\n" 60 for(i = 0; i < ndev; i++) 61 printf "\t&%sdevtab,\n", dev[i]; 62 for(i = 0; i < nildev; i++) 63 printf("\tnil,\n"); 64 printf "\tnil,\n};\n\n"; 65 66 67 for(i = 0; i < nlink; i++) 68 printf "extern void %slink(void);\n", link[i]; 69 70 printf "void links(void){\n"; 71 for(i = 0; i < nlink; i++) 72 printf "\t%slink();\n", link[i]; 73 printf "}\n\n"; 74 75 for(i = 0; i < nmod; i++) 76 printf "extern void %smodinit(void);\n", mod[i]; 77 printf "void modinit(void){\n"; 78 for(i = 0; i < nmod; i++) 79 printf "\t%smodinit();\n",mod[i]; 80 printf "}\n\n"; 81 82 if(nip){ 83 printf "#include \"../ip/ip.h\"\n"; 84 for(i = 0; i < nip; i++) 85 printf "extern void %sinit(Fs*);\n", ip[i]; 86 printf "void (*ipprotoinit[])(Fs*) = {\n"; 87 for(i = 0; i < nip; i++) 88 printf "\t%sinit,\n", ip[i]; 89 printf "\tnil,\n};\n\n"; 90 } 91 92 for(i = 0; i < ncode; i++) 93 printf "%s\n", code[i]; 94 95 printf "char* conffile = \"%s\";\n", ARGV[1]; 96 printf "ulong kerndate = KERNDATE;\n"; 97 98 exit 99}' $* 100