From 79d1d7089a699cf8a09bd5227f9033282001b0b3 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 15 Jul 2001 00:39:48 +0000 Subject: Added --home and --config command line parameters to irssi to specify locations for ~/.irssi and ~/.irssi/config git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1626 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-text/Makefile.am | 1 + src/fe-text/gui-printtext.c | 61 +++----------- src/fe-text/irssi.c | 14 ++-- src/fe-text/textbuffer-commands.c | 13 +-- src/fe-text/textbuffer.c | 168 -------------------------------------- 5 files changed, 27 insertions(+), 230 deletions(-) (limited to 'src/fe-text') diff --git a/src/fe-text/Makefile.am b/src/fe-text/Makefile.am index bddf2409..2b80dd17 100644 --- a/src/fe-text/Makefile.am +++ b/src/fe-text/Makefile.am @@ -33,6 +33,7 @@ irssi_SOURCES = \ statusbar-items.c \ textbuffer.c \ textbuffer-commands.c \ + textbuffer-reformat.c \ textbuffer-view.c \ irssi.c \ module-formats.c diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index 52cc5c9e..e8566f1a 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -31,9 +31,6 @@ int mirc_colors[] = { 15, 0, 1, 2, 12, 6, 5, 4, 14, 10, 3, 11, 9, 13, 8, 7 }; static int scrollback_lines, scrollback_hours, scrollback_burst_remove; -static int scrollback_save_formats; -static GString *format; - static int last_color, last_flags; static int next_xpos, next_ypos; @@ -137,7 +134,8 @@ static void line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line, data[pos++] = LINE_CMD_INDENT; } - *line = textbuffer_insert(buffer, *line, data, pos, NULL); + if (pos > 0) + *line = textbuffer_insert(buffer, *line, data, pos, NULL); last_flags = flags; last_color = fg | (bg << 4); @@ -155,6 +153,7 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor, void *bgcolor, void *pflags, char *str, void *level) { + GUI_WINDOW_REC *gui; TEXT_BUFFER_VIEW_REC *view; LINE_REC *insert_after; LINE_INFO_REC lineinfo; @@ -178,15 +177,18 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor, lineinfo.level = GPOINTER_TO_INT(level); lineinfo.time = time(NULL); - view = WINDOW_GUI(window)->view; - insert_after = WINDOW_GUI(window)->use_insert_after ? - WINDOW_GUI(window)->insert_after : view->buffer->cur_line; + gui = WINDOW_GUI(window); + view = gui->view; + insert_after = gui->use_insert_after ? + gui->insert_after : view->buffer->cur_line; if (flags & GUI_PRINT_FLAG_NEWLINE) view_add_eol(view, &insert_after); line_add_colors(view->buffer, &insert_after, fg, bg, flags); - textbuffer_insert(view->buffer, insert_after, - str, strlen(str), &lineinfo); + insert_after = textbuffer_insert(view->buffer, insert_after, + str, strlen(str), &lineinfo); + if (gui->use_insert_after) + gui->insert_after = insert_after; } static void sig_gui_printtext_finished(WINDOW_REC *window) @@ -205,61 +207,23 @@ static void sig_gui_printtext_finished(WINDOW_REC *window) remove_old_lines(view); } -static void sig_print_format(THEME_REC *theme, const char *module, - TEXT_DEST_REC *dest, void *formatnump, - char **args) -{ - FORMAT_REC *formats; - int formatnum, n; - - if (!scrollback_save_formats) - return; - - formatnum = GPOINTER_TO_INT(formatnump); - formats = g_hash_table_lookup(default_formats, module); - - /* */ - g_string_truncate(format, 0); - - g_string_append_c(format, '\0'); - g_string_append_c(format, (char)LINE_CMD_FORMAT); - - g_string_append(format, module); - - g_string_append_c(format, '\0'); - g_string_append_c(format, (char)LINE_CMD_FORMAT); - - g_string_append(format, formats[formatnum].tag); - - for (n = 0; n < formats[formatnum].params; n++) { - g_string_append_c(format, '\0'); - g_string_append_c(format, (char)LINE_CMD_FORMAT); - - g_string_append(format, args[n]); - } -} - static void read_settings(void) { scrollback_lines = settings_get_int("scrollback_lines"); scrollback_hours = settings_get_int("scrollback_hours"); scrollback_burst_remove = settings_get_int("scrollback_burst_remove"); - scrollback_save_formats = settings_get_bool("scrollback_save_formats"); } void gui_printtext_init(void) { next_xpos = next_ypos = -1; - format = g_string_new(NULL); settings_add_int("history", "scrollback_lines", 500); settings_add_int("history", "scrollback_hours", 24); settings_add_int("history", "scrollback_burst_remove", 10); - settings_add_bool("history", "scrollback_save_formats", FALSE); signal_add("gui print text", (SIGNAL_FUNC) sig_gui_print_text); signal_add("gui print text finished", (SIGNAL_FUNC) sig_gui_printtext_finished); - signal_add("print format", (SIGNAL_FUNC) sig_print_format); signal_add("setup changed", (SIGNAL_FUNC) read_settings); read_settings(); @@ -267,10 +231,7 @@ void gui_printtext_init(void) void gui_printtext_deinit(void) { - g_string_free(format, TRUE); - signal_remove("gui print text", (SIGNAL_FUNC) sig_gui_print_text); signal_remove("print text finished", (SIGNAL_FUNC) sig_gui_printtext_finished); - signal_remove("print format", (SIGNAL_FUNC) sig_print_format); signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index ec55f10f..a2dc04a0 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -38,6 +38,7 @@ #include "gui-readline.h" #include "statusbar.h" #include "gui-windows.h" +#include "textbuffer-reformat.h" #include @@ -117,6 +118,7 @@ static void textui_finish_init(void) textbuffer_init(); textbuffer_view_init(); textbuffer_commands_init(); + textbuffer_reformat_init(); gui_entry_init(); gui_expandos_init(); gui_printtext_init(); @@ -166,6 +168,7 @@ static void textui_deinit(void) mainwindows_deinit(); gui_expandos_deinit(); gui_entry_deinit(); + textbuffer_reformat_deinit(); textbuffer_commands_deinit(); textbuffer_view_deinit(); textbuffer_deinit(); @@ -192,7 +195,7 @@ static void check_oldcrap(void) int found; /* check that default.theme is up-to-date */ - path = g_strdup_printf("%s/.irssi/default.theme", g_get_home_dir()); + path = g_strdup_printf("%s/default.theme", get_irssi_dir()); f = fopen(path, "r+"); if (f == NULL) { g_free(path); @@ -208,7 +211,7 @@ static void check_oldcrap(void) return; } - printf("\nYou seem to have old default.theme in ~/.irssi/ directory.\n"); + printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n"); printf("Themeing system has changed a bit since last irssi release,\n"); printf("you should either delete your old default.theme or manually\n"); printf("merge it with the new default.theme.\n\n"); @@ -224,16 +227,13 @@ static void check_oldcrap(void) static void check_files(void) { struct stat statbuf; - char *path; - path = g_strdup_printf("%s/.irssi", g_get_home_dir()); - if (stat(path, &statbuf) != 0) { + if (stat(get_irssi_dir(), &statbuf) != 0) { /* ~/.irssi doesn't exist, first time running irssi */ display_firsttimer = TRUE; } else { check_oldcrap(); } - g_free(path); } #ifdef WIN32 @@ -253,6 +253,8 @@ static void winsock_init(void) int main(int argc, char **argv) { + core_init_paths(argc, argv); + check_files(); #ifdef WIN32 winsock_init(); diff --git a/src/fe-text/textbuffer-commands.c b/src/fe-text/textbuffer-commands.c index 24847dac..2de83515 100644 --- a/src/fe-text/textbuffer-commands.c +++ b/src/fe-text/textbuffer-commands.c @@ -26,6 +26,7 @@ #include "printtext.h" #include "gui-windows.h" +#include "textbuffer-reformat.h" /* SYNTAX: CLEAR */ static void cmd_clear(const char *data) @@ -205,21 +206,21 @@ static void cmd_scrollback_end(const char *data) /* SYNTAX: SCROLLBACK REDRAW */ static void cmd_scrollback_redraw(void) { -#if 0 GUI_WINDOW_REC *gui; - GList *tmp, *next; + LINE_REC *line, *next; gui = WINDOW_GUI(active_win); screen_refresh_freeze(); - for (tmp = gui->lines; tmp != NULL; tmp = next) { - next = tmp->next; - gui_window_reformat_line(active_win, tmp->data); + line = textbuffer_view_get_lines(gui->view); + while (line != NULL) { + next = line->next; + textbuffer_reformat_line(active_win, line); + line = next; } gui_window_redraw(active_win); screen_refresh_thaw(); -#endif } static void cmd_scrollback_status(void) diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 06cb2fe9..3c11aea3 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -462,174 +462,6 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, return matches; } -#if 0 /* FIXME: saving formats is broken */ -static char *line_read_format(unsigned const char **text) -{ - GString *str; - char *ret; - - str = g_string_new(NULL); - for (;;) { - if (**text == '\0') { - if ((*text)[1] == LINE_CMD_EOL) { - /* leave text at \0 */ - break; - } - if ((*text)[1] == LINE_CMD_FORMAT_CONT) { - /* leave text at \0 */ - break; - } - (*text)++; - - if (**text == LINE_CMD_FORMAT) { - /* move text to start after \0 */ - (*text)++; - break; - } - - if (**text == LINE_CMD_CONTINUE) { - unsigned char *tmp; - - memcpy(&tmp, (*text)+1, sizeof(char *)); - *text = tmp; - continue; - } else if (**text & 0x80) - (*text)++; - continue; - } - - g_string_append_c(str, (char) **text); - (*text)++; - } - - ret = str->str; - g_string_free(str, FALSE); - return ret; -} - -static char *textbuffer_line_get_format(WINDOW_REC *window, LINE_REC *line, - GString *raw) -{ - const unsigned char *text; - char *module, *format_name, *args[MAX_FORMAT_PARAMS], *ret; - TEXT_DEST_REC dest; - int formatnum, argcount; - - text = (const unsigned char *) line->text; - - /* skip the beginning of the line until we find the format */ - g_free(line_read_format(&text)); - if (text[1] == LINE_CMD_FORMAT_CONT) { - g_string_append_c(raw, '\0'); - g_string_append_c(raw, (char)LINE_CMD_FORMAT_CONT); - return NULL; - } - - /* read format information */ - module = line_read_format(&text); - format_name = line_read_format(&text); - - if (raw != NULL) { - g_string_append_c(raw, '\0'); - g_string_append_c(raw, (char)LINE_CMD_FORMAT); - - g_string_append(raw, module); - - g_string_append_c(raw, '\0'); - g_string_append_c(raw, (char)LINE_CMD_FORMAT); - - g_string_append(raw, format_name); - } - - formatnum = format_find_tag(module, format_name); - if (formatnum == -1) - ret = NULL; - else { - argcount = 0; - memset(args, 0, sizeof(args)); - while (*text != '\0' || text[1] != LINE_CMD_EOL) { - args[argcount] = line_read_format(&text); - if (raw != NULL) { - g_string_append_c(raw, '\0'); - g_string_append_c(raw, - (char)LINE_CMD_FORMAT); - - g_string_append(raw, args[argcount]); - } - argcount++; - } - - /* get the format text */ - format_create_dest(&dest, NULL, NULL, line->level, window); - ret = format_get_text_theme_charargs(current_theme, - module, &dest, - formatnum, args); - while (argcount > 0) - g_free(args[--argcount]); - } - - g_free(module); - g_free(format_name); - - return ret; -} - -void textbuffer_reformat_line(WINDOW_REC *window, LINE_REC *line) -{ - GUI_WINDOW_REC *gui; - TEXT_DEST_REC dest; - GString *raw; - char *str, *tmp, *prestr, *linestart, *leveltag; - - gui = WINDOW_GUI(window); - - raw = g_string_new(NULL); - str = textbuffer_line_get_format(window, line, raw); - - if (str == NULL && raw->len == 2 && - raw->str[1] == (char)LINE_CMD_FORMAT_CONT) { - /* multiline format, format explained in one the - following lines. remove this line. */ - textbuffer_line_remove(window, line, FALSE); - } else if (str != NULL) { - /* FIXME: ugly ugly .. and this can't handle - non-formatted lines.. */ - g_string_append_c(raw, '\0'); - g_string_append_c(raw, (char)LINE_CMD_EOL); - - textbuffer_line_text_free(gui, line); - - gui->temp_line = line; - gui->temp_line->text = gui->cur_text->buffer+gui->cur_text->pos; - gui->cur_text->lines++; - gui->eol_marked = FALSE; - - format_create_dest(&dest, NULL, NULL, line->level, window); - - linestart = format_get_line_start(current_theme, &dest, line->time); - leveltag = format_get_level_tag(current_theme, &dest); - - prestr = g_strconcat(linestart == NULL ? "" : linestart, - leveltag, NULL); - g_free_not_null(linestart); - g_free_not_null(leveltag); - - tmp = format_add_linestart(str, prestr); - g_free(str); - g_free(prestr); - - format_send_to_gui(&dest, tmp); - g_free(tmp); - - textbuffer_line_append(gui, raw->str, raw->len); - - gui->eol_marked = TRUE; - gui->temp_line = NULL; - } - g_string_free(raw, TRUE); -} -#endif - void textbuffer_init(void) { buffer_chunk = g_mem_chunk_new("text buffer chunk", -- cgit v1.2.3