Пример #1
0
void slip_stop(slipconn *sc)
{
	interface_stop(sc);
	slip_release(sc);
}
Пример #2
0
int main(int argc, char *argv[])
{
	pSlip slip;
	char *buff;
	int32_t bufflen = 1024;

	FILE *fp = stdin;

	if (argc == 2)
	{
		fp = fopen(argv[1], "rt");
		assert(fp != NULL);

		fseek(fp, 0x0L, SEEK_END);
		bufflen = ftell(fp);
		fseek(fp, 0x0L, SEEK_SET);
	}

	buff = malloc(bufflen+16);

	slip = slip_init();
	assert(slip != NULL);

	printf("\nWelcome to bootstrap slip. Use ctrl-c to exit.\n");

	while (slip->running == SLIP_RUNNING)
	{
		char *p;

		pSlipObject obj;

		printf("> ");
		fflush(stdout);

		memset(buff, 0x0, bufflen+1);
		fflush(stdout);
		fread(buff, 1, bufflen, fp);

		// echo if script
		if (fp != stdin)
			printf("%s", buff);

		fflush(stdout);

		if (buff[0] != 0)
		{
			if ( TokeniseBuffer(slip, buff, strlen(buff)) == 0)
			{
				while (obj != NULL && slip->running == SLIP_RUNNING)
				{
					obj = slip_read(slip);
					if (slip->running == SLIP_RUNNING && obj != NULL)
					{
						obj = slip_evaluate(slip, obj);
						if (slip->running == SLIP_RUNNING && obj != NULL)
							slip_write(slip, obj);
						printf("\n");
					}
				}
			}
			else
				printf("tokenise buffer failed\n");
		}
		else
			slip->running = SLIP_SHUTDOWN;
	};

	if (slip->running == SLIP_SHUTDOWN)
		printf("\nThank you.\n");

	slip_release(slip);

	if (fp != stdin)
		fclose(fp);

	return 0;
}