Exemplo n.º 1
0
/**
 * Get the escape string for a given TTY color, empty string on non-tty FILE
 */
char* tty_escape_get(int fd, tty_escape_t escape)
{
	if (!isatty(fd))
	{
		return "";
	}
	switch (escape)
	{
		case TTY_RESET:
		case TTY_BOLD:
		case TTY_UNDERLINE:
		case TTY_BLINKING:
		case TTY_FG_BLACK:
		case TTY_FG_RED:
		case TTY_FG_GREEN:
		case TTY_FG_YELLOW:
		case TTY_FG_BLUE:
		case TTY_FG_MAGENTA:
		case TTY_FG_CYAN:
		case TTY_FG_WHITE:
		case TTY_FG_DEF:
		case TTY_BG_BLACK:
		case TTY_BG_RED:
		case TTY_BG_GREEN:
		case TTY_BG_YELLOW:
		case TTY_BG_BLUE:
		case TTY_BG_MAGENTA:
		case TTY_BG_CYAN:
		case TTY_BG_WHITE:
		case TTY_BG_DEF:
			return enum_to_name(tty_color_names, escape);
		/* warn if a excape code is missing */
	}
	return "";
}
Exemplo n.º 2
0
/**
 * See header.
 */
int enum_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
					 const void *const *args)
{
	enum_name_t *ed = *((enum_name_t**)(args[0]));
	int val = *((int*)(args[1]));
	char *name, buf[512];

	if (ed && ed->next == ENUM_FLAG_MAGIC)
	{
		name = enum_flags_to_string(ed, val, buf, sizeof(buf));
		if (name == NULL)
		{
			snprintf(buf, sizeof(buf), "(0x%X)", val);
			name = buf;
		}
	}
	else
	{
		name = enum_to_name(ed, val);
		if (name == NULL)
		{
			snprintf(buf, sizeof(buf), "(%d)", val);
			name = buf;
		}
	}
	if (spec->minus)
	{
		return print_in_hook(data, "%-*s", spec->width, name);
	}
	return print_in_hook(data, "%*s", spec->width, name);
}
Exemplo n.º 3
0
/**
 * \brief Saves the low-level keyboard command where the specified game key is
 * mapped.
 * \param command A game command.
 * \param keyboard_key The keyboard key to map to this game command in the
 * savegame.
 */
void GameCommands::set_saved_keyboard_binding(
    GameCommand command, InputEvent::KeyboardKey keyboard_key) {

  const std::string& savegame_variable = get_keyboard_binding_savegame_variable(command);
  const std::string& keyboard_key_name = enum_to_name(keyboard_key);
  get_savegame().set_string(savegame_variable, keyboard_key_name);
}
Exemplo n.º 4
0
/**
 * \brief Implementation of drawable:get_blend_mode().
 * \param l the Lua context that is calling this function
 * \return Number of values to return to Lua.
 */
int LuaContext::drawable_api_get_blend_mode(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    Drawable& drawable = *check_drawable(l, 1);

    BlendMode blend_mode = drawable.get_blend_mode();

    push_string(l, enum_to_name(blend_mode));

    return 1;
  });
}
Exemplo n.º 5
0
END_TEST

START_TEST(test_enum_to_name_split)
{
	char *str = enum_to_name(test_enum_split_names, name_tests_split[_i].val);
	if (str)
	{
		ck_assert_str_eq(str, name_tests_split[_i].str);
	}
	else
	{
		ck_assert(str == name_tests_split[_i].str);
	}
}
Exemplo n.º 6
0
/**
 * Described in header.
 */
int enum_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
					 const void *const *args)
{
	enum_name_t *ed = *((enum_name_t**)(args[0]));
	int val = *((int*)(args[1]));
	char *name, buf[32];

	name = enum_to_name(ed, val);
	if (name == NULL)
	{
		snprintf(buf, sizeof(buf), "(%d)", val);
		name = buf;
	}
	if (spec->minus)
	{
		return print_in_hook(data, "%-*s", spec->width, name);
	}
	return print_in_hook(data, "%*s", spec->width, name);
}
Exemplo n.º 7
0
/**
 * \brief Returns the name of the type of entity.
 * \return The type name of entity.
 */
const std::string& EntityData::get_type_name() const {
    return enum_to_name(get_type());
}