Exemple #1
0
static void
fmt_simple_wrapper(fmt_code_info_t *arg) {
	void *a = va_arg(*arg->app, void *);
	simplefmt_t fn = arg->cl;
	char *str = fn(a);
	fmt_puts(str, strlen(str), arg);
}
Exemple #2
0
static void cvt_i(fmt_code_info_t *info) {
	char buf[32];
	u_int32_t addr = va_arg(*info->app, u_int32_t);
	struct in_addr ia;
	ia.s_addr = addr;
	fmt_sfmt(buf, sizeof(buf), "%s", inet_ntoa(ia)); 
	fmt_puts(buf, strlen(buf), info);
}
Exemple #3
0
static void
pr_args(struct kinfo_proc *kp)
{
	char **argv, *str;
	int left;

	if (kp == NULL)
		goto nothing;		/* XXX - can this happen? */
	left = argwidth;
	argv = kvm_getargv(kd, kp, argwidth+60);  /* +60 for ftpd snip */
	if (argv == NULL)
		goto nothing;

	if (*argv == NULL || **argv == '\0') {
		/* Process has zeroed argv[0], display executable name. */
		fmt_putc('(', &left);
		fmt_puts(kp->p_comm, &left);
		fmt_putc(')', &left);
	}
	while (*argv) {
		/*
		 * ftp argv[0] is in the following format:
		 * ftpd: HOSTNAME: [USER/PASS: ]CMD args (ftpd)
		 */
		if (strncmp(*argv, "ftpd:", 5) == 0) {
			if ((str = strchr(*argv + 5, ':')) != NULL)
				str = strchr(str + 1, ':');
			if (str != NULL) {
				if ((str[0] == ':') &&
				    isspace((unsigned char)str[1]))
					str += 2;
				fmt_puts(str, &left);
			} else
				fmt_puts(*argv, &left);
		} else
			fmt_puts(*argv, &left);
		argv++;
		fmt_putc(' ', &left);
	}
	return;
nothing:
	putchar('-');
}
Exemple #4
0
static void 
cvt_s  (fmt_code_info_t *info) {

	char *str = va_arg(*info->app, char *);
	int len;
	assert(str);

	len = strlen(str);
	if (info->prec != INT_MIN && info->prec < len)
	    len = info->prec;

	fmt_puts(str, len, info);

	return;
}
Exemple #5
0
static void cvt_E(fmt_code_info_t *info) {
	int errno = va_arg(*info->app, int);
	fmt_puts(strerror(errno), strlen(strerror(errno)), info);
}
Exemple #6
0
void
command(const struct kinfo_proc *kp, VARENT *ve)
{
	VAR *v;
	int left, wantspace = 0;
	char **argv, **p;

	v = ve->var;
	if (ve->next != NULL || termwidth != UNLIMITED) {
		if (ve->next == NULL) {
			left = termwidth - (totwidth - v->width);
			if (left < 1) /* already wrapped, just use std width */
				left = v->width;
		} else
			left = v->width;
	} else
		left = -1;
	if (needenv && kd != NULL) {
		argv = kvm_getenvv(kd, kp, termwidth);
		if ((p = argv) != NULL) {
			while (*p) {
				fmt_puts(*p, &left);
				p++;
				if (*p)
					fmt_putc(' ', &left);
				else
					wantspace = 1;
			}
		}
	} else
		argv = NULL;
	if (needcomm) {
		if (!commandonly) {
			if (kd != NULL) {
				argv = kvm_getargv(kd, kp, termwidth);
				if ((p = argv) != NULL) {
					if (wantspace) {
						fmt_putc(' ', &left);
						wantspace = 0;
					}
					while (*p) {
						fmt_puts(*p, &left);
						p++;
						if (*p)
							fmt_putc(' ', &left);
						else
							wantspace = 1;
					}
				}
			}
			if (argv == NULL || argv[0] == '\0' ||
			    strcmp(cmdpart(argv[0]), kp->p_comm)) {
				if (wantspace) {
					fmt_putc(' ', &left);
					wantspace = 0;
				}
				fmt_putc('(', &left);
				fmt_puts(kp->p_comm, &left);
				fmt_putc(')', &left);
			}
		} else {
			if (wantspace) {
				fmt_putc(' ', &left);
				wantspace = 0;
			}
			fmt_puts(kp->p_comm, &left);
		}
	}
	if (ve->next && left > 0) {
		if (wantspace) {
			fmt_putc(' ', &left);
			wantspace = 0;
		}
		printf("%*s", left, "");
	}
}
Exemple #7
0
static void cvt_s(int code, va_list *ap, int put(int c, void *cl), void *cl,
		unsigned char flags[], int width, int precision){
	char *str=va_arg(*ap, char *);
	assert(str);
	fmt_puts(str, strlen(str), put, cl, flags, width, precision);
}