formatting
This commit is contained in:
parent
a61bd97d9b
commit
c5384cb514
|
@ -54,14 +54,11 @@ void BasicIOInit(Picoc *pc)
|
||||||
/* output a single character to either a FILE * or a string */
|
/* output a single character to either a FILE * or a string */
|
||||||
void StdioOutPutc(int OutCh, StdOutStream *Stream)
|
void StdioOutPutc(int OutCh, StdOutStream *Stream)
|
||||||
{
|
{
|
||||||
if (Stream->FilePtr != NULL)
|
if (Stream->FilePtr != NULL) {
|
||||||
{
|
|
||||||
/* output to stdio stream */
|
/* output to stdio stream */
|
||||||
putc(OutCh, Stream->FilePtr);
|
putc(OutCh, Stream->FilePtr);
|
||||||
Stream->CharCount++;
|
Stream->CharCount++;
|
||||||
}
|
} else if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1) {
|
||||||
else if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1)
|
|
||||||
{
|
|
||||||
/* output to a string */
|
/* output to a string */
|
||||||
*Stream->StrOutPtr = OutCh;
|
*Stream->StrOutPtr = OutCh;
|
||||||
Stream->StrOutPtr++;
|
Stream->StrOutPtr++;
|
||||||
|
@ -76,18 +73,13 @@ void StdioOutPutc(int OutCh, StdOutStream *Stream)
|
||||||
/* output a string to either a FILE * or a string */
|
/* output a string to either a FILE * or a string */
|
||||||
void StdioOutPuts(const char *Str, StdOutStream *Stream)
|
void StdioOutPuts(const char *Str, StdOutStream *Stream)
|
||||||
{
|
{
|
||||||
if (Stream->FilePtr != NULL)
|
if (Stream->FilePtr != NULL) {
|
||||||
{
|
|
||||||
/* output to stdio stream */
|
/* output to stdio stream */
|
||||||
fputs(Str, Stream->FilePtr);
|
fputs(Str, Stream->FilePtr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* output to a string */
|
/* output to a string */
|
||||||
while (*Str != '\0')
|
while (*Str != '\0') {
|
||||||
{
|
if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1) {
|
||||||
if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1)
|
|
||||||
{
|
|
||||||
/* output to a string */
|
/* output to a string */
|
||||||
*Stream->StrOutPtr = *Str;
|
*Stream->StrOutPtr = *Str;
|
||||||
Str++;
|
Str++;
|
||||||
|
@ -107,9 +99,7 @@ void StdioFprintfWord(StdOutStream *Stream, const char *Format, unsigned long Va
|
||||||
{
|
{
|
||||||
if (Stream->FilePtr != NULL)
|
if (Stream->FilePtr != NULL)
|
||||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||||
|
else if (Stream->StrOutLen >= 0) {
|
||||||
else if (Stream->StrOutLen >= 0)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||||
#else
|
#else
|
||||||
|
@ -118,9 +108,7 @@ void StdioFprintfWord(StdOutStream *Stream, const char *Format, unsigned long Va
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
Stream->StrOutLen -= CCount;
|
Stream->StrOutLen -= CCount;
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
|
@ -132,9 +120,7 @@ void StdioFprintfFP(StdOutStream *Stream, const char *Format, double Value)
|
||||||
{
|
{
|
||||||
if (Stream->FilePtr != NULL)
|
if (Stream->FilePtr != NULL)
|
||||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||||
|
else if (Stream->StrOutLen >= 0) {
|
||||||
else if (Stream->StrOutLen >= 0)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||||
#else
|
#else
|
||||||
|
@ -143,9 +129,7 @@ void StdioFprintfFP(StdOutStream *Stream, const char *Format, double Value)
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
Stream->StrOutLen -= CCount;
|
Stream->StrOutLen -= CCount;
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
|
@ -157,9 +141,7 @@ void StdioFprintfPointer(StdOutStream *Stream, const char *Format, void *Value)
|
||||||
{
|
{
|
||||||
if (Stream->FilePtr != NULL)
|
if (Stream->FilePtr != NULL)
|
||||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||||
|
else if (Stream->StrOutLen >= 0) {
|
||||||
else if (Stream->StrOutLen >= 0)
|
|
||||||
{
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||||
#else
|
#else
|
||||||
|
@ -168,9 +150,7 @@ void StdioFprintfPointer(StdOutStream *Stream, const char *Format, void *Value)
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
Stream->StrOutLen -= CCount;
|
Stream->StrOutLen -= CCount;
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||||
Stream->CharCount += CCount;
|
Stream->CharCount += CCount;
|
||||||
Stream->StrOutPtr += CCount;
|
Stream->StrOutPtr += CCount;
|
||||||
|
@ -198,20 +178,16 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
SOStream.StrOutLen = StrOutLen;
|
SOStream.StrOutLen = StrOutLen;
|
||||||
SOStream.CharCount = 0;
|
SOStream.CharCount = 0;
|
||||||
|
|
||||||
while (*FPos != '\0')
|
while (*FPos != '\0') {
|
||||||
{
|
if (*FPos == '%') {
|
||||||
if (*FPos == '%')
|
|
||||||
{
|
|
||||||
/* work out what type we're printing */
|
/* work out what type we're printing */
|
||||||
FPos++;
|
FPos++;
|
||||||
ShowType = NULL;
|
ShowType = NULL;
|
||||||
OneFormatBuf[0] = '%';
|
OneFormatBuf[0] = '%';
|
||||||
OneFormatCount = 1;
|
OneFormatCount = 1;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
switch (*FPos) {
|
||||||
switch (*FPos)
|
|
||||||
{
|
|
||||||
case 'd': case 'i': ShowType = &pc->IntType; break; /* integer decimal */
|
case 'd': case 'i': ShowType = &pc->IntType; break; /* integer decimal */
|
||||||
case 'o': case 'u': case 'x': case 'X': ShowType = &pc->IntType; break; /* integer base conversions */
|
case 'o': case 'u': case 'x': case 'X': ShowType = &pc->IntType; break; /* integer base conversions */
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
|
@ -234,10 +210,8 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
OneFormatCount++;
|
OneFormatCount++;
|
||||||
|
|
||||||
/* do special actions depending on the conversion type */
|
/* do special actions depending on the conversion type */
|
||||||
if (ShowType == &pc->VoidType)
|
if (ShowType == &pc->VoidType) {
|
||||||
{
|
switch (*FPos) {
|
||||||
switch (*FPos)
|
|
||||||
{
|
|
||||||
case 'm': StdioOutPuts(strerror(errno), &SOStream); break;
|
case 'm': StdioOutPuts(strerror(errno), &SOStream); break;
|
||||||
case '%': StdioOutPutc(*FPos, &SOStream); break;
|
case '%': StdioOutPutc(*FPos, &SOStream); break;
|
||||||
case '\0': OneFormatBuf[OneFormatCount] = '\0'; StdioOutPutc(*FPos, &SOStream); break;
|
case '\0': OneFormatBuf[OneFormatCount] = '\0'; StdioOutPutc(*FPos, &SOStream); break;
|
||||||
|
@ -253,19 +227,16 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
|
|
||||||
} while (ShowType == NULL && OneFormatCount < MAX_FORMAT);
|
} while (ShowType == NULL && OneFormatCount < MAX_FORMAT);
|
||||||
|
|
||||||
if (ShowType != &pc->VoidType)
|
if (ShowType != &pc->VoidType) {
|
||||||
{
|
|
||||||
if (ArgCount >= Args->NumArgs)
|
if (ArgCount >= Args->NumArgs)
|
||||||
StdioOutPuts("XXX", &SOStream);
|
StdioOutPuts("XXX", &SOStream);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* null-terminate the buffer */
|
/* null-terminate the buffer */
|
||||||
OneFormatBuf[OneFormatCount] = '\0';
|
OneFormatBuf[OneFormatCount] = '\0';
|
||||||
|
|
||||||
/* print this argument */
|
/* print this argument */
|
||||||
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
||||||
if (ShowType == &pc->IntType)
|
if (ShowType == &pc->IntType) {
|
||||||
{
|
|
||||||
/* show a signed integer */
|
/* show a signed integer */
|
||||||
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
||||||
StdioFprintfWord(&SOStream, OneFormatBuf, ExpressionCoerceUnsignedInteger(ThisArg));
|
StdioFprintfWord(&SOStream, OneFormatBuf, ExpressionCoerceUnsignedInteger(ThisArg));
|
||||||
|
@ -273,8 +244,7 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
StdioOutPuts("XXX", &SOStream);
|
StdioOutPuts("XXX", &SOStream);
|
||||||
}
|
}
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
else if (ShowType == &pc->FPType)
|
else if (ShowType == &pc->FPType) {
|
||||||
{
|
|
||||||
/* show a floating point number */
|
/* show a floating point number */
|
||||||
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
||||||
StdioFprintfFP(&SOStream, OneFormatBuf, ExpressionCoerceFP(ThisArg));
|
StdioFprintfFP(&SOStream, OneFormatBuf, ExpressionCoerceFP(ThisArg));
|
||||||
|
@ -282,25 +252,18 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
StdioOutPuts("XXX", &SOStream);
|
StdioOutPuts("XXX", &SOStream);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (ShowType == pc->CharPtrType)
|
else if (ShowType == pc->CharPtrType) {
|
||||||
{
|
|
||||||
if (ThisArg->Typ->Base == TypePointer)
|
if (ThisArg->Typ->Base == TypePointer)
|
||||||
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
||||||
|
|
||||||
else if (ThisArg->Typ->Base == TypeArray && ThisArg->Typ->FromType->Base == TypeChar)
|
else if (ThisArg->Typ->Base == TypeArray && ThisArg->Typ->FromType->Base == TypeChar)
|
||||||
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
||||||
|
|
||||||
else
|
else
|
||||||
StdioOutPuts("XXX", &SOStream);
|
StdioOutPuts("XXX", &SOStream);
|
||||||
}
|
} else if (ShowType == pc->VoidPtrType) {
|
||||||
else if (ShowType == pc->VoidPtrType)
|
|
||||||
{
|
|
||||||
if (ThisArg->Typ->Base == TypePointer)
|
if (ThisArg->Typ->Base == TypePointer)
|
||||||
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
||||||
|
|
||||||
else if (ThisArg->Typ->Base == TypeArray)
|
else if (ThisArg->Typ->Base == TypeArray)
|
||||||
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
||||||
|
|
||||||
else
|
else
|
||||||
StdioOutPuts("XXX", &SOStream);
|
StdioOutPuts("XXX", &SOStream);
|
||||||
}
|
}
|
||||||
|
@ -308,9 +271,7 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
||||||
ArgCount++;
|
ArgCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* just output a normal character */
|
/* just output a normal character */
|
||||||
StdioOutPutc(*FPos, &SOStream);
|
StdioOutPutc(*FPos, &SOStream);
|
||||||
FPos++;
|
FPos++;
|
||||||
|
@ -334,16 +295,13 @@ int StdioBaseScanf(struct ParseState *Parser, FILE *Stream, char *StrIn, char *F
|
||||||
if (Args->NumArgs > MAX_SCANF_ARGS)
|
if (Args->NumArgs > MAX_SCANF_ARGS)
|
||||||
ProgramFail(Parser, "too many arguments to scanf() - %d max", MAX_SCANF_ARGS);
|
ProgramFail(Parser, "too many arguments to scanf() - %d max", MAX_SCANF_ARGS);
|
||||||
|
|
||||||
for (ArgCount = 0; ArgCount < Args->NumArgs; ArgCount++)
|
for (ArgCount = 0; ArgCount < Args->NumArgs; ArgCount++) {
|
||||||
{
|
|
||||||
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
||||||
|
|
||||||
if (ThisArg->Typ->Base == TypePointer)
|
if (ThisArg->Typ->Base == TypePointer)
|
||||||
ScanfArg[ArgCount] = ThisArg->Val->Pointer;
|
ScanfArg[ArgCount] = ThisArg->Val->Pointer;
|
||||||
|
|
||||||
else if (ThisArg->Typ->Base == TypeArray)
|
else if (ThisArg->Typ->Base == TypeArray)
|
||||||
ScanfArg[ArgCount] = &ThisArg->Val->ArrayMem[0];
|
ScanfArg[ArgCount] = &ThisArg->Val->ArrayMem[0];
|
||||||
|
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "non-pointer argument to scanf() - argument %d after format", ArgCount+1);
|
ProgramFail(Parser, "non-pointer argument to scanf() - argument %d after format", ArgCount+1);
|
||||||
}
|
}
|
||||||
|
@ -507,8 +465,7 @@ void StdioPuts(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
||||||
void StdioGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void StdioGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
ReturnValue->Val->Pointer = fgets(Param[0]->Val->Pointer, GETS_MAXValue, stdin);
|
ReturnValue->Val->Pointer = fgets(Param[0]->Val->Pointer, GETS_MAXValue, stdin);
|
||||||
if (ReturnValue->Val->Pointer != NULL)
|
if (ReturnValue->Val->Pointer != NULL) {
|
||||||
{
|
|
||||||
char *EOLPos = strchr(Param[0]->Val->Pointer, '\n');
|
char *EOLPos = strchr(Param[0]->Val->Pointer, '\n');
|
||||||
if (EOLPos != NULL)
|
if (EOLPos != NULL)
|
||||||
*EOLPos = '\0';
|
*EOLPos = '\0';
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction PlatformLibrary[] =
|
struct LibraryFunction PlatformLibrary[] =
|
||||||
{
|
{
|
||||||
{ NULL, NULL }
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void PlatformLibraryInit()
|
void PlatformLibraryInit()
|
||||||
|
|
|
@ -18,9 +18,9 @@ void CLineNo (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction MsvcFunctions[] =
|
struct LibraryFunction MsvcFunctions[] =
|
||||||
{
|
{
|
||||||
{ CTest, "void Test(int);" },
|
{CTest, "void Test(int);"},
|
||||||
{ CLineNo, "int LineNo();" },
|
{CLineNo, "int LineNo();"},
|
||||||
{ NULL, NULL }
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void PlatformLibraryInit(Picoc *pc)
|
void PlatformLibraryInit(Picoc *pc)
|
||||||
|
|
|
@ -743,64 +743,64 @@ struct LibraryFunction PlatformLibrary[] =
|
||||||
/* list of all library functions included with srv1.h */
|
/* list of all library functions included with srv1.h */
|
||||||
struct LibraryFunction SRV1Functions[] =
|
struct LibraryFunction SRV1Functions[] =
|
||||||
{
|
{
|
||||||
{ Csignal, "int signal();" },
|
{Csignal, "int signal();"},
|
||||||
{ Cinput, "int input();" },
|
{Cinput, "int input();"},
|
||||||
{ Cdelay, "void delay(int);" },
|
{Cdelay, "void delay(int);"},
|
||||||
{ Crand, "int rand(int);" },
|
{Crand, "int rand(int);"},
|
||||||
{ Ctime, "int time();" },
|
{Ctime, "int time();"},
|
||||||
{ Ciodir, "void iodir(int);" },
|
{Ciodir, "void iodir(int);"},
|
||||||
{ Cioread, "int ioread();" },
|
{Cioread, "int ioread();"},
|
||||||
{ Ciowrite, "void iowrite(int);" },
|
{Ciowrite, "void iowrite(int);"},
|
||||||
{ Cpeek, "int peek(int, int);" },
|
{Cpeek, "int peek(int, int);"},
|
||||||
{ Cpoke, "void poke(int, int, int);" },
|
{Cpoke, "void poke(int, int, int);"},
|
||||||
{ Cmotors, "void motors(int, int);" },
|
{Cmotors, "void motors(int, int);"},
|
||||||
{ Cmotors2, "void motors2(int, int);" },
|
{Cmotors2, "void motors2(int, int);"},
|
||||||
{ Cservos, "void servos(int, int);" },
|
{Cservos, "void servos(int, int);"},
|
||||||
{ Cservos2, "void servos2(int, int);" },
|
{Cservos2, "void servos2(int, int);"},
|
||||||
{ Cencoders, "void encoders();" },
|
{Cencoders, "void encoders();"},
|
||||||
{ Claser, "void laser(int);" },
|
{Claser, "void laser(int);"},
|
||||||
{ Csonar, "int sonar(int);" },
|
{Csonar, "int sonar(int);"},
|
||||||
{ Crange, "int range();" },
|
{Crange, "int range();"},
|
||||||
{ Cbattery, "int battery();" },
|
{Cbattery, "int battery();"},
|
||||||
{ Cvcolor, "void vcolor(int, int, int, int, int, int, int);" },
|
{Cvcolor, "void vcolor(int, int, int, int, int, int, int);"},
|
||||||
{ Cvfind, "int vfind(int, int, int, int, int);" },
|
{Cvfind, "int vfind(int, int, int, int, int);"},
|
||||||
{ Cvcam, "void vcam(int);" },
|
{Cvcam, "void vcam(int);"},
|
||||||
{ Cvcap, "void vcap();" },
|
{Cvcap, "void vcap();"},
|
||||||
{ Cvrcap, "void vrcap();" },
|
{Cvrcap, "void vrcap();"},
|
||||||
{ Cvdiff, "void vdiff(int);" },
|
{Cvdiff, "void vdiff(int);"},
|
||||||
{ Cvpix, "void vpix(int, int);" },
|
{Cvpix, "void vpix(int, int);"},
|
||||||
{ Cvscan, "int vscan(int, int);" },
|
{Cvscan, "int vscan(int, int);"},
|
||||||
{ Cvmean, "void vmean();" },
|
{Cvmean, "void vmean();"},
|
||||||
{ Cvblob, "int vblob(int, int);" },
|
{Cvblob, "int vblob(int, int);"},
|
||||||
{ Cvjpeg, "int vjpeg(int);" },
|
{Cvjpeg, "int vjpeg(int);"},
|
||||||
{ Cvsend, "void vsend(int);" },
|
{Cvsend, "void vsend(int);"},
|
||||||
{ Ccompass, "int compass();" },
|
{Ccompass, "int compass();"},
|
||||||
{ Canalog, "int analog(int);" },
|
{Canalog, "int analog(int);"},
|
||||||
{ Ctilt, "int tilt(int);" },
|
{Ctilt, "int tilt(int);"},
|
||||||
{ Cgps, "void gps();" },
|
{Cgps, "void gps();"},
|
||||||
{ Creadi2c, "int readi2c(int, int);" },
|
{Creadi2c, "int readi2c(int, int);"},
|
||||||
{ Creadi2c2, "int readi2c2(int, int);" },
|
{Creadi2c2, "int readi2c2(int, int);"},
|
||||||
{ Cwritei2c, "void writei2c(int, int, int);" },
|
{Cwritei2c, "void writei2c(int, int, int);"},
|
||||||
{ Csin, "int sin(int);" },
|
{Csin, "int sin(int);"},
|
||||||
{ Ccos, "int cos(int);" },
|
{Ccos, "int cos(int);"},
|
||||||
{ Ctan, "int tan(int);" },
|
{Ctan, "int tan(int);"},
|
||||||
{ Casin, "int asin(int, int);" },
|
{Casin, "int asin(int, int);"},
|
||||||
{ Cacos, "int acos(int, int);" },
|
{Cacos, "int acos(int, int);"},
|
||||||
{ Catan, "int atan(int, int);" },
|
{Catan, "int atan(int, int);"},
|
||||||
{ Cgps_head, "int gps_head(int, int, int, int);" },
|
{Cgps_head, "int gps_head(int, int, int, int);"},
|
||||||
{ Cgps_dist, "int gps_dist(int, int, int, int);" },
|
{Cgps_dist, "int gps_dist(int, int, int, int);"},
|
||||||
{ Csqrt, "int sqrt(int);" },
|
{Csqrt, "int sqrt(int);"},
|
||||||
{ Cnnshow, "void nnshow(int);" },
|
{Cnnshow, "void nnshow(int);"},
|
||||||
{ Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);" },
|
{Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);"},
|
||||||
{ Cnninit, "void nninit();" },
|
{Cnninit, "void nninit();"},
|
||||||
{ Cnntrain, "void nntrain();" },
|
{Cnntrain, "void nntrain();"},
|
||||||
{ Cnntest, "int nntest(int, int, int, int, int, int, int, int);" },
|
{Cnntest, "int nntest(int, int, int, int, int, int, int, int);"},
|
||||||
{ Cnnmatchblob, "int nnmatchblob(int);" },
|
{Cnnmatchblob, "int nnmatchblob(int);"},
|
||||||
{ Cnnlearnblob, "void nnlearnblob(int);" },
|
{Cnnlearnblob, "void nnlearnblob(int);"},
|
||||||
{ Cautorun, "void autorun(int);" },
|
{Cautorun, "void autorun(int);"},
|
||||||
{ Clineno, "int lineno();" },
|
{Clineno, "int lineno();"},
|
||||||
{ Cerrormsg, "void errormsg(char *);" },
|
{Cerrormsg, "void errormsg(char *);"},
|
||||||
{ NULL, NULL }
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void PlatformLibraryInit()
|
void PlatformLibraryInit()
|
||||||
|
|
|
@ -869,76 +869,76 @@ void Cerrormsg (struct ParseState *Parser, struct Value *ReturnValue, struct Val
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction PlatformLibrary[] =
|
struct LibraryFunction PlatformLibrary[] =
|
||||||
{
|
{
|
||||||
{ Csignal, "int signal();" },
|
{Csignal, "int signal();"},
|
||||||
{ Csignal1, "int signal1();" },
|
{Csignal1, "int signal1();"},
|
||||||
{ Cinput, "int input();" },
|
{Cinput, "int input();"},
|
||||||
{ Cinput1, "int input1();" },
|
{Cinput1, "int input1();"},
|
||||||
{ Cinit_uart1, "void init_uart1(int);" },
|
{Cinit_uart1, "void init_uart1(int);"},
|
||||||
{ Cread_int, "int read_int();" },
|
{Cread_int, "int read_int();"},
|
||||||
{ Cread_str, "int read_str(char *);" },
|
{Cread_str, "int read_str(char *);"},
|
||||||
{ Coutput, "void output(int);" },
|
{Coutput, "void output(int);"},
|
||||||
{ Coutput1, "void output1(int);" },
|
{Coutput1, "void output1(int);"},
|
||||||
{ Cdelay, "void delay(int);" },
|
{Cdelay, "void delay(int);"},
|
||||||
{ Crand, "int rand(int);" },
|
{Crand, "int rand(int);"},
|
||||||
{ Ctime, "int time();" },
|
{Ctime, "int time();"},
|
||||||
{ Ciodir, "void iodir(int);" },
|
{Ciodir, "void iodir(int);"},
|
||||||
{ Cioread, "int ioread();" },
|
{Cioread, "int ioread();"},
|
||||||
{ Ciowrite, "void iowrite(int);" },
|
{Ciowrite, "void iowrite(int);"},
|
||||||
{ Cpeek, "int peek(int, int);" },
|
{Cpeek, "int peek(int, int);"},
|
||||||
{ Cpoke, "void poke(int, int, int);" },
|
{Cpoke, "void poke(int, int, int);"},
|
||||||
{ Cmotors, "void motors(int, int);" },
|
{Cmotors, "void motors(int, int);"},
|
||||||
{ Cmotors2, "void motors2(int, int);" },
|
{Cmotors2, "void motors2(int, int);"},
|
||||||
{ Cmotorx, "void motorx(int, int);" },
|
{Cmotorx, "void motorx(int, int);"},
|
||||||
{ Cservos, "void servos(int, int);" },
|
{Cservos, "void servos(int, int);"},
|
||||||
{ Cservos2, "void servos2(int, int);" },
|
{Cservos2, "void servos2(int, int);"},
|
||||||
{ Cencoders, "void encoders();" },
|
{Cencoders, "void encoders();"},
|
||||||
{ Cencoderx, "int encoderx(int);" },
|
{Cencoderx, "int encoderx(int);"},
|
||||||
{ Claser, "void laser(int);" },
|
{Claser, "void laser(int);"},
|
||||||
{ Csonar, "int sonar(int);" },
|
{Csonar, "int sonar(int);"},
|
||||||
{ Crange, "int range();" },
|
{Crange, "int range();"},
|
||||||
{ Cbattery, "int battery();" },
|
{Cbattery, "int battery();"},
|
||||||
{ Cvcolor, "void vcolor(int, int, int, int, int, int, int);" },
|
{Cvcolor, "void vcolor(int, int, int, int, int, int, int);"},
|
||||||
{ Cvfind, "int vfind(int, int, int, int, int);" },
|
{Cvfind, "int vfind(int, int, int, int, int);"},
|
||||||
{ Cvcam, "void vcam(int);" },
|
{Cvcam, "void vcam(int);"},
|
||||||
{ Cvcap, "void vcap();" },
|
{Cvcap, "void vcap();"},
|
||||||
{ Cvrcap, "void vrcap();" },
|
{Cvrcap, "void vrcap();"},
|
||||||
{ Cvdiff, "void vdiff(int);" },
|
{Cvdiff, "void vdiff(int);"},
|
||||||
{ Cvpix, "void vpix(int, int);" },
|
{Cvpix, "void vpix(int, int);"},
|
||||||
{ Cvscan, "int vscan(int, int);" },
|
{Cvscan, "int vscan(int, int);"},
|
||||||
{ Cvmean, "void vmean();" },
|
{Cvmean, "void vmean();"},
|
||||||
{ Cvblob, "int vblob(int, int);" },
|
{Cvblob, "int vblob(int, int);"},
|
||||||
{ Cvjpeg, "int vjpeg(int);" },
|
{Cvjpeg, "int vjpeg(int);"},
|
||||||
{ Cvsend, "void vsend(int);" },
|
{Cvsend, "void vsend(int);"},
|
||||||
{ Ccompass, "int compass();" },
|
{Ccompass, "int compass();"},
|
||||||
{ Ccompassx, "int compassx();" },
|
{Ccompassx, "int compassx();"},
|
||||||
{ Ccompassxcal, "void compassxcal(int, int, int, int, int);" },
|
{Ccompassxcal, "void compassxcal(int, int, int, int, int);"},
|
||||||
{ Canalog, "int analog(int);" },
|
{Canalog, "int analog(int);"},
|
||||||
{ Canalogx, "int analogx(int);" },
|
{Canalogx, "int analogx(int);"},
|
||||||
{ Ctilt, "int tilt(int);" },
|
{Ctilt, "int tilt(int);"},
|
||||||
{ Cgps, "void gps();" },
|
{Cgps, "void gps();"},
|
||||||
{ Creadi2c, "int readi2c(int, int);" },
|
{Creadi2c, "int readi2c(int, int);"},
|
||||||
{ Creadi2c2, "int readi2c2(int, int);" },
|
{Creadi2c2, "int readi2c2(int, int);"},
|
||||||
{ Cwritei2c, "void writei2c(int, int, int);" },
|
{Cwritei2c, "void writei2c(int, int, int);"},
|
||||||
{ Cabs, "int abs(int);" },
|
{Cabs, "int abs(int);"},
|
||||||
{ Csin, "int sin(int);" },
|
{Csin, "int sin(int);"},
|
||||||
{ Ccos, "int cos(int);" },
|
{Ccos, "int cos(int);"},
|
||||||
{ Ctan, "int tan(int);" },
|
{Ctan, "int tan(int);"},
|
||||||
{ Casin, "int asin(int, int);" },
|
{Casin, "int asin(int, int);"},
|
||||||
{ Cacos, "int acos(int, int);" },
|
{Cacos, "int acos(int, int);"},
|
||||||
{ Catan, "int atan(int, int);" },
|
{Catan, "int atan(int, int);"},
|
||||||
{ Cgps_head, "int gps_head(int, int, int, int);" },
|
{Cgps_head, "int gps_head(int, int, int, int);"},
|
||||||
{ Cgps_dist, "int gps_dist(int, int, int, int);" },
|
{Cgps_dist, "int gps_dist(int, int, int, int);"},
|
||||||
{ Csqrt, "int sqrt(int);" },
|
{Csqrt, "int sqrt(int);"},
|
||||||
{ Cnnshow, "void nnshow(int);" },
|
{Cnnshow, "void nnshow(int);"},
|
||||||
{ Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);" },
|
{Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);"},
|
||||||
{ Cnninit, "void nninit();" },
|
{Cnninit, "void nninit();"},
|
||||||
{ Cnntrain, "void nntrain();" },
|
{Cnntrain, "void nntrain();"},
|
||||||
{ Cnntest, "int nntest(int, int, int, int, int, int, int, int);" },
|
{Cnntest, "int nntest(int, int, int, int, int, int, int, int);"},
|
||||||
{ Cnnmatchblob, "int nnmatchblob(int);" },
|
{Cnnmatchblob, "int nnmatchblob(int);"},
|
||||||
{ Cnnlearnblob, "void nnlearnblob(int);" },
|
{Cnnlearnblob, "void nnlearnblob(int);"},
|
||||||
{ Cautorun, "void autorun(int);" },
|
{Cautorun, "void autorun(int);"},
|
||||||
{ Clineno, "int lineno();" },
|
{Clineno, "int lineno();"},
|
||||||
{ Cerrormsg, "void errormsg(char *);" },
|
{Cerrormsg, "void errormsg(char *);"},
|
||||||
{ NULL, NULL }
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
||||||
/* list of all library functions and their prototypes */
|
/* list of all library functions and their prototypes */
|
||||||
struct LibraryFunction UnixFunctions[] =
|
struct LibraryFunction UnixFunctions[] =
|
||||||
{
|
{
|
||||||
{ Ctest, "void test(int);" },
|
{Ctest, "void test(int);"},
|
||||||
{ Clineno, "int lineno();" },
|
{Clineno, "int lineno();"},
|
||||||
{ NULL, NULL }
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
void PlatformLibraryInit(Picoc *pc)
|
void PlatformLibraryInit(Picoc *pc)
|
||||||
|
|
|
@ -62,10 +62,8 @@ char *PlatformReadFile(Picoc *pc, const char *FileName)
|
||||||
ReadText[BytesRead] = '\0';
|
ReadText[BytesRead] = '\0';
|
||||||
fclose(InFile);
|
fclose(InFile);
|
||||||
|
|
||||||
if ((ReadText[0] == '#') && (ReadText[1] == '!'))
|
if ((ReadText[0] == '#') && (ReadText[1] == '!')) {
|
||||||
{
|
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p) {
|
||||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p)
|
|
||||||
{
|
|
||||||
*p = ' ';
|
*p = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
||||||
|
|
||||||
// If the first character is \n or \r, eat it
|
// If the first character is \n or \r, eat it
|
||||||
ch = getch();
|
ch = getch();
|
||||||
if (ch == '\n' || ch == '\r')
|
if (ch == '\n' || ch == '\r') {
|
||||||
{
|
|
||||||
// And get the next character
|
// And get the next character
|
||||||
ch = getch();
|
ch = getch();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,7 @@ void PlatformCleanup(Picoc *pc)
|
||||||
char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
||||||
{
|
{
|
||||||
#ifdef USE_READLINE
|
#ifdef USE_READLINE
|
||||||
if (Prompt != NULL)
|
if (Prompt != NULL) {
|
||||||
{
|
|
||||||
/* use GNU readline to read the line */
|
/* use GNU readline to read the line */
|
||||||
char *InLine = readline(Prompt);
|
char *InLine = readline(Prompt);
|
||||||
if (InLine == NULL)
|
if (InLine == NULL)
|
||||||
|
@ -105,10 +104,8 @@ char *PlatformReadFile(Picoc *pc, const char *FileName)
|
||||||
ReadText[BytesRead] = '\0';
|
ReadText[BytesRead] = '\0';
|
||||||
fclose(InFile);
|
fclose(InFile);
|
||||||
|
|
||||||
if ((ReadText[0] == '#') && (ReadText[1] == '!'))
|
if ((ReadText[0] == '#') && (ReadText[1] == '!')) {
|
||||||
{
|
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p) {
|
||||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p)
|
|
||||||
{
|
|
||||||
*p = ' ';
|
*p = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,8 +119,7 @@ void PicocPlatformScanFile(Picoc *pc, const char *FileName)
|
||||||
char *SourceStr = PlatformReadFile(pc, FileName);
|
char *SourceStr = PlatformReadFile(pc, FileName);
|
||||||
|
|
||||||
/* ignore "#!/path/to/picoc" .. by replacing the "#!" with "//" */
|
/* ignore "#!/path/to/picoc" .. by replacing the "#!" with "//" */
|
||||||
if (SourceStr != NULL && SourceStr[0] == '#' && SourceStr[1] == '!')
|
if (SourceStr != NULL && SourceStr[0] == '#' && SourceStr[1] == '!') {
|
||||||
{
|
|
||||||
SourceStr[0] = '/';
|
SourceStr[0] = '/';
|
||||||
SourceStr[1] = '/';
|
SourceStr[1] = '/';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue