📄 t3dlib6.cpp
字号:
// get next token
curr_tok++;
pattern_state = PATTERN_STATE_NEXT;
} // end if
else
{
// error pattern doesn't match, restart
pattern_state = PATTERN_STATE_RESTART;
} // end else
} break;
case PATTERN_STATE_STRING:
{
// need to test for non-space chars
// get comparator
switch(token_operator[curr_tok])
{
case '=':
{
// we need exactly
if (strlen(token) == token_numeric[curr_tok])
{
// put this string into table
strcpy(pstrings[num_pstrings++], token);
// get next token
curr_tok++;
pattern_state = PATTERN_STATE_NEXT;
} // end if
else
{
// error pattern doesn't match, restart
pattern_state = PATTERN_STATE_RESTART;
} // end else
} break;
case '>':
{
// we need greater than
if (strlen(token) > token_numeric[curr_tok])
{
// put this string into table
strcpy(pstrings[num_pstrings++], token);
// get next token
curr_tok++;
pattern_state = PATTERN_STATE_NEXT;
} // end if
else
{
// error pattern doesn't match, restart
pattern_state = PATTERN_STATE_RESTART;
} // end else
} break;
case '<':
{
// we need less than
if (strlen(token) < token_numeric[curr_tok])
{
// put this string into table
strcpy(pstrings[num_pstrings++], token);
// get next token
curr_tok++;
pattern_state = PATTERN_STATE_NEXT;
} // end if
else
{
// error pattern doesn't match, restart
pattern_state = PATTERN_STATE_RESTART;
} // end else
} break;
default: break;
} // end switch
} break;
case PATTERN_STATE_MATCH:
{
// we have matched the string, output vars into variable arg list
#ifdef PARSER_DEBUG_ON
printf("\nPattern: %s matched!", pattern);
#endif
return(1);
} break;
case PATTERN_STATE_END: { } break;
default: break;
} // end switch
} // end while
} // end Pattern_Match
// END IMPLEMENTATION OF CPARSERV1 CLASS ///////////////////////////////////
int ReplaceChars(char *string_in, char *string_out, char *replace_chars, char rep_char, int case_on)
{
// this function simply replaces the characters from the input string that
// are listed in replace with the replace char, the results are stored in
// string_out, string_in and isn't touched, the number of replacments is
// returned. if case_on = 1 then case is checked, other it's case insensitive
int num_replacements = 0, // tracks number of characters replaced
index_in = 0, // curr index into input
index_out = 0, // curr index into output
sindex, // loop var into strip array
slength = strlen(replace_chars); // length of strip string
// do some error checking
if (!string_in || !string_out || strlen(string_in) == 0)
return(0);
// nothing to replace
if (!replace_chars || strlen(replace_chars)==0)
{
strcpy(string_out, string_in);
return(0);
} // end if
// determine if case is important
if (case_on==1)
{
// perform char by char copy
while(string_in[index_in])
{
for (sindex = 0; sindex < slength; sindex++)
if (string_in[index_in] == replace_chars[sindex])
{
// replace it
string_out[index_out++] = rep_char;
index_in++;
num_replacements++;
break;
} // end if
// was a replacement performed?, no just copy then
if (sindex >= slength)
string_out[index_out++] = string_in[index_in++];
} // end while
} // end if case_on
else
{
// perform char by char copy with case insensitivity
while(string_in[index_in])
{
for (sindex = 0; sindex < slength; sindex++)
if (toupper(string_in[index_in]) == toupper(replace_chars[sindex]))
{
// replace it
string_out[index_out++] = rep_char;
index_in++;
num_replacements++;
break;
} // end if
// was a strip char found?
if (sindex >= slength)
string_out[index_out++] = string_in[index_in++];
} // end while
} // end if case_off
// terminate output string
string_out[index_out] = 0;
// return extracts
return(num_replacements);
} // end ReplaceChars
//////////////////////////////////////////////////////////////////////////////////
int StripChars(char *string_in, char *string_out, char *strip_chars, int case_on)
{
// this function simply strips/extracts the characters from the input string that
// are listed in strip, the results are stored in string_out, string_in
// isn't touched, the number of extractions or returned
// if case_on = 1 then case is checked, other it's case insensitive
int num_extracts = 0, // tracks number of characters extracted
index_in = 0, // curr index into input
index_out = 0, // curr index into output
sindex, // loop var into strip array
slength = strlen(strip_chars); // length of strip string
// do some error checking
if (!string_in || !string_out || strlen(string_in) == 0)
return(0);
// nothing to replace
if (!strip_chars || strlen(strip_chars)==0)
{
strcpy(string_out, string_in);
return(0);
} // end if
// determine if case is importants
if (case_on==1)
{
// perform char by char copy
while(string_in[index_in])
{
for (sindex = 0; sindex < slength; sindex++)
if (string_in[index_in] == strip_chars[sindex])
{
// jump over input char, it's stripped
index_in++;
num_extracts++;
break;
} // end if
// was a strip char found?
if (sindex >= slength)
string_out[index_out++] = string_in[index_in++];
} // end while
} // end if case_on
else
{
// perform char by char copy with case insensitivity
while(string_in[index_in])
{
for (sindex = 0; sindex < slength; sindex++)
if (toupper(string_in[index_in]) == toupper(strip_chars[sindex]))
{
// jump over input char, it's stripped
index_in++;
num_extracts++;
break;
} // end if
// was a strip char found?
if (sindex >= slength)
string_out[index_out++] = string_in[index_in++];
} // end while
} // end if case_off
// terminate output string
string_out[index_out] = 0;
// return extracts
return(num_extracts);
} // end StripChars
////////////////////////////////////////////////////////////////////////////
int IsInt(char *istring)
{
// validates the sent string as a int and converts it, if it's not valid
// the function sends back INT_MIN, the chances of this being the number
// validated is slim
// [whitespace] [sign]digits
char *string = istring;
// must be of the form
// [whitespace]
while(isspace(*string)) string++;
// [sign]
if (*string=='+' || *string=='-') string++;
// [digits]
while(isdigit(*string)) string++;
// the string better be the same size as the other one
if (strlen(istring) == (int)(string - istring))
return(atoi(istring));
else
return(INT_MIN);
} // end IsInt
//////////////////////////////////////////////////////////////////////////////
float IsFloat(char *fstring)
{
// validates the sent string as a float and converts it, if it's not valid
// the function sends back FLT_MIN, the chances of this being the number
// validated is slim
// [whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits]
char *string = fstring;
// must be of the form
// [whitespace]
while(isspace(*string)) string++;
// [sign]
if (*string=='+' || *string=='-') string++;
// [digits]
while(isdigit(*string)) string++;
// [.digits]
if (*string =='.')
{
string++;
while(isdigit(*string)) string++;
}
// [ {d | D | e | E }[sign]digits]
if (*string =='e' || *string == 'E' || *string =='d' || *string == 'D')
{
string++;
// [sign]
if (*string=='+' || *string=='-') string++;
// [digits]
while(isdigit(*string)) string++;
}
// the string better be the same size as the other one
if (strlen(fstring) == (int)(string - fstring))
return(atof(fstring));
else
return(FLT_MIN);
} // end IsFloat
////////////////////////////////////////////////////////////////////////////
char *StringRtrim(char *string)
{
// trims whitespace from right side, note is destructive
int sindex = 0;
int slength = strlen(string);
if (!string || slength == 0) return(string);
// index to end of string
sindex = slength - 1;
// trim whitespace by overwriting nulls
while( isspace(string[sindex]) && sindex >= 0)
string[sindex--] = 0;
// string doens't need to be moved, so simply return pointer
return(string);
} // end StringRtrim
////////////////////////////////////////////////////////////////////////////
char *StringLtrim(char *string)
{
// trims whitespace from left side, note is destructive
int sindex = 0;
int slength = strlen(string);
if (!string || slength == 0) return(string);
// trim whitespace by advancing pointer
while(isspace(string[sindex]) && sindex < slength)
string[sindex++] = 0; // not needed actually
// copy string to left
memmove((void *)string, (void *)&string[sindex], (slength - sindex)+1);
// now return pointer
return(string);
} // end StringLtrim
////////////////////////////////////////////////////////////////////////////
int Convert_Bitmap_8_16(BITMAP_FILE_PTR bitmap)
{
// function converts a bitmap from 8 bit to 16 bit based on the palette
// and the current bitformat
// is this a valid bitmap file?
if (!bitmap || !bitmap->buffer)
return(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -