Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: [OMPI devel] [PATCH 4/4] opal-ps: function for printing dahsed line.
From: Bert Wesarg (bert.wesarg_at_[hidden])
Date: 2009-02-19 07:29:44


From: Bert Wesarg <Bert.Wesarg_at_[hidden]>

Provide a helper funtion to print a dashed line of variable length and use this
in the pretty_print* functions.

Regards,
Bert Wesarg

---
 orte/tools/orte-ps/orte-ps.c |   37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)
diff --quilt old/orte/tools/orte-ps/orte-ps.c new/orte/tools/orte-ps/orte-ps.c
--- old/orte/tools/orte-ps/orte-ps.c
+++ new/orte/tools/orte-ps/orte-ps.c
@@ -145,6 +145,7 @@ static int pretty_print(orte_ps_mpirun_i
 static int pretty_print_nodes(orte_node_t **nodes, orte_std_cntr_t num_nodes);
 static int pretty_print_jobs(orte_job_t **jobs, orte_std_cntr_t num_jobs);
 static int pretty_print_vpids(orte_job_t *job);
+static void pretty_print_dashed_line(int len);
 
 static char *pretty_node_state(orte_node_state_t state);
 static char *pretty_job_state(orte_job_state_t state);
@@ -390,17 +391,14 @@ static int pretty_print(orte_ps_mpirun_i
     int len_hdr, i;
     
     /*
-     * Print header
+     * Print header and remember header length
      */
     len_hdr = asprintf(&header, "Information from mpirun %s", ORTE_JOBID_PRINT(hnpinfo->hnp->name.jobid));
-    
     printf("\n\n%s\n", header);
     free(header);
-    for (i=0; i < len_hdr; i++) {
-        printf("%c", '-');
-    }
-    printf("\n");
-    
+
+    pretty_print_dashed_line(len_hdr);
+
     /*
      * Print Node Information
      */
@@ -465,10 +463,7 @@ static int pretty_print_nodes(orte_node_
     printf("%*s | ", len_slots_i, "Slots In Use");
     printf("\n");
 
-    for(i = 0; i < line_len; ++i) {
-        printf("-");
-    }
-    printf("\n");
+    pretty_print_dashed_line(line_len);
     
     /*
      * Print Info
@@ -565,10 +560,7 @@ static int pretty_print_jobs(orte_job_t 
 #endif
         printf("\n");
 
-        for(j = 0; j < line_len; ++j) {
-            printf("-");
-        }
-        printf("\n");
+        pretty_print_dashed_line(line_len);
 
         /*
          * Print Info
@@ -719,10 +711,7 @@ static int pretty_print_vpids(orte_job_t
     printf("\n");
     
     printf("\t");
-    for(i = 0; i < line_len; ++i) {
-        printf("-");
-    }
-    printf("\n");
+    pretty_print_dashed_line(line_len);
     
     /*
      * Print Info
@@ -771,6 +760,16 @@ static int pretty_print_vpids(orte_job_t
     return ORTE_SUCCESS;
 }
 
+static void pretty_print_dashed_line(int len) {
+    static const char dashes[8] = "--------";
+
+    while (len >= 8) {
+        printf("%8.8s", dashes);
+        len -= 8;
+    }
+    printf("%*.*s\n", len, len, dashes);
+}
+
 static int gather_information(orte_ps_mpirun_info_t *hnpinfo) {
     int ret;