Beispiel #1
0
unsigned long jvs_textparser::readNext(void)
// reads next item in an open file
// if it's a number it attempts to convert and return it
// returns 0 on fails and set jvsError/jvsErrNum
{
	unsigned long bytes=0;
	unsigned long op=0;
	char *tmp=null;
	char *last=null;
	char cc;	// current char

	errorReset();

	memset(s_jvs_cur,0,255);
	s_jvs_cur[0]=' ';
	s_jvs_cur[1]='\0';

	if(!file_jvs_tp_fd)
	{
		errorSet(JVSERR_NOFILE,"No file has been opened.");
		return false;
	}

	if(!isEOF())
	{
		cc = fgetc(file_jvs_tp_fd);
		while( ! feof(file_jvs_tp_fd) ) 
		{
			// if it's an operator, then return that.
			if(op=isOperator(cc)) 
				return op;
			// space or newline?  don't append it; return if we have a string length already
			if( cc == '\n' || cc == ' ' )
			{
				if(trimStrLen(s_jvs_cur))
					return bytes;	
			} else
			{
				s_jvs_cur[bytes]=cc;
				s_jvs_cur[bytes+1]='\0';
				bytes++;
			}
			
			// get the next character
			cc = fgetc(file_jvs_tp_fd);
		} 
	} else { errorSet(JVSERR_EOF,"File end reached, no more input."); return false; }
	return true;
}
Beispiel #2
0
bool jvs3d_file_x::readList(int elem_per)
{
	unsigned long verts;
	int ret;
	readNext();
	if(isNumeric(s_jvs_cur))
	{
		verts = convertToNumber(s_jvs_cur);
		printf("%u",(int)verts);
		while(verts)
		{
			for(int x = 0; x<elem_per; x++)
			{
				ret = readNext();
				if( ret!=JVS_OP_SEMICOLON ) 
				{ errorSet(JVSERR_PARSE,"Expecting a semicolon."); return false; }
				printf("%s,",s_jvs_cur);
			}
			ret = readNext();
			if( ret != JVS_OP_COMMA ) return false;
			verts--;
		}
	} else return false;
	return true;
}
Beispiel #3
0
int parseList(token *tok, char **s)
{
	int firstLine, lastLine;
	int line;
	int print = 0;
	char *prog;

	firstLine = lastLine = 0;

	if (matchList(tok, s))
	{
		matchWhiteSpace(tok, s);
		if (matchNumber(tok, s))
		{
			firstLine = lastLine = tok->n;

			matchWhiteSpace(tok, s);
			if (matchComma(&testToken, s))
			{
				matchWhiteSpace(tok, s);
				if (matchNumber(tok, s))
					lastLine = tok->n;
				else return 0;
			}
		}

		prog = programGetProgram();
		if (!prog)
		{
			errorSet(ERROR_OUT_OF_MEMORY);
			return 0;
		}

		while (*prog)
		{
			line = atoi(prog);

			if (lastLine && (line > lastLine)) break;

			if (line >= firstLine) print = 1;

			do
			{
				if (print) putchar(*prog);
				++prog;
			} while (*prog != '\n');
			if (print) putchar(*prog);

			++prog;
		}

		return 1;
	}

	return 0;
}
Beispiel #4
0
static int deleteLine(int line)
{
	char *this, *next;
	char *prog;
	int size;

	prog = programGetProgram();
	if (!prog)
	{
		errorSet(ERROR_OUT_OF_MEMORY);
		return 0;
	}

	this = programFindLineNumber(line);
	if (!this)
	{
		errorSet(ERROR_UNKNOWN_LINE_NUMBER);
		return 0;
	}

		// Scan to the next line

	for (next = this; *next != '\n'; next++) ;
	++next;

		// Shuffle the program up, overwriting this line

	while (*next)
	{
		*this = *next;
		++this;
		++next;
	}
	*this = 0;

	size = programGetSize();

	memset(this, 0, PROGRAM_SIZEOF_DATA_SPACE - size);

	return 1;
}
Beispiel #5
0
static int insertLine(int line, char *text)
{
	char *lineStr;
	int lineLen = 0;
	int i;
	char *insertPoint = NULL;
	char *end = NULL;
	char *newEnd = NULL;
	char *prog = NULL;

	prog = programGetProgram();
	if (!prog)
	{
		errorSet(ERROR_OUT_OF_MEMORY);
		return 0;
	}

	deleteLine(line);
	errorSet(ERROR_OK);

	lineStr = itos(line);

	lineLen = strlen(text) + strlen(lineStr) + 2; // add 1 for space and 1 for NL

		// Find insertion point

	insertPoint = programFindNextLineNumber(line);
	if (!insertPoint)
	{
		errorSet(ERROR_OUT_OF_MEMORY);
		return 0;
	}

		// Find end of current program

	end = prog + strlen(prog) - 1;

		// Calculate proposed end of edited program

	newEnd = end + lineLen;
	if ((newEnd - prog) > PROGRAM_SIZEOF_DATA_SPACE)
	{
		errorSet(ERROR_OUT_OF_MEMORY);
		return 0;
	}

		// Shuffle rest of program down, must be backwards

	for (; end >= insertPoint; --end, --newEnd)
		*newEnd = *end;

		// Copy in this line

	for (i = 0; i < strlen(lineStr); i++)
		insertPoint[i] = lineStr[i];

	insertPoint[i] = ' ';

	insertPoint += i + 1;

	for (i = 0; i < strlen(text); i++)
		insertPoint[i] = text[i];

	insertPoint[i] = '\n';

	return 1;
}