int main (int argc, char *argv[]) { #ifdef SOCKS SOCKSinit (argv[0]); #endif if (!fe_args (argc, argv)) return 0; load_config (); fe_init (); xchat_init (); fe_main (); #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG xchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int ld_init(live_decoder_t *decoder, int argc, char **argv) { param_t fe_param; if (argc == 2) { /* * lgalescu: check if args need to be processed from file */ parse_args_file(argv[1]); } else cmd_ln_parse(arg_def, argc, argv); unlimit(); /* some decoder parameter capturing * !!! NOTE - HARDCODED FOR NOW. REPLACE WITH PARSE_ARG() ASAP !!!! */ memset(decoder, 0, sizeof(live_decoder_t)); kb_init(&decoder->kb); decoder->max_wpf = cmd_ln_int32 ("-maxwpf");; decoder->max_histpf = cmd_ln_int32 ("-maxhistpf"); decoder->max_hmmpf = cmd_ln_int32 ("-maxhmmpf"); decoder->phones_skip = cmd_ln_int32 ("-ptranskip"); decoder->hmm_log = cmd_ln_int32("-hmmdump") ? stderr : NULL; decoder->kbcore = decoder->kb.kbcore; decoder->kb.uttid = decoder->uttid; decoder->hypsegs = 0; decoder->num_hypsegs = 0; decoder->hypstr_len = 0; decoder->hypstr[0] = '\0'; decoder->features = feat_array_alloc(kbcore_fcb(decoder->kbcore), LIVEBUFBLOCKSIZE); decoder->ld_state = LD_STATE_IDLE; /* some front-end parameter capturing * !!! NOTE - HARDCODED FOR NOW. REPLACE WITH PARSE_ARG() ASAP !!!! */ memset(&fe_param, 0, sizeof(param_t)); fe_param.SAMPLING_RATE = (float32)cmd_ln_int32 ("-samprate"); fe_param.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param.UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param.NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param.FRAME_RATE = cmd_ln_int32("-frate"); fe_param.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param.FFT_SIZE = cmd_ln_int32("-nfft"); fe_param.WINDOW_LENGTH = cmd_ln_float32("-wlen"); decoder->fe = fe_init(&fe_param); if (!decoder->fe) { E_WARN("Front end initialization fe_init() failed\n"); return -1; } return 0; }
/* This routine initializes decoder variables for live mode decoding */ void live_initialize_decoder(char *live_args) { static kb_t live_kb; int32 maxcepvecs, maxhyplen, samprate, ceplen; param_t *fe_param; /*char const *uttIdNotDefined = "null";*/ parse_args_file(live_args); unlimit(); kb_init(&live_kb); kb = &live_kb; kbcore = kb->kbcore; kb->uttid = ckd_calloc(1000,sizeof(char)); hmmdumpfp = cmd_ln_int32("-hmmdump") ? stderr : NULL; maxwpf = cmd_ln_int32 ("-maxwpf"); maxhistpf = cmd_ln_int32 ("-maxhistpf"); maxhmmpf = cmd_ln_int32 ("-maxhmmpf"); ptranskip = cmd_ln_int32 ("-ptranskip"); maxhyplen = cmd_ln_int32 ("-maxhyplen"); if (!parthyp) parthyp = (partialhyp_t *) ckd_calloc(maxhyplen, sizeof(partialhyp_t)); parthyplen = 0; fe_param = (param_t *) ckd_calloc(1, sizeof(param_t)); samprate = cmd_ln_int32 ("-samprate"); if (samprate != 8000 && samprate != 16000) E_FATAL("Sampling rate %d not supported. Must be 8000 or 16000\n",samprate); fe_param->SAMPLING_RATE = (float32) samprate; fe_param->LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param->UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param->NUM_FILTERS = cmd_ln_int32("-nfilt"); /* 20040413, by ARCHAN. Clear the hardwiring. Hmm. Many people say no to do this, I just can't take it. */ fe_param->FRAME_RATE = cmd_ln_int32("-frate"); /* fe_param->FRAME_RATE = 100; */ fe_param->PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param->FFT_SIZE = cmd_ln_int32("-nfft"); fe_param->WINDOW_LENGTH = cmd_ln_float32("-wlen"); fe_param->doublebw=OFF; fe = fe_init(fe_param); if (!fe) E_FATAL("Front end initialization fe_init() failed\n"); maxcepvecs = cmd_ln_int32 ("-maxcepvecs"); ceplen = kbcore->fcb->cepsize; dummyframe = (float32*) ckd_calloc(1 * ceplen,sizeof(float32)); /* */ }
void main() #endif { game_t game; /* Initialize the front end */ fe_init(); /* Initialize the game */ /* Create the game */ memset(&game, 0, sizeof(game_t)); /* Create the paddle */ init_paddle(&game.paddle, SPECIAL_NONE, (SCREEN_WIDTH/2)-(PADDLE_WIDTH/2)); /* Init the balls (only one active) */ init_ball(&game.p_balls[0], game.paddle.x+(PADDLE_WIDTH/2), PADDLE_Y-PADDLE_HEIGHT, BALL_STATE_ACTIVE|BALL_STATE_HOLDING); game.nr_balls = 1; /* Init the specials */ game.lives = NR_LIVES; /* Set the numbe of levels */ if (fe_load_data(game.p_levels, 0, (FIELD_WIDTH+1)*FIELD_HEIGHT, "Zarkanoid")) fe_finalize(); /* Could not load the levels */ game.levels = (game.p_levels[0]-'0')*10+(game.p_levels[1]-'0'); /* Number of levels */ game.level = 5*((game.p_levels[3]-'0')*10+(game.p_levels[4]-'0')); /* Starting level (skip 5 levels at a time) */ #if defined(TARGET_SDL) /* Set the level to start at to the argument */ if (argc > 1) game.level = atoi(argv[1]); #endif /* Load the first level */ goto_level(&game); /* Draw the game screen */ draw_screen(&game); fe_sleep(100); /* Start the game */ do_game(&game); /* Clean up afterwards */ fe_finalize(); #if defined(TARGET_SDL) return 0; #endif }
int main(int argc, char *argv[]) { game_t game; fe_init(); fe_clear_screen(); game_init(&game, PF_WHITE); game_draw(&game, game.starting_color); game_do(&game); return 0; }
/* This routine initializes decoder variables for live mode decoding */ void live_initialize_decoder(char *live_args) { static kb_t live_kb; int32 maxcepvecs, maxhyplen, samprate, ceplen; param_t *fe_param; char const *uttIdNotDefined = "null"; parse_args_file(live_args); unlimit(); kb_init(&live_kb); kb = &live_kb; kbcore = kb->kbcore; kb->uttid = ckd_salloc(uttIdNotDefined); hmmdumpfp = cmd_ln_int32("-hmmdump") ? stderr : NULL; maxwpf = cmd_ln_int32 ("-maxwpf"); maxhistpf = cmd_ln_int32 ("-maxhistpf"); maxhmmpf = cmd_ln_int32 ("-maxhmmpf"); ptranskip = cmd_ln_int32 ("-ptranskip"); maxhyplen = cmd_ln_int32 ("-maxhyplen"); if (!parthyp) parthyp = (partialhyp_t *) ckd_calloc(maxhyplen, sizeof(partialhyp_t)); fe_param = (param_t *) ckd_calloc(1, sizeof(param_t)); samprate = cmd_ln_int32 ("-samprate"); if (samprate != 8000 && samprate != 16000) E_FATAL("Sampling rate %s not supported. Must be 8000 or 16000\n",samprate); fe_param->SAMPLING_RATE = (float32) samprate; fe_param->LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param->UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param->NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param->FRAME_RATE = 100; /* HARD CODED TO 100 FRAMES PER SECOND */ fe_param->PRE_EMPHASIS_ALPHA = (float32) 0.97; fe = fe_init(fe_param); if (!fe) E_FATAL("Front end initialization fe_init() failed\n"); maxcepvecs = cmd_ln_int32 ("-maxcepvecs"); ceplen = kbcore->fcb->cepsize; dummyframe = (float32*) ckd_calloc(1 * ceplen,sizeof(float32)); /* */ #if defined(THRD) score_barrier = thread_barrier_init(NUM_THREADS); if (!score_barrier) E_FATAL("Cannot initialize score_barrier\n"); #endif }
int main (int argc, char *argv[]) { int ret; srand (time (0)); /* CL: do this only once! */ #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS xchat_remote (); #endif load_config (); #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG xchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main (int argc, char *argv[]) { int ret; g_thread_init(NULL); mowgli_init(); #ifdef _WIN32 conspire_init_winsock(); #endif #ifdef GNUTLS gnutls_global_init (); #endif srand (time (0)); /* CL: do this only once! */ #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; load_config (); fe_init (); xchat_init (); fe_main (); #ifdef GNUTLS gnutls_global_deinit (); #endif #ifdef USE_DEBUG xchat_mem_list (); #endif return 0; }
int main (int argc, char *argv[]) { int ret; srand (time (0)); /* CL: do this only once! */ #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS xchat_remote (); #endif load_config (); fe_init (); xchat_init (); fe_main (); #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG xchat_mem_list (); #endif return 0; }
int main(void) { #ifdef USART_DEBUG usart0_init(); #endif init_pwm(); ir_init(); control_init(); fe_init(); sei(); #ifdef USART_DEBUG usart0_puts("Initialized\n\r"); #endif while (1) { ir_handler(); control_handler(); pwm_handler(); fe_handler(); } }
char * fe_fgets_stdin_fe(char *pr,char *s, int size) { if(!fe_is_initialized) fe_init(); if (fe_stdin_is_tty) { int h=fe_hist_pos; int change=0; char c; int i=0; if (fe_is_raw_tty==0) { fe_temp_set(); } fputs(pr,fe_echo); fflush(fe_echo); fe_cursor_pos=strlen(pr); /* prompt */ memset(s,0,size); loop { c=fe_getchar(); switch(c) { case feCTRL('M'): case feCTRL('J'): { fd_set fdset; struct timeval tv; int sel; fe_add_hist(s); i=strlen(s); if (i<size-1) s[i]='\n'; fputc('\n',fe_echo); fflush(fe_echo); FD_ZERO (&fdset); FD_SET(STDIN_FILENO, &fdset); tv.tv_sec = 0; tv.tv_usec = 0; #ifdef hpux sel = select (STDIN_FILENO+1, (int *)fdset.fds_bits, NULL, NULL, &tv); #else sel = select (STDIN_FILENO+1, &fdset, NULL, NULL, &tv); #endif if (sel==0) fe_temp_reset(); return s; } case feCTRL('H'): case 127: /*delete the character left of the cursor*/ { if (i==0) break; i--; fe_cursor_pos--; if(fe_cursor_pos<0) { fe_cursor_line--; fe_cursor_pos=colmax-1; fe_set_cursor(s,i); } else { fputc('\b',fe_echo); } /* NO BREAK : next: feCTRL('D') */ } case feCTRL('D'): /*delete the character under the cursor or eof*/ { int j; if ((i==0) &&(s[0]=='\0')) return NULL; /*eof*/ if (s[i]!='\0') { j=i; while(s[j]!='\0') { s[j]=s[j+1]; fputc(s[j],fe_echo); j++; } fputc(' ',fe_echo); if (fe_cursor_pos+(j-i)>=colmax) { fe_set_cursor(s,i); } else { while(j>i) { fputc('\b',fe_echo); j--; } } } change=1; fflush(fe_echo); break; } case feCTRL('A'): /* move the cursor to the beginning of the line */ { if (i>=colmax-strlen(pr)) { while (i>=colmax-strlen(pr)) { i-=colmax; fe_cursor_line--; } i=0; fe_cursor_pos=strlen(pr); fe_set_cursor(s,i); } else { while(i>0) { i--; fputc('\b',fe_echo); } fe_cursor_pos=strlen(pr); } break; } case feCTRL('E'): /* move the cursor to the end of the line */ { while(s[i]!='\0') { fputc(s[i],fe_echo); i++; fe_cursor_pos++; if(fe_cursor_pos>=colmax) { fe_cursor_pos=0; if(fe_cursor_line!=(pagelength-1)) fe_cursor_line++; } } break; } case feCTRL('B'): /* move the cursor backward one character */ { if (i>0) { i--; fputc('\b',fe_echo); fe_cursor_pos--; if(fe_cursor_pos<0) { fe_cursor_pos=colmax-1; fe_cursor_line--; } } break; } case feCTRL('F'): /* move the cursor forward one character */ { if(s[i]!='\0') { fputc(s[i],fe_echo); i++; fe_cursor_pos++; if(fe_cursor_pos>=colmax) { fe_cursor_pos=0; if(fe_cursor_line!=(pagelength-1)) fe_cursor_line++; } } break; } case feCTRL('U'): /* delete entire input line */ { fe_ctrl_u(s,&i); fe_cursor_pos=strlen(pr); memset(s,0,size); change=1; break; } #if 0 case feCTRL('W'): /* test hist. */ { int i; PrintS("\nstart hist\n"); for(i=0;i<fe_hist_max;i++) { if(fe_hist[i]!=NULL) { Print("%2d ",i); if(i==fe_hist_pos) PrintS("-"); else PrintS(" "); if(i==h) PrintS(">"); else PrintS(" "); PrintS(fe_hist[i]); PrintLn(); } } Print("end hist, next_pos=%d\n",fe_hist_pos); break; } #endif case feCTRL('K'): /* delete up to the end of the line */ { fe_ctrl_k(s,i); memset(&(s[i]),'\0',size-i); /* s[i]='\0';*/ change=1; break; } case feCTRL('L'): /* redraw screen */ { char t_buf[40]; char *t=t_buf; fe_cursor_line=i/colmax; /*fputs(tgetstr("cl",&t),fe_echo);*/ tputs(tgetstr("cl",&t),pagelength,fe_out_char); fflush(fe_echo); fputs(pr,fe_echo); fputs(s,fe_echo); fe_set_cursor(s,i); break; } case feCTRL('P'): /* previous line */ { fe_ctrl_u(s,&i); fe_get_hist(s,size,&h,change,-1); while(s[i]!='\0') { fputc(s[i],fe_echo); i++; } fe_cursor_pos=strlen(pr)+i/*strlen(s)*/; change=0; break; } case feCTRL('N'): /* next line */ { fe_ctrl_u(s,&i); fe_get_hist(s,size,&h,change,1); while(s[i]!='\0') { fputc(s[i],fe_echo); i++; } fe_cursor_pos=strlen(pr)+i/*strlen(s)*/; change=0; break; } default: { if ((c>=' ')&&(c<=126)) { fputc (c,fe_echo); fe_cursor_pos++; if(fe_cursor_pos>=colmax) { fe_cursor_pos=0; if(fe_cursor_line!=(pagelength-1)) fe_cursor_line++; } if (s[i]!='\0') { /* shift by 1 to the right */ int j=i; int l; while ((s[j]!='\0')&&(j<size-2)) j++; l=j-i; while (j>i) { s[j]=s[j-1]; j--; } /* display */ fwrite(s+i+1,l,1,fe_echo); fflush(fe_echo); /* set cursor */ if(fe_cursor_pos+l>=colmax) { while(fe_cursor_pos+l>=colmax) { fe_cursor_line--; l-=colmax; } fe_set_cursor(s,i); } else { while(l>0) { l--; fputc('\b',fe_echo); } } fflush(fe_echo); } if (i<size-1) s[i]=c; i++; change=1; } } } /* switch */ fflush(fe_echo); } /* loop */ } /*else*/ return fgets(s,size,stdin); }
int main (int argc, char *argv[]) { int i; int ret; srand (time (0)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 3) { for (i = 1; i < argc - 1; i++) { if (strcmp (argv[i], "-d") == 0) { if (xdir) { g_free (xdir); } xdir = strdup (argv[i + 1]); if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main (int32 argc, char *argv[]) { char line[4096], filename[4096], idspec[4096], *uttid, *result; int32 sf, ef, sps, adcin, nf; int16 adbuf[4096]; int32 i, k; float32 **mfcbuf; CDCN_type *cdcn; param_t param; fe_t *fe = NULL; fbs_init (argc, argv); /* Assume that cdcn_init is part of the above fbs_init() */ cdcn = uttproc_get_cdcn_ptr(); adcin = query_adc_input(); assert (adcin); /* Limited to processing audio input files (not cep) */ sps = query_sampling_rate(); fe_init_params(¶m); param.SAMPLING_RATE = (float)sps; if ((fe = fe_init (¶m)) == NULL) { E_ERROR("fe_init() failed to initialize\n"); exit (-1); } mfcbuf = (float32 **) ckd_calloc_2d (8192, 13, sizeof(float32)); /* Process "control file" input through stdin */ while (fgets (line, sizeof(line), stdin) != NULL) { if (uttproc_parse_ctlfile_entry (line, filename, &sf, &ef, idspec) < 0) continue; assert ((sf < 0) && (ef < 0)); /* Processing entire input file */ uttid = build_uttid (idspec); uttproc_begin_utt (uttid); /* Convert raw data file to cepstra */ if (uttfile_open (filename) < 0) { E_ERROR("uttfile_open(%s) failed\n", filename); continue; } fe_start_utt(fe); nf = 0; while ((k = adc_file_read (adbuf, 4096)) >= 0) { if (fe_process_utt (fe, adbuf, k, mfcbuf+nf, &k) == FE_ZERO_ENERGY_ERROR) { E_WARN("Frames with zero energy. Consider using dither\n"); } nf += k; /* WARNING!! No check for mfcbuf overflow */ } fe_end_utt(fe, mfcbuf[nf], &k); fe_close(fe); uttfile_close (); if (nf <= 0) { E_ERROR("Empty utterance\n"); continue; } else E_INFO("%d frames\n", nf); /* Update CDCN module */ cdcn_converged_update (mfcbuf, /* cepstra buffer */ nf, /* Number of frames */ cdcn, /* The CDCN wrapper */ 1 /* One iteration */ ); /* CDCN */ for (i = 0; i < nf; i++) cdcn_norm (mfcbuf[i], cdcn); /* Process normalized cepstra */ uttproc_cepdata (mfcbuf, nf, 1); uttproc_end_utt (); uttproc_result (&k, &result, 1); printf ("\n"); fflush (stdout); } ckd_free_2d((void **)mfcbuf); fbs_end (); return 0; }
int main (int argc, char *argv[]) { int i; int ret; srand (time (0)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 3) { for (i = 1; i < argc - 1; i++) { if (strcmp (argv[i], "-d") == 0) { if (xdir) { g_free (xdir); } xdir = strdup (argv[i + 1]); if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); /* FIXME: if this fail display an error (?) */ make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG hexchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
static int ld_init_impl(live_decoder_t * _decoder, int32 _internal_cmdln) { param_t fe_param; int rv = LD_SUCCESS; assert(_decoder != NULL); unlimit(); /* ARCHAN 20050708: This part should be factored with fe_parse_option */ /* allocate and initialize front-end */ fe_init_params(&fe_param); fe_param.SAMPLING_RATE = cmd_ln_float32("-samprate"); fe_param.FRAME_RATE = cmd_ln_int32("-frate"); fe_param.WINDOW_LENGTH = cmd_ln_float32("-wlen"); fe_param.FB_TYPE = strcmp("mel_scale", cmd_ln_str("-fbtype")) == 0 ? MEL_SCALE : LOG_LINEAR; fe_param.NUM_CEPSTRA = cmd_ln_int32("-ncep"); fe_param.NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param.FFT_SIZE = cmd_ln_int32("-nfft"); fe_param.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param.UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param.dither = strcmp("no", cmd_ln_str("-dither")); fe_param.warp_type = cmd_ln_str("-warp_type"); fe_param.warp_params = cmd_ln_str("-warp_params"); if ((_decoder->fe = fe_init(&fe_param)) == NULL) { E_WARN("Failed to initialize front-end.\n"); rv = LD_ERROR_OUT_OF_MEMORY; goto ld_init_impl_cleanup; } /* capture decoder parameters */ kb_init(&_decoder->kb); /* initialize decoder variables */ _decoder->kbcore = _decoder->kb.kbcore; _decoder->hyp_frame_num = -1; _decoder->uttid = NULL; _decoder->ld_state = LD_STATE_IDLE; _decoder->hyp_str = NULL; _decoder->hyp_segs = NULL; /* _decoder->swap= (cmd_ln_int32("-machine_endian") != cmd_ln_int32("-input_endian")); */ _decoder->swap = (strcmp(cmd_ln_str("-machine_endian"), cmd_ln_str("-input_endian")) != 0); _decoder->phypdump = (cmd_ln_int32("-phypdump")); _decoder->rawext = (cmd_ln_str("-rawext")); if (_decoder->phypdump) E_INFO("Partial hypothesis WILL be dumped\n"); else E_INFO("Partial hypothesis will NOT be dumped\n"); if (_decoder->swap) E_INFO("Input data WILL be byte swapped\n"); else E_INFO("Input data will NOT be byte swapped\n"); _decoder->internal_cmdln = _internal_cmdln; _decoder->features = feat_array_alloc(kbcore_fcb(_decoder->kbcore), LIVEBUFBLOCKSIZE); if (_decoder->features == NULL) { E_WARN("Failed to allocate internal feature buffer.\n"); rv = LD_ERROR_OUT_OF_MEMORY; goto ld_init_impl_cleanup; } return LD_SUCCESS; ld_init_impl_cleanup: if (_decoder->fe != NULL) { fe_close(_decoder->fe); } if (_decoder->features != NULL) { /* consult the implementation of feat_array_alloc() for how to free our * internal feature vector buffer */ ckd_free((void *) **_decoder->features); ckd_free_2d((void **) _decoder->features); } if (_internal_cmdln == TRUE) { cmd_ln_free(); } _decoder->ld_state = LD_STATE_FINISHED; return rv; }
int main (int argc, char *argv[]) { int i; int ret; // BEGIN NEW CODE server *fake_serv; GIOChannel *channel; session *sess; // END NEW CODE #ifdef WIN32 HRESULT coinit_result; #endif srand ((unsigned int) time (NULL)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 2) { for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0) && i + 1 < argc) { xdir = g_strdup (argv[i + 1]); } else if (strncmp (argv[i], "--cfgdir=", 9) == 0) { xdir = g_strdup (argv[i] + 9); } if (xdir != NULL) { if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } break; } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) // RFM: Don't think we hit this g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ // RFM: Does nothing on *NIX set_locale (); // RFM: Parses some command line crap. Not important ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY // RFM: Not using libproxy_factory = px_proxy_factory_new(); #endif #ifdef WIN32 coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED (coinit_result)) { CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); } #endif // RFM: Inits some fe-text stuff fe_init (); // RFM: Pretty sure this just allows us to save chats... /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } // RFM: Checks if root on *NIX #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ // RFM: Loads a bunch of configure options xchat_init (); // BEGIN NEW CODE fake_serv = server_new(); fake_serv->sok = STDIN_FILENO; // fake_serv->pos = 0; //??? sess = session_new(fake_serv, "fake_sess", SESS_CHANNEL, 0); fake_serv->server_session = sess; fake_serv->front_session = sess; channel = g_io_channel_unix_new(STDIN_FILENO); g_io_add_watch(channel, G_IO_IN, (GIOFunc)server_read, fake_serv); //g_io_add_watch(channel, G_IO_IN, (GIOFunc)io_callback, fake_serv); g_io_channel_unref(channel); // END NEW CODE fe_main (); #ifdef WIN32 if (SUCCEEDED (coinit_result)) { CoUninitialize (); } #endif #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int su_serv_create(su_serv_t *psvr, const SA *saddr, socklen_t servlen, int nthread) { if (nthread <= 0) { errno = EINVAL; return -1; } psvr->fd = socket(saddr->sa_family, SOCK_DGRAM, 0); if (psvr->fd < 0) { err_ret("serv %x create failed, socket error", psvr); return -1; } if (bind(psvr->fd, saddr, servlen) < 0) { close(psvr->fd); psvr->fd = -1; return -1; } if (setfd_nonblock(psvr->fd) < 0) { close(psvr->fd); psvr->fd = -1; return -1; } memset(&psvr->servaddr, 0, sizeof(SAUN)); memcpy(&psvr->servaddr, saddr, servlen); psvr->servlen = servlen; psvr->seq = 0; psvr->rttinit = 0; psvr->retry = RTT_MAXNREXMT; psvr->ackwaitnum = 0; list_init(&psvr->ackrecvls); list_init(&psvr->synrecvls); list_init(&psvr->lsackcache); rbt_init(&psvr->rbackcache, cache_getkey, search_cache_cmp); pthread_mutex_init(&psvr->mutex, 0); pthread_mutex_init(&psvr->lock, 0); pthread_cond_init(&psvr->ackcond, 0); pthread_cond_init(&psvr->syncond, 0); pthread_mutex_init(&psvr->cachelock, 0); if (su_serv_thread_install(psvr, nthread) < 0) { pthread_mutex_destroy(&psvr->mutex); pthread_mutex_destroy(&psvr->lock); pthread_mutex_destroy(&psvr->cachelock); pthread_cond_destroy(&psvr->ackcond); pthread_cond_destroy(&psvr->syncond); close(psvr->fd); psvr->fd = -1; return -1; } pthread_mutex_lock(&emutex); if (sugem == 0) { sugem = Em_open(100, -1, 0, 0, 0); Em_run(sugem); struct timeval now; gettimeofday(&now, 0); srand(now.tv_sec % 1000 + now.tv_usec); } psvr->sid = rand() % 65535; pthread_mutex_unlock(&emutex); memset(&psvr->fe, 0, sizeof(fe_t)); fe_init(&psvr->fe, sugem, psvr->fd); fe_set(&psvr->fe, EPOLLIN, handle_su_serv_recv); fe_set(&psvr->fe, EPOLLET, 0); Fe_em_add(&psvr->fe); return psvr->fd; }
int main (int argc, char *argv[]) { int i; int ret; #ifdef WIN32 HRESULT coinit_result; #endif srand ((unsigned int) time (NULL)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 2) { for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0) && i + 1 < argc) { xdir = g_strdup (argv[i + 1]); } else if (strncmp (argv[i], "--cfgdir=", 9) == 0) { xdir = g_strdup (argv[i] + 9); } if (xdir != NULL) { if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } break; } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif #ifdef WIN32 coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED (coinit_result)) { CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); } #endif fe_init (); /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef WIN32 if (SUCCEEDED (coinit_result)) { CoUninitialize (); } #endif #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
/********************************************************************* FUNCTION: fe_init_auto PARAMETERS: fe_t * RETURNS: nothing DESCRIPTION: automatically grab front-end parameters from command line arguments and initializes the front-end structure **********************************************************************/ fe_t * fe_init_auto() { param_t p; fe_init_params(&p); p.SAMPLING_RATE = cmd_ln_float32("-samprate"); p.FRAME_RATE = cmd_ln_int32("-frate"); p.WINDOW_LENGTH = cmd_ln_float32("-wlen"); if (strcmp("mel_scale", cmd_ln_str("-fbtype")) == 0) p.FB_TYPE = MEL_SCALE; else if (strcmp("log_linear", cmd_ln_str("-fbtype")) == 0) p.FB_TYPE = LOG_LINEAR; else { E_WARN("Invalid fbtype\n"); return NULL; } p.NUM_CEPSTRA = cmd_ln_int32("-ncep"); p.NUM_FILTERS = cmd_ln_int32("-nfilt"); p.FFT_SIZE = cmd_ln_int32("-nfft"); p.UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); p.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); p.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); if (cmd_ln_boolean("-dither")) { p.dither = 1; p.seed = cmd_ln_int32("-seed"); } else p.dither = 0; #ifdef WORDS_BIGENDIAN p.swap = strcmp("big", cmd_ln_str("-input_endian")) == 0 ? 0 : 1; #else p.swap = strcmp("little", cmd_ln_str("-input_endian")) == 0 ? 0 : 1; #endif if (cmd_ln_boolean("-logspec")) p.logspec = RAW_LOG_SPEC; if (cmd_ln_boolean("-smoothspec")) p.logspec = SMOOTH_LOG_SPEC; p.doublebw = cmd_ln_boolean("-doublebw"); p.unit_area = cmd_ln_boolean("-unit_area"); p.round_filters = cmd_ln_boolean("-round_filters"); p.remove_dc = cmd_ln_boolean("-remove_dc"); p.verbose = cmd_ln_boolean("-verbose"); if (0 == strcmp(cmd_ln_str("-transform"), "dct")) p.transform = DCT_II; else if (0 == strcmp(cmd_ln_str("-transform"), "legacy")) p.transform = LEGACY_DCT; else if (0 == strcmp(cmd_ln_str("-transform"), "htk")) p.transform = DCT_HTK; else { E_WARN("Invalid transform type (values are 'dct', 'legacy', 'htk')\n"); return NULL; } p.warp_type = cmd_ln_str("-warp_type"); p.warp_params = cmd_ln_str("-warp_params"); p.lifter_val = cmd_ln_int32("-lifter"); return fe_init(&p); }
int main (int argc, char *argv[]) { int i; int ret; #ifdef WIN32 char hexchat_lang[13]; /* LC_ALL= plus 5 chars of hex_gui_lang and trailing \0 */ #endif srand (time (0)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 3) { for (i = 1; i < argc - 1; i++) { if (strcmp (argv[i], "-d") == 0) { if (xdir) { g_free (xdir); } xdir = strdup (argv[i + 1]); if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif load_config (); #ifdef WIN32 /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ strcpy (hexchat_lang, "LC_ALL="); /* this must be ordered EXACTLY as langsmenu[] */ switch (prefs.hex_gui_lang) { case 0: strcat (hexchat_lang, "af"); break; case 1: strcat (hexchat_lang, "sq"); break; case 2: strcat (hexchat_lang, "am"); break; case 3: strcat (hexchat_lang, "ast"); break; case 4: strcat (hexchat_lang, "az"); break; case 5: strcat (hexchat_lang, "eu"); break; case 6: strcat (hexchat_lang, "be"); break; case 7: strcat (hexchat_lang, "bg"); break; case 8: strcat (hexchat_lang, "ca"); break; case 9: strcat (hexchat_lang, "zh_CN"); break; case 10: strcat (hexchat_lang, "zh_TW"); break; case 11: strcat (hexchat_lang, "cs"); break; case 12: strcat (hexchat_lang, "da"); break; case 13: strcat (hexchat_lang, "nl"); break; case 14: strcat (hexchat_lang, "en_GB"); break; case 15: strcat (hexchat_lang, "en"); break; case 16: strcat (hexchat_lang, "et"); break; case 17: strcat (hexchat_lang, "fi"); break; case 18: strcat (hexchat_lang, "fr"); break; case 19: strcat (hexchat_lang, "gl"); break; case 20: strcat (hexchat_lang, "de"); break; case 21: strcat (hexchat_lang, "el"); break; case 22: strcat (hexchat_lang, "gu"); break; case 23: strcat (hexchat_lang, "hi"); break; case 24: strcat (hexchat_lang, "hu"); break; case 25: strcat (hexchat_lang, "id"); break; case 26: strcat (hexchat_lang, "it"); break; case 27: strcat (hexchat_lang, "ja"); break; case 28: strcat (hexchat_lang, "kn"); break; case 29: strcat (hexchat_lang, "rw"); break; case 30: strcat (hexchat_lang, "ko"); break; case 31: strcat (hexchat_lang, "lv"); break; case 32: strcat (hexchat_lang, "lt"); break; case 33: strcat (hexchat_lang, "mk"); break; case 34: strcat (hexchat_lang, "ml"); break; case 35: strcat (hexchat_lang, "ms"); break; case 36: strcat (hexchat_lang, "nb"); break; case 37: strcat (hexchat_lang, "no"); break; case 38: strcat (hexchat_lang, "pl"); break; case 39: strcat (hexchat_lang, "pt"); break; case 40: strcat (hexchat_lang, "pt_BR"); break; case 41: strcat (hexchat_lang, "pa"); break; case 42: strcat (hexchat_lang, "ru"); break; case 43: strcat (hexchat_lang, "sr"); break; case 44: strcat (hexchat_lang, "sk"); break; case 45: strcat (hexchat_lang, "sl"); break; case 46: strcat (hexchat_lang, "es"); break; case 47: strcat (hexchat_lang, "sv"); break; case 48: strcat (hexchat_lang, "th"); break; case 49: strcat (hexchat_lang, "uk"); break; case 50: strcat (hexchat_lang, "vi"); break; case 51: strcat (hexchat_lang, "wa"); break; default: strcat (hexchat_lang, "en"); break; } putenv (hexchat_lang); #endif #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG hexchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main (int argc, char *argv[]) { int ret; #ifdef WIN32 char hexchat_lang[13]; /* LC_ALL= plus 5 chars of gui_lang and trailing \0 */ HANDLE mutex; #endif srand (time (0)); /* CL: do this only once! */ load_config (); #ifdef WIN32 /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ strcpy (hexchat_lang, "LC_ALL="); switch (prefs.gui_lang) { case 0: strcat (hexchat_lang, "sq"); break; case 1: strcat (hexchat_lang, "am"); break; case 2: strcat (hexchat_lang, "az"); break; case 3: strcat (hexchat_lang, "eu"); break; case 4: strcat (hexchat_lang, "be"); break; case 5: strcat (hexchat_lang, "bg"); break; case 6: strcat (hexchat_lang, "ca"); break; case 7: strcat (hexchat_lang, "zh_CN"); break; case 8: strcat (hexchat_lang, "zh_TW"); break; case 9: strcat (hexchat_lang, "cs"); break; case 10: strcat (hexchat_lang, "nl"); break; case 11: strcat (hexchat_lang, "en_GB"); break; case 12: strcat (hexchat_lang, "en_US"); break; case 13: strcat (hexchat_lang, "et"); break; case 14: strcat (hexchat_lang, "fi"); break; case 15: strcat (hexchat_lang, "fr"); break; case 16: strcat (hexchat_lang, "gl"); break; case 17: strcat (hexchat_lang, "de"); break; case 18: strcat (hexchat_lang, "el"); break; case 19: strcat (hexchat_lang, "hi"); break; case 20: strcat (hexchat_lang, "hu_HU"); break; case 21: strcat (hexchat_lang, "it"); break; case 22: strcat (hexchat_lang, "ja"); break; case 23: strcat (hexchat_lang, "kn"); break; case 24: strcat (hexchat_lang, "ko"); break; case 25: strcat (hexchat_lang, "lv"); break; case 26: strcat (hexchat_lang, "lt"); break; case 27: strcat (hexchat_lang, "mk"); break; case 28: strcat (hexchat_lang, "ms"); break; case 29: strcat (hexchat_lang, "nb"); break; case 30: strcat (hexchat_lang, "no"); break; case 31: strcat (hexchat_lang, "pl"); break; case 32: strcat (hexchat_lang, "pt"); break; case 33: strcat (hexchat_lang, "pt_BR"); break; case 34: strcat (hexchat_lang, "pa"); break; case 35: strcat (hexchat_lang, "ru"); break; case 36: strcat (hexchat_lang, "sr"); break; case 37: strcat (hexchat_lang, "sk"); break; case 38: strcat (hexchat_lang, "sl"); break; case 39: strcat (hexchat_lang, "es"); break; case 40: strcat (hexchat_lang, "sv"); break; case 41: strcat (hexchat_lang, "th"); break; case 42: strcat (hexchat_lang, "uk"); break; case 43: strcat (hexchat_lang, "vi"); break; case 44: strcat (hexchat_lang, "wa"); break; default: strcat (hexchat_lang, "en_US"); break; } putenv (hexchat_lang); if (prefs.gui_one_instance && !portable_mode ()) { DWORD error; mutex = CreateMutex (NULL, TRUE, "Local\\hexchat"); error = GetLastError (); if (error == ERROR_ALREADY_EXISTS || mutex == NULL) { /* restoring the XChat window from the tray via the taskbar icon * only works correctly when X-Tray is used, but it's not a big deal * since you can only minimize XChat to tray via the taskbar if you * use X-Tray*/ if (hextray_mode ()) { /* FindWindow() doesn't support wildcards so we check all the open windows */ EnumWindows (enum_windows_impl, NULL); return 0; } else { return 1; } } } #endif #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS xchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG xchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); if (prefs.gui_one_instance && !portable_mode ()) { ReleaseMutex (mutex); CloseHandle (mutex); } #endif return 0; }
int su_peer_create_bind(su_peer_t *psar, int port, const SA *destaddr, socklen_t destlen) { psar->fd = socket(destaddr->sa_family, SOCK_DGRAM, 0); if (psar->fd < 0) { err_ret("peer %x create failed, socket error", psar); return -1; } if (port > 0 && port <= 65535) { void *paddr; SA4 s4; SA6 s6; switch (destaddr->sa_family) { case PF_INET: memcpy(&s4, destaddr, destlen); /* for sin_family and more... */ s4.sin_port = htons(port); inet_pton(PF_INET, "0.0.0.0", &s4.sin_addr.s_addr); paddr = &s4; break; case PF_INET6: memcpy(&s6, destaddr, destlen); /* for sin6_family and more... */ s6.sin6_port = htons(port); inet_pton(PF_INET6, "::", &s6.sin6_addr.__in6_u); paddr = &s6; break; default: close(psar->fd); psar->fd = -1; errno = EINVAL; return -1; } int reuse = 1; if (setsockopt(psar->fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)) < 0) { close(psar->fd); psar->fd = -1; return -1; } if (bind(psar->fd, paddr, destlen) < 0) { close(psar->fd); psar->fd = -1; return -1; } } if (setfd_nonblock(psar->fd) < 0) { close(psar->fd); psar->fd = -1; return -1; } memset(&psar->destaddr, 0, sizeof(SAUN)); memcpy(&psar->destaddr, destaddr, destlen); psar->destlen = destlen; psar->seq = 0; psar->rttinit = 0; psar->retry = RTT_MAXNREXMT; psar->ackwaitnum = 0; list_init(&psar->ackrecvls); list_init(&psar->synrecvls); list_init(&psar->lsackcache); rbt_init(&psar->rbackcache, cache_getkey, search_cache_cmp); psar->nowsynframe = 0; pthread_mutex_init(&psar->mutex, 0); pthread_mutex_init(&psar->lock, 0); pthread_cond_init(&psar->ackcond, 0); pthread_cond_init(&psar->syncond, 0); pthread_mutex_init(&psar->cachelock, 0); if (su_peer_thread_install(psar) < 0) { pthread_mutex_destroy(&psar->mutex); pthread_mutex_destroy(&psar->lock); pthread_cond_destroy(&psar->ackcond); pthread_cond_destroy(&psar->syncond); pthread_mutex_destroy(&psar->cachelock); close(psar->fd); psar->fd = -1; return -1; } pthread_mutex_lock(&emutex); if (sugem == 0) { sugem = Em_open(100, -1, 0, 0, 0); Em_run(sugem, 1); struct timeval now; gettimeofday(&now, 0); srand(now.tv_sec % 1000 + now.tv_usec); } psar->sid = rand() % 65535; pthread_mutex_unlock(&emutex); memset(&psar->fe, 0, sizeof(fe_t)); fe_init(&psar->fe, sugem, psar->fd); fe_set(&psar->fe, EPOLLIN, handle_su_peer_recv); fe_set(&psar->fe, EPOLLET, 0); Fe_em_add(&psar->fe); return psar->fd; }