Ejemplo n.º 1
0
int
ts_main(int argc, char *argv[])
{
	unsigned i, ntasks, n, skip;
	TaskInfo_t *ti, *info;
	bool enabled[NVCONS];
	bool check_cons = false;				// por defecto habilitar todas las consolas
	bool cursor = mt_cons_cursor(false);

	memset(enabled, 0, sizeof enabled);
	for ( i = 1 ; i < argc ; i++ )			// habilitar las consolas especificadas
	{
		unsigned cons = atoi(argv[i]);
		if ( cons < NVCONS )
			enabled[cons] = check_cons = true;
	}

	mt_cons_clear();
	cprintk(WHITE, BLUE, "%s", title);
	mt_cons_gotoxy(0, 24);
	cprintk(WHITE, BLUE, "%s", foot);
	skip = 0;
	do
	{
		info = GetTasks(&ntasks);
		for ( n = 0, i = 1, ti = info ; i < 24 && ntasks-- ; ti++ )
		{
			if ( (check_cons && !enabled[ti->consnum]) || n++ < skip )
				continue;
			mt_cons_gotoxy(0, i++);
			char namebuf[20];
			sprintf(namebuf, ti->protected ? "[%.16s]" : "%.18s", name(ti->task));
			cprintk(WHITE, BLACK, "%8x %-18s %u %10u %-9s %-18.18s", ti->task, namebuf, 
				ti->consnum, ti->priority, statename(ti->state), name(ti->waiting));
			if ( ti->is_timeout )
				cprintk(WHITE, BLACK, " %10u", ti->timeout);
			else
				mt_cons_clreol();
		}
		while ( i < 24 )
		{
			mt_cons_gotoxy(0, i++);
			mt_cons_clreol();
		}
		Free(info);
	}
	while ( getuser(&skip) );
	mt_cons_clear();
	mt_cons_cursor(cursor);	
	return 0;
}
Ejemplo n.º 2
0
int
camino_ns_main(int argc, char **argv)
{
	bool cursor;
	unsigned c;

	ncars = 0;
	pass_max = argc > 1 ? atoi(argv[1]): PASS_MAX;

	mt_cons_clear();
	cursor = mt_cons_cursor(false);

	init_road();

	Ready(ctl = CreateTask(control, 0, NULL, "control", DEFAULT_PRIO));

	mprint(OFFSET, MSGLINE,		"I: auto hacia la izquierda");
	mprint(OFFSET, MSGLINE+1,	"D: auto hacia la derecha");
	mprint(OFFSET, MSGLINE+2,	"S: salir");

	do
		switch ( c = mgetch() )
		{
			case 'I':
			case 'i':
				send_car(LEFTBOUND);
				break;
			case 'D':
			case 'd':
				send_car(RIGHTBOUND);
				break;
			default:
				break;
		}
	while ( c != 's' && c != 'S' ); 

	mprint(OFFSET, MSGLINE + 3, "Esperando que terminen los autos...");
	while ( ncars )
		Yield();

	DeleteTask(ctl);

	mt_cons_clear();
	mt_cons_cursor(cursor);

	return 0;
}
Ejemplo n.º 3
0
int
shell_main(int argc, char **argv)
{
	execpars ex;
	char line[BUFSIZE];
	struct cmdentry *cp;
	unsigned fg, bg;
	TaskInfo_t info;
	char *hist[NHIST];
	int pos, hfirst, hcur, hlast;
	bool wait, found;

	for ( hcur = 0 ; hcur < NHIST ; hcur++ )
		hist[hcur] = Malloc(BUFSIZE);
	hfirst = hcur = hlast = -1;

	mt_cons_getattr(&fg, &bg);
	GetInfo(CurrentTask(), &info);
	while ( true )
	{
		// Leer línea de comando eventualmente usando la historia
		mt_cons_setattr(LIGHTGRAY, BLACK);
		mt_cons_cursor(true);
		cprintk(LIGHTCYAN, BLACK, "\rMT%u> ", info.consnum);
		mt_cons_clreom();
		hcur = -1;
		*line = 0;
		do
		{
			switch ( pos = getline(line, sizeof line) )
			{
				case FIRST:
					if ( (hcur = hfirst) != -1)
						strcpy(line, hist[hcur]);
					break;
				case LAST:
					if ( (hcur = hlast) != -1 )
						strcpy(line, hist[hcur]);
					break;
				case BACK:
					if ( hcur == -1 )
						hcur = hlast;
					else
						if ( hcur != hfirst )
							hcur = prev(hcur);
					if ( hcur != -1 )
						strcpy(line, hist[hcur]);
					break;
				case FWD:
					if ( hcur != -1 )
					{
						if ( hcur == hlast )
						{
							hcur = -1;
							*line = 0;
						}
						else
						{
							hcur = next(hcur);
							strcpy(line, hist[hcur]);
						}
					}
					break;
			}
		}
		while ( pos < 0 );

		// Sacar espacios al final y detectar comando en background
		wait = true;
		while ( --pos >= 0 )
		{
			char c = line[pos];
			switch ( c )
			{
				case ' ':
				case '\t':
				case '\r':
				case '\n':
					line[pos] = 0;
					continue;
			}
			if ( c == '&' )
				wait = false;
			break;
		}

		// Separar en argumentos
		strcpy(ex.buf, line);
		if ( !wait )
			ex.buf[pos] = 0;		// quitamos el & final antes de separar
		ex.nargs = separate(ex.buf, ex.args, NARGS);
		if ( !ex.nargs )
			continue;
		ex.args[ex.nargs] = NULL;

		// Guardar línea en la historia si es distinta de la última
		if ( hlast == -1 )
		{
			hlast = hfirst = 0;
			strcpy(hist[hlast], line);
		}
		else if ( strcmp(hist[hlast], line) != 0 )
		{
			hlast = next(hlast);
			if ( hfirst == hlast )
				hfirst = next(hlast);
			strcpy(hist[hlast], line);
		}

		/* Comandos internos */
		if ( strcmp(ex.args[0], "help") == 0 )
		{
			printk("Comandos internos:\n");
			printk("\thelp\n");
			printk("\texit [status]\n");
			printk("\treboot\n");
			printk("Aplicaciones:\n");\
			for ( cp = cmdtab ; cp->name ; cp++ )
				printk("\t%s %s\n", cp->name, cp->params);
			continue;
		}

		if ( strcmp(ex.args[0], "exit") == 0 )
		{
			mt_cons_setattr(fg, bg);
			for ( hcur = 0 ; hcur < NHIST ; hcur++ )
				Free(hist[hcur]);
			return ex.nargs > 1 ? atoi(ex.args[1]) : 0;
		}

		if ( strcmp(ex.args[0], "reboot") == 0 )
		{
			*(short *) 0x472 = 0x1234;
			while ( true )
				outb(0x64, 0xFE);
		}

		/* Aplicaciones */
		found = false;
		for ( cp = cmdtab ; cp->name ; cp++ )
			if ( strcmp(ex.args[0], cp->name) == 0 )
			{
				found = true;
				ex.func = cp->func;
				if ( wait )						// correr app y esperarla
				{
					int status;

					Task_t *t = CreateTask(attached_app, MAIN_STKSIZE, &ex, ex.args[0], DEFAULT_PRIO);
					Attach(t);
					Ready(t);
					while ( !Join(t, &status) )
						;
					if ( status != 0 )
					{
						cprintk(LIGHTRED, BLACK, "\rStatus: %d\n", status);
						mt_cons_clreol();
					}
				}
				else							// correr app en background
				{
					Task_t *t = CreateTask(detached_app, MAIN_STKSIZE, &ex, ex.args[0], DEFAULT_PRIO);
					cprintk(LIGHTGREEN, BLACK, "\rTask: %x\n", t);
					mt_cons_clreol();
					Ready(t);
					Send(t, NULL, 0);			// esperar que copie los parámetros
				}
				break;
			}

		if ( !found )
			cprintk(LIGHTRED, BLACK, "Comando %s desconocido\n", ex.args[0]);
	}
}