Пример #1
0
// step = 1 - no  control. step = 2 - if no label or func found, throw err
vararray* compile(vararray* lines, vararray* labels, vararray* funcs, int step) {
    vararray* binary = var_ctor(sizeof(char), 128);

    int i = 0, j = 0; // i - line number; j - word number
    int type = 0;
    line_t* cur_line = NULL;
    char word[MAX_WORD_LENGTH];

    DBGPRINT("Lines: %d\n", (int)(lines->nmax));
    for (i = 0; i < (lines->nmax); i++) {
        j = 0;

        cur_line = (line_t*)var_get(lines, i);

        DBGPRINT("Label: %s\n", cur_line->words[j]);
        DBGPRINT("Next word: %s\n", cur_line->words[j+1]);

        DBGPRINT("Keyword: \"%s\"\n", cur_line->words[j]);
        type = get_type(cur_line->words[j]);
        DBGPRINT("Type: %d\n", type);

        if (type == FUNC) {
            put_lf(cur_line->words[j+1], funcs, binary->nmax);
            continue;
        }

        if (type == LABEL) {
            strcpy(word, cur_line->words[j]);
            word[strlen(word)-1] = '\0';
            put_lf(word, labels, binary->nmax);
            DBGPRINT("Label: %s\n", cur_line->words[j]);
            j++;
            DBGPRINT("Next word: %s\n", cur_line->words[j]);
            type = get_type(cur_line->words[j]);
        }

        if (type == EMPTY)
            continue;

        put_cmd(binary, cur_line, j, labels, funcs, step);
    }
    if (step < 2) {
        var_dtor(binary);
        return NULL;
    }
    else
        return binary;
}
Пример #2
0
/*
**	subtest_xenl(test_list, status, ch)
**
**	(xenl) eat newline glitch
*/
static void
subtest_xenl(
	struct test_list *t,
	int *state,
	int *ch)
{
	int i, j, k;

	if (over_strike) {
		/* test (xenl) on overstrike terminals */
		if (!can_go_home || !can_clear_screen) {
			ptextln("(xenl) Newline-glitch not tested, can't home cursor and clear.");
			generic_done_message(t, state, ch);
			return;
		}
		put_clear();
		/*
		   this test must be done in raw mode.  Otherwise UNIX will
		   translate CR to CRLF.
		*/
		if (stty_query(TTY_OUT_TRANS))
			tty_raw(1, char_mask);
		ptext("\nreset (xenl). Does ");
		i = char_count;
		put_str("not ignore CR, does ");
		k = char_count;
		put_str("not ignore LF");
		go_home();
		for (j = 0; j < columns; j++)
			put_this(' ');
		put_cr();
		for (j = 0; j < i; j++)
			putchp(' ');
		put_str("@@@\n@@");
		go_home();
		for (j = 0; j < columns; j++)
			put_this(' ');
		put_lf();
		for (j = 0; j < k; j++)
			putchp(' ');
		put_str("@@@\r@@");
		tty_set();
		go_home();
		put_newlines(4);
		sprintf(temp, "(xenl) Newline-glitch is %s in the data base",
			eat_newline_glitch ? "true" : "false");
		ptextln(temp);
	} else {
		/* test (xenl) when (os) is reset */
		if (!can_go_home) {
			ptextln("(xenl) Newline-glitch not tested, can't home cursor");
			generic_done_message(t, state, ch);
			return;
		}
		/* (xenl) test */
		put_clear();
		/*
		   this test must be done in raw mode.  Otherwise
		   UNIX will translate CR to CRLF.
		*/
		if (stty_query(TTY_OUT_TRANS))
			tty_raw(1, char_mask);
		for (j = 0; j < columns; j++)
			put_this(' ');
		put_cr();
		ptext("(xenl) should be set. Does not ignore CR");
		go_home();
		put_crlf();
		for (j = 0; j < columns; j++)
			put_this(' ');
		put_lf();	/* test (cud1) */
		ptext("(xenl) should be set. Ignores (cud1)");
		go_home();
		put_newlines(3);
		if (scroll_forward && cursor_down &&
			strcmp(scroll_forward, cursor_down)) {
			for (j = 0; j < columns; j++)
				put_this(' ');
			put_ind();	/* test (ind) */
			ptext("(xenl) should be set. Ignores (ind)");
			go_home();
			put_newlines(5);
		}
		tty_set();
		ptextln("If you don't see text above telling you to set it, (xenl) should be false");
		sprintf(temp, "(xenl) Newline-glitch is %s in the data base",
			eat_newline_glitch ? "true" : "false");
		ptextln(temp);
	}
	generic_done_message(t, state, ch);
}
Пример #3
0
/*
**	move_to(from-row, from-column, to-row, to-column, selection)
**
**	move the cursor from (rf, cf) to (rt, ct) using sel
*/
static void
move_to(
	int rf,
	int cf,
	int rt,
	int ct,
	int sel)
{
	char *s;

	if (sel & 16) {	/* use (cup) */
		s = TPARM_2(cursor_address, rt, ct);
		tputs(s, lines, tc_putch);
		return;
	}
	if (sel & 8) {	/* use (hpa) (vpa) */
		if (column_address) {
			s = TPARM_1(column_address, ct);
			tputs(s, 1, tc_putch);
			cf = ct;
		}
		if (row_address) {
			s = TPARM_1(row_address, rt);
			tputs(s, 1, tc_putch);
			rf = rt;
		}
	}
	if (sel & 4) {	/* parameterized relative cursor movement */
		if (parm_right_cursor)
			if (cf < ct) {
				s = TPARM_1(parm_right_cursor, ct - cf);
				tputs(s, ct - cf, tc_putch);
				cf = ct;
			}
		if (parm_left_cursor)
			if (cf > ct) {
				s = TPARM_1(parm_left_cursor, cf - ct);
				tputs(s, cf - ct, tc_putch);
				cf = ct;
			}
		if (parm_down_cursor)
			if (rf < rt) {
				s = TPARM_1(parm_down_cursor, rt - rf);
				tputs(s, rt - rf, tc_putch);
				rf = rt;
			}
		if (parm_up_cursor)
			if (rf > rt) {
				s = TPARM_1(parm_up_cursor, rf - rt);
				tputs(s, rf - rt, tc_putch);
				rf = rt;
			}
	}
	if (sel & 2) {
		if (cursor_left)
			while (cf > ct) {
				tc_putp(cursor_left);
				cf--;
			}
		/*
		   do vertical motion next.  Just in case cursor_down has a
		   side effect of changing the column.  This could happen if
		   the tty handler translates NL to CRNL.
		*/
		if (cursor_down)
			while (rf < rt) {
				tc_putp(cursor_down);
				rf++;
			}
		if (cursor_up)
			while (rf > rt) {
				tc_putp(cursor_up);
				rf--;
			}
		if (cursor_right)
			while (cf < ct) {
				tc_putp(cursor_right);
				cf++;
			}
	}
	/* last chance */
	if (rf > rt) {
		if (can_go_home) {	/* a bit drastic but ... */
			go_home();
			cf = 0;
			rf = 0;
		} else if (cursor_up) {
			while (rf > rt) {
				tc_putp(cursor_up);
				rf--;
			}
		}
	}
	if (ct == 0 && rt > rf) {
		put_crlf();
		cf = 0;
		rf++;
	}
	if (ct == 0 && cf != 0) {
		put_cr();
		cf = 0;
	}
	while (rf < rt) {
		put_lf();
		rf++;
	}
	while (cf > ct) {
		put_str("\b");
		cf--;
	}
	if (cursor_right) {
		while (cf < ct) {
			tc_putp(cursor_right);
			cf++;
		}
	} else {
		/* go ahead and trash my display */
		while (cf < ct) {
			putchp(' ');
			cf++;
		}
	}
}