git: fd6b81712eb9 - main - ps(1): Constify the format strings for canned displays
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 28 Apr 2025 12:23:29 UTC
The branch main has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=fd6b81712eb9a77bbe484954d18fe1fc4a27116b
commit fd6b81712eb9a77bbe484954d18fe1fc4a27116b
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-04-01 12:50:26 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-04-28 11:58:14 +0000
ps(1): Constify the format strings for canned displays
Now that removal of non-explicitly-requested duplicate columns work with
a O(n) algorithm, remove the ad-hoc optimization of crushing the canned
displays' formats after first use and constify their format strings.
No functional change intended.
This change could also be useful if/when allowing, e.g., to double
letters of canned displays to indicate their columns should not be
subject to automatic removal of duplicates (e.g., 'ps -ll').
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49614
---
bin/ps/ps.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index ccbe40bbbc45..0a4a289a6a63 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -147,16 +147,16 @@ static void remove_redundant_columns(struct keyword_info *);
static void pidmax_init(void);
static void usage(void);
-static char dfmt[] = "pid,tt,state,time,command";
-static char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command";
-static char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state,"
- "tt,time,command";
-static char o1[] = "pid";
-static char o2[] = "tt,state,time,command";
-static char ufmt[] = "user,pid,%cpu,%mem,vsz,rss,tt,state,start,time,command";
-static char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz,"
- "%cpu,%mem,command";
-static char Zfmt[] = "label";
+static const char dfmt[] = "pid,tt,state,time,command";
+static const char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command";
+static const char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state,"
+ "tt,time,command";
+static const char o1[] = "pid";
+static const char o2[] = "tt,state,time,command";
+static const char ufmt[] = "user,pid,%cpu,%mem,vsz,rss,tt,state,start,time,command";
+static const char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz,"
+ "%cpu,%mem,command";
+static const char Zfmt[] = "label";
#define PS_ARGS "AaCcD:defG:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ"
@@ -316,7 +316,6 @@ main(int argc, char *argv[])
case 'j':
parsefmt(jfmt, &varlist, 0);
_fmt = 1;
- jfmt[0] = '\0';
break;
case 'L':
showkey();
@@ -324,7 +323,6 @@ main(int argc, char *argv[])
case 'l':
parsefmt(lfmt, &varlist, 0);
_fmt = 1;
- lfmt[0] = '\0';
break;
case 'M':
memf = optarg;
@@ -339,7 +337,6 @@ main(int argc, char *argv[])
parsefmt(o1, &varlist, 1);
parsefmt(optarg, &varlist, 1);
parsefmt(o2, &varlist, 1);
- o1[0] = o2[0] = '\0';
_fmt = 1;
break;
case 'o':
@@ -408,13 +405,11 @@ main(int argc, char *argv[])
parsefmt(ufmt, &varlist, 0);
sortby = SORTCPU;
_fmt = 1;
- ufmt[0] = '\0';
break;
case 'v':
parsefmt(vfmt, &varlist, 0);
sortby = SORTMEM;
_fmt = 1;
- vfmt[0] = '\0';
break;
case 'w':
if (wflag)
@@ -442,7 +437,6 @@ main(int argc, char *argv[])
break;
case 'Z':
parsefmt(Zfmt, &varlist, 0);
- Zfmt[0] = '\0';
break;
case '?':
default: