📄 ftsearch.cpp
字号:
int i, j, number;
// Parse the command line.
*DatabasePath = argv[1];
for(i=2; i<argc; i++)
{
char *argstring = argv[i];
int count = strlen(argstring);
for (j=0; j<count; j++)
{
switch (argstring[j])
{
case 'W':
case 'w':
*IsStemWords = FALSE;
break;
case 'T':
case 't':
*IsThesaurusWords = TRUE;
break;
case 'S':
case 's':
*IsSearchSet = FALSE;
break;
case 'D':
case 'd':
if ( (number = atoi( &argstring[(j+1)] ) ) )
*MaxDocuments = number;
break;
case 'O':
case 'o':
if ( (number = atoi( &argstring[(j+1)] ) ) )
*SortOption = number;
break;
case 'V':
case 'v':
if ( (number = atoi( &argstring[(j+1)] ) ) )
*ViewNumber = number;
break;
}
} // END for (j=0; j<count; j++)
} // END for(i=2; i<argc; i++)
} // END if (argc < 2) ELSE
} // END ProcessArguments()
//---------------------------------------------------------------------------
//
// Name:
// InitDefaultParams
//
// Description:
// Set up all the default parameter strings and numbers for user
// input. Called by ProcessArguments() if no user input params
// were provided.
//
// NOTE:
// You only need to edit this function and ProcessArguments()
// when creating a new sample. The rest of the user interface
// functions below are called by ProcessArguments() and are
// generic, which means that they can stay the same unless
// you increase or decrease the number of parameters to use.
// Then you only need to cut or paste in one more or one less
// block of the switch statements in the functions below.
//---------------------------------------------------------------------------
void InitDefaultParams()
{
// Initialize default parameter strings.
PromptString1 = "File path name for the database to search : [";
ParamString1 = "ftsearch.nsf";
PromptString2 = "Use Stemming Words? (partial word matches) : [";
ParamString2 = "Y";
PromptString3 = "Use Thesaurus Words? (similar word matches) : [";
ParamString3 = "N";
PromptString4 = "Select documents from particular author? : [";
ParamString4 = "Y";
// Initialize default parameter numbers.
PromptNumber1 = "Max number of docs for the result collection : [";
ParamNumber1 = 100;
PromptNumber2 << "\nThe sorting order for the result collection \n"
<< " <1> By Relevance \n"
<< " <2> By Date (newest first) \n"
<< " <3> By Date (oldest first) : [";
ParamNumber2 = 1;
PromptNumber3 << "\nThe kind of view to search under \n"
<< " <1> By Author \n"
<< " <2> Categorize \n"
<< " <3> By Main Topics only \n"
<< " <4> By Main View (default) : [";
ParamNumber3 = 4;
} // END InitDefaultParams()
//---------------------------------------------------------------------------
//
// Name:
// GetArguments
//
// Description:
// Allows the user to change any or all of the input parameter
// IOParameter. The inputs can also be left as they are if desired.
//---------------------------------------------------------------------------
void GetArguments()
{
BOOL isCorrectData = FALSE;
QueryArguments();
while (!isCorrectData)
{
PrintArguments();
cout << "Are these current data settings correct? : [Y] ";
cin >> CommandBuf;
switch( CommandBuf[0] )
{
case 'Y':
case 'y':
isCorrectData = TRUE; // All done, get out now!
break;
default:
// Prompt again for anything other than a "Y" or carriage return.
if( (CommandBuf) != (const char *)"" )
QueryArguments();
else
isCorrectData = TRUE; // All done, get out now!
} // END switch
} // END while
} // END GetArguments()
//---------------------------------------------------------------------------
//
// Name:
// PrintArguments
//
// Description:
// Prints out all of the current input parameters to use.
//---------------------------------------------------------------------------
void PrintArguments()
{
cout << endl;
cout << "The Current Default Data Settings are: " << endl;
cout << endl;
// Print out current parameter strings.
cout << PromptString1 << ParamString1 << "]" << endl;
cout << PromptString2 << ParamString2 << "]" << endl;
cout << PromptString3 << ParamString3 << "]" << endl;
cout << PromptString4 << ParamString4 << "]" << endl;
// Print out current parameter numbers.
cout << PromptNumber1 << ParamNumber1 << "]" << endl;
cout << PromptNumber2 << ParamNumber2 << "]" << endl;
cout << PromptNumber3 << ParamNumber3 << "]" << endl;
cout << endl;
} // END PrintArguments()
//---------------------------------------------------------------------------
//
// Name:
// QueryArguments
//
// Description:
// Queries the user to change any of the input parameters.
// A carriage return on any of the prompts leaves it alone.
//---------------------------------------------------------------------------
void QueryArguments()
{
cout << endl;
cout << "Enter the following parameters (or hit Enter to accept default):" << endl;
cout << endl;
// Prompt for Strings....
cout << PromptString1 << ParamString1 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString1 = CommandBuf;
cout << PromptString2 << ParamString2 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString2 = CommandBuf;
cout << PromptString3 << ParamString3 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString3 = CommandBuf;
cout << PromptString4 << ParamString4 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString4 = CommandBuf;
// Prompt for numbers.
cout << PromptNumber1 << ParamNumber1 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamNumber1 = (LNINT)CommandBuf.StringToInteger();
cout << PromptNumber2 << ParamNumber2 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamNumber2 = (LNINT)CommandBuf.StringToInteger();
cout << PromptNumber3 << ParamNumber3 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamNumber3 = (LNINT)CommandBuf.StringToInteger();
} // END QueryArguments()
//===========================================================================
//
// IOPARAMETER Class Implementation
//
// Description:
// Implementation for a simple generic string buffer class
// to hold user input and output prompts.
//===========================================================================
//===========================================================================
// Constructors
//===========================================================================
IOParameter::IOParameter() // Default constructor.
{
size =1; // Null Terminator.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
pBuf[0] = '\0';
}
//===========================================================================
IOParameter::IOParameter( const char *Str ) // Init with const string.
{
size = strlen(Str) + 1; // Size of string + null term.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Str);
}
//===========================================================================
// Constructs a decimal radix string representation of an integer.
IOParameter::IOParameter( const int Number )
{
char buf[16]; // Temporary buffer for characters.
sprintf(buf, "%d", Number);
size = strlen(buf) + 1; // Size of string + null term.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, buf);
}
//===========================================================================
IOParameter::IOParameter( const IOParameter &Other ) // Copy constructor.
{
size = Other.size;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Other.pBuf);
}
//===========================================================================
// Constructor using 2 IOParameter objects as input.
IOParameter::IOParameter( const IOParameter& Prefix, const IOParameter& Postfix)
{
size = Prefix.size + Postfix.size - 1;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Prefix.pBuf);
strcat(pBuf, Postfix.pBuf);
}
//===========================================================================
// Subscript, etc.
//===========================================================================
char IOParameter::operator [] (int Index)
{
char c;
if (Index > size)
c = '\0';
else
c = pBuf[Index];
return c;
}
//===========================================================================
// Assignment.
//===========================================================================
IOParameter IOParameter::operator = ( const IOParameter &Other )
{
if(pBuf)
delete [] pBuf;
size = Other.size;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Other.pBuf);
return *this;
}
//===========================================================================
IOParameter IOParameter::operator = ( const char *Str )
{
size = strlen(Str) +1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Str);
return *this;
}
//===========================================================================
// I/O operators.
//===========================================================================
ostream &operator << ( ostream &Stream, const IOParameter &Other )
{
Stream << Other.pBuf;
return Stream;
}
//===========================================================================
istream &operator >> ( istream &Stream, IOParameter &Other )
{
const int buflen = 255; // Arbitrary size, change if needed.
char t[buflen]; // temp string...
int len;
for (len=0; len<buflen; len++)
{
Stream.get(t[len]);
if (t[len] == '\n') // Newline character
break;
if (t[len] == '\b') // Backspace character
{
if(len)
{
len--;
// cout << "'\b'"; // For debug only.
}
}
}
t[len] = '\0';
len++;
if(Other.pBuf)
delete [] Other.pBuf;
if (! (Other.pBuf = new char[len]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
Other.size = len;
strcpy(Other.pBuf, t);
return Stream;
} // END istream &operator >>
//===========================================================================
// Concatenate.
//===========================================================================
IOParameter IOParameter::operator + ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
return IOParameter( *this, Other );
}
//===========================================================================
IOParameter IOParameter::operator + ( const char *Str ) // Cat IOParameter and string.
{
return IOParameter( *this, IOParameter(Str) );
}
//===========================================================================
IOParameter operator + ( char *Str, const IOParameter &Other ) // Cat string with IOParameter.
{
return IOParameter( IOParameter(Str), Other );
}
//===========================================================================
IOParameter& IOParameter::operator << ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
IOParameter TempString(*this);
size = TempString.size + Other.size - 1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, TempString.pBuf);
strcat(pBuf, Other.pBuf);
return *this;
}
//===========================================================================
IOParameter& IOParameter::operator << ( const char *Str ) // Cat IOParameter and string.
{
IOParameter TempString(*this);
IOParameter Other(Str);
size = TempString.size + Other.size - 1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, TempString.pBuf);
strcat(pBuf, Other.pBuf);
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -