зеркало из https://github.com/mozilla/pjs.git
removed newline mapping code (instead using compiler mapping of '\n' to '\r' in literals, which should do the right thing).
This commit is contained in:
Родитель
a5e6536104
Коммит
91135e142e
|
@ -29,80 +29,7 @@ namespace JS = JavaScript;
|
|||
using namespace JavaScript;
|
||||
|
||||
|
||||
#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 */
|
||||
#if defined(XP_MAC) && !defined(XP_MAC_MPW)
|
||||
#include <SIOUX.h>
|
||||
#include <MacTypes.h>
|
||||
|
||||
|
@ -121,8 +48,7 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int &
|
|||
argc = 1;
|
||||
argv = mac_argv;
|
||||
}
|
||||
#endif /* XP_MAC_MPW */
|
||||
#endif /* XP_MAC */
|
||||
#endif /* XP_MAC && !XP_MAC_MPW */
|
||||
|
||||
|
||||
// Interactively read a line from the input stream in and put it into s.
|
||||
|
|
|
@ -29,80 +29,7 @@ namespace JS = JavaScript;
|
|||
using namespace JavaScript;
|
||||
|
||||
|
||||
#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 */
|
||||
#if defined(XP_MAC) && !defined(XP_MAC_MPW)
|
||||
#include <SIOUX.h>
|
||||
#include <MacTypes.h>
|
||||
|
||||
|
@ -121,8 +48,7 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int &
|
|||
argc = 1;
|
||||
argv = mac_argv;
|
||||
}
|
||||
#endif /* XP_MAC_MPW */
|
||||
#endif /* XP_MAC */
|
||||
#endif /* XP_MAC && !XP_MAC_MPW */
|
||||
|
||||
|
||||
// Interactively read a line from the input stream in and put it into s.
|
||||
|
|
Загрузка…
Ссылка в новой задаче