home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / gigop806.zip / LOOKUP.CPP < prev    next >
Text File  |  1994-08-04  |  2KB  |  115 lines

  1. #include <io.h>
  2. #include <fcntl.h>
  3. #include <sys\stat.h>
  4. #include <process.h>
  5. #include <stdlib.h>
  6. #include <share.h>
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include "fidoadr.h"
  11. #if !defined(word)
  12.  #ifdef __OS2__
  13.   #define word unsigned short int
  14.  #else
  15.   #define word    unsigned int
  16.   #endif
  17. #endif
  18.  
  19. #if !defined(byte)
  20. #define byte    unsigned char
  21. #endif
  22.  
  23. #define eofidx (feof(nodefile))
  24. #define gnextidx fread(&nextidx,sizeof(nextidx),1,nodefile)
  25. FILE *nodefile;
  26.  
  27. int _validaddress(word czone,word cnet,word cnode)
  28. {word zone,net;register word node;
  29.  zone=net=node=0;
  30.  word nextidx=0;
  31.  fseek(nodefile,0,SEEK_SET);
  32.  while (!eofidx)
  33.   { gnextidx;
  34.     node=nextidx;
  35.     if (node==65535)
  36.       {
  37. newzone:
  38.        gnextidx; zone=net=nextidx;node=0;
  39.        if (zone>czone) return 0; // assume that the idx is in zone order?
  40.       /*
  41.        if (zone<czone)
  42.          {
  43.           while(!eofidx)
  44.            {
  45.             gnextidx;
  46.             if (nextidx==65535) goto newzone;
  47.            }
  48.           }
  49.           */
  50.        }
  51.     if (node==65534)
  52.       {gnextidx;net=nextidx;node=0;}
  53.     if ((cnet==net) && (cnode==node) && (czone==zone)) return 1;
  54.   }
  55.  return 0;
  56. }
  57.  
  58. int validaddress(word czone,word cnet,word cnode)
  59. { int i;
  60.  nodefile=fopen("NODELIST.GIG","rb");
  61.  if (!nodefile)
  62.   {
  63.   cprintf("NODELIST.GIG not in current directory or not openable.\r\n");
  64.   exit(1);
  65.   }
  66.  setvbuf(nodefile,NULL, _IOFBF,2048);
  67.  if (!nodefile)
  68.   {
  69.    return 1;
  70.   }
  71.  i=_validaddress(czone,cnet,cnode);
  72.  fclose(nodefile);
  73.  return i;
  74. }
  75.  
  76. void testaddresses(void)
  77. {
  78.  unsigned zone,net,node;
  79.  for (zone=5;zone<=6;zone++)
  80.   for (net=100;net<300;net++)
  81.     for (node=0;node<1000;node++)
  82.      { putch('.');
  83.      if (validaddress(zone,net,node))
  84.       cprintf("\r%u:%u/%u\r\n",zone,net,node);
  85.       }
  86. }
  87.  
  88.  
  89. void main(int argc, char *argv[])
  90. {
  91.  
  92.  int i;
  93.  FIDOADR fidoadr;
  94.  if (argc == 1)
  95.  
  96.   {
  97.   cprintf("Usage: %s [fidoaddress [fidoaddress ... ]]\r\n",argv[0]);
  98.   cprintf(" where fidoaddress is in the form zone:net/node\r\n");
  99.   }
  100.  
  101.  
  102.  for (i=1;i<argc;i++)
  103.   {
  104.    fidoadr_split(argv[i],&fidoadr);
  105.    if (!fidoadr.zone) fidoadr.zone=1;
  106.    cprintf("Checking: %u:%u/%u.*  ",fidoadr.zone,fidoadr.net,fidoadr.node);
  107.    if (validaddress(fidoadr.zone,fidoadr.net,fidoadr.node))
  108.      cprintf("In index.\r\n");
  109.    else
  110.      cprintf(" does not exist.\r\n");
  111.   }
  112. }
  113.  
  114.  
  115.