fmt.c (50471) | fmt.c (89575) |
---|---|
1/*- 2 * Copyright (c) 1992, 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 --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94"; 37#endif 38static const char rcsid[] = | 1/*- 2 * Copyright (c) 1992, 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 --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94"; 37#endif 38static const char rcsid[] = |
39 "$FreeBSD: head/bin/ps/fmt.c 50471 1999-08-27 23:15:48Z peter $"; | 39 "$FreeBSD: head/bin/ps/fmt.c 89575 2002-01-20 01:30:40Z mikeh $"; |
40#endif /* not lint */ 41 42#include <sys/types.h> 43#include <sys/time.h> 44#include <sys/resource.h> 45#include <err.h> 46#include <stdio.h> 47#include <stdlib.h> --- 8 unchanged lines hidden (view full) --- 56/* 57 * XXX 58 * This is a stub until marc does the real one. 59 */ 60static char * 61shquote(argv) 62 char **argv; 63{ | 40#endif /* not lint */ 41 42#include <sys/types.h> 43#include <sys/time.h> 44#include <sys/resource.h> 45#include <err.h> 46#include <stdio.h> 47#include <stdlib.h> --- 8 unchanged lines hidden (view full) --- 56/* 57 * XXX 58 * This is a stub until marc does the real one. 59 */ 60static char * 61shquote(argv) 62 char **argv; 63{ |
64 long arg_max; | 64 static long arg_max = -1; 65 long len; |
65 char **p, *dst, *src; 66 static char *buf = NULL; 67 68 if (buf == NULL) { 69 if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) 70 errx(1, "sysconf _SC_ARG_MAX failed"); 71 if ((buf = malloc((4 * arg_max) + 1)) == NULL) 72 errx(1, "malloc failed"); 73 } 74 75 if (*argv == 0) { 76 buf[0] = 0; 77 return (buf); 78 } 79 dst = buf; 80 for (p = argv; (src = *p++) != 0; ) { 81 if (*src == 0) 82 continue; | 66 char **p, *dst, *src; 67 static char *buf = NULL; 68 69 if (buf == NULL) { 70 if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) 71 errx(1, "sysconf _SC_ARG_MAX failed"); 72 if ((buf = malloc((4 * arg_max) + 1)) == NULL) 73 errx(1, "malloc failed"); 74 } 75 76 if (*argv == 0) { 77 buf[0] = 0; 78 return (buf); 79 } 80 dst = buf; 81 for (p = argv; (src = *p++) != 0; ) { 82 if (*src == 0) 83 continue; |
83 strvis(dst, src, VIS_NL | VIS_CSTYLE); | 84 len = (4 * arg_max - (dst - buf)) / 4; 85 strvisx(dst, src, strlen(src) < len ? strlen(src) : len, 86 VIS_NL | VIS_CSTYLE); |
84 while (*dst) 85 dst++; | 87 while (*dst) 88 dst++; |
86 *dst++ = ' '; | 89 if ((4 * arg_max - (dst - buf)) / 4 > 0) 90 *dst++ = ' '; |
87 } 88 /* Chop off trailing space */ | 91 } 92 /* Chop off trailing space */ |
89 if (dst != buf) | 93 if (dst != buf && dst[-1] == ' ') |
90 dst--; 91 *dst = '\0'; 92 return (buf); 93} 94 95static char * 96cmdpart(arg0) 97 char *arg0; --- 34 unchanged lines hidden --- | 94 dst--; 95 *dst = '\0'; 96 return (buf); 97} 98 99static char * 100cmdpart(arg0) 101 char *arg0; --- 34 unchanged lines hidden --- |