int MyFPrintF(FILE *file, const char *fmt, ...) { int count; va_list args; va_start(args, fmt); if (isterm(file)) { char *buf; count = vsnprintf(NULL, 0, fmt, args) + 1; if (count == 0) count = MAXPRINTF; va_end(args); va_start(args, fmt); buf = (char *) malloc(count * sizeof(char)); count = vsnprintf(buf, count, fmt, args); TextPutS(&textwin, buf); free(buf); } else { count = vfprintf(file, fmt, args); } va_end(args); return count; }
int MyVFPrintF(FILE *file, const char *fmt, va_list args) { int count; if (isterm(file)) { char *buf; #ifdef __MSC__ count = _vscprintf(fmt, args) + 1; #else va_list args_copied; va_copy(args_copied, args); count = vsnprintf(NULL, 0U, fmt, args_copied) + 1; if (count == 0) count = MAXPRINTF; va_end(args_copied); #endif buf = (char *)malloc(count * sizeof(char)); count = vsnprintf(buf, count, fmt, args); TextPutS(&textwin, buf); free(buf); } else count = vfprintf(file, fmt, args); return count; }
int MyPutS(char *str) { TextPutS(&textwin, str); MyPutCh('\n'); TextMessage(); return 0; /* different from Borland library */ }
char * MyGetS(char *str) { TextPutS(&textwin,"\nDANGER: gets() used\n"); MyFGetS(str,80,stdin); if (strlen(str) > 0 && str[strlen(str)-1]=='\n') str[strlen(str)-1] = '\0'; return str; }
int MyFPutS(const char *str, FILE *file) { if (isterm(file)) { TextPutS(&textwin, (char*) str); #ifndef WGP_CONSOLE TextMessage(); #endif return (*str); /* different from Borland library */ } return fputs(str,file); }
int MyPrintF(const char *fmt, ...) { int count; char *buf; va_list args; va_start(args, fmt); count = vsnprintf(NULL, 0, fmt, args) + 1; if (count == 0) count = MAXPRINTF; va_end(args); va_start(args, fmt); buf = (char *) malloc(count * sizeof(char)); count = vsnprintf(buf, count, fmt, args); TextPutS(&textwin, buf); free(buf); va_end(args); return count; }