mkdev 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/rc
  2. rfork e
  3. DB=usbdb
  4. HDR=../lib/usb.h
  5. subs=`{ grep '^ Cl.*' $HDR |
  6. sed -e 's/.*Cl([a-z]+)[ ]+=[ ]+([0-9]+).*/-e s.\1,.\2,./' |
  7. tr A-Z a-z
  8. }
  9. cat<<EOF
  10. /* machine generated. do not edit */
  11. #include <u.h>
  12. #include <libc.h>
  13. #include <thread.h>
  14. #include "usb.h"
  15. #include "usbd.h"
  16. EOF
  17. awk '
  18. /^#|^$/ { next }
  19. collect && /^[^ \t]/{
  20. collect = 0;
  21. }
  22. $0 ~ /^(embed|auto)/{
  23. section = $0;
  24. collect = 1;
  25. next;
  26. }
  27. collect {
  28. if(section ~ "embed"){
  29. printf("extern int %smain(Dev*, int, char**);\n", $1);
  30. }
  31. }
  32. ' $DB
  33. cat <<EOF
  34. Devtab devtab[] = {
  35. /* device, entrypoint, {csp, csp, csp csp}, vid, did */
  36. EOF
  37. awk '
  38. /^#|^$/ { next }
  39. collect && /^[^ \t]/{
  40. collect = 0;
  41. }
  42. $0 ~ /^(embed|auto)/{
  43. section = $0;
  44. collect = 1;
  45. next;
  46. }
  47. collect {
  48. printf(" {\"%s\"", $1);
  49. if(section ~ "embed"){
  50. fns[nfns++] = $1;
  51. printf(",\t%smain", $1);
  52. } else
  53. printf(", nil");
  54. printf(",\t{");
  55. ncsp = 0;
  56. vid="-1";
  57. did="-1";
  58. args="";
  59. for(i = 2; i <= NF; i++)
  60. if($i ~ "^args="){
  61. sub("args=", "", $i);
  62. for(j = i; j <= NF; j++)
  63. if(j > i)
  64. args = args " " $j;
  65. else
  66. args = $j
  67. }
  68. for(i = 2; i <= NF; i++){
  69. if($i ~ "^csp="){
  70. ncsp++;
  71. sub("csp=", "", $i);
  72. printf("%s, ", $i);
  73. } else
  74. if($i ~ "^subclass="){
  75. ncsp++;
  76. sub("subclass=", "", $i);
  77. printf("DSC|%s, ", $i);
  78. } else
  79. if($i ~ "^class="){
  80. ncsp++;
  81. sub("class=", "", $i);
  82. printf("DCL|%s, ", $i);
  83. } else
  84. if($i ~ "^proto="){
  85. ncsp++;
  86. sub("proto=", "", $i);
  87. printf("DPT|%s, ", $i);
  88. } else
  89. if($i ~ "^vid="){
  90. sub("vid=", "", $i);
  91. vid=$i
  92. } else
  93. if($i ~ "did="){
  94. sub("did=", "", $i);
  95. did=$i
  96. }
  97. }
  98. for(i = ncsp; i < 4; i++)
  99. printf("0, ");
  100. printf("}, %s, %s, \"%s\"},\n", vid, did, args);
  101. }
  102. ' $DB | sed $subs
  103. cat <<EOF
  104. {nil, nil, {0, 0, 0, 0, }, -1, -1, nil},
  105. };
  106. /* end of machine generated */
  107. EOF