This source file includes following definitions.
- orte_info_out
- orte_info_out_int
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "orte_config.h"
22
23 #include <stdio.h>
24 #include <string.h>
25 #ifdef HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #include <signal.h>
29 #ifdef HAVE_TERMIOS_H
30 #include <termios.h>
31 #endif
32 #ifdef HAVE_SYS_IOCTL_H
33 #include <sys/ioctl.h>
34 #endif
35 #include <ctype.h>
36
37 #include "orte/tools/orte-info/orte-info.h"
38
39 #include "opal/util/show_help.h"
40
41 #define OMPI_max(a,b) (((a) > (b)) ? (a) : (b))
42
43
44
45
46
47
48 static int centerpoint = 24;
49 static int screen_width = 78;
50
51
52
53
54 void orte_info_out(const char *pretty_message, const char *plain_message, const char *value)
55 {
56 size_t i, len, max_value_width;
57 char *spaces = NULL;
58 char *filler = NULL;
59 char *pos, *v, savev, *v_to_free;
60
61 #ifdef HAVE_ISATTY
62
63
64
65 if (0 == isatty(STDOUT_FILENO)) {
66 screen_width = INT_MAX;
67 }
68 #endif
69
70 #ifdef TIOCGWINSZ
71 if (screen_width < INT_MAX) {
72 struct winsize size;
73 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, (char*) &size) >= 0) {
74 screen_width = size.ws_col;
75 }
76 }
77 #endif
78
79
80 v = v_to_free = strdup(value);
81 len = strlen(v);
82 if (isspace(v[0])) {
83 char *newv;
84 i = 0;
85 while (isspace(v[i]) && i < len) {
86 ++i;
87 }
88 newv = strdup(v + i);
89 free(v_to_free);
90 v_to_free = v = newv;
91 len = strlen(v);
92 }
93 if (len > 0 && isspace(v[len - 1])) {
94 i = len - 1;
95
96
97
98
99
100 while (isspace(v[i]) && i > 0) {
101 --i;
102 }
103 v[i] = '\0';
104 }
105
106 if (orte_info_pretty && NULL != pretty_message) {
107 if (centerpoint > (int)strlen(pretty_message)) {
108 opal_asprintf(&spaces, "%*s", centerpoint -
109 (int)strlen(pretty_message), " ");
110 } else {
111 spaces = strdup("");
112 #if OPAL_ENABLE_DEBUG
113 if (centerpoint < (int)strlen(pretty_message)) {
114 opal_show_help("help-orte-info.txt",
115 "developer warning: field too long", false,
116 pretty_message, centerpoint);
117 }
118 #endif
119 }
120 max_value_width = screen_width - strlen(spaces) - strlen(pretty_message) - 2;
121 if (0 < strlen(pretty_message)) {
122 opal_asprintf(&filler, "%s%s: ", spaces, pretty_message);
123 } else {
124 opal_asprintf(&filler, "%s ", spaces);
125 }
126 free(spaces);
127 spaces = NULL;
128
129 while (true) {
130 if (strlen(v) < max_value_width) {
131 printf("%s%s\n", filler, v);
132 break;
133 } else {
134 opal_asprintf(&spaces, "%*s", centerpoint + 2, " ");
135
136
137
138
139 savev = v[max_value_width];
140 v[max_value_width] = '\0';
141 pos = (char*)strrchr(v, (int)' ');
142 v[max_value_width] = savev;
143 if (NULL == pos) {
144
145
146
147 pos = strchr(&v[max_value_width], ' ');
148
149 if (NULL == pos) {
150
151
152
153 printf("%s%s\n", filler, v);
154 break;
155 } else {
156 *pos = '\0';
157 printf("%s%s\n", filler, v);
158 v = pos + 1;
159 }
160 } else {
161 *pos = '\0';
162 printf("%s%s\n", filler, v);
163 v = pos + 1;
164 }
165
166
167 free(filler);
168 filler = strdup(spaces);
169 free(spaces);
170 spaces = NULL;
171 }
172 }
173 if (NULL != filler) {
174 free(filler);
175 }
176 if (NULL != spaces) {
177 free(spaces);
178 }
179 } else {
180 if (NULL != plain_message && 0 < strlen(plain_message)) {
181 printf("%s:%s\n", plain_message, value);
182 } else {
183 printf(" %s\n", value);
184 }
185 }
186 if (NULL != v_to_free) {
187 free(v_to_free);
188 }
189 }
190
191 void orte_info_out_int(const char *pretty_message,
192 const char *plain_message,
193 int value)
194 {
195 char *valstr;
196
197 opal_asprintf(&valstr, "%d", (int)value);
198 orte_info_out(pretty_message, plain_message, valstr);
199 free(valstr);
200 }