@@ -104,14 +104,26 @@ static void opal_show_help_finalize(void)
104
104
}
105
105
}
106
106
107
+ static void opal_show_help_output (const char * msg ) {
108
+
109
+ if (-1 < output_stream ) {
110
+ opal_output (output_stream , "%s" , msg );
111
+ }
112
+ else {
113
+ // opal_show_help() was not initialized yet, but we should still be
114
+ // able to print to stderr.
115
+ fprintf (stderr , "%s" , msg );
116
+ }
117
+ }
118
+
107
119
static void opal_show_help_cbfunc (pmix_status_t status , void * cbdata )
108
120
{
109
121
opal_log_info_t * info = (opal_log_info_t * ) cbdata ;
110
122
if (PMIX_SUCCESS != status && PMIX_OPERATION_SUCCEEDED != status ) {
111
123
// Aggregation/de-duplication functionality is *probably* lost,
112
124
// but let's print the error anyway since duplicate error messages
113
125
// is better than hiding it.
114
- opal_output ( output_stream , "%s" , info -> msg );
126
+ opal_show_help_output ( info -> msg );
115
127
}
116
128
PMIX_INFO_DESTRUCT (info -> info );
117
129
if (info -> dirs ) {
@@ -146,7 +158,7 @@ static void local_delivery(const char *file, const char *topic, char *msg) {
146
158
// Aggregation/de-duplication functionality is *definitely* lost,
147
159
// but let's print the error anyway since duplicate error messages
148
160
// is better than hiding it.
149
- opal_output ( output_stream , "%s" , msg );
161
+ opal_show_help_output ( msg );
150
162
PMIX_INFO_DESTRUCT (info );
151
163
if (opal_help_want_aggregate ) {
152
164
PMIX_INFO_DESTRUCT (dirs );
@@ -156,6 +168,15 @@ static void local_delivery(const char *file, const char *topic, char *msg) {
156
168
}
157
169
}
158
170
171
+ static void opal_show_help_error (const char * file , const char * topic ) {
172
+ char * msg ;
173
+ opal_asprintf (& msg ,
174
+ "%sSorry! You were supposed to get help about:\n %s\nfrom the file:\n "
175
+ " %s\nBut I couldn't find that topic in the file. Sorry!\n%s" ,
176
+ dash_line , topic ? topic : "(Not specified)" , file ? file : "(Not specified)" , dash_line );
177
+ local_delivery (topic , file , msg );
178
+ }
179
+
159
180
/*
160
181
* Make one big string with all the lines. This isn't the most
161
182
* efficient method in the world, but we're going for clarity here --
@@ -209,13 +230,11 @@ static int array2string(char **outstring, int want_error_header, char **lines)
209
230
*/
210
231
static int open_file (const char * base , const char * topic )
211
232
{
212
- char * filename ;
213
- char * err_msg = NULL ;
233
+ char * filename = NULL , * err_msg = NULL ;
214
234
size_t base_len ;
215
- int i ;
235
+ int i , rc = OPAL_SUCCESS ;
216
236
217
237
/* If no filename was supplied, use the default */
218
-
219
238
if (NULL == base ) {
220
239
base = default_filename ;
221
240
}
@@ -229,46 +248,54 @@ static int open_file(const char *base, const char *topic)
229
248
*/
230
249
for (i = 0 ; NULL != search_dirs [i ]; i ++ ) {
231
250
filename = opal_os_path (false, search_dirs [i ], base , NULL );
232
- opal_show_help_yyin = fopen (filename , "r" );
233
- if (NULL == opal_show_help_yyin ) {
234
- opal_asprintf (& err_msg , "%s: %s" , filename , strerror (errno ));
235
- base_len = strlen (base );
236
- if (4 > base_len || 0 != strcmp (base + base_len - 4 , ".txt" )) {
237
- free (filename );
238
- opal_asprintf (& filename , "%s%s%s.txt" , search_dirs [i ], OPAL_PATH_SEP , base );
239
- opal_show_help_yyin = fopen (filename , "r" );
251
+ if (filename ) {
252
+ opal_show_help_yyin = fopen (filename , "r" );
253
+ if (NULL == opal_show_help_yyin ) {
254
+ opal_asprintf (& err_msg , "%s: %s" , filename , strerror (errno ));
255
+ base_len = strlen (base );
256
+ if (4 > base_len || 0 != strcmp (base + base_len - 4 , ".txt" )) {
257
+ free (filename );
258
+ opal_asprintf (& filename , "%s%s%s.txt" , search_dirs [i ], OPAL_PATH_SEP , base );
259
+ opal_show_help_yyin = fopen (filename , "r" );
260
+ }
261
+ }
262
+ if (NULL != opal_show_help_yyin ) {
263
+ break ;
240
264
}
241
- }
242
- free (filename );
243
- if (NULL != opal_show_help_yyin ) {
244
- break ;
245
265
}
246
266
}
247
267
}
248
268
249
269
/* If we still couldn't open it, then something is wrong */
250
270
if (NULL == opal_show_help_yyin ) {
251
- char * tmp ;
252
- opal_asprintf (& tmp ,
253
- "%sSorry! You were supposed to get help about:\n %s\nBut I couldn't open "
254
- "the help file:\n %s. Sorry!\n%s" ,
255
- dash_line , topic , err_msg , dash_line );
256
- local_delivery (topic , err_msg , tmp );
257
- free (err_msg );
258
- return OPAL_ERR_NOT_FOUND ;
259
- }
260
-
261
- if (NULL != err_msg ) {
262
- free (err_msg );
271
+ const char * file_ptr = NULL ;
272
+ if (err_msg ) {
273
+ file_ptr = err_msg ;
274
+ }
275
+ else if (filename ) {
276
+ file_ptr = filename ;
277
+ }
278
+ else {
279
+ file_ptr = base ;
280
+ }
281
+ opal_show_help_error (file_ptr , topic );
282
+ rc = OPAL_ERR_NOT_FOUND ;
283
+ goto cleanup ;
263
284
}
264
285
265
286
/* Set the buffer */
266
-
267
287
opal_show_help_init_buffer (opal_show_help_yyin );
268
288
269
- /* Happiness */
289
+ cleanup :
270
290
271
- return OPAL_SUCCESS ;
291
+ if (filename ) {
292
+ free (filename );
293
+ }
294
+ if (err_msg ) {
295
+ free (err_msg );
296
+ }
297
+
298
+ return rc ;
272
299
}
273
300
274
301
/*
@@ -302,13 +329,8 @@ static int find_topic(const char *base, const char *topic)
302
329
break ;
303
330
304
331
case OPAL_SHOW_HELP_PARSE_DONE : {
305
- char * msg ;
306
- opal_asprintf (& msg ,
307
- "%sSorry! You were supposed to get help about:\n %s\nfrom the file:\n "
308
- " %s\nBut I couldn't find that topic in the file. Sorry!\n%s" ,
309
- dash_line , topic , base , dash_line );
310
- local_delivery (topic , base , msg );
311
- return OPAL_ERR_NOT_FOUND ;
332
+ opal_show_help_error (topic , base );
333
+ return OPAL_ERR_NOT_FOUND ;
312
334
}
313
335
default :
314
336
break ;
0 commit comments