From 3d74b5c10650f07d510792f90ecaa4bcae1fd896 Mon Sep 17 00:00:00 2001
From: Miles Bader <miles@gnu.org>
Date: Thu, 17 Oct 1996 15:25:47 +0000
Subject: (psout):   Add TOP parameter.

---
 utils/psout.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

(limited to 'utils/psout.c')

diff --git a/utils/psout.c b/utils/psout.c
index 7f2b0591..805131f9 100644
--- a/utils/psout.c
+++ b/utils/psout.c
@@ -31,7 +31,8 @@ psout (struct proc_stat_list *procs,
        char *fmt_string, int posix_fmt, struct ps_fmt_specs *specs,
        char *sort_key_name, int sort_reverse,
        int output_width, int print_heading,
-       int squash_bogus_fields, int squash_nominal_fields)
+       int squash_bogus_fields, int squash_nominal_fields,
+       int top)
 {
   error_t err;
   struct ps_stream *output;
@@ -96,7 +97,7 @@ psout (struct proc_stat_list *procs,
     error (5, err, "Can't make output stream");
 
   if (print_heading)
-    if (proc_stat_list_num_procs (procs) > 0)
+    if (procs->num_procs > 0)
       {
 	err = ps_fmt_write_titles (fmt, output);
 	if (err)
@@ -117,6 +118,17 @@ psout (struct proc_stat_list *procs,
       ps_fmt_set_output_width (fmt, output_width);
     }
 
+  if (top)
+    /* Restrict output to the top TOP entries.  */
+    {
+      int remove = 0;
+      int filter (struct proc_stat *ps)
+	{
+	  return --top >= 0;
+	}
+      proc_stat_list_filter1 (procs, filter, 0, 0);
+    }
+
   /* Finally, output all the processes!  */
   err = proc_stat_list_fmt (procs, fmt, output);
   if (err)
-- 
cgit v1.2.3