# include <config.h>
#endif
-#include <simgear/props/condition.hxx>
#include "HUD.hxx"
_mode = check_format(_format.c_str());
if (_mode == INVALID) {
- SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid format '" << _format.c_str() << '\'');
+ SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid format '" << _format.c_str()
+ << "' in <label> '" << _name << '\'');
_format = "INVALID";
_mode = NONE;
}
void HUD::Label::draw(void)
{
- if (!(_mode == NONE || _input.isValid() && blink()))
+ if (!(_mode == NONE || (_input.isValid() && blink())))
return;
if (_box) {
}
const int BUFSIZE = 256;
- char buf[BUFSIZE];
+ char buf[BUFSIZE+1];
+ buf[ BUFSIZE] = '\0'; // Be sure to terminate properly
if (_mode == NONE)
- snprintf(buf, BUFSIZE, _format.c_str());
+ snprintf(buf, BUFSIZE, _format.c_str(), 0);
else if (_mode == STRING)
snprintf(buf, BUFSIZE, _format.c_str(), _input.getStringValue());
else if (_mode == INT)
}
-// make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
-//
-HUD::Label::Format HUD::Label::check_format(const char *f) const
-{
- bool l = false;
- Format fmt = STRING;
-
- for (; *f; f++) {
- if (*f == '%') {
- if (f[1] == '%')
- f++;
- else
- break;
- }
- }
- if (*f++ != '%')
- return NONE;
- if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
- f++;
- while (*f && isdigit(*f))
- f++;
- if (*f == '.') {
- f++;
- while (*f && isdigit(*f))
- f++;
- }
- if (*f == 'l')
- l = true, f++;
-
- if (*f == 'd')
- fmt = l ? LONG : INT;
- else if (*f == 'f')
- fmt = l ? DOUBLE : FLOAT;
- else if (*f == 's') {
- if (l)
- return INVALID;
- fmt = STRING;
- } else
- return INVALID;
-
- for (++f; *f; f++) {
- if (*f == '%') {
- if (f[1] == '%')
- f++;
- else
- return INVALID;
- }
- }
- return fmt;
-}
-
-
bool HUD::Label::blink()
{
if (_blink_interval < 0.0f)