예제 #1
0
파일: snprintf.c 프로젝트: dagwieers/op
/** print %c */
static void
print_char(char **at, size_t * left, int *ret, int c, int minw, int minus)
{
    if (1 < minw && !minus)
	print_pad(at, left, ret, ' ', minw - 1);
    print_pad(at, left, ret, c, 1);
    if (1 < minw && minus)
	print_pad(at, left, ret, ' ', minw - 1);
}
예제 #2
0
파일: snprintf.c 프로젝트: dagwieers/op
/** print %s */
static void
print_str(char **at, size_t * left, int *ret, char *s,
	  int minw, int precision, int prgiven, int minus)
{
    int w;
    /* with prec: no more than x characters from this string, stop at 0 */
    if (prgiven)
	w = my_strnlen(s, precision);
    else
	w = (int)strlen(s);	/* up to the nul */
    if (w < minw && !minus)
	print_pad(at, left, ret, ' ', minw - w);
    spool_str(at, left, ret, s, w);
    if (w < minw && minus)
	print_pad(at, left, ret, ' ', minw - w);
}
예제 #3
0
void    print_memory(const void *addr, size_t size)
{
	unsigned char	*ptr;
	int				i = 0;
	int				count_pass;
	int				tcpt;

	ptr = (unsigned char *)addr;
	while (i < (int)size)
	{
		count_pass = 0;
		tcpt = i;
		while (tcpt < (int)size && count_pass < 16)
		{
			print_hex(ptr[tcpt]);
			tcpt++;
			count_pass++;
			if (tcpt < (int)size)
			{
				print_hex(ptr[tcpt]);
				count_pass++;
				tcpt++;
			}
			write(1, " ", 1);
		}
		print_pad(calc_pad(count_pass));
		count_pass = 0;
		tcpt = i;
		while (tcpt < (int)size && count_pass < 16)
		{
			print_ascii(ptr[tcpt]);
			count_pass++;
			tcpt++;
		}
		write(1, "\n", 1);
		i += count_pass;
	}
}
예제 #4
0
파일: subpad.c 프로젝트: altofctl/ctlpad
int main()
{
	int v = 50;
	int c;
	WINDOW *sub_pad;

	initscr();
	cbreak();
	noecho();
	curs_set(0);

	keypad(stdscr, TRUE);

	mvprintw(1, 5, "sub_pad test");
	refresh();
	sub_pad = newwin(3, 56, 4, 10);
	box(sub_pad, 0, 0);
	print_pad(sub_pad, v);

	while((c = getch()) != 'q')
	{
		switch(c)
		{
			case KEY_LEFT:
				if(v > 0) --v;
				break;
			case KEY_RIGHT:
				if(v < 100) ++v;
				break;
			case '0':
				v = 0;
				break;
			case '1':
				v = 10;
				break;
			case '2':
				v = 20;
				break;
			case '3':
				v = 30;
				break;
			case '4':
				v = 40;
				break;
			case '5':
				v = 50;
				break;
			case '6':
				v = 60;
				break;
			case '7':
				v = 70;
				break;
			case '8':
				v = 80;
				break;
			case '9':
				v = 90;
				break;
			default:
				mvprintw(2, 5, "Key pressed '%c'", c);
				refresh();
				break;
		}
		print_pad(sub_pad, v);
	}

	getch();
	endwin();
	return 0;
}
예제 #5
0
파일: snprintf.c 프로젝트: dagwieers/op
/** print number formatted */
static void
print_num(char **at, size_t * left, int *ret, int minw, int precision,
	  int prgiven, int zeropad, int minus, int plus, int space,
	  int zero, int negative, char *buf, int len)
{
    int w = len;		/* excludes minus sign */
    char s = get_negsign(negative, plus, space);
    if (minus) {
	/* left adjust the number into the field, space padding */
	/* calc numw = [sign][zeroes][number] */
	int numw = w;
	if (precision == 0 && zero)
	    numw = 0;
	if (numw < precision)
	    numw = precision;
	if (s)
	    numw++;

	/* sign */
	if (s)
	    print_pad(at, left, ret, s, 1);

	/* number */
	if (precision == 0 && zero) {
	    /* "" for the number */
	} else {
	    if (w < precision)
		print_pad(at, left, ret, '0', precision - w);
	    spool_str_rev(at, left, ret, buf, len);
	}
	/* spaces */
	if (numw < minw)
	    print_pad(at, left, ret, ' ', minw - numw);
    } else {
	/* pad on the left of the number */
	/* calculate numw has width of [sign][zeroes][number] */
	int numw = w;
	if (precision == 0 && zero)
	    numw = 0;
	if (numw < precision)
	    numw = precision;
	if (!prgiven && zeropad && numw < minw)
	    numw = minw;
	else if (s)
	    numw++;

	/* pad with spaces */
	if (numw < minw)
	    print_pad(at, left, ret, ' ', minw - numw);
	/* print sign (and one less zeropad if so) */
	if (s) {
	    print_pad(at, left, ret, s, 1);
	    numw--;
	}
	/* pad with zeroes */
	if (w < numw)
	    print_pad(at, left, ret, '0', numw - w);
	if (precision == 0 && zero)
	    return;
	/* print the characters for the value */
	spool_str_rev(at, left, ret, buf, len);
    }
}