int bg_upnp_device_create_common(bg_upnp_device_t * dev) { int i; /* Set the device pointers in the servives */ for(i = 0; i < dev->num_services; i++) dev->services[i].dev = dev; create_ssdp(dev); create_description(dev); return 1; }
spmat_hyb( const command_queue &queue, int n, int m, const row_t *row_begin, const col_t *col_begin, const val_t *val_begin ) : handle( cusparse_handle(queue) ), desc ( create_description(), detail::deleter() ), mat ( create_matrix(), detail::deleter() ) { cuda_check( cusparseSetMatType(desc.get(), CUSPARSE_MATRIX_TYPE_GENERAL) ); cuda_check( cusparseSetMatIndexBase(desc.get(), CUSPARSE_INDEX_BASE_ZERO) ); fill_matrix(queue, n, m, row_begin, col_begin, val_begin); }
spmat_crs( const command_queue &queue, int n, int m, const row_t *row_begin, const col_t *col_begin, const val_t *val_begin ) : n(n), m(m), nnz(static_cast<unsigned>(row_begin[n] - row_begin[0])), handle( cusparse_handle(queue) ), desc ( create_description(), detail::deleter() ), row(queue, n+1, row_begin), col(queue, nnz, col_begin + row_begin[0]), val(queue, nnz, val_begin + row_begin[0]) { if (row_begin[0] != 0) vector<int>(queue, row) -= row_begin[0]; cuda_check( cusparseSetMatType(desc.get(), CUSPARSE_MATRIX_TYPE_GENERAL) ); cuda_check( cusparseSetMatIndexBase(desc.get(), CUSPARSE_INDEX_BASE_ZERO) ); }
static const char* parse_search_results(roadmap_result* rc, int NumParams, const char* pData) { //Expected data: // VenueList,<id>,<name>,<address>,<crossstreet>,<city>,<state>,<zip>,<geolat>,<geolong>,<phone>,<distance>[,<id>,.....] FoursquareVenue venue; int i; char CommandName[128]; int iBufferSize; double dValue; int count; iBufferSize = 128; if (NumParams == 0) return pData; if ((NumParams - 1) % ROADMAP_FOURSQUARE_VENUE_ENTRIES != 0) { (*rc) = err_parser_unexpected_data; return NULL; } pData = ExtractNetworkString( pData, // [in] Source string CommandName,// [out] Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",\r\n", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if (strcmp(CommandName, "VenueList") != 0) { roadmap_log(ROADMAP_ERROR, "Foursquare - parse_search_results(): could not find command: VenueList (received: '%s')", CommandName); (*rc) = err_parser_unexpected_data; return NULL; } count = (NumParams - 1) / ROADMAP_FOURSQUARE_VENUE_ENTRIES; if (!(*pData) || count == 0) { roadmap_log(ROADMAP_DEBUG, "Foursquare - received empty venues list"); ssd_dialog_hide_all(dec_close); #ifdef IPHONE_NATIVE roadmap_main_show_root(1); #endif //IPHONE_NATIVE roadmap_messagebox_timeout("Foursquare", "We can't find anything nearby.", 5); return pData; } for (i = 0; i < count; ++i){ // 1. id iBufferSize = ROADMAP_FOURSQUARE_ID_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sId, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue id=%s", venue.sId); (*rc) = err_parser_unexpected_data; return NULL; } // 2. name iBufferSize = ROADMAP_FOURSQUARE_NAME_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sName, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue name=%s", venue.sName); (*rc) = err_parser_unexpected_data; return NULL; } // 3. address iBufferSize = ROADMAP_FOURSQUARE_ADDRESS_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sAddress, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue address=%s", venue.sAddress); (*rc) = err_parser_unexpected_data; return NULL; } // 4. crossstreet iBufferSize = ROADMAP_FOURSQUARE_CROSS_STREET_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sCrossStreet, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue crossname=%s", venue.sCrossStreet); (*rc) = err_parser_unexpected_data; return NULL; } // 5. city iBufferSize = ROADMAP_FOURSQUARE_CITY_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sCity, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue city=%s", venue.sCity); (*rc) = err_parser_unexpected_data; return NULL; } // 6. state iBufferSize = ROADMAP_FOURSQUARE_STATE_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sState, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue state=%s", venue.sState); (*rc) = err_parser_unexpected_data; return NULL; } // 7. zip iBufferSize = ROADMAP_FOURSQUARE_ZIP_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sZip, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue zip=%s", venue.sZip); (*rc) = err_parser_unexpected_data; return NULL; } // 8. lat pData = ReadDoubleFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &dValue, // [out] Output value 1); // [in] TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n' venue.iLatitude = (int) (dValue * 1000000); if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue lat=%d", venue.iLatitude); (*rc) = err_parser_unexpected_data; return NULL; } // 9. lon pData = ReadDoubleFromString( pData, // [in] Source string ",", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &dValue, // [out] Output value 1); // [in] TRIM_ALL_CHARS, DO_NOT_TRIM, or 'n' venue.iLongitude = (int) (dValue * 1000000); if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue lon=%d", venue.iLongitude); (*rc) = err_parser_unexpected_data; return NULL; } // 10. phone iBufferSize = ROADMAP_FOURSQUARE_PHONE_MAX_SIZE; pData = ExtractNetworkString( pData, // [in] Source string venue.sPhone, // [out,opt]Output buffer &iBufferSize, // [in,out] Buffer size / Size of extracted string ",", // [in] Array of chars to terminate the copy operation 1); // [in] Remove additional termination chars if( !pData || !(*pData)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue phone=%s", venue.sPhone); (*rc) = err_parser_unexpected_data; return NULL; } // 11. distance pData = ReadIntFromString( pData, // [in] Source string ",\r\n", // [in,opt] Value termination NULL, // [in,opt] Allowed padding &venue.iDistance, // [out] Put it here 1); // [in] Remove additional termination CHARS if( !pData || (!(*pData) && i < count-1)) { roadmap_log( ROADMAP_ERROR, "Foursquare - parse_search_results(): Failed to read venue distance=%d", venue.iDistance); (*rc) = err_parser_unexpected_data; return NULL; } if (gsVenuesCount < ROADMAP_FOURSQUARE_MAX_VENUE_COUNT) { //skip if more venues received create_description (&venue); gsVenuesList[gsVenuesCount++] = venue; } } roadmap_main_set_periodic(100,roadmap_foursquare_venues_list); return pData; }
static gchar* passphrase_mbox(const gchar *uid_hint, const gchar *pass_hint, gint prev_bad) { gchar *the_passphrase = NULL; GtkWidget *vbox; GtkWidget *confirm_box; GtkWidget *window; GtkWidget *pass_entry; GtkWidget *ok_button; GtkWidget *cancel_button; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), _("Passphrase")); gtk_widget_set_size_request(window, 450, -1); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_modal(GTK_WINDOW(window), TRUE); gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(passphrase_deleted), NULL); g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(passphrase_key_pressed), NULL); MANAGE_WINDOW_SIGNALS_CONNECT(window); manage_window_set_transient(GTK_WINDOW(window)); vbox = gtk_vbox_new(FALSE, 8); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); if (uid_hint || pass_hint) { GtkWidget *label; label = create_description (uid_hint, pass_hint, prev_bad); gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0); } pass_entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(vbox), pass_entry, FALSE, FALSE, 0); gtk_entry_set_visibility(GTK_ENTRY(pass_entry), FALSE); gtk_widget_grab_focus(pass_entry); gtkut_stock_button_set_create(&confirm_box, &ok_button, GTK_STOCK_OK, &cancel_button, GTK_STOCK_CANCEL, NULL, NULL); gtk_box_pack_end(GTK_BOX(vbox), confirm_box, FALSE, FALSE, 0); gtk_widget_grab_default(ok_button); g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(passphrase_ok_cb), NULL); g_signal_connect(G_OBJECT(pass_entry), "activate", G_CALLBACK(passphrase_ok_cb), NULL); g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(passphrase_cancel_cb), NULL); gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER); if (grab_all) gtk_window_set_policy (GTK_WINDOW(window), FALSE, FALSE, TRUE); gtk_widget_show_all(window); if (grab_all) { /* make sure that window is viewable * FIXME: this is still not enough */ gtk_widget_show_now(window); gdk_flush(); #ifdef GDK_WINDOWING_X11 gdk_x11_display_grab(gdk_display_get_default()); #endif /* GDK_WINDOWING_X11 */ if (gdk_pointer_grab(window->window, TRUE, 0, window->window, NULL, GDK_CURRENT_TIME)) { #ifdef GDK_WINDOWING_X11 gdk_x11_display_ungrab(gdk_display_get_default()); #endif /* GDK_WINDOWING_X11 */ g_warning("OOPS: Could not grab mouse\n"); gtk_widget_destroy(window); return NULL; } if (gdk_keyboard_grab(window->window, FALSE, GDK_CURRENT_TIME)) { gdk_display_pointer_ungrab(gdk_display_get_default(), GDK_CURRENT_TIME); #ifdef GDK_WINDOWING_X11 gdk_x11_display_ungrab(gdk_display_get_default()); #endif /* GDK_WINDOWING_X11 */ g_warning("OOPS: Could not grab keyboard\n"); gtk_widget_destroy(window); return NULL; } } gtk_main(); if (grab_all) { gdk_display_keyboard_ungrab(gdk_display_get_default(), GDK_CURRENT_TIME); gdk_display_pointer_ungrab(gdk_display_get_default(), GDK_CURRENT_TIME); #ifdef GDK_WINDOWING_X11 gdk_x11_display_ungrab(gdk_display_get_default()); #endif /* GDK_WINDOWING_X11 */ gdk_flush(); } manage_window_focus_out(window, NULL, NULL); if (pass_ack) { const gchar *entry_text; entry_text = gtk_entry_get_text(GTK_ENTRY(pass_entry)); the_passphrase = g_locale_from_utf8(entry_text, -1, NULL, NULL, NULL); if (!the_passphrase) the_passphrase = g_strdup(entry_text); } gtk_widget_destroy(window); return the_passphrase; }
void print_intel_caches(struct cpu_regs_t *regs, const struct cpu_signature_t *sig) { uint8_t buf[16], i; /* It's only possible to have 16 entries on a single line, but we need a 17th for a sentinel value of zero. */ char *entries[17]; char **eptr = entries; /* Only zero last element. All other entries are initialized below. */ entries[16] = 0; memset(buf, 0, sizeof(buf)); *(uint32_t *)&buf[0x0] = regs->eax >> 8; if ((regs->ebx & (1 << 31)) == 0) *(uint32_t *)&buf[0x3] = regs->ebx; if ((regs->ecx & (1 << 31)) == 0) *(uint32_t *)&buf[0x7] = regs->ecx; if ((regs->edx & (1 << 31)) == 0) *(uint32_t *)&buf[0xB] = regs->edx; for (i = 0; i < 0xF; i++) { char *desc = NULL; const struct cache_desc_index_t *d; if (buf[i] == 0) continue; for(d = descs; d->descriptor; d++) { if (d->descriptor == buf[i]) break; } if (d->descriptor) desc = create_description(d); /* Fetch a description. */ if (desc) { *eptr++ = desc; } else { if (buf[i] == 0x49) { /* A very stupid special case. AP-485 says this * is a L3 cache for Intel Xeon processor MP, * Family 0Fh, Model 06h, while it's a L2 cache * on everything else. */ *eptr++ = (sig->family == 0x0F && sig->model == 0x06) ? create_description(&descriptor_49[1]) : create_description(&descriptor_49[0]); } else if (buf[i] != 0x00) { /* This one we can just print right away. Its exact string will vary, and we wouldn't know how to sort it anyway. */ printf(" Unknown cache descriptor (0x%02x)\n", buf[i]); } } } i = eptr - entries; for(; eptr < &entries[17]; eptr++) { *eptr = 0; } /* Sort alphabetically. Makes it a heck of a lot easier to read. */ qsort(entries, i, sizeof(const char *), entry_comparator); /* Print the entries. */ eptr = entries; while (*eptr) { printf(" %s\n", *eptr); free(*eptr); eptr++; } }
static gchar* passphrase_mbox (const gchar *desc) { gchar *the_passphrase = NULL; GtkWidget *vbox; GtkWidget *table; GtkWidget *pass_label; GtkWidget *confirm_box; GtkWidget *window; GtkWidget *pass_entry; GtkWidget *ok_button; GtkWidget *cancel_button; window = gtk_window_new(GTK_WINDOW_DIALOG); gtk_window_set_title(GTK_WINDOW(window), _("Passphrase")); gtk_widget_set_usize(window, 450, -1); gtk_container_set_border_width(GTK_CONTAINER(window), 4); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_modal(GTK_WINDOW(window), TRUE); gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(passphrase_deleted), NULL); gtk_signal_connect(GTK_OBJECT(window), "key_press_event", GTK_SIGNAL_FUNC(passphrase_key_pressed), NULL); MANAGE_WINDOW_SIGNALS_CONNECT(window); manage_window_set_transient(GTK_WINDOW(window)); vbox = gtk_vbox_new(FALSE, 8); gtk_container_add(GTK_CONTAINER(window), vbox); if (desc) { GtkWidget *label; label = create_description (desc); gtk_box_pack_start (GTK_BOX(vbox), label, TRUE, TRUE, 0); } table = gtk_table_new(2, 2, FALSE); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(table), 8); gtk_table_set_row_spacings(GTK_TABLE(table), 12); gtk_table_set_col_spacings(GTK_TABLE(table), 8); pass_label = gtk_label_new(""); gtk_table_attach (GTK_TABLE(table), pass_label, 0, 1, 0, 1, GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0); gtk_misc_set_alignment (GTK_MISC (pass_label), 1, 0.5); pass_entry = gtk_entry_new(); gtk_table_attach (GTK_TABLE(table), pass_entry, 1, 2, 0, 1, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); gtk_entry_set_visibility (GTK_ENTRY(pass_entry), FALSE); gtk_widget_grab_focus (pass_entry); confirm_box = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX(confirm_box), GTK_BUTTONBOX_END); gtk_button_box_set_spacing (GTK_BUTTON_BOX(confirm_box), 5); ok_button = gtk_button_new_with_label (_("OK")); GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT); gtk_box_pack_start (GTK_BOX(confirm_box), ok_button, TRUE, TRUE, 0); cancel_button = gtk_button_new_with_label (_("Cancel")); GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT); gtk_box_pack_start(GTK_BOX(confirm_box), cancel_button, TRUE, TRUE, 0); gtk_box_pack_end(GTK_BOX(vbox), confirm_box, FALSE, FALSE, 0); gtk_widget_grab_default (ok_button); gtk_signal_connect(GTK_OBJECT(ok_button), "clicked", GTK_SIGNAL_FUNC(passphrase_ok_cb), NULL); gtk_signal_connect(GTK_OBJECT(pass_entry), "activate", GTK_SIGNAL_FUNC(passphrase_ok_cb), NULL); gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked", GTK_SIGNAL_FUNC(passphrase_cancel_cb), NULL); if (grab_all) gtk_object_set (GTK_OBJECT(window), "type", GTK_WINDOW_POPUP, NULL); gtk_window_set_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER); if (grab_all) gtk_window_set_policy (GTK_WINDOW(window), FALSE, FALSE, TRUE); gtk_widget_show_all(window); /* don't use XIM on entering passphrase */ gtkut_editable_disable_im(GTK_EDITABLE(pass_entry)); if (grab_all) { XGrabServer(GDK_DISPLAY()); if ( gdk_pointer_grab ( window->window, TRUE, 0, NULL, NULL, GDK_CURRENT_TIME)) { XUngrabServer ( GDK_DISPLAY() ); g_warning ("OOPS: Could not grab mouse\n"); gtk_widget_destroy (window); return NULL; } if ( gdk_keyboard_grab( window->window, FALSE, GDK_CURRENT_TIME )) { gdk_pointer_ungrab (GDK_CURRENT_TIME); XUngrabServer ( GDK_DISPLAY() ); g_warning ("OOPS: Could not grab keyboard\n"); gtk_widget_destroy (window); return NULL; } } gtk_main(); if (grab_all) { XUngrabServer (GDK_DISPLAY()); gdk_pointer_ungrab (GDK_CURRENT_TIME); gdk_keyboard_ungrab (GDK_CURRENT_TIME); gdk_flush(); } manage_window_focus_out(window, NULL, NULL); if (pass_ack) { the_passphrase = gtk_entry_get_text(GTK_ENTRY(pass_entry)); if (the_passphrase) /* Hmmm: Do we really need this? */ the_passphrase = g_strdup (the_passphrase); } gtk_widget_destroy (window); return the_passphrase; }