NOT IN BUILD. Made JSRef work as a Macintosh MPW tool

This commit is contained in:
waldemar%netscape.com 1999-09-17 19:45:07 +00:00
parent a1e921bd32
commit caf430e24d
2 changed files with 80 additions and 1 deletions

View File

@ -83,6 +83,79 @@ FILE *gTestResultFile = NULL;
#define isatty(f) 1
#endif
#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) {
JS_ASSERT(JS_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
#include <SIOUX.h>
#include <MacTypes.h>
@ -103,7 +176,7 @@ static void initConsole(StringPtr consoleName, const char* startupMessage, int *
*argc = 1;
*argv = mac_argv;
}
#endif
#endif
#ifdef JSDEBUGGER
@ -155,6 +228,10 @@ GetLine(JSContext *cx, char *bufp, FILE *fh, const char *prompt) {
{
char line[256];
fprintf(gOutFile, prompt);
#ifdef XP_MAC_MPW
/* Print a CR after the prompt because MPW grabs the entire line when entering an interactive command */
fputc('\n', gOutFile);
#endif
if (fgets(line, 256, fh) == NULL)
return JS_FALSE;
strcpy(bufp, line);
@ -1614,8 +1691,10 @@ main(int argc, char **argv)
gOutFile = stdout;
#ifdef XP_MAC
#ifndef XP_MAC_MPW
initConsole("\pJavaScript Shell", "Welcome to js shell.", &argc, &argv);
#endif
#endif
#ifdef MAC_TEST_HACK
/*

Binary file not shown.