/* nap_exit: cleans up and leaves */ void nap_exit (int really_quit, char *reason, char *format, ...) { if (dead == 1) { kill_all_threads(); exit(1); } else if (dead == 2) { kill_all_threads(); _exit(1); } else if (dead == 3) { kill_all_threads(); kill(getpid(), SIGKILL); } dead++; set_lastlog_size(NULL, NULL, 0); set_history_size(NULL, NULL, 0); if (really_quit) { kill_all_threads(); say("Signon time : %s", my_ctime(start_time)); say("Signoff time : %s", my_ctime(now)); say("Total uptime : %s", convert_time(now - start_time)); } do_hook(EXIT_LIST, "%s", reason ? reason : empty_string); if (reason) say("%s", reason); close_all_servers(); close_all_sockets(); if (term_initialized) { cursor_to_input(); term_cr(); term_clear_to_eol(); term_reset(); } remove_bindings(); clear_variables(); delete_all_windows(); destroy_call_stack(); write_unfinished_list(); debug_cleanup(); fprintf(stdout, "\r"); fflush(stdout); if (really_quit) exit(0); kill_all_threads(); my_signal(SIGABRT, SIG_DFL, 0); kill(getpid(), SIGABRT); kill(getpid(), SIGQUIT); exit(1); }
static void talk_request() { bell(); bell(); if(currutmp->msgcount) { char buf[200]; time_t now = time(0); sprintf(buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", utmpshm->uinfo[currutmp->destuip].userid, my_ctime(&now), (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); move(0, 0); clrtoeol(); outs(buf); refresh(); } else { unsigned char mode0 = currutmp->mode; char c0 = currutmp->chatid[0]; screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); extern screenline_t *big_picture; currutmp->mode = 0; currutmp->chatid[0] = 1; memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); talkreply(); currutmp->mode = mode0; currutmp->chatid[0] = c0; memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); free(screen0); redoscr(); } }
CTTableDiff<COUNT,PROB>* model1::one_step_em(int it, bool seedModel1, Dictionary& dictionary, bool useDict) { CTTableDiff<COUNT,PROB> *diff = new CTTableDiff<COUNT,PROB>(); double minErrors=1.0; string modelName="Model1",shortModelName="1"; time_t st, it_st, fn; string tfile, number, alignfile, test_alignfile; bool dump_files = false ; st = time(NULL); sHandler1.rewind(); cout << "==========================================================\n"; cout << modelName << " Training Started at: "<< my_ctime(&st) << "\n"; it_st = time(NULL); cout << "-----------\n" << modelName << ": Iteration " << it << '\n'; dump_files = (Model1_Dump_Freq != 0) && ((it % Model1_Dump_Freq) == 0) && !NODUMPS ; number = ""; int n = it; do { number.insert((size_t)0, 1, (char)(n % 10 + '0')); } while((n /= 10) > 0); tfile = Prefix + ".t" + shortModelName + "." + number ; alignfile = Prefix + ".A1" ; test_alignfile = Prefix +".tst.A" + shortModelName + "." + number ; initAL(); em_loop_1(diff,it,perp, sHandler1, seedModel1, dump_files, alignfile.c_str(), dictionary, useDict, trainViterbiPerp); //if (testPerp && testHandler) // calculate test perplexity // em_loop(it,*testPerp, *testHandler, seedModel1, dump_files, test_alignfile.c_str(), dictionary, useDict, *testViterbiPerp, true); if( errorsAL()<minErrors ) minErrors=errorsAL(); fn = time(NULL) ; cout << "Partial " << modelName << " Training took: " << difftime(fn, it_st) << " seconds\n"; return diff; }
void chatbox_insert_msg(chatbox_t *chatbox, char *sender, time_t *tm, char *msg) { char buf[65535]; GtkTextView *output_textview; GtkTextBuffer *output_buffer; GtkTextIter start; GtkTextIter end; GtkTextMark *mark; chatbox = (chatbox_t*)(chatbox); output_textview = chatbox->display_textview; output_buffer = gtk_text_view_get_buffer(output_textview); sprintf(buf, "%s(%s):\n", sender, my_ctime(tm)); gtk_text_buffer_get_end_iter(output_buffer, &end); gtk_text_buffer_insert_with_tags_by_name(output_buffer, &end, buf, -1, "blue_fg", "lmarg", "title_font", NULL); insert_msg_with_emotion_to_textview(output_textview, msg); gtk_text_buffer_get_end_iter(output_buffer, &end); mark = gtk_text_buffer_create_mark(output_buffer, NULL, &end, FALSE); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(output_textview), mark, 0.0, TRUE, 0.0, 0.0); gtk_text_buffer_delete_mark(output_buffer, mark); }
int model1::em_thread(int noIterations, int nthread, /*Perplexity& perp, sentenceHandler& sHandler1, */ Dictionary& dictionary, bool useDict /*Perplexity* testPerp, sentenceHandler* testHandler, Perplexity& trainViterbiPerp, Perplexity* testViterbiPerp */ ) { string modelName="Model1", shortModelName="1"; time_t st = time(NULL); string tfile, number, alignfile, test_alignfile; bool dump_files = false ; cout << "==========================================================\n"; cout << modelName << " Training Started at: "<< my_ctime(&st) << "\n"; int it = noIterations; cout << "-----------\n" << modelName << ": Iteration " << it << '\n'; dump_files = (Model1_Dump_Freq != 0) && ((it % Model1_Dump_Freq) == 0 || noIterations == it) && !NODUMPS ; // dump_files = true; number = ""; int n = it; do { number.insert((size_t)0, 1, (char)(n % 10 + '0')); } while((n /= 10) > 0); alignfile = Prefix + ".A" + shortModelName + "." + number + ".part" ; alignfile = alignfile + represent_number(nthread, 3); em_loop(it,perp, sHandler1, false, dump_files, alignfile.c_str(), dictionary, useDict, trainViterbiPerp); return 0; }
static off_t search_by_time(int fd, const char *fmt, time_t t, off_t off_m, off_t off_n) { int rval; time_t val_p; off_t off_p; #ifdef LOGCUT_DEBUG char buf0[256], buf1[256]; #endif while (off_m < off_n) { off_p = line_head(fd, (off_m + off_n) / 2); do { rval = read_time(fd, fmt, &val_p); if (off_p > 1 && rval == 0) { off_p = line_head(fd, off_p - 1); continue; } break; } while (1); if (t <= val_p) { LOGCUT_DBG((stderr, "n %10lld => %10lld %s <= %s\n", off_n, off_p, my_ctime(&t, buf0, sizeof(buf0)), my_ctime(&val_p, buf1, sizeof(buf1)))); off_n = off_p; } else { off_p = line_next(fd, (off_m + off_n) / 2); do { rval = read_time(fd, fmt, &val_p); if (rval == 0) { off_p = line_next(fd, off_p); continue; } break; } while (off_p < off_n); LOGCUT_DBG((stderr, "m %10lld => %10lld %s > %s\n", off_n, off_p, my_ctime(&t, buf0, sizeof(buf0)), my_ctime(&val_p, buf1, sizeof(buf1)))); off_m = off_p; } } return (off_m); }
/* * The client apparantly never was adapted to handle the new NOTE syntax. * So i had to kludge this up to work with it. Currently, NOTEs are sent * something like this: * * NOTICE yournick :Note from nick!user@host /xxxd:xxh:xxm/ [N] message * * and parse() calls parse_notice(), who notices that there is no pefix * and passes it off to parse_local_server_notice(), who checks to see * if it is a note (it is), blows away the "Note from" part, and re-sets * the "from" and "FromUserHost" parts with the nick!user@host part and * passes us the buck with 'line' pointing at the time description * (the /.../ part) */ static void parse_note (char *from, char *line) { char *date, *flags, *high; time_t when; int level; switch (check_ignore(from, FromUserHost, IGNORE_NOTES)) { case IGNORED: return; case HIGHLIGHTED: high = highlight_char; break; default: high = empty_string; } if (check_flooding(from, FromUserHost, NOTE_FLOOD, line)) return; /* at this point, line looks like: "/xxxd:xxh:xxm/ [FLAGS] message goes here" */ date = next_arg(line, &line); flags = next_arg(line, &line); when = convert_note_time_to_real_time(date); level = set_lastlog_msg_level(LOG_NOTES); if (do_hook(NOTE_LIST, "%s %lu %s", from, when, line)) { if (time(NULL) - when > 60) /* not just sent */ put_it("%s[%s]%s %s (%s)", high, from, high, line, my_ctime(when)); else put_it("%s[%s]%s %s", high, from, high, line); } if (beep_on_level & LOG_NOTES) beep_em(1); set_lastlog_msg_level(level); }
static void talk_request() { #ifdef LINUX /* * Linux 下連續 page 對方兩次就可以把對方踢出去: 這是由於某些系統一 * nal 進來就會將 signal handler 設定為內定的 handler, 不幸的是 * default 是將程 erminate. 解決方法是每次 signal 進來就重設 signal * handler */ signal(SIGUSR1, talk_request); #endif bell(); if (currutmp->msgcount) { char buf [200]; time_t now = time(0); sprintf(buf, "[1m[33;41m[%s][34;47m [%s] %s [0m", (currutmp->destuip)->userid, my_ctime(&now), (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); move(0, 0); clrtoeol(); outs(buf); refresh(); } else { uschar mode0 = currutmp->mode; char c0 = currutmp->chatid[0]; screenline *screen = (screenline *) calloc(t_lines, sizeof(screenline)); currutmp->mode = 0; currutmp->chatid[0] = 1; vs_save(screen); talkreply(); vs_restore(screen); currutmp->mode = mode0; currutmp->chatid[0] = c0; } }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; rtems_time_of_day time; int index; puts( "\n\n*** NANOSECOND CLOCK TEST ***" ); time.year = 2007; time.month = 03; time.day = 24; time.hour = 11; time.minute = 15; time.second = 0; time.ticks = 0; status = rtems_clock_set( &time ); directive_failed( status, "clock set" ); /* * Iterate 10 times showing difference in TOD */ printf( "10 iterations of getting TOD\n" ); for (index=0 ; index <10 ; index++ ) { struct timespec start, stop; struct timespec diff; #if 0 clock_gettime( CLOCK_REALTIME, &start ); clock_gettime( CLOCK_REALTIME, &stop ); #else _TOD_Get( &start ); _TOD_Get( &stop ); #endif subtract_em( &start, &stop, &diff ); printf( "Start: %s:%ld\nStop : %s:%ld", my_ctime(start.tv_sec), start.tv_nsec, my_ctime(stop.tv_sec), stop.tv_nsec ); printf( " --> %" PRIdtime_t ":%ld\n", diff.tv_sec, diff.tv_nsec ); } /* * Iterate 10 times showing difference in Uptime */ printf( "\n10 iterations of getting Uptime\n" ); for (index=0 ; index <10 ; index++ ) { struct timespec start, stop; struct timespec diff; rtems_clock_get_uptime( &start ); rtems_clock_get_uptime( &stop ); subtract_em( &start, &stop, &diff ); printf( "%" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n", start.tv_sec, start.tv_nsec, stop.tv_sec, stop.tv_nsec, diff.tv_sec, diff.tv_nsec ); } /* * Iterate 10 times showing difference in Uptime with different counts */ printf( "\n10 iterations of getting Uptime with different loop values\n" ); for (index=1 ; index <=10 ; index++ ) { struct timespec start, stop; struct timespec diff; int j, max = (index * 10000); rtems_clock_get_uptime( &start ); for (j=0 ; j<max ; j++ ) dummy_function_empty_body_to_force_call(); rtems_clock_get_uptime( &stop ); subtract_em( &start, &stop, &diff ); printf( "loop of %d %" PRIdtime_t ":%ld %" PRIdtime_t ":%ld --> %" PRIdtime_t ":%ld\n", max, start.tv_sec, start.tv_nsec, stop.tv_sec, stop.tv_nsec, diff.tv_sec, diff.tv_nsec ); } sleep(1); puts( "*** END OF NANOSECOND CLOCK TEST ***" ); exit(0); }
/* irc_exit: cleans up and leaves */ void BX_irc_exit (int really_quit, char *reason, char *format, ...) { char buffer[BIG_BUFFER_SIZE]; logger(current_window, NULL, 0); if (get_int_var(MSGLOG_VAR)) log_toggle(0, NULL); if (format) { va_list arglist; va_start(arglist, format); vsprintf(buffer, format, arglist); va_end(arglist); } else sprintf(buffer, "%s -- just do it.",irc_version); if (really_quit) { put_it("%s", convert_output_format("$G Signon time : $0-", "%s", my_ctime(start_time))); put_it("%s", convert_output_format("$G Signoff time : $0-", "%s", my_ctime(now))); put_it("%s", convert_output_format("$G Total uptime : $0-", "%s", convert_time(now - start_time))); } do_hook(EXIT_LIST, "%s", reason ? reason : buffer); close_all_servers(reason ? reason : buffer); put_it("%s", buffer ? buffer : reason ? reason : empty_string); clean_up_processes(); if (!dumb_mode && term_initialized) { cursor_to_input(); /* Needed so that ircII doesn't gobble * the last line of the kill. */ term_cr(); term_clear_to_eol(); term_reset(); } destroy_call_stack(); #if defined(THREAD) && defined(WANT_NSLOOKUP) kill_dns(); #endif remove_pid(); if (really_quit) { #ifdef GUI gui_exit(); #else #if defined(WANT_DETACH) && !defined(GUI) kill_attached_if_needed(0); #endif fprintf(stdout, "\r"); fflush(stdout); exit(0); #endif } }
void on_send_gpmessage(GtkWidget *widget, gchatbox_t *chatbox) { gchatbox_t *gchatbox; ifreechat_t *ifc; group_entry_t *group; char buf[65535]; char plain[1024]; char cipher[1024]; unsigned char ivec[8]; BF_KEY key; size_t size; int len; char *msg; time_t pno; GtkTextView *input_textview; GtkTextView *output_textview; CBlowFish *bf; GtkTextBuffer *input_buffer; GtkTextBuffer *output_buffer; GtkTextIter start; GtkTextIter end; GtkTextMark *mark; GdkPixbuf *pixbuf; gchatbox = (gchatbox_t*)(chatbox); ifc = (ifreechat_t*)gchatbox->ifreechat; group = (group_t*)gchatbox->data; pno = time(NULL); input_textview = gchatbox->input_textview; output_textview = gchatbox->display_textview; input_buffer = gtk_text_view_get_buffer(input_textview); output_buffer = gtk_text_view_get_buffer(output_textview); gtk_text_buffer_get_start_iter(input_buffer, &start); gtk_text_buffer_get_end_iter(input_buffer, &end); if (gtk_text_iter_equal(&start, &end)) { printf("Please enter message!!!\n"); return; } msg = gtk_text_buffer_get_text(input_buffer, &start, &end, TRUE); gtk_text_buffer_delete(input_buffer, &start, &end); sprintf(buf, "%s(%s):\n", ifc->nickname, my_ctime(&pno)); gtk_text_buffer_get_end_iter(output_buffer, &end); gtk_text_buffer_insert_with_tags_by_name(output_buffer, &end, buf, -1, "blue_fg", "lmarg", "title_font", NULL); insert_msg_with_emotion_to_textview(output_textview, msg); gtk_text_buffer_get_end_iter(output_buffer, &end); mark = gtk_text_buffer_create_mark(output_buffer, NULL, &end, FALSE); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(output_textview), mark, 0.0, TRUE, 0.0, 0.0); gtk_text_buffer_delete_mark(output_buffer, mark); /* bf = CreateBlowFish(ifc->macaddr, strlen(ifc->macaddr)); // BF_set_key(&key, 12, ifc->macaddr); sprintf(plain, "QUNMSGMARK#%lx#%s", group->group_id, msg); len = strlen(plain); len = BlowFish_Encrypt(bf, plain, cipher, len); // printf("msg: [%s]\n", msg); sprintf(buf, "1_lbt4_%d#128#%s#0#0#%d:%lu:%s:%s:%u:", ifc->avatar_id, ifc->macaddr, len, pno, ifc->username, ifc->hostname, 4194339); size = strlen(buf); memcpy(buf + size, cipher, len + 1); size += len + 1; udp_send_msg((ifreechat_t*)chatbox->ifreechat, ifc->multicast_ip, ifc->port, buf, size); DestroyBlowFish(bf); */ }
/* * numbered_command: does (hopefully) the right thing with the numbered * responses from the server. I wasn't real careful to be sure I got them * all, but the default case should handle any I missed (sorry) * * The format of a numeric looks like so: * * :server-name XXX our-nick Arg1 Arg2 Arg3 ... :ArgN * * The last argument traditionally has a colon before it, but this is not * compulsary. The BreakArgs function has already broken this up into * words for us, so that what we get, looks like this: * * server-name -> from parameter * XXX -> comm parameter * our-nick -> ArgList[0] * Arg1 -> ArgList[1] * Arg2 -> ArgList[2] * ... ... * * BUT! There's a wrinkle in the ointment. The first thing we do is slurp * up ArgList[0] (our-nick) and put it in 'user'. Then we increment the * ArgList array, so what we actually end up with is: * * server-name -> from parameter * XXX -> comm parameter * our-nick -> user * Arg1 -> ArgList[0] * Arg2 -> ArgList[1] * ... ... * ArgN -> ArgList[N-1] * NULL -> ArgList[N] */ void numbered_command (const char *from, const char *comm, char const **ArgList) { const char *target; char *copy; int i; int lastlog_level; int old_current_numeric = current_numeric; int numeric; /* All numerics must have a target (our nickname) */ if (!comm || !*comm) { rfc1459_odd(from, comm, ArgList); return; } numeric = atol(comm); if (numeric < 0 || numeric > 999) { rfc1459_odd(from, comm, ArgList); return; } if (!(target = ArgList[0])) { rfc1459_odd(from, comm, ArgList); return; } ArgList++; lastlog_level = set_lastlog_msg_level(LOG_CRAP); if (ArgList[0] && is_channel(ArgList[0])) message_from(ArgList[0], LOG_CRAP); else message_from(NULL, LOG_CRAP); current_numeric = -numeric; /* must be negative of numeric! */ /* * This first switch statement is only used for those numerics * which either need to perform some action before the numeric * is offered to the user, or by those actions which need to offer * the numeric to the user in some special manner. * * Those numerics which require only special display if the user * does not hook them, are handled below. * * Those numerics which require special action after the numeric * is offered to the user, are also handled below. * * Each of these numerics must either "break" (go to step 2) * or must "goto END" (goto step 3). */ switch (numeric) { /* * I added the "set_server_nickname" here because the client * when auto-fudging your nick will sometimes be confused as * what your nickname really is when you connect. Since the * server always tells us who the message was set to (ie, us) * we just kind of take it at its word. */ case 001: /* #define RPL_WELCOME 001 */ { Timeval i; i.tv_sec = 0; i.tv_usec = 50000; select(0, NULL, NULL, NULL, &i); accept_server_nickname(from_server, target); server_is_registered(from_server, 1); userhostbase(from_server, NULL, got_my_userhost, 1); break; } /* * Now instead of the terribly horrible hack using numeric 002 * to get the server name/server version info, we use the 004 * numeric which is what is the most logical choice for it. * * If any of the arguments are missing, we don't abort, because * the client needs 004 to sync. Instead, we just pass in the * NULL values and hope for the best... */ case 004: /* #define RPL_MYINFO 004 */ { const char *server = NULL, *version = NULL, *umodes = NULL; /* The 004 numeric is too import to "odd server stuff" over. */ /* So if the reply is useless, we'll just wing it */ if (!(server = ArgList[0])) server = version = umodes = NULL; else if (!(version = ArgList[1])) server = version = umodes = NULL; else if (!(umodes = ArgList[2])) server = version = umodes = NULL; else { /* Work around ratbox-1.2-3. */ if (!my_stricmp(umodes, "(brown")) if (ArgList[3] && !my_stricmp(ArgList[3], "paper")) if (ArgList[4] && !my_stricmp(ArgList[4], "bag")) if (ArgList[5] && !my_stricmp(ArgList[5], "release)")) { if (!(umodes = ArgList[6])) { rfc1459_odd(from, comm, ArgList); goto END; } } } got_initial_version_28(server, version, umodes); break; } case 005: { int arg; char *set, *value; for (arg = 0; ArgList[arg] && !strchr(ArgList[arg], ' '); arg++) { set = LOCAL_COPY(ArgList[arg]); value = strchr(set, '='); if (value && *value) *value++ = 0; if (*set == '+') /* parameter append */ { const char *ov = get_server_005(from_server, ++set); value = malloc_strdup2(ov, value); set_server_005(from_server, set, value); new_free(&value); } else if (*set == '-') /* parameter removal */ set_server_005(from_server, ++set, NULL); else if (value && *value) set_server_005(from_server, set, value); else set_server_005(from_server, set, space); } break; } case 10: /* EFNext "Use another server" 010 */ { const char *new_server, *new_port_s, *message; int new_port, old_server; PasteArgs(ArgList, 2); if (!(new_server = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(new_port_s = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } new_port = atol(ArgList[1]); /* Must do these things before calling "display_msg" */ old_server = from_server; add_to_server_list(new_server, new_port, NULL, NULL, get_server_group(from_server), NULL, 0); server_reconnects_to(old_server, from_server); from_server = old_server; break; } case 14: /* Erf/TS4 "cookie" numeric 014 */ { const char * cookie; PasteArgs(ArgList, 0); if (!(cookie = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } use_server_cookie(from_server); set_server_cookie(from_server, cookie); goto END; } case 42: /* ircnet's "unique id" numeric 042 */ { const char * unique_id; const char * message; PasteArgs(ArgList, 1); if (!(unique_id = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } else if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } set_server_unique_id(from_server, unique_id); if (do_hook(current_numeric, "%s %s %s", from, unique_id, message)) goto DISPLAY; goto END; } case 301: /* #define RPL_AWAY 301 */ { const char *nick, *message; PasteArgs(ArgList, 1); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } /* Ach. /on 301 doesn't offer 'from' as $0. Bummer. */ if (do_hook(current_numeric, "%s %s", nick, message)) goto DISPLAY; goto END; } case 340: /* #define RPL_USERIP 307 */ if (!get_server_005(from_server, "USERIP")) break; /* FALLTHROUGH */ case 302: /* #define RPL_USERHOST 302 */ userhost_returned(from_server, from, comm, ArgList); goto END; case 303: /* #define RPL_ISON 303 */ ison_returned(from_server, from, comm, ArgList); goto END; case 315: /* #define RPL_ENDOFWHO 315 */ who_end(from_server, from, comm, ArgList); goto END; case 321: /* #define RPL_LISTSTART 321 */ { const char *channel, *user_cnt, *line; channel = ArgList[0] = "Channel"; user_cnt = ArgList[1] = "Users"; line = ArgList[2] = "Topic"; ArgList[3] = NULL; /* Then see if they want to hook /ON LIST */ if (!do_hook(LIST_LIST, "%s %s %s", channel, user_cnt, line)) goto END; /* * Otherwise, this line is ok. */ break; } case 322: /* #define RPL_LIST 322 */ { const char *channel, *user_cnt, *line; int cnt; int funny_flags, funny_min, funny_max; const char *funny_match; PasteArgs(ArgList, 2); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(user_cnt = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(line = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } funny_flags = get_server_funny_flags(from_server); funny_min = get_server_funny_min(from_server); funny_max = get_server_funny_max(from_server); funny_match = get_server_funny_match(from_server); /* * Do not display if the channel has no topic and the user asked * for only channels with topics. */ if (funny_flags & FUNNY_TOPIC && !(line && *line)) goto END; /* * Do not display if the channel does not have the necessary * number of users the user asked for */ cnt = my_atol(user_cnt); if (funny_min && (cnt < funny_min)) goto END; if (funny_max && (cnt > funny_max)) goto END; /* * Do not display if the channel is not private or public as the * user requested. */ if ((funny_flags & FUNNY_PRIVATE) && (*channel != '*')) goto END; if ((funny_flags & FUNNY_PUBLIC) && (*channel == '*')) goto END; /* * Do not display if the channel does not match the user's * supplied wildcard pattern */ if (funny_match && wild_match(funny_match, channel) == 0) goto END; /* Then see if they want to hook /ON LIST */ if (!do_hook(LIST_LIST, "%s %s %s", channel, user_cnt, line)) goto END; /* * Otherwise, this line is ok. */ break; } case 324: /* #define RPL_CHANNELMODEIS 324 */ { const char *mode, *channel; PasteArgs(ArgList, 1); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(mode = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } /* If we're waiting for MODE reply. */ if (channel_is_syncing(channel, from_server)) { int numonchannel, maxnum; copy = LOCAL_COPY(channel); update_channel_mode(channel, mode); update_all_status(); maxnum = get_server_max_cached_chan_size(from_server); if (maxnum >= 0) { numonchannel = number_on_channel(copy, from_server); if (numonchannel <= maxnum) whobase(from_server, copy, add_user_who, add_user_end); else channel_not_waiting(copy, from_server); } else whobase(from_server, copy, add_user_who, add_user_end); #if 0 goto END; #endif } break; } case 352: /* #define RPL_WHOREPLY 352 */ whoreply(from_server, NULL, comm, ArgList); goto END; case 353: /* #define RPL_NAMREPLY 353 */ { const char *type, *channel, *line; PasteArgs(ArgList, 2); if (!(type = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(channel = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(line = ArgList[2])) { line = empty_string; } if (channel_is_syncing(channel, from_server)) { char *line_copy = LOCAL_COPY(line); char *nick; while ((nick = next_arg(line_copy, &line_copy)) != NULL) { /* XXX - Hack to work around space at end of 353 */ forcibly_remove_trailing_spaces(nick, NULL); /* * 1999 Oct 29 -- This is a hack to compensate for * a bug in older ircd implementations that can result * in a truncated nickname at the end of a names reply. * The last nickname in a names list is then always * treated with suspicion until the WHO reply is * completed and we know that its not truncated. --esl */ if (!line || !*line) add_to_channel(channel, nick, from_server, 1, 0, 0, 0); else add_to_channel(channel, nick, from_server, 0, 0, 0, 0); } message_from(channel, LOG_CRAP); break; } else { int cnt; const char *ptr; int funny_flags, funny_min, funny_max; const char *funny_match; funny_flags = get_server_funny_flags(from_server); funny_min = get_server_funny_min(from_server); funny_max = get_server_funny_max(from_server); funny_match = get_server_funny_match(from_server); ptr = line; for (cnt = -1; ptr; cnt++) { if ((ptr = strchr(ptr, ' ')) != NULL) ptr++; } if (funny_min && (cnt < funny_min)) goto END; else if (funny_max && (cnt > funny_max)) goto END; if ((funny_flags & FUNNY_PRIVATE) && (*type == '=')) goto END; if ((funny_flags & FUNNY_PUBLIC) && ((*type == '*') || (*type == '@'))) goto END; if (funny_match && wild_match(funny_match, channel) == 0) goto END; } /* Everything is OK. */ break; } case 354: /* #define RPL_XWHOREPLY 354 */ xwhoreply(from_server, NULL, comm, ArgList); goto END; /* XXX Yea yea, these are out of order. so shoot me. */ case 346: /* #define RPL_INVITELIST (+I for erf) */ case 348: /* #define RPL_EXCEPTLIST (+e for erf) */ case 367: /* #define RPL_BANLIST */ number_of_bans++; break; case 347: /* #define END_OF_INVITELIST */ case 349: /* #define END_OF_EXCEPTLIST */ case 368: /* #define END_OF_BANLIST */ { const char *channel; if (!get_int_var(SHOW_END_OF_MSGS_VAR)) goto END; if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } #ifdef IRCII_LIKE_BAN_SUMMARY if (do_hook(current_numeric, "%s %s %d", from, channel, number_of_bans)) #else if (do_hook(current_numeric, "%s %d %s", from, number_of_bans, channel)) #endif { put_it("%s Total number of %s on %s - %d", banner(), numeric == 347 ? "invites" : (numeric == 349 ? "exceptions" : (numeric == 368 ? "bans" : "wounds")), channel, number_of_bans); } goto END; } /* XXX Shouldn't this set "You're operator" flag for hybrid? */ case 381: /* #define RPL_YOUREOPER 381 */ if (!is_server_registered(from_server)) { rfc1459_odd(from, comm, ArgList); goto END; } break; /* ":%s 401 %s %s :No such nick/channel" */ case 401: /* #define ERR_NOSUCHNICK 401 */ { const char *nick; if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!is_channel(nick)) { notify_mark(from_server, nick, 0, 0); if (get_int_var(AUTO_WHOWAS_VAR)) { int foo = get_int_var(NUM_OF_WHOWAS_VAR); if (foo > -1) send_to_server("WHOWAS %s %d", nick, foo); else send_to_server("WHOWAS %s", nick); } } break; } /* Bizarre dalnet extended who replies. */ /* ":%s 402 %s %s :No such server" */ case 402: { const char *server; if (!(server = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } fake_who_end(from_server, from, comm, server); break; } /* Yet more bizarre dalnet extended who replies. */ /* ":%s 522 %s :/WHO Syntax incorrect, use /who ? for help" */ /* ":%s 523 %s :Error, /who limit of %d exceed." */ case 522: case 523: { /* * This dalnet error message doesn't even give us the * courtesy of telling us which who request was in error, * so we have to guess. Whee. */ fake_who_end(from_server, from, comm, NULL); break; } case 403: /* #define ERR_NOSUCHCHANNEL 403 */ { const char * s; const char * channel; const char * message; PasteArgs(ArgList, 1); /* Some servers BBC and send back an empty reply. */ if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } /* Do not accept 403's from remote servers. */ s = get_server_itsname(from_server); if (my_strnicmp(s, from, strlen(s))) { rfc1459_odd(from, comm, ArgList); goto END; } /* * Some servers BBC and send this instead of a * 315 numeric when a who request has been completed. */ if (fake_who_end(from_server, from, comm, channel)) ; /* * If you try to JOIN or PART the "*" named channel, as may * happen if epic gets confused, the server may tell us that * channel does not exist. But it would be death to try to * destroy that channel as epic will surely do the wrong thing! * Otherwise, we somehow tried to reference a channel that * this server claims does not exist; we blow the channel away * for good measure. */ else if (strcmp(channel, "*")) remove_channel(channel, from_server); break; } case 421: /* #define ERR_UNKNOWNCOMMAND 421 */ { const char *token; if (!(token = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (check_server_redirect(from_server, token)) goto END; if (check_server_wait(from_server, token)) goto END; break; } case 432: /* #define ERR_ERRONEUSNICKNAME 432 */ { const char *nick; if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!my_stricmp(target, nick)) yell("WARNING: Strange invalid nick message received." " You are probably lagged."); else if (get_int_var(AUTO_NEW_NICK_VAR)) fudge_nickname(from_server); else reset_nickname(from_server); break; } case 437: /* av2.9's "Nick collision" numeric 437 */ /* Also, undernet/dalnet "You are banned" */ /* Also, av2.10's "Can't do that" numeric */ /* Also, cs's "too many nick changes" num */ { /* * Ugh. What a total trainwreck this is. Sometimes, I * really hate all the ircd's out there in the world that * have to be supported. * * Well, there are at least four different, occasionally * scrutable ways we can get this numeric. * * 1a) On ircnet -- As an unregistered user, the NICK that * we are trying to register was used in the past 90 * seconds or so. The server expects us to send * another NICK request. * ARGV[0] IS NICK, REGISTERED IS NO * 1b) On ircnet -- As a registered user, the NICK that * we are trying to register was used in the past 90 * seconds or so. The server expects us not to do * anything (like a 432 numeric). * ARGV[0] IS NICK, REGISTERED IS YES * 2) On ircnet -- As a registered user, we are trying to * join a channel that was netsplit in the past 24 hours * or so. The server expects us not to do anything. * ARGV[0] IS CHANNEL, REGISTERED IS YES * 3) On undernet/dalnet -- As a registered user, who is * on a channel where we are banned, a NICK request * was rejected (because we are banned). The server * expects us not to do anything. * ARGV[0] IS CHANNEL, REGISTERED IS YES * 4) On a comstud efnet servers -- As a registered user, * we have changed our nicknames too many times in * too short a time. The server expects us not to do * anything. * ARGV[0] IS ERROR, ARGV[1] IS NULL. * I understand this numeric will be moving to 439. */ /* * Weed out the comstud one first, since it's the most bizarre. */ if (ArgList[0] && ArgList[1] == NULL) { accept_server_nickname(from_server, target); break; } /* * Now if it's a channel, it might be ircnet telling us we * can't join the channel, or undernet telling us that we * can't change our nickname because we're banned. The * easiest way to tell is to see if we are on the channel. */ if (is_channel(ArgList[0])) { /* XXX Is this really neccesary? */ if (!im_on_channel(ArgList[0], from_server)) remove_channel(ArgList[0], from_server); break; } /* * Otherwise, a nick command failed. Oh boy. * If we are registered, abort the nick change and * hope for the best. */ if (is_server_registered(from_server)) { accept_server_nickname(from_server, target); break; } /* * Otherwise, it's an ircnet "nick not available" error. * Let the nickname reset numerics handle this mess. */ /* FALLTHROUGH */ } case 433: /* #define ERR_NICKNAMEINUSE 433 */ case 438: /* EFnet/TS4 "nick collision" numeric 438 */ case 453: /* EFnet/TS4 "nickname lost" numeric 453 */ { const char *nick; if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!my_stricmp(target, nick)) /* * This should stop the "rolling nicks" in their tracks. */ yell("WARNING: Strange invalid nick message received." " You are probably lagged."); else if (get_int_var(AUTO_NEW_NICK_VAR)) fudge_nickname(from_server); else reset_nickname(from_server); if (!from) from = "-1"; break; } case 439: /* Comstud's "Can't change nickname" */ { accept_server_nickname(from_server, target); break; } case 442: /* #define ERR_NOTONCHANNEL 442 */ { const char * s; const char * channel; const char * message; PasteArgs(ArgList, 1); /* Some servers BBC and send back an empty reply. */ if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } /* Do not accept this numeric from remote servers */ s = get_server_itsname(from_server); if (my_strnicmp(s, from, strlen(s))) { rfc1459_odd(from, comm, ArgList); goto END; } /* Do not ever delete the "*" channel */ if (strcmp(ArgList[0], "*")) remove_channel(ArgList[0], from_server); break; } case 451: /* #define ERR_NOTREGISTERED 451 */ /* * Sometimes the server doesn't catch the USER line, so * here we send a simplified version again -lynx */ register_server(from_server, NULL); break; case 462: /* #define ERR_ALREADYREGISTRED 462 */ change_server_nickname(from_server, NULL); break; case 465: /* #define ERR_YOUREBANNEDCREEP 465 */ { /* * There used to be a say() here, but if we arent * connected to a server, then doing say() is not * a good idea. So now it just doesnt do anything. */ server_reconnects_to(from_server, NOSERV); break; } case 477: /* #define ERR_NEEDREGGEDNICK 477 */ /* IRCnet has a different 477 numeric. */ if (ArgList[0] && *ArgList[0] == '+') break; /* FALLTHROUGH */ case 471: /* #define ERR_CHANNELISFULL 471 */ case 473: /* #define ERR_INVITEONLYCHAN 473 */ case 474: /* #define ERR_BANNEDFROMCHAN 474 */ case 475: /* #define ERR_BADCHANNELKEY 475 */ case 476: /* #define ERR_BADCHANMASK 476 */ { const char *channel; if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } cant_join_channel(ArgList[0], from_server); break; } } /* DEFAULT OFFER */ /* * This is the "default hook" case, where we offer to the user all of * the numerics that were not offered above. We simply catenate * all of the arguments into a string and offer to the user. * If the user bites, then we skip the "default display" section. */ copy = alloca(IRCD_BUFFER_SIZE + 1); *copy = 0; for (i = 0; ArgList[i]; i++) { if (i) strlcat(copy, " ", IRCD_BUFFER_SIZE); strlcat(copy, ArgList[i], IRCD_BUFFER_SIZE); } if (!do_hook(current_numeric, "%s %s", from, copy)) goto END; DISPLAY: /* DEFAULT DISPLAY */ /* * This is the "default display" case, where if the user does not * hook the numeric, we output the message in some special way. * If a numeric does not require special outputting, then we will * just display it with ``display_msg'' */ switch (numeric) { case 221: /* #define RPL_UMODEIS 221 */ { const char *umode; PasteArgs(ArgList, 0); if (!(umode = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s Your user mode is \"%s\"", banner(), umode); break; } case 271: /* #define SILENCE_LIST 271 */ { const char *perp, *victim; PasteArgs(ArgList, 1); if (!(perp = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(victim = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s is ignoring %s", banner(), perp, victim); break; } case 301: /* #define RPL_AWAY 301 */ { const char *nick, *message; PasteArgs(ArgList, 1); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s is away: %s", banner(), nick, message); break; } case 311: /* #define RPL_WHOISUSER 311 */ { const char *nick, *user, *host, *channel, *name; PasteArgs(ArgList, 4); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(user = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(host = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(channel = ArgList[3])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(name = ArgList[4])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s is %s@%s (%s)", banner(), nick, user, host, name); break; } case 312: /* #define RPL_WHOISSERVER 312 */ { const char *nick, *server, *pithy; PasteArgs(ArgList, 2); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(server = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(pithy = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s on irc via server %s (%s)", banner(), server, pithy); break; } case 313: /* #define RPL_WHOISOPERATOR 313 */ { const char *nick, *message; PasteArgs(ArgList, 1); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(message = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s %s", banner(), ArgList[0], ArgList[1]); break; } case 314: /* #define RPL_WHOWASUSER 314 */ { const char *nick, *user, *host, *unused, *name; PasteArgs(ArgList, 4); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(user = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(host = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(unused = ArgList[3])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(name = ArgList[4])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s was %s@%s (%s)",banner(), nick, user, host, name); break; } case 317: /* #define RPL_WHOISIDLE 317 */ { const char *nick, *idle_str, *startup_str; int idle; const char * unit; char startup_ctime[128]; if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(idle_str = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(startup_str = ArgList[2])) { /* No problem */; } *startup_ctime = 0; if (startup_str) /* Undernet/TS4 */ { time_t startup; if ((startup = atol(startup_str)) != 0) snprintf(startup_ctime, 128, ", signed on at %s", my_ctime(startup)); } if ((idle = atoi(idle_str)) > 59) { idle /= 60; unit = "minute"; } else unit = "second"; put_it ("%s %s has been idle %d %ss%s", banner(), nick, idle, unit, startup_ctime); break; } case 318: /* #define RPL_ENDOFWHOIS 318 */ { PasteArgs(ArgList, 0); if (get_int_var(SHOW_END_OF_MSGS_VAR)) display_msg(from, comm, ArgList); break; } case 319: /* #define RPL_WHOISCHANNELS 319 */ { const char *nick, *channels; PasteArgs(ArgList, 1); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(channels = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s on channels: %s", banner(), channels); break; } case 321: /* #define RPL_LISTSTART 321 */ /* Our screwy 321 handling demands this. BAH! */ put_it("%s Channel Users Topic", banner()); break; case 322: /* #define RPL_LIST 322 */ { static char format[25]; static int last_width = -1; const char *channel, *user_cnt, *line; PasteArgs(ArgList, 2); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(user_cnt = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(line = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } /* Figure out how to display this to the user. */ if (last_width != get_int_var(CHANNEL_NAME_WIDTH_VAR)) { if ((last_width = get_int_var(CHANNEL_NAME_WIDTH_VAR))) snprintf(format, 25, "%%-%u.%us %%-5s %%s", (unsigned) last_width, (unsigned) last_width); else strlcpy(format, "%s\t%-5s %s", sizeof format); } if (*channel == '*') say(format, "Prv", user_cnt, line); else say(format, check_channel_type(channel), user_cnt, line); break; } case 324: /* #define RPL_CHANNELMODEIS 324 */ { const char *mode, *channel; PasteArgs(ArgList, 1); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(mode = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s Mode for channel %s is \"%s\"", banner(), channel, mode); break; } case 329: /* #define CREATION_TIME 329 */ { const char *channel, *time1_str, *time2_str, *time3_str; time_t time1, time2, time3; PasteArgs(ArgList, 2); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(time1_str = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(time2_str = ArgList[2])) { /* No problem */; } if (!(time3_str = ArgList[3])) { /* No problem */; } /* Erf/TS4 support */ if (time2_str && time3_str) { time1 = (time_t)my_atol(time1_str); time2 = (time_t)my_atol(time2_str); time3 = (time_t)my_atol(time3_str); put_it("%s Channel %s was created at %ld, " "+c was last set at %ld, " "and has been opless since %ld", banner(), channel, time1, time2, time3); } else { time1 = (time_t)my_atol(time1_str); put_it("%s Channel %s was created at %s", banner(), channel, my_ctime(time1)); } break; } case 330: /* #define RPL_WHOISLOGGEDIN 330 */ { const char *nick, *login, *reason; PasteArgs(ArgList, 2); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(login = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(reason = ArgList[2])) { reason = "is logged in as"; } put_it("%s %s %s %s", banner(), nick, reason, login); break; } case 332: /* #define RPL_TOPIC 332 */ { const char *channel, *topic; PasteArgs(ArgList, 1); if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(topic = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s Topic for %s: %s", banner(), channel, topic); break; } case 333: /* #define RPL_TOPICWHOTIME 333 */ { const char *channel, *nick, *when_str; time_t howlong; if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(nick = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(when_str = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } howlong = time(NULL) - my_atol(when_str); put_it("%s The topic was set by %s %ld sec ago",banner(), nick, howlong); break; } case 341: /* #define RPL_INVITING 341 */ { const char *nick, *channel; if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(channel = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } message_from(channel, LOG_CRAP); put_it("%s Inviting %s to channel %s", banner(), nick, channel); break; } case 351: /* #define RPL_VERSION 351 */ { const char *version, *itsname, *stuff; PasteArgs(ArgList, 2); if (!(version = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(itsname = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(stuff = ArgList[2])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s Server %s: %s %s",banner(), itsname, version, stuff); break; } case 353: /* #define RPL_NAMREPLY 353 */ { static int last_width; char format[41]; const char *type, *channel, *line; PasteArgs(ArgList, 2); if (!(type = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(channel = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(line = ArgList[2])) { line = empty_string; } /* This is only for when the user joined the channel */ if (channel_is_syncing(channel, from_server)) { /* If the user bites on /ON NAMES, then skip the rest */ message_from(channel, LOG_CRAP); if (do_hook(NAMES_LIST, "%s %s", channel, line)) if (get_int_var(SHOW_CHANNEL_NAMES_VAR)) say("Users on %s: %s", check_channel_type(channel), line); break; } /* If the user grabs /ON NAMES then just stop right here */ if (!do_hook(NAMES_LIST, "%s %s", channel, line)) break; /* This all is for when the user has not just joined channel */ if (last_width != get_int_var(CHANNEL_NAME_WIDTH_VAR)) { if ((last_width = get_int_var(CHANNEL_NAME_WIDTH_VAR))) snprintf(format, 40, "%%s: %%-%u.%us %%s", (unsigned char) last_width, (unsigned char) last_width); else strlcpy(format, "%s: %s\t%s", sizeof format); } else strlcpy(format, "%s: %s\t%s", sizeof format); message_from(channel, LOG_CRAP); if (*type == '=') { if (last_width && ((int)strlen(channel) > last_width)) { char *channel_copy = LOCAL_COPY(channel); channel_copy[last_width-1] = '>'; channel_copy[last_width] = 0; channel = channel_copy; } put_it(format, "Pub", check_channel_type(channel), line); } else if (*type == '*') put_it(format, "Prv", check_channel_type(channel), line); else if (*type == '@') put_it(format, "Sec", check_channel_type(channel), line); break; } case 364: /* #define RPL_LINKS 364 */ { const char *itsname, *uplink, *stuff; PasteArgs(ArgList, 2); if (!(itsname = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(uplink = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(stuff = ArgList[2])) { stuff = empty_string; } if (stuff) put_it("%s %-20s %-20s %s", banner(), itsname, uplink, stuff); else put_it("%s %-20s %s", banner(), itsname, uplink); break; } case 366: /* #define RPL_ENDOFNAMES 366 */ { const char *channel; if (!get_int_var(SHOW_END_OF_MSGS_VAR)) break; if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!channel_is_syncing(channel, from_server)) display_msg(from, comm, ArgList); break; } case 346: /* +I on erf */ case 348: /* +e on erf */ case 367: /* +b */ { const char *channel, *ban, *perp, *when_str; time_t howlong; if (!(channel = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(ban = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(perp = ArgList[2])) { /* No problem. */ } if (!(when_str = ArgList[3])) { /* No problem. */ } if (perp && when_str) { howlong = time(NULL) - my_atol(when_str); put_it("%s %s %-25s set by %-10s %ld sec ago", banner(), channel, ban, perp, howlong); } else put_it("%s %s %s", banner(), channel, ban); break; } case 401: /* #define ERR_NOSUCHNICK 401 */ { const char *nick, *stuff; PasteArgs(ArgList, 1); if (!(nick = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } if (!(stuff = ArgList[1])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s: %s", banner(), nick, stuff); break; } case 219: /* #define RPL_ENDOFSTATS 219 */ case 232: /* #define RPL_ENDOFSERVICES 232 */ case 365: /* #define RPL_ENDOFLINKS 365 */ case 369: /* #define RPL_ENDOFWHOWAS 369 */ case 374: /* #define RPL_ENDOFINFO 374 */ case 394: /* #define RPL_ENDOFUSERS 394 */ { PasteArgs(ArgList, 0); if (get_int_var(SHOW_END_OF_MSGS_VAR)) display_msg(from, comm, ArgList); break; } case 471: /* #define ERR_CHANNELISFULL 471 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s (Channel is full)", banner(), message); break; } case 473: /* #define ERR_INVITEONLYCHAN 473 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s (You must be invited)", banner(), message); break; } case 474: /* #define ERR_BANNEDFROMCHAN 474 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s (You are banned)", banner(), message); break; } case 475: /* #define ERR_BADCHANNELKEY 475 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s (You must give the correct key)", banner(), message); break; } case 476: /* #define ERR_BADCHANMASK 476 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } put_it("%s %s (Bad channel mask)", banner(), message); break; } case 477: /* #define ERR_NEEDREGGEDNICK 477 */ { const char *message; PasteArgs(ArgList, 0); if (!(message = ArgList[0])) { rfc1459_odd(from, comm, ArgList); goto END; } /* IRCnet has a different 477 numeric. */ if (message && *message == '+') { display_msg(from, comm, ArgList); break; } PasteArgs(ArgList, 0); put_it("%s %s (You must use a registered nickname)", banner(), message); break; } default: display_msg(from, comm, ArgList); } END: /* * This is where we clean up after our numeric. Numeric-specific * cleanups can occur here, and then below we reset the display * settings. */ switch (numeric) { case 347: /* #define END_OF_INVITELIST */ case 349: /* #define END_OF_EXCEPTLIST */ case 368: number_of_bans = 0; break; case 464: /* #define ERR_PASSWDMISMATCH 464 */ { char server_num[8]; if (oper_command) oper_command = 0; else if (!is_server_registered(from_server)) { server_reconnects_to(from_server, NOSERV); say("Password required for connection to server %s", get_server_name(from_server)); if (!dumb_mode) { strlcpy(server_num, ltoa(from_server), sizeof server_num); add_wait_prompt("Server Password:", password_sendline, server_num, WAIT_PROMPT_LINE, 0); } } } } current_numeric = old_current_numeric; set_lastlog_msg_level(lastlog_level); message_from(NULL, LOG_CRAP); }
void on_send_message(GtkWidget *widget, pchatbox_t *chatbox) { pchatbox_t *pchatbox; ifreechat_t *ifc; user_t *user; char buf[65535]; char *msg; time_t pno; GtkTextView *input_textview; GtkTextView *output_textview; GtkTextBuffer *input_buffer; GtkTextBuffer *output_buffer; GtkTextIter start; GtkTextIter end; GtkTextMark *mark; GdkPixbuf *pixbuf; pchatbox = (pchatbox_t*)(chatbox); ifc = (ifreechat_t*)pchatbox->ifreechat; user = (user_t*)pchatbox->data; pno = time(NULL); input_textview = pchatbox->input_textview; output_textview = pchatbox->display_textview; input_buffer = gtk_text_view_get_buffer(input_textview); output_buffer = gtk_text_view_get_buffer(output_textview); gtk_text_buffer_get_start_iter(input_buffer, &start); gtk_text_buffer_get_end_iter(input_buffer, &end); if (gtk_text_iter_equal(&start, &end)) { printf("Please enter message!!!\n"); return; } msg = gtk_text_buffer_get_text(input_buffer, &start, &end, TRUE); gtk_text_buffer_delete(input_buffer, &start, &end); sprintf(buf, "%s(%s):\n", ifc->nickname, my_ctime(&pno)); gtk_text_buffer_get_end_iter(output_buffer, &end); gtk_text_buffer_insert_with_tags_by_name(output_buffer, &end, buf, -1, "blue_fg", "lmarg", "title_font", NULL); insert_msg_with_emotion_to_textview(output_textview, msg); gtk_text_buffer_get_end_iter(output_buffer, &end); mark = gtk_text_buffer_create_mark(output_buffer, NULL, &end, FALSE); gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(output_textview), mark, 0.0, TRUE, 0.0, 0.0); gtk_text_buffer_delete_mark(output_buffer, mark); // printf("msg: [%s]\n", msg); sprintf(buf, "1_lbt4_%d#128#%s#0#0#0:%lu:%s:%s:%u:%s", ifc->avatar_id, ifc->macaddr, pno, ifc->username, ifc->hostname, 0x120, msg); // printf("buf: %s\n", buf); udp_send_msg((ifreechat_t*)chatbox->ifreechat, user->ipaddr, ifc->port, buf, strlen(buf)); }
int model1::em_with_tricks(int noIterations, /*Perplexity& perp, sentenceHandler& sHandler1, */ bool seedModel1, Dictionary& dictionary, bool useDict /*Perplexity* testPerp, sentenceHandler* testHandler, Perplexity& trainViterbiPerp, Perplexity* testViterbiPerp */ , bool dumpCount , const char* dumpCountName, bool useString) // If specified, then will dump files before last iteration { double minErrors=1.0; int minIter=0; string modelName="Model1",shortModelName="1"; time_t st, it_st, fn, it_fn; string tfile, number, alignfile, test_alignfile; bool dump_files = false ; st = time(NULL); sHandler1.rewind(); cout << "==========================================================\n"; cout << modelName << " Training Started at: "<< my_ctime(&st) << "\n"; for(int it = 1; it <= noIterations; it++) { it_st = time(NULL); cout << "-----------\n" << modelName << ": Iteration " << it << '\n'; dump_files = (Model1_Dump_Freq != 0) && ((it % Model1_Dump_Freq) == 0 || it == noIterations) && !NODUMPS ; //dump_files = true; number = ""; int n = it; do { number.insert((size_t)0, 1, (char)(n % 10 + '0')); } while((n /= 10) > 0); tfile = Prefix + ".t" + shortModelName + "." + number ; alignfile = Prefix + ".A" + shortModelName + "." + number+".part0" ; test_alignfile = Prefix +".tst.A" + shortModelName + "." + number ; initAL(); threadID = 0; int th; vector<em_loop_t> ths; ths.resize(NCPUS); sHandler1.rewind(); for (th=1; th<NCPUS; th++) { ths[th].m1=this; ths[th].it = it; ths[th].nthread = th; ths[th].dict = & dictionary; ths[th].useDict = useDict; ths[th].result = 0; ths[th].valid = pthread_create(&(ths[th].thread),NULL,exe_emloop,&(ths[th])); if(ths[th].valid) { cerr << "Error starting thread " << th << endl; } } em_loop(it,perp, sHandler1, seedModel1, dump_files, alignfile.c_str(), dictionary, useDict, trainViterbiPerp); perp.record("Model1"); trainViterbiPerp.record("Model1"); errorReportAL(cout, "IBM-1"); cerr << "Main thread done, waiting" << endl;; for (th=1; th<NCPUS; th++) { pthread_join((ths[th].thread),NULL); cerr << "Thread " << th << "done" << endl; } if (testPerp && testHandler) // calculate test perplexity em_loop(it,*testPerp, *testHandler, seedModel1, dump_files, test_alignfile.c_str(), dictionary, useDict, *testViterbiPerp, true); if( errorsAL()<minErrors ) { minErrors=errorsAL(); minIter=it; } //if (dump_files){ // if( OutputInAachenFormat==1 ) // tTable.printCountTable(tfile.c_str(),Elist.getVocabList(),Flist.getVocabList(),1); //} cerr << "Normalizing T " << endl; /** If asked for dumping count table, just dump it. */ if(dumpCount && it == noIterations) { string realTableName = dumpCountName; realTableName += ".t.count"; tTable.printCountTable(realTableName.c_str(),Elist.getVocabList(),Flist.getVocabList(),useString); } tTable.normalizeTable(Elist, Flist); //cout << tTable.getProb(2,2) << endl; cerr << " DONE Normalizing " << endl; cout << modelName << ": ("<<it<<") TRAIN CROSS-ENTROPY " << perp.cross_entropy() << " PERPLEXITY " << perp.perplexity() << '\n'; if (testPerp && testHandler) cout << modelName << ": ("<<it<<") TEST CROSS-ENTROPY " << (*testPerp).cross_entropy() << " PERPLEXITY " << (*testPerp).perplexity() << '\n'; cout << modelName << ": ("<<it<<") VITERBI TRAIN CROSS-ENTROPY " << trainViterbiPerp.cross_entropy() << " PERPLEXITY " << trainViterbiPerp.perplexity() << '\n'; if (testPerp && testHandler) cout << modelName << ": ("<< it<<") VITERBI TEST CROSS-ENTROPY " << (*testViterbiPerp).cross_entropy() << " PERPLEXITY " << (*testViterbiPerp).perplexity() << '\n'; if (dump_files) { if( OutputInAachenFormat==0 ) tTable.printProbTable(tfile.c_str(),Elist.getVocabList(), Flist.getVocabList(),OutputInAachenFormat); } it_fn = time(NULL); cout << "Model 1 Iteration: " << it<< " took: " << difftime(it_fn, it_st) << " seconds\n"; } fn = time(NULL) ; cout << "Entire " << modelName << " Training took: " << difftime(fn, st) << " seconds\n"; return minIter; }