home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume22 / pathalias10 / part03 / def.h < prev    next >
C/C++ Source or Header  |  1990-06-07  |  4KB  |  154 lines

  1. /* pathalias -- by steve bellovin, as told to peter honeyman */
  2.  
  3. #ifndef lint
  4. #ifdef MAIN
  5. static char    *h_sccsid = "@(#)def.h    9.5 88/05/09";
  6. #endif /*MAIN*/
  7. #endif /*lint*/
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. #include "config.h"
  12.  
  13. typedef    long Cost;
  14. typedef struct node node;
  15. typedef struct link link;
  16.  
  17. #ifdef lint
  18. #define vprintf fprintf
  19. #else /*!lint -- this gives null effect warning*/
  20. /* because it's there ... */
  21. #define vprintf        !Vflag ? 0 : fprintf
  22. #endif /*lint*/
  23.  
  24. #define NTRACE    16    /* can trace up to NTRACE hosts/links */
  25.  
  26. /* flags for n_flag */
  27. #define ISPRIVATE  0x0001 /* invisible outside its definition file */
  28. #define NALIAS       0x0002 /* heaped as an alias */
  29. #define ATSIGN       0x0004 /* seen an at sign?  used for magic @/% rules */
  30. #define MAPPED       0x0008 /* extracted from heap */
  31. #define    NDEAD       0x0010 /* out links are dead */
  32. #define HASLEFT       0x0020 /* has a left side net character */
  33. #define HASRIGHT   0x0040 /* route has a right side net character */
  34. #define    NNET       0x0080 /* network pseudo-host */
  35. #define INDFS       0x0100 /* used when removing net cycles (for -g) */
  36. #define DUMP       0x0200 /* we have dumped this net's edges (for -g) */
  37. #define PRINTED       0x0400 /* this host has been printed */
  38. #define NTERMINAL  0x0800 /* heaped as terminal edge (or alias thereto) */
  39. #define NREF       0x1000 /* node has an "interesting" reference */
  40.  
  41. #define ISADOMAIN(n)     ((n)->n_name[0] == '.')
  42. #define ISANET(n)     (((n)->n_flag & NNET) || ISADOMAIN(n))
  43. #define ALTEREGO(n1, n2) ((n1)->n_name == (n2)->n_name)
  44. #define DEADHOST(n)     (((n)->n_flag & (NDEAD | NTERMINAL)) && !ISANET(n))
  45. #define DEADLINK(l)     ((l)->l_flag & LDEAD)
  46. #define DEADNET(n)     (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD))
  47. #define GATEWAYED(n)     (DEADNET(n) || ISADOMAIN(n))
  48.  
  49. #ifndef DEBUG
  50. /*
  51.  * save some space in nodes -- there are > 10,000 allocated!
  52.  */
  53.  
  54. #define n_root un1.nu_root
  55. #define n_net un1.nu_net
  56. #define n_copy un1.nu_copy
  57.  
  58. #define n_private un2.nu_priv
  59. #define n_parent  un2.nu_par
  60.  
  61. /* WARNING: if > 2^16 nodes, type of n_tloc must change */
  62. struct node {
  63.     char    *n_name;    /* host name */
  64.     link    *n_link;    /* adjacency list */
  65.     Cost    n_cost;        /* cost to this host */
  66.     union {
  67.         node *nu_net;    /* others in this network (parsing) */
  68.         node *nu_root;    /* root of net cycle (graph dumping) */
  69.         node *nu_copy;    /* circular copy list (mapping) */
  70.     } un1;
  71.     union {
  72.         node *nu_priv;    /* other privates in this file (parsing) */
  73.         node *nu_par;    /* parent in shortest path tree (mapping) */
  74.     } un2;
  75.     unsigned short n_tloc;    /* back ptr to heap/hash table */
  76.     unsigned short n_flag;        /* see manifests above */
  77. };
  78.  
  79. #endif /*DEBUG*/
  80.  
  81. #define MILLION (1000L * 1000L)
  82. #define    DEFNET    '!'            /* default network operator */
  83. #define    DEFDIR    LLEFT            /* host on left is default */
  84. #define    DEFCOST    ((Cost) 4000)        /* default cost of a link */
  85. #define    INF    ((Cost) 100 * MILLION)    /* infinitely expensive link */
  86. #define DEFPENALTY ((Cost) 200)        /* default avoidance cost */
  87.  
  88. /* data structure for adjacency list representation */
  89.  
  90. /* flags for l_dir */
  91.  
  92. #define NETDIR(l)    ((l)->l_flag & LDIR)
  93. #define NETCHAR(l)    ((l)->l_netop)
  94.  
  95. #define LDIR      0x0008    /* 0 for left, 1 for right */
  96. #define LRIGHT      0x0000    /* user@host style */
  97. #define LLEFT      0x0008    /* host!user style */
  98.  
  99. #define LDEAD      0x0010    /* this link is dead */
  100. #define LALIAS      0x0020    /* this link is an alias */
  101. #define LTREE      0x0040    /* member of shortest path tree */
  102. #define LGATEWAY  0x0080    /* this link is a gateway */
  103. #define LTERMINAL 0x0100    /* this link is terminal */
  104.  
  105. #ifndef DEBUG
  106. /*
  107.  * borrow a field for link/node tracing.  there's a shitload of
  108.  * edges -- every word counts.  only so much squishing is possible:
  109.  * alignment dictates that the size be a multiple of four.
  110.  */
  111.  
  112. #define l_next un.lu_next
  113. #define l_from un.lu_from
  114.  
  115. struct link {
  116.     node    *l_to;        /* adjacent node */
  117.     Cost    l_cost;        /* edge cost */
  118.     union {
  119.         link *lu_next;    /* rest of adjacency list (not tracing) */
  120.         node *lu_from;    /* source node (tracing) */
  121.     } un;
  122.     short    l_flag;        /* right/left syntax, flags */
  123.     char    l_netop;    /* network operator */
  124. };
  125.  
  126. #endif /*DEBUG*/
  127.  
  128. #ifdef DEBUG
  129. /*
  130.  * flattening out the unions makes it easier
  131.  * to debug (when pi is unavailable).
  132.  */
  133. struct node {
  134.     char    *n_name;
  135.     link    *n_link;
  136.     Cost    n_cost;
  137.     node    *n_net;
  138.     node    *n_root;
  139.     node    *n_copy;
  140.     node    *n_private;
  141.     node    *n_parent;
  142.     unsigned short n_tloc;
  143.     unsigned short n_flag;
  144. };
  145. struct link {
  146.     node    *l_to;
  147.     Cost    l_cost;
  148.     link    *l_next;
  149.     node    *l_from;
  150.     short    l_flag;
  151.     char    l_netop;
  152. };
  153. #endif /*DEBUG*/
  154.