# Hey Emacs! This file might as well be -*- C -*- # # make_fd.awk -- create prototype, FD and pragma files # # Author: ppessi # # Copyright © 1993, 1994 AmiTCP/IP Group, # Helsinki University of Technology, Finland. # # Created : Mon Nov 29 21:14:58 1993 ppessi # Last modified: Sat Feb 12 02:57:44 1994 ppessi # # $Id: make_fd.awk,v 1.4 1994/02/17 02:23:05 ppessi Exp $ # # $Log: make_fd.awk,v $ # Revision 1.4 1994/02/17 02:23:05 ppessi # Changed the defines for include files # # Revision 1.3 1994/01/21 08:32:32 ppessi # Added a "what" variable to determine the conversion result # # Revision 1.2 1994/01/21 05:00:16 ppessi # Fancier blurbs. # # # # Each prototype must in the form # ASM type name(REG(rn) type name); # Do not forget argument name! # The tagcall stub must be given in the next line of # /* TAGCALL tag_call_stub_name */ # BEGIN { stderr = "console:"; if (what != "protos" && what != "pragmas" && what != "fd") { print "but what to do?" > stderr; exit(10); } library = "usergroup"; basename = "UserGroupBase"; fds = "fd/"library"_lib.fd"; pragmaname = "pragmas/"library"_pragmas.h" pragmas = "include/"pragmaname; outputname = "clib/"library"_protos.h"; define = toupper(outputname); gsub("[/.]", "_", define); output = "include/"outputname; libprefix = "^R_"; libfunctype = "^ASM$"; libincludename = "libraries/"library".h"; libincludedefine = toupper(libincludename); gsub("[/.]", "_", libincludedefine); libinclude = "include/"libincludename; libincludename1 = "pwd.h"; libincludedefine1 = toupper(libincludename1); gsub("[/.]", "_", libincludedefine1); libincludename2 = "grp.h"; libincludedefine2 = toupper(libincludename2); gsub("[/.]", "_", libincludedefine2); copyright = \ "**\tCopyright (c) 1993 AmiTCP/IP Group, \n"\ "**\t Helsinki University of Technology, Finland.\n"\ "**\t All rights reserved.\n"; state = 0; priv = 1; public = 2; release="$Release$"; rcsdate="$Date: 1994/02/17 02:23:05 $"; } state == 0 && $0 ~ /\$Date/ { rcsdate = $0; sub(/^[^$]*/, "", rcsdate); sub(/[^$]*$/, "", rcsdate); } state == 0 && $0 ~ /\$Revision/ { rcsid = $0; sub(/^[^$]*/, "", rcsid); sub(/[^$]*$/, "", rcsid); fnfmt = "**\t$Filename: %s $\n"; rcsfmt = "**\t%s\n"; if (what == "protos") { protosblurb="**\n**\tC prototypes for %s.library\n**\n"; printf("#ifndef %s\n", define); printf("#define %s\n", define); printf("/*\n"); printf(fnfmt, outputname ); printf(rcsfmt, release); printf(rcsfmt, rcsid); printf(rcsfmt, rcsdate); printf(protosblurb, library); printf(copyright); printf("*/\n"); printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", libincludedefine, libincludename); printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", libincludedefine1, libincludename1); printf("\n#ifndef %s\n#include \<%s\>\n#endif\n", libincludedefine2, libincludename2); } else if (what == "pragmas") { pragmablurb="**\n**\tPragmas file for %s.library\n**\n"; printf("/*\n"); printf(fnfmt, pragmaname ); printf(rcsfmt, release); printf(rcsfmt, rcsid); printf(rcsfmt, rcsdate); printf(pragmablurb, library); printf(copyright); printf("*/\n"); } else if (what == "fd") { fdblurb="**\n**\tFD file for %s.library\n**\n"; printf("**\n"); printf(fnfmt, fds ); printf(rcsfmt, release); printf(rcsfmt, rcsid); printf(rcsfmt, rcsdate); printf(fdblurb, library); printf(copyright); printf("**\n"); printf("##base _%s\n##bias 30\n##public\n", basename); } base = 30; state = public; next; } state != 0 && $1 ~ libfunctype { if (!match($0, /[A-Za-z][A-Za-z0-9_]*\(/)) { printf("$0: No function name") >stderr; exit 1; } fname = substr($0, RSTART, RLENGTH - 1); sub(libprefix, "", fname); rtype = substr($0, 1, RSTART - 1); sub(/^[^ ]* */, "", rtype); registerless = rtype""fname"("; arglist = $0; argnames = ""; reglist = ""; twoline = 0; sub(/^[^(]*\(/, "", arglist); sub(/\)[^)]*$/, "", arglist); argn = split(arglist, args, ","); if (argn != 1 || args[1] !~ "^void$") { pragmacode = sprintf("%02X", argn); for (i = 1; i < argn + 1; i++) { sub(/ */, "", args[i]); apn = split(args[i], ap, "[ *]+"); if (match(ap[1], /^REG\(d[0-7]\)$/)) { pragmacode = sprintf("%X%s", substr(ap[1], 6, 1), pragmacode); } else if (match(ap[1], /^REG\(a[0-7]\)$/)) { pragmacode = sprintf("%X%s", substr(ap[1], 6, 1) + 8, pragmacode); } else { printf("%s: argument %s has no register\n", fname, ap[apn]) > stderr; exit 1; } argnames=argnames""ap[apn]; reglist=reglist""substr(ap[1], 5, 2); sub(/^REG\(..\) */, "", args[i]); lastrl = registerless; if (!twoline && length(registerless""args[i]) > 76) { twoline = 1; registerless=registerless"\n "; } registerless = registerless""args[i] if (i < argn) { argnames = argnames", "; reglist = reglist"/"; registerless = registerless", "; } } } else { registerless = registerless"void"; pragmacode = "00"; } if (what == "protos") { printf("%s);\n", registerless); } else if (what == "pragmas") { printf("#pragma libcall %s %s %X %s\n", basename, fname, base, pragmacode); } else if (what == "fd") { printf("%s(%s)(%s)\n", fname, argnames, reglist); } base += 6; next; } state != 0 && $1 ~ /^\/\*$/ && $2 == "TAGCALL" { sub(fname, $3, lastrl); if (what == "protos") { printf("%s ...);\n", lastrl); } else if (what == "pragmas") { printf("#pragma tagcall %s %s %X %s\n", basename, $3, base - 6, pragmacode); } next; } state != 0 && $1 ~ /^\/\*$/ { if (what == "protos") { printf "%s\n", $0; } else if (what == "pragmas") { printf "%s\n", $0; } else if (what == "fd") { sub(/\/\*/, "*------", $0); sub(/\*\//, "------*", $0); print $0; } next; } state != 0 { if (what == "protos") { print $0; } } END { if (what == "protos") { printf("\n#endif /* %s */\n", define); } else if (what == "fd") { printf("##end\n") } }