Add a new API to the show_help system that allows external users (e.g., libraries built upon OMPI) to define their own locations for show_help files. This allows such users to exploit the rather nice features of the OPAL show_help system -without- interfering with the ability of the ORTE and OMPI layers to use show_help themselves.
Reviewed by Jeff to protect toes...and to get some good comments :-) This commit was SVN r22026.
Этот коммит содержится в:
родитель
163c64cb4d
Коммит
176fdd3a83
@ -195,6 +195,13 @@ opal_init_util(void)
|
||||
/* initialize the output system */
|
||||
opal_output_init();
|
||||
|
||||
/* initialize install dirs code */
|
||||
if (OPAL_SUCCESS != (ret = opal_installdirs_base_open())) {
|
||||
fprintf(stderr, "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_INIT)\n",
|
||||
__FILE__, __LINE__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* initialize the help system */
|
||||
opal_show_help_init();
|
||||
|
||||
@ -206,13 +213,6 @@ opal_init_util(void)
|
||||
goto return_error;
|
||||
}
|
||||
|
||||
/* initialize install dirs code */
|
||||
if (OPAL_SUCCESS != (ret = opal_installdirs_base_open())) {
|
||||
fprintf(stderr, "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_INIT)\n",
|
||||
__FILE__, __LINE__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* init the trace function */
|
||||
opal_trace_init();
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
static const char *default_filename = "help-messages";
|
||||
static const char *dash_line = "--------------------------------------------------------------------------\n";
|
||||
static int output_stream = -1;
|
||||
|
||||
static char **search_dirs = NULL;
|
||||
|
||||
int opal_show_help_init(void)
|
||||
{
|
||||
@ -50,6 +50,8 @@ int opal_show_help_init(void)
|
||||
lds.lds_want_stderr = true;
|
||||
output_stream = opal_output_open(&lds);
|
||||
|
||||
opal_argv_append_nosize(&search_dirs, opal_install_dirs.pkgdatadir);
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
@ -57,6 +59,12 @@ int opal_show_help_finalize(void)
|
||||
{
|
||||
opal_output_close(output_stream);
|
||||
output_stream = -1;
|
||||
|
||||
/* destruct the search list */
|
||||
if (NULL != search_dirs) {
|
||||
opal_argv_free(search_dirs);
|
||||
};
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
||||
@ -118,6 +126,7 @@ static int open_file(const char *base, const char *topic)
|
||||
char *filename;
|
||||
char *err_msg = NULL;
|
||||
size_t base_len;
|
||||
int i;
|
||||
|
||||
/* If no filename was supplied, use the default */
|
||||
|
||||
@ -126,24 +135,27 @@ static int open_file(const char *base, const char *topic)
|
||||
}
|
||||
|
||||
/* Try to open the file. If we can't find it, try it with a .txt
|
||||
extension. */
|
||||
|
||||
filename = opal_os_path( false, opal_install_dirs.pkgdatadir, base, NULL );
|
||||
* extension.
|
||||
*/
|
||||
for (i=0; NULL != search_dirs[i]; i++) {
|
||||
filename = opal_os_path( false, search_dirs[i], base, NULL );
|
||||
opal_show_help_yyin = fopen(filename, "r");
|
||||
if (NULL == opal_show_help_yyin) {
|
||||
asprintf(&err_msg, "%s: %s", filename, strerror(errno));
|
||||
base_len = strlen(base);
|
||||
if (4 > base_len || 0 != strcmp(base + base_len - 4, ".txt")) {
|
||||
free(filename);
|
||||
asprintf(&filename, "%s%s%s.txt", opal_install_dirs.pkgdatadir,
|
||||
OPAL_PATH_SEP, base);
|
||||
asprintf(&filename, "%s%s%s.txt", search_dirs[i], OPAL_PATH_SEP, base);
|
||||
opal_show_help_yyin = fopen(filename, "r");
|
||||
}
|
||||
}
|
||||
free(filename);
|
||||
if (NULL != opal_show_help_yyin) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we still couldn't open it, then something is wrong */
|
||||
|
||||
if (NULL == opal_show_help_yyin) {
|
||||
opal_output(output_stream, "%sSorry! You were supposed to get help about:\n %s\nBut I couldn't open the help file:\n %s. Sorry!\n%s", dash_line, topic, err_msg, dash_line);
|
||||
free(err_msg);
|
||||
@ -330,3 +342,9 @@ int opal_show_help(const char *filename, const char *topic,
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int opal_show_help_add_dir(const char *directory)
|
||||
{
|
||||
opal_argv_append_nosize(&search_dirs, directory);
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
@ -154,6 +154,21 @@ OPAL_DECLSPEC char* opal_show_help_vstring(const char *filename,
|
||||
const char *topic,
|
||||
bool want_error_header, va_list ap);
|
||||
|
||||
/**
|
||||
* This function adds another search location for the files that
|
||||
* back show_help messages. Locations will be searched starting
|
||||
* with the prefix installation directory, then cycled through
|
||||
* any additional directories in the order they were added
|
||||
*
|
||||
* This interface allows libraries that use OMPI to take advantage
|
||||
* of the show_help functionality. OMPI defines the show_help directory
|
||||
* based on where OMPI was installed. However, if the library wants to
|
||||
* use show_help to provide error output specific to itself, then it
|
||||
* nees to tell show_help how to find its own show_help files - without
|
||||
* interfering with the linked ORTE libs when they need to do show_help.
|
||||
*/
|
||||
OPAL_DECLSPEC int opal_show_help_add_dir(const char *directory);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user