/* * This function either rebuilds the status_func[] tables for each of the * three possible status_format's (single, lower double, upper double) for * a particular window (w != NULL) or for the global default status bars * (w == NULL) * * This function should only by the functions that actually change the * status formats (build_status, new_window, and window_status_format*) */ void rebuild_a_status (Window *w) { int i, k; Status *s; if (w) s = &w->status; else s = &main_status; for (k = 0; k < 3; k++) { new_free((char **)&s->line[k].format); s->line[k].count = 0; /* * If we have an overriding status_format, then we parse * that out. */ if (w && s->line[k].raw) build_status_format(s, k); /* * Otherwise, If this is for a window, just copy the essential * information over from the main status lines. */ else if (w) { s->line[k].format = malloc_strdup(main_status.line[k].format); for (i = 0; i < MAX_FUNCTIONS; i++) { s->line[k].func[i] = main_status.line[k].func[i]; s->line[k].map[i] = main_status.line[k].map[i]; s->line[k].key[i] = main_status.line[k].key[i]; } s->line[k].count = main_status.line[k].count; } /* * Otherwise, this *is* the main status lines we are generating * and we need to do all the normal shenanigans. */ else { if (k == 0) s->line[k].raw = get_string_var(STATUS_FORMAT_VAR); else if (k == 1) s->line[k].raw = get_string_var(STATUS_FORMAT1_VAR); else /* (k == 2) */ s->line[k].raw = get_string_var(STATUS_FORMAT2_VAR); build_status_format(s, k); } } }
bool Theme::load(const char *f) { E_RETURN_VAL_IF_FAIL(f != NULL, false); /* do not allow loading if clear() wasn't called before */ E_RETURN_VAL_IF_FAIL(priv->sc == NULL, false); priv->is_loaded = false; init_interpreter(); scheme *ss = priv->sc; /* * Determine from which directory we loads file, and set that file as base directory * where '(include)' statement can search additional files. Include uses 'private::theme.search-path'. */ char *path = edelib_strndup(f, PATH_MAX); if(!path) E_FATAL(E_STRLOC ": No memory\n"); char *dir = local_dirname(path); /* If returned name is the same as file, dirname wasn't found directory name in given path. */ if(strcmp(dir, f) != 0) { pointer sym = mk_symbol(ss, "private:theme.search-path"); edelib_scheme_define(ss, ss->global_env, sym, mk_string(ss, dir)); ss->vptr->setimmutable(sym); } /* scheme copies path, so we do not need it any more */ free(path); FILE *fd = fopen(f, "r"); if(!fd) { edelib_scheme_deinit(ss); free(ss); priv->sc = 0; return false; } edelib_scheme_load_named_file(ss, fd, f); fclose(fd); if(ss->no_memory) { E_WARNING(E_STRLOC ": No memory to load theme source in interpreter\n"); return false; } if(ss->retcode != 0) return false; /* fetch common variables */ priv->name = get_string_var(ss, "private:theme.name"); priv->author = get_string_var(ss, "private:theme.author"); priv->sample = get_string_var(ss, "private:theme.sample"); priv->is_loaded = true; return true; }
void setup_ov_mode(int on, int hide, int log) { #ifdef WANT_OPERVIEW char *default_oper = "wsckf"; Window *win = NULL; if (on) { if ((win = get_window_by_name("oper_view"))) { if (win->log) do_log(0, NULL, &win->log_fp); delete_window(win); update_all_windows(); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); } send_to_server("MODE %s -%s%s", get_server_nickname(from_server), get_string_var(OPER_MODES_VAR)?get_string_var(OPER_MODES_VAR):default_oper, send_umode); } else { Window *tmp = NULL; win = current_window; if ((tmp = new_window(current_window->screen))) { malloc_strcpy(&tmp->name, "oper_view"); tmp->double_status = 0; if (hide) hide_window(tmp); else resize_window(1, tmp, -5); tmp->window_level = LOG_WALLOP|LOG_OPNOTE|LOG_SNOTE; tmp->absolute_size = 1; tmp->skip = 1; set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, fget_string_var(FORMAT_OV_FSET)); build_status(tmp, NULL, 0); update_all_windows(); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); send_to_server("MODE %s +%s", get_server_nickname(from_server), get_string_var(OPER_MODES_VAR)?get_string_var(OPER_MODES_VAR):default_oper); set_screens_current_window(win->screen, win); tmp->mangler = operlog_line_mangler; if (log != -1) { tmp->log = log; if (tmp->log) do_log(log, "~/.BitchX/operview.log", &tmp->log_fp); } } } #endif }
/* * we keep local copies of each of the variables so we can properly determine * when something has changed. if neither ca_path nor ca_file is set, then we * load the default paths. */ void ssl_setup_certs(u_char *dummy) { #ifdef USE_OPENSSL if (!ssl_ctx) return; static u_char *ca_file; static u_char *ca_path; static u_char *chain_file; static u_char *private_key_file; u_char *cur_ca_file = get_string_var(SSL_CA_FILE_VAR); u_char *cur_ca_path = get_string_var(SSL_CA_PATH_VAR); u_char *cur_chain_file = get_string_var(SSL_CA_CHAIN_FILE_VAR); u_char *cur_private_key_file = get_string_var(SSL_CA_PRIVATE_KEY_FILE_VAR); if (ca_file != cur_ca_file || ca_path != cur_ca_path) { ca_file = cur_ca_file; ca_path = cur_ca_path; Debug(DB_SSL, "calling SSL_CTX_load_verify_locations(%s, %s)", ca_file, ca_path); SSL_CTX_load_verify_locations(ssl_ctx, CP(ca_file), CP(ca_path)); } if (!ca_path && !ca_file) SSL_CTX_set_default_verify_paths(ssl_ctx); if (chain_file != cur_chain_file) { chain_file = cur_chain_file; Debug(DB_SSL, "calling SSL_CTX_use_certificate_chain_file(%s)", chain_file); SSL_CTX_use_certificate_chain_file(ssl_ctx, CP(chain_file)); } if (private_key_file != cur_private_key_file) { private_key_file = cur_private_key_file; Debug(DB_SSL, "calling SSL_CTX_use_PrivateKey_file(%s)", private_key_file); SSL_CTX_use_PrivateKey_file(ssl_ctx, CP(private_key_file), SSL_FILETYPE_PEM); } #endif }
/* * history_match: using wild_match(), this finds the latest match in the * history file and returns it as the function result. Returns null if there * is no match. Note that this sticks a '*' at the end if one is not already * there. */ static char *history_match(char *match) { char *ptr; char *match_str = NULL; if (*(match + strlen(match) - 1) == '*') malloc_strcpy(&match_str, match); else { match_str = new_malloc(strlen(match) + 2); strcpy(match_str, match); strcat(match_str, "*"); } if (get_int_var(HISTORY_VAR)) { if ((last_dir == -1) || (tmp == (History *) NULL)) tmp = command_history_head; else tmp = tmp->next; for (; tmp; tmp = tmp->next) { ptr = tmp->stuff; while (ptr && strchr(get_string_var(CMDCHARS_VAR), *ptr)) ptr++; if (wild_match(match_str, ptr)) { new_free(&match_str); last_dir = PREV; return (tmp->stuff); } } } last_dir = -1; new_free(&match_str); return NULL; }
static void p_part(char *from, char **ArgList) { char *channel; if (!from || !*from) return; channel = ArgList[0]; PasteArgs(ArgList, 1); message_from(channel, LOG_CRAP); in_on_who = 1; if ((check_ignore(from, FromUserHost, channel, IGNORE_PARTS | IGNORE_CRAP, NULL) != IGNORED) && do_hook(LEAVE_LIST, "%s %s %s %s", from, channel, FromUserHost, ArgList[1] ? ArgList[1] : empty_str)) put_it("%s", convert_output_format(get_format(FORMAT_LEAVE_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, channel, ArgList[1] ? ArgList[1] : empty_str)); if (!my_stricmp(from, get_server_nickname(from_server))) { remove_channel(channel, from_server); remove_from_mode_list(channel, from_server); remove_from_join_list(channel, from_server); set_input_prompt(curr_scr_win, get_string_var(INPUT_PROMPT_VAR), 0); } else { remove_from_channel(channel, from, from_server, 0, NULL); } update_all_status(curr_scr_win, NULL, 0); update_input(UPDATE_ALL); message_from(NULL, LOG_CRAP); in_on_who = 0; }
/* * This is an alternative form of put_it which writes three asterisks * before actually putting things out. */ static void vsay (const char *format, va_list args) { if (window_display && format) { char *str; *putbuf = 0; if ((str = get_string_var(BANNER_VAR))) { if (get_int_var(BANNER_EXPAND_VAR)) { char *foo; foo = expand_alias(str, empty_string); strlcpy(putbuf, foo, sizeof putbuf); new_free(&foo); } else strlcpy(putbuf, str, sizeof putbuf); strlcat(putbuf, " ", sizeof putbuf); } vsnprintf(putbuf + strlen(putbuf), sizeof(putbuf) - strlen(putbuf) - 1, format, args); put_echo(putbuf); } }
/* * add_to_log: add the given line to the log file. If no log file is open * this function does nothing. */ void add_to_log (FILE *fp, long winref, const unsigned char *line, int mangler, const char *rewriter) { char *local_line; size_t size; int must_free = 0; if (!fp || inhibit_logging) return; /* * We need to make a local copy because 'mangle_line' * diddles around with the source, and so we can't subject * line to that, it is 'const'. * * 'mangle_line' can expand the input string, so it is * neccesary to allocate more than we need. */ size = (strlen(line) + 1) * 11; local_line = alloca(size + 1); strlcpy(local_line, line, size + 1); /* Do this first */ if (mangler == 0) mangler = logfile_line_mangler; if (mangler) if (mangle_line(local_line, mangler, size) > size) (void)0; /* Whimper -- what to do, what to do? */ if (get_int_var(NO_CONTROL_LOG_VAR)) { char *tmp = alloca(strlen(local_line) + 1); strip_control(local_line, tmp); strlcpy(local_line, tmp, size); } if (rewriter == NULL) rewriter = get_string_var(LOG_REWRITE_VAR); if (rewriter) { char *prepend_exp; char argstuff[10240]; int args_flag; /* First, create the $* list for the expando */ snprintf(argstuff, 10240, "%ld %s", winref, local_line); /* Now expand the expando with the above $* */ prepend_exp = expand_alias(rewriter, argstuff, &args_flag, NULL); local_line = prepend_exp; must_free = 1; } fprintf(fp, "%s\n", local_line); fflush(fp); if (must_free) new_free(&local_line); }
void serversay(int save, int from_server, const char *format, ...) { Window *old_target_window = target_window; char servername[200]; int len = 0; char *out = NULL; if (get_int_var(OV_VAR)) target_window = get_window_by_name("OPER_VIEW"); if (window_display && format) { va_list args; va_start (args, format); vsnprintf(putbuf, LARGE_BIG_BUFFER_SIZE, format, args); va_end(args); strmcpy(servername, convert_output_format(get_string_var(SERVER_PROMPT_VAR), "%s", ov_server(from_server)?ov_server(from_server):empty_string), 79); len = strlen(putbuf); out = alloca(strlen(servername)+len+5); len = strlen(servername); strcpy(out, servername); out[len] = ' '; out[len+1] = 0; strcat(out, putbuf); if (*out) put_echo(out); } target_window = old_target_window; if (save && out) add_last_type(&last_servermsg[0], MAX_LAST_MSG, NULL, NULL, NULL, out); }
/* * set_log_file: sets the log file name. If logging is on already, this * closes the last log file and reopens it with the new name. This is called * automatically when you SET LOGFILE. */ void set_log_file(Window * win, char *filename, int unused) { char *expanded; if (filename) { if (strcmp(filename, get_string_var(LOGFILE_VAR))) expanded = expand_twiddle(filename); else expanded = expand_twiddle(get_string_var(LOGFILE_VAR)); set_string_var(LOGFILE_VAR, expanded); new_free(&expanded); if (irclog_fp) { logger(curr_scr_win, NULL, 0); logger(curr_scr_win, NULL, 1); } } }
static void reinit_screen(Window *win, char *unused, int value) { set_input_prompt(current_window, NULL, 0); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); update_all_windows(); update_all_status(current_window, NULL, 0); update_input(UPDATE_ALL); }
/* * add_to_log: add the given line to the log file. If no log file is open * this function does nothing. * (Note: "logref" should be -1 unless we are logging from a /log log, ie, * any place that is not inside logfiles.c) */ void add_to_log (int logref, FILE *fp, long winref, const unsigned char *line, int mangler, const char *rewriter) { char *local_line = NULL; int old_logref; static int recursive = 0; /* * I added "recursive" because this function should not * generate any output. But it might generate output if * the string expand was bogus below. I chose to "fix" this * by refusing to log anything recursively. The downside * is any errors won't get logged, which may or may not be * a problem, I haven't decided yet. */ if (recursive > 0) return; if (!fp || inhibit_logging) return; recursive++; old_logref = current_log_refnum; current_log_refnum = logref; /* Do this first */ /* Either do mangling or /set no_control_log, but never both! */ if (mangler == 0) mangler = logfile_line_mangler; else if (get_int_var(NO_CONTROL_LOG_VAR)) mangler |= STRIP_UNPRINTABLE; if (mangler) local_line = new_normalize_string(line, 1, mangler); else local_line = malloc_strdup(line); if (rewriter == NULL) rewriter = get_string_var(LOG_REWRITE_VAR); if (rewriter) { char *prepend_exp; char argstuff[10240]; /* First, create the $* list for the expando */ snprintf(argstuff, 10240, "%ld %s", winref, local_line); new_free(&local_line); /* Now expand the expando with the above $* */ prepend_exp = expand_alias(rewriter, argstuff); local_line = prepend_exp; } fprintf(fp, "%s\n", local_line); fflush(fp); new_free(&local_line); current_log_refnum = old_logref; recursive--; }
void print_lastlog(Lastlog *msg, int timelog) { time_t ltime; struct tm *tm; char buff[129]; if (timelog) { ltime = msg->time; tm = localtime(<ime); strftime(buff, 128, get_string_var(LASTLOG_TIMEFORMAT_VAR) ? get_string_var(LASTLOG_TIMEFORMAT_VAR) : "[%H:%M]", tm); put_it("%s %s", buff, msg->msg); } else put_it("%s", msg->msg); }
void debug_window(Window *win, char *value, int unused) { Window *old_win = win; char *nv = NULL; internal_debug = parse_debug(value, internal_debug, &nv); set_string_var(DEBUG_VAR, nv); if (internal_debug) { Window *tmp = NULL; if (!get_window_by_name("debug") && (tmp = new_window(win->screen))) { malloc_strcpy(&tmp->name, "debug"); tmp->double_status = 0; hide_window(tmp); tmp->window_level = LOG_DEBUG; tmp->absolute_size = 1; tmp->skip = 1; debugging_window = tmp; set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, DEFAULT_FORMAT_DEBUG_FSET); build_status(tmp, NULL, 0); update_all_windows(); set_input_prompt(win, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); set_screens_current_window(old_win->screen, old_win); } } else { if ((old_win = get_window_by_name("debug"))) { delete_window(old_win); debugging_window = NULL; update_all_windows(); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); cursor_to_input(); } } new_free(&nv); }
static void handle_swap(int windownum) { char *p = NULL; malloc_sprintf(&p, "SWAP %d", windownum); t_parse_command("WINDOW", p); set_channel_window(curr_scr_win, get_current_channel_by_refnum(curr_scr_win->refnum), curr_scr_win->server); new_free(&p); set_input_prompt(curr_scr_win, get_string_var(INPUT_PROMPT_VAR), 0); update_input(UPDATE_ALL); update_all_windows(); }
static int check_cdrom_str(void) { char *str; if ((str = get_string_var(CD_DEVICE_VAR))) { if (!drive) cd_init(str); return 1; } put_it("%s: /SET CD_DEVICE - The name of the CDROM device",cparse(cdrom_prompt)); return 0; }
int save_formats(FILE *outfile) { char thefile[BIG_BUFFER_SIZE+1]; char *p; int i; int count = 0; FsetNumber *tmp; #if defined(__EMX__) || defined(WINNT) sprintf(thefile, "%s/%s.fmt", get_string_var(CTOOLZ_DIR_VAR), version); #else sprintf(thefile, "%s/%s.formats", get_string_var(CTOOLZ_DIR_VAR), version); #endif p = expand_twiddle(thefile); outfile = fopen(p, "w"); if (!outfile) { bitchsay("Cannot open file %s for saving!", thefile); new_free(&p); return 1; } for (i = 0; i < NUMBER_OF_FSET; i++) { if (fset_array[i].string) fprintf(outfile, "FSET %s %s\n", fset_array[i].name, fset_array[i].string); else fprintf(outfile, "FSET -%s\n", fset_array[i].name); } count = NUMBER_OF_FSET; for (tmp = numeric_fset; tmp; tmp = tmp->next) { fprintf(outfile, "FSET %d %s\n", tmp->numeric, tmp->format); count++; } fclose(outfile); bitchsay("Saved %d formats to %s", count, thefile); new_free(&p); return 0; }
/* logger: if flag is 0, logging is turned off, else it's turned on */ void logger(Window *win, char *unused, int flag) { char *logfile; if ((logfile = get_string_var(LOGFILE_VAR)) == NULL) { say("You must set the LOGFILE variable first!"); set_int_var(LOG_VAR, 0); return; } do_log(flag, logfile, &irclog_fp); if (!irclog_fp && flag) set_int_var(LOG_VAR, 0); }
void ignore_last_nick(char dumb, char *dumber) { NickTab *nick; char *tmp1; if ((nick = gettabkey(1, NULL))) { set_input(empty_str); tmp1 = m_sprintf("%sig %s", get_string_var(CMDCHARS_VAR), nick->nick); set_input(tmp1); new_free(&tmp1); } update_input(UPDATE_ALL); }
void input_msgreply(char dumb, char *dumber) { char *cmdchar; char *line, *cmd, *t; char *snick; NickTab *nick = NULL; int got_space = 0; if (!(cmdchar = get_string_var(CMDCHARS_VAR))) cmdchar = DEFAULT_CMDCHARS; t = line = m_strdup(get_input()); if (t) got_space = strchr(t, ' ') ? 1 : 0; cmd = next_arg(line, &line); snick = next_arg(line, &line); if ((cmd && *cmd == *cmdchar && got_space) || !cmd) { if (cmd && *cmd == *cmdchar) cmd++; if (in_completion == STATE_NORMAL && snick) strncpy(new_nick, snick, sizeof(new_nick) - 1); if ((nick = getnextnick(new_nick, input_lastmsg, snick))) { if (nick->nick && *(nick->nick)) { snick = nick->nick; malloc_strcpy(&input_lastmsg, nick->nick); } } if (nick) { char *tmp = NULL; input_clear_line('\0', NULL); if (get_fset_var(FORMAT_NICK_MSG_FSET)) malloc_strcpy(&tmp, stripansicodes(convert_output_format (get_fset_var(FORMAT_NICK_MSG_FSET), "%s%s %s %s", cmdchar, nick->type ? nick->type : cmd ? cmd : "msg", nick->nick, line ? line : empty_str))); else malloc_sprintf(&tmp, "%s%s %s %s", cmdchar, nick->type ? nick->type : cmd ? cmd : "msg", nick->nick, line ? line : empty_str); set_input(tmp); new_free(&tmp); } else command_completion(0, NULL); } else command_completion(0, NULL); update_input(UPDATE_ALL); new_free(&t); }
void reset_clock (void *stuff) { char * sclock; if (x_debug & DEBUG_BROKEN_CLOCK) reset_broken_clock(); else if (get_int_var(METRIC_TIME_VAR)) reset_metric_clock(); else reset_standard_clock(); sclock = get_string_var(STATUS_CLOCK_VAR); if (sclock && *sclock) update_all_status(); }
/* logger: if flag is 0, logging is turned off, else it's turned on */ void logger (const void *stuff) { int flag = *(const int *)stuff; char *logfile; if ((logfile = get_string_var(LOGFILE_VAR)) == (char *) 0) { say("You must set the LOGFILE variable first!"); set_int_var(LOG_VAR, 0); return; } do_log(flag, logfile, &irclog_fp); if (!irclog_fp && flag) set_int_var(LOG_VAR, 0); }
void check_shit(ChannelList *chan) { ShitList *Bans; if (!chan || !chan->chop || !shitlist_list || chan->server <= -1 || !get_cset_int_var(chan->csets, SHITLIST_CSET)) return; if (!check_channel_match(get_string_var(PROTECT_CHANNELS_VAR), chan->channel)) return; for (Bans = shitlist_list; Bans; Bans = Bans->next) { /* this is a permanent ban */ if (!check_channel_match(Bans->channels, chan->channel)) continue; if ((Bans->level == 4) && !ban_is_on_channel(Bans->filter, chan) && !eban_is_on_channel(Bans->filter, chan)) add_mode(chan, "b", 1, Bans->filter, NULL, get_int_var(NUM_BANMODES_VAR)); } flush_mode_all(chan); }
static int simple_exec_try(const char *exec, active_db_h * service, process_h * process) { char *exec_args = NULL; char **argv = NULL; size_t argc = 0; int ret; D_("exec: %s, service: %s, process: %s\n", exec, service->name, process->pt->name); /* exec_args should be parsed at the moment, too */ exec_args = (char *)get_string_var(&EXEC_ARGS, process->pt->name, service); if (exec_args) { initng_string_fix_escapes(exec_args); /* split the string, with entries to an array of strings */ argv = initng_string_split_delim(exec_args + 1, WHITESPACE, &argc); /* make sure it succeeded */ if (!argv || !argv[0]) { if (argv) initng_string_split_delim_free(argv); F_("initng_string_split_delim exec_args returns NULL.\n"); return FALSE; } } else { /* we need a empty argv anyway */ argv = (char **)initng_toolbox_calloc(2, sizeof(char *)); argv[1] = NULL; argc = 0; } argv[0] = (char *)exec; ret = simple_exec_fork(process, service, argc, argv); if (argv) initng_string_split_delim_free(argv); return ret; }
/* * syserr is exactly like say, except that if the error occured while * you were loading a script, it tells you where it happened. */ static void vsyserr (int server, const char *format, va_list args) { char * str; int l, old_from_server = from_server; int i_set_from_server = 0; if (!window_display || !format) return; *putbuf = 0; if ((str = get_string_var(BANNER_VAR))) { if (get_int_var(BANNER_EXPAND_VAR)) { char *foo; foo = expand_alias(str, empty_string); strlcpy(putbuf, foo, sizeof putbuf); new_free(&foo); } else strlcpy(putbuf, str, sizeof putbuf); strlcat(putbuf, " INFO -- ", sizeof putbuf); } vsnprintf(putbuf + strlen(putbuf), sizeof(putbuf) - strlen(putbuf) - 1, format, args); if (is_server_valid(server)) { old_from_server = from_server; from_server = server; i_set_from_server = 1; } l = message_from(NULL, LEVEL_SYSERR); if (do_hook(YELL_LIST, "%s", putbuf)) put_echo(putbuf); pop_message_from(l); if (i_set_from_server) from_server = old_from_server; }
/* logger: if flag is 0, logging is turned off, else it's turned on */ void logger (void *stuff) { VARIABLE *v; int flag; char * logfile; v = (VARIABLE *)stuff; flag = v->integer; if ((logfile = get_string_var(LOGFILE_VAR)) == (char *) 0) { say("You must set the LOGFILE variable first!"); v->integer = 0; return; } do_log(flag, logfile, &irclog_fp); if (!irclog_fp && flag) v->integer = 0; }
static void p_kill(char *from, char **ArgList) { char sc[20]; int port; int local = 0; port = get_server_port(from_server); if (ArgList[1] && strstr(ArgList[1], get_server_name(from_server))) if (!strchr(from, '.')) local = 1; snprintf(sc, 19, "+%i %d", from_server, port); close_server(from_server, empty_str); clean_whois_queue(); window_check_servers(); set_input_prompt(curr_scr_win, get_string_var(INPUT_PROMPT_VAR), 0); if (strchr(from, '.')) { say("Server [%s] has rejected you (probably due to a nick collision)", from); t_parse_command("SERVER", NULL); } else { if (local && get_int_var(NEXT_SERVER_ON_LOCAL_KILL_VAR)) { int i = from_server + 1; if (i >= number_of_servers) i = 0; snprintf(sc, 19, "+%i", i); from_server = -1; } if (do_hook(DISCONNECT_LIST, "Killed by %s (%s)", from, ArgList[1] ? ArgList[1] : "(No Reason Given)")) put_it("%s", convert_output_format(get_format(FORMAT_KILL_FSET), "%s %s", update_clock(GET_TIME), ArgList[1] ? ArgList[1] : "You have been Killed")); if (get_int_var(AUTO_RECONNECT_VAR)) t_parse_command("SERVER", NULL); } update_all_status(curr_scr_win, NULL, 0); }
/* * banner: This returns in a static string of either "xxx" where * xxx is the current numeric, or "***" if SHOW_NUMBERS is OFF */ const char * banner (void) { static char thing[80]; char *str; if (current_numeric > 0 && get_int_var(SHOW_NUMERICS_VAR)) snprintf(thing, sizeof thing, "%3.3u", current_numeric); else if ((str = get_string_var(BANNER_VAR))) { if (get_int_var(BANNER_EXPAND_VAR)) { char *foo = expand_alias(str, empty_string); strlcpy(thing, foo, sizeof thing); new_free(&foo); } else strlcpy(thing, str, sizeof thing); } else *thing = 0; return (thing); }
int main(int argc, char *argv[], char *envp[]) { char *channel; debug_init(); srand((unsigned)time(NULL)); time(&start_time); time(&idle_time); time(&now); #ifdef WINNT fprintf(stdout, "%s %s\r\n", nap_version, internal_version); fprintf(stdout, "%s\r\n", main_version); #else fprintf(stdout, "%s %s\n", nap_version, internal_version); fprintf(stdout, "%s\n", main_version); #endif channel = parse_args(argv, argc, envp); FD_ZERO(&readables); FD_ZERO(&writables); if (term_init(NULL)) _exit(1); /* my_signal(SIGQUIT, SIG_IGN, 0);*/ my_signal(SIGHUP, irc_exit_old, 0); my_signal(SIGTERM, irc_exit_old, 0); my_signal(SIGPIPE, SIG_IGN, 0); my_signal(SIGINT, cntl_c, 0); my_signal(SIGALRM, nothing, 0); my_signal(SIGCHLD, child_reap, 0); my_signal(SIGCONT, term_cont, 0); my_signal(SIGWINCH, sig_refresh_screen, 0); my_signal(SIGUSR1, sigusr1, 0); if (!init_screen()) { create_new_screen(); new_window(main_screen); } init_keys(); init_keys2(); init_variables(); #ifdef WANT_THREAD init_share_mutexes(); #ifdef WANT_NSLOOKUP start_dns(); #endif #ifdef WANT_MP3PLAYER start_mp3(); #endif #ifdef GTK start_tgtk(); #endif #endif build_status(current_window, NULL, 0); update_input(UPDATE_ALL); #ifndef WINNT charset_ibmpc(); #endif load_scripts(); read_unfinished_list(); if (auto_connect) { int serv = 0; reload_save(NULL, NULL, NULL, NULL, 0); if (starting_server != -1) serv = starting_server; connect_to_server_by_refnum(serv, -1, create); current_window->server = serv; xterm_settitle(); } else { if (do_get_napigator) get_napigator(); display_server_list(); } set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0); for (;;) io("main"); #ifdef GUI1 gui_exit(); #else nappanic("get_line() returned"); #endif return (-((int)0xdead)); }
/* * help_me: The big one. The help procedure that handles working out * what was actually requested, sets up the paused topic list if it is * needed, does pretty much all the hard work. */ static void help_me (char *topics, char *args) { char * ptr; glob_t g; int entries = 0, cnt, i, cols; Stat stat_buf; char path[BIG_BUFFER_SIZE+1]; int help_paused_first_call = 0; char * help_paused_path = (char *) 0; char * help_paused_name = (char *) 0; char * temp; char tmp[BIG_BUFFER_SIZE+1]; char buffer[BIG_BUFFER_SIZE+1]; char * pattern = NULL; strlcpy(help_topic_list, topics, sizeof help_topic_list); ptr = get_string_var(HELP_PATH_VAR); snprintf(path, sizeof path, "%s/%s", ptr, topics); for (ptr = path; (ptr = strchr(ptr, ' '));) *ptr = '/'; /* * first we check access to the help dir, whinge if we can't, then * work out we need to ask them for more help, else we check the * args list, and do the stuff */ if (help_show_directory) { help_show_paused_topic(paused_topic, empty_string); help_show_directory = 0; } finished_help_paging = 0; if (access(path, R_OK|X_OK)) { help_put_it(no_help, "*** Cannot access help directory!"); set_help_screen((Screen *) 0); return; } this_arg = next_arg(args, &args); if (!this_arg && *help_topic_list && get_int_var(HELP_PROMPT_VAR)) { if ((temp = strrchr(help_topic_list, ' ')) != NULL) *temp = '\0'; else *help_topic_list = '\0'; snprintf(tmp, sizeof tmp, "%s%sHelp? ", help_topic_list, *help_topic_list ? " " : empty_string); if (!dumb_mode) add_wait_prompt(tmp, help_me, help_topic_list, WAIT_PROMPT_LINE, 1); return; } if (!this_arg) { set_help_screen((Screen *) 0); return; } create_help_window(); if (!help_window) return; /* * This is just a bogus while loop which is intended to allow * the user to do '/help alias expressions' without having to * include a slash inbetween the topic and subtopic. * * If all goes well, we 'break' at the bottom of the loop. */ while (this_arg) { entries = 0; if (!*this_arg) help_topic(path, NULL); if (strcmp(this_arg, "?") == 0) { this_arg = empty_string; if (!dont_pause_topic) dont_pause_topic = 1; } /* * entry_size is set to the width of the longest help topic * (adjusted for compression extensions, of course.) */ entry_size = 0; /* * Gather up the names of the files in the help directory. */ { size_t size; #ifndef HAVE_FCHDIR char opath[MAXPATHLEN + 1]; getcwd(opath, MAXPATHLEN); #else int cwd = open(".", O_RDONLY); #endif size = strlen(path) + 2 + strlen(this_arg) + 3; chdir(path); pattern = alloca(size); snprintf(pattern, size, "%s*", this_arg); #ifdef GLOB_INSENSITIVE bsd_glob(pattern, GLOB_INSENSITIVE, NULL, &g); #else bsd_glob(pattern, 0, NULL, &g); #endif #ifndef HAVE_FCHDIR chdir(opath); #else fchdir(cwd); close(cwd); #endif } for (i = 0; i < g.gl_matchc; i++) { char *tmp2 = g.gl_pathv[i]; int len = strlen(tmp2); if (!end_strcmp(tmp2, ".gz", 3)) len -= 3; entry_size = (len > entry_size) ? len : entry_size; } /* * Right here we need to check for an 'exact match'. * An 'exact match' would be sitting in gl_pathv[0], * and it is 'exact' if it is identical to what we are * looking for, or if it is the same except that it has * a compression extension on it */ if (g.gl_matchc > 1) { char *str1 = g.gl_pathv[0]; const char *str2 = this_arg; int len1 = strlen(str1); int len2 = strlen(str2); if (len1 == len2 && !my_stricmp(str1, str2)) entries = 1; else if (len1 - 3 == len2 && !my_strnicmp(str1, str2, len2) && !end_strcmp(str1, ".gz", 3)) entries = 1; else if (len1 - 2 == len2 && !my_strnicmp(str1, str2, len2) && !end_strcmp(str1, ".Z", 2)) entries = 1; else if (len1 - 2 == len2 && !my_strnicmp(str1, str2, len2) && !end_strcmp(str1, ".z", 2)) entries = 1; } if (!*help_topic_list) dont_pause_topic = 1; /* reformatted */ /* * entries: -1 means something really died, 0 means there * was no help, 1, means it wasn't a directory, and so to * show the help file, and the default means to add the * stuff to the paused topic list.. */ if (!entries) entries = g.gl_matchc; switch (entries) { case -1: { help_put_it(no_help, "*** Error during help function: %s", strerror(errno)); set_help_screen(NULL); if (help_paused_first_call) { help_topic(help_paused_path, help_paused_name); help_paused_first_call = 0; new_free(&help_paused_path); new_free(&help_paused_name); } message_from(NULL, LOG_CRAP); return; } case 0: { help_put_it(this_arg, "*** No help available on %s: Use ? for list of topics", this_arg); if (!get_int_var(HELP_PROMPT_VAR)) { set_help_screen(NULL); break; } snprintf(tmp, sizeof tmp, "%s%sHelp? ", help_topic_list, *help_topic_list ? " " : empty_string); if (!dumb_mode) add_wait_prompt(tmp, help_me, help_topic_list, WAIT_PROMPT_LINE, 1); if (help_paused_first_call) { help_topic(help_paused_path, help_paused_name); help_paused_first_call = 0; new_free(&help_paused_path); new_free(&help_paused_name); } break; } case 1: { snprintf(tmp, sizeof tmp, "%s/%s", path, g.gl_pathv[0]); stat(tmp, &stat_buf); if (stat_buf.st_mode & S_IFDIR) { strlcpy(path, tmp, sizeof path); if (*help_topic_list) strlcat(help_topic_list, " ", sizeof help_topic_list); strlcat(help_topic_list, g.gl_pathv[0], sizeof help_topic_list); if (!(this_arg = next_arg(args, &args))) { help_paused_first_call = 1; malloc_strcpy(&help_paused_path, path); malloc_strcpy(&help_paused_name, g.gl_pathv[0]); dont_pause_topic = -1; this_arg = "?"; } bsd_globfree(&g); continue; } else { help_topic(path, g.gl_pathv[0]); finished_help_paging = 0; break; } } default: { help_show_directory = 1; strlcpy(paused_topic, help_topic_list, sizeof paused_topic); help_pause_add_line("*** %s choices:", help_topic_list); entry_size += 2; cols = (current_term->TI_cols - 10) / entry_size; strlcpy(buffer, empty_string, sizeof(buffer)); cnt = 0; for (i = 0; i < entries; i++) { if (!end_strcmp(g.gl_pathv[i], ".gz", 3)) chop(g.gl_pathv[i], 3); strlcat(buffer, g.gl_pathv[i], sizeof buffer); /* * Since we already know how many columns each * line will contain, we check to see if we have * accumulated that many entries. If we have, we * output the line to the screen. */ if (++cnt == cols) { help_pause_add_line("%s", buffer); *buffer = 0; cnt = 0; } /* * If we have not finished this line, then we have * to pad the name length out to the expected width. * 'entry_size' is the column width. We also have * do adjust for compression extension. */ else strextend(buffer, ' ', entry_size - strlen(g.gl_pathv[i])); } help_pause_add_line("%s", buffer); if (help_paused_first_call) { help_topic(help_paused_path, help_paused_name); help_paused_first_call = 0; new_free(&help_paused_path); new_free(&help_paused_name); } if (dont_pause_topic == 1) { help_show_paused_topic(paused_topic, empty_string); help_show_directory = 0; } break; } } /* end of reformatting */ bsd_globfree(&g); break; } /* * This one is for when there was never a topic and the prompt * never got a topic.. and help_screen was never reset.. * phone, jan 1993. */ if (!*help_topic_list && finished_help_paging) set_help_screen((Screen *) 0); message_from(NULL, LOG_CRAP); }