const char * fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen) { size_t len; char *ap, *cp; if (argv == NULL || argv[0] == NULL) { if (cmd == NULL) return (""); ap = NULL; len = maxlen + 3; } else { ap = shquote(argv); len = strlen(ap) + maxlen + 4; } cp = malloc(len); if (cp == NULL) errx(1, "malloc failed"); if (ap == NULL) { if (thread != NULL) { asprintf(&ap, "%s/%s", cmd, thread); sprintf(cp, "[%.*s]", (int)maxlen, ap); free(ap); } else sprintf(cp, "[%.*s]", (int)maxlen, cmd); } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); else strcpy(cp, ap); return (cp); }
const char * fmt_argv(char **argv, char *cmd, size_t maxlen) { size_t len; char *ap, *cp; if (argv == NULL || argv[0] == NULL) { if (cmd == NULL) return (""); ap = NULL; len = maxlen + 3; } else { ap = shquote(argv); len = strlen(ap) + maxlen + 4; } cp = malloc(len); if (cp == NULL) return (NULL); if (ap == NULL) sprintf(cp, " (%.*s)", (int)maxlen, cmd); else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); else (void) strcpy(cp, ap); return (cp); }
void command(const struct kinfo_proc *kp, VARENT *ve) { VAR *v; int left, wantspace = 0; char **argv, **p; /* * Determine the available number of display columns. * Always decrement and check after writing. * No check is needed before mbswprint() * and after writing the last data, though. */ 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 = INT_MAX; if (needenv && kd != NULL) { argv = kvm_getenvv(kd, kp, termwidth); if ((p = argv) != NULL) { while (*p) { if (wantspace) { putchar(' '); left--; } left -= mbswprint(*p, left, 0); if (left == 0) return; p++; wantspace = 1; } } } else argv = NULL; if (needcomm) { if (!commandonly) { if (kd != NULL) { argv = kvm_getargv(kd, kp, termwidth); if ((p = argv) != NULL) { while (*p) { if (wantspace) { putchar(' '); left--; } left -= mbswprint(*p, left, 0); if (left == 0) return; p++; wantspace = 1; } } } if (argv == NULL || argv[0] == '\0' || strcmp(cmdpart(argv[0]), kp->p_comm)) { if (wantspace) { putchar(' '); if (--left == 0) return; } putchar('('); left--; left -= mbswprint(kp->p_comm, left, 0); if (left == 0) return; putchar(')'); left--; } } else { if (wantspace) { putchar(' '); left--; } left -= mbswprint(kp->p_comm, left, 0); } } if (ve->next != NULL) while (left-- > 0) putchar(' '); }
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, ""); } }