예제 #1
0
파일: prefs.c 프로젝트: hagenkaye/ne
int load_prefs(buffer *const b, const char *const name)
{
    if (!b || !name)
    {
        return ERROR;
    }

    assert_buffer(b);

    b->exec_only_options = 1;

    int error = OK;
    char_stream *const cs = load_stream(NULL, name, false, false);
    if (cs)
    {
        error = play_macro(b, cs);
        free_char_stream(cs);
    }
    else
    {
        error = ERROR;
    }

    b->exec_only_options = 0;

    return error;
}
예제 #2
0
파일: buffer.c 프로젝트: dmt4/ne
void free_buffer_contents(buffer * const b) {

	if (!b) return;

	block_signals();

	free_list(&b->line_desc_pool_list, free_line_desc_pool);
	free_list(&b->char_pool_list, free_char_pool);
	new_list(&b->line_desc_list);
	b->cur_line_desc = b->top_line_desc = NULL;

	b->allocated_chars = b->free_chars = 0;
	b->is_CRLF = false;
	b->encoding = ENC_ASCII;
	b->bookmark_mask = 0;
	b->mtime = 0;

	free_char_stream(b->last_deleted);
	b->last_deleted = NULL;

	free(b->filename);
	b->filename = NULL;

	reset_undo_buffer(&b->undo);
	b->is_modified = b->marking = b->recording = b->x_wanted = 0;

	release_signals();
}
예제 #3
0
파일: prefs.c 프로젝트: vigna/ne
int save_prefs(buffer * const b, const char * const name) {
	if (!b || !name) return ERROR;

	assert_buffer(b);

	char_stream *cs = alloc_char_stream(PREF_FILE_SIZE_GUESS);
	if (cs) {
		/* We create a macro by recording an action for each kind of flag. */

		if (!saving_defaults && b->syn) record_action(cs, SYNTAX_A, -1, (const char *)b->syn->name, verbose_macros);

		record_action(cs, TABSIZE_A,          b->opt.tab_size,       NULL, verbose_macros);
		/* Skip cur_clip */
		record_action(cs, RIGHTMARGIN_A,      b->opt.right_margin,   NULL, verbose_macros);
		record_action(cs, FREEFORM_A,         b->opt.free_form,      NULL, verbose_macros);
		record_action(cs, HEXCODE_A,          b->opt.hex_code,       NULL, verbose_macros);
		record_action(cs, WORDWRAP_A,         b->opt.word_wrap,      NULL, verbose_macros);
		record_action(cs, AUTOINDENT_A,       b->opt.auto_indent,    NULL, verbose_macros);
		record_action(cs, PRESERVECR_A,       b->opt.preserve_cr,    NULL, verbose_macros);
		record_action(cs, INSERT_A,           b->opt.insert,         NULL, verbose_macros);
		record_action(cs, DOUNDO_A,           b->opt.do_undo,        NULL, verbose_macros);
		record_action(cs, AUTOPREFS_A,        b->opt.auto_prefs,     NULL, verbose_macros);
		record_action(cs, NOFILEREQ_A,        b->opt.no_file_req,    NULL, verbose_macros);
		/* Skip read_only */
		/* Skip search_back */
		record_action(cs, CASESEARCH_A,       b->opt.case_search,    NULL, verbose_macros);
		record_action(cs, TABS_A,             b->opt.tabs,           NULL, verbose_macros);
		record_action(cs, DELTABS_A,          b->opt.del_tabs,       NULL, verbose_macros);
		record_action(cs, SHIFTTABS_A,        b->opt.shift_tabs,     NULL, verbose_macros);
		record_action(cs, AUTOMATCHBRACKET_A, b->opt.automatch,      NULL, verbose_macros);
		record_action(cs, BINARY_A,           b->opt.binary,         NULL, verbose_macros);
		record_action(cs, UTF8AUTO_A,         b->opt.utf8auto,       NULL, verbose_macros);
		record_action(cs, VISUALBELL_A,       b->opt.visual_bell,    NULL, verbose_macros);

		if (saving_defaults) {
			/* We only save the global flags that differ from their defaults. */
			/* Make sure these are in sync with the defaults near the top of ne.c. */
#ifndef ALTPAGING
			if (req_order)       record_action(cs, REQUESTORDER_A,  req_order,      NULL, verbose_macros);
#else
			if (!req_order)      record_action(cs, REQUESTORDER_A,  req_order,      NULL, verbose_macros);
#endif
			if (fast_gui)        record_action(cs, FASTGUI_A,       fast_gui,       NULL, verbose_macros);
			if (!status_bar)     record_action(cs, STATUSBAR_A,     status_bar,     NULL, verbose_macros);
			if (!verbose_macros) record_action(cs, VERBOSEMACROS_A, verbose_macros, NULL, verbose_macros);
			saving_defaults = false;
		}

		const int error = save_stream(cs, name, b->is_CRLF, false);
		free_char_stream(cs);
		return error;
	}

	return OUT_OF_MEMORY;
}
예제 #4
0
파일: buffer.c 프로젝트: dmt4/ne
void free_buffer(buffer * const b) {
	if (b == NULL) return;

	assert_buffer(b);

	free_buffer_contents(b);

	free_char_stream(b->cur_macro);

	free(b->find_string);
	free(b->replace_string);
	free(b->command_line);
	if (b->attr_buf) free(b->attr_buf);
	free(b);
}
예제 #5
0
파일: streams.c 프로젝트: dmt4/ne
char_stream *load_stream_from_fh(char_stream *cs, const int fh, const bool preserve_cr, const bool binary) {
	if (fh < 0) return NULL;

	char terminators[] = { 0x0d, 0x0a };
	if (preserve_cr) terminators[0] = 0;

	assert_char_stream(cs);

	off_t len = lseek(fh, 0, SEEK_END);

	if (len < 0) return NULL;

	lseek(fh, 0, SEEK_SET);

	if (!(cs = realloc_char_stream(cs, len))) return NULL;

	if (read_safely(fh, cs->stream, len) < len) {
		free_char_stream(cs);
		return NULL;
	}

	if (binary) {
		cs->len = len;
		assert_char_stream(cs);
		return cs;
	}

	int64_t j;
	for(int64_t i = j = 0; i < len; i++, j++) {
		if (i < len - 1 && !preserve_cr && cs->stream[i] == '\r' && cs->stream[i + 1] == '\n') i++;
		cs->stream[j] = cs->stream[i];

		if (cs->stream[j] == terminators[0] || cs->stream[j] == terminators[1]) cs->stream[j] = 0;
	}

	memset(cs->stream + j, 0, len - j);

	cs->len = j;

	assert_char_stream(cs);

	return cs;
}