/* **** HBBS Door Code****************************************************** */

/*
  DoorName
  ========

    Zippy Search by Ben Clifton (Teppic)

  Version
  =======

    0.01, release  0, 24/12/1995

  Options
  =======

    N_ND->ActiveDoor->SystemOptions
    -------------------------------



    Command Line Arguments
    ----------------------

  ToDo
  ====




*/

/* **** Includes *********************************************************** */

#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>

#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/Access.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>
#include <HBBS/hbbscommon_pragmas.h>
#include <HBBS/Hbbsnode_protos.h>
#include <HBBS/Hbbsnode_pragmas.h>

/* **** Definitions ******************************************************** */

#define BENS_HEADER "+------------------------------------------------------+\r\n|            Zippy Search V1 by Ben Clifton            |\r\n|           (C) 1995 Ruby Knight Productions           |\r\n+------------------------------------------------------+\r\n"

/* **** Variables ********************************************************** */


struct Library *HBBSCommonBase  = NULL;
struct Library *HBBSNodeBase    = NULL;

struct BBSGlobalData *BBSGlobal = NULL;
struct NodeData *N_ND           = NULL;
int    N_NodeNum                = -1;

long __stack=16*1024; // increse this in 4k incrments if you suffer from
                      // random/suprious crashings after or during the running
                      // of your door.

int    gargc;         // these are just copies of main()'s argc and argv..
char   **gargv;

ULONG CurrentFileNumber = 0;
ULONG LinesOutput = 0;

BOOL NonStop = FALSE, Lopt = FALSE;

struct List *FileNames;

char tmpstr[BIG_STR];

/* **** Functions ********************************************************** */


#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif

static VOID cleanup(ULONG num)
{
  if (HBBSNodeBase)
  {
    HBBS_CleanUpDoor();
    CloseLibrary (HBBSNodeBase);
  }

  if (HBBSCommonBase)
  {
    HBBS_CleanUpCommon();
    CloseLibrary (HBBSCommonBase);
  }

  if (num) printf("Door Error = %d\n",num);

  exit(0);
}

static VOID init(char *name)
{
  if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  {
    cleanup(1);
  }

  if (!(HBBS_InitCommon()))
  {
    cleanup(2);
  }

  if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  {
    cleanup(3);
  }

  if (!(HBBS_InitDoor(N_NodeNum,name)))
  {
    cleanup(4);
  }
  SetProgramName(name);
}

void FM_strFNcpy( char *in, char *out, int start, int num )
{
  int loop, i;

  for( i=0, loop = start; (loop < num+start) && (in[loop]); loop++, i++ ) out[i] = in[loop];
  out[i]=0;
}

void FM_RemoveCR( char *s )
{
  if( s[0] )
  {
    if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
      s[strlen(s)-1] = 0;
    if( (s[strlen(s)-1] == '\n')|| (s[strlen(s)-1] == '\r' ) )
      s[strlen(s)-1] = 0;
  }
}

void strpad(char *buffer, int requiredlen, UBYTE PadChar)
{
  int many;
  int loop;
  int clen=strlen(buffer);

  if (clen<requiredlen)
  {
    many=requiredlen-clen;
    for (loop=0;loop<=many;loop++) buffer[clen+loop]=PadChar;
    buffer[requiredlen]=0;
  }
}

/*
BOOL ScreenPausePrompt( BOOL ReachedEOF )
{
  BOOL retval=FALSE;
  V_BOOL Help;
  int n;
  struct Node *node;
  char filename[BIG_STR], rp[BIG_STR], *filenames;
  int where, i;

  if ((!NonStop) || (NonStop && ReachedEOF))
  {
    do
    {
      Help=FALSE;
      if( ReachedEOF )
      {
        strcpy(N_ND->CharsAllowed,"YyFfRr?NnQq");
        DOOR_WriteText(ANSI_RESET "End-Of-File "ANSI_FG_YELLOW"["ANSI_FG_WHITE"Q/F/R/?"ANSI_FG_YELLOW"]"ANSI_FG_WHITE " : ");
      }
      else
      {
        strcpy(N_ND->CharsAllowed,"YyNnCcAaLlFfRr?Qq");
        DOOR_WriteText(ANSI_RESET "More "ANSI_FG_YELLOW"["ANSI_FG_WHITE"Y/N/Q/C/A/L/F/R/?"ANSI_FG_YELLOW"]"ANSI_FG_WHITE " : ");
      }
      DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS|GL_IMMEDIATE|GL_NORETURN,'\0',1,0,NULL);
      if (N_ND->OnlineStatus==OS_ONLINE)
      {
        DOOR_WriteText("\r[K"); // erase line
        if (stricmp("F",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_CYAN "Enter Filenames To Tag > "ANSI_FG_WHITE);
          DOOR_GetLine(GL_EDIT|GL_DISPLAY,'\0',0,0,NULL);
          if (N_ND->OnlineStatus==OS_ONLINE)
          {
            RemoveSpaces(N_ND->CurrentLine);
            if (N_ND->CurrentLine[0])
            {
              strcpy(tmpstr,N_ND->CurrentLine);
              DOOR_UserDoor("A",tmpstr);
              Help=TRUE;
            }
          }
        }
        else
        if (stricmp("R",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_CYAN"Enter FileNumber To Tag > "ANSI_FG_WHITE);
          DOOR_GetLine(GL_EDIT|GL_DISPLAY,'\0',0,0,NULL);
          if (N_ND->OnlineStatus==OS_ONLINE)
          {
            RemoveSpaces(N_ND->CurrentLine);
            if (N_ND->CurrentLine[0])
            {
              tmpstr[0]=0;
              for( i=0; i<strlen( N_ND->CurrentLine ); i++ )
              {
                if( N_ND->CurrentLine[i] == ',' )
                {
                  rp[i] = ' ';
                }
                else
                {
                  rp[i] = N_ND->CurrentLine[i];
                }
              }
              rp[i] = 0;

              filenames = rp;

              while (filenames[0]) // any chars left ?
              {
                while ((filenames[0]==' ') && (filenames[0])) filenames++; //skip spaces..

                if (filenames[0])
                {
                  if (((where=position(" ",filenames))>=0) )
                  {
                    strNcpy(filename,filenames,where);
                    filenames+=where;
                  }
                  else
                  {
                    strcpy(filename,filenames);
                    filenames+=strlen(filename);
                  }
                  n = atol( filename );
                  if (n>0 && n<=CurrentFileNumber)
                  {
                    node = GetNode( FileNames, n-1 );
                    sprintf( tmpstr+strlen(tmpstr), "%s ", node->ln_Name );
                  }
                }
              }
              if (tmpstr[0]) DOOR_UserDoor("A",tmpstr);
              Help=TRUE;
            }
          }
        }
        else
        if (stricmp("C",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_CLS);
        }
        else
        if ((stricmp("N",N_ND->CurrentLine)==0) || (stricmp("Q",N_ND->CurrentLine)==0))
        {
          retval=TRUE;
        }
        else
        if (stricmp("A",N_ND->CurrentLine)==0)
        {
          NonStop=TRUE;
        }
        else
        if (stricmp("L",N_ND->CurrentLine)==0)
        {
          NonStop=TRUE;
          Lopt=TRUE;
        }
        if (stricmp("?",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_CYAN
                         "?  -  This Help Page.\r\n"
                         "C  -  Clear Screen And Continue.\r\n"
                         "N/Q-  No More Please (QUIT).\r\n"
                         "Y  -  Display next screen of files\r\n"
                         "A  -  Display All of remaining files (same as /X's NS).\r\n"
                         "A  -  As A but does CLS after each screenfull\r\n"
                         "F  -  Flag File By NAME.\r\n"
                         "R  -  Flag File By NUMBER.\r\n");
          Help=TRUE;
        }
      }
    }
    while ((N_ND->OnlineStatus==OS_ONLINE) && (Help));
  }
  LinesOutput=0;

  if ( Lopt ) DOOR_WriteText( ANSI_CLS );

  return(retval);
}
*/


BOOL ScreenPausePrompt( BOOL ReachedEOF )
{
  BOOL retval=FALSE;
  V_BOOL Help;

  if ((!NonStop) || (NonStop && ReachedEOF))
  {
    do
    {
      Help=FALSE;

      if (ReachedEOF)
      {
        strcpy(N_ND->CharsAllowed,"YyNnQqFfRr? ");
        DOOR_WriteText(ANSI_RESET "End-Of-File "ANSI_FG_YELLOW"["ANSI_FG_WHITE"Y/N/F/R/?"ANSI_FG_YELLOW"]"ANSI_FG_WHITE " : ");
      }
      else
      {
        strcpy(N_ND->CharsAllowed,"LlYyNnCcAaFfRr?Qq ");
        DOOR_WriteText(ANSI_RESET "More "ANSI_FG_YELLOW"["ANSI_FG_WHITE"Y/N/C/A/F/R/?"ANSI_FG_YELLOW"]"ANSI_FG_WHITE " : ");
      }


      DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS|GL_IMMEDIATE|GL_NORETURN,'\0',1,0,NULL);
      if (N_ND->OnlineStatus==OS_ONLINE)
      {
        DOOR_WriteText("\r[K"); // erase line
        if (stricmp("F",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_CYAN "Enter Filenames To Tag > "ANSI_FG_WHITE);
          DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_HISTORY|GL_NORETURN,'\0',0,0,NULL);
          if (N_ND->OnlineStatus==OS_ONLINE)
          {
            DOOR_WriteText("\r[K"); // erase line
            RemoveSpaces(N_ND->CurrentLine);
            if (N_ND->CurrentLine[0])
            {
              strcpy(tmpstr,N_ND->CurrentLine);
              DOOR_UserDoor("A",tmpstr);
              Help=TRUE;
            }
          }
        }
        else
        if (stricmp("R",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_CYAN"Enter FileNumbers To Tag > "ANSI_FG_WHITE);
          DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_HISTORY|GL_NORETURN,'\0',0,0,NULL);
          RemoveSpaces(N_ND->CurrentLine);
          if (N_ND->CurrentLine[0])
          {
            // this (horrible) code is nicked from ben's Zippy program
            // hence the horrible varialbe names and huge amount of them..

            LONG i,where;
            UBYTE filename[BIG_STR],rp[BIG_STR],*filenames;


            DOOR_WriteText("\r[K"); // erase line

            tmpstr[0]=0;

            for( i=0; i<strlen( N_ND->CurrentLine ); i++ )
            {
              if( N_ND->CurrentLine[i] == ',' )
              {
                rp[i] = ' ';
              }
              else
              {
                rp[i] = N_ND->CurrentLine[i];
              }
            }
            rp[i] = 0;


            filenames = rp;

            // but this bit is mine...

            while (filenames[0]) // any chars left ?
            {
              while ((filenames[0]==' ') && (filenames[0])) filenames++; //skip spaces..

              if (filenames[0])
              {
                if (((where=position(" ",filenames))>=0) )
                {
                  strNcpy(filename,filenames,where);
                  filenames+=where;
                }
                else
                {
                  strcpy(filename,filenames);
                  filenames+=strlen(filename);
                }

                // and this isn't mine..

                i = atol( filename );
                if (i>0 && i<=CurrentFileNumber)
                {
                  sprintf( tmpstr+strlen(tmpstr), "%s ", HBBS_ListName(FileNames, i-1) );
                }

              }
            }
            // but this is..
            if (tmpstr[0]) DOOR_UserDoor("A",tmpstr);
            Help=TRUE;
          }
        }
        else
        if (stricmp("C",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_CLS);
        }
        else
        if (stricmp("L",N_ND->CurrentLine)==0)
        {
          NonStop=TRUE;
          Lopt=TRUE;
        }
        else
        if ((stricmp("N",N_ND->CurrentLine)==0) || (stricmp("Q",N_ND->CurrentLine)==0))
        {
          retval=TRUE;
        }
        else
        if (stricmp("A",N_ND->CurrentLine)==0)
        {
          NonStop=TRUE;
        }
        if (stricmp("?",N_ND->CurrentLine)==0)
        {
          DOOR_WriteText(ANSI_FG_WHITE
                         "Help\r\n~~~~\r\n\r\n"
                         "?    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  This Help Page\r\n"
                         "C    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  Clear Screen And Continue\r\n"
                         "N/Q  "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  No More Please (QUIT)\r\n"
                         "A    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  Display All of remaining files (same as /X's NS)\r\n"
                         "L    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  Display All of remaining files with CLS's!\r\n"
                         "F    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  Flag File By NAME\r\n"
                         "R    "ANSI_FG_CYAN"-"ANSI_FG_WHITE"  Flag File By NUMBER\r\n");
          Help=TRUE;
        }
      }
    }
    while ((N_ND->OnlineStatus==OS_ONLINE) && (Help));
  }
  LinesOutput=0;


  if (N_ND->OnlineStatus==OS_ONLINE)
  {
    if ( Lopt && !ReachedEOF) DOOR_WriteText( ANSI_CLS );
  }
  else
  {
    retval=TRUE; // cancel!
  }

  return(retval);
}

void PrintLine( char *Buffer)
{
  // Depending on the it at the start of the buffer different things happen to the
  // output of the reset of the buffer..
  UBYTE buffer[82];
  strcpy( buffer, Buffer );

  if (buffer[1]==' ')
  {
    switch (buffer[0])
    {
      case 'F' :
        CurrentFileNumber++;
        DOOR_WriteText(ANSI_RESET ANSI_FG_BLUE);
        sprintf(tmpstr,"-- "ANSI_FG_YELLOW"["ANSI_FG_WHITE" %d "ANSI_FG_YELLOW"]"ANSI_FG_WHITE" - "ANSI_FG_YELLOW"["ANSI_FG_WHITE" %s "ANSI_FG_YELLOW"]"ANSI_FG_WHITE" - "ANSI_FG_YELLOW"["ANSI_FG_WHITE" Node %d "ANSI_FG_YELLOW"]"ANSI_FG_BLUE" ",CurrentFileNumber,BBSGlobal->BBSName,N_ND->NodeNum);
        strpad(tmpstr,79+60,'-'); // +60 for the ansi!
        strcat(tmpstr,"\r\n");
        DOOR_WriteText(tmpstr);

        // first part of line needs to be CYAN

        DOOR_WriteText(ANSI_FG_CYAN);
        strNcpy(tmpstr,&buffer[2],34);
        DOOR_WriteText(tmpstr);

        // last part of line needs to be WHITE

        DOOR_WriteText(ANSI_FG_WHITE);
        strfcpy(tmpstr,&buffer[2],34); // index at 0, so use 34 instead of 35 for the 34th char..
        DOOR_WriteText(tmpstr);
        DOOR_WriteText("\r\n");
        LinesOutput+=2;
        break;
      case 'I' :
        DOOR_WriteText(ANSI_FG_WHITE);
        DOOR_WriteText(&buffer[2]);
        DOOR_WriteText("\r\n");
        LinesOutput++;
        break;
      case 'X' :
        strpad(buffer,81,' '); // make sure it's 81 chars long.. 79 are printed..
        DOOR_WriteText(ANSI_BG_BLUE ANSI_FG_WHITE);
        DOOR_WriteText(&buffer[2]);
        DOOR_WriteText("\r\n");
        DOOR_WriteText(ANSI_RESET);
        LinesOutput++;
        break;
      case 'P' :
        DOOR_WriteText(ANSI_RESET);
        DOOR_WriteText(&buffer[2]);
        DOOR_WriteText("\r\n");
        DOOR_WriteText(ANSI_RESET);
        LinesOutput++;
        break;
      case 'T' :
        if (strlen(buffer)>=25)
        {
          strNcpy(tmpstr,&buffer[2],25);
          DOOR_WriteText(tmpstr);
          DOOR_WriteText(ANSI_FG_YELLOW);
          strNcpy(tmpstr,&buffer[27],8);
          DOOR_WriteText(tmpstr);
          DOOR_WriteText(ANSI_FG_WHITE);
          DOOR_WriteText(&buffer[35]);
          DOOR_WriteText("\r\n");
          LinesOutput++;
        }
        break;
      case 'N' :
        if (strlen(buffer)>=25)
        {
          strNcpy(tmpstr,&buffer[2],25);
          DOOR_WriteText(tmpstr);
          DOOR_WriteText(ANSI_FG_GREEN);
          strNcpy(tmpstr,&buffer[27],8);
          DOOR_WriteText(tmpstr);
          DOOR_WriteText(ANSI_FG_WHITE);
          DOOR_WriteText(&buffer[35]);
          DOOR_WriteText("\r\n");
          LinesOutput++;
        }
        break;
    }
  }
}

void DisplayFileIDList( struct List *list )
{
  struct Node *ptr;

  for( ptr = list->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  {
    PrintLine( ptr->ln_Name );
  }
}

BOOL DoWeWantToDisplayThis( struct List *list, char *SearchString )
{
  struct Node *ptr;
  BOOL Found = FALSE;
  char *isubstr, *istr;

  /* *C* Add Highlight */

  for( ptr = list->lh_Head; ptr->ln_Succ; ptr = ptr->ln_Succ )
  {
    if (isubstr=upcase(SearchString))
    {
      if (istr=upcase(ptr->ln_Name))
      {
        if( strstr( istr, isubstr ) ) Found = TRUE;
        FreeStr(istr);
      }
      FreeStr(isubstr);
    }
  }
  return( Found );
}

#define BUFLEN 1024

void SearchFileList( char *FileName, char *SearchString )
{
  BPTR FL, FH;
  char InBuffer[BUFLEN+1];
  BOOL Quit = FALSE, Done, EOFReached = FALSE;
  struct List *FileIDList;
  ULONG NodesInList = 0,NumberFound = 0;

  if( FL = Lock( FileName, SHARED_LOCK ))
  {
    if( FH = OpenFromLock( FL ))
    {
      /* Get First Line of IDs */
      Done = FALSE;
      while( (N_ND->OnlineStatus==OS_ONLINE) && (!Done) )
      {
        if( FGets( FH, InBuffer, BUFLEN ) )
        {
          FM_RemoveCR( InBuffer );
          if( InBuffer[0] == 'F' )
          {
            Done = TRUE;
          }
        }
        else
        {
          Done = TRUE;
          Quit = TRUE;
          DOOR_WriteText( "Error : Reading From FileList\r\n" );
        }
      }

      if( !Quit )
      {
        while( (N_ND->OnlineStatus==OS_ONLINE) && (!Quit) && (!EOFReached ) )
        {
          if( FileIDList = HBBS_CreateList() )
          {
            NodesInList = 0;
            if( InBuffer[0] == 'F' )
            {
              if( !(NewStrNode( InBuffer, FileIDList )) )
              {
                NodesInList++;
                Done = FALSE;
                while( (N_ND->OnlineStatus==OS_ONLINE) && (!Done) )
                {
                  if( !(FGets( FH, InBuffer, BUFLEN )))
                  {
                    EOFReached = TRUE;
                    Done = TRUE;
                    if( IoErr() )
                    {
                      DOOR_WriteText( "Error : Reading From FileList\r\n" );
                    }
                  }
                  FM_RemoveCR( InBuffer );

                  switch( InBuffer[0] )
                  {
                    case 'F':
                      Done = TRUE;
                      break;
                    case 'I':
                    case 'X':
                    case 'P':
                    case 'T':
                    case 'N':
                      NodesInList++;
                      if( NewStrNode( InBuffer, FileIDList ) )
                      {
                        DOOR_WriteText( "Error : Not enough Mem..." );
                        Quit = TRUE;
                      }
                      break;
                  }
                }

                if( !Quit )
                {
                  if( DoWeWantToDisplayThis( FileIDList, SearchString ) )
                  {
                    NumberFound++;
                    if ((1 + LinesOutput + NodesInList) > (N_ND->User.CallData.LinesPerScreen-1) )
                    {
                      Quit=ScreenPausePrompt(FALSE);
                    }
                    if( (!Quit)&&(N_ND->OnlineStatus==OS_ONLINE))
                    {

                      FM_strFNcpy( FileIDList->lh_Head->ln_Name, tmpstr, 2, 12 );
                      RemoveSpaces( tmpstr );

                      NewStrNode( tmpstr, FileNames );

                      DisplayFileIDList( FileIDList );
                    }
                  }
                }
              }
              else
              {
                DOOR_WriteText( "Error : Not enough Mem..." );
                Quit = TRUE;
              }
            }
            if( FileIDList )
            {
              FreeStrList( FileIDList );
              FileIDList = NULL;
            }
          }
        }
        if( !(NumberFound > 0) && (N_ND->OnlineStatus==OS_ONLINE))
        {
          sprintf( tmpstr, "No file descriptions contain \"%s\".\r\n", SearchString );
          DOOR_WriteText( tmpstr );
        }
        else
        {
          if( EOFReached ) ScreenPausePrompt(TRUE);
        }
      }
      Close( FH );
      FL = NULL;
    }
    else
    {
      DOOR_WriteText( "Error : Unable to open filelist\r\n" );
    }
    if( FL )  UnLock( FL );
  }
  else
  {
    DOOR_WriteText( "Error : FileList does not exist\r\n" );
  }
}

long CheckArgs( char *str )
{
  long retval = -1;

  if( str[0] )
  {
    switch( str[0] )
    {
      case 'a':
      case 'A':
        retval = -1;
        DOOR_WriteText( "Scanning all FileLists\r\n" );
        break;
      default:
        retval = atol( str );
        if( !((retval > 0) && ( retval <= N_ND->CurrentConf->FileLists )) )
        {
          DOOR_WriteText( "FileList does not exist. Using Last List.\r\n" );
          retval = N_ND->CurrentConf->FileLists;
        }
        break;
    }
  }
  return( retval );
}
/* **** DoorMain *********************************************************** */

void DoorMain( void )
{
  char SearchString[BIG_STR], filename[BIG_STR];
  struct Node *node;
  BOOL DoAll = FALSE, Done = FALSE;
  long FileListToRead;


  DOOR_WriteText( ANSI_RESET );

  DOOR_WriteText( ANSI_FG_YELLOW ANSI_BG_BLACK ANSI_UNDERLINE
                  "                                                                               \r\n" );
  DOOR_WriteText( ANSI_BG_RED
                  "      Teppic Zippy Search V1.0   (C) 1995 Teppic/Ruby Knight Productions       " ANSI_RESET "\r\n\r\n" );

  SearchString[0] = 0;

  if (N_ND->User.Acs.Data[ACS_SCANFILES] == 'Y')
  {
    if( N_ND->CurrentConf )
    {
      if( N_ND->CurrentConf->FileLists>0 )
      {

        FileListToRead = N_ND->CurrentConf->FileLists;

        if( gargc < 3 )
        {
          DOOR_WriteText(ANSI_FG_YELLOW "Enter Search String "ANSI_FG_BLUE ": "ANSI_FG_WHITE );
          DOOR_GetLine( GL_DISPLAY|GL_EDIT|GL_HISTORY|GL_IMMEDIATE, '\0', 0, 0, NULL );
          if (N_ND->OnlineStatus==OS_ONLINE)
          {
            RemoveSpaces( N_ND->CurrentLine );
            strcpy( SearchString, N_ND->CurrentLine );
            DOOR_WriteText(ANSI_FG_YELLOW "Enter FileList to use or A "ANSI_FG_BLUE": " ANSI_FG_WHITE);
            DOOR_GetLine( GL_DISPLAY|GL_EDIT|GL_HISTORY|GL_IMMEDIATE, '\0', 0, 0, NULL );
            if (N_ND->OnlineStatus==OS_ONLINE)
            {
              RemoveSpaces( N_ND->CurrentLine );

              FileListToRead = CheckArgs( N_ND->CurrentLine );
              if( FileListToRead == -1 )
              {
                FileListToRead = 1;
                DoAll = TRUE;
              }
            }
          }
        }
        else
        {
          if( gargv[2][0] == '?' )
          {
            DOOR_WriteText( "Usage : [searchstring] [A|<Filelist Number>]\r\n\r\n" );
          }
          else
          {
            strcpy( SearchString, gargv[2] );
          }
        }

        if( N_ND->OnlineStatus==OS_ONLINE )
        {
          if( gargc >=4 )
          {
            FileListToRead = CheckArgs( gargv[3] );
            if( FileListToRead == -1 )
            {
              FileListToRead = 1;
              DoAll = TRUE;
            }
          }

          if( SearchString[0] )
          {
            if( FileNames = HBBS_CreateList() )
            {

              Done = FALSE;
              while( (!Done) && (FileListToRead <= N_ND->CurrentConf->FileLists ) && (N_ND->OnlineStatus==OS_ONLINE))
              {

                node = GetNode(N_ND->CurrentConf->FileList, FileListToRead-1);

                sprintf( tmpstr, "Searching for \"%s\" in filelist %ld.\r\n", SearchString, FileListToRead );
                DOOR_WriteText( tmpstr );

                sprintf(filename,"%sWork/Zippy.TEMP",N_ND->NodeLocation);

                if (PathOK(node->ln_Name))
                {
//                  if( HBBS_CopyFile( node->ln_Name, filename, 0 ) )
//                  {

                    SearchFileList( node->ln_Name, SearchString );

//                    DeleteFile( filename );
//                  }
//                  else
//                  {
//                    DOOR_WriteText( "Error : cannot duplicate filelist\r\n" );
//                  }
                }
                else
                {
                  DOOR_WriteText( "Error : filelist is not availiable\r\n" );
                }
                FileListToRead++;

                if( !DoAll ) Done = TRUE;
              }
              if (N_ND->OnlineStatus==OS_ONLINE)
              {
                DOOR_WriteText( "Done!\r\n" );
              }
              FreeStrList( FileNames );
            }
            else
            {
              DOOR_WriteText( "Error : Not enough memory\r\n" );
            }
          }
        }
      }
    }
  }
  else
  {
    DOOR_WriteText("Access Denied!\r\n");
  }
}

int main(int argc,char **argv)
{
  gargc=argc;
  gargv=argv;

  if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  {
    printf("Invalid/No Paramaters for door!\n");
    exit (20);
  }
  init("BZippy");

  if (BBSGlobal=HBBS_GimmeBBS())
  {
    if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
    {
      DoorMain();
    }
  }
  cleanup(0);
}

/* **** End Of File ******************************************************** */
