Exemple #1
0
/* Page through a file like the more command
 *	cmdstr	command string to process
 *	ipwdstr	Initial PWD
 */
void rosh_more(const char *cmdstr)
{
    int fd;
    char filestr[ROSH_PATH_SZ];
    int cmdpos;
    int rows, cols;
    char *scrbuf;
    int ret;

    ROSH_DEBUG("CMD: '%s'\n", cmdstr);
    /* Initialization */
    filestr[0] = 0;
    cmdpos = 0;
    ret = getscreensize(1, &rows, &cols);
    if (ret) {
	ROSH_DEBUG("getscreensize() fail(%d); fall back\n", ret);
	ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
	/* If either fail, go under normal size, just in case */
	if (!rows)
	    rows = 20;
	if (!cols)
	    cols = 75;
    }
    ROSH_DEBUG("\tUSE ROWS='%d'\tCOLS='%d'\n", rows, cols);
    /* 32 bit align beginning of row and over allocate */
    scrbuf = malloc(rows * ((cols+3)&(INT_MAX - 3)));
    if (!scrbuf)
	return;

    /* skip the first word */
    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
    if (strlen(filestr) > 0) {
	/* There is no need to mess up the console if we don't have a
	   file */
	rosh_console_raw();
	while (strlen(filestr) > 0) {
	    printf("--File = '%s'\n", filestr);
	    fd = open(filestr, O_RDONLY);
	    if (fd != -1) {
		rosh_more_fd(fd, rows, cols, scrbuf);
		close(fd);
	    } else {
		rosh_error(errno, "more", filestr);
		errno = 0;
	    }
	    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
	}
	rosh_console_std();
    }
    free(scrbuf);
}				/* rosh_more */
Exemple #2
0
/* Page through a file like the more command
 *	cmdstr	command string to process
 *	ipwdstr	Initial PWD
 */
void rosh_more(const char *cmdstr)
{
    int fd;
    char filestr[ROSH_PATH_SZ];
    int cmdpos;
    int rows, cols;

    ROSH_DEBUG("CMD: '%s'\n", cmdstr);
    /* Initialization */
    filestr[0] = 0;
    cmdpos = 0;
    if (getscreensize(1, &rows, &cols)) {
	ROSH_DEBUG("getscreensize() fail; fall back\n");
	ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
	/* If either fail, go under normal size, just in case */
	if (!rows)
	    rows = 20;
	if (!cols)
	    cols = 75;
    }
    ROSH_DEBUG("\tUSE ROWS='%d'\tCOLS='%d'\n", rows, cols);

    /* skip the first word */
    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
    if (strlen(filestr) > 0) {
	/* There is no need to mess up the console if we don't have a
	   file */
	rosh_console_raw();
	while (strlen(filestr) > 0) {
	    printf("--File = '%s'\n", filestr);
	    fd = open(filestr, O_RDONLY);
	    if (fd != -1) {
		rosh_more_fd(fd, rows, cols);
		close(fd);
	    } else {
		rosh_error(errno, "more", filestr);
		errno = 0;
	    }
	    cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
	}
	rosh_console_std();
    }
}				/* rosh_more */