src/util/show_help.c
/*
 * Make one big string with all the lines.  This isn't the most
 * efficient method in the world, but we're going for clarity here --
 * not optimization.  :-)
 */
Make one big string with all the lines.  This isn't the most
efficient method in the world, but we're going for clarity here
not optimization.
Make one big string with all the lines . This isn ' t the most efficient method in the world but we ' re going for clarity here not optimization .
static int array2string(char **outstring, int want_error_header, char **lines)
{
    int i, count;
    size_t len;
    len = want_error_header ? 2 * strlen(dash_line) : 0;
    count = prte_argv_count(lines);
    for (i = 0; i < count; ++i) {
        if (NULL == lines[i]) {
            break;
        }
        len += strlen(lines[i]) + 1;
    }
    (*outstring) = (char *) malloc(len + 1);
    if (NULL == *outstring) {
        return PRTE_ERR_OUT_OF_RESOURCE;
    }
    *(*outstring) = '\0';
    if (want_error_header) {
        strcat(*outstring, dash_line);
    }
    for (i = 0; i < count; ++i) {
        if (NULL == lines[i]) {
            break;
        }
        strcat(*outstring, lines[i]);
        strcat(*outstring, "\n");
    }
    if (want_error_header) {
        strcat(*outstring, dash_line);
    }
    return PRTE_SUCCESS;
}
static int array2string ( char * * outstring , int want_error_header , char * * lines ) { int i , count ; size_t len ; len = want_error_header ? 2 * strlen ( dash_line ) : 0 ; count = prte_argv_count ( lines ) ; for ( i = 0 ; i < count ; ++ i ) { if ( NULL == lines [ i ] ) { break ; } len += strlen ( lines [ i ] ) + 1 ; } ( * outstring ) = ( char * ) malloc ( len + 1 ) ; if ( NULL == * outstring ) { return PRTE_ERR_OUT_OF_RESOURCE ; } * ( * outstring ) = ' \0 ' ; if ( want_error_header ) { strcat ( * outstring , dash_line ) ; } for ( i = 0 ; i < count ; ++ i ) { if ( NULL == lines [ i ] ) { break ; } strcat ( * outstring , lines [ i ] ) ; strcat ( * outstring , " \n " ) ; } if ( want_error_header ) { strcat ( * outstring , dash_line ) ; } return PRTE_SUCCESS ; }
Make one big string with all the lines.
Make one big string with all the lines .
/* See how much space we need */ /* Malloc it out */ /* Fill the big string */