1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 30#if 0 31#ifndef lint 32static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; 33#endif /* not lint */ 34#endif 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/bin/ps/print.c 192239 2009-05-17 04:00:43Z brian $"); |
38 39#include <sys/param.h> 40#include <sys/time.h> 41#include <sys/resource.h> 42#include <sys/proc.h> 43#include <sys/stat.h> 44 45#include <sys/mac.h> --- 79 unchanged lines hidden (view full) --- 125 VAR *v; 126 int left; 127 char *cp, *vis_env, *vis_args; 128 129 v = ve->var; 130 if (cflag) { 131 /* If it is the last field, then don't pad */ 132 if (STAILQ_NEXT(ve, next_ve) == NULL) { |
133 if (k->ki_d.prefix) 134 (void)printf("%s", k->ki_d.prefix); |
135 (void)printf("%s", k->ki_p->ki_comm); 136 if (showthreads && k->ki_p->ki_numthreads > 1) |
137 (void)printf("/%s", k->ki_p->ki_ocomm); |
138 } else 139 (void)printf("%-*s", v->width, k->ki_p->ki_comm); 140 return; 141 } 142 if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) 143 errx(1, "malloc failed"); 144 strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); |
145 146 if (STAILQ_NEXT(ve, next_ve) == NULL) { 147 /* last field */ |
148 149 if (k->ki_env) { 150 if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) 151 == NULL) 152 errx(1, "malloc failed"); 153 strvis(vis_env, k->ki_env, 154 VIS_TAB | VIS_NL | VIS_NOSLASH); 155 } else 156 vis_env = NULL; 157 |
158 if (termwidth == UNLIMITED) { |
159 if (k->ki_d.prefix) 160 (void)printf("%s", k->ki_d.prefix); |
161 if (vis_env) 162 (void)printf("%s ", vis_env); 163 (void)printf("%s", vis_args); 164 } else { 165 left = termwidth - (totwidth - v->width); 166 if (left < 1) /* already wrapped, just use std width */ 167 left = v->width; |
168 if ((cp = k->ki_d.prefix) != NULL) 169 while (--left >= 0 && *cp) 170 (void)putchar(*cp++); |
171 if ((cp = vis_env) != NULL) { 172 while (--left >= 0 && *cp) 173 (void)putchar(*cp++); 174 if (--left >= 0) 175 putchar(' '); 176 } 177 for (cp = vis_args; --left >= 0 && *cp != '\0';) 178 (void)putchar(*cp++); 179 } |
180 if (vis_env != NULL) 181 free(vis_env); |
182 } else |
183 /* ki_d.prefix & ki_env aren't shown for interim fields */ |
184 (void)printf("%-*.*s", v->width, v->width, vis_args); 185 free(vis_args); |
186} 187 188void 189ucomm(KINFO *k, VARENT *ve) 190{ 191 char tmpbuff[COMMLEN + OCOMMLEN + 2]; 192 VAR *v; 193 194 v = ve->var; 195 if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */ |
196 if (k->ki_d.prefix) 197 (void)printf("%s", k->ki_d.prefix); |
198 (void)printf("%s", k->ki_p->ki_comm); 199 if (showthreads && k->ki_p->ki_numthreads > 1) 200 printf("/%s", k->ki_p->ki_ocomm); 201 } else { 202 bzero(tmpbuff, sizeof(tmpbuff)); 203 if (showthreads && k->ki_p->ki_numthreads > 1) 204 sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm, 205 k->ki_p->ki_ocomm); --- 671 unchanged lines hidden --- |