Ejemplo n.º 1
0
int strout(char *str)
{
	if (str) {
		textio_print_string(str);
		return os_string_length(str);
	} else {
		return -1;
	}
}
Ejemplo n.º 2
0
void GlkInterface::smartstatusline() {
	zchar packed[256];
	uint32 buf[256];
	zchar *a, *b, *c, *d;
	int roomlen, scorelen, scoreofs;
	int len, tmp;

	packspaces(statusline, packed);
	len = os_string_length(packed);

	a = packed;
	while (a[0] == ' ')
		a++;

	b = a;
	while (b[0] != 0 && !(b[0] == ' ' && b[1] == ' '))
		b++;

	c = b;
	while (c[0] == ' ')
		c++;

	d = packed + len - 1;
	while (d[0] == ' ' && d > c)
		d--;
	if (d[0] != ' ' && d[0] != 0)
		d++;
	if (d < c)
		d = c;

	roomlen = b - a;
	scorelen = d - c;
	scoreofs = h_screen_cols - scorelen - 2;
	if (scoreofs <= roomlen)
		scoreofs = roomlen + 2;

	for (tmp = 0; tmp < h_screen_cols; tmp++)
		buf[tmp] = ' ';

	memcpy(buf + 1 + scoreofs, c, scorelen * sizeof(zchar));
	memcpy(buf + 1, a, roomlen * sizeof(zchar));

	glk_window_move_cursor(gos_upper, 0, 0);
	glk_put_buffer_uni(buf, h_screen_cols);
	glk_window_move_cursor(gos_upper, cury - 1, curx - 1);
}
Ejemplo n.º 3
0
zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued)
{
	event_t ev;
	winid_t win = gos_curwin ? gos_curwin : gos_lower;

	if (!continued && gos_linepending)
		gos_cancel_pending_line(); 

	if (!continued || !gos_linepending)
	{
		glk_request_line_event_uni(win, buf, max, os_string_length(buf));
		if (timeout != 0)
			glk_request_timer_events(timeout * 100);
	}

	gos_linepending = 0;

	while (1)
	{
		glk_select(&ev);
		if (ev.type == evtype_Arrange) {
			gos_update_height();
			gos_update_width();
		}
		else if (ev.type == evtype_Timer)
		{
			gos_linewin = win;
			gos_linepending = 1;
			gos_linebuf = buf;
			return ZC_TIME_OUT;
		}
		else if (ev.type == evtype_LineInput)
			break;
	}

	glk_request_timer_events(0);
	buf[ev.val1] = '\0';

	if (gos_upper && mach_status_ht < curr_status_ht)
		reset_status_ht();
	curr_status_ht = 0;

	return ZC_RETURN;
}
Ejemplo n.º 4
0
int puts(char *str)
{
	os_print_string(str);
	os_print_newline();
	return os_string_length(str);
}
Ejemplo n.º 5
0
int printf(char *fmt, ...)
{
	int i = 0;
	int printed = 0;
	char *arg = (char*)&fmt + sizeof(char*);
	char *str;

	if (fmt[0] == '\0') {
		return 0;
	}

	do {
		if (fmt[i] == '\n') {
			os_print_newline();
			printed += 2;
			continue;
		} else if (fmt[i] != '%') {
			os_print_char(fmt[i]);
			printed++;
			continue;
		}

		switch (fmt[++i]) {
			case 'd':
			case 'i':
				str = os_sint_to_string(*(int*)arg);
				printed += os_string_length(str);
				os_print_string(str);
				arg += sizeof(int);
				break;

			case 'u':
				str = os_int_to_string(*(int*)arg);
				printed += os_string_length(str);
				os_print_string(str);
				arg += sizeof(int);
				break;

			case 'x':
			case 'X':
				os_print_4hex(*(int*)arg);
				printed += 4;
				arg += sizeof(int);
				break;

			case 'c':
				os_print_char(*arg);
				printed++;
				arg += sizeof(int);
				break;

			case 's':
				str = *(char**)arg;
				printed += os_string_length(str);
				os_print_string(str);
				arg += sizeof(char*);
				break;

			case 'p':
				os_print_string("0x");
				os_print_4hex(*(int*)arg);
				printed += 6;
				arg += sizeof(int);
				break;

			case 'n':
				*(int*)arg = printed;
				arg += sizeof(int*);
				break;

			case '%':
				os_print_char('%');
				printed++;
				break;
		}

	} while (fmt[++i]);

	return printed;
}