home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / pathalias / y.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-24  |  26.3 KB  |  1,046 lines

  1. #ifndef lint
  2. char yysccsid[] = "@(#)yaccpar    1.5 (Berkeley) 06/03/90";
  3. #endif
  4. #line 2 "parse.y"
  5. /* pathalias -- by steve bellovin, as told to peter honeyman */
  6. #ifndef lint
  7. static char    *sccsid = "@(#)parse.y    9.10 88/09/07";
  8. #endif /* lint */
  9.  
  10. #include "def.h"
  11.  
  12. /* scanner states (yylex, parse) */
  13. #define OTHER        0
  14. #define COSTING        1
  15. #define NEWLINE        2
  16. #define FILENAME    3
  17.  
  18. /* exports */
  19. long Tcount;
  20. extern void yyerror();
  21.  
  22. /* imports */
  23. extern node *addnode(), *addprivate();
  24. extern void fixprivate(), alias(), deadlink(), deletelink();
  25. extern link *addlink();
  26. extern int strcmp();
  27. extern char *strsave();
  28. extern int optind;
  29. extern char *Cfile, *Netchars, **Argv;
  30. extern int Lineno, Argc;
  31.  
  32. /* privates */
  33. STATIC void fixnet(), adjust();
  34. STATIC int yylex(), yywrap(), getword();
  35. static int Scanstate = NEWLINE;    /* scanner (yylex) state */
  36.  
  37. /* flags for ys_flags */
  38. #define TERMINAL 1
  39. #line 38 "parse.y"
  40. typedef union {
  41.     node    *y_node;
  42.     Cost    y_cost;
  43.     char    y_net;
  44.     char    *y_name;
  45.     struct {
  46.         node *ys_node;
  47.         Cost ys_cost;
  48.         short ys_flag;
  49.         char ys_net;
  50.         char ys_dir;
  51.     } y_s;
  52. } YYSTYPE;
  53. #line 54 "y.tab.c"
  54. #define SITE 257
  55. #define HOST 258
  56. #define STRING 259
  57. #define COST 260
  58. #define NET 261
  59. #define EOL 262
  60. #define PRIVATE 263
  61. #define DEAD 264
  62. #define DELETE 265
  63. #define FILETOK 266
  64. #define ADJUST 267
  65. #define YYERRCODE 256
  66. short yylhs[] = {                                        -1,
  67.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  68.     0,    3,    3,    3,    8,    8,    8,    8,    8,    8,
  69.     1,    1,    1,    2,    2,    4,    4,    4,    6,    6,
  70.     6,    9,    9,    7,    7,    7,   15,   15,    5,    5,
  71.     5,   16,   12,   12,   12,   11,   11,   10,   17,   20,
  72.    20,   20,   21,   21,   22,   23,   18,   19,   24,   24,
  73.    24,   25,   13,   26,   27,   13,   14,   14,   14,   14,
  74.    14,   14,   14,
  75. };
  76. short yylen[] = {                                         2,
  77.     0,    2,    3,    3,    3,    3,    3,    3,    3,    3,
  78.     2,    3,    4,    2,    1,    1,    1,    1,    1,    1,
  79.     1,    2,    2,    1,    3,    3,    3,    2,    5,    6,
  80.     6,    1,    2,    1,    3,    2,    4,    3,    1,    3,
  81.     2,    4,    1,    3,    2,    1,    3,    1,    4,    1,
  82.     3,    2,    1,    3,    0,    0,    6,    4,    1,    3,
  83.     2,    2,    0,    0,    0,    5,    1,    2,    3,    3,
  84.     3,    3,    3,
  85. };
  86. short yydefred[] = {                                      0,
  87.     0,    0,   11,   15,    2,    0,    0,    0,    0,    0,
  88.    32,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  89.     0,    0,    0,    0,   55,    0,    3,    0,    4,    0,
  90.     5,   24,    0,    0,    0,    0,    0,    0,    0,    6,
  91.     7,    8,    9,   10,   39,   38,    0,    0,    0,   43,
  92.     0,    0,    0,    0,   50,    0,   48,    0,    0,   59,
  93.     0,   27,   22,    0,   26,   64,   12,   23,    0,   34,
  94.     0,    0,   37,    0,    0,   42,    0,    0,   49,   56,
  95.    62,    0,   58,   13,   25,    0,    0,    0,    0,   40,
  96.    47,   44,   54,   51,    0,   60,   67,    0,    0,    0,
  97.     0,   35,    0,   29,   57,    0,    0,    0,    0,    0,
  98.     0,    0,   30,   31,   69,    0,    0,   72,   73,   66,
  99. };
  100. short yydgoto[] = {                                       2,
  101.    36,   37,   12,   13,   47,   14,   71,   15,   16,   49,
  102.    50,   51,   67,  100,   17,   18,   19,   20,   21,   54,
  103.    55,   56,   95,   59,   60,   86,  112,
  104. };
  105. short yysindex[] = {                                   -234,
  106.  -237,  -55,    0,    0,    0,  -96,  -93,  -78,  -74,  -72,
  107.     0,  -41,  -36, -204,  -44, -109, -202, -178, -177, -176,
  108.  -175, -104, -168, -167,    0, -166,    0,  -14,    0, -165,
  109.     0,    0,  -51, -164, -163,   59, -161,   -5, -154,    0,
  110.     0,    0,    0,    0,    0,    0,  -21,    0, -153,    0,
  111.   -20,    0, -150,  -18,    0, -142,    0,   59,  -16,    0,
  112.    59,    0,    0,   57,    0,    0,    0,    0, -154,    0,
  113.   -15, -137,    0, -166, -168,    0, -166, -167,    0,    0,
  114.     0, -166,    0,    0,    0,  -35,  -13, -135,  -38,    0,
  115.     0,    0,    0,    0,   -2,    0,    0,  -35,  -35,   14,
  116.    59,    0,   59,    0,    0,   28,   26,  -35,  -35,  -35,
  117.   -35,   83,    0,    0,    0,   28,   28,    0,    0,    0,
  118. };
  119. short yyrindex[] = {                                      1,
  120.     0,    0,    0,    0,    0,  -42,  -24,  -22,  -19,  -17,
  121.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  122.     0,    0,    0,    0,    0,    0,    0,  -33,    0,  -32,
  123.     0,    0,    0,    0, -103,  -31,  -40,    0,    0,    0,
  124.     0,    0,    0,    0,    0,    0,    0,  -37,    0,    0,
  125.     0,  -29,    0,    0,    0,    0,    0,  -12,    0,    0,
  126.   -31,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  127.     0,  -11,    0,    0,  -10,    0,    0,   -9,    0,    0,
  128.     0,   -4,    0,    0,    0,    0,    0,    3, -136,    0,
  129.     0,    0,    0,    0,    0,    0,    0,    0,    0,   84,
  130.  -136,    0, -136,    0,    0,   31,    0,    0,    0,    0,
  131.     0,    0,    0,    0,    0,   36,   37,    0,    0,    0,
  132. };
  133. short yygindex[] = {                                      0,
  134.    99,   96,    0,    0,    0,    0,   61,    0,    0,   24,
  135.    56,    0,   -6,  -45,    0,    0,    0,    0,    0,    0,
  136.    54,    0,    0,    0,   51,    0,    0,
  137. };
  138. #define YYTABLESIZE 268
  139. short yytable[] = {                                      21,
  140.     1,   66,   28,   21,   99,   11,   46,   30,   34,   98,
  141.    14,   28,   63,   39,   53,   34,   35,   16,   16,   33,
  142.    46,    1,   72,   75,    3,   78,   22,   82,   88,   23,
  143.    88,   63,   41,   45,   52,   17,   17,   18,   18,   61,
  144.    19,   19,   20,   20,   24,   34,   36,   53,   25,   58,
  145.    26,   81,  106,  107,   84,  110,  108,   31,  109,   40,
  146.   111,    1,  116,  117,  118,  119,  115,  110,  108,  110,
  147.   109,   68,  111,   68,  111,   68,   70,   71,   70,   71,
  148.    70,   71,  104,   41,   42,   43,   44,   46,   48,   52,
  149.    57,   62,   64,   65,  113,   53,  114,   91,   66,   68,
  150.    93,   53,   70,   73,   76,   58,   79,   74,   83,   89,
  151.    77,  101,   63,   41,   45,   52,   80,   69,   85,   90,
  152.    61,  102,  105,  120,   65,   63,   61,   36,   63,   87,
  153.    92,   94,   96,    0,    0,    0,    0,    0,    0,    0,
  154.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  155.     0,   38,   45,    0,    0,    0,    0,   33,    0,    0,
  156.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  157.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  158.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  159.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  160.     0,    0,    4,    0,    0,   32,    5,    6,    7,    8,
  161.     9,   10,   32,    0,   16,    0,   33,    0,   16,    0,
  162.    27,   21,  103,   48,   97,   29,    0,    0,   14,   28,
  163.    63,   48,   17,    0,   18,    0,   17,   19,   18,   20,
  164.     0,   19,   32,   20,    0,    0,   33,    0,    0,    0,
  165.     0,    0,    0,    0,    0,    0,    0,    0,    1,    0,
  166.     0,    0,    1,    1,    1,    1,    1,    1,
  167. };
  168. short yycheck[] = {                                      40,
  169.     0,   40,   44,   44,   40,   61,   44,   44,   60,   45,
  170.    44,   44,   44,  123,   44,   60,   61,   60,   61,  123,
  171.   125,  256,   44,   44,  262,   44,  123,   44,   44,  123,
  172.    44,   44,   44,   44,   44,   60,   61,   60,   61,   44,
  173.    60,   61,   60,   61,  123,   60,   44,   24,  123,   26,
  174.   123,   58,   98,   99,   61,   42,   43,  262,   45,  262,
  175.    47,   61,  108,  109,  110,  111,   41,   42,   43,   42,
  176.    45,   41,   47,   43,   47,   45,   41,   41,   43,   43,
  177.    45,   45,   89,  262,  262,  262,  262,  125,  257,  257,
  178.   257,  257,  257,  257,  101,  125,  103,   74,   40,  261,
  179.    77,   78,  257,  125,  125,   82,  125,  261,  125,  125,
  180.   261,  125,  125,  125,  125,  125,  259,  123,   62,  257,
  181.   125,  257,  125,   41,   41,  262,   28,  125,   33,   69,
  182.    75,   78,   82,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  183.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  184.    -1,  261,  257,   -1,   -1,   -1,   -1,  261,   -1,   -1,
  185.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  186.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  187.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  188.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  189.    -1,   -1,  258,   -1,   -1,  257,  262,  263,  264,  265,
  190.   266,  267,  257,   -1,  257,   -1,  261,   -1,  261,   -1,
  191.   262,  262,  261,  261,  260,  262,   -1,   -1,  262,  262,
  192.   262,  261,  257,   -1,  257,   -1,  261,  257,  261,  257,
  193.    -1,  261,  257,  261,   -1,   -1,  261,   -1,   -1,   -1,
  194.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,   -1,
  195.    -1,   -1,  262,  263,  264,  265,  266,  267,
  196. };
  197. #define YYFINAL 2
  198. #ifndef YYDEBUG
  199. #define YYDEBUG 0
  200. #endif
  201. #define YYMAXTOKEN 267
  202. #if YYDEBUG
  203. char *yyname[] = {
  204. "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  205. 0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,0,0,
  206. "'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  207. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,0,0,
  208. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  209. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  210. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  211. 0,0,0,0,0,0,0,"SITE","HOST","STRING","COST","NET","EOL","PRIVATE","DEAD",
  212. "DELETE","FILETOK","ADJUST",
  213. };
  214. char *yyrule[] = {
  215. "$accept : map",
  216. "map :",
  217. "map : map EOL",
  218. "map : map links EOL",
  219. "map : map aliases EOL",
  220. "map : map network EOL",
  221. "map : map private EOL",
  222. "map : map dead EOL",
  223. "map : map delete EOL",
  224. "map : map file EOL",
  225. "map : map adjust EOL",
  226. "map : error EOL",
  227. "links : host site cost",
  228. "links : links ',' site cost",
  229. "links : links ','",
  230. "host : HOST",
  231. "host : PRIVATE",
  232. "host : DEAD",
  233. "host : DELETE",
  234. "host : FILETOK",
  235. "host : ADJUST",
  236. "site : asite",
  237. "site : NET asite",
  238. "site : asite NET",
  239. "asite : SITE",
  240. "asite : '<' SITE '>'",
  241. "aliases : host '=' SITE",
  242. "aliases : aliases ',' SITE",
  243. "aliases : aliases ','",
  244. "network : nhost '{' nlist '}' cost",
  245. "network : nhost NET '{' nlist '}' cost",
  246. "network : nhost '{' nlist '}' NET cost",
  247. "nhost : '='",
  248. "nhost : host '='",
  249. "nlist : SITE",
  250. "nlist : nlist ',' SITE",
  251. "nlist : nlist ','",
  252. "private : PRIVATE '{' plist '}'",
  253. "private : PRIVATE '{' '}'",
  254. "plist : SITE",
  255. "plist : plist ',' SITE",
  256. "plist : plist ','",
  257. "dead : DEAD '{' dlist '}'",
  258. "dlist : delem",
  259. "dlist : dlist ',' delem",
  260. "dlist : dlist ','",
  261. "delem : SITE",
  262. "delem : usite NET usite",
  263. "usite : SITE",
  264. "delete : DELETE '{' dellist '}'",
  265. "dellist : delelem",
  266. "dellist : dellist ',' delelem",
  267. "dellist : dellist ','",
  268. "delelem : SITE",
  269. "delelem : usite NET usite",
  270. "$$1 :",
  271. "$$2 :",
  272. "file : FILETOK '{' $$1 STRING $$2 '}'",
  273. "adjust : ADJUST '{' adjlist '}'",
  274. "adjlist : adjelem",
  275. "adjlist : adjlist ',' adjelem",
  276. "adjlist : adjlist ','",
  277. "adjelem : usite cost",
  278. "cost :",
  279. "$$3 :",
  280. "$$4 :",
  281. "cost : '(' $$3 cexpr $$4 ')'",
  282. "cexpr : COST",
  283. "cexpr : '-' cexpr",
  284. "cexpr : '(' cexpr ')'",
  285. "cexpr : cexpr '+' cexpr",
  286. "cexpr : cexpr '-' cexpr",
  287. "cexpr : cexpr '*' cexpr",
  288. "cexpr : cexpr '/' cexpr",
  289. };
  290. #endif
  291. #define yyclearin (yychar=(-1))
  292. #define yyerrok (yyerrflag=0)
  293. #ifndef YYSTACKSIZE
  294. #ifdef YYMAXDEPTH
  295. #define YYSTACKSIZE YYMAXDEPTH
  296. #else
  297. #define YYSTACKSIZE 300
  298. #endif
  299. #endif
  300. int yydebug;
  301. int yynerrs;
  302. int yyerrflag;
  303. int yychar;
  304. short *yyssp;
  305. YYSTYPE *yyvsp;
  306. YYSTYPE yyval;
  307. YYSTYPE yylval;
  308. #define yystacksize YYSTACKSIZE
  309. short yyss[YYSTACKSIZE];
  310. YYSTYPE yyvs[YYSTACKSIZE];
  311. #line 235 "parse.y"
  312.  
  313. void
  314. #ifdef YYDEBUG
  315. /*VARARGS1*/
  316. yyerror(fmt, arg)
  317.     char *fmt, *arg;
  318. #else
  319. yyerror(s)
  320.     char *s;
  321. #endif
  322. {
  323.     /* a concession to bsd error(1) */
  324.     fprintf(stderr, "\"%s\", ", Cfile);
  325. #ifdef YYDEBUG
  326.     fprintf(stderr, "line %d: ", Lineno);
  327.     fprintf(stderr, fmt, arg);
  328.     putc('\n', stderr);
  329. #else
  330.     fprintf(stderr, "line %d: %s\n", Lineno, s);
  331. #endif
  332. }
  333.  
  334. /*
  335.  * patch in the costs of getting on/off the network.
  336.  *
  337.  * for each network member on netlist, add links:
  338.  *    network -> member    cost = 0;
  339.  *    member -> network    cost = parameter.
  340.  *
  341.  * if network and member both require gateways, assume network
  342.  * is a gateway to member (but not v.v., to avoid such travesties
  343.  * as topaz!seismo.css.gov.edu.rutgers).
  344.  *
  345.  * note that members can have varying costs to a network, by suitable
  346.  * multiple declarations.  this is a feechur, albeit a useless one.
  347.  */
  348. STATIC void
  349. fixnet(network, nlist, cost, netchar, netdir)
  350.     register node *network;
  351.     node *nlist;
  352.     Cost cost;
  353.     char netchar, netdir;
  354. {    register node *member, *nextnet;
  355.     link *l;
  356.     static int netanon = 0;
  357.     char anon[25];
  358.  
  359.     if (network == 0) {
  360.         sprintf(anon, "[unnamed net %d]", netanon++);
  361.         network = addnode(anon);
  362.     }
  363.     network->n_flag |= NNET;
  364.  
  365.     /* insert the links */
  366.     for (member = nlist ; member; member = nextnet) {
  367.  
  368.         /* network -> member, cost is 0 */
  369.         l = addlink(network, member, (Cost) 0, netchar, netdir);
  370.         if (GATEWAYED(network) && GATEWAYED(member))
  371.             l->l_flag |= LGATEWAY;
  372.  
  373.         /* member -> network, cost is parameter */
  374.         /* never ever ever crawl up from a domain*/
  375.         if (!ISADOMAIN(network))
  376.             (void) addlink(member, network, cost, netchar, netdir);
  377.  
  378.         nextnet = member->n_net;
  379.         member->n_net = 0;    /* clear for later use */
  380.     }
  381. }
  382.  
  383. /* scanner */
  384.  
  385. #define QUOTE '"'
  386. #define STR_EQ(s1, s2) (s1[2] == s2[2] && strcmp(s1, s2) == 0)
  387. #define NLRETURN() {Scanstate = NEWLINE; return EOL;}
  388.  
  389. static struct ctable {
  390.     char *cname;
  391.     Cost cval;
  392. } ctable[] = {
  393.     /* ordered by frequency of appearance in a "typical" dataset */
  394.     {"DIRECT", 200},
  395.     {"DEMAND", 300},
  396.     {"DAILY", 5000},
  397.     {"HOURLY", 500},
  398.     {"DEDICATED", 100},
  399.     {"EVENING", 2000},
  400.     {"LOCAL", 25},
  401.     {"LOW", 5},    /* baud rate, quality penalty */
  402.     {"DEAD", MILLION},
  403.     {"POLLED", 5000},
  404.     {"WEEKLY", 30000},
  405.     {"HIGH", -5},    /* baud rate, quality bonus */
  406.     {"FAST", -80},    /* high speed (>= 9.6 kbps) modem */
  407.     /* deprecated */
  408.     {"ARPA", 100},
  409.     {"DIALED", 300},
  410.     {0, 0}
  411. };
  412.  
  413. STATIC int
  414. yylex()
  415. {    static char retbuf[128];    /* for return to yacc part */
  416.     register int c;
  417.     register char *buf = retbuf;
  418.     register struct ctable *ct;
  419.     register Cost cost;
  420.     char errbuf[128];
  421.  
  422.     if (feof(stdin) && yywrap())
  423.         return EOF;
  424.  
  425.     /* count lines, skip over space and comments */
  426.     if ((c = getchar()) == EOF)
  427.         NLRETURN();
  428.     
  429. continuation:
  430.     while (c == ' ' || c == '\t')
  431.         if ((c = getchar()) == EOF)
  432.             NLRETURN();
  433.  
  434.     if (c == '#')
  435.         while ((c = getchar()) != '\n')
  436.             if (c == EOF)
  437.                 NLRETURN();
  438.  
  439.     /* scan token */
  440.     if (c == '\n') {
  441.         Lineno++;
  442.         if ((c = getchar()) != EOF) {
  443.             if (c == ' ' || c == '\t')
  444.                 goto continuation;
  445.             ungetc(c, stdin);
  446.         }
  447.         NLRETURN();
  448.     }
  449.  
  450.     switch(Scanstate) {
  451.     case COSTING:
  452.         if (isdigit(c)) {
  453.             cost = c - '0';
  454.             for (c = getchar(); isdigit(c); c = getchar())
  455.                 cost = (cost * 10) + c - '0';
  456.             ungetc(c, stdin);
  457.             yylval.y_cost = cost;
  458.             return COST;
  459.         }
  460.  
  461.         if (getword(buf, c) == 0) {
  462.             for (ct = ctable; ct->cname; ct++)
  463.                 if (STR_EQ(buf, ct->cname)) {
  464.                     yylval.y_cost = ct->cval;
  465.                     return COST;
  466.                 }
  467.             sprintf(errbuf, "unknown cost (%s), using default", buf);
  468.             yyerror(errbuf);
  469.             yylval.y_cost = DEFCOST;
  470.             return COST;
  471.         }
  472.  
  473.         return c;    /* pass the buck */
  474.  
  475.     case NEWLINE:
  476.         Scanstate = OTHER;
  477.         if (getword(buf, c) != 0)
  478.             return c;
  479.         /*
  480.          * special purpose tokens.
  481.          *
  482.          * the "switch" serves the dual-purpose of recognizing
  483.          * unquoted tokens only.
  484.          */
  485.         switch(c) {
  486.         case 'p':
  487.             if (STR_EQ(buf, "private"))
  488.                 return PRIVATE;
  489.             break;
  490.         case 'd':
  491.             if (STR_EQ(buf, "dead"))
  492.                 return DEAD;
  493.             if (STR_EQ(buf, "delete"))
  494.                 return DELETE;
  495.             break;
  496.         case 'f':
  497.             if (STR_EQ(buf, "file"))
  498.                 return FILETOK;
  499.             break;
  500.         case 'a':
  501.             if (STR_EQ(buf, "adjust"))
  502.                 return ADJUST;
  503.             break;
  504.         }
  505.  
  506.         yylval.y_name = buf;
  507.         return HOST;
  508.  
  509.     case FILENAME:
  510.         while (c != EOF && isprint(c)) {
  511.             if (c == ' ' || c == '\t' || c == '\n' || c == '}')
  512.                 break;
  513.             *buf++ = c;
  514.             c = getchar();
  515.         }
  516.         if (c != EOF)
  517.             ungetc(c, stdin);
  518.         *buf = 0;
  519.         yylval.y_name = retbuf;
  520.         return STRING;
  521.     }
  522.  
  523.     if (getword(buf, c) == 0) {
  524.         yylval.y_name = buf;
  525.         return SITE;
  526.     }
  527.  
  528.     if (index(Netchars, c)) {
  529.         yylval.y_net = c;
  530.         return NET;
  531.     }
  532.  
  533.     return c;
  534. }
  535.  
  536. /*
  537.  * fill str with the next word in [0-9A-Za-z][-._0-9A-Za-z]+ or a quoted
  538.  * string that contains no newline.  return -1 on failure or EOF, 0 o.w.
  539.  */ 
  540. STATIC int
  541. getword(str, c)
  542.     register char *str;
  543.     register int c;
  544. {
  545.     if (c == QUOTE) {
  546.         while ((c = getchar()) != QUOTE) {
  547.             if (c == '\n') {
  548.                 yyerror("newline in quoted string\n");
  549.                 ungetc(c, stdin);
  550.                 return -1;
  551.             }
  552.             if (c == EOF) {
  553.                 yyerror("EOF in quoted string\n");
  554.                 return -1;
  555.             }
  556.             *str++ = c;
  557.         }
  558.         *str = 0;
  559.         return 0;
  560.     }
  561.  
  562.     /* host name must start with alphanumeric or `.' */
  563.     if (!isalnum(c) && c != '.')
  564.         return -1;
  565.  
  566. yymore:
  567.     do {
  568.         *str++ = c;
  569.         c = getchar();
  570.     } while (isalnum(c) || c == '.' || c == '_');
  571.  
  572.     if (c == '-' && Scanstate != COSTING)
  573.         goto yymore;
  574.  
  575.     ungetc(c, stdin);
  576.     *str = 0;
  577.     return 0;
  578. }
  579.  
  580. STATIC int
  581. yywrap()
  582. {    char errbuf[100];
  583.  
  584.     fixprivate();    /* munge private host definitions */
  585.     Lineno = 1;
  586.     while (optind < Argc) {
  587.         if (freopen((Cfile = Argv[optind++]), "r", stdin) != 0)
  588.             return 0;
  589.         sprintf(errbuf, "%s: %s", Argv[0], Cfile);
  590.         perror(errbuf);
  591.     }
  592.     freopen("/dev/null", "r", stdin);
  593.     return -1;
  594. }
  595.  
  596. STATIC void
  597. adjust(n, cost)
  598.     node *n;
  599.     Cost cost;
  600. {    link *l;
  601.  
  602.     n->n_cost += cost;    /* cumulative */
  603.  
  604.     /* hit existing links */
  605.     for (l = n->n_link; l; l = l->l_next) {
  606.         if ((l->l_cost += cost) < 0) {
  607.             char buf[100];
  608.  
  609.             l->l_flag |= LDEAD;
  610.             sprintf(buf, "link to %s deleted with negative cost",
  611.                             l->l_to->n_name);
  612.             yyerror(buf);
  613.         }
  614.     }
  615. }
  616. #line 617 "y.tab.c"
  617. #define YYABORT goto yyabort
  618. #define YYACCEPT goto yyaccept
  619. #define YYERROR goto yyerrlab
  620. int
  621. yyparse()
  622. {
  623.     register int yym, yyn, yystate;
  624. #if YYDEBUG
  625.     register char *yys;
  626.     extern char *getenv();
  627.  
  628.     if (yys = getenv("YYDEBUG"))
  629.     {
  630.         yyn = *yys;
  631.         if (yyn >= '0' && yyn <= '9')
  632.             yydebug = yyn - '0';
  633.     }
  634. #endif
  635.  
  636.     yynerrs = 0;
  637.     yyerrflag = 0;
  638.     yychar = (-1);
  639.  
  640.     yyssp = yyss;
  641.     yyvsp = yyvs;
  642.     *yyssp = yystate = 0;
  643.  
  644. yyloop:
  645.     if (yyn = yydefred[yystate]) goto yyreduce;
  646.     if (yychar < 0)
  647.     {
  648.         if ((yychar = yylex()) < 0) yychar = 0;
  649. #if YYDEBUG
  650.         if (yydebug)
  651.         {
  652.             yys = 0;
  653.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  654.             if (!yys) yys = "illegal-symbol";
  655.             printf("yydebug: state %d, reading %d (%s)\n", yystate,
  656.                     yychar, yys);
  657.         }
  658. #endif
  659.     }
  660.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  661.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  662.     {
  663. #if YYDEBUG
  664.         if (yydebug)
  665.             printf("yydebug: state %d, shifting to state %d\n",
  666.                     yystate, yytable[yyn]);
  667. #endif
  668.         if (yyssp >= yyss + yystacksize - 1)
  669.         {
  670.             goto yyoverflow;
  671.         }
  672.         *++yyssp = yystate = yytable[yyn];
  673.         *++yyvsp = yylval;
  674.         yychar = (-1);
  675.         if (yyerrflag > 0)  --yyerrflag;
  676.         goto yyloop;
  677.     }
  678.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  679.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  680.     {
  681.         yyn = yytable[yyn];
  682.         goto yyreduce;
  683.     }
  684.     if (yyerrflag) goto yyinrecovery;
  685. #ifdef lint
  686.     goto yynewerror;
  687. #endif
  688. yynewerror:
  689.     yyerror("syntax error");
  690. #ifdef lint
  691.     goto yyerrlab;
  692. #endif
  693. yyerrlab:
  694.     ++yynerrs;
  695. yyinrecovery:
  696.     if (yyerrflag < 3)
  697.     {
  698.         yyerrflag = 3;
  699.         for (;;)
  700.         {
  701.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  702.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  703.             {
  704. #if YYDEBUG
  705.                 if (yydebug)
  706.                     printf("yydebug: state %d, error recovery shifting\
  707.  to state %d\n", *yyssp, yytable[yyn]);
  708. #endif
  709.                 if (yyssp >= yyss + yystacksize - 1)
  710.                 {
  711.                     goto yyoverflow;
  712.                 }
  713.                 *++yyssp = yystate = yytable[yyn];
  714.                 *++yyvsp = yylval;
  715.                 goto yyloop;
  716.             }
  717.             else
  718.             {
  719. #if YYDEBUG
  720.                 if (yydebug)
  721.                     printf("yydebug: error recovery discarding state %d\n",
  722.                             *yyssp);
  723. #endif
  724.                 if (yyssp <= yyss) goto yyabort;
  725.                 --yyssp;
  726.                 --yyvsp;
  727.             }
  728.         }
  729.     }
  730.     else
  731.     {
  732.         if (yychar == 0) goto yyabort;
  733. #if YYDEBUG
  734.         if (yydebug)
  735.         {
  736.             yys = 0;
  737.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  738.             if (!yys) yys = "illegal-symbol";
  739.             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  740.                     yystate, yychar, yys);
  741.         }
  742. #endif
  743.         yychar = (-1);
  744.         goto yyloop;
  745.     }
  746. yyreduce:
  747. #if YYDEBUG
  748.     if (yydebug)
  749.         printf("yydebug: state %d, reducing by rule %d (%s)\n",
  750.                 yystate, yyn, yyrule[yyn]);
  751. #endif
  752.     yym = yylen[yyn];
  753.     yyval = yyvsp[1-yym];
  754.     switch (yyn)
  755.     {
  756. case 12:
  757. #line 79 "parse.y"
  758. {
  759.         struct link *l;
  760.  
  761.         l = addlink(yyvsp[-2].y_node, yyvsp[-1].y_s.ys_node, yyvsp[0].y_cost, yyvsp[-1].y_s.ys_net, yyvsp[-1].y_s.ys_dir);
  762.         if (GATEWAYED(yyvsp[-1].y_s.ys_node))
  763.             l->l_flag |= LGATEWAY;
  764.         if (yyvsp[-1].y_s.ys_flag & TERMINAL)
  765.             l->l_flag |= LTERMINAL;
  766.       }
  767. break;
  768. case 13:
  769. #line 88 "parse.y"
  770. {
  771.         struct link *l;
  772.  
  773.         l = addlink(yyvsp[-3].y_node, yyvsp[-1].y_s.ys_node, yyvsp[0].y_cost, yyvsp[-1].y_s.ys_net, yyvsp[-1].y_s.ys_dir);
  774.         if (GATEWAYED(yyvsp[-1].y_s.ys_node))
  775.             l->l_flag |= LGATEWAY;
  776.         if (yyvsp[-1].y_s.ys_flag & TERMINAL)
  777.             l->l_flag |= LTERMINAL;
  778.       }
  779. break;
  780. case 15:
  781. #line 100 "parse.y"
  782. {yyval.y_node = addnode(yyvsp[0].y_name);}
  783. break;
  784. case 16:
  785. #line 101 "parse.y"
  786. {yyval.y_node = addnode("private");}
  787. break;
  788. case 17:
  789. #line 102 "parse.y"
  790. {yyval.y_node = addnode("dead");}
  791. break;
  792. case 18:
  793. #line 103 "parse.y"
  794. {yyval.y_node = addnode("delete");}
  795. break;
  796. case 19:
  797. #line 104 "parse.y"
  798. {yyval.y_node = addnode("file");}
  799. break;
  800. case 20:
  801. #line 105 "parse.y"
  802. {yyval.y_node = addnode("adjust");}
  803. break;
  804. case 21:
  805. #line 108 "parse.y"
  806. {
  807.         yyval.y_s = yyvsp[0].y_s;
  808.         yyval.y_s.ys_net = DEFNET;
  809.         yyval.y_s.ys_dir = DEFDIR;
  810.       }
  811. break;
  812. case 22:
  813. #line 113 "parse.y"
  814. {
  815.         yyval.y_s = yyvsp[0].y_s;
  816.         yyval.y_s.ys_net = yyvsp[-1].y_net;
  817.         yyval.y_s.ys_dir = LRIGHT;
  818.       }
  819. break;
  820. case 23:
  821. #line 118 "parse.y"
  822. {
  823.         yyval.y_s = yyvsp[-1].y_s;
  824.         yyval.y_s.ys_net = yyvsp[0].y_net;
  825.         yyval.y_s.ys_dir = LLEFT;
  826.       }
  827. break;
  828. case 24:
  829. #line 125 "parse.y"
  830. {
  831.         yyval.y_s.ys_node = addnode(yyvsp[0].y_name);
  832.         yyval.y_s.ys_flag = 0;
  833.       }
  834. break;
  835. case 25:
  836. #line 129 "parse.y"
  837. {
  838.         Tcount++;
  839.         yyval.y_s.ys_node = addnode(yyvsp[-1].y_name);
  840.         yyval.y_s.ys_flag = TERMINAL;
  841.       }
  842. break;
  843. case 26:
  844. #line 136 "parse.y"
  845. {alias(yyvsp[-2].y_node, addnode(yyvsp[0].y_name));}
  846. break;
  847. case 27:
  848. #line 137 "parse.y"
  849. {alias(yyvsp[-2].y_node, addnode(yyvsp[0].y_name));}
  850. break;
  851. case 29:
  852. #line 141 "parse.y"
  853. {fixnet(yyvsp[-4].y_node, yyvsp[-2].y_node, yyvsp[0].y_cost, DEFNET, DEFDIR);}
  854. break;
  855. case 30:
  856. #line 142 "parse.y"
  857. {fixnet(yyvsp[-5].y_node, yyvsp[-2].y_node, yyvsp[0].y_cost, yyvsp[-4].y_net, LRIGHT);}
  858. break;
  859. case 31:
  860. #line 143 "parse.y"
  861. {fixnet(yyvsp[-5].y_node, yyvsp[-3].y_node, yyvsp[0].y_cost, yyvsp[-1].y_net, LLEFT);}
  862. break;
  863. case 32:
  864. #line 146 "parse.y"
  865. {yyval.y_node = 0;    /* anonymous net */}
  866. break;
  867. case 33:
  868. #line 147 "parse.y"
  869. {yyval.y_node = yyvsp[-1].y_node;    /* named net */}
  870. break;
  871. case 34:
  872. #line 150 "parse.y"
  873. {yyval.y_node = addnode(yyvsp[0].y_name);}
  874. break;
  875. case 35:
  876. #line 151 "parse.y"
  877. {
  878.         node *n;
  879.  
  880.         n = addnode(yyvsp[0].y_name);
  881.         if (n->n_net == 0) {
  882.             n->n_net = yyvsp[-2].y_node;
  883.             yyval.y_node = n;
  884.         }
  885.       }
  886. break;
  887. case 38:
  888. #line 164 "parse.y"
  889. {fixprivate();}
  890. break;
  891. case 39:
  892. #line 167 "parse.y"
  893. {addprivate(yyvsp[0].y_name)->n_flag |= ISPRIVATE;}
  894. break;
  895. case 40:
  896. #line 168 "parse.y"
  897. {addprivate(yyvsp[0].y_name)->n_flag |= ISPRIVATE;}
  898. break;
  899. case 46:
  900. #line 179 "parse.y"
  901. {deadlink(addnode(yyvsp[0].y_name), (node *) 0);}
  902. break;
  903. case 47:
  904. #line 180 "parse.y"
  905. {deadlink(yyvsp[-2].y_node, yyvsp[0].y_node);}
  906. break;
  907. case 48:
  908. #line 183 "parse.y"
  909. {yyval.y_node = addnode(yyvsp[0].y_name);}
  910. break;
  911. case 53:
  912. #line 192 "parse.y"
  913. {
  914.         node *n;
  915.  
  916.         n = addnode(yyvsp[0].y_name);
  917.         deletelink(n, (node *) 0);
  918.         n->n_flag |= ISPRIVATE;
  919.       }
  920. break;
  921. case 54:
  922. #line 199 "parse.y"
  923. {deletelink(yyvsp[-2].y_node, yyvsp[0].y_node);}
  924. break;
  925. case 55:
  926. #line 202 "parse.y"
  927. {Scanstate = FILENAME;}
  928. break;
  929. case 56:
  930. #line 202 "parse.y"
  931. {Scanstate = OTHER;}
  932. break;
  933. case 57:
  934. #line 202 "parse.y"
  935. {
  936.         Lineno = 0;
  937.         Cfile = strsave(yyvsp[-2].y_name);
  938.     }
  939. break;
  940. case 62:
  941. #line 214 "parse.y"
  942. {adjust(yyvsp[-1].y_node, yyvsp[0].y_cost);}
  943. break;
  944. case 63:
  945. #line 216 "parse.y"
  946. {yyval.y_cost = DEFCOST;    /* empty -- cost is always optional */}
  947. break;
  948. case 64:
  949. #line 217 "parse.y"
  950. {Scanstate = COSTING;}
  951. break;
  952. case 65:
  953. #line 217 "parse.y"
  954. {Scanstate = OTHER;}
  955. break;
  956. case 66:
  957. #line 218 "parse.y"
  958. {yyval.y_cost = yyvsp[-2].y_cost;}
  959. break;
  960. case 68:
  961. #line 222 "parse.y"
  962. {yyval.y_cost = -yyvsp[0].y_cost;}
  963. break;
  964. case 69:
  965. #line 223 "parse.y"
  966. {yyval.y_cost = yyvsp[-1].y_cost;}
  967. break;
  968. case 70:
  969. #line 224 "parse.y"
  970. {yyval.y_cost = yyvsp[-2].y_cost + yyvsp[0].y_cost;}
  971. break;
  972. case 71:
  973. #line 225 "parse.y"
  974. {yyval.y_cost = yyvsp[-2].y_cost - yyvsp[0].y_cost;}
  975. break;
  976. case 72:
  977. #line 226 "parse.y"
  978. {yyval.y_cost = yyvsp[-2].y_cost * yyvsp[0].y_cost;}
  979. break;
  980. case 73:
  981. #line 227 "parse.y"
  982. {
  983.         if (yyvsp[0].y_cost == 0)
  984.             yyerror("zero divisor\n");
  985.         else
  986.             yyval.y_cost = yyvsp[-2].y_cost / yyvsp[0].y_cost;
  987.       }
  988. break;
  989. #line 990 "y.tab.c"
  990.     }
  991.     yyssp -= yym;
  992.     yystate = *yyssp;
  993.     yyvsp -= yym;
  994.     yym = yylhs[yyn];
  995.     if (yystate == 0 && yym == 0)
  996.     {
  997. #if YYDEBUG
  998.         if (yydebug)
  999.             printf("yydebug: after reduction, shifting from state 0 to\
  1000.  state %d\n", YYFINAL);
  1001. #endif
  1002.         yystate = YYFINAL;
  1003.         *++yyssp = YYFINAL;
  1004.         *++yyvsp = yyval;
  1005.         if (yychar < 0)
  1006.         {
  1007.             if ((yychar = yylex()) < 0) yychar = 0;
  1008. #if YYDEBUG
  1009.             if (yydebug)
  1010.             {
  1011.                 yys = 0;
  1012.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1013.                 if (!yys) yys = "illegal-symbol";
  1014.                 printf("yydebug: state %d, reading %d (%s)\n",
  1015.                         YYFINAL, yychar, yys);
  1016.             }
  1017. #endif
  1018.         }
  1019.         if (yychar == 0) goto yyaccept;
  1020.         goto yyloop;
  1021.     }
  1022.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  1023.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  1024.         yystate = yytable[yyn];
  1025.     else
  1026.         yystate = yydgoto[yym];
  1027. #if YYDEBUG
  1028.     if (yydebug)
  1029.         printf("yydebug: after reduction, shifting from state %d \
  1030. to state %d\n", *yyssp, yystate);
  1031. #endif
  1032.     if (yyssp >= yyss + yystacksize - 1)
  1033.     {
  1034.         goto yyoverflow;
  1035.     }
  1036.     *++yyssp = yystate;
  1037.     *++yyvsp = yyval;
  1038.     goto yyloop;
  1039. yyoverflow:
  1040.     yyerror("yacc stack overflow");
  1041. yyabort:
  1042.     return (1);
  1043. yyaccept:
  1044.     return (0);
  1045. }
  1046.