topon 429 B

123456789101112131415161718192021222324252627
  1. /* Generate copy of topology of input graph
  2. * Replace names with numbers
  3. */
  4. BEGIN {
  5. int id = 0;
  6. char* names[char*];
  7. char* mapn (char* inname)
  8. {
  9. char* s = names[inname];
  10. if (s == "") {
  11. s = id++;
  12. names[inname] = s;
  13. }
  14. return s;
  15. }
  16. }
  17. BEG_G {
  18. graph_t g = graph ($.name, "U");
  19. }
  20. N { node (g, mapn($.name)); }
  21. E { edge (node (g, mapn($.tail.name)), node (g, mapn($.head.name)), ""); }
  22. END_G {
  23. write (g);
  24. }