int main(int argc, char *argv[]) { char *host=NULL; char *fname=NULL; int port=SERVER_PORT; int rval=-1,i; int size; int volume=100; __u8 *buf; int iact=0; struct sigaction act; /* Assign sig_term as our SIGTERM handler */ act.sa_sigaction = sig_action; sigemptyset(&act.sa_mask); // no other signals are blocked act.sa_flags = SA_SIGINFO; // use sa_sigaction instead of sa_handler sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); sigaction(SIGCHLD, &act, NULL); for(i=1;i<argc;i++){ if(!strcmp(argv[i],"-i")){ iact=1; continue; } if(!strcmp(argv[i],"--port")){ port=atoi(argv[++i]); continue; } if(!strcmp(argv[i],"--vol")){ volume=atoi(argv[++i]); continue; } if(!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h")) return print_usage(argv); if(!host) {host=argv[i]; continue;} if(!fname) {fname=argv[i]; continue;} } if(!host) return print_usage(argv); if(!iact && !fname) return print_usage(argv); raopld=(raopld_t*)malloc(sizeof(raopld_t)); if(!raopld) goto erexit; memset(raopld,0,sizeof(raopld_t)); for(i=0;i<MAX_NUM_OF_FDS;i++) raopld->fds[i].fd=-1; raopld->raopcl=raopcl_open(); if(!raopld->raopcl) goto erexit; if(raopcl_connect(raopld->raopcl,host,port)) goto erexit; if(raopcl_update_volume(raopld->raopcl,volume)) goto erexit; printf("%s\n",RAOP_CONNECTED); fflush(stdout); if(fname && !(raopld->auds=auds_open(fname,0))) goto erexit; set_fd_event(0,RAOP_FD_READ,console_read,NULL); rval=0; while(!rval){ if(!raopld->auds){ // if audio data is not opened, just check events rval=main_event_handler(raopld); continue; } switch(raopcl_get_pause(raopld->raopcl)){ case OP_PAUSE: rval=main_event_handler(); continue; case NODATA_PAUSE: if(auds_poll_next_sample(raopld->auds)){ raopcl_set_pause(raopld->raopcl,NO_PAUSE); }else{ rval=main_event_handler(); continue; } case NO_PAUSE: if(!auds_poll_next_sample(raopld->auds)){ // no next data, turn into pause status raopcl_set_pause(raopld->raopcl,NODATA_PAUSE); continue; } if(auds_get_next_sample(raopld->auds, &buf, &size)){ auds_close(raopld->auds); raopld->auds=NULL; raopcl_wait_songdone(raopld->raopcl,1); } if(raopcl_send_sample(raopld->raopcl,buf,size)) break; do{ if((rval=main_event_handler())) break; }while(raopld->auds && raopcl_sample_remsize(raopld->raopcl)); break; default: rval=-1; break; } } rval=raopcl_close(raopld->raopcl); erexit: if(raopld->auds) auds_close(raopld->auds); if(raopld) free(raopld); return rval; }
void event_loop() { ULONG wait, signal; BOOL shouldplay = FALSE; char *symbol = NULL; branch branchallowed = NOBRANCH; /* Obtain the window wait signal mask. */ //IIntuition->GetAttr( WINDOW_SigMask, MainWinObj, &signal ); /* Input Event Loop */ while( !done ) { signal = obtain_all_signals(); wait = IExec->Wait(signal|SIGBREAKF_CTRL_C|SIGF_CHILD); if (wait & SIGBREAKF_CTRL_C) done = TRUE; if(wait & debug_sigfield) { //console_printf(OUTPUT_SYSTEM, "SIG from debug hook\n"); //console_printf(OUTPUT_SYSTEM, "traptype = 0x%08x\n", *((uint32 *)debug_hook.h_Data)); button_set_continue(); BOOL crashed = FALSE; uint32 traptype = *((uint32 *)debug_hook.h_Data); if(traptype != 0x700 && traptype != 0xd00) { catch_sline = FALSE; should_continue = FALSE; console_printf(OUTPUT_WARNING, "Your program has crashed! ip = 0x%x", context_copy.ip); } BOOL tracing = FALSE; //signal from debugger means TRAP task_playing = FALSE; suspend_all_breakpoints(); if(stepping_out) { stepping_out = FALSE; stepout_remove(); } if (asm_trace) { asmstep_remove(); if(!should_continue && !stepping_over) { switch(is_branch_allowed()) { case DISALLOWEDBRANCH: if(catch_sline) { stepping_out = TRUE; stepout_install(); shouldplay = TRUE; } else { //console_printf(OUTPUT_WARNING, "Branch into new area not allowed!"); enable(TRUE, GAD_STEPOUT_BUTTON, TAG_END); enable(FALSE, GAD_STEPINTO_BUTTON, GAD_STEPOVER_BUTTON, GAD_DISASSEMBLER_STEP_BUTTON, TAG_END); } catch_sline = FALSE; stepping_over = FALSE; break; case DISALLOWEDBRANCHCOND: if(catch_sline) { stepping_out = TRUE; stepout_install(); shouldplay = TRUE; } else { //console_printf(OUTPUT_WARNING, "Branch into new area not allowed!"); enable(TRUE, GAD_STEPOVER_BUTTON, GAD_STEPOUT_BUTTON, TAG_END); enable(FALSE, GAD_STEPINTO_BUTTON, GAD_DISASSEMBLER_STEP_BUTTON, TAG_END); } catch_sline = FALSE; stepping_over = FALSE; break; default: break; } } tracing = TRUE; if(!should_continue && !catch_sline) { disassembler_makelist(); variables_update(); source_update(); } } if (should_continue) { install_all_breakpoints(); shouldplay = TRUE; should_continue = FALSE; } else { current_function = stabs_get_function_from_address (context_copy.ip); if (current_function) hasfunctioncontext = TRUE; else if(!stepping_over && try_import_segment(context_copy.ip) > 0) { current_function = stabs_get_function_from_address(context_copy.ip); if(current_function) hasfunctioncontext = TRUE; else hasfunctioncontext = FALSE; } else hasfunctioncontext = FALSE; if (hasfunctioncontext) { //dprintf("current_function == %s\n", current_function->name); //if(stepover_func) // dprintf("stepover_func == %s\n", stepover_func->name); int nline = get_nline_from_address (context_copy.ip); if(nline >= 0) { if(stepping_over) { if(current_function == stepover_func && current_function->line[nline].infile != current_function->line[current_function->currentline].infile) { catch_sline = FALSE; stepping_over = FALSE; current_function->currentline = nline; } } else { catch_sline = FALSE; current_function->currentline = nline; } } else if (!catch_sline) { nline = guess_line_in_function(); if(nline) current_function->currentline = nline; } else if (!tracing) { console_printf(OUTPUT_WARNING, "Function overload error!"); //printf("function size: 0x%x function address: 0x%x\n", current_function->size, current_function->address); } } else if(!stepping_over && (symbol = get_symbol_from_value(context_copy.ip))) { console_printf(OUTPUT_NORMAL, "At symbol %s: 0x%x", symbol, context_copy.ip); if(catch_sline) { catch_sline = FALSE; enable(TRUE, GAD_START_BUTTON, GAD_STEPINTO_BUTTON, GAD_STEPOUT_BUTTON, GAD_DISASSEMBLER_STEP_BUTTON, TAG_END); enable(FALSE, GAD_PAUSE_BUTTON, GAD_STEPOVER_BUTTON, TAG_END); } source_update(); variables_update(); stacktrace_update(); disassembler_makelist(); show_disassembler(); } else if(!stepping_over && !tracing) { console_printf(OUTPUT_WARNING, "Program has stopped at an unknown point in memory (TRAP)"); disassembler_makelist(); variables_update(); stacktrace_update(); show_disassembler(); } if(catch_sline) { if(stepping_over && get_branched_function() != current_function) asmstep_nobranch(); else asmstep(); } else if(hasfunctioncontext) { if (current_function != old_function) output_functionheader(); old_function = current_function; enable(TRUE, GAD_START_BUTTON, GAD_STEPOVER_BUTTON, GAD_STEPINTO_BUTTON, GAD_STEPOUT_BUTTON, GAD_KILL_BUTTON, TAG_END); enable(FALSE, GAD_PAUSE_BUTTON, GAD_SELECT_BUTTON, TAG_END); remove_line_breakpoints(); variables_update(); stacktrace_update(); disassembler_makelist(); source_update(); if(!tracing) show_source(); } } } if(wait & SIGF_CHILD) { task_exists = FALSE; task_playing = FALSE; should_continue = FALSE; asm_trace = FALSE; hasfunctioncontext = FALSE; current_function = NULL; breakpoints_installed = FALSE; enable(TRUE, GAD_RELOAD_BUTTON, GAD_SELECT_BUTTON, TAG_END); enable(FALSE, GAD_START_BUTTON, GAD_PAUSE_BUTTON, GAD_STEPOVER_BUTTON, GAD_STEPINTO_BUTTON, GAD_KILL_BUTTON, GAD_SETBREAK_BUTTON, GAD_FILENAME_STRING, GAD_HEX_BUTTON, TAG_END); button_set_start(); IIntuition->RefreshGadgets ((struct Gadget *)MainObj[GAD_FILENAME_STRING], mainwin, NULL); close_all_elfhandles(); free_symbols(); stabs_free_stabs(); free_breakpoints(); //tracking_clear(); modules_close_window(); hex_close_window(); variables_clear(); source_clear(); sourcelist_clear(); stacktrace_clear(); disassembler_clear(); console_printf(OUTPUT_SYSTEM, "Program has ended"); } if (wait & main_obtain_window_signal()) { main_event_handler(); } if (wait & hex_obtain_window_signal()) { hex_event_handler(); } if (wait & breakpoints_obtain_window_signal()) { breakpoints_event_handler(); } if (wait & sigwin_obtain_signal()) { sigwin_event_handler(); } if(wait & import_obtain_window_signal()) { import_event_handler(); } if(wait & arexx_obtain_signal()) { arexx_event_handler(); } if(wait & pipe_obtain_signal()) { char buffer[1024]; int len = pipe_read(buffer); console_write_raw_data(OUTPUT_FROM_EXECUTABLE, buffer, len); } if (shouldplay) { play(); task_playing = TRUE; } shouldplay = FALSE; } return; }