1: /* pathalias -- by steve bellovin, as told to peter honeyman */
   2: #ifndef lint
   3: static char *sccsid = "@(#)main.c	9.1 87/10/04";
   4: #endif
   5: 
   6: #define MAIN    /* for sccsid in header files */
   7: 
   8: #include "def.h"
   9: 
  10: /* exports */
  11: extern void die();
  12: char *Cfile;    /* current input file */
  13: char *Graphout; /* file for dumping edges (-g option) */
  14: char *Linkout;  /* file for dumping shortest path tree */
  15: char **Argv;    /* external copy of argv (for input files) */
  16: p_node Home;    /* node for local host */
  17: int Cflag;  /* print costs (-c option) */
  18: int Dflag;  /* penalize routes beyond domains (-D option) */
  19: int Iflag;  /* ignore case (-i option) */
  20: int Tflag;  /* trace links (-t option) */
  21: int Vflag;  /* verbose (-v option) */
  22: int Fflag;  /* print cost of first hop */
  23: int Argc;   /* external copy of argc (for input files) */
  24: long Lineno = 1;/* line number within current input file */
  25: 
  26: /* imports */
  27: extern long allocation();
  28: extern void wasted(), mapit(), penalize(), hashanalyze(), deadlink();
  29: extern void printit();
  30: extern char *local();
  31: extern p_node addnode();
  32: #ifndef TMPFILES
  33: #define getnode(x) x
  34: #define getlink(y) y
  35: #else  /*TMPFILES*/
  36: void initstruct();
  37: extern node *getnode();
  38: extern link *getlink();
  39: extern char *nfile, *lfile, *sfile;
  40: extern long nhits, lhits, nmisses, lmisses;
  41: #endif /*TMPFILES*/
  42: extern char *optarg;
  43: extern int optind;
  44: extern long Lcount, Ncount;
  45: 
  46: #define USAGE "usage: %s [-vciDf] [-l localname] [-d deadlink] [-t tracelink] [-g edgeout] [-s treeout] [-a avoid] [files ...]\n"
  47: 
  48: main(argc, argv)
  49:     register int argc;
  50:     register char **argv;
  51: {   char *locname = 0, buf[32], *bang;
  52:     register int c;
  53:     int errflg = 0;
  54: 
  55:     setbuf(stderr, (char *) 0);
  56:     (void) allocation();    /* initialize data space monitoring */
  57:     Cfile = "[deadlinks]";  /* for tracing dead links */
  58:     Argv = argv;
  59:     Argc = argc;
  60: 
  61: #ifdef TMPFILES
  62:     initstruct();       /* initialize the node cache, etc. */
  63: #endif /*TMPFILES*/
  64: 
  65:     while ((c = getopt(argc, argv, "a:cd:Dfg:il:s:t:v")) != EOF)
  66:         switch(c) {
  67:         case 'a':   /* adjust cost out of arg */
  68:             penalize(optarg, DEFPENALTY);
  69:             break;
  70:         case 'c':   /* print cost info */
  71:             Cflag++;
  72:             break;
  73:         case 'd':   /* dead host or link */
  74:             if ((bang = index(optarg, '!')) != 0) {
  75:                 *bang++ = 0;
  76:                 deadlink(addnode(optarg), addnode(bang));
  77:             } else
  78:                 deadlink(addnode(optarg), (p_node) 0);
  79:             break;
  80:         case 'D':   /* penalize routes beyond domains */
  81:             Dflag++;
  82:             break;
  83:         case 'f':   /* print cost of first hop */
  84:             Cflag++;
  85:             Fflag++;
  86:             break;
  87:         case 'g':   /* graph output file */
  88:             Graphout = optarg;
  89:             break;
  90:         case 'i':   /* ignore case */
  91:             Iflag++;
  92:             break;
  93:         case 'l':   /* local name */
  94:             locname = optarg;
  95:             break;
  96:         case 's':   /* show shortest path tree */
  97:             Linkout = optarg;
  98:             break;
  99:         case 't':   /* trace this link */
 100:             if (tracelink(optarg) < 0) {
 101:                 fprintf(stderr, "%s: can trace only %d links\n", Argv[0], NTRACE);
 102:                 exit(1);
 103:             }
 104:             Tflag = 1;
 105:             break;
 106:         case 'v':   /* verbose stderr, mixed blessing */
 107:             Vflag++;
 108: #ifndef TMPFILES    /* This could have unexpected side effects. */
 109:             if (Vflag == 1) {
 110:                 /* v8 pi snarf, benign EBADF elsewhere */
 111:                 sprintf(buf, "/proc/%05d\n", getpid());
 112:                 write(3, buf, strlen(buf));
 113:             }
 114: #endif /*TMPFILES*/
 115:             break;
 116:         default:
 117:             errflg++;
 118:         }
 119: 
 120:     if (errflg) {
 121:         fprintf(stderr, USAGE, Argv[0]);
 122:         exit(1);
 123:     }
 124:     argv += optind;     /* kludge for yywrap() */
 125: 
 126:     if (*argv)
 127:         freopen("/dev/null", "r", stdin);
 128:     else
 129:         Cfile = "[stdin]";
 130: 
 131:     if (!locname)
 132:         locname = local();
 133:     if (*locname == 0) {
 134:         locname = "lostinspace";
 135:         fprintf(stderr, "%s: using \"%s\" for local name\n",
 136:                 Argv[0], locname);
 137:     }
 138: 
 139:     Home = addnode(locname);    /* add home node */
 140:     getnode(Home)->n_cost = 0;  /* doesn't cost to get here */
 141: 
 142:     yyparse();          /* read in link info */
 143: 
 144:     if (Vflag > 1)
 145:         hashanalyze();
 146:     vprintf(stderr, "%ld vertices, %ld edges\n", Ncount, Lcount);
 147:     vprintf(stderr, "allocation is %ldk after parsing\n", allocation());
 148: 
 149:     Cfile = "[backlinks]";  /* for tracing back links */
 150:     Lineno = 0;
 151: 
 152:     /* compute shortest path tree */
 153:     mapit();
 154:     vprintf(stderr, "allocation is %ldk after mapping\n", allocation());
 155: 
 156:     /* traverse tree and print paths */
 157:     printit();
 158:     vprintf(stderr, "allocation is %ldk after printing\n", allocation());
 159: 
 160:     wasted();   /* how much was wasted in memory allocation? */
 161: 
 162: #ifdef TMPFILES     /* print out handy statistics, and clean up. */
 163:     vprintf(stderr, "node cache %ld hits, %ld misses\n", nhits, nmisses);
 164:     vprintf(stderr, "link cache %ld hits, %ld misses\n", lhits, lmisses);
 165: #ifndef DEBUG
 166:     (void) unlink(nfile);
 167:     (void) unlink(lfile);
 168:     (void) unlink(sfile);
 169: #endif /*DEBUG*/
 170: #endif /*TMPFILES*/
 171: 
 172:     return 0;
 173: }
 174: 
 175: void
 176: die(s)
 177:     char *s;
 178: {
 179:     fprintf(stderr, "%s: %s; notify the authorities\n", Argv[0], s);
 180: #ifdef DEBUG
 181:         fflush(stdout);
 182:         fflush(stderr);
 183:         abort();
 184: #else
 185: #ifdef TMPFILES
 186:         (void) unlink(nfile);
 187:         (void) unlink(lfile);
 188:         (void) unlink(sfile);
 189: #endif /*TMPFILES*/
 190:         exit(-1);
 191: #endif
 192: }

Defined functions

main defined in line 48; never used

Defined variables

Argc defined in line 23; used 1 times
  • in line 59
Argv defined in line 15; used 7 times
Cfile defined in line 12; used 3 times
Cflag defined in line 17; used 5 times
Dflag defined in line 18; used 3 times
Fflag defined in line 22; used 1 times
  • in line 85
Graphout defined in line 13; used 5 times
Iflag defined in line 19; used 1 times
  • in line 91
Lineno defined in line 24; used 1 times
Linkout defined in line 14; used 4 times
Tflag defined in line 20; used 7 times
Vflag defined in line 21; used 7 times
sccsid defined in line 3; never used

Defined macros

MAIN defined in line 6; never used
USAGE defined in line 46; used 1 times
getlink defined in line 34; used 1 times
  • in line 38
getnode defined in line 33; used 2 times
Last modified: 1988-04-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3850
Valid CSS Valid XHTML 1.0 Strict