/* * $dbmctl(OPEN type filename) * Open a DBM file for read and write access. * $dbmctl(OPEN_READ type filename) * Open a DBM file for read-only access. * $dbmctl(CLOSE refnum) * Close a previously opened DBM file * $dbmctl(ADD refnum "key" data) * Insert a new key/data pair. Fail if key already exists. * $dbmctl(CHANGE refnum "key" data) * If key already exists, change its data. If it doesn't exist, add it. * $dbmctl(DELETE refnum "key") * Remove a key/data pair * $dbmctl(READ refnum "key") * Return the data for a key. * $dbmctl(NEXT_KEY refnum start-over) * Return the next key in the database * $dbmctl(ALL_KEYS refnum) * Return all keys -- could be huge! could take a long time! * $dbmctl(ERROR refnum) * Return the errno for the last error. * * "refnum" is a value returned by OPEN and OPEN_READ. * "type" must always be "STD" for now. * "filename" is a dbm file (without the .db extension!) * "key" is a dbm key. Spaces are important! * "data" is a dbm value. Spaces are important! * */ char * dbmctl (char *input) { char * listc; int refnum; char * type; char * key; int retval; char * retstr; GET_FUNC_ARG(listc, input); if (!my_strnicmp(listc, "OPEN", 4)) { GET_FUNC_ARG(type, input); /* Ignored for now */ retval = open_dbm(input, 0, 0); RETURN_INT(retval); } else if (!my_strnicmp(listc, "OPEN_READ", 5)) { GET_FUNC_ARG(type, input); /* Ignored for now */ retval = open_dbm(input, 1, 0); RETURN_INT(retval); } else if (!my_strnicmp(listc, "CLOSE", 2)) { GET_INT_ARG(refnum, input); retval = close_dbm(refnum); RETURN_INT(retval); } else if (!my_strnicmp(listc, "ADD", 2)) { GET_INT_ARG(refnum, input); GET_DWORD_ARG(key, input); retval = write_to_dbm(refnum, key, input, 0); RETURN_INT(retval); } else if (!my_strnicmp(listc, "CHANGE", 2)) { GET_INT_ARG(refnum, input); GET_DWORD_ARG(key, input); retval = write_to_dbm(refnum, key, input, 1); RETURN_INT(retval); } else if (!my_strnicmp(listc, "DELETE", 1)) { GET_INT_ARG(refnum, input); GET_DWORD_ARG(key, input); retval = delete_from_dbm(refnum, key); RETURN_INT(retval); } else if (!my_strnicmp(listc, "READ", 1)) { GET_INT_ARG(refnum, input); GET_DWORD_ARG(key, input); retstr = read_from_dbm(refnum, key); RETURN_MSTR(retstr); } else if (!my_strnicmp(listc, "NEXT_KEY", 1)) { int restart; GET_INT_ARG(refnum, input); GET_INT_ARG(restart, input); retstr = iterate_on_dbm(refnum, restart); RETURN_MSTR(retstr); } else if (!my_strnicmp(listc, "ALL_KEYS", 2)) { GET_INT_ARG(refnum, input); retstr = all_keys_for_dbm(refnum); RETURN_MSTR(retstr); } else if (!my_strnicmp(listc, "ERROR", 1)) { GET_INT_ARG(refnum, input); retval = error_from_dbm(refnum); RETURN_INT(retval); } RETURN_EMPTY; }
unsigned long parse_lastlog_level(char *str, int display) { char *ptr, *rest; int len, i; unsigned long p, level; int neg; level = 0; while ((str = next_arg(str, &rest)) != NULL) { while (str) { if ((ptr = strchr(str, ',')) != NULL) *ptr++ = '\0'; if ((len = strlen(str)) != 0) { if (my_strnicmp(str, "ALL", len) == 0) level = LOG_ALL; else if (my_strnicmp(str, "NONE", len) == 0) level = 0; else { if (*str == '-') { str++; len--; neg = 1; } else neg = 0; for (i = 0, p = 1; i < NUMBER_OF_LEVELS; i++, p <<= 1) { if (!my_strnicmp(str, levels[i], len)) { if (neg) level &= (LOG_ALL ^ p); else level |= p; break; } } if (i == NUMBER_OF_LEVELS) { if (display) say("Unknown lastlog level: %s", str); return LOG_ALL; } } } str = ptr; } str = rest; } return (level); }
static void console_kick_player(connection_type* ct, char *name) { int i, len; player_type *p_ptr, *p_ptr_search; p_ptr = 0; /* Check the players in the game */ for (i = 1; i <= NumPlayers; i++) { p_ptr_search = Players[i]; len = strlen(p_ptr_search->name); if (!my_strnicmp(p_ptr_search->name, name, len)) { p_ptr = p_ptr_search; break; } } /* Check name */ if (p_ptr) { /* Kick him */ Destroy_connection(p_ptr->conn, "kicked out"); /* Success */ cq_printf(&ct->wbuf, "%T", "Kicked player\n"); return; } else { /* Failure */ cq_printf(&ct->wbuf, "%T", "No such player\n"); } }
char *get_help_topic(char *args, int helpfunc) { char *new_comm = NULL; int found = 0, i; char *others = NULL; new_comm = LOCAL_COPY(args); for (i = 0; helpfunc ? script_help[i] : help_index[i]; i++) { if (!my_strnicmp(helpfunc?script_help[i]->title:help_index[i]->title, new_comm, strlen(new_comm))) { int j; char *text = NULL; if (found++) { m_s3cat(&others, " , ", helpfunc?script_help[i]->title:help_index[i]->title); continue; } if (args && *args && do_hook(HELPTOPIC_LIST, "%s", args)) put_it("%s",convert_output_format("$G \002$0\002: Help on Topic: \002$1\002", version, args)); for (j = 0; ; j++) { if (helpfunc && (script_help[i] && script_help[i]->contents[j])) text = script_help[i]->contents[j]; else if (!helpfunc && (help_index[i] && help_index[i]->contents[j])) text = help_index[i]->contents[j]; else break; if (text && do_hook(HELPSUBJECT_LIST, "%s %s", new_comm, text)) { in_chelp++; put_it("%s", convert_output_format(text, NULL)); in_chelp--; } } text = helpfunc ?script_help[i]->relates:help_index[i]->relates; if (text && do_hook(HELPTOPIC_LIST, "%s", text)) put_it("%s", convert_output_format(text, NULL)); } else if (found) break; } if (!found) { if (do_hook(HELPTOPIC_LIST, "%s", args)) bitchsay("No help on %s", args); } if (others && found) { if (do_hook(HELPTOPIC_LIST, "%d %s", found, others)) put_it("Other %d subjects: %s", found - 1, others); } new_free(&others); if (helpfunc) return m_strdup(empty_string); return NULL; }
PRIVATE void Wav_FindNextChunk( const char *name ) { while( 1 ) { iff_pdata = iff_last_chunk; if( iff_pdata >= iff_end ) { // Didn't find the chunk iff_pdata = NULL; return; } iff_pdata += 4; iff_chunk_len = Wav_GetLittleLong(); if( iff_chunk_len < 0 ) { iff_pdata = NULL; return; } iff_pdata -= 8; iff_last_chunk = iff_pdata + 8 + ((iff_chunk_len + 1) & ~1); if( ! my_strnicmp((const char *)iff_pdata, name, 4) ) { return; } } }
/* * Return information about a specific player */ static void console_whois(connection_type* ct, char *name) { int i, len; u16b major, minor, patch, extra; char brave[15]; //output[1024]; player_type *p_ptr, *p_ptr_search; p_ptr = 0; /* Find this player */ for (i = 1; i <= NumPlayers; i++) { p_ptr_search = Players[i]; len = strlen(p_ptr_search->name); if (!my_strnicmp(p_ptr_search->name, name, len)) { p_ptr = p_ptr_search; } } if (!p_ptr) { cq_printf(&ct->wbuf, "%T", "No such player\n"); return; } /* Output player information */ /* General character description */ (p_ptr->no_ghost) ? strcpy(brave,"brave \0") : strcpy(brave,"\0"); cq_printf(&ct->wbuf, "%T", format("%s is a %slevel %d %s %s at %d ft\n", p_ptr->name, brave, p_ptr->lev, p_name + p_info[p_ptr->prace].name, c_name + c_info[p_ptr->pclass].name, p_ptr->dun_depth*50)); /* Breakup the client version identifier */ major = (p_ptr->version & 0xF000) >> 12; minor = (p_ptr->version & 0xF00) >> 8; patch = (p_ptr->version & 0xF0) >> 4; extra = (p_ptr->version & 0xF); /* Player connection info */ cq_printf(&ct->wbuf, "%T", format("(%s@%s [%s] v%d.%d.%d.%d)\n", p_ptr->realname, p_ptr->hostname, p_ptr->addr, major, minor, patch, extra)); /* Other interesting factoids */ if ( p_ptr->lives > 0 ) cq_printf(&ct->wbuf, "%T", format("Has resurected %d times.\n", p_ptr->lives)); if ( p_ptr->max_dlv == 0 ) cq_printf(&ct->wbuf, "%T", format("Has never left the town!\n")); else cq_printf(&ct->wbuf, "%T", format("Has ventured down to %d ft\n", p_ptr->max_dlv*50)); i = p_ptr->msg_hist_ptr-1; if( i >= 0 ) { if (!STRZERO(p_ptr->msg_log[i])) { cq_printf(&ct->wbuf, "%T", format("Last message: %s\n", p_ptr->msg_log[i])); } } }
/* * quit_response: Used by irc_io when called from irc_quit to see if we got * the right response to our question. If the response was affirmative, the * user gets booted from irc. Otherwise, life goes on. */ static void quit_response(char *dummy, char *ptr) { int len; if ((len = strlen(ptr)) != 0) if (!my_strnicmp(ptr, "yes", len)) irc_exit(1, NULL, "IRC][ %s: Rest in peace", irc_version); }
/* * quit_response: Used by irc_io when called from nap_quit to see if we got * the right response to our question. If the response was affirmative, the * user gets booted from irc. Otherwise, life goes on. */ static void quit_response(char *dummy, char *ptr) { int len; if ((len = strlen(ptr)) != 0) if (!my_strnicmp(ptr, "yes", len)) nap_exit(1, "TekNap Rest in peace", NULL); }
unsigned long convert_str_to_flags(char *str) { char *p; register int i; register unsigned long j; unsigned long flags = 0; int done; if (!str || !*str) return 0; if (!my_strnicmp("FRIEND", str, 6)) flags = ADD_FRIEND; else if (!my_strnicmp("MASTER", str, 6)) flags = ADD_MASTER; else if (!my_strnicmp("OWNER", str, 5)) flags = ADD_OWNER; while ((p = next_in_comma_list(str, &str))) { if (!*p) break; upper(p); done = 0; for (i = 0, j = 1; strflags[i]; i++, j <<= 1 ) { if (!strcmp(p, strflags[i])) { flags |= j; done = 1; break; } } if (!done) { for (i = 0, j = PROT_REOP; protflags[i]; i++, j <<= 1) { if (!strcmp(p, protflags[i])) { flags |= j; break; } } } } return flags; }
/* * $levelctl(LEVELS) * $levelctl(ADD name) * $levelctl(ALIAS old-name new-name) * $levelctl(LOOKUP name-or-number) * $levelctl(NORMALIZE string) */ char *levelctl (char *input) { char *listc, *retval; const char *newlevel, *oldlevel; int oldnum, newnum; GET_FUNC_ARG(listc, input); if (!my_strnicmp(listc, "LEVELS", 2)) { retval = get_all_levels(); RETURN_MSTR(retval); } else if (!my_strnicmp(listc, "ADD", 2)) { GET_FUNC_ARG(newlevel, input); newnum = add_new_level(newlevel); RETURN_INT(newnum); } else if (!my_strnicmp(listc, "ALIAS", 2)) { GET_FUNC_ARG(oldlevel, input); GET_FUNC_ARG(newlevel, input); oldnum = str_to_level(oldlevel); newnum = add_new_level_alias(oldnum, newlevel); RETURN_INT(newnum); } else if (!my_strnicmp(listc, "LOOKUP", 2)) { GET_FUNC_ARG(newlevel, input); if (is_number(newlevel)) { oldnum = STR2INT(newlevel); oldlevel = level_to_str(oldnum); RETURN_STR(oldlevel); } else { oldnum = str_to_level(newlevel); RETURN_INT(oldnum); } } else if (!my_strnicmp(listc, "NORMALIZE", 1)) { Mask m; const char *r; char *err = NULL; mask_unsetall(&m); str_to_mask(&m, input, &err); /* Errors are ignored */ r = mask_to_str(&m); RETURN_STR(r); } RETURN_EMPTY; }
int kill_message (const char *from, const char *cline) { char *poor_sap; char *bastard; const char *path_to_bastard; char *reason; char *line; line = LOCAL_COPY(cline); poor_sap = next_arg(line, &line); /* Dalnet kill BBC and doesnt append the period */ if (!end_strcmp(poor_sap, ".", 1)) chop(poor_sap, 1); /* dalnet kill BBC and doesnt use "From", but "from" */ if (my_strnicmp(line, "From ", 5)) { yell("Attempted to parse an ill-formed KILL request [%s %s]", poor_sap, line); return 0; } line += 5; bastard = next_arg(line, &line); /* Hybrid BBC and doesn't include the kill-path. */ /* Fend off future BBC kills */ if (my_strnicmp(line, "Path: ", 6)) { path_to_bastard = "*"; reason = line; /* Hope for the best */ } else { line += 6; path_to_bastard = next_arg(line, &line); reason = line; } return !do_hook(KILL_LIST, "%s %s %s %s %s", from, poor_sap, bastard, path_to_bastard, reason); }
int str_to_level (const char *orig) { int i, len; len = strlen(orig); for (i = 0; i < level_bucket->numitems; i++) if (!my_strnicmp(orig, LEVELNAME(i), len)) return LEVELNUM(i); return -1; }
void nap_chat(int snum) { GetFile *gf; unsigned char buffer[3*BIG_BUFFER_SIZE+1]; SocketList *s; long bytesread; char *tmp, *p; if (!(s = get_socket(snum)) || !(gf = (GetFile *)s->info)) { put_it("error get_socket(%d)", snum); nap_finished_file(snum, PREMATURE_FINISH); return; } if (gf->deleted) { if (gf->write != -1) close(gf->write); gf->write = -1; if (gf->deleted++ > 5) close_socketread(snum); return; } bytesread = new_dgets(buffer, snum, 1, BIG_BUFFER_SIZE); switch (bytesread) { case -1: say("Lost DCC CHAT to %s [%s]", gf->nick, (dgets_errno == -1) ? "Remote End Closed Connection" : strerror(dgets_errno)); break_from_list((List **)&transfer_struct, (List *)gf); nap_finished_file(snum, PREMATURE_FINISH); break; case 0: break; default: tmp = buffer; if ((p = strrchr(tmp, '\r'))) *p = 0; if ((p = strrchr(tmp, '\n'))) *p = 0; my_decrypt(tmp, strlen(tmp), gf->passwd); gf->received += bytesread; #ifdef ALLOW_DCC_COMMANDS if ((gf->flags & NAP_DCC_COMMANDS) == NAP_DCC_COMMANDS) { if (!my_strnicmp(tmp, ".cmd ", 5) && *(tmp+6)) parse_line("DCC", tmp+5, NULL, 0, 0, 1); } #endif put_it(FORMAT_DCC_MSG, gf->nick, gf->ip, tmp); break; } }
static Logfile * logfile_type (Logfile *log, char **args) { char *arg = new_next_arg(*args, args); if (!log) { say("TYPE: You need to specify a logfile first"); return NULL; } clean_log_targets(log); if (!my_strnicmp(arg, "SERVER", 1)) log->type = LOG_SERVERS; else if (!my_strnicmp(arg, "WINDOW", 1)) log->type = LOG_WINDOWS; else if (!my_strnicmp(arg, "TARGET", 1)) log->type = LOG_TARGETS; else say("TYPE: Unknown type of log"); return log; }
/* * * * * * * * * * * * * * BIND * * * * * * * * * * * * * */ static int grok_meta (const uc *ptr, const uc **end) { int meta = -1; const uc * str; /* * Well, if it is going to be anywhere, META has to be out front, * so lets slurp it up if its there. */ if (!my_strnicmp(ptr, "META", 4)) { str = ptr = ptr + 4; while (isdigit(*ptr)) ptr++; if (*ptr == '_' && !my_strnicmp(ptr, "_CHARACTER", 10)) ptr = ptr + 10; if (*ptr == '-') ptr++; meta = atol(str); } *end = ptr; return meta; }
static char const *strcasestr(char const *haystack, char const *needle) { int needleLen = strlen(needle); char const *retp = nullptr; while(*haystack) { // strncasecmp, strnicmp, _strnicmp not working under mingw with some flags if(my_strnicmp(haystack, needle, needleLen) == 0) { retp = haystack; break; } haystack++; } return retp; }
static void not_valid_channel(u_char *from, u_char **ArgList) { u_char *channel; u_char *s; if (!(channel = ArgList[0]) || !ArgList[1]) return; PasteArgs(ArgList, 1); s = server_get_name(parsing_server()); if (0 == my_strnicmp(s, from, my_strlen(s))) { remove_channel(channel, parsing_server()); put_it("%s %s %s", numeric_banner(), channel, ArgList[1]); } }
char *JNL_HTTPGet::getheader(char *headername) { char *ret=NULL; if (strlen(headername)<1||!m_recvheaders) return NULL; char *p=m_recvheaders; while (*p) { if (!my_strnicmp(headername,p,strlen(headername))) { ret=p+strlen(headername); while (*ret == ' ') ret++; break; } p+=strlen(p)+1; } return ret; }
/* * display_msg: handles the displaying of messages from the variety of * possible formats that the irc server spits out. * * Simplified some time in 1996. * -- called by more than one place. */ static void display_msg (const char *from, const char *comm, const char **ArgList) { char *ptr = NULL; const char *rest; int drem; /* XXX - * ArgList[0] was passed to who_from() which means we need to * either reset who_from() with our own copy, or not detokenize * ArgList[0], because this breaks channel targeting! */ if (!(rest = PasteArgs(ArgList, 0))) { rfc1459_odd(from, comm, ArgList); return; } if (from && (my_strnicmp(get_server_itsname(from_server), from, strlen(get_server_itsname(from_server))) == 0)) from = NULL; /* This fix by SrfRog, again by |Rain| */ if (ptr && ptr > rest && ptr[-1] == ' ') /* per RFC 1459 */ *ptr++ = 0; else ptr = NULL; drem = (from) && (!get_int_var(SUPPRESS_FROM_REMOTE_SERVER_VAR)); /* * This handles all the different cases of server messages. * If you dont believe me, try it out. :P * * There are 16 distinct possibilities, since there are 4 * independant variables. In practice only about 6 to 8 of * the possibilities are used. */ put_it("%s %s%s%s%s%s%s%s", banner(), strlen(rest) ? rest : empty_string, strlen(rest) && ptr ? ":" : empty_string, strlen(rest) ? space : empty_string, ptr ? ptr : empty_string, drem ? "(from " : empty_string, drem ? from : empty_string, drem ? ")" : empty_string ); }
static int input_is_password_prompt(void) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); u_char* buf = inputdata->buffer.buf; unsigned limit = inputdata->buffer.minpos; if (limit < 9) return 0; /* If the prompt ends with "Password:"******"Password:"******"Operator Password:"******"Server Password:"******"Password:"), 9) == 0; }
static Logfile * logfile_server (Logfile *log, char **args) { char *arg = new_next_arg(*args, args); if (!log) { say("SERVER: You need to specify a logfile first"); return NULL; } if (!my_strnicmp(arg, "ALL", 1)) log->servref = NOSERV; else if (!is_number(arg)) say("/LOG SERVER: The log's server needs to be a number or ALL"); else log->servref = str_to_servref(arg); return log; }
void get_help_topic(const char *args, int helpfunc) { int found = 0, i; char *others = NULL; struct chelp_index *index = helpfunc ? &script_help : &bitchx_help; size_t arglen = strlen(args); for (i = 0; i < index->size; i++) { if (!my_strnicmp(index->entries[i].title, args, arglen)) { int j; char *text = NULL; if (found++) { m_s3cat(&others, " , ", index->entries[i].title); continue; } if (do_hook(HELPTOPIC_LIST, "%s", index->entries[i].title)) put_it("%s", convert_output_format("$G \002$0\002: Help on Topic: \002$1-\002", "%s %s", version, index->entries[i].title)); for (j = 0; (text = index->entries[i].contents[j]) != NULL; j++) { if (do_hook(HELPSUBJECT_LIST, "%s , %s", index->entries[i].title, text)) { in_chelp++; put_it("%s", convert_output_format(text, NULL)); in_chelp--; } } text = index->entries[i].relates; if (text && do_hook(HELPTOPIC_LIST, "%s", text)) put_it("%s", convert_output_format(text, NULL)); } else if (found) break; } if (!found) { if (do_hook(HELPTOPIC_LIST, "%s", args)) bitchsay("No help on %s", args); } if (others && found) { if (do_hook(HELPTOPIC_LIST, "%d %s", found, others)) put_it("Other %d subjects: %s", found - 1, others); } new_free(&others); }
int read_file(FILE *help_file, int helpfunc) { char line[BIG_BUFFER_SIZE + 1]; int item_number = 0; int topic = -1; struct chelp_index *index = helpfunc ? &script_help : &bitchx_help; free_index(index); while (fgets(line, sizeof line, help_file)) { size_t len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; if (!*line || *line == '#') continue; if (*line != ' ') { /* we got a topic copy to topic */ if (!my_strnicmp(line, "-RELATED", 7)) { if (topic > -1) { index->entries[topic].relates = m_strdup(line + 8); } } else { topic++; item_number = 0; RESIZE(index->entries, index->entries[0], topic + 1); index->entries[topic].title = m_strdup(line); index->entries[topic].contents = new_malloc(sizeof(char *)); index->entries[topic].contents[0] = NULL; index->entries[topic].relates = NULL; } } else if (topic > -1) { /* we found the subject material */ item_number++; RESIZE(index->entries[topic].contents, char *, item_number + 1); index->entries[topic].contents[item_number - 1] = m_strdup(line); index->entries[topic].contents[item_number] = NULL; } }
static void set_speed(Window *win, char *value, int unused) { int def_speed = 0; if (value && *value) { for (def_speed = 0; _n_speed[def_speed]; def_speed++) { if (!my_strnicmp(value, _n_speed[def_speed], strlen(value))) break; } if (def_speed > MAX_SPEED) if (isdigit(*value)) def_speed = my_atol(value); if (def_speed > MAX_SPEED) def_speed = 0; } send_all_servers(CMDS_CHANGESPEED, "%d", def_speed); set_int_var(DEFAULT_SPEED_VAR, def_speed); set_string_var(DEFAULT_SPEED_VAR, _n_speed[def_speed]); return; }
/* * display_msg: handles the displaying of messages from the variety of * possible formats that the irc server spits out. you'd think someone would * simplify this */ void display_msg(u_char *from, u_char **ArgList) { u_char *ptr; u_char *rest; rest = PasteArgs(ArgList, 0); if (from && (my_strnicmp(server_get_itsname(parsing_server()), from, my_strlen(server_get_itsname(parsing_server()))) == 0)) from = NULL; if ((ptr = (u_char *) my_index(rest, ':')) != NULL) { *(ptr++) = (u_char) 0; if (my_strlen(rest)) { if (from) put_it("%s %s: %s (from %s)", numeric_banner(), rest, ptr, from); else put_it("%s %s: %s", numeric_banner(), rest, ptr); } else { if (from) put_it("%s %s (from %s)", numeric_banner(), ptr, from); else put_it("%s %s", numeric_banner(), ptr); } } else { if (from) put_it("%s %s (from %s)", numeric_banner(), rest, from); else put_it("%s %s", numeric_banner(), rest); } }
int list_strnicmp(List *item1, char *str) { return my_strnicmp(item1->name, str, strlen(str)); }
/* * 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); }
/* * $logctl(NEW) * $logctl(REFNUMS [ACTIVE|INACTIVE|ALL]) * $logctl(REFNUM log-desc) * $logctl(ADD log-desc [target]) * $logctl(DELETE log-desc [target]) * $logctl(GET <refnum> [LIST]) * $logctl(SET <refnum> [ITEM] [VALUE]) * $logctl(MATCH [pattern]) * $logctl(PMATCH [pattern]) * * [LIST] and [ITEM] are one of the following * REFNUM The refnum for the log (GET only) * NAME The logical name for the log * FILENAME The filename this log writes to * SERVER The server this log associates with (-1 for any) * TARGETS All of the targets for this log * LEVEL The Lastlog Level for this log * REWRITE The rewrite rule for this log * MANGLE The mangle rule for this log * STATUS 1 if log is on, 0 if log is off. * TYPE Either "TARGET", "WINDOW", or "SERVER" */ char *logctl (char *input) { char *refstr; char *listc; int val; Logfile *log; GET_FUNC_ARG(listc, input); if (!my_strnicmp(listc, "NEW", 3)) { log = new_logfile(); RETURN_INT(log->refnum); } else if (!my_strnicmp(listc, "LAST_CREATED", 12)) { RETURN_INT(last_logref); } else if (!my_strnicmp(listc, "REFNUMS", 7)) { char * retval = NULL; int active; GET_FUNC_ARG(refstr, input); if (!my_stricmp(refstr, "ACTIVE")) active = 1; else if (!my_stricmp(refstr, "INACTIVE")) active = 0; else if (!my_stricmp(refstr, "ALL")) active = -1; else RETURN_EMPTY; for (log = logfiles; log; log = log->next) { if (active != -1 && active != log->active) continue; malloc_strcat_word(&retval, space, ltoa(log->refnum), DWORD_NO); } RETURN_MSTR(retval); } else if (!my_strnicmp(listc, "REFNUM", 6)) { GET_FUNC_ARG(refstr, input); if (!(log = get_log_by_desc(refstr))) RETURN_EMPTY; RETURN_INT(log->refnum); } else if (!my_strnicmp(listc, "ADD", 2)) { GET_FUNC_ARG(refstr, input); if (!(log = get_log_by_desc(refstr))) RETURN_EMPTY; logfile_add(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "DELETE", 2)) { GET_FUNC_ARG(refstr, input); if (!(log = get_log_by_desc(refstr))) RETURN_EMPTY; logfile_remove(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "GET", 2)) { GET_FUNC_ARG(refstr, input); if (!(log = get_log_by_desc(refstr))) RETURN_EMPTY; GET_FUNC_ARG(listc, input); if (!my_strnicmp(listc, "REFNUM", 3)) { RETURN_INT(log->refnum); } else if (!my_strnicmp(listc, "NAME", 3)) { RETURN_STR(log->name); } else if (!my_strnicmp(listc, "FILENAME", 3)) { RETURN_STR(log->filename); } else if (!my_strnicmp(listc, "SERVER", 3)) { RETURN_INT(log->servref); } else if (!my_strnicmp(listc, "TARGETS", 3)) { char *ret = logfile_get_targets(log); RETURN_MSTR(ret); } else if (!my_strnicmp(listc, "LEVEL", 3)) { const char *ret = mask_to_str(&log->mask); RETURN_STR(ret); } else if (!my_strnicmp(listc, "REWRITE", 3)) { RETURN_STR(log->rewrite); } else if (!my_strnicmp(listc, "MANGLE", 3)) { RETURN_STR(log->mangle_desc); } else if (!my_strnicmp(listc, "STATUS", 3)) { RETURN_INT(log->active); } else if (!my_strnicmp(listc, "TYPE", 3)) { RETURN_STR(logtype[log->type]); } else if (!my_strnicmp(listc, "ACTIVITY", 1)) { RETURN_INT(log->activity); } } else if (!my_strnicmp(listc, "SET", 1)) { GET_FUNC_ARG(refstr, input); if (!(log = get_log_by_desc(refstr))) RETURN_EMPTY; GET_FUNC_ARG(listc, input); if (!my_strnicmp(listc, "NAME", 3)) { logfile_name(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "FILENAME", 3)) { logfile_filename(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "SERVER", 3)) { logfile_server(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "TARGETS", 3)) { clean_log_targets(log); logfile_add(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "LEVEL", 3)) { logfile_level(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "REWRITE", 3)) { logfile_rewrite(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "MANGLE", 3)) { logfile_mangle(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "STATUS", 3)) { GET_INT_ARG(val, input); if (val) logfile_on(log, &input); else logfile_off(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "TYPE", 3)) { logfile_type(log, &input); RETURN_INT(1); } else if (!my_strnicmp(listc, "ACTIVITY", 1)) { logfile_activity(log, &input); RETURN_INT(1); } } else if (!my_strnicmp(listc, "MATCH", 1)) { RETURN_EMPTY; /* Not implemented for now. */ } else if (!my_strnicmp(listc, "PMATCH", 1)) { RETURN_EMPTY; /* Not implemented for now. */ } else if (!my_strnicmp(listc, "CURRENT", 1)) { RETURN_INT(current_log_refnum); } else RETURN_EMPTY; RETURN_EMPTY; }
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; }
/* ----------------------------------------------------------------------------- Function: LoadWavInfo -Load wav file. Parameters: filename -[in] Name of wav file to load. wav -[out] wav data. info -[out] wav sound info. Returns: True if file loaded, otherwise false. Notes: Caller is responsible for freeing wav data by calling Z_Free. ----------------------------------------------------------------------------- */ PUBLIC _boolean LoadWavInfo( const char *filename, W8 **wav, soundInfo_t *info ) { filehandle_t *hFile; W8 *data; W32 wavlength; hFile = FS_OpenFile( filename, 0 ); if( ! hFile ) { return false; } data = (PW8)FS_GetLoadedFilePointer( hFile, SEEK_SET ); wavlength = FS_GetFileSize( hFile ); iff_data = data; iff_end = data + wavlength; // look for RIFF signature Wav_FindChunk( "RIFF" ); if( ! (iff_pdata && ! my_strnicmp( (const char *)iff_pdata + 8, "WAVE", 4 ) ) ) { Com_DPrintf( "[LoadWavInfo]: Missing RIFF/WAVE chunks (%s)\n", filename ); FS_CloseFile( hFile ); return false; } // Get "fmt " chunk iff_data = iff_pdata + 12; Wav_FindChunk( "fmt " ); if( ! iff_pdata ) { Com_DPrintf( "[LoadWavInfo]: Missing fmt chunk (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 8; if( Wav_GetLittleShort() != 1 ) { Com_DPrintf( "[LoadWavInfo]: Microsoft PCM format only (%s)\n", filename ); FS_CloseFile( hFile ); return false; } info->channels = Wav_GetLittleShort(); info->sample_rate = Wav_GetLittleLong(); iff_pdata += 4; info->sample_size = Wav_GetLittleShort(); // Bytes Per Sample if (info->sample_size != 1 && info->sample_size != 2) { Com_DPrintf( "[LoadWavInfo]: only 8 and 16 bit WAV files supported (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 2; // Find data chunk Wav_FindChunk( "data" ); if( ! iff_pdata ) { Com_DPrintf( "[LoadWavInfo]: missing 'data' chunk (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 4; info->samples = Wav_GetLittleLong() / info->sample_size; if( info->samples <= 0 ) { Com_DPrintf( "[LoadWavInfo]: file with 0 samples (%s)\n", filename ); FS_CloseFile( hFile ); return false; } // Load the data *wav = Z_Malloc( info->samples * info->sample_size ); memcpy( *wav, data + (iff_pdata - data), info->samples * info->sample_size ); FS_CloseFile( hFile ); return true; }