home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / pd / pathalias / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  4.4 KB  |  155 lines

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