1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/*
* Copyright Colten Edwards 1996
*/
#include "irc.h"
#include "struct.h"
#include <sys/stat.h>
#include "ircterm.h"
#include "server.h"
#include "vars.h"
#include "ircaux.h"
#include "input.h"
#include "window.h"
#include "screen.h"
#include "output.h"
#include "status.h"
#include "misc.h"
FILE * msg_fp = NULL;
static Window *msg_window = NULL;
static int finished_msg_paging = 0;
static Screen *msg_screen = NULL;
static int use_msg_window = 0;
static void log_prompt _((char *name, char *line));
static void set_msg_screen _((Screen *));
static char *(*read_log_func) _((char *, int, FILE *));
void log_put_it(const char *topic, const char *format, ...);
BUILT_IN_COMMAND(remove_log)
{
char *expand;
char *filename = NULL;
int old_display = window_display;
int reset_logptr = 0;
if ((get_string_var(MSGLOGFILE_VAR) == NULL) || (get_string_var(CTOOLZ_DIR_VAR) == NULL))
return;
malloc_sprintf(&filename, "%s/%s", get_string_var(CTOOLZ_DIR_VAR), get_string_var(MSGLOGFILE_VAR));
expand = expand_twiddle(filename);
new_free(&filename);
window_display = 0;
reset_logptr = logmsg(LOG_CURRENT, NULL, 3, NULL);
log_toggle(0, NULL);
window_display = old_display;
if (unlink(expand))
{
bitchsay("Error unlinking: %s", expand);
new_free(&expand);
return;
}
window_display = 0;
set_int_var(MSGCOUNT_VAR, 0);
if (reset_logptr)
log_toggle(1, NULL);
window_display = old_display;
bitchsay("Removed %s.", expand);
status_update(1);
new_free(&expand);
}
static int in_read_log = 0;
BUILT_IN_COMMAND(readlog)
{
char *expand;
struct stat stat_buf;
char *filename = NULL;
static char buffer[BIG_BUFFER_SIZE + 1];
read_log_func = fgets;
if (!get_string_var(MSGLOGFILE_VAR))
if (!args || (args && !*args))
return;
if (msg_window)
return;
if (command)
{
in_read_log = 1;
if (my_stricmp(command, "MORE"))
{
if (args && *args && *args == '-' && !my_stricmp(args, "-r"))
{
next_arg(args, &args);
read_log_func = rfgets;
}
}
}
if (args && *args)
malloc_sprintf(&filename, "%s", args);
else
malloc_sprintf(&filename, "%s/%s", get_string_var(CTOOLZ_DIR_VAR), get_string_var(MSGLOGFILE_VAR));
expand = expand_twiddle(filename);
new_free(&filename);
stat(expand, &stat_buf);
strcpy(buffer, expand);
if (stat_buf.st_mode & S_IFDIR)
return;
if ((msg_fp = fopen(expand, "r")) == NULL)
{
log_put_it(expand, "%s Error Opening Log file %s", thing_ansi, expand);
new_free(&expand);
msg_fp = NULL;
return;
}
if (read_log_func == rfgets)
fseek(msg_fp, 0, SEEK_END);
new_free(&expand);
msg_window = current_window;
msg_screen = current_window->screen;
log_prompt(buffer, NULL);
}
/*
* show_help: show's either a page of text from a help_fp, or the whole
* thing, depending on the value of HELP_PAGER_VAR. If it gets to the end,
* (in either case it will eventally), it closes the file, and returns 0
* to indicate this.
*/
static int show_log(Window *window, char *name)
{
Window *old_window;
int rows = 0;
char line[300];
if (window)
{
old_window = current_window;
current_window = window;
}
else
{
old_window = NULL;
window = current_window;
}
if (get_int_var(HELP_PAGER_VAR))
rows = window->display_size - (window->double_status + 2);
while (--rows)
{
if ((*read_log_func)(line, 299, msg_fp))
{
if (*(line + strlen(line) - 1) == '\n')
*(line + strlen(line) - 1) = (char) 0;
log_put_it(name, "%s", line);
}
else
{
if (msg_fp) fclose(msg_fp);
set_msg_screen(NULL);
msg_fp = NULL;
return (0);
}
}
return (1);
}
void remove_away_log(char *stuff, char *line)
{
if ((line && toupper(*line) == 'Y'))
remove_log(NULL, NULL, NULL, NULL);
in_read_log = 0;
}
static void set_msg_screen(Screen *screen)
{
msg_screen = screen;
if (!msg_screen && msg_window)
{
if (use_msg_window)
{
int display = window_display;
window_display = 0;
delete_window(msg_window);
window_display = display;
}
msg_window = NULL;
update_all_windows();
}
}
/*
* log_prompt: The main procedure called to display the log file
* currently being accessed. Using add_wait_prompt(), it sets it
* self up to be recalled when the next page is asked for. If
* called when we have finished paging the log file, we exit, as
* there is nothing left to show. If line is 'q' or 'Q', exit the
* log pager, clean up, etc.. If all is cool for now, we call
* show_help, and either if its finished, exit, or prompt for the
* next page.
*/
static void log_prompt(char *name, char *line)
{
if (line && ((*line == 'q') || (*line == 'Q')))
{
finished_msg_paging = 1;
if (msg_fp) fclose(msg_fp);
msg_fp = NULL;
set_msg_screen(NULL);
if (!in_read_log)
add_wait_prompt("Delete msg log [y/N]? ", remove_away_log, "", WAIT_PROMPT_LINE,1);
return;
}
if (show_log(msg_window, name))
{
add_wait_prompt("*** Hit any key for more, 'q' to quit ***",
log_prompt, name, WAIT_PROMPT_KEY,1);
}
else
{
if (msg_fp)fclose(msg_fp);
set_msg_screen(NULL);
msg_fp = NULL;
if (!in_read_log)
add_wait_prompt("Delete msg log [y/N]? ", remove_away_log, "", WAIT_PROMPT_LINE,1);
}
}
|