1
1

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.
Этот коммит содержится в:
Ralph Castain 2009-09-29 02:07:46 +00:00
родитель 163c64cb4d
Коммит 176fdd3a83
3 изменённых файлов: 59 добавлений и 26 удалений

Просмотреть файл

@ -195,6 +195,13 @@ opal_init_util(void)
/* initialize the output system */ /* initialize the output system */
opal_output_init(); 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 */ /* initialize the help system */
opal_show_help_init(); opal_show_help_init();
@ -206,13 +213,6 @@ opal_init_util(void)
goto return_error; 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 */ /* init the trace function */
opal_trace_init(); opal_trace_init();

Просмотреть файл

@ -40,16 +40,18 @@
static const char *default_filename = "help-messages"; static const char *default_filename = "help-messages";
static const char *dash_line = "--------------------------------------------------------------------------\n"; static const char *dash_line = "--------------------------------------------------------------------------\n";
static int output_stream = -1; static int output_stream = -1;
static char **search_dirs = NULL;
int opal_show_help_init(void) int opal_show_help_init(void)
{ {
opal_output_stream_t lds; opal_output_stream_t lds;
OBJ_CONSTRUCT(&lds, opal_output_stream_t); OBJ_CONSTRUCT(&lds, opal_output_stream_t);
lds.lds_want_stderr = true; lds.lds_want_stderr = true;
output_stream = opal_output_open(&lds); output_stream = opal_output_open(&lds);
opal_argv_append_nosize(&search_dirs, opal_install_dirs.pkgdatadir);
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
@ -57,6 +59,12 @@ int opal_show_help_finalize(void)
{ {
opal_output_close(output_stream); opal_output_close(output_stream);
output_stream = -1; output_stream = -1;
/* destruct the search list */
if (NULL != search_dirs) {
opal_argv_free(search_dirs);
};
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
@ -118,32 +126,36 @@ static int open_file(const char *base, const char *topic)
char *filename; char *filename;
char *err_msg = NULL; char *err_msg = NULL;
size_t base_len; size_t base_len;
int i;
/* If no filename was supplied, use the default */ /* If no filename was supplied, use the default */
if (NULL == base) { if (NULL == base) {
base = default_filename; base = default_filename;
} }
/* Try to open the file. If we can't find it, try it with a .txt /* Try to open the file. If we can't find it, try it with a .txt
extension. */ * extension.
*/
filename = opal_os_path( false, opal_install_dirs.pkgdatadir, base, NULL ); for (i=0; NULL != search_dirs[i]; i++) {
opal_show_help_yyin = fopen(filename, "r"); filename = opal_os_path( false, search_dirs[i], base, NULL );
if (NULL == opal_show_help_yyin) { opal_show_help_yyin = fopen(filename, "r");
asprintf(&err_msg, "%s: %s", filename, strerror(errno)); if (NULL == opal_show_help_yyin) {
base_len = strlen(base); asprintf(&err_msg, "%s: %s", filename, strerror(errno));
if (4 > base_len || 0 != strcmp(base + base_len - 4, ".txt")) { base_len = strlen(base);
free(filename); if (4 > base_len || 0 != strcmp(base + base_len - 4, ".txt")) {
asprintf(&filename, "%s%s%s.txt", opal_install_dirs.pkgdatadir, free(filename);
OPAL_PATH_SEP, base); asprintf(&filename, "%s%s%s.txt", search_dirs[i], OPAL_PATH_SEP, base);
opal_show_help_yyin = fopen(filename, "r"); opal_show_help_yyin = fopen(filename, "r");
}
}
free(filename);
if (NULL != opal_show_help_yyin) {
break;
} }
} }
free(filename);
/* If we still couldn't open it, then something is wrong */ /* If we still couldn't open it, then something is wrong */
if (NULL == opal_show_help_yyin) { 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); 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); free(err_msg);
@ -330,3 +342,9 @@ int opal_show_help(const char *filename, const char *topic,
return rc; 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, const char *topic,
bool want_error_header, va_list ap); 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 * \internal
* *