src/sel1.c
char *
selPrintToString(SEL  *sel)
{
char     is_center;
char    *str, *strptr;
l_int32  type;
l_int32  sx, sy, cx, cy, x, y;

    PROCNAME("selPrintToString");

    if (!sel)
        return (char *)ERROR_PTR("sel not defined", procName, NULL);

    selGetParameters(sel, &sy, &sx, &cy, &cx);
    if ((str = (char *)CALLOC(1, sy * (sx + 1) + 1)) == NULL)
        return (char *)ERROR_PTR("calloc fail for str", procName, NULL);
    strptr = str;

    for (y = 0; y < sy; ++y) {
        for (x = 0; x < sx; ++x) {
            selGetElement(sel, y, x, &type);
            is_center = (x == cx && y == cy);
            switch (type) {
                case SEL_HIT:
                    *(strptr++) = is_center ? 'X' : 'x';
                    break;
                case SEL_MISS:
                    *(strptr++) = is_center ? 'O' : 'o';
                    break;
                case SEL_DONT_CARE:
                    *(strptr++) = is_center ? 'C' : ' ';
                    break;
            }
        }
        *(strptr++) = '\n';
    }

    return str;
}
/*!
 *  selPrintToString()
 *
 *      Input:  sel
 *      Return: str (string; caller must free)
 *
 *  Notes:
 *      (1) This is an inverse function of selCreateFromString.
 *          It prints a textual representation of the SEL to a malloc'd
 *          string.  The format is the same as selCreateFromString
 *          except that newlines are inserted into the output
 *          between rows.
 *      (2) This is useful for debugging.  However, if you want to
 *          save some Sels in a file, put them in a Sela and write
 *          them out with selaWrite().  They can then be read in
 *          with selaRead().
 */
selPrintToString()
Input:  sel
Return: str (string; caller must free)

(1) This is an inverse function of selCreateFromString.
It prints a textual representation of the SEL to a malloc'd
string.  The format is the same as selCreateFromString
except that newlines are inserted into the output
between rows.
(2) This is useful for debugging.  However, if you want to
save some Sels in a file, put them in a Sela and write
them out with selaWrite().  They can then be read in
with selaRead().
selPrintToString () Input : sel Return : str ( string ; caller must free ) ( 1 ) This is an inverse function of selCreateFromString . It prints a textual representation of the SEL to a malloc ' d string . The format is the same as selCreateFromString except that newlines are inserted into the output between rows . ( 2 ) This is useful for debugging . However if you want to save some Sels in a file put them in a Sela and write them out with selaWrite () . They can then be read in with selaRead () .
char *
selPrintToString(SEL  *sel)
{
char     is_center;
char    *str, *strptr;
l_int32  type;
l_int32  sx, sy, cx, cy, x, y;
    PROCNAME("selPrintToString");
    if (!sel)
        return (char *)ERROR_PTR("sel not defined", procName, NULL);
    selGetParameters(sel, &sy, &sx, &cy, &cx);
    if ((str = (char *)CALLOC(1, sy * (sx + 1) + 1)) == NULL)
        return (char *)ERROR_PTR("calloc fail for str", procName, NULL);
    strptr = str;
    for (y = 0; y < sy; ++y) {
        for (x = 0; x < sx; ++x) {
            selGetElement(sel, y, x, &type);
            is_center = (x == cx && y == cy);
            switch (type) {
                case SEL_HIT:
                    *(strptr++) = is_center ? 'X' : 'x';
                    break;
                case SEL_MISS:
                    *(strptr++) = is_center ? 'O' : 'o';
                    break;
                case SEL_DONT_CARE:
                    *(strptr++) = is_center ? 'C' : ' ';
                    break;
            }
        }
        *(strptr++) = '\n';
    }
    return str;
}
char * selPrintToString ( SEL * sel ) { char is_center ; char * str , * strptr ; l_int32 type ; l_int32 sx , sy , cx , cy , x , y ; PROCNAME ( " " ) ; if ( ! sel ) return ( char * ) ERROR_PTR ( " " , procName , NULL ) ; selGetParameters ( sel , & sy , & sx , & cy , & cx ) ; if ( ( str = ( char * ) CALLOC ( 1 , sy * ( sx + 1 ) + 1 ) ) == NULL ) return ( char * ) ERROR_PTR ( " " , procName , NULL ) ; strptr = str ; for ( y = 0 ; y < sy ; ++ y ) { for ( x = 0 ; x < sx ; ++ x ) { selGetElement ( sel , y , x , & type ) ; is_center = ( x == cx && y == cy ) ; switch ( type ) { case SEL_HIT : * ( strptr ++ ) = is_center ? ' ' : ' ' ; break ; case SEL_MISS : * ( strptr ++ ) = is_center ? ' ' : ' ' ; break ; case SEL_DONT_CARE : * ( strptr ++ ) = is_center ? ' ' : ' ' ; break ; } } * ( strptr ++ ) = ' \n ' ; } return str ; }
selPrintToString()
      Input:  sel
      Return: str (string; caller must free)
selPrintToString () Input : sel Return : str ( string ; caller must free )