Ejemplo n.º 1
0
/*
 * print_flag_set
 * Prints a set of flags which are set in an integer. The names and values of
 * the possible flags are taken from an array passed as the fourth argument.
 * All flags in the array are expected to be distinct, and non-zero.
 */
static char *
print_flag_set(char *buffer_start, char *c, long flags,
		const struct flag_desc *desc)
{
	bool is_zero = flags == 0;
	while (flags != 0 && desc->printable_name != NULL) {
		if (is_zero && desc->flag == 0)
			return print_flag(buffer_start, c,
						desc->printable_name);
		if ((flags & desc->flag) != 0) {
			c = print_flag(buffer_start, c, desc->printable_name);
			flags &= ~desc->flag;
		}
		desc++;
	}

	if (flags != 0) {
		if (c != buffer_start)
			c = print_cstr(c, " | ");
		c = print_hex(c, flags);
	}

	if (c == buffer_start)
		c = print_cstr(c, "0");

	return c;
}
Ejemplo n.º 2
0
/*
 * print_flag - appends a vertical bar separated list of strings with a
 * new one, returns a pointer to end of the resulting string.
 * The buffer_start argument is expected to point to the beginning of
 * the list (where no separator is needed), and the c argument is treated
 * as current iterator in the list.
 */
static char *
print_flag(char *buffer_start, char *c, const char *flag_name)
{
	if (c != buffer_start)
		c = print_cstr(c, " | ");

	return c = print_cstr(c, flag_name);
}
Ejemplo n.º 3
0
void z_read( zmachine *zm ) {
  zbyte max = read_byte( zm, zm->zargs[0] );
  zbyte size = read_byte( zm, zm->zargs[0] + 1 );

  VALUE line;

  int i;

  if( h_version(zm) < 5 ) {
    max -= 1;
    size = 0;
  }

  line = rb_funcall( keyboard(zm), id_read_line, 1, UINT2NUM(max - size) );

  for( i = 0; i < RSTRING_LEN(line); i++ ) {
    zchar c = *(RSTRING_PTR(line) + i);

    write_byte( zm, zm->zargs[0] + text_buffer_offset(zm) + size + i, 
      translate_to_zscii( zm->m, c ) );
  }

  if( h_version(zm) < 5 ) {
    write_byte( zm, zm->zargs[0] + text_buffer_offset(zm) + size + i, 0 );
  }

  if( h_version(zm) > 4 ) {
    write_byte( zm, zm->zargs[0] + 1, i );
  }

  /* write the parse table */

  if( zm->zargs[1] != 0 ) {
    write_parse_table( zm, line, zm->zargs[1], h_dictionary(zm), 0 );
  }

  /* echo the input back to the output */

  print_cstr( zm, "> " );
  print_rstr( zm, line );
  print_cstr( zm, "\n" );

  /* store the terminating character (if required) */

  if( h_version(zm) > 4 ) {
    p_store( zm, translate_to_zscii( zm->m, 10 ) );
  }
}
Ejemplo n.º 4
0
/*
 * print_hex - prints a 64 but value as a 16 digit hexadecimal number
 * If the number is zero, prints "(null)".
 */
static char *
print_pointer(char *c, long pointer)
{
	if (pointer == 0)
		return print_cstr(c, "(null)");

	*c++ = '0';
	*c++ = 'x';
	return print_number(c, (unsigned long)pointer, 16, 16);
}