home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / pathalias / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-17  |  4.1 KB  |  170 lines

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