src/util/show_help.c
/*
 * Find the right file to open
 */
Find the right file to open
Find the right file to open
static int open_file(const char *base, const char *topic)
{
    char *filename;
    char *err_msg = NULL;
    size_t base_len;
    int i;
    if (NULL == base) {
        base = default_filename;
    }
    if (NULL != search_dirs) {
        for (i = 0; NULL != search_dirs[i]; i++) {
            filename = prte_os_path(false, search_dirs[i], base, NULL);
            prte_show_help_yyin = fopen(filename, "r");
            if (NULL == prte_show_help_yyin) {
                prte_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);
                    prte_asprintf(&filename, "%s%s%s.txt", search_dirs[i], PRTE_PATH_SEP, base);
                    prte_show_help_yyin = fopen(filename, "r");
                }
            }
            free(filename);
            if (NULL != prte_show_help_yyin) {
                break;
            }
        }
    }
    if (NULL == prte_show_help_yyin) {
        prte_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);
        return PRTE_ERR_NOT_FOUND;
    }
    if (NULL != err_msg) {
        free(err_msg);
    }
    prte_show_help_init_buffer(prte_show_help_yyin);
    return PRTE_SUCCESS;
}
static int open_file ( const char * base , const char * topic ) { char * filename ; char * err_msg = NULL ; size_t base_len ; int i ; if ( NULL == base ) { base = default_filename ; } if ( NULL != search_dirs ) { for ( i = 0 ; NULL != search_dirs [ i ] ; i ++ ) { filename = prte_os_path ( false , search_dirs [ i ] , base , NULL ) ; prte_show_help_yyin = fopen ( filename , " " ) ; if ( NULL == prte_show_help_yyin ) { prte_asprintf ( & err_msg , " " , filename , strerror ( errno ) ) ; base_len = strlen ( base ) ; if ( 4 > base_len || 0 != strcmp ( base + base_len - 4 , " " ) ) { free ( filename ) ; prte_asprintf ( & filename , " " , search_dirs [ i ] , PRTE_PATH_SEP , base ) ; prte_show_help_yyin = fopen ( filename , " " ) ; } } free ( filename ) ; if ( NULL != prte_show_help_yyin ) { break ; } } } if ( NULL == prte_show_help_yyin ) { prte_output ( output_stream , " \n \n " " \n \n " , dash_line , topic , err_msg , dash_line ) ; free ( err_msg ) ; return PRTE_ERR_NOT_FOUND ; } if ( NULL != err_msg ) { free ( err_msg ) ; } prte_show_help_init_buffer ( prte_show_help_yyin ) ; return PRTE_SUCCESS ; }
Find the right file to open
Find the right file to open
/* If no filename was supplied, use the default */ /* if this is called prior to someone initializing the system,
     * then don't try to look
     */ /* Try to open the file.  If we can't find it, try it with a .txt
         * extension.
         */ /* If we still couldn't open it, then something is wrong */ /* Set the buffer */ /* Happiness */