Пример #1
0
void requestParserDelete(requestParser_t parser) {
	requestParserImpl_t* pParser = PARSER(parser);
	if (pParser) {
		if (pParser->pCommand) {
			commandDelete(pParser->fallocator, pParser->pCommand);
		}
		FREE(pParser);
	}
}
Пример #2
0
/**+main **/
int main()
{	 uint i;
   char getcommand[maxlen];
   nativerand=1;
   printf("\nWelcome to Text Elite 1.4.\n");

   for(i=0;i<=lasttrade;i++) strcpy(tradnames[i],commodities[i].name);

   mysrand(12345);/* Ensure repeatability */

   galaxynum=1;	buildgalaxy(galaxynum);

   currentplanet=numforLave;                        /* Don't use jump */
   localmarket = genmarket(0x00,galaxy[numforLave]);/* Since want seed=0 */

   fuel=maxfuel;
   
#define PARSER(S) { char buf[0x10];strcpy(buf,S);parser(buf);}   
   
   PARSER("hold 20");         /* Small cargo bay */
   PARSER("cash +100");       /* 100 CR */
   PARSER("help");

#undef PARSER

   for(;;)
   { printf("\n\nCash :%.1f>",((float)cash)/10);
     gets(getcommand);
     parser(getcommand);
   } 

 
   /* 6502 Elite fires up at Lave with fluctuation=00
      and these prices tally with the NES ones.
      However, the availabilities reside in the saved game data.
      Availabilities are calculated (and fluctuation randomised)
      on hyperspacing
      I have checked with this code for Zaonce with fluctaution &AB 
      against the SuperVision 6502 code and both prices and availabilities tally.
   */
return(0);
}
Пример #3
0
/*
 * This is called when parserParse returns 0 indicating success;
 * Using the data captured by the parser we will use the
 * commands.h  interface to construct appropriate command to be
 * executed by the server.
 *
 */
command_t* requestParserGetCommandAndReset(requestParser_t parser, dataStream_t dataStream) {
	requestParserImpl_t* pParser = PARSER(parser);
	command_t* pCommand   = pParser->pCommand;
	u_int32_t newSize = dataStreamGetSize(dataStream) - pParser->requestSize;

	pParser->pCommand    = fallocatorMalloc(pParser->fallocator, sizeof(command_t));
	pParser->endOfLine   = 0;
	pParser->requestSize = 0;
	pParser->state       = parse_first;

	dataStreamTruncateFromStart(dataStream, newSize);
	return pCommand;
}
Пример #4
0
/* returns -1 on error, 1 if more input is required, 0 when parse is complete */
int requestParserParse(requestParser_t parser, dataStream_t dataStream) {
	requestParserImpl_t* pParser = PARSER(parser);
	char** tokens = 0;
	int    ntokens = 0, endOfLine = 0, parseResult = 0, returnValue = 0;

	IfTrue(pParser, ERR, "Null Parser Object");
	IfTrue(pParser->pCommand, ERR, "Null command object");

	if (pParser->state == parse_first) {
		endOfLine = dataStreamFindEndOfLine(dataStream);
		if (endOfLine <= 0) {
			returnValue = 1;
			goto OnSuccess;
		}
		pParser->endOfLine = endOfLine;
		tokens = tokenizeFirstLine(pParser->fallocator, dataStream, endOfLine, &ntokens);
		IfTrue(tokens, DEBUG, "Error getting tokens");
		parseResult = parseFirstLineRequest(pParser->fallocator, pParser, tokens, ntokens);
		if (parseResult < 0) {
			LOG(INFO, "parsing error %d\n", parseResult);
			goto OnError;
		}
		if (!isDataExpected(pParser)) {
			pParser->requestSize = endOfLine + 2;
			goto OnSuccess;
		}
		pParser->state = parse_data;
		pParser->requestSize = endOfLine + 2 + pParser->pCommand->dataLength + 2;
	}

	if (pParser->state == parse_data) {
		if (dataStreamGetSize(dataStream) < pParser->requestSize) {
			returnValue = 1;
			goto OnSuccess;
		}
		pParser->pCommand->dataStream = dataStreamSubStream(pParser->fallocator, dataStream, (pParser->endOfLine+2),
				                                            pParser->pCommand->dataLength);
		IfTrue(pParser->pCommand->dataStream, INFO, "Error creating data stream");
	}
	goto OnSuccess;
OnError:
	returnValue = -1;
OnSuccess:
	if (pParser) {
		cleanupTokens(pParser->fallocator, tokens, ntokens);
		tokens = 0;
	}
	return returnValue;
}