Deleted Added
full compact
fmt.c (130897) fmt.c (245610)
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

--- 20 unchanged lines hidden (view full) ---

29
30#if 0
31#ifndef lint
32static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94";
33#endif
34#endif
35
36#include <sys/cdefs.h>
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

--- 20 unchanged lines hidden (view full) ---

29
30#if 0
31#ifndef lint
32static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94";
33#endif
34#endif
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/bin/ps/fmt.c 130897 2004-06-22 02:18:29Z gad $");
37__FBSDID("$FreeBSD: head/bin/ps/fmt.c 245610 2013-01-18 18:24:40Z jhb $");
38
39#include <sys/types.h>
40#include <sys/time.h>
41#include <sys/resource.h>
42
43#include <err.h>
44#include <limits.h>
45#include <stdio.h>

--- 54 unchanged lines hidden (view full) ---

100cmdpart(char *arg0)
101{
102 char *cp;
103
104 return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
105}
106
107const char *
38
39#include <sys/types.h>
40#include <sys/time.h>
41#include <sys/resource.h>
42
43#include <err.h>
44#include <limits.h>
45#include <stdio.h>

--- 54 unchanged lines hidden (view full) ---

100cmdpart(char *arg0)
101{
102 char *cp;
103
104 return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
105}
106
107const char *
108fmt_argv(char **argv, char *cmd, size_t maxlen)
108fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen)
109{
110 size_t len;
111 char *ap, *cp;
112
113 if (argv == NULL || argv[0] == NULL) {
114 if (cmd == NULL)
115 return ("");
116 ap = NULL;
117 len = maxlen + 3;
118 } else {
119 ap = shquote(argv);
120 len = strlen(ap) + maxlen + 4;
121 }
122 cp = malloc(len);
123 if (cp == NULL)
124 errx(1, "malloc failed");
109{
110 size_t len;
111 char *ap, *cp;
112
113 if (argv == NULL || argv[0] == NULL) {
114 if (cmd == NULL)
115 return ("");
116 ap = NULL;
117 len = maxlen + 3;
118 } else {
119 ap = shquote(argv);
120 len = strlen(ap) + maxlen + 4;
121 }
122 cp = malloc(len);
123 if (cp == NULL)
124 errx(1, "malloc failed");
125 if (ap == NULL)
126 sprintf(cp, "[%.*s]", (int)maxlen, cmd);
127 else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
125 if (ap == NULL) {
126 if (showthreads && thread != NULL) {
127 asprintf(&ap, "%s/%s", cmd, thread);
128 sprintf(cp, "[%.*s]", (int)maxlen, ap);
129 free(ap);
130 } else
131 sprintf(cp, "[%.*s]", (int)maxlen, cmd);
132 } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
128 sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
129 else
130 strcpy(cp, ap);
131 return (cp);
132}
133 sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
134 else
135 strcpy(cp, ap);
136 return (cp);
137}