static char * encrypt_by_prog (const unsigned char *str, size_t *len, Crypt *key) { char *ret = NULL, *input; char * args[3]; int iplen; args[0] = malloc_strdup(key->prog); args[1] = malloc_strdup("encrypt"); args[2] = NULL; input = malloc_strdup2(key->key, "\n"); iplen = strlen(input); new_realloc((void**)&input, *len + iplen); memmove(input + iplen, str, *len); *len += iplen; ret = exec_pipe(key->prog, input, len, args); new_free(&args[0]); new_free(&args[1]); new_free((char**)&input); new_realloc((void**)&ret, 1+*len); ret[*len] = 0; return ret; }
char *make_string_var_bydata (int type, void *vp) { char *ret = (char *) 0; VARIABLE *data = (VARIABLE *)vp; switch (type) { case STR_VAR: if (data->string) ret = malloc_strdup(data->string); break; case INT_VAR: ret = malloc_strdup(ltoa(data->integer)); break; case BOOL_VAR: ret = malloc_strdup(var_settings[data->integer]); break; case CHAR_VAR: { char utf8str[16]; ucs_to_utf8(data->integer, utf8str, sizeof(utf8str)); ret = malloc_strdup(utf8str); break; } default: panic(1, "make_string_var_bydata: unrecognized type [%d]", type); } return (ret); }
/* Stopping has one big memory leak right now, so it's not used. */ void perlstartstop (int startnotstop) { if (startnotstop && !isperlrunning) { char *embedding[3]; embedding[0] = malloc_strdup(empty_string); embedding[1] = malloc_strdup("-e"); embedding[2] = malloc_strdup("$SIG{__DIE__}=$SIG{__WARN__}=\\&EPIC::yell;"); ++isperlrunning; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, xs_init, 3, embedding, NULL); if (SvTRUE(ERRSV)) yell("perl_parse: %s", SvPV_nolen(ERRSV)); perl_run(my_perl); if (SvTRUE(ERRSV)) yell("perl_run: %s", SvPV_nolen(ERRSV)); } else if (!startnotstop && isperlrunning && !perlcalldepth) { perl_destruct(my_perl); if (SvTRUE(ERRSV)) yell("perl_destruct: %s", SvPV_nolen(ERRSV)); perl_free(my_perl); if (SvTRUE(ERRSV)) yell("perl_free: %s", SvPV_nolen(ERRSV)); isperlrunning=0; } }
/* * Create a clone of 'var' suitable for putting on the symbol table stack * This does not create a new built in variable! * The new IrcVariable created here can be "used" by $symbolctl() but * can not be put into the bucket! * Pass it to 'unclone_biv' later. */ IrcVariable * clone_biv (IrcVariable *old) { IrcVariable *var; if (!old) return NULL; /* Take THAT! */ var = (IrcVariable *)new_malloc(sizeof(IrcVariable)); var->type = old->type; if (old->script) var->script = malloc_strdup(old->script); else var->script = NULL; var->func = old->func; var->data = new_malloc(sizeof(union builtin_variable)); var->flags = 0; switch (old->type) { case BOOL_VAR: case CHAR_VAR: case INT_VAR: var->data->integer = old->data->integer; break; case STR_VAR: if (old->data->string) var->data->string = malloc_strdup(old->data->string); else var->data->string = NULL; break; } return var; }
char * file_readb (int fd, int numb) { File *ptr = lookup_file(fd); if (!ptr) return malloc_strdup(empty_string); else { char * ret; char * blah; blah = (char *)new_malloc(numb+1); if (ptr->elf->fp) { clearerr(ptr->elf->fp); numb = fread(blah, 1, numb, ptr->elf->fp); #ifdef HAVE_LIBARCHIVE } else if (ptr->elf->a) { numb = archive_read_data(ptr->elf->a, blah, numb); #endif } else { /* others */ } if ((ret = transform_string_dyn("+CTCP", blah, numb, NULL))) new_free(&blah); else ret = blah; return ret; } }
/* * 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--; }
/* BIV stands for "built in variable" */ static int add_biv (const char *name, int bucket, int type, void (*func) (void *), const char *script, ...) { IrcVariable *var; va_list va; int numval; const char *strval; var = (IrcVariable *)new_malloc(sizeof(IrcVariable)); var->type = type; if (script) var->script = malloc_strdup(script); else var->script = NULL; var->func = func; var->data = new_malloc(sizeof(union builtin_variable)); var->flags = 0; va_start(va, script); switch (var->type) { case BOOL_VAR: case CHAR_VAR: case INT_VAR: numval = va_arg(va, int); var->data->integer = numval; break; case STR_VAR: strval = va_arg(va, char *); if (strval) var->data->string = malloc_strdup(strval); else var->data->string = NULL; break; } va_end(va); add_builtin_variable_alias(name, var); if (bucket) { add_to_bucket(var_bucket, name, var); return (var_bucket->numitems - 1); } else return -1; }
/* * 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); } } }
/* * init_mbox_checking: Look for the user's mbox * * Look for an mbox-style mailbox. If the user sets the MAIL environment * variable, we use that. Otherwise, we look for a file by the user's name * in the usual directories (/var/spool/mail, /usr/spool/mail, /var/mail, * and /usr/mail). If we cannot find an mbox anywhere, we forcibly turn off * mail checking. This will defeat the mail timer and save the user trouble. * * Return value: * 1 if an mbox was found. * 0 if an mbox was not found. */ static int init_mbox_checking (void) { const char *mbox_path_list = "/var/spool/mail:/usr/spool/mail:" "/var/mail:/usr/mail"; Filename tmp_mbox_path; if (getenv("MAIL") && file_exists(getenv("MAIL"))) mbox_path = malloc_strdup(getenv("MAIL")); else if (!path_search(username, mbox_path_list, tmp_mbox_path)) mbox_path = malloc_strdup(tmp_mbox_path); else { say("I can't find your mailbox."); set_int_var(MAIL_VAR, 0); return 0; } return 1; }
/* * clone_timer: Create a copy of an existing timer, suitable for rescheduling */ static Timer *clone_timer (Timer *otimer) { Timer *ntimer = new_timer(); strlcpy(ntimer->ref, otimer->ref, sizeof ntimer->ref); ntimer->time = otimer->time; if ((ntimer->callback = otimer->callback)) ntimer->callback_data = otimer->callback_data; else ntimer->command = malloc_strdup(otimer->command); ntimer->subargs = malloc_strdup(otimer->subargs); ntimer->prev = NULL; ntimer->next = NULL; ntimer->events = otimer->events; ntimer->interval = otimer->interval; ntimer->server = otimer->server; ntimer->window = otimer->window; return ntimer; }
/* * clone_timer: Create a copy of an existing timer, suitable for rescheduling */ static Timer *clone_timer (Timer *otimer) { Timer *ntimer = new_timer(); malloc_strcpy(&ntimer->ref, otimer->ref); ntimer->time = otimer->time; if ((ntimer->callback = otimer->callback)) ntimer->callback_data = otimer->callback_data; else ntimer->command = malloc_strdup(otimer->command); ntimer->subargs = malloc_strdup(otimer->subargs); ntimer->prev = NULL; ntimer->next = NULL; ntimer->events = otimer->events; ntimer->interval = otimer->interval; ntimer->domain = otimer->domain; ntimer->domref = otimer->domref; ntimer->cancelable = otimer->cancelable; ntimer->fires = otimer->fires; return ntimer; }
/* * XXX - Ugh! Some getaddrinfo()s take AF_UNIX paths as the 'servname' * instead of as the 'nodename'. How heinous! */ int my_getaddrinfo (const char *nodename, const char *servname, const AI *hints, AI **res) { #ifdef GETADDRINFO_DOES_NOT_DO_AF_UNIX int do_af_unix = 0; USA storage; AI * results; int len; if (nodename && strchr(nodename, '/')) do_af_unix = 1; if (hints && hints->ai_family == AF_UNIX) do_af_unix = 1; if (do_af_unix) { memset(&storage, 0, sizeof(storage)); storage.sun_family = AF_UNIX; strlcpy(storage.sun_path, nodename, sizeof(storage.sun_path)); #ifdef HAVE_SA_LEN # ifdef SUN_LEN storage.sun_len = SUN_LEN(&storage); # else storage.sun_len = strlen(nodename) + 1; # endif #endif len = strlen(storage.sun_path) + 3; (*res) = new_malloc(sizeof(*results)); (*res)->ai_flags = 0; (*res)->ai_family = AF_UNIX; (*res)->ai_socktype = SOCK_STREAM; (*res)->ai_protocol = 0; (*res)->ai_addrlen = len; (*res)->ai_canonname = malloc_strdup(nodename); (*res)->ai_addr = new_malloc(sizeof(storage)); *(USA *)((*res)->ai_addr) = storage; (*res)->ai_next = 0; return 0; } #endif /* * XXX -- Support getaddrinfo()s that want an AF_UNIX path to * be the second argument and not the first one. Bleh. */ if ((nodename && strchr(nodename, '/')) || (hints && hints->ai_family == AF_UNIX)) return getaddrinfo(NULL, nodename, hints, res); else return getaddrinfo(nodename, servname, hints, res); }
static void show_var_value (const char *name, IrcVariable *var, int newval) { char *value; value = make_string_var_bydata(var->type, (void *)var->data); if (!value) value = malloc_strdup("<EMPTY>"); say("%s value of %s is %s", newval ? "New" : "Current", name, value); new_free(&value); }
static XS (XS_call) { int foo = 0; char* retval=NULL; char* arg=NULL; dXSARGS; for (foo=0; foo<items; foo++) { arg = malloc_strdup((char*)SvPV_nolen(ST(foo))); retval = (char*)call_function(arg, ""); XST_mPV(foo, retval); new_free(&arg); new_free(&retval); } XSRETURN(items); }
static XS (XS_expr) { unsigned foo, food = 0; char* retval=NULL; char* arg=NULL; dXSARGS; for (foo=0; foo<items; foo++) { arg = malloc_strdup((char*)SvPV_nolen(ST(foo))); retval = (char*)parse_inline(arg, "", &food); XST_mPV(foo, retval); new_free(&arg); new_free(&retval); } XSRETURN(items); }
/* * init_maildir_checking: Look for the user's maildir * * Return value: * 1 if a maildir was found. * 0 if a maildir was not found. */ static int init_maildir_checking (void) { Filename tmp_maildir_path; const char * maildir; const char * envvar; envvar = "MAILDIR"; if (!(maildir = getenv(envvar))) { envvar = "MAIL"; if (!(maildir = getenv(envvar))) { say("Can't find your maildir -- Both your MAILDIR " "and MAIL environment variables are unset."); set_int_var(MAIL_VAR, 0); return 0; } } if (!file_exists(maildir)) { say("The file in your %s environment variable " "does not exist.", envvar); set_int_var(MAIL_VAR, 0); return 0; } if (!isdir(maildir)) { say("The file in your %s environment variable " "is not a directory.", envvar); set_int_var(MAIL_VAR, 0); return 0; } strlcpy(tmp_maildir_path, maildir, sizeof(Filename)); strlcat(tmp_maildir_path, "/new", sizeof(Filename)); if (!file_exists(tmp_maildir_path) || !isdir(tmp_maildir_path)) { say("The directory in your %s environment variable " "does not contain a sub-directory called 'new'", envvar); set_int_var(MAIL_VAR, 0); return 0; } maildir_path = malloc_strdup(maildir); maildir_last_changed = -1; return 1; }
/* Called by the epic hooks to activate tcl on-demand. */ void ruby_startstop (int value) { VALUE rubyval; /* If it is already in the state we want, do nothing. */ if (is_ruby_running == value) return; /* Do a shutdown */ if (value == 0) { is_ruby_running = 0; /* Do shutdown stuff */ return; } /* Do a startup */ ++is_ruby_running; ruby_init(); ruby_init_loadpath(); ruby_script(malloc_strdup(irc_version)); rubyclass = rb_define_class("EPIC", rb_cObject); rb_define_singleton_method(rubyclass, "echo", epic_echo, 1); rb_define_singleton_method(rubyclass, "say", epic_say, 1); rb_define_singleton_method(rubyclass, "cmd", epic_cmd, 1); rb_define_singleton_method(rubyclass, "eval", epic_eval, 1); rb_define_singleton_method(rubyclass, "expr", epic_expr, 1); rb_define_singleton_method(rubyclass, "call", epic_call, 1); rb_gc_register_address(&rubyclass); /* XXX Is it a hack to do it like this instead of in pure C? */ rubyval = rb_eval_string("EPICstderr = Object.new unless defined? EPICstderr\n" "def EPICstderr.write(string) \n" " str = string.chomp \n" " EPIC.echo(\"RUBY-ERROR: #{str}\") \n" "end \n" "$stderr = EPICstderr"); if (rubyval == Qnil) say("stderr assignment returned Qnil"); rubyval = rb_eval_string("EPICstdout = Object.new unless defined? EPICstdout\n" "def EPICstdout.write(string) \n" " str = string.chomp \n" " EPIC.echo(str) \n" "end \n" "$stdout = EPICstdout"); if (rubyval == Qnil) say("stderr assignment returned Qnil"); }
int add_new_level_alias (int level, const char *name) { const char *name_copy; int * levelnum; int i; if ((i = str_to_level(name)) != -1) return i; name_copy = malloc_strdup(name); levelnum = new_malloc(sizeof(int)); *levelnum = level; add_to_bucket(level_bucket, name_copy, levelnum); return *levelnum; }
static void copy_key (const char *orig, size_t orig_len, char **key, size_t *keylen) { #if 0 size_t key_len; orig_len = strlen(orig); /* XXX for now */ if ((key_len = orig_len) < 9) key_len = 9; *key = new_malloc(key_len); memset(*key, 0, key_len); strlcpy(*key, orig, key_len); #else *key = malloc_strdup(orig); #endif *keylen = orig_len; }
char * file_read (int fd) { File *ptr = lookup_file(fd); if (!ptr) return malloc_strdup(empty_string); else { char *ret = NULL; size_t retlen = 0; size_t retbufsiz = 0; char *end = NULL; if (ptr->elf->fp) clearerr(ptr->elf->fp); for (;;) { retbufsiz += 4096; RESIZE(ret, char, retbufsiz); ret[retlen] = 0; /* Keep this -- C requires it! */ if (!epic_fgets(ret + retlen, retbufsiz - retlen, ptr->elf)) break; if ((end = strchr(ret + retlen, '\n'))) break; retlen = retbufsiz - 1; } /* Do we need to truncate the result? */ if (end) *end = 0; /* Either the newline */ else if ( (ptr->elf->fp) && (ferror(ptr->elf->fp)) ) *ret = 0; /* Or the whole thing on error */ /* XXX TODO -- this is just temporary */ if (invalid_utf8str(ret)) { const char *encodingx; encodingx = find_recoding("scripts", NULL, NULL); recode_with_iconv(encodingx, NULL, &ret, &retlen); } return ret; } }
/* * This adds a new /wait %proc -cmd entry to a running process. */ void add_process_wait (int proc_index, const char *cmd) { Process *proc = process_list[proc_index]; List *new_ewl, *posn; new_ewl = new_malloc(sizeof(List)); new_ewl->next = NULL; new_ewl->name = malloc_strdup(cmd); if ((posn = proc->waitcmds)) { while (posn->next) posn = posn->next; posn->next = new_ewl; } else proc->waitcmds = new_ewl; }
int add_new_level (const char *name) { const char *name_copy; int * levelnum; int i; if ((i = str_to_level(name)) != -1) return i; /* Don't allow overflow */ if (next_level >= BIT_MAXBIT) return -1; name_copy = malloc_strdup(name); levelnum = new_malloc(sizeof(int)); *levelnum = next_level++; add_to_bucket(level_bucket, name_copy, levelnum); return *levelnum; }
/* * convert_sub_format: This is used to convert the formats of the * sub-portions of the status line to a format statement specially designed * for that sub-portions. convert_sub_format looks for a single occurence of * %c (where c is passed to the function). When found, it is replaced by "%s" * for use in a snprintf. All other occurences of % followed by any other * character are left unchanged. Only the first occurence of %c is * converted, all subsequence occurences are left unchanged. This routine * mallocs the returned string. */ char *convert_sub_format (const char *format, char c) { char buffer[BIG_BUFFER_SIZE + 1]; int pos = 0; int dont_got_it = 1; if (!format) return NULL; /* NULL in, NULL out */ while (*format && pos < BIG_BUFFER_SIZE - 4) { if (*format != '%') { buffer[pos++] = *format++; continue; } format++; if (*format == c && dont_got_it) { dont_got_it = 0; buffer[pos++] = '%'; buffer[pos++] = 's'; format++; } else if (*format != '%') { buffer[pos++] = '%'; buffer[pos++] = '%'; buffer[pos++] = *format; format++; } else { buffer[pos++] = '%'; buffer[pos++] = '%'; } } buffer[pos] = 0; return malloc_strdup(buffer); }
char * file_readb (int fd, int numb) { File *ptr = lookup_file(fd); if (!ptr) return malloc_strdup(empty_string); else { char *blah = (char *)new_malloc(numb+1); char *bleh = NULL; if (ptr->elf->fp) { clearerr(ptr->elf->fp); numb = fread(blah, 1, numb, ptr->elf->fp); #ifdef HAVE_LIBARCHIVE } else if (ptr->elf->a) { numb = archive_read_data(ptr->elf->a, blah, numb); #endif } else { /* others */ } bleh = enquote_it(blah, numb); new_free(&blah); return bleh; } }
char * file_read (int fd) { File *ptr = lookup_file(fd); if (!ptr) return malloc_strdup(empty_string); else { char *ret = NULL; char *end = NULL; size_t len = 0; size_t newlen = 0; if (ptr->elf->fp) clearerr(ptr->elf->fp); for (;;) { newlen += 4096; RESIZE(ret, char, newlen); ret[len] = 0; /* Keep this -- C requires it! */ if (!epic_fgets(ret + len, newlen - len, ptr->elf)) break; if ((end = strchr(ret + len, '\n'))) break; len = newlen - 1; } /* Do we need to truncate the result? */ if (end) *end = 0; /* Either the newline */ else if ( (ptr->elf->fp) && (ferror(ptr->elf->fp)) ) *ret = 0; /* Or the whole thing on error */ return ret; } }
/* * crypt_msg: Given plaintext 'str', constructs a body suitable for sending * via PRIVMSG or DCC CHAT. */ char *crypt_msg (char *str, Crypt *key) { char buffer[CRYPT_BUFFER_SIZE + 1]; char thing[6]; char *ptr; snprintf(thing, 6, "%cSED ", CTCP_DELIM_CHAR); *buffer = 0; if ((ptr = do_crypt(str, key, 1))) { if (!*ptr) { yell("WARNING: Empty encrypted message, but message " "sent anyway. Bug?"); } strlcat(buffer, thing, sizeof buffer); strlcat(buffer, ptr, sizeof buffer); strlcat(buffer, CTCP_DELIM_STR, sizeof buffer); new_free(&ptr); } else strlcat(buffer, str, sizeof buffer); return malloc_strdup(buffer); }
/* * extract is a simpler version of extract2, it is used when we dont * want special treatment of "firstword" if it is negative. This is * typically used by the word/list functions, which also dont care if * we strip out or leave in any whitespace, we just do what is the * fastest. */ char * real_extract (char *start, int firstword, int lastword, int extended) { /* * firstword and lastword must be zero. If they are not, * then they are assumed to be invalid However, please note * that taking word set (-1,3) is valid and contains the * words 0, 1, 2, 3. But word set (-1, -1) is an empty_string. */ const char * mark; const char * mark2; char * booya = NULL; CHECK_EXTENDED_SUPPORT /* * Before we do anything, we strip off leading and trailing * spaces. * * ITS OK TO TAKE OUT SPACES HERE, AS THE USER SHOULDNT EXPECT * THAT THE WORD FUNCTIONS WOULD RETAIN ANY SPACES. (That is * to say that since the word/list functions dont pay attention * to the whitespace anyhow, noone should have any problem with * those ops removing bothersome whitespace when needed.) */ while (*start && my_isspace(*start)) start++; remove_trailing_spaces(start, 0); if (firstword == EOS) { mark = start + strlen(start); move_word_rel(start, (const char **)&mark, -1, extended, "\""); } /* If the firstword is positive, move to that word */ else if (firstword >= 0) real_move_to_abs_word(start, (const char **)&mark, firstword, extended, "\""); /* Its negative. Hold off right now. */ else mark = start; /* * When we find the last word, we need to move to the * END of the word, so that word 3 to 3, would include * all of word 3, so we sindex to the space after the word */ /* EOS is a #define meaning "end of string" */ if (lastword == EOS) mark2 = start + strlen(start); else { if (lastword >= 0) real_move_to_abs_word(start, (const char **)&mark2, lastword+1, extended, "\""); else /* its negative -- thats not valid */ return malloc_strdup(empty_string); while (mark2 > start && my_isspace(mark2[-1])) mark2--; } /* * Ok.. now if we get to here, then lastword is positive, so * we sanity check firstword. */ if (firstword < 0) firstword = 0; if (firstword > lastword) /* this works even if fw was < 0 */ return malloc_strdup(empty_string); /* * If the end is before the string, then there is nothing * to extract (this is perfectly legal, btw) */ if (mark2 < mark) return malloc_strdup(empty_string); booya = strext(mark, mark2); return booya; }
static Logfile * logfile_add (Logfile *log, char **args) { char *ptr; WNickList *new_w; char *arg = next_arg(*args, args); int i; if (!log) { say("ADD: You need to specify a logfile first"); return NULL; } if (!arg) say("ADD: Add nicknames/channels to be logged to this file"); else while (arg) { if ((ptr = strchr(arg, ','))) *ptr++ = 0; if (log->type == LOG_TARGETS) { if (!find_in_list((List **)&log->targets, arg, !USE_WILDCARDS)) { say("Added %s to log name list", arg); new_w = (WNickList *)new_malloc(sizeof(WNickList)); new_w->nick = malloc_strdup(arg); add_to_list((List **)&(log->targets), (List *)new_w); } else say("%s already on log name list", arg); } else if (log->type == LOG_SERVERS || log->type == LOG_WINDOWS) { int refnum; if (log->type == LOG_SERVERS && !my_strnicmp("ALL", arg, 1)) refnum = NOSERV; else refnum = my_atol(arg); for (i = 0; i < MAX_TARGETS; i++) { if (log->refnums[i] == refnum) { say("%s already on log refnum list", arg); break; } } for (i = 0; i < MAX_TARGETS; i++) { if (log->refnums[i] == -1) { say("Added %d to log name list", refnum); log->refnums[i] = refnum; break; } } if (i >= MAX_TARGETS) say("Could not add %d to log name list!", refnum); } arg = ptr; } return log; }
void do_stack_set (int type, char *args) { VarStack *item; char *varname = NULL; char *(*dummy) (void) = NULL; IrcVariable *var; if (set_stack == NULL && (type == STACK_POP || type == STACK_LIST)) { say("Set stack is empty!"); return; } if (STACK_PUSH == type) { varname = next_arg(args, &args); if (!varname) { say("Must specify a variable name to stack"); return; } upper(varname); item = (VarStack *)new_malloc(sizeof(VarStack)); item->varname = malloc_strdup(varname); item->value = make_string_var(varname); item->next = set_stack; set_stack = item; return; } else if (STACK_POP == type) { VarStack *prev = NULL; int owd = window_display; varname = next_arg(args, &args); if (!varname) { say("Must specify a variable name to stack"); return; } upper(varname); for (item = set_stack; item; prev = item, item = item->next) { /* If this is not it, go to the next one */ if (my_stricmp(varname, item->varname)) continue; /* remove it from the list */ if (prev == NULL) set_stack = item->next; else prev->next = item->next; window_display = 0; get_var_alias(item->varname, &dummy, &var); set_variable(item->varname, var, item->value, 1); window_display = owd; new_free(&item->varname); new_free(&item->value); new_free(&item); return; } say("%s is not on the Set stack!", varname); return; } else if (STACK_LIST == type) { VarStack *prev = NULL; for (item = set_stack; item; prev = item, item = item->next) say("Variable [%s] = %s", item->varname, item->value ? item->value : "<EMPTY>"); return; } else say("Unknown STACK type ??"); }
EXTERN_C void xs_init(void) { const char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS(malloc_strdup("DynaLoader::boot_DynaLoader"), boot_DynaLoader, malloc_strdup(file)); newXS(malloc_strdup("EPIC::cmd"), XS_cmd, malloc_strdup("IRC")); newXS(malloc_strdup("EPIC::eval"), XS_eval, malloc_strdup("IRC")); newXS(malloc_strdup("EPIC::expr"), XS_expr, malloc_strdup("IRC")); newXS(malloc_strdup("EPIC::call"), XS_call, malloc_strdup("IRC")); newXS(malloc_strdup("EPIC::yell"), XS_yell, malloc_strdup("IRC")); }