/* Send the whole thing to the player. */
static char *newDesc;
newDesc = str_dup( output );
return newDesc;
}
while( *desc != ':' )
{
if( *desc == '\0' )
{
log_printf( "Error: tag has no parser ':'. Room: %d.", m_InRoom->vnum );
*common = *desc;
break;
}
*common = *desc;
*++common = '\0';
++desc;
}
/* Skip the colon and space ': '. */
desc += 2;
# Description:
# [#season summer: You are standing within the expanse of the famous Darkhaven Square. A
# stone statue of occupies the square's center, surrounded by gardens of
# flowers in full bloom which enhance the air of serenity and peace here in
# the center of the city. The main road lead away in the cardinal directions, while
# to the northeast and northwest are forested paths. The spires of a
# cathedral can be seen rising to the northwest.]
# [#season spring: You are standing within the expanse of the famous Darkhaven Square. A
# stone statue of occupies the square's center, surrounded by gardens of
# budding flowers which fill the air with lovely fragrances here in the center
# of the city. The main road lead away in the cardinal directions, while
# to the northeast and northwest are forested paths. The spires of a
# cathedral can be seen rising to the northwest.]
# [#season fall: You are standing within the expanse of the famous Darkhaven Square. A
# stone statue of occupies the square's center, surrounded by gardens of
# wilting flowers as winter fast approaches here in the center of the city.
# The main road lead away in the cardinal directions, while to the northeast
# and northwest are forested paths of many color falling leaves. The spires of a
# cathedral can be seen rising to the northwest.]
# [#season winter: You are standing within the frigid expanse of the famous Darkhaven
# Square. A stone statue of occupies the square's center, surrounded by an army
# of snowmen the children of the city have built here in the center of the city.
# The main roads have been cleared away in the cardinal directions, while
# to the northeast and northwest are forested paths which are still lightly covered
# in snow. The spires of a cathedral can be seen rising to the northwest.]
You are [#position] within the [#season winter: frigid] expanse of the famous Darkhaven
Square. A stone statue of something occupies the square's center, surrounded by
[#season summer: gardens of flowers in full bloom which enhance the air of serenity and peace]
[#season spring: gardens of budding flowers which fill the air with lovely fragrances]
[#season fall: gardens of wilting flowers as winter fast approaches]
[#season winter: an army of snowmen the children of the city have built]
here in the center of the city. The main road lead away in the cardinal directions, while to
the northeast and northwest are forested paths
[#season fall: of many color falling leaves]
[#season winter: which are still lightly covered in snow]
. The spires of a cathedral can be seen rising to the northwest.
..InsertionTag.h..
class InsertionTag {
char *varName; // position
InsertionTag(char *name);
replaceInStr(char *string, char *varValue);
};
.. InsertionTag.c ..
InsertionTag::InsertionTag(char *name){
varName = name;
}
void InsertionTag::replaceInStr(char *string, char *varValue){
//varValue would be the actual position, such as standing or sitting.
//string is the entire room text
replace(string, varName, varValue); //using th function from
//http://bytes.com/groups/c/223500-how-rep...
}
class ConditionalTag::InsertionTag{
char *conditionMatch; // value of the variable to match, eg winter, summer, whatever
char *replacement; // value of the replacement text, eg "leaves are falling down on the floor"
ConditionalTag(char *name, char *conditionMatch, char *replacement);
void replaceInStr(char *string, char *varValue);
};
.. ConditionalTag.h..
ConditionalTag::ConditionalTag(char * name, char *match, char *replace){
name = strcpy(name);
conditionMatch = strcpy(match);
replacement= strcpy(replace);
}
void ConditionalTag::replaceInStr(char *string, char *varValue){
//find in string, replace occurance with replacement
InsertionTag parent = ((InsertionTag)*this);
if(varValue == conditionMatch){
// not sure this is right, basically want to call parent classes functionality. you could just replicate the call tho
parent->replaceInStr(string, strcat(varName, strcat(strcat(":", name), replacement), replacement);
}else{
// remove the text and tag, we are not wanted
parent->replaceInStr(string, strcat(varName, strcat(strcat(":", name), replacement), "");
}
}
struct parse_part_t {
int type; /* literal, variable, condition */
const char* string; /* literal value or variable name */
int op; /* operator */
const char* compare; /* value for comparisons */
};
// very C-like pseudo code
do {
// find beginning of tag
delim = strstr(input, "[#");
// append output from before tag
if (delim != input)
append_to_output(&output, input, delim - input);
// expect a name token
get_token(&input, &token);
if (token.type != TNAME) {
// display error however you want
return;
}
variable_name = token.string;
// check to see if we have an operator
get_token(&input, &token);
if (token.type == TOP) {
operator = token.operator;
// get a comparison value
get_token(&input, &token);
if (token.type != TNAME && token.type != TNUMBER) {
// parse error
return;
}
comparison_value = token.string;
// we now expact a : token
get_token(&input, &token);
if (token.type != TCOLON) {
// parse error
return;
}
// find the end of the data, which is at the first ]
end_marker = strchr(input, ']');
if (end_marker == NULL) {
// parse error
return;
}
// do the comparison; if true, we print the data following the : until the first ], otherwise we ignore it
if (do_comparison(variable_name, op, comparison_value) == TRUE) {
add_output(input, end_marker - input);
}
// set the input to point to just after the ]
input = end_marker + 1;
// no operator, so we expect a closing bracket ]
} else if (token.type == TEND) {
// evaluate the variable into the output
eval_variable_to_output(&output, variable_name);
// not an operator and not a closing bracket… parse error
} else {
// report parse error
return;
}
} while (delim != NULL);
// append remaining input
append_to_output(&output, input, strlen(input));
get_token {
skip_whitespace;
if (*input == 0)
return token TEOF;
if (isdigit(*input)) {
copy_digits;
return token TNUMBER;
} else if (isalpha(*input)) {
copy_alpha;
return token TNAME;
} else if (*input == ':') {
return token TCOLON;
} else if (*input == ']') {
return token TEND;
} else {
return token TUNKNOWN;
}
}