formatting
This commit is contained in:
parent
a61bd97d9b
commit
c5384cb514
275
cstdlib/stdio.c
275
cstdlib/stdio.c
|
@ -32,7 +32,7 @@ typedef struct StdOutStreamStruct
|
|||
char *StrOutPtr;
|
||||
int StrOutLen;
|
||||
int CharCount;
|
||||
|
||||
|
||||
} StdOutStream;
|
||||
|
||||
/* our representation of varargs within picoc */
|
||||
|
@ -54,18 +54,15 @@ void BasicIOInit(Picoc *pc)
|
|||
/* output a single character to either a FILE * or a string */
|
||||
void StdioOutPutc(int OutCh, StdOutStream *Stream)
|
||||
{
|
||||
if (Stream->FilePtr != NULL)
|
||||
{
|
||||
if (Stream->FilePtr != NULL) {
|
||||
/* output to stdio stream */
|
||||
putc(OutCh, Stream->FilePtr);
|
||||
Stream->CharCount++;
|
||||
}
|
||||
else if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1)
|
||||
{
|
||||
} else if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1) {
|
||||
/* output to a string */
|
||||
*Stream->StrOutPtr = OutCh;
|
||||
Stream->StrOutPtr++;
|
||||
|
||||
|
||||
if (Stream->StrOutLen > 1)
|
||||
Stream->StrOutLen--;
|
||||
|
||||
|
@ -76,28 +73,23 @@ void StdioOutPutc(int OutCh, StdOutStream *Stream)
|
|||
/* output a string to either a FILE * or a string */
|
||||
void StdioOutPuts(const char *Str, StdOutStream *Stream)
|
||||
{
|
||||
if (Stream->FilePtr != NULL)
|
||||
{
|
||||
if (Stream->FilePtr != NULL) {
|
||||
/* output to stdio stream */
|
||||
fputs(Str, Stream->FilePtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* output to a string */
|
||||
while (*Str != '\0')
|
||||
{
|
||||
if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1)
|
||||
{
|
||||
while (*Str != '\0') {
|
||||
if (Stream->StrOutLen < 0 || Stream->StrOutLen > 1) {
|
||||
/* output to a string */
|
||||
*Stream->StrOutPtr = *Str;
|
||||
Str++;
|
||||
Stream->StrOutPtr++;
|
||||
|
||||
|
||||
if (Stream->StrOutLen > 1)
|
||||
Stream->StrOutLen--;
|
||||
|
||||
|
||||
Stream->CharCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +99,7 @@ void StdioFprintfWord(StdOutStream *Stream, const char *Format, unsigned long Va
|
|||
{
|
||||
if (Stream->FilePtr != NULL)
|
||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||
|
||||
else if (Stream->StrOutLen >= 0)
|
||||
{
|
||||
else if (Stream->StrOutLen >= 0) {
|
||||
#ifndef WIN32
|
||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||
#else
|
||||
|
@ -118,9 +108,7 @@ void StdioFprintfWord(StdOutStream *Stream, const char *Format, unsigned long Va
|
|||
Stream->StrOutPtr += CCount;
|
||||
Stream->StrOutLen -= CCount;
|
||||
Stream->CharCount += CCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||
Stream->CharCount += CCount;
|
||||
Stream->StrOutPtr += CCount;
|
||||
|
@ -132,9 +120,7 @@ void StdioFprintfFP(StdOutStream *Stream, const char *Format, double Value)
|
|||
{
|
||||
if (Stream->FilePtr != NULL)
|
||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||
|
||||
else if (Stream->StrOutLen >= 0)
|
||||
{
|
||||
else if (Stream->StrOutLen >= 0) {
|
||||
#ifndef WIN32
|
||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||
#else
|
||||
|
@ -143,9 +129,7 @@ void StdioFprintfFP(StdOutStream *Stream, const char *Format, double Value)
|
|||
Stream->StrOutPtr += CCount;
|
||||
Stream->StrOutLen -= CCount;
|
||||
Stream->CharCount += CCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||
Stream->CharCount += CCount;
|
||||
Stream->StrOutPtr += CCount;
|
||||
|
@ -157,9 +141,7 @@ void StdioFprintfPointer(StdOutStream *Stream, const char *Format, void *Value)
|
|||
{
|
||||
if (Stream->FilePtr != NULL)
|
||||
Stream->CharCount += fprintf(Stream->FilePtr, Format, Value);
|
||||
|
||||
else if (Stream->StrOutLen >= 0)
|
||||
{
|
||||
else if (Stream->StrOutLen >= 0) {
|
||||
#ifndef WIN32
|
||||
int CCount = snprintf(Stream->StrOutPtr, Stream->StrOutLen, Format, Value);
|
||||
#else
|
||||
|
@ -168,9 +150,7 @@ void StdioFprintfPointer(StdOutStream *Stream, const char *Format, void *Value)
|
|||
Stream->StrOutPtr += CCount;
|
||||
Stream->StrOutLen -= CCount;
|
||||
Stream->CharCount += CCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int CCount = sprintf(Stream->StrOutPtr, Format, Value);
|
||||
Stream->CharCount += CCount;
|
||||
Stream->StrOutPtr += CCount;
|
||||
|
@ -188,84 +168,75 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
|||
struct ValueType *ShowType;
|
||||
StdOutStream SOStream;
|
||||
Picoc *pc = Parser->pc;
|
||||
|
||||
|
||||
if (Format == NULL)
|
||||
Format = "[null format]\n";
|
||||
|
||||
FPos = Format;
|
||||
|
||||
FPos = Format;
|
||||
SOStream.FilePtr = Stream;
|
||||
SOStream.StrOutPtr = StrOut;
|
||||
SOStream.StrOutLen = StrOutLen;
|
||||
SOStream.CharCount = 0;
|
||||
|
||||
while (*FPos != '\0')
|
||||
{
|
||||
if (*FPos == '%')
|
||||
{
|
||||
|
||||
while (*FPos != '\0') {
|
||||
if (*FPos == '%') {
|
||||
/* work out what type we're printing */
|
||||
FPos++;
|
||||
ShowType = NULL;
|
||||
OneFormatBuf[0] = '%';
|
||||
OneFormatCount = 1;
|
||||
|
||||
do
|
||||
{
|
||||
switch (*FPos)
|
||||
{
|
||||
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 */
|
||||
|
||||
do {
|
||||
switch (*FPos) {
|
||||
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 */
|
||||
#ifndef NO_FP
|
||||
case 'e': case 'E': ShowType = &pc->FPType; break; /* double, exponent form */
|
||||
case 'f': case 'F': ShowType = &pc->FPType; break; /* double, fixed-point */
|
||||
case 'g': case 'G': ShowType = &pc->FPType; break; /* double, flexible format */
|
||||
case 'e': case 'E': ShowType = &pc->FPType; break; /* double, exponent form */
|
||||
case 'f': case 'F': ShowType = &pc->FPType; break; /* double, fixed-point */
|
||||
case 'g': case 'G': ShowType = &pc->FPType; break; /* double, flexible format */
|
||||
#endif
|
||||
case 'a': case 'A': ShowType = &pc->IntType; break; /* hexadecimal, 0x- format */
|
||||
case 'c': ShowType = &pc->IntType; break; /* character */
|
||||
case 's': ShowType = pc->CharPtrType; break; /* string */
|
||||
case 'p': ShowType = pc->VoidPtrType; break; /* pointer */
|
||||
case 'n': ShowType = &pc->VoidType; break; /* number of characters written */
|
||||
case 'm': ShowType = &pc->VoidType; break; /* strerror(errno) */
|
||||
case '%': ShowType = &pc->VoidType; break; /* just a '%' character */
|
||||
case '\0': ShowType = &pc->VoidType; break; /* end of format string */
|
||||
case 'a': case 'A': ShowType = &pc->IntType; break; /* hexadecimal, 0x- format */
|
||||
case 'c': ShowType = &pc->IntType; break; /* character */
|
||||
case 's': ShowType = pc->CharPtrType; break; /* string */
|
||||
case 'p': ShowType = pc->VoidPtrType; break; /* pointer */
|
||||
case 'n': ShowType = &pc->VoidType; break; /* number of characters written */
|
||||
case 'm': ShowType = &pc->VoidType; break; /* strerror(errno) */
|
||||
case '%': ShowType = &pc->VoidType; break; /* just a '%' character */
|
||||
case '\0': ShowType = &pc->VoidType; break; /* end of format string */
|
||||
}
|
||||
|
||||
|
||||
/* copy one character of format across to the OneFormatBuf */
|
||||
OneFormatBuf[OneFormatCount] = *FPos;
|
||||
OneFormatCount++;
|
||||
|
||||
/* do special actions depending on the conversion type */
|
||||
if (ShowType == &pc->VoidType)
|
||||
{
|
||||
switch (*FPos)
|
||||
{
|
||||
case 'm': StdioOutPuts(strerror(errno), &SOStream); break;
|
||||
case '%': StdioOutPutc(*FPos, &SOStream); break;
|
||||
case '\0': OneFormatBuf[OneFormatCount] = '\0'; StdioOutPutc(*FPos, &SOStream); break;
|
||||
case 'n':
|
||||
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
||||
if (ThisArg->Typ->Base == TypeArray && ThisArg->Typ->FromType->Base == TypeInt)
|
||||
*(int *)ThisArg->Val->Pointer = SOStream.CharCount;
|
||||
break;
|
||||
if (ShowType == &pc->VoidType) {
|
||||
switch (*FPos) {
|
||||
case 'm': StdioOutPuts(strerror(errno), &SOStream); break;
|
||||
case '%': StdioOutPutc(*FPos, &SOStream); break;
|
||||
case '\0': OneFormatBuf[OneFormatCount] = '\0'; StdioOutPutc(*FPos, &SOStream); break;
|
||||
case 'n':
|
||||
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
||||
if (ThisArg->Typ->Base == TypeArray && ThisArg->Typ->FromType->Base == TypeInt)
|
||||
*(int *)ThisArg->Val->Pointer = SOStream.CharCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FPos++;
|
||||
|
||||
|
||||
} while (ShowType == NULL && OneFormatCount < MAX_FORMAT);
|
||||
|
||||
if (ShowType != &pc->VoidType)
|
||||
{
|
||||
|
||||
if (ShowType != &pc->VoidType) {
|
||||
if (ArgCount >= Args->NumArgs)
|
||||
StdioOutPuts("XXX", &SOStream);
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* null-terminate the buffer */
|
||||
OneFormatBuf[OneFormatCount] = '\0';
|
||||
|
||||
|
||||
/* print this argument */
|
||||
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
|
||||
if (ShowType == &pc->IntType)
|
||||
{
|
||||
if (ShowType == &pc->IntType) {
|
||||
/* show a signed integer */
|
||||
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
||||
StdioFprintfWord(&SOStream, OneFormatBuf, ExpressionCoerceUnsignedInteger(ThisArg));
|
||||
|
@ -273,54 +244,44 @@ int StdioBasePrintf(struct ParseState *Parser, FILE *Stream, char *StrOut, int S
|
|||
StdioOutPuts("XXX", &SOStream);
|
||||
}
|
||||
#ifndef NO_FP
|
||||
else if (ShowType == &pc->FPType)
|
||||
{
|
||||
else if (ShowType == &pc->FPType) {
|
||||
/* show a floating point number */
|
||||
if (IS_NUMERIC_COERCIBLE(ThisArg))
|
||||
StdioFprintfFP(&SOStream, OneFormatBuf, ExpressionCoerceFP(ThisArg));
|
||||
else
|
||||
StdioOutPuts("XXX", &SOStream);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (ShowType == pc->CharPtrType)
|
||||
{
|
||||
else if (ShowType == pc->CharPtrType) {
|
||||
if (ThisArg->Typ->Base == TypePointer)
|
||||
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
||||
|
||||
else if (ThisArg->Typ->Base == TypeArray && ThisArg->Typ->FromType->Base == TypeChar)
|
||||
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
||||
|
||||
else
|
||||
StdioOutPuts("XXX", &SOStream);
|
||||
}
|
||||
else if (ShowType == pc->VoidPtrType)
|
||||
{
|
||||
} else if (ShowType == pc->VoidPtrType) {
|
||||
if (ThisArg->Typ->Base == TypePointer)
|
||||
StdioFprintfPointer(&SOStream, OneFormatBuf, ThisArg->Val->Pointer);
|
||||
|
||||
else if (ThisArg->Typ->Base == TypeArray)
|
||||
StdioFprintfPointer(&SOStream, OneFormatBuf, &ThisArg->Val->ArrayMem[0]);
|
||||
|
||||
else
|
||||
StdioOutPuts("XXX", &SOStream);
|
||||
}
|
||||
|
||||
|
||||
ArgCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* just output a normal character */
|
||||
StdioOutPutc(*FPos, &SOStream);
|
||||
FPos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* null-terminate */
|
||||
if (SOStream.StrOutPtr != NULL && SOStream.StrOutLen > 0)
|
||||
*SOStream.StrOutPtr = '\0';
|
||||
|
||||
*SOStream.StrOutPtr = '\0';
|
||||
|
||||
return SOStream.CharCount;
|
||||
}
|
||||
|
||||
|
@ -330,24 +291,21 @@ int StdioBaseScanf(struct ParseState *Parser, FILE *Stream, char *StrIn, char *F
|
|||
struct Value *ThisArg = Args->Param[0];
|
||||
int ArgCount = 0;
|
||||
void *ScanfArg[MAX_SCANF_ARGS];
|
||||
|
||||
|
||||
if (Args->NumArgs > 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)));
|
||||
|
||||
if (ThisArg->Typ->Base == TypePointer)
|
||||
|
||||
if (ThisArg->Typ->Base == TypePointer)
|
||||
ScanfArg[ArgCount] = ThisArg->Val->Pointer;
|
||||
|
||||
else if (ThisArg->Typ->Base == TypeArray)
|
||||
ScanfArg[ArgCount] = &ThisArg->Val->ArrayMem[0];
|
||||
|
||||
else
|
||||
ProgramFail(Parser, "non-pointer argument to scanf() - argument %d after format", ArgCount+1);
|
||||
}
|
||||
|
||||
|
||||
if (Stream != NULL)
|
||||
return fscanf(Stream, Format, ScanfArg[0], ScanfArg[1], ScanfArg[2], ScanfArg[3], ScanfArg[4], ScanfArg[5], ScanfArg[6], ScanfArg[7], ScanfArg[8], ScanfArg[9]);
|
||||
else
|
||||
|
@ -355,77 +313,77 @@ int StdioBaseScanf(struct ParseState *Parser, FILE *Stream, char *StrIn, char *F
|
|||
}
|
||||
|
||||
/* stdio calls */
|
||||
void StdioFopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Pointer = fopen(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFreopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFreopen(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Pointer = freopen(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFclose(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFclose(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fclose(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFread(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFread(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fread(Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Integer, Param[3]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFwrite(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFwrite(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fwrite(Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Integer, Param[3]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFgetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFgetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fgetc(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFgets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFgets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Pointer = fgets(Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioRemove(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioRemove(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = remove(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioRename(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioRename(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = rename(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioRewind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioRewind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
rewind(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioTmpfile(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioTmpfile(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Pointer = tmpfile();
|
||||
}
|
||||
|
||||
void StdioClearerr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioClearerr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
clearerr((FILE *)Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFeof(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFeof(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = feof((FILE *)Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFerror(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFerror(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = ferror((FILE *)Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFileno(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFileno(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
#ifndef WIN32
|
||||
ReturnValue->Val->Integer = fileno(Param[0]->Val->Pointer);
|
||||
|
@ -434,88 +392,87 @@ void StdioFileno(struct ParseState *Parser, struct Value *ReturnValue, struct Va
|
|||
#endif
|
||||
}
|
||||
|
||||
void StdioFflush(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFflush(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fflush(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFgetpos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFgetpos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fgetpos(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFsetpos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFsetpos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fsetpos(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFputc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFputc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fputc(Param[0]->Val->Integer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFputs(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFputs(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fputs(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFtell(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFtell(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = ftell(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioFseek(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioFseek(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = fseek(Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Integer);
|
||||
}
|
||||
|
||||
void StdioPerror(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioPerror(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
perror(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioPutc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioPutc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = putc(Param[0]->Val->Integer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioPutchar(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioPutchar(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = putchar(Param[0]->Val->Integer);
|
||||
}
|
||||
|
||||
void StdioSetbuf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioSetbuf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
setbuf(Param[0]->Val->Pointer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioSetvbuf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioSetvbuf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
setvbuf(Param[0]->Val->Pointer, Param[1]->Val->Pointer, Param[2]->Val->Integer, Param[3]->Val->Integer);
|
||||
}
|
||||
|
||||
void StdioUngetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioUngetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = ungetc(Param[0]->Val->Integer, Param[1]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioPuts(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioPuts(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = puts(Param[0]->Val->Pointer);
|
||||
}
|
||||
|
||||
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);
|
||||
if (ReturnValue->Val->Pointer != NULL)
|
||||
{
|
||||
if (ReturnValue->Val->Pointer != NULL) {
|
||||
char *EOLPos = strchr(Param[0]->Val->Pointer, '\n');
|
||||
if (EOLPos != NULL)
|
||||
*EOLPos = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void StdioGetchar(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioGetchar(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = getchar();
|
||||
}
|
||||
|
@ -523,7 +480,7 @@ void StdioGetchar(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
void StdioPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg PrintfArgs;
|
||||
|
||||
|
||||
PrintfArgs.Param = Param;
|
||||
PrintfArgs.NumArgs = NumArgs-1;
|
||||
ReturnValue->Val->Integer = StdioBasePrintf(Parser, stdout, NULL, 0, Param[0]->Val->Pointer, &PrintfArgs);
|
||||
|
@ -537,7 +494,7 @@ void StdioVprintf(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
void StdioFprintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg PrintfArgs;
|
||||
|
||||
|
||||
PrintfArgs.Param = Param + 1;
|
||||
PrintfArgs.NumArgs = NumArgs-2;
|
||||
ReturnValue->Val->Integer = StdioBasePrintf(Parser, Param[0]->Val->Pointer, NULL, 0, Param[1]->Val->Pointer, &PrintfArgs);
|
||||
|
@ -548,19 +505,19 @@ void StdioVfprintf(struct ParseState *Parser, struct Value *ReturnValue, struct
|
|||
ReturnValue->Val->Integer = StdioBasePrintf(Parser, Param[0]->Val->Pointer, NULL, 0, Param[1]->Val->Pointer, Param[2]->Val->Pointer);
|
||||
}
|
||||
|
||||
void StdioSprintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioSprintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg PrintfArgs;
|
||||
|
||||
|
||||
PrintfArgs.Param = Param + 1;
|
||||
PrintfArgs.NumArgs = NumArgs-2;
|
||||
ReturnValue->Val->Integer = StdioBasePrintf(Parser, NULL, Param[0]->Val->Pointer, -1, Param[1]->Val->Pointer, &PrintfArgs);
|
||||
}
|
||||
|
||||
void StdioSnprintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void StdioSnprintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg PrintfArgs;
|
||||
|
||||
|
||||
PrintfArgs.Param = Param+2;
|
||||
PrintfArgs.NumArgs = NumArgs-3;
|
||||
ReturnValue->Val->Integer = StdioBasePrintf(Parser, NULL, Param[0]->Val->Pointer, Param[1]->Val->Integer, Param[2]->Val->Pointer, &PrintfArgs);
|
||||
|
@ -569,7 +526,7 @@ void StdioSnprintf(struct ParseState *Parser, struct Value *ReturnValue, struct
|
|||
void StdioScanf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg ScanfArgs;
|
||||
|
||||
|
||||
ScanfArgs.Param = Param;
|
||||
ScanfArgs.NumArgs = NumArgs-1;
|
||||
ReturnValue->Val->Integer = StdioBaseScanf(Parser, stdin, NULL, Param[0]->Val->Pointer, &ScanfArgs);
|
||||
|
@ -578,7 +535,7 @@ void StdioScanf(struct ParseState *Parser, struct Value *ReturnValue, struct Val
|
|||
void StdioFscanf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg ScanfArgs;
|
||||
|
||||
|
||||
ScanfArgs.Param = Param+1;
|
||||
ScanfArgs.NumArgs = NumArgs-2;
|
||||
ReturnValue->Val->Integer = StdioBaseScanf(Parser, Param[0]->Val->Pointer, NULL, Param[1]->Val->Pointer, &ScanfArgs);
|
||||
|
@ -587,7 +544,7 @@ void StdioFscanf(struct ParseState *Parser, struct Value *ReturnValue, struct Va
|
|||
void StdioSscanf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
struct StdVararg ScanfArgs;
|
||||
|
||||
|
||||
ScanfArgs.Param = Param+1;
|
||||
ScanfArgs.NumArgs = NumArgs-2;
|
||||
ReturnValue->Val->Integer = StdioBaseScanf(Parser, NULL, Param[0]->Val->Pointer, Param[1]->Val->Pointer, &ScanfArgs);
|
||||
|
@ -685,13 +642,13 @@ void StdioSetupFunc(Picoc *pc)
|
|||
|
||||
/* make a "struct __FILEStruct" which is the same size as a native FILE structure */
|
||||
StructFileType = TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__FILEStruct"), sizeof(FILE));
|
||||
|
||||
|
||||
/* get a FILE * type */
|
||||
FilePtrType = TypeGetMatching(pc, NULL, StructFileType, TypePointer, 0, pc->StrEmpty, TRUE);
|
||||
|
||||
/* make a "struct __va_listStruct" which is the same size as our struct StdVararg */
|
||||
TypeCreateOpaqueStruct(pc, NULL, TableStrRegister(pc, "__va_listStruct"), sizeof(FILE));
|
||||
|
||||
|
||||
/* define EOF equal to the system EOF */
|
||||
VariableDefinePlatformVar(pc, NULL, "EOF", &pc->IntType, (union AnyValue *)&EOFValue, FALSE);
|
||||
VariableDefinePlatformVar(pc, NULL, "SEEK_SET", &pc->IntType, (union AnyValue *)&SEEK_SETValue, FALSE);
|
||||
|
@ -704,7 +661,7 @@ void StdioSetupFunc(Picoc *pc)
|
|||
VariableDefinePlatformVar(pc, NULL, "_IONBF", &pc->IntType, (union AnyValue *)&_IONBFValue, FALSE);
|
||||
VariableDefinePlatformVar(pc, NULL, "L_tmpnam", &pc->IntType, (union AnyValue *)&L_tmpnamValue, FALSE);
|
||||
VariableDefinePlatformVar(pc, NULL, "GETS_MAX", &pc->IntType, (union AnyValue *)&GETS_MAXValue, FALSE);
|
||||
|
||||
|
||||
/* define stdin, stdout and stderr */
|
||||
VariableDefinePlatformVar(pc, NULL, "stdin", FilePtrType, (union AnyValue *)&stdinValue, FALSE);
|
||||
VariableDefinePlatformVar(pc, NULL, "stdout", FilePtrType, (union AnyValue *)&stdoutValue, FALSE);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
/* list of all library functions and their prototypes */
|
||||
struct LibraryFunction PlatformLibrary[] =
|
||||
{
|
||||
{ NULL, NULL }
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void PlatformLibraryInit()
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "../interpreter.h"
|
||||
|
||||
void MsvcSetupFunc(Picoc *pc)
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
void CTest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void CTest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
printf("test(%d)\n", Param[0]->Val->Integer);
|
||||
Param[0]->Val->Integer = 1234;
|
||||
}
|
||||
|
||||
void CLineNo (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void CLineNo (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = Parser->Line;
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ void CLineNo (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
/* list of all library functions and their prototypes */
|
||||
struct LibraryFunction MsvcFunctions[] =
|
||||
{
|
||||
{ CTest, "void Test(int);" },
|
||||
{ CLineNo, "int LineNo();" },
|
||||
{ NULL, NULL }
|
||||
{CTest, "void Test(int);"},
|
||||
{CLineNo, "int LineNo();"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void PlatformLibraryInit(Picoc *pc)
|
||||
|
|
|
@ -5,10 +5,10 @@ static int GPSlat, GPSlon, GPSalt, GPSfix, GPSsat, GPSutc, Elcount, Ercount;
|
|||
static int ScanVect[16], NNVect[NUM_OUTPUT];
|
||||
|
||||
struct ValueType *IntArrayType;
|
||||
|
||||
|
||||
|
||||
void SRV1SetupFunc()
|
||||
{
|
||||
{
|
||||
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty, TRUE);
|
||||
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
||||
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
||||
|
@ -49,7 +49,7 @@ void Cinput(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
void Cdelay(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int del;
|
||||
|
||||
|
||||
del = Param[0]->Val->Integer;
|
||||
if ((del < 0) || (del > 1000000))
|
||||
return;
|
||||
|
@ -69,7 +69,7 @@ void Ctime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
void Ciodir(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int dir;
|
||||
|
||||
|
||||
dir = Param[0]->Val->Integer;
|
||||
*pPORTHIO_DIR = ((dir << 10) & 0xFC00) + (*pPORTHIO_DIR & 0x03FF); // H15/14/13/12/11/10 - 1=output, 0=input
|
||||
*pPORTHIO_INEN = (((~dir) << 10) & 0xFC00) + (*pPORTHIO_INEN & 0x03FF); // invert dir bits to enable inputs
|
||||
|
@ -91,27 +91,27 @@ void Cpeek(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
unsigned char *cp;
|
||||
unsigned short *sp;
|
||||
unsigned int *ip;
|
||||
|
||||
|
||||
/* x = peek(addr, size);
|
||||
mask ptr to align with word size */
|
||||
ptr = Param[0]->Val->Integer;
|
||||
size = Param[1]->Val->Integer;
|
||||
switch (size) {
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
ReturnValue->Val->Integer = (int)((unsigned int)*cp);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE); // align with even boundary
|
||||
ReturnValue->Val->Integer = (int)((unsigned short)*sp);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC); // aling with quad boundary
|
||||
ReturnValue->Val->Integer = (int)*ip;
|
||||
break;
|
||||
default:
|
||||
ReturnValue->Val->Integer = 0;
|
||||
break;
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
ReturnValue->Val->Integer = (int)((unsigned int)*cp);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE); // align with even boundary
|
||||
ReturnValue->Val->Integer = (int)((unsigned short)*sp);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC); // aling with quad boundary
|
||||
ReturnValue->Val->Integer = (int)*ip;
|
||||
break;
|
||||
default:
|
||||
ReturnValue->Val->Integer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,37 +121,37 @@ void Cpoke(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
unsigned char *cp;
|
||||
unsigned short *sp;
|
||||
unsigned int *ip;
|
||||
|
||||
|
||||
/* x = poke(addr, size, val);
|
||||
mask ptr to align with word size */
|
||||
ptr = Param[0]->Val->Integer;
|
||||
size = Param[1]->Val->Integer;
|
||||
val = Param[2]->Val->Integer;
|
||||
switch (size) {
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
*cp = (unsigned char)(val & 0x000000FF);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE);
|
||||
*sp = (unsigned short)(val & 0x0000FFFF);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC);
|
||||
*ip = val;
|
||||
break;
|
||||
default: // don't bother with bad value
|
||||
break;
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
*cp = (unsigned char)(val & 0x000000FF);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE);
|
||||
*sp = (unsigned short)(val & 0x0000FFFF);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC);
|
||||
*ip = val;
|
||||
break;
|
||||
default: // don't bother with bad value
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Cencoders(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
unsigned int ix;
|
||||
|
||||
ix = encoders(); // read left and right encoders; save data to C globals lcount, rcount
|
||||
Elcount = (ix >> 16) & 0x0000FFFF;
|
||||
Ercount = ix & 0x0000FFFF;
|
||||
|
||||
ix = encoders(); // read left and right encoders; save data to C globals lcount, rcount
|
||||
Elcount = (ix >> 16) & 0x0000FFFF;
|
||||
Ercount = ix & 0x0000FFFF;
|
||||
}
|
||||
|
||||
void Cmotors(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
|
@ -191,7 +191,7 @@ void Cmotors2(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cservos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int lspeed, rspeed;
|
||||
|
||||
|
||||
lspeed = Param[0]->Val->Integer;
|
||||
if ((lspeed < 0) || (lspeed > 100))
|
||||
ProgramFail(NULL, "servos(): TMR2 value out of range");
|
||||
|
@ -209,7 +209,7 @@ void Cservos(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cservos2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int lspeed, rspeed;
|
||||
|
||||
|
||||
lspeed = Param[0]->Val->Integer;
|
||||
if ((lspeed < 0) || (lspeed > 100))
|
||||
ProgramFail(NULL, "servos2(): TMR6 value out of range");
|
||||
|
@ -228,15 +228,15 @@ void Claser(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
{
|
||||
*pPORTHIO &= 0xFD7F; // turn off both lasers
|
||||
switch (Param[0]->Val->Integer) {
|
||||
case 1:
|
||||
*pPORTHIO |= 0x0080; // turn on left laser
|
||||
break;
|
||||
case 2:
|
||||
*pPORTHIO |= 0x0200; // turn on right laser
|
||||
break;
|
||||
case 3:
|
||||
*pPORTHIO |= 0x0280; // turn on both lasers
|
||||
break;
|
||||
case 1:
|
||||
*pPORTHIO |= 0x0080; // turn on left laser
|
||||
break;
|
||||
case 2:
|
||||
*pPORTHIO |= 0x0200; // turn on right laser
|
||||
break;
|
||||
case 3:
|
||||
*pPORTHIO |= 0x0280; // turn on both lasers
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,11 +264,11 @@ void Cbattery(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
ReturnValue->Val->Integer = 1; // battery voltage okay
|
||||
}
|
||||
|
||||
void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vcolor (color, ymin, ymax, umin, umax, vmin, vmax);
|
||||
void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vcolor (color, ymin, ymax, umin, umax, vmin, vmax);
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
ymin[ix] = Param[1]->Val->Integer;
|
||||
ymax[ix] = Param[2]->Val->Integer;
|
||||
|
@ -278,7 +278,7 @@ void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
vmax[ix] = Param[6]->Val->Integer;
|
||||
}
|
||||
|
||||
void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set camera functions -
|
||||
void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set camera functions -
|
||||
// enable/disable AGC(4) / AWB(2) / AEC(1) camera controls
|
||||
// vcam(7) = AGC+AWB+AEC on vcam(0) = AGC+AWB+AEC off
|
||||
{
|
||||
|
@ -291,11 +291,11 @@ void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
i2cwrite(0x21, (unsigned char *)i2c_data, 1, SCCB_ON); // OV7725
|
||||
}
|
||||
|
||||
void Cvfind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vfind (color, x1, x2, y1, y2);
|
||||
void Cvfind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vfind (color, x1, x2, y1, y2);
|
||||
{
|
||||
int ix, x1, x2, y1, y2;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
x1 = Param[1]->Val->Integer;
|
||||
x2 = Param[2]->Val->Integer;
|
||||
|
@ -337,13 +337,13 @@ void Cvscan(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
if ((col < 1) || (col > 9))
|
||||
ProgramFail(NULL, "vscan(): number of columns must be between 1 and 9");
|
||||
thresh = Param[1]->Val->Integer;
|
||||
if ((thresh < 0) || (thresh > 9999))
|
||||
if ((thresh < 0) || (thresh > 9999))
|
||||
ProgramFail(NULL, "vscan(): threshold must be between 0 and 9999");
|
||||
ix = vscan((unsigned char *)SPI_BUFFER1, (unsigned char *)FRAME_BUF, thresh, (unsigned int)col, (unsigned int *)&ScanVect[0]);
|
||||
ReturnValue->Val->Integer = ix;
|
||||
}
|
||||
|
||||
void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
vmean((unsigned char *)FRAME_BUF);
|
||||
Iy1 = mean[0];
|
||||
|
@ -361,7 +361,7 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
iblob = Param[1]->Val->Integer;
|
||||
if (iblob > MAX_BLOBS)
|
||||
ProgramFail(NULL, "blob(): invalid blob index");
|
||||
|
||||
|
||||
numblob = vblob((unsigned char *)FRAME_BUF, (unsigned char *)FRAME_BUF3, ix);
|
||||
|
||||
if ((blobcnt[iblob] == 0) || (numblob == -1)) {
|
||||
|
@ -379,14 +379,14 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
void Cvjpeg (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
unsigned int image_size, qual;
|
||||
unsigned char *output_start, *output_end;
|
||||
|
||||
|
||||
qual = Param[0]->Val->Integer;
|
||||
if ((qual < 1) || (qual > 8))
|
||||
ProgramFail(NULL, "vjpeg(): quality parameter out of range");
|
||||
|
||||
|
||||
output_start = (unsigned char *)JPEG_BUF;
|
||||
output_end = encode_image((unsigned char *)FRAME_BUF, output_start, qual,
|
||||
FOUR_TWO_TWO, imgWidth, imgHeight);
|
||||
output_end = encode_image((unsigned char *)FRAME_BUF, output_start, qual,
|
||||
FOUR_TWO_TWO, imgWidth, imgHeight);
|
||||
image_size = (unsigned int)(output_end - output_start);
|
||||
|
||||
ReturnValue->Val->Integer = image_size;
|
||||
|
@ -395,15 +395,15 @@ void Cvjpeg (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cvsend (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
unsigned int ix, image_size;
|
||||
unsigned char *cp;
|
||||
|
||||
|
||||
image_size = Param[0]->Val->Integer;
|
||||
if ((image_size < 0) || (image_size > 200000))
|
||||
ProgramFail(NULL, "vsend(): image size out of range");
|
||||
|
||||
|
||||
led1_on();
|
||||
|
||||
cp = (unsigned char *)JPEG_BUF;
|
||||
for (ix=0; ix<image_size; ix++)
|
||||
for (ix=0; ix<image_size; ix++)
|
||||
putchar(*cp++);
|
||||
|
||||
led0_on();
|
||||
|
@ -413,7 +413,7 @@ void Ccompass(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
{
|
||||
unsigned char i2c_data[2];
|
||||
unsigned int ix;
|
||||
|
||||
|
||||
i2c_data[0] = 0x41; // read compass twice to clear last reading
|
||||
i2cread(0x22, (unsigned char *)i2c_data, 2, SCCB_ON);
|
||||
delayMS(20);
|
||||
|
@ -426,7 +426,7 @@ void Ccompass(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Ctilt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass
|
||||
{
|
||||
unsigned int ix;
|
||||
|
||||
|
||||
ix = (unsigned int)Param[0]->Val->Integer;
|
||||
if ((ix<1) || (ix>3))
|
||||
ProgramFail(NULL, "tilt(): invalid channel");
|
||||
|
@ -439,33 +439,33 @@ void Canalog(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
unsigned int ix, channel;
|
||||
unsigned char mask1[] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08 };
|
||||
unsigned char mask2[] = { 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
|
||||
// decide which i2c device based on channel range
|
||||
ix = (unsigned char)Param[0]->Val->Integer;
|
||||
if ((ix<1) || (ix>28))
|
||||
ProgramFail(NULL, "analog(): invalid channel");
|
||||
device_id = 0;
|
||||
switch (ix / 10) {
|
||||
case 0:
|
||||
device_id = 0x20; // channels 1-8
|
||||
break;
|
||||
case 1:
|
||||
device_id = 0x23; // channels 11-18
|
||||
break;
|
||||
case 2:
|
||||
device_id = 0x24; // channels 21-28
|
||||
break;
|
||||
case 0:
|
||||
device_id = 0x20; // channels 1-8
|
||||
break;
|
||||
case 1:
|
||||
device_id = 0x23; // channels 11-18
|
||||
break;
|
||||
case 2:
|
||||
device_id = 0x24; // channels 21-28
|
||||
break;
|
||||
}
|
||||
channel = ix % 10;
|
||||
if ((channel<1) || (channel>8))
|
||||
ProgramFail(NULL, "analog(): invalid channel");
|
||||
|
||||
|
||||
// set timer register 3
|
||||
i2c_data[0] = 0x03;
|
||||
i2c_data[1] = 0x01;
|
||||
i2cwrite(device_id, (unsigned char *)i2c_data, 1, SCCB_ON);
|
||||
|
||||
// set analog channel
|
||||
// set analog channel
|
||||
i2c_data[0] = 0x02;
|
||||
i2c_data[1] = mask1[channel-1];
|
||||
i2c_data[2] = mask2[channel-1];
|
||||
|
@ -495,21 +495,21 @@ void Cgps(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Creadi2c(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax val = readi2c(device, register);
|
||||
{
|
||||
unsigned char i2c_device, i2c_data[2];
|
||||
|
||||
|
||||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
|
||||
|
||||
i2cread(i2c_device, (unsigned char *)i2c_data, 1, SCCB_OFF);
|
||||
ReturnValue->Val->Integer = ((int)i2c_data[0] & 0x000000FF);
|
||||
}
|
||||
|
||||
void Creadi2c2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax two_byte_val = readi2c(device, register);
|
||||
void Creadi2c2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax two_byte_val = readi2c(device, register);
|
||||
{
|
||||
unsigned char i2c_device, i2c_data[2];
|
||||
|
||||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
|
||||
|
||||
i2cread(i2c_device, (unsigned char *)i2c_data, 2, SCCB_OFF);
|
||||
ReturnValue->Val->Integer = (((unsigned int)i2c_data[0] << 8) + i2c_data[1]);
|
||||
}
|
||||
|
@ -521,14 +521,14 @@ void Cwritei2c(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
i2c_data[1] = (unsigned char)Param[2]->Val->Integer;
|
||||
|
||||
|
||||
i2cwrite(i2c_device, (unsigned char *)i2c_data, 1, SCCB_OFF);
|
||||
}
|
||||
|
||||
void Csin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // sin(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = sin(ix);
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ void Csin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Ccos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // cos(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = cos(ix);
|
||||
}
|
||||
|
@ -544,7 +544,7 @@ void Ccos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Ctan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // tan(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = tan(ix);
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ void Catan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
y = Param[0]->Val->Integer;
|
||||
x = Param[1]->Val->Integer;
|
||||
ReturnValue->Val->Integer = atan(y, x);
|
||||
}
|
||||
}
|
||||
|
||||
void Cgps_head(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // gps_head(lat1, lon1, lat2, lon2)
|
||||
{
|
||||
|
@ -585,7 +585,7 @@ void Cgps_head(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
lat2 = Param[2]->Val->Integer;
|
||||
lon2 = Param[3]->Val->Integer;
|
||||
ReturnValue->Val->Integer = gps_head(lat1, lon1, lat2, lon2);
|
||||
}
|
||||
}
|
||||
|
||||
void Cgps_dist(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // gps_dist(lat1, lon1, lat2, lon2)
|
||||
{
|
||||
|
@ -595,18 +595,18 @@ void Cgps_dist(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
lat2 = Param[2]->Val->Integer;
|
||||
lon2 = Param[3]->Val->Integer;
|
||||
ReturnValue->Val->Integer = gps_dist(lat1, lon1, lat2, lon2);
|
||||
}
|
||||
}
|
||||
|
||||
void Csqrt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // sqrt(x)
|
||||
{
|
||||
int x;
|
||||
x = Param[0]->Val->Integer;
|
||||
ReturnValue->Val->Integer = isqrt(x);
|
||||
}
|
||||
}
|
||||
|
||||
void Cnnset(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnset(): invalid index");
|
||||
|
@ -616,7 +616,7 @@ void Cnnset(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
|
||||
void Cnnshow(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnshow(): invalid index");
|
||||
|
@ -634,7 +634,7 @@ void Cnntrain(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
for (ix=0; ix<NUM_NPATTERNS; ix++) {
|
||||
nnset_pattern(ix);
|
||||
nncalculate_network();
|
||||
for (i1=0; i1<NUM_OUTPUT; i1++)
|
||||
for (i1=0; i1<NUM_OUTPUT; i1++)
|
||||
printf(" %3d", N_OUT(i1)/10);
|
||||
printf("\r\n");
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ void Cnntrain(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cnntest(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1, i2, max;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = 0;
|
||||
for (i1=0; i1<8; i1++) {
|
||||
ch = (unsigned char)Param[i1]->Val->Integer;
|
||||
|
@ -667,9 +667,9 @@ void Cnntest(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
ReturnValue->Val->Integer = ix;
|
||||
}
|
||||
|
||||
void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1, max;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > MAX_BLOBS)
|
||||
ProgramFail(NULL, "nnmatchblob(): invalid blob index");
|
||||
|
@ -679,7 +679,7 @@ void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
square the aspect ratio of x1, x2, y1, y2
|
||||
then subsample blob pixels to populate N_IN(0:63) with 0:1024 values
|
||||
then nncalculate_network() and display the N_OUT() results */
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[ix], blobx1[ix], blobx2[ix],
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[ix], blobx1[ix], blobx2[ix],
|
||||
bloby1[ix], bloby2[ix], imgWidth, imgHeight);
|
||||
nncalculate_network();
|
||||
ix = 0;
|
||||
|
@ -696,13 +696,13 @@ void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
|
||||
void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnlearnblob(): invalid index");
|
||||
if (!blobcnt[0])
|
||||
ProgramFail(NULL, "nnlearnblob(): no blob to grab");
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[0], blobx1[0], blobx2[0],
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[0], blobx1[0], blobx2[0],
|
||||
bloby1[0], bloby2[0], imgWidth, imgHeight);
|
||||
nnpack8x8(ix);
|
||||
nndisplay(ix);
|
||||
|
@ -711,7 +711,7 @@ void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct
|
|||
void Cautorun (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, t0;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
t0 = readRTC();
|
||||
while (readRTC() < (t0 + ix*1000)) { // watch for ESC in 'ix' seconds
|
||||
|
@ -743,64 +743,64 @@ struct LibraryFunction PlatformLibrary[] =
|
|||
/* list of all library functions included with srv1.h */
|
||||
struct LibraryFunction SRV1Functions[] =
|
||||
{
|
||||
{ Csignal, "int signal();" },
|
||||
{ Cinput, "int input();" },
|
||||
{ Cdelay, "void delay(int);" },
|
||||
{ Crand, "int rand(int);" },
|
||||
{ Ctime, "int time();" },
|
||||
{ Ciodir, "void iodir(int);" },
|
||||
{ Cioread, "int ioread();" },
|
||||
{ Ciowrite, "void iowrite(int);" },
|
||||
{ Cpeek, "int peek(int, int);" },
|
||||
{ Cpoke, "void poke(int, int, int);" },
|
||||
{ Cmotors, "void motors(int, int);" },
|
||||
{ Cmotors2, "void motors2(int, int);" },
|
||||
{ Cservos, "void servos(int, int);" },
|
||||
{ Cservos2, "void servos2(int, int);" },
|
||||
{ Cencoders, "void encoders();" },
|
||||
{ Claser, "void laser(int);" },
|
||||
{ Csonar, "int sonar(int);" },
|
||||
{ Crange, "int range();" },
|
||||
{ Cbattery, "int battery();" },
|
||||
{ Cvcolor, "void vcolor(int, int, int, int, int, int, int);" },
|
||||
{ Cvfind, "int vfind(int, int, int, int, int);" },
|
||||
{ Cvcam, "void vcam(int);" },
|
||||
{ Cvcap, "void vcap();" },
|
||||
{ Cvrcap, "void vrcap();" },
|
||||
{ Cvdiff, "void vdiff(int);" },
|
||||
{ Cvpix, "void vpix(int, int);" },
|
||||
{ Cvscan, "int vscan(int, int);" },
|
||||
{ Cvmean, "void vmean();" },
|
||||
{ Cvblob, "int vblob(int, int);" },
|
||||
{ Cvjpeg, "int vjpeg(int);" },
|
||||
{ Cvsend, "void vsend(int);" },
|
||||
{ Ccompass, "int compass();" },
|
||||
{ Canalog, "int analog(int);" },
|
||||
{ Ctilt, "int tilt(int);" },
|
||||
{ Cgps, "void gps();" },
|
||||
{ Creadi2c, "int readi2c(int, int);" },
|
||||
{ Creadi2c2, "int readi2c2(int, int);" },
|
||||
{ Cwritei2c, "void writei2c(int, int, int);" },
|
||||
{ Csin, "int sin(int);" },
|
||||
{ Ccos, "int cos(int);" },
|
||||
{ Ctan, "int tan(int);" },
|
||||
{ Casin, "int asin(int, int);" },
|
||||
{ Cacos, "int acos(int, int);" },
|
||||
{ Catan, "int atan(int, int);" },
|
||||
{ Cgps_head, "int gps_head(int, int, int, int);" },
|
||||
{ Cgps_dist, "int gps_dist(int, int, int, int);" },
|
||||
{ Csqrt, "int sqrt(int);" },
|
||||
{ Cnnshow, "void nnshow(int);" },
|
||||
{ Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);" },
|
||||
{ Cnninit, "void nninit();" },
|
||||
{ Cnntrain, "void nntrain();" },
|
||||
{ Cnntest, "int nntest(int, int, int, int, int, int, int, int);" },
|
||||
{ Cnnmatchblob, "int nnmatchblob(int);" },
|
||||
{ Cnnlearnblob, "void nnlearnblob(int);" },
|
||||
{ Cautorun, "void autorun(int);" },
|
||||
{ Clineno, "int lineno();" },
|
||||
{ Cerrormsg, "void errormsg(char *);" },
|
||||
{ NULL, NULL }
|
||||
{Csignal, "int signal();"},
|
||||
{Cinput, "int input();"},
|
||||
{Cdelay, "void delay(int);"},
|
||||
{Crand, "int rand(int);"},
|
||||
{Ctime, "int time();"},
|
||||
{Ciodir, "void iodir(int);"},
|
||||
{Cioread, "int ioread();"},
|
||||
{Ciowrite, "void iowrite(int);"},
|
||||
{Cpeek, "int peek(int, int);"},
|
||||
{Cpoke, "void poke(int, int, int);"},
|
||||
{Cmotors, "void motors(int, int);"},
|
||||
{Cmotors2, "void motors2(int, int);"},
|
||||
{Cservos, "void servos(int, int);"},
|
||||
{Cservos2, "void servos2(int, int);"},
|
||||
{Cencoders, "void encoders();"},
|
||||
{Claser, "void laser(int);"},
|
||||
{Csonar, "int sonar(int);"},
|
||||
{Crange, "int range();"},
|
||||
{Cbattery, "int battery();"},
|
||||
{Cvcolor, "void vcolor(int, int, int, int, int, int, int);"},
|
||||
{Cvfind, "int vfind(int, int, int, int, int);"},
|
||||
{Cvcam, "void vcam(int);"},
|
||||
{Cvcap, "void vcap();"},
|
||||
{Cvrcap, "void vrcap();"},
|
||||
{Cvdiff, "void vdiff(int);"},
|
||||
{Cvpix, "void vpix(int, int);"},
|
||||
{Cvscan, "int vscan(int, int);"},
|
||||
{Cvmean, "void vmean();"},
|
||||
{Cvblob, "int vblob(int, int);"},
|
||||
{Cvjpeg, "int vjpeg(int);"},
|
||||
{Cvsend, "void vsend(int);"},
|
||||
{Ccompass, "int compass();"},
|
||||
{Canalog, "int analog(int);"},
|
||||
{Ctilt, "int tilt(int);"},
|
||||
{Cgps, "void gps();"},
|
||||
{Creadi2c, "int readi2c(int, int);"},
|
||||
{Creadi2c2, "int readi2c2(int, int);"},
|
||||
{Cwritei2c, "void writei2c(int, int, int);"},
|
||||
{Csin, "int sin(int);"},
|
||||
{Ccos, "int cos(int);"},
|
||||
{Ctan, "int tan(int);"},
|
||||
{Casin, "int asin(int, int);"},
|
||||
{Cacos, "int acos(int, int);"},
|
||||
{Catan, "int atan(int, int);"},
|
||||
{Cgps_head, "int gps_head(int, int, int, int);"},
|
||||
{Cgps_dist, "int gps_dist(int, int, int, int);"},
|
||||
{Csqrt, "int sqrt(int);"},
|
||||
{Cnnshow, "void nnshow(int);"},
|
||||
{Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);"},
|
||||
{Cnninit, "void nninit();"},
|
||||
{Cnntrain, "void nntrain();"},
|
||||
{Cnntest, "int nntest(int, int, int, int, int, int, int, int);"},
|
||||
{Cnnmatchblob, "int nnmatchblob(int);"},
|
||||
{Cnnlearnblob, "void nnlearnblob(int);"},
|
||||
{Cautorun, "void autorun(int);"},
|
||||
{Clineno, "int lineno();"},
|
||||
{Cerrormsg, "void errormsg(char *);"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void PlatformLibraryInit()
|
||||
|
|
|
@ -9,7 +9,7 @@ static int ScanVect[16], NNVect[NUM_OUTPUT];
|
|||
void PlatformLibraryInit()
|
||||
{
|
||||
struct ValueType *IntArrayType;
|
||||
|
||||
|
||||
IntArrayType = TypeGetMatching(NULL, &IntType, TypeArray, 16, StrEmpty, TRUE);
|
||||
VariableDefinePlatformVar(NULL, "scanvect", IntArrayType, (union AnyValue *)&ScanVect, FALSE);
|
||||
VariableDefinePlatformVar(NULL, "neuron", IntArrayType, (union AnyValue *)&NNVect, FALSE);
|
||||
|
@ -64,7 +64,7 @@ void Cread_int(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
{
|
||||
int ix, sign;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = 0;
|
||||
sign = 1;
|
||||
while (1) {
|
||||
|
@ -85,7 +85,7 @@ void Cread_str(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
{
|
||||
int ix;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = 0;
|
||||
char *cp = (char *)Param[0]->Val->Pointer;
|
||||
while (1) {
|
||||
|
@ -100,9 +100,9 @@ void Cread_str(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
cp[ix] = 0;
|
||||
ix--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ReturnValue->Val->Integer = ix;
|
||||
ReturnValue->Val->Integer = ix;
|
||||
}
|
||||
|
||||
void Cinit_uart1(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return 0-9 from console input
|
||||
|
@ -129,7 +129,7 @@ void Coutput1(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cdelay(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int del;
|
||||
|
||||
|
||||
del = Param[0]->Val->Integer;
|
||||
if ((del < 0) || (del > 1000000))
|
||||
return;
|
||||
|
@ -149,7 +149,7 @@ void Ctime(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
void Ciodir(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int dir;
|
||||
|
||||
|
||||
dir = Param[0]->Val->Integer;
|
||||
*pPORTHIO_DIR = ((dir << 10) & 0xFC00) + (*pPORTHIO_DIR & 0x03FF); // H15/14/13/12/11/10 - 1=output, 0=input
|
||||
*pPORTHIO_INEN = (((~dir) << 10) & 0xFC00) + (*pPORTHIO_INEN & 0x03FF); // invert dir bits to enable inputs
|
||||
|
@ -171,27 +171,27 @@ void Cpeek(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
unsigned char *cp;
|
||||
unsigned short *sp;
|
||||
unsigned int *ip;
|
||||
|
||||
|
||||
/* x = peek(addr, size);
|
||||
mask ptr to align with word size */
|
||||
ptr = Param[0]->Val->Integer;
|
||||
size = Param[1]->Val->Integer;
|
||||
switch (size) {
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
ReturnValue->Val->Integer = (int)((unsigned int)*cp);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE); // align with even boundary
|
||||
ReturnValue->Val->Integer = (int)((unsigned short)*sp);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC); // aling with quad boundary
|
||||
ReturnValue->Val->Integer = (int)*ip;
|
||||
break;
|
||||
default:
|
||||
ReturnValue->Val->Integer = 0;
|
||||
break;
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
ReturnValue->Val->Integer = (int)((unsigned int)*cp);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE); // align with even boundary
|
||||
ReturnValue->Val->Integer = (int)((unsigned short)*sp);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC); // aling with quad boundary
|
||||
ReturnValue->Val->Integer = (int)*ip;
|
||||
break;
|
||||
default:
|
||||
ReturnValue->Val->Integer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,45 +201,45 @@ void Cpoke(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
unsigned char *cp;
|
||||
unsigned short *sp;
|
||||
unsigned int *ip;
|
||||
|
||||
|
||||
/* x = poke(addr, size, val);
|
||||
mask ptr to align with word size */
|
||||
ptr = Param[0]->Val->Integer;
|
||||
size = Param[1]->Val->Integer;
|
||||
val = Param[2]->Val->Integer;
|
||||
switch (size) {
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
*cp = (unsigned char)(val & 0x000000FF);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE);
|
||||
*sp = (unsigned short)(val & 0x0000FFFF);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC);
|
||||
*ip = val;
|
||||
break;
|
||||
default: // don't bother with bad value
|
||||
break;
|
||||
case 1: // char *
|
||||
cp = (unsigned char *)ptr;
|
||||
*cp = (unsigned char)(val & 0x000000FF);
|
||||
break;
|
||||
case 2: // short *
|
||||
sp = (unsigned short *)(ptr & 0xFFFFFFFE);
|
||||
*sp = (unsigned short)(val & 0x0000FFFF);
|
||||
break;
|
||||
case 4: // int *
|
||||
ip = (unsigned int *)(ptr & 0xFFFFFFFC);
|
||||
*ip = val;
|
||||
break;
|
||||
default: // don't bother with bad value
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Cencoders(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
unsigned int ix;
|
||||
|
||||
ix = encoders(); // read left and right encoders; save data to C globals lcount, rcount
|
||||
Elcount = (ix >> 16) & 0x0000FFFF;
|
||||
Ercount = ix & 0x0000FFFF;
|
||||
|
||||
ix = encoders(); // read left and right encoders; save data to C globals lcount, rcount
|
||||
Elcount = (ix >> 16) & 0x0000FFFF;
|
||||
Ercount = ix & 0x0000FFFF;
|
||||
}
|
||||
|
||||
void Cencoderx(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = (unsigned char)Param[0]->Val->Integer;
|
||||
if ((ix<0) || (ix>7))
|
||||
if ((ix<0) || (ix>7))
|
||||
ProgramFail(NULL, "encoderx(): invalid channel");
|
||||
ReturnValue->Val->Integer = encoder_4wd(ix);
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ void Cmotorx(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
{
|
||||
unsigned char ch;
|
||||
int ls, rs;
|
||||
|
||||
|
||||
ls = Param[0]->Val->Integer;
|
||||
if ((ls < -100) || (ls > 100))
|
||||
ProgramFail(NULL, "motors(): left motor value out of range");
|
||||
|
@ -307,7 +307,7 @@ void Cmotorx(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cservos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int lspeed, rspeed;
|
||||
|
||||
|
||||
lspeed = Param[0]->Val->Integer;
|
||||
if ((lspeed < 0) || (lspeed > 100))
|
||||
ProgramFail(NULL, "servos(): TMR2 value out of range");
|
||||
|
@ -325,7 +325,7 @@ void Cservos(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cservos2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
int lspeed, rspeed;
|
||||
|
||||
|
||||
lspeed = Param[0]->Val->Integer;
|
||||
if ((lspeed < 0) || (lspeed > 100))
|
||||
ProgramFail(NULL, "servos2(): TMR6 value out of range");
|
||||
|
@ -344,15 +344,15 @@ void Claser(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
{
|
||||
*pPORTHIO &= 0xFD7F; // turn off both lasers
|
||||
switch (Param[0]->Val->Integer) {
|
||||
case 1:
|
||||
*pPORTHIO |= 0x0080; // turn on left laser
|
||||
break;
|
||||
case 2:
|
||||
*pPORTHIO |= 0x0200; // turn on right laser
|
||||
break;
|
||||
case 3:
|
||||
*pPORTHIO |= 0x0280; // turn on both lasers
|
||||
break;
|
||||
case 1:
|
||||
*pPORTHIO |= 0x0080; // turn on left laser
|
||||
break;
|
||||
case 2:
|
||||
*pPORTHIO |= 0x0200; // turn on right laser
|
||||
break;
|
||||
case 3:
|
||||
*pPORTHIO |= 0x0280; // turn on both lasers
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,11 +380,11 @@ void Cbattery(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
ReturnValue->Val->Integer = 1; // battery voltage okay
|
||||
}
|
||||
|
||||
void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vcolor (color, ymin, ymax, umin, umax, vmin, vmax);
|
||||
void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vcolor (color, ymin, ymax, umin, umax, vmin, vmax);
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
ymin[ix] = Param[1]->Val->Integer;
|
||||
ymax[ix] = Param[2]->Val->Integer;
|
||||
|
@ -394,7 +394,7 @@ void Cvcolor(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
vmax[ix] = Param[6]->Val->Integer;
|
||||
}
|
||||
|
||||
void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set camera functions -
|
||||
void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set camera functions -
|
||||
// enable/disable AGC(4) / AWB(2) / AEC(1) camera controls
|
||||
// vcam(7) = AGC+AWB+AEC on vcam(0) = AGC+AWB+AEC off
|
||||
{
|
||||
|
@ -407,11 +407,11 @@ void Cvcam(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
i2cwrite(0x21, (unsigned char *)i2c_data, 1, SCCB_ON); // OV7725
|
||||
}
|
||||
|
||||
void Cvfind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vfind (color, x1, x2, y1, y2);
|
||||
void Cvfind(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // set color bin -
|
||||
// vfind (color, x1, x2, y1, y2);
|
||||
{
|
||||
int ix, x1, x2, y1, y2;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
x1 = Param[1]->Val->Integer;
|
||||
x2 = Param[2]->Val->Integer;
|
||||
|
@ -453,13 +453,13 @@ void Cvscan(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
if ((col < 1) || (col > 9))
|
||||
ProgramFail(NULL, "vscan(): number of columns must be between 1 and 9");
|
||||
thresh = Param[1]->Val->Integer;
|
||||
if ((thresh < 0) || (thresh > 9999))
|
||||
if ((thresh < 0) || (thresh > 9999))
|
||||
ProgramFail(NULL, "vscan(): threshold must be between 0 and 9999");
|
||||
ix = vscan((unsigned char *)SPI_BUFFER1, (unsigned char *)FRAME_BUF, thresh, (unsigned int)col, (unsigned int *)&ScanVect[0]);
|
||||
ReturnValue->Val->Integer = ix;
|
||||
}
|
||||
|
||||
void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void Cvmean(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
vmean((unsigned char *)FRAME_BUF);
|
||||
Iy1 = mean[0];
|
||||
|
@ -477,7 +477,7 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
iblob = Param[1]->Val->Integer;
|
||||
if (iblob > MAX_BLOBS)
|
||||
ProgramFail(NULL, "blob(): invalid blob index");
|
||||
|
||||
|
||||
numblob = vblob((unsigned char *)FRAME_BUF, (unsigned char *)FRAME_BUF3, ix);
|
||||
|
||||
if ((blobcnt[iblob] == 0) || (numblob == -1)) {
|
||||
|
@ -495,14 +495,14 @@ void Cvblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
void Cvjpeg (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
unsigned int image_size, qual;
|
||||
unsigned char *output_start, *output_end;
|
||||
|
||||
|
||||
qual = Param[0]->Val->Integer;
|
||||
if ((qual < 1) || (qual > 8))
|
||||
ProgramFail(NULL, "vjpeg(): quality parameter out of range");
|
||||
|
||||
|
||||
output_start = (unsigned char *)JPEG_BUF;
|
||||
output_end = encode_image((unsigned char *)FRAME_BUF, output_start, qual,
|
||||
FOUR_TWO_TWO, imgWidth, imgHeight);
|
||||
output_end = encode_image((unsigned char *)FRAME_BUF, output_start, qual,
|
||||
FOUR_TWO_TWO, imgWidth, imgHeight);
|
||||
image_size = (unsigned int)(output_end - output_start);
|
||||
|
||||
ReturnValue->Val->Integer = image_size;
|
||||
|
@ -511,15 +511,15 @@ void Cvjpeg (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cvsend (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
unsigned int ix, image_size;
|
||||
unsigned char *cp;
|
||||
|
||||
|
||||
image_size = Param[0]->Val->Integer;
|
||||
if ((image_size < 0) || (image_size > 200000))
|
||||
ProgramFail(NULL, "vsend(): image size out of range");
|
||||
|
||||
|
||||
led1_on();
|
||||
|
||||
cp = (unsigned char *)JPEG_BUF;
|
||||
for (ix=0; ix<image_size; ix++)
|
||||
for (ix=0; ix<image_size; ix++)
|
||||
putchar(*cp++);
|
||||
|
||||
led0_on();
|
||||
|
@ -529,7 +529,7 @@ void Ccompass(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
{
|
||||
unsigned char i2c_data[2];
|
||||
unsigned int ix;
|
||||
|
||||
|
||||
i2c_data[0] = 0x41; // read compass twice to clear last reading
|
||||
i2cread(0x22, (unsigned char *)i2c_data, 2, SCCB_ON);
|
||||
delayMS(20);
|
||||
|
@ -543,7 +543,7 @@ void Ccompassx(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
{
|
||||
short x, y, z;
|
||||
int ix;
|
||||
|
||||
|
||||
ix = (int)read_compass3x(&x, &y, &z);
|
||||
Cxmin = cxmin;
|
||||
Cxmax = cxmax;
|
||||
|
@ -565,7 +565,7 @@ void Ccompassxcal(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
void Ctilt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass
|
||||
{
|
||||
unsigned int ix;
|
||||
|
||||
|
||||
ix = (unsigned int)Param[0]->Val->Integer;
|
||||
if ((ix<1) || (ix>3))
|
||||
ProgramFail(NULL, "tilt(): invalid channel");
|
||||
|
@ -575,7 +575,7 @@ void Ctilt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
void Canalog(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass
|
||||
{
|
||||
unsigned int ix, channel;
|
||||
|
||||
|
||||
ix = (unsigned char)Param[0]->Val->Integer;
|
||||
if ((ix<1) || (ix>28))
|
||||
ProgramFail(NULL, "analog(): invalid channel");
|
||||
|
@ -584,7 +584,7 @@ void Canalog(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
ProgramFail(NULL, "analog(): invalid channel");
|
||||
ReturnValue->Val->Integer = analog(ix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* read analog channel 0-7 from SRV-4WD (
|
||||
channel 0 = battery level
|
||||
|
@ -598,9 +598,9 @@ void Canalog(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Canalogx(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // return reading from HMC6352 I2C compass
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = (unsigned char)Param[0]->Val->Integer;
|
||||
if ((ix<0) || (ix>7))
|
||||
if ((ix<0) || (ix>7))
|
||||
ProgramFail(NULL, "analogx(): invalid channel");
|
||||
ReturnValue->Val->Integer = analog_4wd(ix);
|
||||
}
|
||||
|
@ -619,21 +619,21 @@ void Cgps(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Creadi2c(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax val = readi2c(device, register);
|
||||
{
|
||||
unsigned char i2c_device, i2c_data[2];
|
||||
|
||||
|
||||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
|
||||
|
||||
i2cread(i2c_device, (unsigned char *)i2c_data, 1, SCCB_OFF);
|
||||
ReturnValue->Val->Integer = ((int)i2c_data[0] & 0x000000FF);
|
||||
}
|
||||
|
||||
void Creadi2c2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax two_byte_val = readi2c(device, register);
|
||||
void Creadi2c2(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // syntax two_byte_val = readi2c(device, register);
|
||||
{
|
||||
unsigned char i2c_device, i2c_data[2];
|
||||
|
||||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
|
||||
|
||||
i2cread(i2c_device, (unsigned char *)i2c_data, 2, SCCB_OFF);
|
||||
ReturnValue->Val->Integer = (((unsigned int)i2c_data[0] << 8) + i2c_data[1]);
|
||||
}
|
||||
|
@ -645,14 +645,14 @@ void Cwritei2c(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
i2c_device = (unsigned char)Param[0]->Val->Integer;
|
||||
i2c_data[0] = (unsigned char)Param[1]->Val->Integer;
|
||||
i2c_data[1] = (unsigned char)Param[2]->Val->Integer;
|
||||
|
||||
|
||||
i2cwrite(i2c_device, (unsigned char *)i2c_data, 1, SCCB_OFF);
|
||||
}
|
||||
|
||||
void Cabs(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // abs(int)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // return absolute value of int
|
||||
if (ix < 0)
|
||||
ix = -ix;
|
||||
|
@ -661,7 +661,7 @@ void Cabs(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Csin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // sin(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = sin(ix);
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ void Csin(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Ccos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // cos(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = cos(ix);
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ void Ccos(struct ParseState *Parser, struct Value *ReturnValue, struct Value **P
|
|||
void Ctan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // tan(angle)
|
||||
{
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer; // input to function is angle in degrees
|
||||
ReturnValue->Val->Integer = tan(ix);
|
||||
}
|
||||
|
@ -708,7 +708,7 @@ void Catan(struct ParseState *Parser, struct Value *ReturnValue, struct Value **
|
|||
y = Param[0]->Val->Integer;
|
||||
x = Param[1]->Val->Integer;
|
||||
ReturnValue->Val->Integer = atan(y, x);
|
||||
}
|
||||
}
|
||||
|
||||
void Cgps_head(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // gps_head(lat1, lon1, lat2, lon2)
|
||||
{
|
||||
|
@ -718,7 +718,7 @@ void Cgps_head(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
lat2 = Param[2]->Val->Integer;
|
||||
lon2 = Param[3]->Val->Integer;
|
||||
ReturnValue->Val->Integer = gps_head(lat1, lon1, lat2, lon2);
|
||||
}
|
||||
}
|
||||
|
||||
void Cgps_dist(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // gps_dist(lat1, lon1, lat2, lon2)
|
||||
{
|
||||
|
@ -728,18 +728,18 @@ void Cgps_dist(struct ParseState *Parser, struct Value *ReturnValue, struct Valu
|
|||
lat2 = Param[2]->Val->Integer;
|
||||
lon2 = Param[3]->Val->Integer;
|
||||
ReturnValue->Val->Integer = gps_dist(lat1, lon1, lat2, lon2);
|
||||
}
|
||||
}
|
||||
|
||||
void Csqrt(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) // sqrt(x)
|
||||
{
|
||||
int x;
|
||||
x = Param[0]->Val->Integer;
|
||||
ReturnValue->Val->Integer = isqrt(x);
|
||||
}
|
||||
}
|
||||
|
||||
void Cnnset(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnset(): invalid index");
|
||||
|
@ -749,7 +749,7 @@ void Cnnset(struct ParseState *Parser, struct Value *ReturnValue, struct Value *
|
|||
|
||||
void Cnnshow(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnshow(): invalid index");
|
||||
|
@ -767,7 +767,7 @@ void Cnntrain(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
for (ix=0; ix<NUM_NPATTERNS; ix++) {
|
||||
nnset_pattern(ix);
|
||||
nncalculate_network();
|
||||
for (i1=0; i1<NUM_OUTPUT; i1++)
|
||||
for (i1=0; i1<NUM_OUTPUT; i1++)
|
||||
printf(" %3d", N_OUT(i1)/10);
|
||||
printf("\r\n");
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ void Cnntrain(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
void Cnntest(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1, i2, max;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = 0;
|
||||
for (i1=0; i1<8; i1++) {
|
||||
ch = (unsigned char)Param[i1]->Val->Integer;
|
||||
|
@ -800,9 +800,9 @@ void Cnntest(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
ReturnValue->Val->Integer = ix;
|
||||
}
|
||||
|
||||
void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, i1, max;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > MAX_BLOBS)
|
||||
ProgramFail(NULL, "nnmatchblob(): invalid blob index");
|
||||
|
@ -812,7 +812,7 @@ void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
square the aspect ratio of x1, x2, y1, y2
|
||||
then subsample blob pixels to populate N_IN(0:63) with 0:1024 values
|
||||
then nncalculate_network() and display the N_OUT() results */
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[ix], blobx1[ix], blobx2[ix],
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[ix], blobx1[ix], blobx2[ix],
|
||||
bloby1[ix], bloby2[ix], imgWidth, imgHeight);
|
||||
nncalculate_network();
|
||||
ix = 0;
|
||||
|
@ -829,13 +829,13 @@ void Cnnmatchblob(struct ParseState *Parser, struct Value *ReturnValue, struct V
|
|||
|
||||
void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
if (ix > NUM_NPATTERNS)
|
||||
ProgramFail(NULL, "nnlearnblob(): invalid index");
|
||||
if (!blobcnt[0])
|
||||
ProgramFail(NULL, "nnlearnblob(): no blob to grab");
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[0], blobx1[0], blobx2[0],
|
||||
nnscale8x8((unsigned char *)FRAME_BUF3, blobix[0], blobx1[0], blobx2[0],
|
||||
bloby1[0], bloby2[0], imgWidth, imgHeight);
|
||||
nnpack8x8(ix);
|
||||
nndisplay(ix);
|
||||
|
@ -844,7 +844,7 @@ void Cnnlearnblob (struct ParseState *Parser, struct Value *ReturnValue, struct
|
|||
void Cautorun (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) {
|
||||
int ix, t0;
|
||||
unsigned char ch;
|
||||
|
||||
|
||||
ix = Param[0]->Val->Integer;
|
||||
t0 = readRTC();
|
||||
while (readRTC() < (t0 + ix*1000)) { // watch for ESC in 'ix' seconds
|
||||
|
@ -869,76 +869,76 @@ void Cerrormsg (struct ParseState *Parser, struct Value *ReturnValue, struct Val
|
|||
/* list of all library functions and their prototypes */
|
||||
struct LibraryFunction PlatformLibrary[] =
|
||||
{
|
||||
{ Csignal, "int signal();" },
|
||||
{ Csignal1, "int signal1();" },
|
||||
{ Cinput, "int input();" },
|
||||
{ Cinput1, "int input1();" },
|
||||
{ Cinit_uart1, "void init_uart1(int);" },
|
||||
{ Cread_int, "int read_int();" },
|
||||
{ Cread_str, "int read_str(char *);" },
|
||||
{ Coutput, "void output(int);" },
|
||||
{ Coutput1, "void output1(int);" },
|
||||
{ Cdelay, "void delay(int);" },
|
||||
{ Crand, "int rand(int);" },
|
||||
{ Ctime, "int time();" },
|
||||
{ Ciodir, "void iodir(int);" },
|
||||
{ Cioread, "int ioread();" },
|
||||
{ Ciowrite, "void iowrite(int);" },
|
||||
{ Cpeek, "int peek(int, int);" },
|
||||
{ Cpoke, "void poke(int, int, int);" },
|
||||
{ Cmotors, "void motors(int, int);" },
|
||||
{ Cmotors2, "void motors2(int, int);" },
|
||||
{ Cmotorx, "void motorx(int, int);" },
|
||||
{ Cservos, "void servos(int, int);" },
|
||||
{ Cservos2, "void servos2(int, int);" },
|
||||
{ Cencoders, "void encoders();" },
|
||||
{ Cencoderx, "int encoderx(int);" },
|
||||
{ Claser, "void laser(int);" },
|
||||
{ Csonar, "int sonar(int);" },
|
||||
{ Crange, "int range();" },
|
||||
{ Cbattery, "int battery();" },
|
||||
{ Cvcolor, "void vcolor(int, int, int, int, int, int, int);" },
|
||||
{ Cvfind, "int vfind(int, int, int, int, int);" },
|
||||
{ Cvcam, "void vcam(int);" },
|
||||
{ Cvcap, "void vcap();" },
|
||||
{ Cvrcap, "void vrcap();" },
|
||||
{ Cvdiff, "void vdiff(int);" },
|
||||
{ Cvpix, "void vpix(int, int);" },
|
||||
{ Cvscan, "int vscan(int, int);" },
|
||||
{ Cvmean, "void vmean();" },
|
||||
{ Cvblob, "int vblob(int, int);" },
|
||||
{ Cvjpeg, "int vjpeg(int);" },
|
||||
{ Cvsend, "void vsend(int);" },
|
||||
{ Ccompass, "int compass();" },
|
||||
{ Ccompassx, "int compassx();" },
|
||||
{ Ccompassxcal, "void compassxcal(int, int, int, int, int);" },
|
||||
{ Canalog, "int analog(int);" },
|
||||
{ Canalogx, "int analogx(int);" },
|
||||
{ Ctilt, "int tilt(int);" },
|
||||
{ Cgps, "void gps();" },
|
||||
{ Creadi2c, "int readi2c(int, int);" },
|
||||
{ Creadi2c2, "int readi2c2(int, int);" },
|
||||
{ Cwritei2c, "void writei2c(int, int, int);" },
|
||||
{ Cabs, "int abs(int);" },
|
||||
{ Csin, "int sin(int);" },
|
||||
{ Ccos, "int cos(int);" },
|
||||
{ Ctan, "int tan(int);" },
|
||||
{ Casin, "int asin(int, int);" },
|
||||
{ Cacos, "int acos(int, int);" },
|
||||
{ Catan, "int atan(int, int);" },
|
||||
{ Cgps_head, "int gps_head(int, int, int, int);" },
|
||||
{ Cgps_dist, "int gps_dist(int, int, int, int);" },
|
||||
{ Csqrt, "int sqrt(int);" },
|
||||
{ Cnnshow, "void nnshow(int);" },
|
||||
{ Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);" },
|
||||
{ Cnninit, "void nninit();" },
|
||||
{ Cnntrain, "void nntrain();" },
|
||||
{ Cnntest, "int nntest(int, int, int, int, int, int, int, int);" },
|
||||
{ Cnnmatchblob, "int nnmatchblob(int);" },
|
||||
{ Cnnlearnblob, "void nnlearnblob(int);" },
|
||||
{ Cautorun, "void autorun(int);" },
|
||||
{ Clineno, "int lineno();" },
|
||||
{ Cerrormsg, "void errormsg(char *);" },
|
||||
{ NULL, NULL }
|
||||
{Csignal, "int signal();"},
|
||||
{Csignal1, "int signal1();"},
|
||||
{Cinput, "int input();"},
|
||||
{Cinput1, "int input1();"},
|
||||
{Cinit_uart1, "void init_uart1(int);"},
|
||||
{Cread_int, "int read_int();"},
|
||||
{Cread_str, "int read_str(char *);"},
|
||||
{Coutput, "void output(int);"},
|
||||
{Coutput1, "void output1(int);"},
|
||||
{Cdelay, "void delay(int);"},
|
||||
{Crand, "int rand(int);"},
|
||||
{Ctime, "int time();"},
|
||||
{Ciodir, "void iodir(int);"},
|
||||
{Cioread, "int ioread();"},
|
||||
{Ciowrite, "void iowrite(int);"},
|
||||
{Cpeek, "int peek(int, int);"},
|
||||
{Cpoke, "void poke(int, int, int);"},
|
||||
{Cmotors, "void motors(int, int);"},
|
||||
{Cmotors2, "void motors2(int, int);"},
|
||||
{Cmotorx, "void motorx(int, int);"},
|
||||
{Cservos, "void servos(int, int);"},
|
||||
{Cservos2, "void servos2(int, int);"},
|
||||
{Cencoders, "void encoders();"},
|
||||
{Cencoderx, "int encoderx(int);"},
|
||||
{Claser, "void laser(int);"},
|
||||
{Csonar, "int sonar(int);"},
|
||||
{Crange, "int range();"},
|
||||
{Cbattery, "int battery();"},
|
||||
{Cvcolor, "void vcolor(int, int, int, int, int, int, int);"},
|
||||
{Cvfind, "int vfind(int, int, int, int, int);"},
|
||||
{Cvcam, "void vcam(int);"},
|
||||
{Cvcap, "void vcap();"},
|
||||
{Cvrcap, "void vrcap();"},
|
||||
{Cvdiff, "void vdiff(int);"},
|
||||
{Cvpix, "void vpix(int, int);"},
|
||||
{Cvscan, "int vscan(int, int);"},
|
||||
{Cvmean, "void vmean();"},
|
||||
{Cvblob, "int vblob(int, int);"},
|
||||
{Cvjpeg, "int vjpeg(int);"},
|
||||
{Cvsend, "void vsend(int);"},
|
||||
{Ccompass, "int compass();"},
|
||||
{Ccompassx, "int compassx();"},
|
||||
{Ccompassxcal, "void compassxcal(int, int, int, int, int);"},
|
||||
{Canalog, "int analog(int);"},
|
||||
{Canalogx, "int analogx(int);"},
|
||||
{Ctilt, "int tilt(int);"},
|
||||
{Cgps, "void gps();"},
|
||||
{Creadi2c, "int readi2c(int, int);"},
|
||||
{Creadi2c2, "int readi2c2(int, int);"},
|
||||
{Cwritei2c, "void writei2c(int, int, int);"},
|
||||
{Cabs, "int abs(int);"},
|
||||
{Csin, "int sin(int);"},
|
||||
{Ccos, "int cos(int);"},
|
||||
{Ctan, "int tan(int);"},
|
||||
{Casin, "int asin(int, int);"},
|
||||
{Cacos, "int acos(int, int);"},
|
||||
{Catan, "int atan(int, int);"},
|
||||
{Cgps_head, "int gps_head(int, int, int, int);"},
|
||||
{Cgps_dist, "int gps_dist(int, int, int, int);"},
|
||||
{Csqrt, "int sqrt(int);"},
|
||||
{Cnnshow, "void nnshow(int);"},
|
||||
{Cnnset, "void nnset(int, int, int, int, int, int, int, int, int);"},
|
||||
{Cnninit, "void nninit();"},
|
||||
{Cnntrain, "void nntrain();"},
|
||||
{Cnntest, "int nntest(int, int, int, int, int, int, int, int);"},
|
||||
{Cnnmatchblob, "int nnmatchblob(int);"},
|
||||
{Cnnlearnblob, "void nnlearnblob(int);"},
|
||||
{Cautorun, "void autorun(int);"},
|
||||
{Clineno, "int lineno();"},
|
||||
{Cerrormsg, "void errormsg(char *);"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "../interpreter.h"
|
||||
|
||||
void UnixSetupFunc()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
void Ctest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void Ctest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
printf("test(%d)\n", Param[0]->Val->Integer);
|
||||
Param[0]->Val->Integer = 1234;
|
||||
}
|
||||
|
||||
void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
ReturnValue->Val->Integer = Parser->Line;
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
|||
/* list of all library functions and their prototypes */
|
||||
struct LibraryFunction UnixFunctions[] =
|
||||
{
|
||||
{ Ctest, "void test(int);" },
|
||||
{ Clineno, "int lineno();" },
|
||||
{ NULL, NULL }
|
||||
{Ctest, "void test(int);"},
|
||||
{Clineno, "int lineno();"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
void PlatformLibraryInit(Picoc *pc)
|
||||
|
|
|
@ -17,7 +17,7 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
|||
{
|
||||
if (Prompt != NULL)
|
||||
printf("%s", Prompt);
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
return fgets(Buf, MaxLen, stdin);
|
||||
}
|
||||
|
@ -43,34 +43,32 @@ char *PlatformReadFile(Picoc *pc, const char *FileName)
|
|||
FILE *InFile;
|
||||
int BytesRead;
|
||||
char *p;
|
||||
|
||||
|
||||
if (stat(FileName, &FileInfo))
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
|
||||
ReadText = malloc(FileInfo.st_size + 1);
|
||||
if (ReadText == NULL)
|
||||
ProgramFailNoParser(pc, "out of memory\n");
|
||||
|
||||
|
||||
InFile = fopen(FileName, "r");
|
||||
if (InFile == NULL)
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
|
||||
BytesRead = fread(ReadText, 1, FileInfo.st_size, InFile);
|
||||
if (BytesRead == 0)
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
ReadText[BytesRead] = '\0';
|
||||
fclose(InFile);
|
||||
|
||||
if ((ReadText[0] == '#') && (ReadText[1] == '!'))
|
||||
{
|
||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p)
|
||||
{
|
||||
|
||||
if ((ReadText[0] == '#') && (ReadText[1] == '!')) {
|
||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p) {
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return ReadText;
|
||||
|
||||
return ReadText;
|
||||
}
|
||||
|
||||
/* read and scan a file for definitions */
|
||||
|
|
|
@ -14,20 +14,19 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
|||
{
|
||||
int ix;
|
||||
char ch, *cp;
|
||||
|
||||
|
||||
printf(Prompt);
|
||||
|
||||
|
||||
ix = 0;
|
||||
cp = 0;
|
||||
|
||||
|
||||
// If the first character is \n or \r, eat it
|
||||
ch = getch();
|
||||
if (ch == '\n' || ch == '\r')
|
||||
{
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
// And get the next character
|
||||
ch = getch();
|
||||
}
|
||||
|
||||
|
||||
while (ix++ < MaxLen) {
|
||||
|
||||
if (ch == 0x1B || ch == 0x03) { // ESC character or ctrl-c (to avoid problem with TeraTerm) - exit
|
||||
|
@ -51,7 +50,7 @@ void PlatformPutc(unsigned char OutCh, union OutputStreamInfo *Stream)
|
|||
{
|
||||
if (OutCh == '\n')
|
||||
putchar('\r');
|
||||
|
||||
|
||||
putchar(OutCh);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,20 +39,19 @@ void PlatformCleanup(Picoc *pc)
|
|||
char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
||||
{
|
||||
#ifdef USE_READLINE
|
||||
if (Prompt != NULL)
|
||||
{
|
||||
if (Prompt != NULL) {
|
||||
/* use GNU readline to read the line */
|
||||
char *InLine = readline(Prompt);
|
||||
if (InLine == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
Buf[MaxLen-1] = '\0';
|
||||
strncpy(Buf, InLine, MaxLen-2);
|
||||
strncat(Buf, "\n", MaxLen-2);
|
||||
|
||||
|
||||
if (InLine[0] != '\0')
|
||||
add_history(InLine);
|
||||
|
||||
|
||||
free(InLine);
|
||||
return Buf;
|
||||
}
|
||||
|
@ -60,7 +59,7 @@ char *PlatformGetLine(char *Buf, int MaxLen, const char *Prompt)
|
|||
|
||||
if (Prompt != NULL)
|
||||
printf("%s", Prompt);
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
return fgets(Buf, MaxLen, stdin);
|
||||
}
|
||||
|
@ -86,34 +85,32 @@ char *PlatformReadFile(Picoc *pc, const char *FileName)
|
|||
FILE *InFile;
|
||||
int BytesRead;
|
||||
char *p;
|
||||
|
||||
|
||||
if (stat(FileName, &FileInfo))
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
|
||||
ReadText = malloc(FileInfo.st_size + 1);
|
||||
if (ReadText == NULL)
|
||||
ProgramFailNoParser(pc, "out of memory\n");
|
||||
|
||||
|
||||
InFile = fopen(FileName, "r");
|
||||
if (InFile == NULL)
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
|
||||
BytesRead = fread(ReadText, 1, FileInfo.st_size, InFile);
|
||||
if (BytesRead == 0)
|
||||
ProgramFailNoParser(pc, "can't read file %s\n", FileName);
|
||||
|
||||
ReadText[BytesRead] = '\0';
|
||||
fclose(InFile);
|
||||
|
||||
if ((ReadText[0] == '#') && (ReadText[1] == '!'))
|
||||
{
|
||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p)
|
||||
{
|
||||
|
||||
if ((ReadText[0] == '#') && (ReadText[1] == '!')) {
|
||||
for (p = ReadText; (*p != '\r') && (*p != '\n'); ++p) {
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return ReadText;
|
||||
|
||||
return ReadText;
|
||||
}
|
||||
|
||||
/* read and scan a file for definitions */
|
||||
|
@ -122,10 +119,9 @@ void PicocPlatformScanFile(Picoc *pc, const char *FileName)
|
|||
char *SourceStr = PlatformReadFile(pc, FileName);
|
||||
|
||||
/* ignore "#!/path/to/picoc" .. by replacing the "#!" with "//" */
|
||||
if (SourceStr != NULL && SourceStr[0] == '#' && SourceStr[1] == '!')
|
||||
{
|
||||
SourceStr[0] = '/';
|
||||
SourceStr[1] = '/';
|
||||
if (SourceStr != NULL && SourceStr[0] == '#' && SourceStr[1] == '!') {
|
||||
SourceStr[0] = '/';
|
||||
SourceStr[1] = '/';
|
||||
}
|
||||
|
||||
PicocParse(pc, FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE, TRUE);
|
||||
|
|
Loading…
Reference in a new issue