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