/* Print to file, echoing to stderr */ int inchi_fprintf( FILE* f, const char* lpszFormat, ... ) { int ret=0, ret2=0; va_list argList; if (f) { my_va_start( argList, lpszFormat ); ret = inchi_vfprintf( f, lpszFormat, argList ); va_end( argList ); /*^^^ No output to stderr from within dll or GUI program */ #if ( !defined(TARGET_API_LIB) && !defined(BUILD_LIB_FOR_WINCHI) ) if ( f != stderr ) { my_va_start( argList, lpszFormat ); ret2 = vfprintf( stderr, lpszFormat, argList ); va_end( argList ); } #endif return ret? ret : ret2; } return 0; }
/* This function's output should not be displayed in the output pane */ int inchi_print_nodisplay( FILE* f, const char* lpszFormat, ... ) { int ret=0; va_list argList; FILE* fi; if (f) fi = f; else fi = stdout; my_va_start( argList, lpszFormat ); ret = vfprintf( fi, lpszFormat, argList ); return ret; }
/* Print to string buffer or to file+stderr */ int inchi_ios_eprint( INCHI_IOSTREAM * ios, const char* lpszFormat, ... ) { int ret=0, ret2=0; va_list argList; if (!ios) return -1; if (ios->type == INCHI_IOSTREAM_STRING) /* was #if ( defined(TARGET_API_LIB) || defined(BUILD_CINCHI_WITH_INCHIKEY) ) */ { /* output to string buffer */ int max_len, nAddLength = 0; char *new_str = NULL; my_va_start( argList, lpszFormat ); max_len = GetMaxPrintfLength( lpszFormat, argList); va_end( argList ); if ( max_len >= 0 ) { if ( ios->s.nAllocatedLength - ios->s.nUsedLength <= max_len ) { /* enlarge output string */ nAddLength = inchi_max( INCHI_ADD_STR_LEN, max_len ); new_str = (char *)inchi_calloc( ios->s.nAllocatedLength + nAddLength, sizeof(new_str[0]) ); if ( new_str ) { if ( ios->s.pStr ) { if ( ios->s.nUsedLength > 0 ) { memcpy( new_str, ios->s.pStr, sizeof(new_str[0])* ios->s.nUsedLength ); } inchi_free( ios->s.pStr ); } ios->s.pStr = new_str; ios->s.nAllocatedLength += nAddLength; } else { return -1; /* failed */ } } /* output */ my_va_start( argList, lpszFormat ); ret = vsprintf( ios->s.pStr + ios->s.nUsedLength, lpszFormat, argList ); va_end(argList); if ( ret >= 0 ) { ios->s.nUsedLength += ret; } return ret; } return -1; } else if (ios->type == INCHI_IOSTREAM_FILE) { if ( ios->f) { /* output to plain file */ my_va_start( argList, lpszFormat ); ret = inchi_vfprintf( ios->f, lpszFormat, argList ); va_end( argList ); #if ( !defined(TARGET_API_LIB) && !defined(BUILD_LIB_FOR_WINCHI) ) /*^^^ No output to stderr from within dll or GUI program */ if ( ios->f != stderr ) { my_va_start( argList, lpszFormat ); ret2 = vfprintf( stderr, lpszFormat, argList ); va_end( argList ); } #endif return ret? ret : ret2; } } /* no output */ return 0; }
int inchi_ios_print_nodisplay( INCHI_IOSTREAM * ios, const char* lpszFormat, ... ) { if (!ios) return -1; if (ios->type == INCHI_IOSTREAM_STRING) { /* output to string buffer */ int ret=0, max_len; va_list argList; my_va_start( argList, lpszFormat ); max_len = GetMaxPrintfLength( lpszFormat, argList); va_end( argList ); if ( max_len >= 0 ) { if ( ios->s.nAllocatedLength - ios->s.nUsedLength <= max_len ) { /* enlarge output string */ int nAddLength = inchi_max( INCHI_ADD_STR_LEN, max_len ); char *new_str = (char *)inchi_calloc( ios->s.nAllocatedLength + nAddLength, sizeof(new_str[0]) ); if ( new_str ) { if ( ios->s.pStr ) { if ( ios->s.nUsedLength > 0 ) { memcpy( new_str, ios->s.pStr, sizeof(new_str[0])*ios->s.nUsedLength ); } inchi_free( ios->s.pStr ); } ios->s.pStr = new_str; ios->s.nAllocatedLength += nAddLength; } else { return -1; /* failed */ } } /* output */ my_va_start( argList, lpszFormat ); ret = vsprintf( ios->s.pStr + ios->s.nUsedLength, lpszFormat, argList ); va_end(argList); if ( ret >= 0 ) { ios->s.nUsedLength += ret; } return ret; } return -1; } else if (ios->type == INCHI_IOSTREAM_FILE) { /* output to file */ int ret=0, ret2=0; va_list argList; if (ios->f) { my_va_start( argList, lpszFormat ); ret = vfprintf( ios->f, lpszFormat, argList ); va_end( argList ); } else { my_va_start( argList, lpszFormat ); ret2 = vfprintf( stdout, lpszFormat, argList ); va_end( argList ); } return ret? ret : ret2; } /* no output */ return 0; }