Ejemplo n.º 1
0
int until(int laddr1, int laddr2, int under_glob)
	{
	register int cnt, status;
	register char *lp_save;
	int condition;

	if(laddr1 <= 0)
		return(ERROR5);

	if(*lp >= '0'  &&  *lp <= '9')
		cnt = getint();
	else
		cnt = -1;

	if((condition = get_cond()) < 0)
		return(ERROR5);

	if(condition != NOT_TRUE_OR_FALSE)
		cc_reg = !condition;

	curln = laddr1;
	lp_save = lp;
	for(curln = laddr1 ; curln <= laddr2 ; ++curln) {
		status = OK;
		while((cnt >= 0 ? --cnt : 1) >= 0  &&  status == OK  &&  cc_reg != condition) {
			lp = lp_save;
			status = exec_line(under_glob, 1);
			}
		}
	--curln;

	lp = "\n"; /* Force main to fetch a new line */
	return(OK);
	}
Ejemplo n.º 2
0
// check serial in and handle the character
void read_line(void)
{
	if (serial_available()) {
		uint8_t c;
		c = serial_read();
		if (line_pos >= cols - 1) {
			exec_line();
			reset_line();
			char_to_line(c);
		} else if (c == '\n') {
			// ignore '\n' 
		} else if (c == '\r') {
			exec_line();
			reset_line();
		} else {
			char_to_line(c);
		}
	}
}
Ejemplo n.º 3
0
void exec_on(const char *var)
{
	int i, find = 0;
	for(i = 0; i < onscount; i++) {
		if(strcmp(ons[i].argv[0], var) == 0 ||
			(!find && strcmp(ons[i].argv[0], "X") == 0)) {

			find = 1;
			exec_line(ons[i].argc - 1, &ons[i].argv[1]);
		}
	}
}
Ejemplo n.º 4
0
int		do_exec_eval(t_param *param, char *seq, char **line)
{
  int		res;
  int		i;

  res = 0;
  seq = line[0];
  xsfree(line);
  line = my_str_to_wordtab_light(seq, build_delimiters_tab("&&", 0));
  i = -1;
  while (line[++i])
    {
      res = exec_line(param, line[i]);
      if (res)
	{
	  xsfree(line);
	  return (res);
	}
    }
  xsfree(line);
  return (res);
}
Ejemplo n.º 5
0
void
lsh_exec(lsh_t *lsh)
{
#ifdef WITH_READLINE
	int ret;
	char *line, *s;
#endif

	RiBegin(RI_NULL);

#ifdef WITH_READLINE
	while (1) {
		printf("Example usage:\n");
		printf("lsh: file RIBFILE  -> specify RIB file to render\n");
		printf("lsh: render        -> start rendering\n");
		printf("\n");

		line = readline("lsh: ");

		if (!line) break;

		s = stripwhite(line);

		if (*s) {
			add_history(s);
			ret = exec_line(s);
			if (ret < 0) break;
		}

		free(line);
	}
#endif

	RiEnd();

	(void)lsh;		/* for gcc */
}
Ejemplo n.º 6
0
// Arduino master setup
void setup(void)
{
	// set font for the console window
	u8g.setFont(u8g_font_6x10);

	// set upper left position for the string draw procedure
	u8g.setFontPosTop();

	// calculate the number of rows for the display
	rows = u8g.getHeight() / u8g.getFontLineSpacing();
	if (rows > ROW_MAX)
		rows = ROW_MAX;

	// estimate the number of columns for the display
	cols = u8g.getWidth() / u8g.getStrWidth("m");
	if (cols > LINE_MAX - 1)
		cols = LINE_MAX - 1;

	clear_screen();		// clear screen
	delay(1000);		// do some delay
	serial_begin(115200);	// init serial
	exec_line();		// place the input buffer into the screen
	reset_line();		// clear input buffer
}
Ejemplo n.º 7
0
int main()
{
	char buf[64], *v[SZ];
	struct alias *a;
	int n, i, r, skip_actions;
	FILE *f;
	pthread_t rv, ks;

	ui_init();
	ui_animation(0);

	f = fopen("commands.desc", "r");
	if(f == NULL) {
		ui_print("failed to open commands.desc\n");
		goto end;
	}

	// parse command list
	while(fgets(buf, 64, f)) {
		for(i = 0, v[i] = strtok(buf, " \n");
			 v[i]; v[++i] = strtok(0, " \n"));
		parse_line(i, v);
	}
	fclose(f);

	// init bin
	for(i = 0;; ) {
		a = get_alias("bin", i++);
		if(!a) break;
		ui_bin_add_tag(a->str);
	}
	ui_bin_add_tag("timeout");

	// init options tip
	ui_tip_update(1, "Press the corresponding key to perform that function:");
	ui_tip_update(3, "<S> Handler Speed");
	ui_tip_update(4, "<R> Reset");
	ui_tip_update(5, "<Q> Quit");

	// init io
	r = io_init();
	ptsname_r(r, buf, 64);
	ui_print("pts name is: %s (%d)\n", buf, r);

	// init wait queue
	wait_queue_init();

	// init receiver
	pthread_create(&rv, NULL, receiver, NULL);

	// init keyserver
	pthread_create(&ks, NULL, keyserver, NULL);

again:
	ui_print("\n\nnew routine:\n");
	skip_actions = 0;
	for(wait_queue_init(), i = 0;
	 i < lscount; i++) {
		if(skip_actions && (!strcmp(lines[i].argv[0], "send")
					  || !strcmp(lines[i].argv[0], "wait")))
			continue;
		if(exec_line(lines[i].argc, lines[i].argv) < 0)
			skip_actions = 1;
	}
	wait_queue_deinit();
	if(!stop) goto again;

end:
	ui_deinit();
	io_deinit();
}
//The main telnet task
void telnet_task_main(void)
{
/*
	commands[0].command="help";
	commands[0].exec = &telnet_help;

	commands[1].command="echo";
	commands[1].exec = &telnet_echo;

	commands[2].command="time";
	commands[2].exec = &telnet_time;

	commands[3].command="quit";
	commands[3].exec = &telnet_quit;

	commands[4].command="memdump";
	commands[4].exec = &telnet_memdump;
*/
	connection_event.event_mask = ReadableOrException;
	telnet_handle = FILE_INVALID_HANDLE;
	socket_listen(HTONS(23), &telnet_connect_accept );

	unsigned short pos = 0;
	while(1)
	{
restart:
		while( ! file_get_next_event( &telnet_handle, 1, &connection_event) )
		{
			task_yield();
		}
		if( connection_event.event & Exception )
		{
//#ifdef __DEBUG
			puts("\r\nTelnet: Closing connection");
//#endif
			file_close( telnet_handle );
			telnet_handle = FILE_INVALID_HANDLE;
			pos = 0;
			optneg_mode = 0;
			goto restart;
		}

		unsigned short avail = buffer_available(&telnet_receive_buffer);
		char* rd_buf = buffer_read_ptr(&telnet_receive_buffer);
		while( pos < avail)//if avail == 1, rd_buf[0] is the last char we can read
		{
			unsigned char c = rd_buf[pos];
			if( pos == REC_BUF_SIZE-1 )
			{
				//buffer is full, but no CR/LF seen yet... what to do?
				//either discard line, or pretend the last char was \r ??
				c = '\r';
			}

			switch(c)
			{
				case TELNET_IAC:
					if( avail - pos > 2 )
					{
						//buf[pos+1] = will/wont/do/dont
						//buf[pos+2] = option
						switch( (unsigned char) rd_buf[pos+2] )
						{
							case TELNET_ECHO:
								switch( (unsigned char) rd_buf[pos+1] )
								{
									case TELNET_DO:
										//other end wants us to echo
										telnet_mode |= MODE_ECHO;
										break;
									case TELNET_DONT:
										//other end demands we don't echo
										telnet_mode &= ~MODE_ECHO;
										break;
								}
								break;
						}
						//remove 3 chars from buffer
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 3 );
						avail -= 3;
					}
					else
					{
						task_yield();
					}
					break;
				case '\r': // could be \r\n , \r\0 or just \r on its own
					pos++;
					if( telnet_mode & MODE_ECHO)
					{
						file_puts(CRLF, telnet_handle);
					}
					//if there's a following character, and it's \n or \0, chomp it too.
					if( pos < avail && (rd_buf[pos+1] == '\n' || rd_buf[pos+1] == '\0')) pos++; 
					exec_line( rd_buf, rd_buf+pos ); //if read rd_buf[0], pos == 1 -> end = (rd_ptr + 1)

					buffer_seek( &telnet_receive_buffer, pos ); //free buffer
					rd_buf = buffer_read_ptr(&telnet_receive_buffer);

					pos = 0;
					avail = buffer_available(&telnet_receive_buffer);
					file_putchar('>', telnet_handle);
					break;
				case '\b':
				case 0x7f:
					puts("\r\ntel:backspace");
					if( pos > 0 ) //not the first character
					{
						if( telnet_mode & MODE_ECHO)
						{
							file_putchar('\b', telnet_handle);
							file_putchar(' ', telnet_handle);
							file_putchar('\b', telnet_handle);
						}
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos-1], 2 );
						avail-=2;
						pos--;
					}
					else
					{
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 1 );
						avail--;
					}
					break;
				default:
					if( c >= ' ' && c <='~' )
					{
						if( telnet_mode & MODE_ECHO)
						{
							file_putchar(c, telnet_handle);
							pos++;
						}
					}
					else
					{
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 1 );
						avail--;
					}
			}//end switch
		}//end while loop

		task_yield();
	}//end outer while
}