Ejemplo n.º 1
0
resize_term(int ToLines, int ToCols)
{
    int result = OK;
    int was_stolen = (screen_lines - SP->_lines_avail);

    T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
       ToLines, ToCols,
       screen_lines, screen_columns));

    if (is_term_resized(ToLines, ToCols)) {
	int myLines = screen_lines;
	int myCols = screen_columns;

	if (ToLines > screen_lines) {
	    increase_size(myLines = ToLines, myCols, was_stolen);
	}

	if (ToCols > screen_columns) {
	    increase_size(myLines, myCols = ToCols, was_stolen);
	}

	if (ToLines < myLines ||
	    ToCols < myCols) {
	    decrease_size(ToLines, ToCols, was_stolen);
	}

	screen_lines = lines = ToLines;
	screen_columns = columns = ToCols;

	SP->_lines_avail = lines - was_stolen;

	if (SP->oldhash) {
	    FreeAndNull(SP->oldhash);
	}
	if (SP->newhash) {
	    FreeAndNull(SP->newhash);
	}
    }

    /*
     * Always update LINES, to allow for call from lib_doupdate.c which
     * needs to have the count adjusted by the stolen (ripped off) lines.
     */
    LINES = ToLines - was_stolen;
    COLS = ToCols;

    returnCode(result);
}
Ejemplo n.º 2
0
void
free_attrib2(BUFFER *bp, AREGION ** rpp)
{
    AREGION *ap = *rpp;
    AREGION *next = ap->ar_next;

    /* The caller already has found the right value for 'rpp',
     * so there is no need to call detach_attrib() to find it.
     */
    mark_buffers_windows(bp);
    ap->ar_region.r_attr_id = 0;

    beginDisplay();
#if OPT_HYPERTEXT
    FreeAndNull(ap->ar_hypercmd);
#endif
    if (ap == &selregion)
	selbufp = NULL;
    else if (ap == &startregion)
	startbufp = NULL;
    else
	free((char *) ap);
    endofDisplay();

    /* finally, delink the region */
    *rpp = next;
}
Ejemplo n.º 3
0
void
free_attribs(BUFFER *bp)
{
    AREGION *p, *q;

    beginDisplay();
    p = bp->b_attribs;
    while (p != NULL) {
	q = p->ar_next;
#if OPT_HYPERTEXT
	FreeAndNull(p->ar_hypercmd);
#endif
	if (p == &selregion)
	    selbufp = NULL;
	else if (p == &startregion)
	    startbufp = NULL;
	else
	    free((char *) p);
	p = q;
    }
    bp->b_attribs = NULL;

    free_line_attribs(bp);
    endofDisplay();
}
Ejemplo n.º 4
0
_nc_last_db(void)
{
    if (ThisDbList != 0) {
	FreeAndNull(ThisDbList);
    }
    ThisDbSize = 0;
}
Ejemplo n.º 5
0
_nc_free_tparm(void)
{
    if (out_buff != 0) {
	FreeAndNull(out_buff);
	out_size = 0;
	out_used = 0;
    }
}
Ejemplo n.º 6
0
static void
deleteTemp(void)
{
    register int n;

    for (n = 0; n < 2; n++) {
        if (myName[n] != 0) {
            TRACE(("deleteTemp #%d '%s'\n", n, myName[n]));
            (void) unlink(myName[n]);
            FreeAndNull(myName[n]);
        }
    }
}
Ejemplo n.º 7
0
_nc_freeall(void)
{
    WINDOWLIST *p, *q;
    static va_list empty_va;

    T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
    if (SP != 0) {
	if (SP->_oldnum_list != 0) {
	    FreeAndNull(SP->_oldnum_list);
	}
	if (SP->_panelHook.destroy != 0) {
	    SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel);
	}
    }
#endif
    if (SP != 0) {
	_nc_lock_global(curses);

	while (_nc_windows != 0) {
	    bool deleted = FALSE;

	    /* Delete only windows that're not a parent */
	    for (each_window(p)) {
		bool found = FALSE;

		for (each_window(q)) {
		    if ((p != q)
			&& (q->win._flags & _SUBWIN)
			&& (&(p->win) == q->win._parent)) {
			found = TRUE;
			break;
		    }
		}

		if (!found) {
		    if (delwin(&(p->win)) != ERR)
			deleted = TRUE;
		    break;
		}
	    }

	    /*
	     * Don't continue to loop if the list is trashed.
	     */
	    if (!deleted)
		break;
	}
	delscreen(SP);
	_nc_unlock_global(curses);
    }
Ejemplo n.º 8
0
static const char *
_nc_visbuf2n(int bufnum, const char *buf, int len)
{
    const char *vbuf = 0;
    char *tp;
    int count;

    if (buf == 0)
	return ("(null)");
    if (buf == CANCELLED_STRING)
	return ("(cancelled)");

    if (len < 0)
	len = (int) strlen(buf);

    count = len;
#ifdef TRACE
    vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len));
#else
    {
	static char *mybuf[NUM_VISBUFS];
	int c;

	if (bufnum < 0) {
	    for (c = 0; c < NUM_VISBUFS; ++c) {
		FreeAndNull(mybuf[c]);
	    }
	    tp = 0;
	} else {
	    mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
	    vbuf = tp = mybuf[bufnum];
	}
    }
#endif
    if (tp != 0) {
	int c;

	*tp++ = D_QUOTE;
	while ((--count >= 0) && (c = *buf++) != '\0') {
	    tp = VisChar(tp, UChar(c), NormalLen(len));
	}
	*tp++ = D_QUOTE;
	*tp = '\0';
    } else {
	vbuf = ("(_nc_visbuf2n failed)");
    }
    return (vbuf);
}
Ejemplo n.º 9
0
/*
 * catchup all groups in .newsrc
 */
void
catchup_newsrc_file(
	void)
{
	int i;
	struct t_group *group;

	for (i = 0; i < selmenu.max; i++) {
		group = &active[my_group[i]];
		group->newsrc.present = TRUE;
		FreeAndNull(group->newsrc.xbitmap);
		if (group->xmax > group->newsrc.xmax)
			group->newsrc.xmax = group->xmax;
		group->newsrc.xmin = group->newsrc.xmax + 1;
		group->newsrc.num_unread = 0;
		group->newsrc.xbitlen = 0;
	}
}
Ejemplo n.º 10
0
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL * termp)
{
    int rc = ERR;

    T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp));

    if (termp != 0) {
#ifdef USE_TERM_DRIVER
	TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
#endif
	TERMINAL *cur = (
#if USE_REENTRANT
			    NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG)
#else
			    cur_term
#endif
	);

	_nc_free_termtype(&(termp->type));
	if (termp == cur)
	    NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0);

	FreeIfNeeded(termp->_termname);
#if USE_HOME_TERMINFO
	if (_nc_globals.home_terminfo != 0) {
	    FreeAndNull(_nc_globals.home_terminfo);
	}
#endif
#ifdef USE_TERM_DRIVER
	if (TCB->drv)
	    TCB->drv->release(TCB);
#endif
	free(termp);

	rc = OK;
    }
    returnCode(rc);
}
Ejemplo n.º 11
0
/*
 * Mark a group as read
 * If art != NULL then we explicitly process each article thus
 * catching crossposts as well, otherwise we simply scrub the
 * bitmap and adjust the highwater mark.
 */
void
grp_mark_read(
	struct t_group *group,
	struct t_article *art)
{
	int i;

#ifdef DEBUG_NEWSRC
	debug_print_comment("c/C command");
#endif /* DEBUG_NEWSRC */

	if (art != NULL) {
		for_each_art(i)
			art_mark(group, &art[i], ART_READ);
	}

	FreeAndNull(group->newsrc.xbitmap);
	group->newsrc.xbitlen = 0;
	if (group->xmax > group->newsrc.xmax)
		group->newsrc.xmax = group->xmax;
	group->newsrc.xmin = group->newsrc.xmax + 1;
	group->newsrc.num_unread = 0;
}
Ejemplo n.º 12
0
/*
 * If we were writing to a pipe, invoke the read-process with stdin set to the
 * temporary-file.  This is used in the filter-buffer code, which needs both
 * read- and write-pipes.
 */
void
npflush(void)
{
    if (myCmds != 0) {
        if (myWrtr != 0) {
            int fd;
            static FILE *pp;

            (void) fflush(*myWrtr);
#if 0
            (void) fclose(*myWrtr);
            *myWrtr = fopen(myName[0], "r");
#else
            rewind(*myWrtr);
#endif
            fd = createTemp("r");
            pp = fdopen(fd, "r");
            myRead = &pp;
            *myPipe = readPipe(myCmds, fileno(*myWrtr), fd);
        }
        FreeAndNull(myCmds);
    }
}
Ejemplo n.º 13
0
static char *
sasl_auth_plain(
	char *user,
	char *pass)
{
	Gsasl *ctx = NULL;
	Gsasl_session *session;
	char *p = NULL;
	const char *mech = "PLAIN";

	if (gsasl_init(&ctx) != GSASL_OK) /* TODO: do this only once at startup */
		return p;
	if (gsasl_client_start(ctx, mech, &session) != GSASL_OK) {
		gsasl_done(ctx);
		return p;
	}
	gsasl_property_set(session, GSASL_AUTHID, user);
	gsasl_property_set(session, GSASL_PASSWORD, pass);
	if (gsasl_step64(session, NULL, &p) != GSASL_OK)
		FreeAndNull(p);
	gsasl_finish(session);
	gsasl_done(ctx);
	return p;
}
Ejemplo n.º 14
0
static void
hist_add(
	int w)
{
	char *p;
	char *tmp;
#if defined(MULTIBYTE_ABLE) && !defined(NO_LOCALE)
	int size = wcstombs(NULL, gl_buf, 0);

	tmp = my_malloc(size + 1);
	if (wcstombs(tmp, gl_buf, size) == (size_t) -1) {
		/* conversation failed */
		free(tmp);
		return;
	} else
		tmp[size] = '\0';
#else
	tmp = my_strdup(gl_buf);
#endif /* MULTIBYTE_ABLE && !NO_LOCALE */
	p = tmp;

	if (w == HIST_NONE)
		return;

	while (*p == ' ' || *p == '\t')		/* only save nonblank line */
		p++;

	if (*p) {
		input_history[w][hist_last[w]] = tmp;
		hist_last[w] = (hist_last[w] + 1) % HIST_SIZE;
		FreeAndNull(input_history[w][hist_last[w]]);	/* erase next location */
	} else	/* we didn't need tmp, so free it */
		free(tmp);

	hist_pos[w] = hist_last[w];
}
Ejemplo n.º 15
0
tgetent(char *bufp, const char *name)
{
    int errcode;
    int n;
    bool found_cache = FALSE;

    START_TRACE();
    T((T_CALLED("tgetent()")));

    _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);

    /*
     * In general we cannot tell if the fixed sgr0 is still used by the
     * caller, but if tgetent() is called with the same buffer, that is
     * good enough, since the previous data would be invalidated by the
     * current call.
     *
     * bufp may be a null pointer, e.g., GNU termcap.  That allocates data,
     * which is good until the next tgetent() call.  The conventional termcap
     * is inconvenient because of the fixed buffer size, but because it uses
     * caller-supplied buffers, can have multiple terminal descriptions in
     * use at a given time.
     */
    for (n = 0; n < TGETENT_MAX; ++n) {
	bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp);
	if (same_result) {
	    CacheInx = n;
	    if (FIX_SGR0 != 0) {
		FreeAndNull(FIX_SGR0);
	    }
	    /*
	     * Also free the terminfo data that we loaded (much bigger leak).
	     */
	    if (LAST_TRM != 0 && LAST_TRM != cur_term) {
		TERMINAL *trm = LAST_TRM;
		del_curterm(LAST_TRM);
		for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
		    if (LAST_TRM == trm)
			LAST_TRM = 0;
		CacheInx = n;
	    }
	    found_cache = TRUE;
	    break;
	}
    }
    if (!found_cache) {
	int best = 0;

	for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
	    if (LAST_SEQ < MyCache[best].sequence) {
		best = CacheInx;
	    }
	}
	CacheInx = best;
    }
    LAST_TRM = cur_term;
    LAST_SEQ = ++CacheSeq;

    PC = 0;
    UP = 0;
    BC = 0;
    FIX_SGR0 = 0;		/* don't free it - application may still use */

    if (errcode == 1) {

	if (cursor_left)
	    if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0)
		backspace_if_not_bs = cursor_left;

	/* we're required to export these */
	if (pad_char != NULL)
	    PC = pad_char[0];
	if (cursor_up != NULL)
	    UP = cursor_up;
	if (backspace_if_not_bs != NULL)
	    BC = backspace_if_not_bs;

	if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) {
	    if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
		if (FIX_SGR0 != exit_attribute_mode) {
		    free(FIX_SGR0);
		}
		FIX_SGR0 = 0;
	    }
	}
	LAST_BUF = bufp;
	LAST_USE = TRUE;

	SetNoPadding(SP);
	(void) baudrate();	/* sets ospeed as a side-effect */

/* LINT_PREPRO
#if 0*/
#include <capdefaults.c>
/* LINT_PREPRO
#endif*/

    }

#ifdef FREEBSD_NATIVE
    /*
     * This is a REALLY UGLY hack. Basically, if we originate with
     * a termcap source, try and copy it out.
     */
    if (bufp && _nc_termcap[0])
	strncpy(bufp, _nc_termcap, 1024);
#endif

    returnCode(errcode);
}
Ejemplo n.º 16
0
_nc_freeall(void)
{
    WINDOWLIST *p, *q;
    char *s;

    T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
    _nc_free_tparm();
    if (_nc_oldnums != 0) {
	FreeAndNull(_nc_oldnums);
    }
#endif
    if (SP != 0) {
	while (_nc_windows != 0) {
	    /* Delete only windows that're not a parent */
	    for (p = _nc_windows; p != 0; p = p->next) {
		bool found = FALSE;

		for (q = _nc_windows; q != 0; q = q->next) {
		    if ((p != q)
			&& (q->win._flags & _SUBWIN)
			&& (&(p->win) == q->win._parent)) {
			found = TRUE;
			break;
		    }
		}

		if (!found) {
		    delwin(&(p->win));
		    break;
		}
	    }
	}
	delscreen(SP);
    }

    del_curterm(cur_term);
    _nc_free_entries(_nc_head);
    _nc_get_type(0);
    _nc_first_name(0);
#if USE_WIDEC_SUPPORT
    FreeIfNeeded(_nc_wacs);
#endif
#if NO_LEAKS
    _nc_alloc_entry_leaks();
    _nc_captoinfo_leaks();
    _nc_comp_scan_leaks();
#endif

    if ((s = _nc_home_terminfo()) != 0)
	free(s);

    (void) _nc_printf_string(0, 0);
#ifdef TRACE
    (void) _nc_trace_buf(-1, 0);
#endif

#if HAVE_LIBDBMALLOC
    malloc_dump(malloc_errfd);
#elif HAVE_LIBDMALLOC
#elif HAVE_LIBMPATROL
    __mp_summary();
#elif HAVE_PURIFY
    purify_all_inuse();
#endif
    returnVoid;
}
Ejemplo n.º 17
0
resize_term(int ToLines, int ToCols)
{
    int result = OK;
    int was_stolen = (screen_lines - SP->_lines_avail);

    T((T_CALLED("resize_term(%d,%d) old(%d,%d)"),
       ToLines, ToCols,
       screen_lines, screen_columns));

    if (is_term_resized(ToLines, ToCols)) {
	int myLines = current_lines = screen_lines;
	int myCols = current_cols = screen_columns;

#ifdef TRACE
	if (_nc_tracing & TRACE_UPDATE)
	    show_window_sizes("before");
#endif
	if (ToLines > screen_lines) {
	    increase_size(myLines = ToLines, myCols, was_stolen);
	    current_lines = myLines;
	    current_cols = myCols;
	}

	if (ToCols > screen_columns) {
	    increase_size(myLines, myCols = ToCols, was_stolen);
	    current_lines = myLines;
	    current_cols = myCols;
	}

	if (ToLines < myLines ||
	    ToCols < myCols) {
	    decrease_size(ToLines, ToCols, was_stolen);
	}

	screen_lines = lines = ToLines;
	screen_columns = columns = ToCols;

	SP->_lines_avail = lines - was_stolen;

	if (SP->oldhash) {
	    FreeAndNull(SP->oldhash);
	}
	if (SP->newhash) {
	    FreeAndNull(SP->newhash);
	}
#ifdef TRACE
	if (_nc_tracing & TRACE_UPDATE) {
	    LINES = ToLines - was_stolen;
	    COLS = ToCols;
	    show_window_sizes("after");
	}
#endif
    }

    /*
     * Always update LINES, to allow for call from lib_doupdate.c which
     * needs to have the count adjusted by the stolen (ripped off) lines.
     */
    LINES = ToLines - was_stolen;
    COLS = ToCols;

    returnCode(result);
}
Ejemplo n.º 18
0
/*
 * Parse the newsrc sequence for the specified group
 */
static void
parse_bitmap_seq(
	struct t_group *group,
	char *seq)
{
	char *ptr;
	int sum = 0;
	long low = 0L;
	long high = 0L;
	long min, max;
	t_bool gotseq = FALSE;

	/*
	 * Skip possible non-numeric prefix
	 */
	ptr = seq;
	while (ptr && *ptr && (*ptr < '0' || *ptr > '9'))
		ptr++;

#ifdef DEBUG_NEWSRC
	{
		char buf[NEWSRC_LINE];
		sprintf(buf, "Parsing [%s%c %.*s]", group->name, SUB_CHAR(group->subscribed), (int) (NEWSRC_LINE - strlen(group->name) - 20), ptr);
		debug_print_comment(buf);
		debug_print_bitmap(group, NULL);
	}
#endif /* DEBUG_NEWSRC */

	if (ptr) {
		gotseq = TRUE;
		ptr = parse_get_seq(ptr, &low, &high);

		if (high < group->xmin - 1)
			high = group->xmin - 1;

		min = ((low <= 1) ? (high + 1) : 1);

		if (group->xmin > min)
			min = group->xmin;

		if (group->xmax > high)
			max = group->xmax;
		else
			max = high;		/* trust newsrc's max */

		FreeAndNull(group->newsrc.xbitmap);
		group->newsrc.xmax = max;
		group->newsrc.xmin = min;
		group->newsrc.xbitlen = (max - min) + 1;
		if (group->newsrc.xbitlen > 0) {
			group->newsrc.xbitmap = my_malloc(BITS_TO_BYTES(group->newsrc.xbitlen));
			NSETRNG1(group->newsrc.xbitmap, 0L, group->newsrc.xbitlen - 1L);
		}

		if (min <= high) {
			if (low > min)
				sum = low - min;
			else
				low = min;
			NSETRNG0(group->newsrc.xbitmap, low - min, high - min);
		}

		/*
		 * Pick up any additional articles/ranges after the first
		 */
		while (*ptr)
			ptr = parse_subseq(group, ptr, &low, &high, &sum);
	} else {
		FreeAndNull(group->newsrc.xbitmap);
		group->newsrc.xmax = group->xmax;
		if (group->xmin > 0)
			group->newsrc.xmin = group->xmin;
		else
			group->newsrc.xmin = 1;
		group->newsrc.xbitlen = (group->newsrc.xmax - group->newsrc.xmin) + 1;
		if (group->newsrc.xbitlen > 0) {
			group->newsrc.xbitmap = my_malloc(BITS_TO_BYTES(group->newsrc.xbitlen));
			NSETRNG1(group->newsrc.xbitmap, 0L, group->newsrc.xbitlen - 1L);
		}
/*
wait_message(2, "BITMAP Grp=[%s] MinMax=[%ld-%ld] Len=[%ld]\n",
	group->name, group->xmin, group->xmax, group->newsrc.xbitlen);
*/
	}

	group->newsrc.present = TRUE;

	if (gotseq) {
		if (group->newsrc.xmax > high)
			sum += group->newsrc.xmax - high;
	} else
		sum = (int) ((group->count >= 0) ? group->count : ((group->newsrc.xmax - group->newsrc.xmin) + 1));

	group->newsrc.num_unread = sum;
#ifdef DEBUG_NEWSRC
	debug_print_bitmap(group, NULL);
#endif /* DEBUG_NEWSRC */
}
Ejemplo n.º 19
0
_nc_first_db(DBDIRS * state, int *offset)
{
    bool cache_has_expired = FALSE;
    *state = dbdTIC;
    *offset = 0;

    T(("_nc_first_db"));

    /* build a blob containing all of the strings we will use for a lookup
     * table.
     */
    if (my_blob == 0 || (cache_has_expired = cache_expired())) {
	size_t blobsize = 0;
	const char *values[dbdLAST];
	struct stat *my_stat;
	int j, k;

	if (cache_has_expired)
	    free_cache();

	for (j = 0; j < dbdLAST; ++j)
	    values[j] = 0;

	/*
	 * This is the first item in the list, and is used only when tic is
	 * writing to the database, as a performance improvement.
	 */
	values[dbdTIC] = TicDirectory;

#if NCURSES_USE_DATABASE
#ifdef TERMINFO_DIRS
	values[dbdCfgList] = TERMINFO_DIRS;
#endif
#ifdef TERMINFO
	values[dbdCfgOnce] = TERMINFO;
#endif
#endif

#if NCURSES_USE_TERMCAP
	values[dbdCfgList2] = TERMPATH;
#endif

	if (use_terminfo_vars()) {
#if NCURSES_USE_DATABASE
	    values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce);
	    values[dbdHome] = _nc_home_terminfo();
	    (void) cache_getenv("HOME", dbdHome);
	    values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList);

#endif
#if NCURSES_USE_TERMCAP
	    values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2);
	    /* only use $TERMCAP if it is an absolute path */
	    if (values[dbdEnvOnce2] != 0
		&& *values[dbdEnvOnce2] != '/') {
		values[dbdEnvOnce2] = 0;
	    }
	    values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2);
#endif /* NCURSES_USE_TERMCAP */
	}

	for (j = 0; j < dbdLAST; ++j) {
	    if (values[j] == 0)
		values[j] = "";
	    blobsize += 2 + strlen(values[j]);
	}

	my_blob = malloc(blobsize);
	if (my_blob != 0) {
	    *my_blob = '\0';
	    for (j = 0; j < dbdLAST; ++j) {
		add_to_blob(values[j], blobsize);
	    }

	    /* Now, build an array which will be pointers to the distinct
	     * strings in the blob.
	     */
	    blobsize = 2;
	    for (j = 0; my_blob[j] != '\0'; ++j) {
		if (my_blob[j] == NCURSES_PATHSEP)
		    ++blobsize;
	    }
	    my_list = typeCalloc(char *, blobsize);
	    my_stat = typeCalloc(struct stat, blobsize);
	    if (my_list != 0 && my_stat != 0) {
		k = 0;
		my_list[k++] = my_blob;
		for (j = 0; my_blob[j] != '\0'; ++j) {
		    if (my_blob[j] == NCURSES_PATHSEP) {
			my_blob[j] = '\0';
			my_list[k++] = &my_blob[j + 1];
		    }
		}

		/*
		 * Eliminate duplicates from the list.
		 */
		for (j = 0; my_list[j] != 0; ++j) {
#ifdef TERMINFO
		    if (*my_list[j] == '\0')
			my_list[j] = strdup(TERMINFO);
#endif
		    for (k = 0; k < j; ++k) {
			if (!strcmp(my_list[j], my_list[k])) {
			    k = j - 1;
			    while ((my_list[j] = my_list[j + 1]) != 0) {
				++j;
			    }
			    j = k;
			    break;
			}
		    }
		}

		/*
		 * Eliminate non-existent databases, and those that happen to
		 * be symlinked to another location.
		 */
		for (j = 0; my_list[j] != 0; ++j) {
		    bool found = check_existence(my_list[j], &my_stat[j]);
#if HAVE_LINK
		    if (found) {
			for (k = 0; k < j; ++k) {
			    if (my_stat[j].st_dev == my_stat[k].st_dev
				&& my_stat[j].st_ino == my_stat[k].st_ino) {
				found = FALSE;
				break;
			    }
			}
		    }
#endif
		    if (!found) {
			k = j;
			while ((my_list[k] = my_list[k + 1]) != 0) {
			    ++k;
			}
			--j;
		    }
		}
		my_size = j;
		my_time = time((time_t *) 0);
	    } else {
		FreeAndNull(my_blob);
	    }
	    free(my_stat);
	}
Ejemplo n.º 20
0
static void
free_cache(void)
{
    FreeAndNull(my_blob);
    FreeAndNull(my_list);
}
Ejemplo n.º 21
0
NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0)
{
    int result = ERR;
    int maxpairs = 0, maxcolors = 0;

    T((T_CALLED("start_color(%p)"), (void *) SP_PARM));

    if (SP_PARM == 0) {
	result = ERR;
    } else if (SP_PARM->_coloron) {
	result = OK;
    } else {
	maxpairs = MaxPairs;
	maxcolors = MaxColors;
	if (reset_color_pair(NCURSES_SP_ARG) != TRUE) {
	    set_foreground_color(NCURSES_SP_ARGx
				 default_fg(NCURSES_SP_ARG),
				 NCURSES_SP_NAME(_nc_outch));
	    set_background_color(NCURSES_SP_ARGx
				 default_bg(NCURSES_SP_ARG),
				 NCURSES_SP_NAME(_nc_outch));
	}
#if !NCURSES_EXT_COLORS
	/*
	 * Without ext-colors, we cannot represent more than 256 color pairs.
	 */
	if (maxpairs > 256)
	    maxpairs = 256;
#endif

	if (maxpairs > 0 && maxcolors > 0) {
	    SP_PARM->_pair_limit = maxpairs;

#if NCURSES_EXT_FUNCS
	    /*
	     * If using default colors, allocate extra space in table to
	     * allow for default-color as a component of a color-pair.
	     */
	    SP_PARM->_pair_limit += (1 + (2 * maxcolors));
#endif
	    SP_PARM->_pair_count = maxpairs;
	    SP_PARM->_color_count = maxcolors;
#if !USE_REENTRANT
	    COLOR_PAIRS = maxpairs;
	    COLORS = maxcolors;
#endif

	    SP_PARM->_color_pairs = TYPE_CALLOC(colorpair_t, SP_PARM->_pair_limit);
	    if (SP_PARM->_color_pairs != 0) {
		SP_PARM->_color_table = TYPE_CALLOC(color_t, maxcolors);
		if (SP_PARM->_color_table != 0) {
		    SP_PARM->_color_pairs[0] = PAIR_OF(default_fg(NCURSES_SP_ARG),
						       default_bg(NCURSES_SP_ARG));
		    init_color_table(NCURSES_SP_ARG);

		    T(("started color: COLORS = %d, COLOR_PAIRS = %d",
		       COLORS, COLOR_PAIRS));

		    SP_PARM->_coloron = 1;
		    result = OK;
		} else if (SP_PARM->_color_pairs != 0) {
		    FreeAndNull(SP_PARM->_color_pairs);
		}
	    }
	} else {
	    result = OK;
	}
    }
    returnCode(result);
}
Ejemplo n.º 22
0
/*
 * Discard all set/clr customizations.
 */
void
vl_ctype_discard(void)
{
    FreeAndNull(ctype_sets);
    FreeAndNull(ctype_clrs);
}
Ejemplo n.º 23
0
/*
 * This function reallocates NCURSES window structures.  It is invoked in
 * response to a SIGWINCH interrupt.  Other user-defined windows may also need
 * to be reallocated.
 *
 * Because this performs memory allocation, it should not (in general) be
 * invoked directly from the signal handler.
 */
int
resizeterm(int ToLines, int ToCols)
{
	int stolen = screen_lines - SP->_lines_avail;
	int bottom = screen_lines + SP->_topstolen - stolen;

	T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"),
		ToLines, ToCols,
		screen_lines, screen_columns));

	SP->_sig_winch = FALSE;

	if (ToLines != screen_lines
	 || ToCols  != screen_columns) {
		WINDOWLIST *wp;

#if USE_SIGWINCH
		ungetch(KEY_RESIZE);	/* so application can know this */
		clearok(curscr, TRUE);	/* screen contents are unknown */
#endif

		for (wp = _nc_windows; wp != 0; wp = wp->next) {
			WINDOW *win = wp->win;
			int myLines = win->_maxy + 1;
			int myCols  = win->_maxx + 1;

			/* pads aren't treated this way */
			if (win->_flags & _ISPAD)
				continue;

			if (win->_begy >= bottom) {
				win->_begy += (ToLines - screen_lines);
			} else {
				if (myLines == screen_lines - stolen
				 && ToLines != screen_lines)
				 	myLines = ToLines - stolen;
				else
				if (myLines == screen_lines
				 && ToLines != screen_lines)
				 	myLines = ToLines;
			}

			if (myCols  == screen_columns
			 && ToCols  != screen_columns)
			 	myCols = ToCols;

			if (wresize(win, myLines, myCols) != OK)
				returnCode(ERR);
		}

		screen_lines   = lines    = ToLines;
		screen_columns = columns  = ToCols;

		SP->_lines_avail = lines - stolen;

		if (SP->oldhash) { FreeAndNull(SP->oldhash); }
		if (SP->newhash) { FreeAndNull(SP->newhash); }
	}

	/*
	 * Always update LINES, to allow for call from lib_doupdate.c which
	 * needs to have the count adjusted by the stolen (ripped off) lines.
	 */
	LINES = ToLines - stolen;
	COLS  = ToCols;

	returnCode(OK);
}
Ejemplo n.º 24
0
NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
{
    int rc = ERR;
    int n;
    bool found_cache = FALSE;
#ifdef USE_TERM_DRIVER
    TERMINAL *termp = 0;
#endif

    START_TRACE();
    T((T_CALLED("tgetent()")));

    TINFO_SETUP_TERM(&termp, (NCURSES_CONST char *) name,
		     STDOUT_FILENO, &rc, TRUE);

#ifdef USE_TERM_DRIVER
    if (termp == 0 ||
	!((TERMINAL_CONTROL_BLOCK *) termp)->drv->isTerminfo)
	returnCode(rc);
#endif

    /*
     * In general we cannot tell if the fixed sgr0 is still used by the
     * caller, but if tgetent() is called with the same buffer, that is
     * good enough, since the previous data would be invalidated by the
     * current call.
     *
     * bufp may be a null pointer, e.g., GNU termcap.  That allocates data,
     * which is good until the next tgetent() call.  The conventional termcap
     * is inconvenient because of the fixed buffer size, but because it uses
     * caller-supplied buffers, can have multiple terminal descriptions in
     * use at a given time.
     */
    for (n = 0; n < TGETENT_MAX; ++n) {
	bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp);
	if (same_result) {
	    CacheInx = n;
	    if (FIX_SGR0 != 0) {
		FreeAndNull(FIX_SGR0);
	    }
	    /*
	     * Also free the terminfo data that we loaded (much bigger leak).
	     */
	    if (LAST_TRM != 0 && LAST_TRM != TerminalOf(SP_PARM)) {
		TERMINAL *trm = LAST_TRM;
		NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx LAST_TRM);
		for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
		    if (LAST_TRM == trm)
			LAST_TRM = 0;
		CacheInx = n;
	    }
	    found_cache = TRUE;
	    break;
	}
    }
    if (!found_cache) {
	int best = 0;

	for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
	    if (LAST_SEQ < MyCache[best].sequence) {
		best = CacheInx;
	    }
	}
	CacheInx = best;
    }
    if (rc == 1) {
	LAST_TRM = TerminalOf(SP_PARM);
	LAST_SEQ = ++CacheSeq;
    } else {
	LAST_TRM = 0;
    }

    PC = 0;
    UP = 0;
    BC = 0;
    FIX_SGR0 = 0;		/* don't free it - application may still use */

    if (rc == 1) {

	if (cursor_left)
	    if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0)
		backspace_if_not_bs = cursor_left;

	/* we're required to export these */
	if (pad_char != NULL)
	    PC = pad_char[0];
	if (cursor_up != NULL)
	    UP = cursor_up;
	if (backspace_if_not_bs != NULL)
	    BC = backspace_if_not_bs;

	if ((FIX_SGR0 = _nc_trim_sgr0(&TerminalType(TerminalOf(SP_PARM))))
	    != 0) {
	    if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
		if (FIX_SGR0 != exit_attribute_mode) {
		    free(FIX_SGR0);
		}
		FIX_SGR0 = 0;
	    }
	}
	LAST_BUF = bufp;
	LAST_USE = TRUE;

	SetNoPadding(SP_PARM);
	(void) NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);	/* sets ospeed as a side-effect */

/* LINT_PREPRO
#if 0*/
#include <capdefaults.c>
/* LINT_PREPRO
#endif*/

    }
    returnCode(rc);
}
Ejemplo n.º 25
0
void GetTwissCoupledSetReturn( int Status, 
										 int nDims, 
										  mxArray* plhs[], 
										  struct Ctwiss* T )
{

	mxArray *ReturnStruc ;         /* the thing we want to return */
	mxArray *mxrealvec ;           /* subsidiary mxArray for ReturnStruc */
	double *mxrealp ;              /* pointer into real vectors */
	int i ;
	size_t dims[4]={0,0,0,0} ;
	static const char *fieldname[] = {   /* 3 field names */
		"S","P","beta"} ;	

	char** messages ; 
	int nmsg ;
	

/* Set the return status and any messages */

   messages = GetAndClearMessages( &nmsg ) ;
	plhs[0] = CreateStatusCellArray( Status, nmsg, messages ) ;

/* if the T pointer is NULL, then there's no point even trying to
   unpack the data structure because it doesn't exist.  In that case,
	head for the exit now. */

	if (T == NULL)
	{
		Status = 1 ;
		plhs[1] = mxCreateCellMatrix( 0 , 0 ) ;
		goto egress ;
	}

/* we can now use Status for the local status of this function */

	Status = 0 ;

/* get a Matlab structure mxArray for the return */

	dims[0] = 6 ; 
	dims[1] = 6 ;
	dims[2] = nDims ;
	dims[3] = T->nentry ;
	ReturnStruc = mxCreateStructMatrix( 1, 1, 3, fieldname ) ;

/* set the values of the real vectors now: */

/* S */
	mxrealvec = mxCreateDoubleMatrix(1,T->nentry,mxREAL) ;
	if (mxrealvec == NULL)
		goto egress ;

	mxrealp = mxGetPr( mxrealvec ) ;
	if (mxrealp == NULL)
		goto egress ;

	for (i=0 ; i<T->nentry ; i++ )
		mxrealp[i] = T->S[i] ;
	mxSetField( ReturnStruc, 0, fieldname[0], mxrealvec ) ;
	
/* P */
	mxrealvec = mxCreateDoubleMatrix(1,T->nentry,mxREAL) ;
	if (mxrealvec == NULL)
		goto egress ;

	mxrealp = mxGetPr( mxrealvec ) ;
	if (mxrealp == NULL)
		goto egress ;

	for (i=0 ; i<T->nentry ; i++ )
		mxrealp[i] = T->E[i] ;
	mxSetField( ReturnStruc, 0, fieldname[1], mxrealvec ) ;

/* now for the multi-dimensional Twiss array */	

	dims[0] = 6 ; 
	dims[1] = 6 ;
	dims[2] = nDims ;
	dims[3] = T->nentry ;
	mxrealvec = mxCreateNumericArray( 4, dims, mxDOUBLE_CLASS, mxREAL) ;
	mxrealp = mxGetPr( mxrealvec ) ;

/* fill the array with data */

	for (i=0 ; i<6*6*nDims*T->nentry ; i++)
		mxrealp[i] = T->Twiss[i] ;
	mxSetField( ReturnStruc, 0, fieldname[2], mxrealvec ) ;

/* set return variable */

	plhs[1] = ReturnStruc ;
	Status = 1 ;

/* cleanup and exit */

egress:

	if (T != NULL)
	{
	  FreeAndNull((void**)&(T->S)) ;
	  FreeAndNull((void**)&(T->E)) ;
	  FreeAndNull((void**)&(T->Twiss)) ;
	}

	if (WolskiInit != NULL)
	{
		mxDestroyArray(WolskiInit) ;
		WolskiInit = NULL ;
	}

	return ;

}
Ejemplo n.º 26
0
SDL_Surface *L4FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) {
	char* apptitle = APPTITLE;
	char* wintitle = WINTITLE;

	printf("L4FB_SetVideoMode: %dx%d@%d:\n", width, height, bpp);
	/*
	 * is requested resolution higher than the framebuffer's one?
	 */

	if( width > (int)this->hidden->vvi.width
		|| height > (int)this->hidden->vvi.height)
	{
		return (NULL);
	}
	
	/*
	 * calc the offsets for current resolution the center the image 
	 */
	
	this->hidden->x_offset = (this->hidden->vvi.width - width ) / 2;
	this->hidden->y_offset = (this->hidden->vvi.height - height) / 2;

	// make sure to have correct scale
	if (L4FB_video_scale_factor<=0) L4FB_video_scale_factor = 1.0;
	
	// reject unsupported bpp
	if (bpp != 16) return NULL;
	// reject unsupported flags
	if (flags & SDL_OPENGL) return NULL;

	/* Allocate the new pixel format for the screen */
	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
		SDL_SetError("Couldn't allocate new pixel format for requested mode");
		return(NULL);
	}

	// if we were double buffered clear shadow buffer
	if (current->flags & SDL_DOUBLEBUF) {
		FreeAndNull(current->pixels);
	}

	// init new window
	if (this->wm_title) wintitle = this->wm_title;
	if (this->wm_icon)  apptitle = this->wm_icon;



//	L4FB_SetCaption(this, wintitle, apptitle);

	if (l4_is_invalid_cap(this->hidden->ev_ds) || !this->hidden->ev_ds)
		L4FB_InstallEventHandler(this);

	/* Set up the new mode framebuffer */
	current->w = width;
	current->h = height;
	current->pitch = SDL_CalculatePitch(current);
	this->hidden->pitch =  current->pitch;
	current->flags =  SDL_PREALLOC | SDL_ASYNCBLIT;


//	if (current->pixels)
//	{
//		/* TODO: ERROR HANDLING */
//	}

//	memset(current->pixels, 0, current->h*current->pitch);


	/* since we want to center image in fb we allway have to use doublebuf... */

	this->hidden->fb_start = this->hidden->fbmem_vaddr + this->hidden->vvi.buffer_offset;

	current->pixels = malloc(current->h*current->pitch);

	if (current->pixels) {
		// success!
		printf("allocated shadow buffer\n");
		this->hidden->pixels = current->pixels;
		memset(current->pixels, 0, current->h*current->pitch);
	} else
		return NULL;


	if (flags&SDL_DOUBLEBUF) {

		current->flags |= SDL_DOUBLEBUF|SDL_HWSURFACE;
		// try to alloc shadow buffer
	}
 
	/* We're done */
	return(current);
}
Ejemplo n.º 27
0
BOOL GetConfiguration(
	PEXT_ARG pExtArg,
	PDEVICE pDevice,
	PDISC pDisc
	)
{
	CDB::_GET_CONFIGURATION cdb = { 0 };
	cdb.OperationCode = SCSIOP_GET_CONFIGURATION;
	cdb.RequestType = SCSI_GET_CONFIGURATION_REQUEST_TYPE_CURRENT;
	cdb.StartingFeature[1] = FeatureProfileList;
	WORD wSize = sizeof(GET_CONFIGURATION_HEADER);
	REVERSE_BYTES_SHORT(&cdb.AllocationLength, &wSize);

	_declspec(align(4)) GET_CONFIGURATION_HEADER configHeader = { 0 };
	BYTE byScsiStatus = 0;
	if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB10GENERIC_LENGTH
		, &configHeader, wSize, &byScsiStatus, _T(__FUNCTION__), __LINE__)
		|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
		pDisc->SCSI.wCurrentMedia = ProfileCdrom;
		// not false. because undefined mmc1..
		if (pDevice->byPlxtrDrive == PLXTR_DRIVE_TYPE::PX40TS) {
			pDevice->FEATURE.byCanCDText = TRUE;
			pDevice->FEATURE.byC2ErrorData = TRUE;
		}
		OutputDriveNoSupportLogA(GET_CONFIGURATION);
	}
	else {
		pDisc->SCSI.wCurrentMedia =
			MAKEWORD(configHeader.CurrentProfile[1], configHeader.CurrentProfile[0]);
		if (pDisc->SCSI.wCurrentMedia == ProfileInvalid) {
			OutputDriveLogA(
				"SCSIOP_GET_CONFIGURATION didn't fail. But it couldn't get CurrentMedia on this drive\n"
				"\tSet CurrentMedia to CD-ROM\n");
			configHeader.CurrentProfile[1] = ProfileCdrom;
			pDisc->SCSI.wCurrentMedia = ProfileCdrom;
		}
		OutputGetConfigurationHeader(&configHeader);

		DWORD dwAllLen =
			MAKELONG(MAKEWORD(configHeader.DataLength[3], configHeader.DataLength[2]),
			MAKEWORD(configHeader.DataLength[1], configHeader.DataLength[0])) -
			sizeof(configHeader.DataLength) + sizeof(GET_CONFIGURATION_HEADER);
		LPBYTE pPConf = NULL;
		LPBYTE lpConf = NULL;
		if (!GetAlignedCallocatedBuffer(pDevice, &pPConf,
			dwAllLen, &lpConf, _T(__FUNCTION__), __LINE__)) {
			return FALSE;
		}
		REVERSE_BYTES_SHORT(&cdb.AllocationLength, &dwAllLen);

		if (!ScsiPassThroughDirect(pExtArg, pDevice, &cdb, CDB10GENERIC_LENGTH
			, lpConf, dwAllLen, &byScsiStatus, _T(__FUNCTION__), __LINE__)
			|| byScsiStatus >= SCSISTAT_CHECK_CONDITION) {
			// not false. because undefined mmc1..
			OutputDriveNoSupportLogA(GET_CONFIGURATION);
		}
		else {
			OutputGetConfigurationFeatureNumber(pDevice,
				lpConf + sizeof(GET_CONFIGURATION_HEADER), dwAllLen - sizeof(GET_CONFIGURATION_HEADER));
			if (pDevice->byPlxtrDrive == (BYTE)PLXTR_DRIVE_TYPE::PXW1210A ||
				pDevice->byPlxtrDrive == (BYTE)PLXTR_DRIVE_TYPE::PXW1210S) {
				// Somehow SetCDSpeed fails in PX-W1210...
				pDevice->FEATURE.bySetCDSpeed = FALSE;
			}
		}
		FreeAndNull(pPConf);
	}
	return TRUE;
}
Ejemplo n.º 28
0
_nc_hash_map(void)
{
    HASHMAP *sp;
    register int i;
    int start, shift, size;

    if (screen_lines > lines_alloc) {
	if (hashtab)
	    free(hashtab);
	hashtab = typeMalloc(HASHMAP, (screen_lines + 1) * 2);
	if (!hashtab) {
	    if (oldhash) {
		FreeAndNull(oldhash);
	    }
	    lines_alloc = 0;
	    return;
	}
	lines_alloc = screen_lines;
    }

    if (oldhash && newhash) {
	/* re-hash only changed lines */
	for (i = 0; i < screen_lines; i++) {
	    if (PENDING(i))
		newhash[i] = hash(NEWTEXT(i));
	}
    } else {
	/* re-hash all */
	if (oldhash == 0)
	    oldhash = typeCalloc(unsigned long, (unsigned) screen_lines);
	if (newhash == 0)
	    newhash = typeCalloc(unsigned long, (unsigned) screen_lines);
	if (!oldhash || !newhash)
	    return;		/* malloc failure */
	for (i = 0; i < screen_lines; i++) {
	    newhash[i] = hash(NEWTEXT(i));
	    oldhash[i] = hash(OLDTEXT(i));
	}
    }

#ifdef HASH_VERIFY
    for (i = 0; i < screen_lines; i++) {
	if (newhash[i] != hash(NEWTEXT(i)))
	    fprintf(stderr, "error in newhash[%d]\n", i);
	if (oldhash[i] != hash(OLDTEXT(i)))
	    fprintf(stderr, "error in oldhash[%d]\n", i);
    }
#endif

    /*
     * Set up and count line-hash values.
     */
    memset(hashtab, '\0', sizeof(*hashtab) * (screen_lines + 1) * 2);
    for (i = 0; i < screen_lines; i++) {
	unsigned long hashval = oldhash[i];

	for (sp = hashtab; sp->hashval; sp++)
	    if (sp->hashval == hashval)
		break;
	sp->hashval = hashval;	/* in case this is a new entry */
	sp->oldcount++;
	sp->oldindex = i;
    }
    for (i = 0; i < screen_lines; i++) {
	unsigned long hashval = newhash[i];

	for (sp = hashtab; sp->hashval; sp++)
	    if (sp->hashval == hashval)
		break;
	sp->hashval = hashval;	/* in case this is a new entry */
	sp->newcount++;
	sp->newindex = i;

	OLDNUM(i) = _NEWINDEX;	/* initialize old indices array */
    }

    /*
     * Mark line pairs corresponding to unique hash pairs.
     *
     * We don't mark lines with offset 0, because it can make fail
     * extending hunks by cost_effective. Otherwise, it does not
     * have any side effects.
     */
    for (sp = hashtab; sp->hashval; sp++)
	if (sp->oldcount == 1 && sp->newcount == 1
	    && sp->oldindex != sp->newindex) {
	    TR(TRACE_UPDATE | TRACE_MOVE,
	       ("new line %d is hash-identical to old line %d (unique)",
		sp->newindex, sp->oldindex));
	    OLDNUM(sp->newindex) = sp->oldindex;
	}

    grow_hunks();

    /*
     * Eliminate bad or impossible shifts -- this includes removing
     * those hunks which could not grow because of conflicts, as well
     * those which are to be moved too far, they are likely to destroy
     * more than carry.
     */
    for (i = 0; i < screen_lines;) {
	while (i < screen_lines && OLDNUM(i) == _NEWINDEX)
	    i++;
	if (i >= screen_lines)
	    break;
	start = i;
	shift = OLDNUM(i) - i;
	i++;
	while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i
	       == shift)
	    i++;
	size = i - start;
	if (size < 3 || size + min(size / 8, 2) < abs(shift)) {
	    while (start < i) {
		OLDNUM(start) = _NEWINDEX;
		start++;
	    }
	}
    }

    /* After clearing invalid hunks, try grow the rest. */
    grow_hunks();
}
Ejemplo n.º 29
0
static int
next_char(void)
{
    static char *result;
    static size_t allocated;
    int the_char;

    if (!yyin) {
	if (result != 0) {
	    FreeAndNull(result);
	    FreeAndNull(pushname);
	    allocated = 0;
	}
	/*
	 * An string with an embedded null will truncate the input.  This is
	 * intentional (we don't read binary files here).
	 */
	if (bufptr == 0 || *bufptr == '\0')
	    return (EOF);
	if (*bufptr == '\n') {
	    _nc_curr_line++;
	    _nc_curr_col = 0;
	} else if (*bufptr == '\t') {
	    _nc_curr_col = (_nc_curr_col | 7);
	}
    } else if (!bufptr || !*bufptr) {
	/*
	 * In theory this could be recoded to do its I/O one character at a
	 * time, saving the buffer space.  In practice, this turns out to be
	 * quite hard to get completely right.  Try it and see.  If you
	 * succeed, don't forget to hack push_back() correspondingly.
	 */
	size_t used;
	size_t len;

	do {
	    bufstart = 0;
	    used = 0;
	    do {
		if (used + (LEXBUFSIZ / 4) >= allocated) {
		    allocated += (allocated + LEXBUFSIZ);
		    result = typeRealloc(char, allocated, result);
		    if (result == 0)
			return (EOF);
		    bufstart = result;
		}
		if (used == 0)
		    _nc_curr_file_pos = ftell(yyin);

		if (fgets(result + used, (int) (allocated - used), yyin) != 0) {
		    bufstart = result;
		    if (used == 0) {
			_nc_curr_line++;
			_nc_curr_col = 0;
		    }
		} else {
		    if (used != 0)
			strlcat(result, "\n", allocated);
		}
		if ((bufptr = bufstart) != 0) {
		    used = strlen(bufptr);
		    while (iswhite(*bufptr)) {
			if (*bufptr == '\t') {
			    _nc_curr_col = (_nc_curr_col | 7) + 1;
			} else {
			    _nc_curr_col++;
			}
			bufptr++;
		    }

		    /*
		     * Treat a trailing <cr><lf> the same as a <newline> so we
		     * can read files on OS/2, etc.
		     */
		    if ((len = strlen(bufptr)) > 1) {
			if (bufptr[len - 1] == '\n'
			    && bufptr[len - 2] == '\r') {
			    len--;
			    bufptr[len - 1] = '\n';
			    bufptr[len] = '\0';
			}
		    }
		} else {
		    return (EOF);
		}
	    } while (bufptr[len - 1] != '\n');	/* complete a line */
	} while (result[0] == '#');	/* ignore comments */
Ejemplo n.º 30
0
void
vl_ctype_leaks(void)
{
    FreeAndNull(ctype_sets);
    FreeAndNull(ctype_clrs);
}