home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libg++ / proto-kit / hierarchy < prev    next >
Text File  |  1991-06-28  |  4KB  |  140 lines

  1. #!/usr/local/bin/gawk -f
  2. #**************************************************************************************
  3. #
  4. # hierarchy:
  5. #        This program takes an input file which defines a DAG
  6. #    and expands it into a tree.  It is useful when you have a tree of
  7. #     generic types.  See the sample input file "file_types.hierarchy"
  8. #    for a sample dataset, and sample outputs "file_types.includes.h",
  9. #    "file_types.operation.h" and "file_types.type.h".  The input has 
  10. #    three distinct types of input lines:
  11. #
  12. #        root     TYPE
  13. #        set    <TAG>    TYPE1    TYPE2    ...
  14. #        children    TYPE|<TAG>    TYPE|<TAG>    TYPE|<TAG>    ...
  15. #
  16. #    each word is tab-separated.  "root" defines the root type of the 
  17. #    tree.  "set" defines an alias for a list of types.  "children"
  18. #    defines the child types (or sets of types) for a given type or 
  19. #    set of types.
  20. #
  21. #**************************************************************************************
  22. # command line switches:
  23. #    -voutput_type=type    -- print the specialized type definition (iPcress only)
  24. #    -voutput_type=general    -- general output type.  has sub-options
  25. #        -vpreamble=???    -- print this ??? string before the type
  26. #        -vpostamble=???    -- print this ??? string after after the type
  27. #        -vprint_first=1    -- if you want to include the root type
  28. #
  29. #
  30. #**************************************************************************************
  31.  
  32. function print_type_node (queue, node, out,    i) {
  33.     for (i = 1 ; i <= queue[node] ; i ++)
  34.       printf "%s", queue[node,i] ;
  35.     printf "_type = \n\t" ;
  36.     for (i = 1 ; i <= queue[node] ; i ++)
  37.       {
  38.         printf "isa_%s", queue[node,i] ;
  39.         if (i < queue[node])
  40.           printf " | " ;
  41.       }
  42.         printf ",\n" ;
  43.     return
  44. }
  45.  
  46. function print_general_node (queue, node,     i) {
  47.     if ((queue[node] > 1) || (print_first == 1))
  48.       {
  49.         printf "%s", preamble;
  50.         for (i = 1 ; i <= queue[node] ; i ++)
  51.           {
  52.             if ((i == queue[node]) && (i > 1))
  53.           printf ".";
  54.             printf "%s", queue[node,i] ;
  55.           }
  56.       printf "%s\n", postamble;
  57.       }
  58.     return
  59. }
  60.  
  61. BEGIN { head = 2;
  62.     tail = 1;
  63.     }
  64.  
  65. $1 == "set" { 
  66.     set_names[$2] = NF - 2;
  67.     for (dummy = 3 ; dummy <= NF ; dummy ++)
  68.       {
  69.         set_names[$2,dummy - 2] = $dummy;
  70.       }
  71.     }
  72.  
  73. $1 == "root" { root_set = $2 ; }
  74.  
  75. ($1 == "children") && ($2 ~ /<.+>/) { 
  76.     for (s_el = 1 ; s_el <= set_names[$2] ; s_el ++)
  77.       {
  78.         t=0 ;
  79.         for (dummy = 3 ; dummy <= NF ; dummy ++)
  80.           if ($dummy ~ /<.+>/)
  81.             {
  82.           for (i = 1 ; i <= set_names[$dummy] ; i ++)
  83.             {
  84.               t++
  85.               children[set_names[$2,s_el],t] = set_names[$dummy,i]
  86.             }
  87.         }
  88.           else
  89.         {
  90.           t ++
  91.               children[set_names[$2,s_el],t] = $dummy;
  92.         }
  93.         children[set_names[$2,s_el]] = t;
  94.        }
  95.     }
  96.  
  97. ($1 == "children") && ($2 !~ /<.+>/) { 
  98.     t = 0;
  99.     for (dummy = 3 ; dummy <= NF ; dummy ++)
  100.       if ($dummy ~ /<.+>/)
  101.         {
  102.           for (i = 1 ; i <= set_names[$dummy] ; i ++)
  103.         {
  104.           t++
  105.           children[$2,t] = set_names[$dummy,i]
  106.         }
  107.         }
  108.       else
  109.         {
  110.           t ++
  111.           children[$2,t] = $dummy;
  112.         }
  113.     children[$2] = t;
  114.     }
  115.  
  116. END { 
  117.     queue[1] = 1;
  118.     queue[1,1] = root_set;
  119.     while (head > tail)
  120.       {
  121.         if (output_type == "type")
  122.           print_type_node(queue,tail);
  123.         if (output_type == "general")
  124.           print_general_node(queue,tail);
  125.  
  126.         for (i = 1 ; i <= children[queue[tail,queue[tail]]] ; i ++)
  127.           {
  128.         # add new node to queue
  129.         for (j = 1 ; j <= queue[tail] ; j ++)
  130.             queue[head,j] = queue[tail,j];
  131.         queue[head] = queue[tail] + 1;
  132.         queue[head,queue[head]] = children[queue[tail,queue[tail]],i]
  133.         head ++
  134.           }
  135.         tail ++
  136.       }
  137.      }
  138.  
  139.  
  140.