void B_AppendToggleStateToString(ebstate_t state, ddstring_t* str) { if(state == EBTOG_UNDEFINED) Str_Append(str, "-undefined"); if(state == EBTOG_DOWN) Str_Append(str, "-down"); if(state == EBTOG_REPEAT) Str_Append(str, "-repeat"); if(state == EBTOG_PRESS) Str_Append(str, "-press"); if(state == EBTOG_UP) Str_Append(str, "-up"); }
char const *Str_GetLine(ddstring_t *str, char const *src) { DENG_ASSERT(str); if(!str) return 0; if(src != 0) { // We'll append the chars one by one. char buf[2]; memset(buf, 0, sizeof(buf)); for(Str_Clear(str); *src && *src != '\n'; src++) { if(*src != '\r') { buf[0] = *src; Str_Append(str, buf); } } // Strip whitespace around the line. Str_Strip(str); // The newline is excluded. if(*src == '\n') src++; } return src; }
ddstring_t *Str_AppendChar(ddstring_t *str, char ch) { char append[2]; append[0] = ch; append[1] = '\0'; return Str_Append(str, append); }
void B_AppendAnglePositionToString(float pos, ddstring_t* str) { if(pos < 0) Str_Append(str, "-center"); else Str_Appendf(str, "-angle%g", pos); }
/** * Does the opposite of the B_Parse* methods for event descriptor, including the * state conditions. */ void B_EventBindingToString(const evbinding_t* eb, ddstring_t* str) { int i; Str_Clear(str); B_AppendDeviceDescToString(eb->device, eb->type, eb->id, str); if(eb->type == E_TOGGLE) { B_AppendToggleStateToString(eb->state, str); } else if(eb->type == E_AXIS) { B_AppendAxisPositionToString(eb->state, eb->pos, str); } else if(eb->type == E_ANGLE) { B_AppendAnglePositionToString(eb->pos, str); } else if(eb->type == E_SYMBOLIC) { Str_Appendf(str, "-%s", eb->symbolicName); } // Append any state conditions. for(i = 0; i < eb->numConds; ++i) { Str_Append(str, " + "); B_AppendConditionToString(&eb->conds[i], str); } }
void B_AppendConditionToString(const statecondition_t* cond, ddstring_t* str) { if(cond->type == SCT_STATE) { if(cond->flags.multiplayer) { Str_Append(str, "multiplayer"); } } else if(cond->type == SCT_MODIFIER_STATE) { Str_Appendf(str, "modifier-%i", cond->id - CTL_MODIFIER_1 + 1); } else { B_AppendDeviceDescToString(cond->device, cond->type == SCT_TOGGLE_STATE? E_TOGGLE : cond->type == SCT_AXIS_BEYOND? E_AXIS : E_ANGLE, cond->id, str); } if(cond->type == SCT_TOGGLE_STATE || cond->type == SCT_MODIFIER_STATE) { B_AppendToggleStateToString(cond->state, str); } else if(cond->type == SCT_AXIS_BEYOND) { B_AppendAxisPositionToString(cond->state, cond->pos, str); } else if(cond->type == SCT_ANGLE_AT) { B_AppendAnglePositionToString(cond->pos, str); } // Flags. if(cond->flags.negate) { Str_Append(str, "-not"); } }
ddstring_t *Str_Appendf(ddstring_t *str, char const *format, ...) { DENG_ASSERT(str); if(!str) return 0; { char buf[4096]; va_list args; // Print the message into the buffer. va_start(args, format); dd_vsnprintf(buf, sizeof(buf), format, args); va_end(args); Str_Append(str, buf); return str; } }
virtual void invoke(int player, EventSequenceArg* args, int numArgs) { if(!strchr(Str_Text(&commandTemplate), '%')) { DD_Execute(true/*silent*/, Str_Text(&commandTemplate)); return; } // Compose the command from the template, inserting values for named arguments. /// @todo This logic should be extracted and made into an Str method. AutoStr* cmd = AutoStr_NewStd(); // Reserve an estimate of the composed command length. Str_Reserve(cmd, Str_Length(&commandTemplate) + numArgs + 1); int len = Str_Length(&commandTemplate); const char* start = Str_Text(&commandTemplate); const char* ch = start, *substart = start; while(ch + 1 < start + len) { if(ch[0] == '%' && ch[1] && ch[1] != '%') { Str_PartAppend(cmd, substart, 0, ch - substart); if(ch[1] == 'p') { Str_AppendChar(cmd, '0' + player); } else { int arg = ch[1] - '0' - 1; DENG_ASSERT(arg >= 0 && arg < 9); Str_AppendChar(cmd, char(args[arg])); } ch += 2; substart = ch; } else { ch++; } } // Add anything remaining. Str_Append(cmd, substart); DD_Execute(true/*silent*/, Str_Text(cmd)); }
void B_AppendDeviceDescToString(uint device, ddeventtype_t type, int id, ddstring_t* str) { inputdev_t* dev = I_GetDevice(device, false); const char* name; if(type != E_SYMBOLIC) { // Name of the device. Str_Append(str, dev->name); Str_Append(str, "-"); } switch(type) { case E_TOGGLE: if(dev->keys[id].name) { Str_Append(str, dev->keys[id].name); } else if(device == IDEV_KEYBOARD) { name = B_ShortNameForKey(id); if(name) Str_Append(str, name); else Str_Appendf(str, "code%03i", id); } else Str_Appendf(str, "button%i",id + 1); break; case E_AXIS: Str_Append(str, dev->axes[id].name); break; case E_ANGLE: Str_Appendf(str, "hat%i", id + 1); break; case E_SYMBOLIC: Str_Append(str, "sym"); break; default: Con_Error("B_AppendDeviceDescToString: Invalid value, type = %i.", (int) type); break; } }