home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / osrc_149.lzh / route.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-08  |  24.4 KB  |  862 lines

  1. /***************************************************************************/
  2. /***                                                                     ***/
  3. /***               oMMM - The Outbound Matrix Message Masher             ***/
  4. /***                      Copyright 1989 BS Software                     ***/
  5. /***                                                                     ***/
  6. /***                           FILENAME: ROUTE.C                         ***/
  7. /***                                                                     ***/
  8. /***                             oMMM's Router                           ***/
  9. /***                                                                     ***/
  10. /***                 Based on the original oMMM, a portion of            ***/
  11. /***               the Opus Computer-Based Conversation System           ***/
  12. /***                     Copyright 1986, Wynn Wagner III                 ***/
  13. /***                                                                     ***/
  14. /***************************************************************************/
  15. /***                                                                     ***/
  16. /***                    Tabs set at every 4th column                     ***/
  17. /***                                                                     ***/
  18. /***************************************************************************/
  19.  
  20. /*
  21.     Polytron Version Control System Comments:
  22.  
  23.     The revision of this file is *** $Revision:   1.40  $ ***
  24.  
  25.     History of changes from 1.30 release version
  26.  
  27.     $Log:   C:/OMMM/PROJFILE/ROUTE.C_V  $
  28.  * 
  29.  *    Rev 1.40   12 Feb 1989  4:56:34   Marshall Presnell
  30.  * Public Release Version 1.40
  31.  * 
  32.  *    Rev 1.31   31 Jan 1989  0:58:40   Marshall Presnell
  33.  * oMMM 1.35 Beta Release Version
  34.  * 
  35.  *    Rev 1.30   23 Jan 1989 17:54:02   Marshall Presnell
  36.  * Public Source Code Release - Version 1.30
  37.  
  38. */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Include files                                                            */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include    "ommm.h"
  45.  
  46.  
  47. /* #include    <sys\stat.h> */
  48. #include    <ctype.h>
  49. #include    <stdlib.h>
  50. #include    <string.h>
  51. /* #include    <io.h> */
  52. #include    <fcntl.h>
  53.  
  54. /*--------------------------------------------------------------------------*/
  55. /* Static function declarations                                             */
  56. /*--------------------------------------------------------------------------*/
  57.  
  58. static int    pwd(void);
  59. static void    route_poll(void);
  60. /* static */ void    route_donorm(void);
  61. static void    route_leave(void);
  62. static void    route_one(void);
  63. /* static */ void    route_arc(void); 
  64. static void    route_docrash(void);
  65. static void    route_hostroute(void);
  66. static void    route_send(void);
  67.  
  68. /*--------------------------------------------------------------------------*/
  69. /* Static variable definitions                                              */
  70. /*--------------------------------------------------------------------------*/
  71.  
  72. #define    NA    -1
  73. #define    NL    NULL
  74. #define    IL    ((int) DO_ILLEGAL)
  75.  
  76. #define    NONE    0
  77. #define    CONT    1
  78. #define    BREAK    2
  79.  
  80. static struct _router {
  81.  
  82.     char *    verb;
  83.     char    mode;
  84.     ADDRESS    dest;
  85.     char    thischar;
  86.     char *    thisext1;
  87.     char *    thisext2;
  88.     char *    thisext3;
  89.     char *    thisext4;
  90.     int        (*spc_func) ();
  91.     int        after_fn;
  92.     int        AddFlag;
  93. }    r_matrix[] = {
  94.  
  95. /*
  96.  
  97. NOTE:    This table does not contain tabs at all. This will allow all you non-
  98.         tab drinkers to read this beast without having to do severe
  99.         re-formatting.
  100.  
  101.  
  102.  V               M    Z   N   N   C    E      E      E      E      F    A    
  103.  e               o    o   e   o   h    x      x      x      x      u    f    A
  104.  r               d    n   t   d   a    t      t      t      t      n    t    d
  105.  b               e    e       e   r    1      2      3      4      c    e    d
  106.  --------------- ---- --- --- --- ---- ------ ------ ------ ------ ---- ---- -*/
  107.  
  108. #ifdef ADD_STUFF
  109.  "arcaddcm",     'C', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  110.  "arcadddirect", 'D', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  111.  "arcaddhold",   'H', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  112. #endif
  113.  "arccm",        'C', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  114.  "arcdirect",    'D', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  115.  "archold",      'H', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  116.  "docm",         'Z', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  117.  "hostroute",    'R', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  118.  "leave",        'L', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  119.  "normcm",       '2', IL, IL, IL, 'C', "OUT", "FLO", "DUT", "DLO", NL,  NA,  0,
  120.  "normdirect",   'N', IL, IL, IL, 'D', "OUT", "FLO", "",    "",    NL,  NA,  0,
  121.  "normhold",     '1', IL, IL, IL, 'H', "OUT", "FLO", "DUT", "DLO", NL,  NA,  0,
  122. #ifdef ADD_STUFF
  123.  "oneaddcm",     'c', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  124.  "oneadddirect", 'd', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  125.  "oneaddhold",   'h', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  126. #endif
  127.  "onecm",        'c', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  128.  "onedirect",    'd', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  129.  "onehold",      'h', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  130.  "password",     NA,  NA, NA, NA, NA,  NL,    NL,    NL,    NL,    pwd, CONT,0,
  131.  "poll",         'P', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  132.  "route-to",     'r', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  133.  "send",         'S', IL, IL, IL, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0,
  134.  "uncm",         '4', IL, IL, IL, 'o', "CUT", "CLO", "",    "",    NL,  NA,  0,
  135.  "undirect",     '5', IL, IL, IL, 'o', "DUT", "DLO", "",    "",    NL,  NA,  0,
  136.  "unhold",       '3', IL, IL, IL, 'o', "HUT", "HLO", "",    "",    NL,  NA,  0,
  137. #ifdef ADD_STUFF
  138.  "zooaddcm",     'C', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  139.  "zooadddirect", 'D', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  140.  "zooaddhold",   'H', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  141. #endif
  142.  "zoocm",        'C', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  143.  "zoodirect",    'D', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  144.  "zoohold",      'H', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  145. #ifdef ADD_STUFF
  146.  "z1addcm",      'c', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  147.  "z1adddirect",  'd', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  148.  "z1addhold",    'h', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  1,
  149. #endif
  150.  "z1cm",         'c', IL, IL, IL, 'C', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  151.  "z1direct",     'd', IL, IL, IL, 'D', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  152.  "z1hold",       'h', IL, IL, IL, 'H', "FLO", NL,    NL,    NL,    NL,  NA,  0,
  153.  
  154.  
  155. /*  DO NOT REMOVE THE FOLLOWING LINE! ADD TO TABLE ABOVE THIS LINE!       */
  156.  
  157.  NULL,           NA,  NA, NA, NA, NA,  NL,    NL,    NL,    NL,    NL,  NA,  0
  158.  
  159. };
  160.  
  161. #ifdef ADD_STUFF
  162.     int            AddFlag = 0;
  163. #endif
  164.  
  165. int                ArcType = 'a';
  166. static char *    sptr;
  167.  
  168. static FILE *    fp;
  169. static char        s[100];
  170. static char        parm[100];
  171. static char        towhom[80];
  172. static char        oldname[80];
  173. static char        newname[80];
  174. static char        thisext1[4];
  175. static char        thisext2[4];
  176. static char        thisext3[4];
  177. static char        thisext4[4];
  178. static char *    p;
  179. static char *    q;
  180. static char        q1;
  181. static int        oth;
  182. static int        line = 0;
  183. static int        cur_sched = 0;
  184. static char        thischar;
  185. static int        ctr;
  186. static int        err;
  187. static int        CONTINUE = 0;
  188. static int        not_in_table;
  189.  
  190. /*--------------------------------------------------------------------------*/
  191. /* LOCAL VARIABLES                                                          */
  192. /*--------------------------------------------------------------------------*/
  193.  
  194. PW_PTR            pw[100];        /* See MISC.C for reference         */
  195. int                num_pw = 0;        /* See MISC.C for reference         */
  196.  
  197. /*--------------------------------------------------------------------------*/
  198. /* External variable declarations                                           */
  199. /*--------------------------------------------------------------------------*/
  200.  
  201. extern ADDRESS    ctlnet[];
  202.  
  203. /****************************************************************************/
  204.  
  205. /*--------------------------------------------------------------------------*/
  206. /* PWD                                                     LOCAL FUNCTION   */
  207. /*--------------------------------------------------------------------------*/
  208.  
  209.  static int
  210. pwd(void)
  211. {
  212.     pw[num_pw] = (PW_PTR) calloc(1, sizeof(PW));
  213.     if (sscanf(sptr, "%d:%d/%d %s", pw[num_pw]->zone, pw[num_pw]->net, pw[num_pw]->node, oldname) != 4) {
  214.         sscanf(sptr, "%d/%d %s", pw[num_pw]->net, pw[num_pw]->node, oldname);
  215.         pw[num_pw]->zone = our_zone;
  216.     }
  217.     strupr(oldname);
  218.     pw[num_pw]->password = (char *) malloc(strlen(oldname) + 1);
  219.     strcpy(pw[num_pw++]->password, oldname);
  220.     return (0);
  221. }
  222.  
  223. /*--------------------------------------------------------------------------*/
  224. /* ROUTE POLL                                              LOCAL FUNCTION   */
  225. /*--------------------------------------------------------------------------*/
  226.  
  227.  static void
  228. route_poll()
  229. {
  230.     do {
  231.         cur.node = DO_ILLEGAL;
  232.         sptr = pull_address(sptr);
  233.         if ((cur.net == DO_ALL) || (cur.node == DO_ALL) || (cur.net == DO_OTHERS) || (cur.node == DO_OTHERS)) {
  234.             printf("ERR: can't use `ALL' or `OTHERS' in POLL , line %d\n", line);
  235.             fflush(stdout);
  236.             sptr = pull_address(sptr);
  237.             continue;
  238.         }
  239.         if (cur.node == DO_ILLEGAL) {
  240.             continue;
  241.         }
  242.  
  243.         printf("\rPOLL    ");
  244.         fflush(stdout);
  245.         if (cur.node == DO_OURNET) {
  246.             sprintf(towhom, "%s%04x*.?LO", holding_path, OURNET);
  247.             cur.net = OURNET;
  248.         } else {
  249.             sprintf(towhom, "%s%04x%04x.?LO", adjust_packet_path(cur.zone), cur.net, cur.node);
  250.         }
  251.         q1 = 'O';
  252.         if (dir_findfirst(towhom, NORMAL, &dta) == 0) {
  253.             do {
  254.                 if (dta.name[9] != 'H') {
  255.                     q1 = 0;
  256.                     break;
  257.                 }
  258.             } while (dir_findnext(&dta) == 0);
  259.         }
  260.         if (q1) {
  261.             towhom[strlen(towhom) - 3] = 'F';
  262.             outfile = fopen(towhom, "ab");
  263.             fclose(outfile);
  264.             outfile = NULL;
  265.         }
  266.         printf("%d:%d/%d", cur.zone,cur.net, cur.node);
  267.         fflush(stdout);
  268.  
  269.     } while (*sptr);
  270. }
  271.  
  272. /*--------------------------------------------------------------------------*/
  273. /* ROUTE HOSTROUTE                                         LOCAL FUNCTION   */
  274. /*--------------------------------------------------------------------------*/
  275.  
  276.  static void
  277. route_hostroute()
  278. {
  279.     ctr = 0;
  280.  
  281. hostloop:
  282.  
  283.     /* Get a .OUT file name */
  284.     sprintf(towhom, "%s*.OUT", holding_path);
  285.     for (i = 0; i <= ctr; i++) {
  286.         if (!i) {
  287.             err = dir_findfirst(towhom, NORMAL, &dta);
  288.         } else {
  289.             err = dir_findnext(&dta);
  290.         }
  291.     }
  292.  
  293.     if (!err) {
  294.         do {
  295.             /* Get the net/node number out */
  296.             sscanf(dta.name, "%04x%04x", &cur.net, &cur.node);
  297.  
  298.             /* If it is to node 0, then skip it */
  299.             /* If it has a .FLO then loop again */
  300.             sprintf(towhom, "%s%04x%04x.FLO", holding_path, cur.net, cur.node);
  301.             if ((!dir_findfirst(towhom, NORMAL, &dta)) || (cur.node == 0) || (cur.net < 100)) {
  302.                 ++ctr;
  303.                 goto hostloop;
  304.             }
  305.  
  306.             for (i = 0; i < ALIAS_CNT; i++) {
  307.                 if (ctlnet[i].net <= 0)
  308.                     break;
  309.                 if (ctlnet[i].net == cur.net) {
  310.                     ++ctr;
  311.                     goto hostloop;
  312.                 }
  313.             }
  314.  
  315.             /* Add it to the x/0 packet */
  316.             sprintf(oldname, "%s%04x%04x.OUT", holding_path, cur.net, cur.node);
  317.             sprintf(newname, "%s%04x0000.OUT", holding_path, cur.net);
  318.             open_outfile('O', cur.net, 0, 0, 0);
  319.             fwrite("\0\0", 1,2,outfile);
  320.             fclose(outfile);
  321.             outfile = NULL;
  322.             append_out(oldname, newname);
  323.  
  324.             /* Loop again */
  325.             sprintf(towhom, "%s*.OUT", holding_path);
  326.             for (i = 0; i <= ctr; i++) {
  327.                 if (!i) {
  328.                     err = dir_findfirst(towhom, NORMAL, &dta);
  329.                 } else {
  330.                     err = dir_findnext(&dta);
  331.                 }
  332.             }
  333.         } while (!err);
  334.     }
  335. }
  336.  
  337. /*--------------------------------------------------------------------------*/
  338. /* ROUTE SEND                                              LOCAL FUNCTION   */
  339. /*--------------------------------------------------------------------------*/
  340.  
  341.  static void
  342. route_send()
  343. {
  344.     int        status;
  345.     char *    dfe;
  346.     char    sfn[80];
  347.     char    dfn[80];
  348.  
  349.     do {
  350.         sptr = pull_address(sptr);
  351.  
  352.         if (cur.net == DO_ILLEGAL) {
  353.             continue;
  354.         }
  355.  
  356.         if (cur.net == DO_OURNET) {
  357.             sprintf(towhom, "%s%04x*.N*",adjust_packet_path(cur.zone),OURNET);
  358.         } else if (cur.net == DO_ALL) {
  359.             sprintf(towhom, "%s*.N*",adjust_packet_path(cur.zone));
  360.         } else if (cur.net == DO_OTHERS) {
  361.             sprintf(towhom, "%s*.N*",adjust_packet_path(cur.zone));
  362.             oth = 1;
  363.         } else if (cur.node == DO_ALL) {
  364.             sprintf(towhom, "%s%04x*.N*",adjust_packet_path(cur.zone),cur.net);
  365.         } else {
  366.             sprintf(towhom, "%s%04x%04x.N*",adjust_packet_path(cur.zone), cur.net, cur.node);
  367.         }
  368.  
  369.         status = dir_findfirst(towhom,0,&dta);
  370.  
  371.         if (status == 0) do {
  372.             if (sscanf(dta.name, "%04x%04x", &cur.net,&cur.node) != 2)
  373.                 continue;
  374.  
  375.             if (oth && (cur.net == OURNET))
  376.                 continue;
  377.  
  378.             sprintf(sfn,"%s%s",adjust_packet_path(cur.zone),dta.name);
  379.             strcpy(dfn,sfn);
  380.  
  381.             if ((dfe = strrchr(dfn,'.')) != NULL)
  382.                 dfe++;
  383.  
  384.             if (*dfe != 'N')
  385.                 continue;
  386.  
  387.             if (*(dfe + 2) == 'T') {
  388.                 *dfe = *(dfe + 1);
  389.                 *(dfe + 1) = 'U';
  390.             }
  391.  
  392.             if (*(dfe + 2) == 'O') {
  393.                 *dfe = *(dfe + 1);
  394.                 *(dfe + 1) = 'L';
  395.             }
  396.  
  397.             if (*(dfe + 1) == 'Q') {
  398.                 *dfe = *(dfe + 1);
  399.                 *(dfe + 1) = 'E';
  400.             }
  401.  
  402.             printf("SEND %d:%d/%d\n",cur.zone,cur.net,cur.node);
  403.             fflush(stdout);
  404.  
  405.             if (rename(sfn,dfn))
  406.                 perror("can't rename");
  407.  
  408.         } while((status = dir_findnext(&dta)) == 0);
  409.  
  410.     } while (*sptr);
  411. }
  412.  
  413. /*--------------------------------------------------------------------------*/
  414. /* ROUTE DONORM                                            LOCAL FUNCTION   */
  415. /*--------------------------------------------------------------------------*/
  416.  
  417.  /* static */ void
  418. route_donorm()
  419. {
  420.     do {
  421.         sptr = pull_address(sptr);
  422.  
  423.         if (cur.net == DO_ILLEGAL) {
  424.             continue;
  425.         }
  426.  
  427.         if (cur.net == DO_OURNET) {
  428.             sprintf(towhom, "%04x*.%s", OURNET, thisext1);
  429.         } else if (cur.net == DO_ALL) {
  430.             sprintf(towhom, "*.%s", thisext1);
  431.         } else if (cur.net == DO_OTHERS) {
  432.             sprintf(towhom, "*.%s", thisext1);
  433.         } else if (cur.node == DO_ALL) {
  434.             sprintf(towhom, "%04x*.%s", cur.net, thisext1);
  435.         } else {
  436.             sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext1);
  437.         }
  438.  
  439.         if(*thisext1) make_normal(cur.zone, towhom, thischar, 0);
  440.  
  441.         if (cur.net == DO_OURNET) {
  442.             sprintf(towhom, "%04x*.%s", OURNET, thisext2);
  443.         } else if (cur.net == DO_ALL) {
  444.             sprintf(towhom, "*.%s", thisext2);
  445.         } else if (cur.net == DO_OTHERS) {
  446.             sprintf(towhom, "*.%s", thisext2);
  447.         } else if (cur.node == DO_ALL) {
  448.             sprintf(towhom, "%04x*.%s", cur.net, thisext2);
  449.         } else {
  450.             sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext2);
  451.         }
  452.  
  453.         if(*thisext2) make_normal(cur.zone, towhom, thischar, 0);
  454.  
  455.         if (cur.net == DO_OURNET) {
  456.             sprintf(towhom, "%04x*.%s", OURNET, thisext3);
  457.         } else if (cur.net == DO_ALL) {
  458.             sprintf(towhom, "*.%s", thisext3);
  459.         } else if (cur.net == DO_OTHERS) {
  460.             sprintf(towhom, "*.%s", thisext3);
  461.         } else if (cur.node == DO_ALL) {
  462.             sprintf(towhom, "%04x*.%s", cur.net, thisext3);
  463.         } else {
  464.             sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext3);
  465.         }
  466.  
  467.         if(*thisext3) make_normal(cur.zone, towhom, thischar, 0);
  468.  
  469.         if (cur.net == DO_OURNET) {
  470.             sprintf(towhom, "%04x*.%s", OURNET, thisext4);
  471.         } else if (cur.net == DO_ALL) {
  472.             sprintf(towhom, "*.%s", thisext4);
  473.         } else if (cur.net == DO_OTHERS) {
  474.             sprintf(towhom, "*.%s", thisext4);
  475.         } else if (cur.node == DO_ALL) {
  476.             sprintf(towhom, "%04x*.%s", cur.net, thisext4);
  477.         } else {
  478.             sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext4);
  479.         }
  480.  
  481.         if(*thisext4) make_normal(cur.zone, towhom, thischar, 0);
  482.  
  483.     } while (*sptr);
  484. }
  485.  
  486. /*--------------------------------------------------------------------------*/
  487. /* ROUTE LEAVE                                             LOCAL FUNCTION   */
  488. /*--------------------------------------------------------------------------*/
  489.  
  490.  static void
  491. route_leave()
  492. {
  493.     int        status;
  494.     char *    sfe;
  495.     char *    dfe;
  496.     char    sfn[80];
  497.     char    dfn[80];
  498.  
  499.     do {
  500.         oth = 0;
  501.         sptr = pull_address(sptr);
  502.  
  503.         if (cur.net == DO_ILLEGAL) {
  504.             continue;
  505.         }
  506.  
  507.         if (cur.net == DO_OURNET) {
  508.             sprintf(towhom, "%s%04x*.*", adjust_packet_path(cur.zone), OURNET);
  509.             cur.net = OURNET;
  510.         } else if (cur.net == DO_ALL) {
  511.             sprintf(towhom, "%s*.*", adjust_packet_path(cur.zone));
  512.         } else if (cur.net == DO_OTHERS) {
  513.             sprintf(towhom, "%s*.*", adjust_packet_path(cur.zone));
  514.             oth = 1;
  515.         } else if (cur.node == DO_ALL) {
  516.             sprintf(towhom, "%s%04x*.*", adjust_packet_path(cur.zone), cur.net);
  517.         } else {
  518.             sprintf(towhom, "%s%04x%04x.*", adjust_packet_path(cur.zone), cur.net, cur.node);
  519.         }
  520.  
  521.         status = dir_findfirst(towhom,0,&dta);
  522.  
  523.         if (status == 0) do {
  524.             if (sscanf(dta.name, "%04x%04x", &cur.net,&cur.node) != 2)
  525.                 continue;
  526.  
  527.             if (oth && (cur.net == OURNET))
  528.                 continue;
  529.  
  530.             sprintf(sfn,"%s%s",adjust_packet_path(cur.zone),dta.name);
  531.             strcpy(dfn,sfn);
  532.  
  533.             if ((sfe = strrchr(dfn,'.')) != NULL)
  534.                 sfe++;
  535.  
  536.             if (*(sfe + 1) == 'R')
  537.                 continue;
  538.  
  539.             if ((dfe = strpbrk(sfe,"ODCHRF")) != NULL) {
  540.                 *(dfe + 1) = *sfe;
  541.                 *dfe = 'N';
  542.             }
  543.  
  544.             printf("LEAVE %d:%d/%d\n",cur.zone,cur.net,cur.node);
  545.             fflush(stdout);
  546.  
  547.             if (rename(sfn,dfn))
  548.                 perror("can't rename");
  549.  
  550.         } while ((status = dir_findnext(&dta)) == 0);
  551.     } while (*sptr);
  552. }
  553.  
  554. /*--------------------------------------------------------------------------*/
  555. /* ROUTE ONE                                               LOCAL FUNCTION   */
  556. /*--------------------------------------------------------------------------*/
  557.  
  558.  static void
  559. route_one()
  560. {
  561.     do {
  562.         oth = 0;
  563.         sptr = pull_address(sptr);
  564.  
  565.         if (cur.net == DO_ILLEGAL) {
  566.             continue;
  567.         }
  568.  
  569.         if (cur.net == DO_OURNET) {
  570.             sprintf(towhom, "%04x*.%s", OURNET, thisext1);
  571.         } else if (cur.net == DO_ALL) {
  572.             sprintf(towhom, "*.%s", thisext1);
  573.         } else if (cur.net == DO_OTHERS) {
  574.             sprintf(towhom, "*.%s", thisext1);
  575.         } else if (cur.node == DO_ALL) {
  576.             sprintf(towhom, "%04x*.%s", cur.net, thisext1);
  577.         } else {
  578.             sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext1);
  579.         }
  580.  
  581.         make_normal(cur.zone, towhom, thischar, 0);
  582.         if (cur.net == DO_OURNET) {
  583.             sprintf(towhom, "%s%04x*.OUT", holding_path, OURNET);
  584.             cur.net = OURNET;
  585.         } else if (cur.net == DO_ALL) {
  586.             sprintf(towhom, "%s*.OUT", holding_path);
  587.         } else if (cur.net == DO_OTHERS) {
  588.             sprintf(towhom, "%s*.OUT", holding_path);
  589.             oth = 1;
  590.         } else if (cur.node == DO_ALL) {
  591.             sprintf(towhom, "%s%04x*.OUT", holding_path, cur.net);
  592.         } else {
  593.             sprintf(towhom, "%s%04x%04x.OUT", adjust_packet_path(cur.zone), cur.net, cur.node);
  594.         }
  595.  
  596. loop2:
  597.  
  598.         if (!dir_findfirst(towhom, NORMAL, &dta))
  599.             do {
  600.                 if (((q1 = dta.name[strlen(dta.name) - 3]) != 'H') && (strchr("NMPR", q1) == NULL)) {
  601.                     sscanf(dta.name, "%04x%04x", &cur.net, &cur.node);
  602.                     if (oth && (cur.net == OURNET)) {
  603.                         continue;
  604.                     }
  605.                     dest.zone = cur.zone;
  606.                     dest.net = cur.net;
  607.                     dest.node = cur.node;
  608.  
  609.                     printf("\rONE     %d:%d/%d", cur.zone,cur.net, cur.node, p);
  610.                     fflush(stdout);
  611.                     parm[0] = 0;
  612.                     add_parm(parm);
  613.                     archive(parm);
  614.  
  615.                     goto loop2;
  616.                 }
  617.             } while (!dir_findnext(&dta));
  618.     } while (*sptr);
  619. }
  620.  
  621. /*--------------------------------------------------------------------------*/
  622. /* ROUTE ARC                                               LOCAL FUNCTION   */
  623. /*--------------------------------------------------------------------------*/
  624.  
  625. /* static */ void
  626. route_arc()
  627. {
  628.     sptr = pull_address(sptr);
  629.     dest.zone = cur.zone;
  630.     if (dest.net == DO_ILLEGAL) {
  631.         if ((cur.net == DO_ALL) || (cur.node == DO_ALL) || (cur.net == DO_OTHERS) || (cur.node == DO_OTHERS)) {
  632.             printf("ERR: can't use `ALL' or `OTHERS' in ARC statement , line %d\n", line);
  633.             fflush(stdout);
  634.             return;
  635.         }
  636.     }
  637.     if (dest.net == DO_ILLEGAL) {
  638.         if (cur.net == DO_ILLEGAL) {
  639.             return;
  640.         } else
  641.             dest = cur;
  642.     }
  643.     if (cur.net == DO_OURNET) {
  644.         sprintf(towhom, "%04x*.%s", OURNET, thisext1);
  645.     } else if (cur.net == DO_ALL) {
  646.         sprintf(towhom, "*.%s", thisext1);
  647.     } else if (cur.net == DO_OTHERS) {
  648.         sprintf(towhom, "*.%s", thisext1);
  649.     } else if (cur.node == DO_ALL) {
  650.         sprintf(towhom, "%04x*.%s", cur.net, thisext1);
  651.     } else {
  652.         sprintf(towhom, "%04x%04x.%s", cur.net, cur.node, thisext1);
  653.     }
  654.     make_normal(cur.zone, towhom, thischar, 0);
  655.  
  656.     sprintf(towhom, "%s%04x%04x", adjust_packet_path(cur.zone), cur.net, cur.node);
  657.  
  658.     memset(parm,0,sizeof parm);
  659.  
  660.     add_parm(parm);
  661.  
  662.     while (*sptr) {
  663.         sptr = pull_address(sptr);
  664.         add_parm(parm);
  665.     }
  666.  
  667.     for (i = 0; parm[i]; i++) {
  668.         if (parm[i] == ' ') {
  669.             archive(parm);
  670.             memset(parm,0,sizeof parm);
  671.             break;
  672.         }
  673.     }
  674. }
  675.  
  676. /*--------------------------------------------------------------------------*/
  677. /* ROUTE DOCRASH                                           LOCAL FUNCTION   */
  678. /*--------------------------------------------------------------------------*/
  679.  
  680.  static void
  681. route_docrash()
  682. {
  683.     sprintf(towhom, "*.NC?");
  684.     make_normal(our_zone, towhom, 'O', 0);
  685. }
  686.  
  687. /*--------------------------------------------------------------------------*/
  688. /* DO ROUTING                                                               */
  689. /*--------------------------------------------------------------------------*/
  690.  
  691.  void
  692. do_routing(char *route_name, int sched2)
  693. {
  694.     if (!route_name[0]) {
  695.         printf("\nNo routefile given\n");
  696.         fflush(stdout);
  697.         return;
  698.     }
  699.     mode = 0;
  700.     errno = 0;
  701.     fp = fopen(route_name, "rt");
  702.     if (errno) {
  703.         printf("\nCan't open route file (%s)\n", route_name);
  704.         fflush(stdout);
  705.         return;
  706.     }
  707.     do {
  708.         s[0] = 0;
  709.         line++;
  710. #        ifdef ADD_STUFF
  711.             AddFlag = 0;
  712. #        endif
  713.         ArcType = 'a';
  714.  
  715.         cur.zone = our_zone;
  716.         cur.net = ctlnet[0].net;
  717.         cur.node = ctlnet[0].node; /* a bug ? */
  718.  /*         cur.node = ctlnet[1].node; */
  719.  
  720.         fgets(s, 90, fp);
  721.         strlwr(s);
  722.         sptr = stpblk(s);
  723.         for (i = 0; sptr[i]; i++) {
  724.             if (!isspace(sptr[i]) && ((sptr[i] == ';') || (sptr[i] < ' ')))
  725.                 sptr[i] = 0;
  726.         }
  727.  
  728.         if (!sptr[0]) {
  729.             continue;
  730.         }
  731.  
  732.         /* We have a schedule statement */
  733.  
  734.         if (!strncmp(sptr, "sched", 5)) {
  735.             sptr += 5;
  736.             while ((*sptr) && (!isspace(*sptr)))
  737.                 ++sptr;
  738.             while ((*sptr) && isspace(*sptr))
  739.                 ++sptr;
  740.             cur_sched = toupper(*sptr);
  741.             if (cur_sched == sched2)
  742.                 cur_sched = 0;
  743.             continue;
  744.         }
  745.  
  746.         /* If we are in the wrong schedule, just continue */
  747.  
  748.         if (cur_sched) {
  749.             continue;
  750.         }
  751.  
  752.         i = 0;
  753.         CONTINUE = 0;
  754.         not_in_table = 1;
  755.         while (r_matrix[i].verb != NULL) {
  756.             if (!strncmp(sptr, r_matrix[i].verb, strlen(r_matrix[i].verb))) {
  757.                 not_in_table = 0;
  758.                 sptr += strlen(r_matrix[i].verb);
  759.                 AddFlag = r_matrix[i].AddFlag;
  760.                 ArcType = r_matrix[i].verb[0];
  761.                 if (r_matrix[i].mode != (char) NA) {
  762.                     mode = r_matrix[i].mode;
  763.                 }
  764.                 if (r_matrix[i].dest.zone != NA) {
  765.                     dest.zone = r_matrix[i].dest.zone;
  766.                 }
  767.                 if (r_matrix[i].dest.net != NA) {
  768.                     dest.net = r_matrix[i].dest.net;
  769.                 }
  770.                 if (r_matrix[i].dest.node != NA) {
  771.                     dest.node = r_matrix[i].dest.node;
  772.                 }
  773.                 if (r_matrix[i].thischar != (char) NA) {
  774.                     thischar = r_matrix[i].thischar;
  775.                 }
  776.                 if (r_matrix[i].thisext1 != NL) {
  777.                     strcpy(thisext1, r_matrix[i].thisext1);
  778.                 }
  779.                 if (r_matrix[i].thisext2 != NL) {
  780.                     strcpy(thisext2, r_matrix[i].thisext2);
  781.                 }
  782.                 if (r_matrix[i].thisext3 != NL) {
  783.                     strcpy(thisext3, r_matrix[i].thisext3);
  784.                 }
  785.                 if (r_matrix[i].thisext4 != NL) {
  786.                     strcpy(thisext4, r_matrix[i].thisext4);
  787.                 }
  788.                 if (r_matrix[i].spc_func != NL) {
  789.                     (*r_matrix[i].spc_func) ();    /* This causes a warning    */
  790.                                                 /* It's safe to ignore it    */
  791.                     CONTINUE = 1;
  792.                 }
  793.             }
  794.             i++;
  795.         }
  796.         if (not_in_table) {
  797.             if (!isdigit(*sptr)) {
  798.                 mode = 0;
  799.             }
  800.         }
  801.  
  802.         if (CONTINUE)
  803.             continue;
  804.  
  805.         switch (mode) {
  806.             case 0:
  807.                 printf("\nCan't figure out line #%d\n", line);
  808.                 fflush(stdout);
  809.                 break;
  810.  
  811.             case 'P':                /* POLL, just send a dummy packet        */
  812.                 route_poll();
  813.                 break;
  814.  
  815.             case 'R':                /* ROUTE, do host routing                */
  816.                 route_hostroute();
  817.                 break;
  818.  
  819.             case 'Z':                /* DOCRASH, normalize crash nodes        */
  820.                 route_docrash();
  821.                 break;
  822.  
  823.             case 'S':                /* SEND, normalize the listed nodes        */
  824.                 route_send();
  825.                 break;
  826.  
  827.             case '1':                /* NORMHOLD/CRASH just make it held        */
  828.             case '2':
  829.             case '3':
  830.             case '4':
  831.             case '5':
  832.             case 'N':
  833.                 route_donorm();
  834.                 break;
  835.  
  836.             case 'L':                /* LEAVE, rename the packets            */
  837.                 route_leave();
  838.                 break;
  839.  
  840.             case 'c':                /* ONE*, do archiving                    */
  841.             case 'h':
  842.             case 'd':
  843.                 route_one();
  844.                 break;
  845.  
  846.             case 'D':                /* ARC*, do archiving                    */
  847.             case 'H':
  848.             case 'C':
  849.             default:
  850.                 route_arc();
  851.                 break;
  852.         }
  853.     } while (!feof(fp));
  854.     fclose(fp);
  855.     fp = NULL;
  856. }
  857.  
  858. /*--------------------------------------------------------------------------*/
  859. /*                                END OF FILE                               */
  860. /*--------------------------------------------------------------------------*/
  861. /* ID: 808.28@24950  Last Changed: 08 Apr 1990 15:59:29 by max */
  862.