logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

entities.awk (924B)


  1. BEGIN {
  2. for (i = 32; i <= 126; ++i)
  3. ord[sprintf("%c", i)] = i
  4. n = -1
  5. }
  6. function makenode(c) {
  7. ++n
  8. splits[n] = c
  9. left[n] = -1
  10. equal[n] = -1
  11. right[n] = -1
  12. values[n] = 0
  13. }
  14. function insert(nodes, id, c) {
  15. nextid = nodes[id]
  16. if (nextid != -1)
  17. return nextid
  18. makenode(c)
  19. nodes[id] = n
  20. return n
  21. }
  22. /^(#|$)/ {next}
  23. {
  24. id = 0
  25. c = ord[substr($1, 1, 1)]
  26. if (n < 0)
  27. makenode(c)
  28. for (i = 1; i <= length($1) + 1;) {
  29. if (c < splits[id]) {
  30. id = insert(left, id, c)
  31. } else if (c == splits[id]) {
  32. if (i >= length($1))
  33. values[id] = $2
  34. if (c == 0)
  35. break
  36. ++i
  37. c = i <= length($1) ? ord[substr($1, i, 1)] : 0
  38. id = insert(equal, id, c)
  39. } else {
  40. id = insert(right, id, c)
  41. }
  42. }
  43. }
  44. END {
  45. print "static hubbub_entity_node dict[] = {"
  46. for (i = 0; i <= n; ++i)
  47. print "\t{ "splits[i]", "left[i]", "equal[i]", "right[i]", "values[i]" },"
  48. print "};"
  49. print "static int32_t dict_root = 0;"
  50. }