print.c (189078) | print.c (192239) |
---|---|
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> | 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 189078 2009-02-26 18:01:07Z attilio $"); | 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) { | 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); |
|
133 (void)printf("%s", k->ki_p->ki_comm); 134 if (showthreads && k->ki_p->ki_numthreads > 1) | 135 (void)printf("%s", k->ki_p->ki_comm); 136 if (showthreads && k->ki_p->ki_numthreads > 1) |
135 printf("/%s", k->ki_p->ki_ocomm); | 137 (void)printf("/%s", k->ki_p->ki_ocomm); |
136 } else 137 (void)printf("%-*s", v->width, k->ki_p->ki_comm); 138 return; 139 } 140 if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) 141 errx(1, "malloc failed"); 142 strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); | 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); |
143 if (k->ki_env) { 144 if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL) 145 errx(1, "malloc failed"); 146 strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH); 147 } else 148 vis_env = NULL; | |
149 150 if (STAILQ_NEXT(ve, next_ve) == NULL) { 151 /* last field */ | 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 |
|
152 if (termwidth == UNLIMITED) { | 158 if (termwidth == UNLIMITED) { |
159 if (k->ki_d.prefix) 160 (void)printf("%s", k->ki_d.prefix); |
|
153 if (vis_env) 154 (void)printf("%s ", vis_env); 155 (void)printf("%s", vis_args); 156 } else { 157 left = termwidth - (totwidth - v->width); 158 if (left < 1) /* already wrapped, just use std width */ 159 left = v->width; | 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++); |
|
160 if ((cp = vis_env) != NULL) { 161 while (--left >= 0 && *cp) 162 (void)putchar(*cp++); 163 if (--left >= 0) 164 putchar(' '); 165 } 166 for (cp = vis_args; --left >= 0 && *cp != '\0';) 167 (void)putchar(*cp++); 168 } | 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); |
|
169 } else | 182 } else |
170 /* XXX env? */ | 183 /* ki_d.prefix & ki_env aren't shown for interim fields */ |
171 (void)printf("%-*.*s", v->width, v->width, vis_args); 172 free(vis_args); | 184 (void)printf("%-*.*s", v->width, v->width, vis_args); 185 free(vis_args); |
173 if (vis_env != NULL) 174 free(vis_env); | |
175} 176 177void 178ucomm(KINFO *k, VARENT *ve) 179{ 180 char tmpbuff[COMMLEN + OCOMMLEN + 2]; 181 VAR *v; 182 183 v = ve->var; 184 if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */ | 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); |
|
185 (void)printf("%s", k->ki_p->ki_comm); 186 if (showthreads && k->ki_p->ki_numthreads > 1) 187 printf("/%s", k->ki_p->ki_ocomm); 188 } else { 189 bzero(tmpbuff, sizeof(tmpbuff)); 190 if (showthreads && k->ki_p->ki_numthreads > 1) 191 sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm, 192 k->ki_p->ki_ocomm); --- 671 unchanged lines hidden --- | 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 --- |