// Load sentence file into memory, insert null terminators to
// delimit sentence name/sentence pairs. Keep pointer to each
// sentence name so we can search later.
void VOX_ReadSentenceFile( const char *psentenceFileName )
{
char c, *pch, *pFileData;
char *pchlast, *pSentenceData;
int fileSize;
// load file
pFileData = (char *)FS_LoadFile( psentenceFileName, &fileSize, false );
if( !pFileData )
{
MsgDev( D_WARN, "couldn't load %s\n", psentenceFileName );
return;
}
pch = pFileData;
pchlast = pch + fileSize;
while( pch < pchlast )
{
// only process this pass on sentences
pSentenceData = NULL;
// skip newline, cr, tab, space
c = *pch;
while( pch < pchlast && IsWhiteSpace( c ))
c = *(++pch);
// skip entire line if first char is /
if( *pch != '/' )
{
sentence_t *pSentence = &g_Sentences[g_numSentences++];
pSentence->pName = pch;
pSentence->length = 0;
// scan forward to first space, insert null terminator
// after sentence name
c = *pch;
while( pch < pchlast && c != ' ' )
c = *(++pch);
if( pch < pchlast )
*pch++ = 0;
// a sentence may have some line commands, make an extra pass
pSentenceData = pch;
}
// scan forward to end of sentence or eof
while( pch < pchlast && pch[0] != '\n' && pch[0] != '\r' )
pch++;
// insert null terminator
if( pch < pchlast ) *pch++ = 0;
// If we have some sentence data, parse out any line commands
if( pSentenceData && pSentenceData < pchlast )
{
int index = g_numSentences - 1;
// the current sentence has an index of count-1
VOX_ParseLineCommands( pSentenceData, index );
}
}
}
开发者ID:n00ner,项目名称:xash3d,代码行数:71,代码来源:s_vox.c
示例2: switch
BOOL CSZCommandLine::Analyze(LPCTSTR lpszCmdLine)
{
BOOL bResult = FALSE;
int nParamNamePos = 0;
int nParamValuePos = 0;
int nSubCommandPos = 0;
CString strParamName;
CString strSubCommand;
BOOL bInQuotation = FALSE;
EM_CMDLINE_STATUS nStatus = em_Cmd_New_Arg;
m_mapParams.RemoveAll();
if (!lpszCmdLine)
goto Exit0;
for (int nPos = 0; 0 == nPos || lpszCmdLine[nPos - 1]; ++nPos)
{
TCHAR ch = lpszCmdLine[nPos];
switch (nStatus)
{
case em_Cmd_New_Arg:
bInQuotation = FALSE;
// no break;
case em_Cmd_White_Space:
if (IsWhiteSpace(ch))
{
nStatus = em_Cmd_White_Space;
}
else if (IsArgNamePrefix(ch))
{
nStatus = em_Cmd_Arg_Name_Prefix;
}
else if (IsAlpha(ch))
{ // skip sub command
nSubCommandPos = nPos;
nStatus = em_Cmd_Sub_Command;
}
else if (IsQuotation(ch))
{
bInQuotation = TRUE;
nStatus = em_Cmd_White_Space;
}
else
{
goto Exit0;
}
break;
case em_Cmd_Sub_Command:
if (IsWhiteSpace(ch))
{
strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
AppendSubCommand(strSubCommand);
nStatus = em_Cmd_New_Arg;
}
else if (IsAlpha(ch))
{ // skip sub command
nStatus = em_Cmd_Sub_Command;
}
else if (IsQuotation(ch))
{
strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
AppendSubCommand(strSubCommand);
nStatus = em_Cmd_New_Arg;
}
else
{
goto Exit0;
}
break;
case em_Cmd_Arg_Name_Prefix:
if (IsWhiteSpace(ch))
{
goto Exit0;
}
else if (IsArgNamePrefix(ch))
{ // Á¬ÐøµÄǰ׺
nStatus = em_Cmd_Arg_Name_Prefix;
}
else
{
nParamNamePos = nPos;
nStatus = em_Cmd_Arg_Name;
}
break;
case em_Cmd_Arg_Name:
if (IsWhiteSpace(ch))
//.........这里部分代码省略.........
void TiXmlElement::StreamIn (std::istream * in, TIXML_STRING * tag)
{
// We're called with some amount of pre-parsing. That is, some of "this"
// element is in "tag". Go ahead and stream to the closing ">"
while( in->good() )
{
int c = in->get();
if ( c <= 0 )
{
TiXmlDocument* document = GetDocument();
if ( document )
document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
return;
}
(*tag) += (char) c ;
if ( c == '>' )
break;
}
if ( tag->length() < 3 ) return;
// Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
// If not, identify and stream.
if ( tag->at( tag->length() - 1 ) == '>'
&& tag->at( tag->length() - 2 ) == '/' )
{
// All good!
return;
}
else if ( tag->at( tag->length() - 1 ) == '>' )
{
// There is more. Could be:
// text
// cdata text (which looks like another node)
// closing tag
// another node.
for ( ;; )
{
StreamWhiteSpace( in, tag );
// Do we have text?
if ( in->good() && in->peek() != '<' )
{
// Yep, text.
TiXmlText text( "" );
text.StreamIn( in, tag );
// What follows text is a closing tag or another node.
// Go around again and figure it out.
continue;
}
// We now have either a closing tag...or another node.
// We should be at a "<", regardless.
if ( !in->good() ) return;
assert( in->peek() == '<' );
int tagIndex = (int) tag->length();
bool closingTag = false;
bool firstCharFound = false;
for( ;; )
{
if ( !in->good() )
return;
int c = in->peek();
if ( c <= 0 )
{
TiXmlDocument* document = GetDocument();
if ( document )
document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
return;
}
if ( c == '>' )
break;
*tag += (char) c;
in->get();
// Early out if we find the CDATA id.
if ( c == '[' && tag->size() >= 9 )
{
size_t len = tag->size();
const char* start = tag->c_str() + len - 9;
if ( strcmp( start, "<![CDATA[" ) == 0 ) {
assert( !closingTag );
break;
}
}
if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
{
firstCharFound = true;
if ( c == '/' )
closingTag = true;
}
//.........这里部分代码省略.........
void TiXmlElement::StreamIn (TIXML_ISTREAM * in, TIXML_STRING * tag)
{
// We're called with some amount of pre-parsing. That is, some of "this"
// element is in "tag". Go ahead and stream to the closing ">"
while( in->good() )
{
int c = in->get();
(*tag) += (TCHAR) c ;
if ( c == '>' )
break;
}
if ( tag->length() < 3 ) return;
// Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
// If not, identify and stream.
if ( tag->at( tag->length() - 1 ) == '>'
&& tag->at( tag->length() - 2 ) == '/' )
{
// All good!
return;
}
else if ( tag->at( tag->length() - 1 ) == '>' )
{
// There is more. Could be:
// text
// closing tag
// another node.
for ( ;; )
{
StreamWhiteSpace( in, tag );
// Do we have text?
if ( in->good() && in->peek() != '<' )
{
// Yep, text.
TiXmlText text( TEXT("") );
text.StreamIn( in, tag );
// What follows text is a closing tag or another node.
// Go around again and figure it out.
continue;
}
// We now have either a closing tag...or another node.
// We should be at a "<", regardless.
if ( !in->good() ) return;
assert( in->peek() == '<' );
size_t tagIndex = tag->length();
bool closingTag = false;
bool firstCharFound = false;
for( ;; )
{
if ( !in->good() )
return;
int c = in->peek();
if ( c == '>' )
break;
*tag += (TCHAR)c;
in->get();
if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
{
firstCharFound = true;
if ( c == '/' )
closingTag = true;
}
}
// If it was a closing tag, then read in the closing '>' to clean up the input stream.
// If it was not, the streaming will be done by the tag.
if ( closingTag )
{
int c = in->get();
assert( c == '>' );
*tag += (TCHAR)c;
// We are done, once we've found our closing tag.
return;
}
else
{
// If not a closing tag, id it, and stream.
const TCHAR* tagloc = tag->c_str() + tagIndex;
TiXmlNode* node = Identify( tagloc );
if ( !node )
return;
node->StreamIn( in, tag );
delete node;
node = 0;
// No return: go around from the beginning: text, closing tag, or node.
}
}
//.........这里部分代码省略.........
int InPlaceParser::ProcessLine(int lineno,char *line,InPlaceParserInterface *callback)
{
int ret = 0;
const char *argv[MAXARGS];
int argc = 0;
char *foo = line;
while ( !EOS(*foo) && argc < MAXARGS )
{
foo = SkipSpaces(foo); // skip any leading spaces
if ( EOS(*foo) ) break;
if ( *foo == mQuoteChar ) // if it is an open quote
{
foo++;
if ( argc < MAXARGS )
{
argv[argc++] = foo;
}
while ( !EOS(*foo) && *foo != mQuoteChar ) foo++;
if ( !EOS(*foo) )
{
*foo = 0; // replace close quote with zero byte EOS
foo++;
}
}
else
{
foo = AddHard(argc,argv,foo); // add any hard separators, skip any spaces
if ( IsNonSeparator(*foo) ) // add non-hard argument.
{
bool quote = false;
if ( *foo == mQuoteChar )
{
foo++;
quote = true;
}
if ( argc < MAXARGS )
{
argv[argc++] = foo;
}
if ( quote )
{
while (*foo && *foo != mQuoteChar ) foo++;
if ( *foo ) *foo = 32;
}
// continue..until we hit an eos ..
while ( !EOS(*foo) ) // until we hit EOS
{
if ( IsWhiteSpace(*foo) ) // if we hit a space, stomp a zero byte, and exit
{
*foo = 0;
foo++;
break;
}
else if ( IsHard(*foo) ) // if we hit a hard separator, stomp a zero byte and store the hard separator argument
{
const char *hard = &mHardString[*foo*2];
*foo = 0;
if ( argc < MAXARGS )
{
argv[argc++] = hard;
}
foo++;
break;
}
foo++;
} // end of while loop...
}
}
}
if ( argc )
{
ret = callback->ParseLine(lineno, argc, argv );
}
return ret;
}
nsresult nsPropertiesParser::ParseBuffer(const PRUnichar* aBuffer,
PRUint32 aBufferLength)
{
const PRUnichar* cur = aBuffer;
const PRUnichar* end = aBuffer + aBufferLength;
// points to the start/end of the current key or value
const PRUnichar* tokenStart = nsnull;
// if we're in the middle of parsing a key or value, make sure
// the current token points to the beginning of the current buffer
if (mState == eParserState_Key ||
mState == eParserState_Value) {
tokenStart = aBuffer;
}
nsAutoString oldValue;
while (cur != end) {
PRUnichar c = *cur;
switch (mState) {
case eParserState_AwaitingKey:
if (c == '#' || c == '!')
EnterCommentState();
else if (!IsWhiteSpace(c)) {
// not a comment, not whitespace, we must have found a key!
EnterKeyState();
tokenStart = cur;
}
break;
case eParserState_Key:
if (c == '=' || c == ':') {
mKey += Substring(tokenStart, cur);
WaitForValue();
}
break;
case eParserState_AwaitingValue:
if (IsEOL(c)) {
// no value at all! mimic the normal value-ending
EnterValueState();
FinishValueState(oldValue);
}
// ignore white space leading up to the value
else if (!IsWhiteSpace(c)) {
tokenStart = cur;
EnterValueState();
// make sure to handle this first character
if (ParseValueCharacter(c, cur, tokenStart, oldValue))
cur++;
// If the character isn't consumed, don't do cur++ and parse
// the character again. This can happen f.e. for char 'X' in sequence
// "\u00X". This character can be control character and must be
// processed again.
continue;
}
break;
case eParserState_Value:
if (ParseValueCharacter(c, cur, tokenStart, oldValue))
cur++;
// See few lines above for reason of doing this
continue;
case eParserState_Comment:
// stay in this state till we hit EOL
if (c == '\r' || c== '\n')
WaitForKey();
break;
}
// finally, advance to the next character
cur++;
}
// if we're still parsing the value and are in eParserSpecial_None, then
// append whatever we have..
if (mState == eParserState_Value && tokenStart &&
mSpecialState == eParserSpecial_None) {
mValue += Substring(tokenStart, cur);
}
// if we're still parsing the key, then append whatever we have..
else if (mState == eParserState_Key && tokenStart) {
mKey += Substring(tokenStart, cur);
}
return NS_OK;
}
bool TextAreaTextRange::CheckEndPointIsUnitEndpoint(_In_ EndPoint check, _In_ TextUnit unit, _In_ TEXTATTRIBUTEID specificAttribute)
{
if (unit == TextUnit_Character)
{
return true;
}
EndPoint next;
EndPoint prev;
if (!_control->StepCharacter(check, true, &next) ||
!_control->StepCharacter(check, false, &prev))
{
// If we're at the beginning or end, we're at an endpoint
return true;
}
else if (unit == TextUnit_Word)
{
if (IsWhiteSpace(prev) && !IsWhiteSpace(check))
{
return true;
}
return false;
}
else if (unit == TextUnit_Line || unit == TextUnit_Paragraph)
{
return check.line != next.line;
}
// TextUnit_Page and TextUnit_Document are covered by the initial beginning/end check
else if (unit == TextUnit_Page || unit == TextUnit_Document)
{
return false;
}
else if (unit == TextUnit_Format)
{
bool matching = true;
bool checkedLineBoundary = false;
// There are limited attributes that vary in this control
// If its not one of those attributes, then it is not an Endpoint
// unless it's the document start or end, which is checked above
for (int i = 0; i < ARRAYSIZE(lineVariableAttributes); i++)
{
if (specificAttribute == 0 || specificAttribute == lineVariableAttributes[i])
{
if (!checkedLineBoundary)
{
if (!CheckEndPointIsUnitEndpoint(check, TextUnit_Paragraph, 0))
{
break;
}
checkedLineBoundary = true;
}
VARIANT varC = _control->GetAttributeAtPoint(check, lineVariableAttributes[i]);
VARIANT varN = _control->GetAttributeAtPoint(next, lineVariableAttributes[i]);
HRESULT hr = VarCmp(&varC, &varN, LOCALE_NEUTRAL);
VariantClear(&varC);
VariantClear(&varN);
if (hr != VARCMP_EQ)
{
matching = false;
break;
}
}
}
for (int i = 0; i < ARRAYSIZE(charVariableAttributes); i++)
{
if (specificAttribute == 0 || specificAttribute == charVariableAttributes[i])
{
int *annotationIds;
int annotationCount;
if (GetAnnotationsAtPoint(check, &annotationIds, &annotationCount))
{
int *prevAnnotationIds;
int prevAnnotationCount;
if (GetAnnotationsAtPoint(prev, &prevAnnotationIds, &prevAnnotationCount))
{
if (annotationCount != prevAnnotationCount)
{
matching = false;
}
// Since all our annotations are the same type, if the number matches,
// then the UIA_AnnotationTypesAttributeId all match
else if (charVariableAttributes[i] == UIA_AnnotationObjectsAttributeId)
{
for (int j = 0; j < annotationCount; j++)
{
if (annotationIds[j] != prevAnnotationIds[j])
{
matching = false;
}
}
}
delete [] prevAnnotationIds;
}
//.........这里部分代码省略.........
const char* TiXmlAttribute::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
{
p = SkipWhiteSpace(p, encoding);
if (!p || !*p) return 0;
int tabsize = 4;
if (document)
tabsize = document->TabSize();
if (data)
{
data->Stamp(p, encoding);
location = data->Cursor();
}
// Read the name, the '=' and the value.
const char* pErr = p;
p = ReadName(p, &name, encoding);
if (!p || !*p)
{
if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding);
return 0;
}
p = SkipWhiteSpace(p, encoding);
if (!p || !*p || *p != '=')
{
if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
return 0;
}
++p; // skip '='
p = SkipWhiteSpace(p, encoding);
if (!p || !*p)
{
if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
return 0;
}
const char* end;
if (*p == '\'')
{
++p;
end = "\'";
p = ReadText(p, &value, false, end, false, encoding);
}
else if (*p == '"')
{
++p;
end = "\"";
p = ReadText(p, &value, false, end, false, encoding);
}
else
{
// All attribute values should be in single or double quotes.
// But this is such a common error that the parser will try
// its best, even without them.
value = "";
while ( p && *p // existence
&& !IsWhiteSpace(*p) && *p != '\n' && *p != '\r' // whitespace
&& *p != '/' && *p != '>') // tag end
{
value += *p;
++p;
}
}
return p;
}
void conv(RR& x, const char *s)
{
long c;
long cval;
long sign;
ZZ a, b;
long i = 0;
if (!s) Error("bad RR input");
c = s[i];
while (IsWhiteSpace(c)) {
i++;
c = s[i];
}
if (c == '-') {
sign = -1;
i++;
c = s[i];
}
else
sign = 1;
long got1 = 0;
long got_dot = 0;
long got2 = 0;
a = 0;
b = 1;
cval = CharToIntVal(c);
if (cval >= 0 && cval <= 9) {
got1 = 1;
while (cval >= 0 && cval <= 9) {
mul(a, a, 10);
add(a, a, cval);
i++;
c = s[i];
cval = CharToIntVal(c);
}
}
if (c == '.') {
got_dot = 1;
i++;
c = s[i];
cval = CharToIntVal(c);
if (cval >= 0 && cval <= 9) {
got2 = 1;
while (cval >= 0 && cval <= 9) {
mul(a, a, 10);
add(a, a, cval);
mul(b, b, 10);
i++;
c = s[i];
cval = CharToIntVal(c);
}
}
}
if (got_dot && !got1 && !got2) Error("bad RR input");
ZZ e;
long got_e = 0;
long e_sign;
if (c == 'e' || c == 'E') {
got_e = 1;
i++;
c = s[i];
if (c == '-') {
e_sign = -1;
i++;
c = s[i];
}
else if (c == '+') {
e_sign = 1;
i++;
c = s[i];
}
else
e_sign = 1;
cval = CharToIntVal(c);
if (cval < 0 || cval > 9) Error("bad RR input");
e = 0;
while (cval >= 0 && cval <= 9) {
//.........这里部分代码省略.........
开发者ID:Macaulay2,项目名称:Singular,代码行数:101,代码来源:RR.c
示例18: TRACEBEGIN
/*
* CRchTxtPtr::ChangeCase(cch, Type, publdr)
*
* @mfunc
* Change case of cch chars starting at this text ptr according to Type,
* which has the possible values:
*
* tomSentenceCase = 0: capitalize first letter of each sentence
* tomLowerCase = 1: change all letters to lower case
* tomUpperCase = 2: change all letters to upper case
* tomTitleCase = 3: capitalize the first letter of each word
* tomToggleCase = 4: toggle the case of each letter
*
* @rdesc
* TRUE iff a change occurred
*
* @devnote
* Since this routine only changes the case of characters, it has no
* effect on rich-text formatting. However it is part of the CRchTxtPtr
* class in order to notify the display of changes. CTxtRanges are also
* notified just in case the text blocks are modified.
*/
BOOL CRchTxtPtr::ChangeCase (
LONG cch, //@parm # chars to change case for
LONG Type, //@parm Type of change case command
IUndoBuilder *publdr) //@parm UndoBuilder to receive anti-event
// for any replacements
{
TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CRchTxtPtr::ChangeCase");
_TEST_INVARIANT_
#define BUFFERLEN 256
LONG cchChunk, cchFirst, cchGet, cchLast;
BOOL fAlpha, fToUpper, fUpper; // Flags controling case change
BOOL fChange = FALSE; // No change yet
BOOL fStart = TRUE; // Start of Word/Sentence
TCHAR * pch; // Ptr to walk rgCh with
WORD * pType; // Ptr to walk rgType with
TCHAR rgCh[BUFFERLEN]; // Char buffer to work in
WORD rgType[BUFFERLEN]; // C1_TYPE array for rgCh
if( GetCp() )
{
if( Type == tomSentenceCase )
{
fStart = _rpTX.IsAtBOSentence();
}
else if( Type == tomTitleCase )
{
// check to see if we are at the beginning of
// a word. This is the case if the character preceeding
// our current position is white space.
fStart = IsWhiteSpace(_rpTX.PrevChar());
_rpTX.AdvanceCp(1);
}
}
while(cch > 0) // Do 'em all (or as many as
{ // in story)
cchChunk = min(BUFFERLEN, cch); // Get next bufferful
cch -= cchChunk; // Decrement the count
cchGet = _rpTX.GetText(cchChunk, rgCh); // Manipulate chars in buffer
if(cchGet < cchChunk) // (for undo, need to use
{ // ReplaceRange())
cch = 0; // No more chars in story,
if(!cchGet) // so we'll be done
break; // We're done already
cchChunk = cchGet; // Something in this chunk
}
GetStringTypeEx(0, CT_CTYPE1, rgCh, // Find out whether chars are
cchChunk, rgType); // UC, LC, or neither
cchLast = 0; // Default nothing to replace
cchFirst = -1;
for(pch = rgCh, pType = rgType; // Process buffered chars
cchChunk;
cchChunk--, pch++, pType++)
{
fAlpha = *pType & (C1_UPPER | C1_LOWER); // Nonzero if UC or LC
fUpper = (*pType & C1_UPPER) != 0; // TRUE if UC
fToUpper = fStart ? TRUE : fUpper; // capitalize first letter of a
// sentence
switch(Type)
{ // Decide whether to change
case tomLowerCase: // case and determine start
fToUpper = FALSE; // of word/sentence for title
break; // and sentence cases
case tomUpperCase:
fToUpper = TRUE;
break;
case tomToggleCase:
fToUpper = !fUpper;
break;
case tomSentenceCase:
if(*pch == TEXT('.')) // If sentence terminator,
fStart = TRUE; // capitalize next alpha
//.........这里部分代码省略.........
请发表评论