Exemplo n.º 1
0
Arquivo: df.c Projeto: rovaughn/distro
static int
mnt_show(const char *fsname, const char *dir)
{
	struct statvfs s;
	unsigned long long total, used, avail;
	int capacity = 0;
	int bs;

	if (statvfs(dir, &s) < 0) {
		weprintf("statvfs %s:", dir);
		return -1;
	}

	bs = s.f_frsize / blksize;
	total = s.f_blocks * bs;
	avail = s.f_bfree * bs;
	used = total - avail;

	if (used + avail) {
		capacity = (used * 100) / (used + avail);
		if (used * 100 != capacity * (used + avail))
			capacity++;
	}

	if (hflag)
		print_human(fsname, total, used, avail, capacity, dir);
	else
		printf("%-12s %9llu %9llu %9llu %7d%%  %s\n",
		       fsname, total, used, avail, capacity, dir);

	return 0;
}
Exemplo n.º 2
0
void print(const struct params *prm, const struct usbmon_packet_1 *ep,
    const unsigned char *data)
{
	static uint64_t start_sec = 0;

	switch (par.format) {
	case TFMT_OLD:
		/*
		 * Old and new APIs are made compatible just so we
		 * can cast like this.
		 */
		print_48(&par, (struct usbmon_packet *) ep, data);
		break;
	case TFMT_1U:
		print_1u(&par, ep, data);
		break;
	default: /* TFMT_HUMAN */
		if (start_sec == 0)
			start_sec = ep->ts_sec;
		print_human(&par, ep, data, start_sec);
	}
}
Exemplo n.º 3
0
void
oneline(char *file)
{
	if (!init) {
		// delay loading of the seq until we need to scan the first
		// file, in case someone in the pipe updated the map before
		char *seq = blaze822_seq_open(0);
		blaze822_seq_load(seq);
		cur = blaze822_seq_cur();
		init = 1;
	}

	int indent = 0;
	while (*file == ' ' || *file == '\t') {
		indent++;
		file++;
	}

	struct message *msg = blaze822(file);
	char *flags = msg ? strstr(file, ":2,") : 0;
	if (!flags)
		flags = "";
	else
		flags += 3;

	int wleft = cols;

	char *f;
	for (f = fflag; *f; f++) {
		if (*f == '\\') {
			f++;
			switch (*f) {
			case 'n': putchar('\n'); wleft = cols; break;
			case 't': putchar('\t'); wleft -= (8 - wleft % 8); break;
			default:
				putchar('\\'); wleft--;
				putchar(*f); wleft--;
			}
			continue;
		}
		if (*f != '%') {
			putchar(*f);
			wleft--;
			continue;
		}
		f++;

		int w = 0;
		if ((*f >= '0' && *f <= '9') || *f == '-') {
			errno = 0;
			char *e;
			w = strtol(f, &e, 10);
			if (errno != 0)
				w = 0;
			else
				f = e;
		}

		if (!*f)
			break;

		switch (*f) {
		case '%':
			putchar('%');
			wleft--;
			break;
		case 'c':
			if (cur && strcmp(cur, file) == 0)
				putchar('>');
			else
				putchar(' ');
			wleft--;
			break;
		case 'u':  // unseen
			if (strchr(flags, 'T'))
				putchar('x');
			else if (strchr(flags, 'F'))
				putchar('*');
			else if (msg && !strchr(flags, 'S'))
				putchar('.');
			else
				putchar(' ');
			wleft--;
			break;
		case 'r':  // replied
			if (strchr(flags, 'R'))
				putchar('-');
			else if (strchr(flags, 'P'))
				putchar(':');
			else
				putchar(' ');
			wleft--;
			break;
		case 't':  // to-flag
			wleft -= printf("%s", fmt_to_flag(msg));
			break;
		case 'M':  // raw Maildir flags
			if (!w) w = -3;
			wleft -= printf("%*s", w, flags);
			break;
		case 'n':
			{
				long lineno = msg ? blaze822_seq_find(file) : 0;

				if (lineno)
					wleft -= printf("%*ld", w, lineno);
				else
					wleft -= printf("%*s", w, "");
			}
			break;
		case 'd':
		case 'D':
			if (!w) w = 10;
			wleft -= printf("%*s", w,
			    fmt_date(msg, w, Iflag || *f == 'D'));
			break;
		case 'f':
			if (w < 0)
				w += wleft;
			if (w)
				wleft -= u8putstr(stdout,
				    fmt_from(msg), w, 1);
			else
				wleft -= u8putstr(stdout,
				    fmt_from(msg), wleft, 0);
			break;
		case 'i':
			{
				int z;
				if (!w)
					w = 1;

				if (indent >= 10) {
					wleft -= printf("..%2d..", indent);
					indent = 10 - 6/w;
				}

				for (z = 0; z < w*indent; z++)
					putchar(' ');
				wleft -= w*indent;
			}
			break;
		case 's':
		case 'S':
			if (w < 0)
				w += wleft;
			if (w)
				wleft -= u8putstr(stdout,
				    fmt_subject(msg, file, *f == 'S'), w, 1);
			else
				wleft -= u8putstr(stdout,
				    fmt_subject(msg, file, *f == 'S'), wleft, 0);
			break;
		case 'b':
			{
				struct stat st;
				if (msg) {
					if (stat(file, &st) != 0)
						st.st_size = 0;
					wleft -= print_human(st.st_size, w);
				} else {
					wleft -= printf("%.*s", w, "");
				}
			}
			break;
		case 'F':
			{
				char *e = file + strlen(file);
				while (file < e && *e != '/')
					e--;
				e--;
				while (file < e && *e != '/')
					e--;
				while (file < e && *e == '/')
					e--;
				char *b = e;
				e++;
				while (file < b && *b != '/')
					b--;
				if (*b == '/')
					b++;
				if (*b == '.')
					b++;
				if (w) {
					if (w < 0)
						w = -w;
					wleft -= printf("%*.*s",
					    -w, (int)(e-b < w ? e-b : w), b);
				} else {
					wleft -= printf("%.*s", (int)(e-b), b);
				}
			}
			break;
		case 'R':
			if (w)
				wleft -= printf("%*.*s", w, w, file);
			else
				wleft -= printf("%s", file);
			break;
		case 'I':
			{
				char *m = msg ? blaze822_hdr(msg, "message-id") : 0;
				if (!m)
					m = "(unknown)";
				if (w)
					wleft -= printf("%*.*s", w, w, m);
				else
					wleft -= printf("%s", m);
			}
			break;
		default:
			putchar('%');
			putchar(*f);
			wleft -= 2;
		}
	}

	printf("\n");

	blaze822_free(msg);
}
Exemplo n.º 4
0
Arquivo: main.cpp Projeto: CCJY/coliru
void change_human(struct human h){
    strcpy(h.name, "Alice");    
    printf("age %d | name address %p | name: %s\n",h.age, h.name, h.name);
    print_human(h);
}