rendered paste bodyint cmd_loop(uboot_t *o, FILE *rx, FILE *tx) {
char done;
struct fd_set rfd;
struct fd_set efd;
struct timeval tv;
int x;
int max_fd;
char xbuf[1024];
char *buf;
int ii;
done = 0;
max_fd = 0;
if (!o || !rx) {
return errno = EINVAL;
}
if (tx) {
stdout = tx;
stderr = tx;
}
mbrSetArr[0].s_value=(void *)o->directory;
mbrSetArr[0].s_size=sizeof (o->directory);
mbrSetArr[1].s_value=(void *)o->kernel;
mbrSetArr[1].s_size=sizeof (o->kernel);
mbrSetArr[2].s_value=(void *)o->initrd;
mbrSetArr[2].s_size=sizeof (o->initrd);
mbrSetArr[3].s_value=(void *)o->command;
mbrSetArr[3].s_size=sizeof (o->command);
mbrSetArr[4].s_value=(void *)&o->mach;
mbrSetArr[4].s_size=sizeof (o->mach);
mbrSetArr[5].s_value=(void *)&o->loader;
mbrSetArr[5].s_size=sizeof (o->loader);
mbrSetArr[6].s_value=(void *)&o->heap;
mbrSetArr[6].s_size=sizeof (o->heap);
cmd_print (tx, "%s version %s, Copyright (C) 2005 Everett Coleman II\r\n", PACKAGE, VERSION);
cmd_print (tx, "%s comes with ABSOLUTELY NO WARRANTY; for details type `help warranty'\r\n", PACKAGE);
cmd_print (tx, "This is free software, and you are welcome to redistribute it\r\n");
cmd_print (tx, "under certain conditions; type `help conditions' for details.\r\n\r\n");
cmd_print (tx, "'load' code by Husam Senussi <husamsenussi@hotmail.com>, ported by me.\r\n\r\n");
memPhysReset ();
max_fd=fileno (rx);
while (!done) {
for (ii = 0; ii < 1024; ii++) {
xbuf[ii] = 0;
}
buf = 0;
cmd_print (tx, "oboot# "); // prompt
for (; tx;) {
tv.tv_sec = 1;
tv.tv_usec = 0;
x = 0;
FD_ZERO(&rfd);
FD_ZERO(&efd);
FD_SET(max_fd, &rfd);
FD_SET(max_fd, &efd);
x = select(max_fd + 1, &rfd, 0, &efd, &tv);
if (feof (rx) || (x < 0))
goto break_loop;
if (x && FD_ISSET(max_fd, &efd))
break;
if (x && FD_ISSET(max_fd, &rfd))
break;
if (wp_count ())
wp_check (tx);
} /* while (1) */
buf=fgets (xbuf, sizeof (xbuf), rx);
if (!buf && feof (rx)) {
break;
}
su_eatlws (&buf);
su_eattws (&buf);
if (!buf[0] || (buf[0] == '#'))
continue;
done=cmd_process (o, rx, tx, buf);
} /* while (!done) */
break_loop:
cmd_print (tx, "bye.\r\n");
memPhysReset ();
return 0;
} /* cmd_loop */