static void cancel_thread(GtkWidget *widget, gpointer *data) { LOG(LOG_DEBUG, "IN : cancel_thread()"); gtk_timeout_remove(tag_timeout); gtk_grab_remove(cancel_dialog); gtk_widget_destroy(cancel_dialog); pthread_cancel(tid); thread_running = 0; cancel_dialog=NULL; label_cancel=NULL; show_result_tree(); push_message("\n"); push_message(_("Canceled")); push_message("\n"); if(search_result == NULL) push_message(_("No hit.")); LOG(LOG_DEBUG, "OUT : cancel_thread()"); }
void input_direction( int *x, int *y ) { int c = 0; *x = 0; *y = 0; while( 1 ) { c = getch(); switch( c ) { case 'h': *x = -1; return; case 'j': *y = 1; return; case 'k': *y = -1; return; case 'l': *x = 1; return; default: push_message( "Invalid input.", message_normal, 0, turn_count ); ; } } }
static EVENT_HANDLER(application_ready){ MSG msg; size_t msgLength = MAX_MESSAGE_SIZE; CHECK(CNET_read_application(&msg.dest, &msg.data, &msgLength)); //printf("Message read from application layer %s, destined for address %d\n", msg.data, msg.dest); push_message(msg, msgLength + sizeof(CnetAddr)); }
void CacheLogger::log_debug(const char *component, const char *format, ...) { va_list arg; va_start(arg, format); push_message(LL_DEBUG, component, format, arg); va_end(arg); }
void CacheLogger::log_error(const char *component, const char *format, ...) { va_list arg; va_start(arg, format); push_message(LL_ERROR, component, format, arg); va_end(arg); }
static gint watch_thread(gpointer data){ char msg[256]; //LOG(LOG_DEBUG, "IN : watch_thread()"); if(thread_running){ pthread_mutex_lock(&mutex); sprintf(msg, _("%d hit"), hit_count); if(GTK_IS_LABEL(label_match)){ gtk_label_set_text(GTK_LABEL(label_match), msg); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), search_progress); } pthread_mutex_unlock(&mutex); // LOG(LOG_DEBUG, "OUT : watch_thread() : CONTINUE"); return(1); } gtk_timeout_remove(tag_timeout); show_result_tree(); if(search_result == NULL) push_message(_("No hit.")); else { push_message(""); } // if(ebook_search_method() != SEARCH_METHOD_GREP) select_first_item(); gtk_grab_remove(cancel_dialog); gtk_widget_destroy(cancel_dialog); cancel_dialog=NULL; label_cancel=NULL; pthread_mutex_destroy(&mutex); //LOG(LOG_DEBUG, "OUT : watch_thread()"); return(0); }
int w_wait(lua_State * L) { static Event::Message m; if(instance->wait(m)) { return push_message(L, m); } return 0; }
void skynet_mq_pushst(struct skynet_mq *mq, struct skynet_message_package *pack) { struct skynet_mq expand; if (perpare_space(mq, &expand)) { skynet_free(mq->q); mq->tail = expand.tail; mq->cap = expand.cap; mq->q = expand.q; } push_message(mq, pack); }
static int vlclua_vlm_execute_command( lua_State *L ) { vlm_t **pp_vlm = (vlm_t**)luaL_checkudata( L, 1, "vlm" ); const char *psz_command = luaL_checkstring( L, 2 ); vlm_message_t *message; int i_ret; i_ret = vlm_ExecuteCommand( *pp_vlm, psz_command, &message ); lua_settop( L, 0 ); push_message( L, message ); vlm_MessageDelete( message ); return 1 + vlclua_push_ret( L, i_ret ); }
static int poll_i(lua_State * L) { static Event::Message m; while(instance->poll(m)) { int args = push_message(L, m); if(args > 0) return args; } // No pending events. return 0; }
void skynet_mq_pushmt(struct skynet_mq *mq, struct skynet_message_package *pack) { struct skynet_mq expand; if (perpare_space(mq, &expand)) { rwlock_wlock(&mq->lock); void * ptr = mq->q; if (mq->head < expand.head) { // the head changes (some one pop in another thread) between perpare_space and rwlock_wlock mq->head += mq->cap; } mq->q = expand.q; mq->cap = expand.cap; mq->tail = expand.tail; rwlock_wunlock(&mq->lock); skynet_free(ptr); } push_message(mq, pack); }
int main(void) { struct mg_server *server = mg_create_server(NULL, ev_handler); time_t current_timer = 0, last_timer = time(NULL); mg_set_option(server, "listening_port", "8080"); printf("Started on port %s\n", mg_get_option(server, "listening_port")); for (;;) { mg_poll_server(server, 100); current_timer = time(NULL); if (current_timer - last_timer > 0) { last_timer = current_timer; push_message(server, current_timer); } } mg_destroy_server(&server); return 0; }
static void search_selection() { GtkTextIter start; GtkTextIter end; gchar *text; gchar *euc_str; gint method; LOG(LOG_DEBUG, "IN : search_selection()"); gtk_text_buffer_get_selection_bounds(text_buffer, &start, &end); text = gtk_text_buffer_get_text(text_buffer, &start, &end, FALSE); if(strlen(text) == 0) return; gtk_entry_set_text(GTK_ENTRY(word_entry), text); euc_str = iconv_convert("utf-8", "euc-jp", text); method = ebook_search_method(); if(method == SEARCH_METHOD_INTERNET){ web_search(); } else if(method == SEARCH_METHOD_GREP){ clear_message(); grep_search(euc_str); } else { clear_message(); ebook_search(euc_str, method); if(search_result == NULL) push_message(_("No hit.")); } save_word_history(text); gtk_editable_select_region(GTK_EDITABLE(word_entry), 0, GTK_ENTRY(word_entry)->text_length); // show_result_tree(); g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selection()"); }
static DBusMessage *map_push_message(DBusConnection *connection, DBusMessage *message, void *user_data) { struct map_data *map = user_data; char *filename; char *folder; GObexApparam *apparam; DBusMessageIter args; dbus_message_iter_init(message, &args); if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); dbus_message_iter_get_basic(&args, &filename); dbus_message_iter_next(&args); if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) { return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); } dbus_message_iter_get_basic(&args, &folder); dbus_message_iter_next(&args); apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_CHARSET, CHARSET_UTF8); if (parse_push_options(apparam, &args) == NULL) { g_obex_apparam_free(apparam); return g_dbus_create_error(message, ERROR_INTERFACE ".InvalidArguments", NULL); } return push_message(map, message, filename, folder, apparam); }
static void push_message( lua_State *L, vlm_message_t *message ) { lua_createtable( L, 0, 2 ); lua_pushstring( L, message->psz_name ); lua_setfield( L, -2, "name" ); if( message->i_child > 0 ) { int i; lua_createtable( L, message->i_child, 0 ); for( i = 0; i < message->i_child; i++ ) { lua_pushinteger( L, i+1 ); push_message( L, message->child[i] ); lua_settable( L, -3 ); } lua_setfield( L, -2, "children" ); } if ( message->psz_value ) { lua_pushstring( L, message->psz_value ); lua_setfield( L, -2, "value" ); } }
int melee_attack( entity_t *atk, entity_t *def ) { if( !atk->in_hand ) { if( atk == player ) { buf_t *msg = bufprintf( "You %s the %s.", atk->natural->attack_name, def->name->data ); push_message( msg ); bufdestroy( msg ); } else if( def == player ) { buf_t *msg = bufprintf( "The %s %ss you.", atk->name->data, atk->natural->attack_name ); push_message( msg ); bufdestroy( msg ); } take_damage( def, atk->natural ); return 1; } if( atk->in_hand->type != ITEMTYPE_WEAPON ) { if( atk == player ) { buf_t *msg = bufnew( "You're not wielding a weapon." ); push_message( msg ); bufdestroy( msg ); } return 0; } weapon_t *wpn = (weapon_t*)atk->in_hand->specific; if( wpn->type != WEAPONTYPE_MELEE ) { /* TODO: ranged weapons that also have melee attacks? */ if( atk == player ) { buf_t *msg = bufnew( "You're not wielding a melee weapon." ); push_message( msg ); bufdestroy( msg ); } return 0; } if( atk == player ) { buf_t *msg = bufprintf( "You hit the %s!", def->name->data ); push_message( msg ); bufdestroy( msg ); } else if( def == player ) { buf_t *msg = bufprintf( "The %s hits you!", atk->name->data ); push_message( msg ); bufdestroy( msg ); } take_damage( def, wpn ); return 1; }
void CacheLogger::vlog_error(const char *component, const char *format, va_list va) { push_message(LL_ERROR, component, format, va); }
void CacheLogger::vlog_info(const char *component, const char *format, va_list va) { push_message(LL_INFO, component, format, va); }
void CacheLogger::vlog_warn(const char *component, const char *format, va_list va) { push_message(LL_WARN, component, format, va); }
void push_action(int id, int what, int type, int tag) { push_message(id, what, type, tag, 0, 0); }
void CacheLogger::vlog_debug(const char *component, const char *format, va_list va) { push_message(LL_DEBUG, component, format, va); }
void push_detail(int id, int type, int tag, int val, int arg1) { push_message(id, ACTION_DETAIL, type, tag, val, arg1); }
void * cve_searcher (void *arg) { int i = 0, j = 0, k = 0, total = 0, count = 0, sz; char buf[20][LINE_SIZE_MAX], line[LINE_SIZE_MAX]; cve_query *cq = arg; regex_t rx; regmatch_t m[1]; FILE *f = fopen ("./allitems.txt", "r"); if (f == NULL) return; if (regcomp (&rx, cq->query, REG_ICASE | REG_EXTENDED | REG_NOSUB) != 0) { printf ("regex compilation failed!!\n"); push_message (cq->destination, "Invalid regular expression provided"); return; } if (pthread_mutex_lock (&c_lock) == 0) { printf ("Executing cve query of %s destined for %s\n", cq->query, cq->destination); while (!feof (f)) { fgets (line, LINE_SIZE_MAX, f); if (strlen (line) > 10) if (strncmp (line, DELIMITER, strlen (line)) == 0) { for (i = 0, sz = 0; i < 20 && !feof (f);) { fgets (line, LINE_SIZE_MAX, f); sz += strlen (line); if (sz > 10) if (strncmp (line, DELIMITER, sz) == 0) { for (j = 0; j < count; j++) { if (!regexec (&rx, buf[j], 1, m, 0)) { printf ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); fflush (stdout); for (i = 0; i < count; i++) { if (buf[0]) printf ("--%s", buf[0]); fflush (stdout); push_message (cq->destination, buf[i]); ++total; if (total > 50) return; } } } count = 0; goto next; } if (line) { count++; snprintf (buf[i], strlen (line), "%s", &line); ++i; } } } next: i; } } pthread_mutex_unlock (&c_lock); regfree (&rx); free (cq); }
static void search_selected(gchar *str) { gchar *euc_str; gint method; glong len; LOG(LOG_DEBUG, "IN : search_selected(%s)", str); if(selection_mode <= SELECTION_DO_NOTHING) { LOG(LOG_DEBUG, "OUT : search_selected() = NOP1"); return; } if(strcmp(previous, str) == 0){ // Do nothing if the word is the save as before. LOG(LOG_DEBUG, "same as before"); ; } else { euc_str = iconv_convert("utf-8", "euc-jp", str); if(validate_euc_str(euc_str) == FALSE) { g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selected() = INVALID"); return; } remove_space(euc_str); len = g_utf8_strlen(str, -1); if((auto_minchar <= len) && (len <= auto_maxchar)) { gtk_entry_set_text(GTK_ENTRY(word_entry), str); method = ebook_search_method(); if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_MULTI) || (method == SEARCH_METHOD_FULL_TEXT)){ LOG(LOG_DEBUG, "OUT : search_selected() = NOP2"); return; } if(selection_mode <= SELECTION_COPY_ONLY) { LOG(LOG_DEBUG, "OUT : search_selected() = COPY"); return; } clear_message(); clear_search_result(); if(method == SEARCH_METHOD_GREP){ grep_search(euc_str); show_result_tree(); select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); save_word_history(str); } else { ebook_search_auto(euc_str, method); show_result_tree(); if(search_result){ if(selection_mode == SELECTION_POPUP) { show_result_in_popup(); } else { select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); } save_word_history(str); } else { current_in_result = NULL; set_current_result(NULL); if(selection_mode == SELECTION_POPUP) { beep(); } else { if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); push_message(_("No hit.")); } } } sprintf(previous, "%s", str); } else { LOG(LOG_DEBUG, "OUT : search_selected() = LENGTH"); } g_free(euc_str); } LOG(LOG_DEBUG, "OUT : search_selected()"); }
void CacheLogger::log_debug(const char *component, Exception &e) { push_message(LL_DEBUG, component, e); }
void CacheLogger::log_warn(const char *component, Exception &e) { push_message(LL_WARN, component, e); }
void CacheLogger::log_info(const char *component, Exception &e) { push_message(LL_INFO, component, e); }
/* TODO: accuracy */ int ranged_attack( entity_t *atk, int tx, int ty ) { weapon_t *wpn; int cx = atk->x, cy = atk->y; if( !atk->in_hand ) { if( atk == player ) { buf_t *msg = bufnew( "You're not wielding anything!" ); push_message( msg ); bufdestroy( msg ); } return 0; } if( atk->in_hand->type != ITEMTYPE_WEAPON ) { if( atk == player ) { buf_t *msg = bufnew( "You're not wielding a weapon!" ); push_message( msg ); bufdestroy( msg ); } return 0; } wpn = (weapon_t*)atk->in_hand->specific; if( wpn->type != WEAPONTYPE_HANDGUN ) { if( atk == player ) { buf_t *msg = bufnew( "You're not wielding a ranged weapon!" ); push_message( msg ); bufdestroy( msg ); } return 0; } /* consume ammo */ if( wpn->ammo_loaded >= 1 ) { wpn->ammo_loaded -= 1; } else { buf_t *msg = bufnew( "The clip is empty!" ); push_message( msg ); bufdestroy( msg ); return 0; } if( atk == player ) { buf_t *msg = bufnew( "You shoot your weapon!" ); push_message( msg ); bufdestroy( msg ); } while( 1 ) { cx += tx; cy += ty; if( is_legal( cx, cy ) && ( dungeon[atk->z]->terrain[cx][cy]->flags & TILEFLAG_SOLID ) ) { /* you hit something solid */ break; } attrset( COLOR_PAIR( C_RED ) ); mvaddch( cy+2, cx, '*' ); entity_t *e = entity_find_by_position( cx, cy, atk->z ); if( e ) { buf_t *msg = bufprintf( "You hit the %s!", e->name->data ); push_message( msg ); bufdestroy( msg ); take_damage( e, wpn ); break; } } refresh(); msleep( 100 ); return 1; }
void CacheLogger::log_error(const char *component, Exception &e) { push_message(LL_ERROR, component, e); }
gpointer read_data_thread(gboolean *stop) { /* This is mostly taken straight from alsa-utils-1.0.19 amidi/amidi.c by Clemens Ladisch <*****@*****.**> */ int err; int npfds; struct pollfd *pfds; GString *string = NULL; npfds = snd_rawmidi_poll_descriptors_count(input); pfds = alloca(npfds * sizeof(struct pollfd)); snd_rawmidi_poll_descriptors(input, pfds, npfds); do { unsigned char buf[256]; int i, length; unsigned short revents; /* SysEx messages can't contain bytes with 8th bit set. memset our buffer to 0xFF, so if for some reason we'll get out of reply bounds, we'll catch it */ memset(buf, '\0', sizeof(buf)); err = poll(pfds, npfds, 200); if (err < 0 && errno == EINTR) break; if (err < 0) { g_error("poll failed: %s", strerror(errno)); break; } if ((err = snd_rawmidi_poll_descriptors_revents(input, pfds, npfds, &revents)) < 0) { g_error("cannot get poll events: %s", snd_strerror(errno)); break; } if (revents & (POLLERR | POLLHUP)) break; if (!(revents & POLLIN)) continue; err = snd_rawmidi_read(input, buf, sizeof(buf)); if (err == -EAGAIN) continue; if (err < 0) { g_error("cannot read: %s", snd_strerror(err)); break; } length = 0; for (i = 0; i < err; ++i) if ((unsigned char)buf[i] != 0xFE) /* ignore active sensing */ buf[length++] = buf[i]; i = 0; while (i < length) { int pos; int bytes; if (string == NULL) { while (buf[i] != 0xF0 && i < length) i++; } pos = i; for (bytes = 0; (bytes<length-i) && (buf[i+bytes] != 0xF7); bytes++); if (buf[i+bytes] == 0xF7) bytes++; i += bytes; if (string == NULL) string = g_string_new_len((gchar*)&buf[pos], bytes); else g_string_append_len(string, (gchar*)&buf[pos], bytes); if ((unsigned char)string->str[string->len-1] == 0xF7) { /* push message on stack */ push_message(string); string = NULL; } } } while (*stop == FALSE); if (string) { g_string_free(string, TRUE); string = NULL; } return NULL; }