示例#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 */
示例#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 */
示例#3
0
文件: tcap.c 项目: ajaysusarla/cgol
static void tcapopen(void)
{
        char *t, *p;
        char tcbuf[1024];
        char *tv_stype;
        char err_str[72];
        int int_col, int_row;


        if ((tv_stype = getenv("TERM")) == NULL) {
                puts("Environment variable TERM not defined!");
                exit(EXIT_FAILURE);
        }

        if ((tgetent(tcbuf, tv_stype)) !=1) {
                sprintf(err_str, "Unknown terminal type %s!", tv_stype);
                puts(err_str);
                exit(EXIT_FAILURE);
        }

        /* Get screen size */
        getscreensize(&int_col, &int_row);
        term.t_nrow = int_row -1;
        term.t_ncol = int_col;

        if ((term.t_nrow <= 0)
            && (term.t_nrow = (short) tgetnum("li") == -1)) {
                puts("termcap entry incomplete (lines)");
                exit(EXIT_FAILURE);
        }

        if ((term.t_ncol <= 0)
            && (term.t_ncol = (short) tgetnum("co") == -1)) {
                puts("termcap entry incomplete (columns)");
                exit(EXIT_FAILURE);
        }

        term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
        term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;

        p = tcapbuf;
        t = tgetstr("pc", &p);
        if (t)
                PC = *t;
        else
                PC = 0;

        CL = tgetstr("cl", &p);
        CM = tgetstr("cm", &p);
        CE = tgetstr("ce", &p);
        if (CE != NULL)
                eolexists = TRUE;
        UP = tgetstr("up", &p);
        SE = tgetstr("se", &p);
        SO = tgetstr("so", &p);
        if (SO != NULL)
                revexists = TRUE;


        tioinit();
}
示例#4
0
int main(int argc, char *argv[])
{
    const char *cmdline;
    struct menu *m;
    int rows, cols;
    int i;

    (void)argc;

    parse_configs(argv + 1);

    /*
     * We don't start the console until we have parsed the configuration
     * file, since the configuration file might impact the console
     * configuration, e.g. MENU RESOLUTION.
     */
    start_console();
    if (getscreensize(1, &rows, &cols)) {
	/* Unknown screen size? */
	rows = 24;
	cols = 80;
    }

    /* Some postprocessing for all menus */
    for (m = menu_list; m; m = m->next) {
	if (!m->mparm[P_WIDTH])
	    m->mparm[P_WIDTH] = cols;

	/* If anyone has specified negative parameters, consider them
	   relative to the bottom row of the screen. */
	for (i = 0; i < NPARAMS; i++)
	    if (m->mparm[i] < 0)
		m->mparm[i] = max(m->mparm[i] + rows, 0);
    }

    cm = start_menu;

    if (!cm->nentries) {
	fputs("Initial menu has no LABEL entries!\n", stdout);
	return 1;		/* Error! */
    }

    for (;;) {
	local_cursor_enable(true);
	cmdline = run_menu();

	if (clearmenu)
	    clear_screen();

	local_cursor_enable(false);
	printf("\033[?25h\033[%d;1H\033[0m", END_ROW);

	if (cmdline) {
	    uint32_t type = parse_image_type(cmdline);

	    execute(cmdline, type, false);
	    if (cm->onerror) {
		type = parse_image_type(cm->onerror);
		execute(cm->onerror, type, true);
	    }
	} else {
	    return 0;		/* Exit */
	}
    }
}
示例#5
0
static void
tcapopen(void)
{
	char *t, *p;
	char tcbuf[2048];
	char *tv_stype;
	char err_str[72];
	int i, j;
	static int already_open = 0;

	static const struct {
		char *name;
		char **data;
	} tc_strings[] = {
		 { "AL", &AL }		/* add p1 lines above cursor */
		,{ "DL", &DL }		/* delete p1 lines, begin at cursor */
		,{ "al", &al }		/* add line below cursor */
		,{ "ce", &CE }		/* clear to end of line */
		,{ "cl", &CL }		/* clear screen, cursor to home */
		,{ "cm", &CM }		/* move cursor to row p1, col p2 */
		,{ "cs", &CS }		/* set scrolling to rows p1 .. p2 */
		,{ "dl", &dl }		/* delete line */
		,{ "ke", &KE }		/* end keypad-mode */
		,{ "ks", &KS }		/* start keypad-mode */
		,{ "se", &SE }		/* end standout-mode */
		,{ "sf", &SF }		/* scroll forward 1 line */
		,{ "so", &SO }		/* start standout-mode */
		,{ "sr", &SR }		/* scroll reverse 1 line */
		,{ "te", &TE }		/* end cursor-motion program */
		,{ "ti", &TI }		/* initialize cursor-motion program */
#if	OPT_COLOR
		,{ "AF", &Sf }		/* set ANSI foreground-color */
		,{ "AB", &Sb }		/* set ANSI background-color */
		,{ "Sf", &Sf }		/* set foreground-color */
		,{ "Sb", &Sb }		/* set background-color */
		,{ "op", &orig_colors }	/* set to original color pair */
		,{ "oc", &orig_colors }	/* set to original colors */
#endif
#if	OPT_FLASH
		,{ "vb", &vb }		/* visible bell */
#endif
#if	OPT_VIDEO_ATTRS
		,{ "me", &ME }		/* turn off all attributes */
		,{ "md", &MD }		/* turn on bold attribute */
		,{ "us", &US }		/* underline-start */
		,{ "ue", &UE }		/* underline-end */
#endif
	};

	if (already_open) 
		return;

	if ((tv_stype = getenv("TERM")) == NULL)
	{
		puts("Environment variable TERM not defined!");
		ExitProgram(BADEXIT);
	}

	if ((tgetent(tcbuf, tv_stype)) != 1)
	{
		(void)lsprintf(err_str, "Unknown terminal type %s!", tv_stype);
		puts(err_str);
		ExitProgram(BADEXIT);
	}

	/* Get screen size from system, or else from termcap.  */
	getscreensize(&term.t_ncol, &term.t_nrow);
 
	if ((term.t_nrow <= 1) && (term.t_nrow=(short)tgetnum("li")) == -1) {
		term.t_nrow = 24;
	}

	if ((term.t_ncol <= 1) &&(term.t_ncol=(short)tgetnum("co")) == -1){
		term.t_ncol = 80;
	}

	/* are we probably an xterm?  */
	p = tcbuf;
	i_am_xterm = FALSE;
	if (strncmp(tv_stype, "xterm", sizeof("xterm") - 1) == 0) {
		i_am_xterm = TRUE;
		x_origin = 0;
		y_origin = 0;
	}
	else
		while (*p && *p != ':') {
			if (*p == 'x' 
			    && strncmp(p, "xterm", sizeof("xterm") - 1) == 0) {
				i_am_xterm = TRUE;
				x_origin = 0;
				y_origin = 0;
				break;
			}
			p++;
		}

	term.t_mrow =  term.t_nrow;
	term.t_mcol =  term.t_ncol;

	p = tcapbuf;
	for (i = 0; i < TABLESIZE(tc_strings); i++) {
		/* allow aliases */
		if (*(tc_strings[i].data) == 0)
		    *(tc_strings[i].data) = tgetstr(tc_strings[i].name, &p);
	}

#if HAVE_EXTERN_TCAP_PC
	t = tgetstr("pc", &p);
	if(t)
		PC = *t;
#endif

	if (SO != NULL)
		revexist = TRUE;

	if(CL == NULL || CM == NULL)
	{
		puts("Incomplete termcap entry\n");
		ExitProgram(BADEXIT);
	}

	if (CE == NULL) 	/* will we be able to use clear to EOL? */
		eolexist = FALSE;

	if (!CS || !SR) { /* some xterm's termcap entry is missing entries */
		if (i_am_xterm) {
			if (!CS) CS = "\033[%i%d;%dr";
			if (!SR) SR = "\033[M";
		}
	}

	if (CS && SR) {
		if (SF == NULL) /* assume '\n' scrolls forward */
			SF = "\n";
		term.t_scroll = tcapscroll_reg;
	} else if ((DL && AL) || (dl && al)) {
		term.t_scroll = tcapscroll_delins;
	} else {
		term.t_scroll = null_t_scroll;
	}
#if	OPT_COLOR
	if (orig_colors == 0)
		orig_colors = tgetstr("me", &p);
	set_palette(initpalettestr);
#endif
#if OPT_VIDEO_ATTRS
	if (US == 0 && UE == 0) {	/* if we don't have underline, do bold */
		US = MD;
		UE = ME;
	}
#endif

	for (i = TABLESIZE(keyseqs); i--; ) {
	    char *seq = tgetstr(keyseqs[i].capname, &p);
	    if (seq) {
		int len;
#define DONT_MAP_DEL 1
#if DONT_MAP_DEL
		/* NetBSD, FreeBSD, etc. have the kD (delete) function key
		    defined as the DEL char.  i don't like this hack, but
		    until we (and we may never) have separate system "map"
		    and "map!" maps, we can't allow this -- DEL has different
		    semantics in insert and command mode, whereas KEY_Delete
		    has the same semantics (whatever they may be) in both. 
		    KEY_Delete is the only non-motion system map, by the
		    way -- so the rest are benign in insert or command
		    mode.  */
		if (strcmp(seq,"\177") == 0)
		    continue;
#endif
		addtosysmap(seq, len = strlen(seq), keyseqs[i].code);
		/*
		 * Termcap represents nulls as octal 200, which is ambiguous
		 * (ugh).  To avoid losing escape sequences that may contain
		 * nulls, check here, and add a mapping for the strings with
		 * explicit nulls.
		 */
#define TCAP_NULL '\200'
		if (strchr(seq, TCAP_NULL) != 0) {
		    char temp[BUFSIZ];
		    (void)strcpy(temp, seq);
		    for (j = 0; j < len; j++)
			if (char2int(temp[j]) == TCAP_NULL)
			    temp[j] = '\0';
		    addtosysmap(temp, len, keyseqs[i].code);
		}
	    }
	}
#if OPT_XTERM
	addtosysmap("\033[M", 3, KEY_Mouse);
#if OPT_XTERM >= 3
	addtosysmap("\033[t", 3, KEY_text);
	addtosysmap("\033[T", 3, KEY_textInvalid);
#endif
#endif
	        
	if (p >= &tcapbuf[TCAPSLEN])
	{
		puts("Terminal description too big!\n");
		ExitProgram(BADEXIT);
	}
	ttopen();
	already_open = TRUE;
}
示例#6
0
文件: dwipe.c 项目: sTeeLM/dwipe1_5
int main(int argc, char *argv[])
{
	struct driveinfo drive;
	struct driveinfo *d = &drive;
    char buffer[4096] = {0};
    unsigned int index = 0;
    int ret, progress, progress_old;
    int rows, cols;

	(void)argc;
	(void)argv;

	openconsole(&dev_stdcon_r, &dev_stdcon_w);

    if (getscreensize(1, &rows, &cols)) {
        /* Unknown screen size? */
        rows = 24;
        cols = 80;
    }
    memset(buffer, 'A', 4096);

    memcpy(buffer, boot_code, sizeof(boot_code));  
    buffer[510] = 0x55;
    buffer[511] = 0xaa;
    
    printf("DWIPE version %s, by sTeeL <*****@*****.**>\n", __DWIPE_VERSION__);

    printf("remove USB DISK and hit ENTER key\n");

    get_key(stdin, 0);

	for (int disk = 0x80; disk < 0xff; disk++) {
		memset(d, 0, sizeof(struct driveinfo));
		d->disk = disk;
		get_drive_parameters(d);

		/* Do not print output when drive does not exists */
		if (errno_disk == -1 || !d->cbios)
			continue;

		if (errno_disk) {
			get_error("reading disk");
			continue;
		}

		printf("DISK 0x%X:\n", d->disk);
		printf("  C/H/S: %d heads, %d cylinders\n",
			d->legacy_max_head + 1, d->legacy_max_cylinder + 1);
		printf("         %d sectors/track, %d drives\n",
			d->legacy_sectors_per_track, d->legacy_max_drive);
		printf("  EDD:   ebios=%d, EDD version: %X\n",
			d->ebios, d->edd_version);
		printf("         %d heads, %d cylinders\n",
			(int) d->edd_params.heads, (int) d->edd_params.cylinders);
		printf("         %d sectors, %d bytes/sector, %d sectors/track\n",
			(int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector,
			(int) d->edd_params.sectors_per_track);
		printf("         Host bus: %s, Interface type: %s\n\n",
			d->edd_params.host_bus_type, d->edd_params.interface_type);

        progress_old = 0;

        print_progress(0, cols);
        for(index = 0; index < d->edd_params.sectors ; index += 8 ) {
            ret = dwipe_write_sectors(d, index, buffer, 8);
            if(ret == -1) {
                printf("ERROR!\n");
                continue;
            } else {
                progress = index * 100 / d->edd_params.sectors;
                if(progress != progress_old) {
                    progress_old = progress;
                    print_progress(progress, cols);
                }
            }
        }
        print_progress(100, cols);
        printf("\nDONE\n\n");

        
	}
    syslinux_reboot(0);
	return 0;
}
示例#7
0
文件: tcap.c 项目: k0gaMSX/uemacs
static void tcapopen(void)
{
	char *t, *p;
	char tcbuf[1024];
	char *tv_stype;
	char err_str[72];
	int int_col, int_row;

        if ((tv_stype = getenv("TERM")) == NULL) {
                puts("Environment variable TERM not defined!");
                exit(1);
        }

        if ((tgetent(tcbuf, tv_stype)) != 1) {
                sprintf(err_str, "Unknown terminal type %s!",
                        tv_stype);
                puts(err_str);
                exit(1);
        }

        /* Get screen size from system, or else from termcap.  */
        getscreensize(&int_col, &int_row);
        term.t_nrow = int_row - 1;
        term.t_ncol = int_col;

        if ((term.t_nrow <= 0)
            && (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
                puts("termcap entry incomplete (lines)");
                exit(1);
        }

        if ((term.t_ncol <= 0)
            && (term.t_ncol = (short) tgetnum("co")) == -1) {
                puts("Termcap entry incomplete (columns)");
                exit(1);
        }
#ifdef SIGWINCH
        term.t_mrow = MAXROW;
        term.t_mcol = MAXCOL;
#else
        term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
        term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;
#endif
        p = tcapbuf;
        t = tgetstr("pc", &p);
        if (t)
                PC = *t;
        else
                PC = 0;

        CL = tgetstr("cl", &p);
        CM = tgetstr("cm", &p);
        CE = tgetstr("ce", &p);
        UP = tgetstr("up", &p);
        SE = tgetstr("se", &p);
        SO = tgetstr("so", &p);
        if (SO != NULL)
                revexist = TRUE;

        if (tgetnum("sg") > 0) {	/* can reverse be used? P.K. */
                revexist = FALSE;
                SE = NULL;
                SO = NULL;
        }
        TI = tgetstr("ti", &p);	/* terminal init and exit */
        TE = tgetstr("te", &p);

        if (CL == NULL || CM == NULL || UP == NULL) {
                puts("Incomplete termcap entry\n");
                exit(1);
        }

        if (CE == NULL)	/* will we be able to use clear to EOL? */
                eolexist = FALSE;
#if SCROLLCODE
        CS = tgetstr("cs", &p);
        SF = tgetstr("sf", &p);
        SR = tgetstr("sr", &p);
        DL = tgetstr("dl", &p);
        AL = tgetstr("al", &p);

        if (CS && SR) {
                if (SF == NULL)	/* assume '\n' scrolls forward */
                        SF = "\n";
                term.t_scroll = tcapscroll_reg;
        } else if (DL && AL) {
                term.t_scroll = tcapscroll_delins;
        } else {
                term.t_scroll = NULL;
        }
#endif

        if (p >= &tcapbuf[TCAPSLEN]) {
                puts("Terminal description too big!\n");
                exit(1);
        }
	ttopen();
}