makefuns.awk 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. BEGIN {
  2. FS = "|";
  3. seenproc = 0;
  4. CC="${CMD}"
  5. if (prototypes == "") prototypes = "prototypes"
  6. }
  7. /^%/ {}
  8. /^$/ {}
  9. /^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ {
  10. if(seenproc) {
  11. print "}"
  12. print "--EOF--"
  13. printf "if %s O_%s.c\n",CC,nam
  14. printf "then :\nelse exit 1\nfi\n"
  15. printf "rm -f O_%s.c\n",nam
  16. }
  17. seenproc = 1
  18. $1 = substr($1,1,index($1,"\t")-1);
  19. nam = $1
  20. printf "cat > O_%s.c << '--EOF--'\n",$1
  21. print "#include \"nopt.h\""
  22. printf "void O_%s(",$1
  23. prototype = "_PROTOTYPE(void O_" $1 ", ("
  24. nparms = split($2,parms,":");
  25. for(p=1;p<nparms;p++) {
  26. if(p!=1) {
  27. printf ","
  28. }
  29. split(parms[p+1],a," ")
  30. printf a[1]
  31. }
  32. printf ")\n"
  33. if(nparms > 1) {
  34. prototype = prototype parms[1]
  35. printf "\t%s",parms[1]
  36. }
  37. else {
  38. prototype = prototype "void"
  39. }
  40. for(p=1;p<nparms;p++) {
  41. split(parms[p+1],a," ")
  42. prototype = prototype " " a[1]
  43. printf " %s;\n",a[1]
  44. if(a[2]) {
  45. prototype = prototype ", " a[2] a[3] a[4]
  46. printf "\t%s%s%s",a[2],a[3],a[4]
  47. }
  48. }
  49. print prototype "));" >> prototypes
  50. if($3) {
  51. printf "{\n\t%s\n",$3
  52. }
  53. else {
  54. printf "{\n"
  55. }
  56. }
  57. /^ / {
  58. print
  59. }
  60. END {
  61. if(seenproc) {
  62. print "}"
  63. print "--EOF--"
  64. printf "if %s O_%s.c\n",CC,nam
  65. printf "then :\nelse exit 1\nfi\n"
  66. printf "rm -f O_%s.c\n",nam
  67. }
  68. }