backed out "fix" (thanks waldemar)

This commit is contained in:
beard%netscape.com 2000-04-05 04:24:19 +00:00
Родитель c61aa04c58
Коммит 2ff22a0e79
2 изменённых файлов: 152 добавлений и 4 удалений

Просмотреть файл

@ -29,7 +29,80 @@ namespace JS = JavaScript;
using namespace JavaScript;
#if defined(XP_MAC) && !defined(XP_MAC_MPW)
#ifdef XP_MAC
#ifdef XP_MAC_MPW
/* Macintosh MPW replacements for the ANSI routines. These translate LF's to CR's because
the MPW libraries supplied by Metrowerks don't do that for some reason. */
static void translateLFtoCR(char *str, int length)
{
char *limit = str + length;
while (str != limit) {
if (*str == '\n')
*str = '\r';
str++;
}
}
int fputc(int c, FILE *file)
{
char buffer = c;
if (buffer == '\n')
buffer = '\r';
return fwrite(&buffer, 1, 1, file);
}
int fputs(const char *s, FILE *file)
{
char buffer[4096];
int n = strlen(s);
int extra = 0;
while (n > sizeof buffer) {
memcpy(buffer, s, sizeof buffer);
translateLFtoCR(buffer, sizeof buffer);
extra += fwrite(buffer, 1, sizeof buffer, file);
n -= sizeof buffer;
s += sizeof buffer;
}
memcpy(buffer, s, n);
translateLFtoCR(buffer, n);
return extra + fwrite(buffer, 1, n, file);
}
int fprintf(FILE* file, const char *format, ...)
{
va_list args;
char smallBuffer[4096];
int n;
int bufferSize = sizeof smallBuffer;
char *buffer = smallBuffer;
int result;
va_start(args, format);
n = vsnprintf(buffer, bufferSize, format, args);
va_end(args);
while (n < 0) {
if (buffer != smallBuffer)
free(buffer);
bufferSize <<= 1;
buffer = malloc(bufferSize);
if (!buffer) {
ASSERT(false);
return 0;
}
va_start(args, format);
n = vsnprintf(buffer, bufferSize, format, args);
va_end(args);
}
translateLFtoCR(buffer, n);
result = fwrite(buffer, 1, n, file);
if (buffer != smallBuffer)
free(buffer);
return result;
}
#else /* XP_MAC_MPW */
#include <SIOUX.h>
#include <MacTypes.h>
@ -48,7 +121,8 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int &
argc = 1;
argv = mac_argv;
}
#endif /* XP_MAC && !XP_MAC_MPW */
#endif /* XP_MAC_MPW */
#endif /* XP_MAC */
// Interactively read a line from the input stream in and put it into s.

Просмотреть файл

@ -29,7 +29,80 @@ namespace JS = JavaScript;
using namespace JavaScript;
#if defined(XP_MAC) && !defined(XP_MAC_MPW)
#ifdef XP_MAC
#ifdef XP_MAC_MPW
/* Macintosh MPW replacements for the ANSI routines. These translate LF's to CR's because
the MPW libraries supplied by Metrowerks don't do that for some reason. */
static void translateLFtoCR(char *str, int length)
{
char *limit = str + length;
while (str != limit) {
if (*str == '\n')
*str = '\r';
str++;
}
}
int fputc(int c, FILE *file)
{
char buffer = c;
if (buffer == '\n')
buffer = '\r';
return fwrite(&buffer, 1, 1, file);
}
int fputs(const char *s, FILE *file)
{
char buffer[4096];
int n = strlen(s);
int extra = 0;
while (n > sizeof buffer) {
memcpy(buffer, s, sizeof buffer);
translateLFtoCR(buffer, sizeof buffer);
extra += fwrite(buffer, 1, sizeof buffer, file);
n -= sizeof buffer;
s += sizeof buffer;
}
memcpy(buffer, s, n);
translateLFtoCR(buffer, n);
return extra + fwrite(buffer, 1, n, file);
}
int fprintf(FILE* file, const char *format, ...)
{
va_list args;
char smallBuffer[4096];
int n;
int bufferSize = sizeof smallBuffer;
char *buffer = smallBuffer;
int result;
va_start(args, format);
n = vsnprintf(buffer, bufferSize, format, args);
va_end(args);
while (n < 0) {
if (buffer != smallBuffer)
free(buffer);
bufferSize <<= 1;
buffer = malloc(bufferSize);
if (!buffer) {
ASSERT(false);
return 0;
}
va_start(args, format);
n = vsnprintf(buffer, bufferSize, format, args);
va_end(args);
}
translateLFtoCR(buffer, n);
result = fwrite(buffer, 1, n, file);
if (buffer != smallBuffer)
free(buffer);
return result;
}
#else /* XP_MAC_MPW */
#include <SIOUX.h>
#include <MacTypes.h>
@ -48,7 +121,8 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int &
argc = 1;
argv = mac_argv;
}
#endif /* XP_MAC && !XP_MAC_MPW */
#endif /* XP_MAC_MPW */
#endif /* XP_MAC */
// Interactively read a line from the input stream in and put it into s.