Esempio n. 1
0
const char *tstring (void)
{
	const char *t;
	char *c;

	t = tnext ();
	if (!t)
		return NULL;
	if (*t != '"')
		return t;

	strcpy (tstringbuf, t+1);
	do {
		t = tnext ();
		if (!t)
		{
			simlog (SLC_DEBUG, "Parse error after '%s'", tstringbuf);
			return NULL;
		}
		strcat (tstringbuf, " ");
		strcat (tstringbuf, t);
		c = strchr (tstringbuf, '"');
	} while (c == NULL);
	*c = '\0';
	return tstringbuf;
}
Esempio n. 2
0
/**
 * Read the next token and interpret it as a constant.
 * Return its value.
 */
uint32_t tconst (void)
{
	const char *t = tnext ();
	uint32_t i;

	/* If no value is given, default to 0. */
	if (!t)
		return 0;

	/* Interpret certain fixed strings */
	if (teq (t, "on") || teq (t, "high") || teq (t, "active"))
		return 1;
	if (teq (t, "off") || teq (t, "low") || teq (t, "inactive"))
		return 0;

	/* Dollar sign indicates a variable expansion */
	if (*t == '$')
	{
		if (isdigit (t[1]))
			return conf_read_stack (t[1] - '0');
		else
			return conf_read (t+1);
	}

	/* TODO : Builtin strings */

	/* Anything else is interpreted as a C-formatted number. */
	i = strtoul (t, NULL, 0);

	/* Optional modifiers that can occur after the number */
	t = tnext ();
	if (t)
	{
		if (teq (t, "ms"))
			;
		else if (teq (t, "secs"))
			i *= 1000;
		else
			tunget (t);
	}
	return i;
}
Esempio n. 3
0
END_TEST

START_TEST (tryalloc_iterate_memory)
{
    void * allocs[10];
    try {
        for(int i = 0; i < 10; i++)
            allocs[i] = tmalloc(10);
        throw((void *)0x01);
    }
    catch(e, m) {
        int i = 0;
        while(m != NULL)
        {
            ck_assert_ptr_eq(tvalue(m), allocs[i]);
            i++;
            m = tnext(m);
        }
    }
    
}
Esempio n. 4
0
/**
 * Read the next token, which must be a signal name.
 * Currently, this must be the last token in the command.
 * The general format is <type> <number>.
 */
uint32_t tsigno (void)
{
	const char *t = tnext ();
	uint32_t signo;

	if (teq (t, "sol"))
		signo = SIGNO_SOL;
	else if (teq (t, "zerocross"))
		signo = SIGNO_ZEROCROSS;
	else if (teq (t, "triac"))
		signo = SIGNO_TRIAC;
	else if (teq (t, "lamp"))
		signo = SIGNO_LAMP;
	else if (teq (t, "sol_voltage"))
		signo = SIGNO_SOL_VOLTAGE;
	else if (teq (t, "ac_angle"))
		signo = SIGNO_AC_ANGLE;
	else
		return 0;
	signo += tconst ();
	return signo;
}
bool Criadouro::run(priority_queue< pair<Time,Evento*> >& fila_de_eventos){
    cout << "Criadouro" << endl;
    Time tnext(tnow.medida + Distribuicao::expo(media));
    int percent, remetente, destinatario;
    percent = rand()%100;

    if(percent < percent_for_LL){
        remetente    = LOCAL;
        destinatario = LOCAL;
        local.receber(new Mensagem(remetente,destinatario, tnow), fila_de_eventos);
    }
    else{
        percent-= percent_for_LL;
        if(percent < percent_for_LR){
            remetente    = LOCAL;
            destinatario = REMOTO;
            local.receber(new Mensagem(remetente,destinatario, tnow),fila_de_eventos);
        }
        else{
            percent-= percent_for_LR;
            if(percent < percent_for_RL){
                remetente    = REMOTO;
                destinatario = LOCAL;
                remoto.receber(new Mensagem(remetente,destinatario, tnow),fila_de_eventos);
            }
            else{
                remetente    = REMOTO;
                destinatario = REMOTO;
                remoto.receber(new Mensagem(remetente,destinatario, tnow),fila_de_eventos);
            }
        }
    }

    fila_de_eventos.push(make_pair(tnext, new Criadouro(tnext, this->local, this->remoto)));
    return true;
}
Esempio n. 6
0
/**
 * Parse and execute a script command.
 */
void exec_script (char *cmd)
{
	const char *t;
	uint32_t v, count;

	tlast = NULL;

	/* Blank lines and comments are ignored */
	t = tfirst (cmd);
	if (!t)
		return;
	if (*t == '#')
		return;

	/*********** capture [subcommand] [args...] ***************/
	if (teq (t, "capture"))
	{
		struct signal_expression *ex;

		t = tnext ();
		if (teq (t, "start"))
		{
			ex = texpr ();
			signal_capture_start (ex);
		}
		else if (teq (t, "stop"))
		{
			ex = texpr ();
			signal_capture_stop (ex);
		}
		else if (teq (t, "debug"))
		{
		}
		else if (teq (t, "file"))
		{
			t = tnext ();
			signal_capture_set_file (t);
		}
		else if (teq (t, "add"))
		{
			signal_capture_add (tsigno ());
		}
		else if (teq (t, "del"))
		{
			signal_capture_del (tsigno ());
		}
	}

	/*********** set [var] [value] ***************/
	else if (teq (t, "set"))
	{
		t = tnext ();
		v = tconst ();
		conf_write (t, v);
	}
	/*********** p/print [var] ***************/
	else if (teq (t, "p") || teq (t, "print"))
	{
		v = tconst ();
		simlog (SLC_DEBUG, "%d", v);
	}
	/*********** include [filename] ***************/
	else if (teq (t, "include"))
	{
		t = tnext ();
		exec_script_file (t);
	}
	/*********** sw [id] ***************/
	else if (teq (t, "sw"))
	{
		v = tsw ();
		count = tconst ();
		if (count == 0)
			count = 1;
		while (count > 0)
		{
			sim_switch_depress (v);
			count--;
		}
	}
	/*********** swtoggle [id] ***************/
	else if (teq (t, "swtoggle"))
	{
		v = tsw ();
		count = tconst ();
		if (count == 0)
			count = 1;
		while (count > 0)
		{
			sim_switch_toggle (v);
			count--;
		}
	}
	/*********** key [keyname] [switch] ***************/
	else if (teq (t, "key"))
	{
		t = tnext ();
		v = tsw ();
		simlog (SLC_DEBUG, "Key '%c' = %s", *t, names_of_switches[v]);
		sim_key_install (*t, v);
	}
	/*********** push [value] ***************/
	else if (teq (t, "push"))
	{
		v = tconst ();
		conf_push (v);
	}
	/*********** pop [argcount] ***************/
	else if (teq (t, "pop"))
	{
		v = tconst ();
		conf_pop (v);
	}
	/*********** sleep [time] ***************/
	else if (teq (t, "sleep"))
	{
		v = tconst ();
		simlog (SLC_DEBUG, "Sleeping for %d ms", v);
		v /= IRQS_PER_TICK;
		do {
			task_sleep (TIME_16MS);
		} while (--v > 0);
		simlog (SLC_DEBUG, "Awake again.", v);
	}
	/*********** exit ***************/
	else if (teq (t, "exit"))
	{
		sim_exit (0);
	}
}
Esempio n. 7
0
/**
 * Parse a complex expression and return a
 * signal_expression that describes it.
 */
struct signal_expression *texpr (void)
{
	struct signal_expression *ex, *ex1, *ex2;
	const char *t;

	t = tnext ();
	if (!t)
		return NULL;

	ex = expr_alloc ();
	if (teq (t, "at"))
	{
		ex->op = SIG_TIME;
		ex->u.timer = tconst ();
	}
	else if (teq (t, "after"))
	{
		ex->op = SIG_TIMEDIFF;
		ex->u.timer = tconst ();
	}
	else
	{
		tunget (t);
		ex->op = SIG_SIGNO;
		ex->u.signo = tsigno ();
		simlog (SLC_DEBUG, "Signo changed = 0x%X\n", ex->u.signo);

		t = tnext ();
		if (t)
		{
			if (teq (t, "is"))
			{
				ex1 = ex;

				ex2 = expr_alloc ();
				ex2->op = SIG_CONST;
				ex2->u.value = tconst ();

				ex = expr_alloc ();
				ex->op = SIG_EQ;
				ex->u.binary.left = ex1;
				ex->u.binary.right = ex2;
			}
		}
	}

	t = tnext ();
	if (t)
	{
		ex1 = ex;
		ex2 = texpr ();
		ex = expr_alloc ();
		ex->u.binary.left = ex1;
		ex->u.binary.right = ex2;
		if (teq (t, "and"))
			ex->op = SIG_AND;
		else if (teq (t, "or"))
			ex->op = SIG_OR;
	}

	return ex;
}
Esempio n. 8
0
static void tty_init(void)
{
	int fd[2];
	pid_t pid;

	if (pipe(fd) < 0) {
		perror("pipe");
		exit(1);
	}

	pid = fork();
	if (pid == -1) {
		perror("fork");
		exit(1);
	}

	if (pid == 0) {
		close(fd[0]);
		dup2(fd[1], 1);
		execl("/usr/lib/tchelp", "tchelp", "li#co#cm$ce$cd$cl$",
		      NULL);
		_exit(1);
	}
	close(fd[1]);

	if (read(fd[0], ival,sizeof(int)) != sizeof(int)) {
		perror("tcread");
		exit(1);
	}
	if (ival[0] == 0)
		exit(1);

	if (read(fd[0], ival + 1 ,2 * sizeof(int)) != 2 * sizeof(int)) {
		perror("tcread");
		exit(1);
	}
	/* Don't need space for the two integer values reported */
	ival[0] -= 2 * sizeof(int);
	t_go = sbrk((ival[0] + 3) & ~3);
	if (t_go == (void *) -1) {
		perror("sbrk");
		exit(1);
	}
	if (read(fd[0], t_go, ival[0]) != ival[0]) {
		perror("tcread2");
		exit(1);
	}
	close(fd[0]);
	t_clreol = tnext(t_go);
	t_clreos = tnext(t_clreol);
	if (*t_clreos == 0)	/* No clr eos - try for clr/home */
		t_clreos++;	/* cl cap if present */

	if (!*t_go) {
		write(2, "sok: insufficient terminal control.\n", 36);
		exit(1);
	}

	if (tcgetattr(0, &tcsave) == 0) {
		atexit(is_done);
		memcpy(&tcnew, &tcsave, sizeof(struct termios));
		tcnew.c_cc[VMIN] = 1;
		tcnew.c_cc[VTIME] = 0;
		tcnew.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK);
		signal(SIGINT, quit_game);
		/* FIXME: handle stop/cont properly */
		signal(SIGTSTP, SIG_IGN);
		if (tcsetattr(0, TCSADRAIN, &tcnew))
			perror("tcsetattr");
	}
	if (ioctl(0, TIOCGWINSZ, &win)) {
		win.ws_col = 80;
		win.ws_row = 25;
	}
	if (win.ws_col > MAXCOLS)
		win.ws_col = MAXCOLS;
	left = (win.ws_col - MAP_W) / 2;
}