/** * gst_adapter_map: * @adapter: a #GstAdapter * @size: the number of bytes to map/peek * * Gets the first @size bytes stored in the @adapter. The returned pointer is * valid until the next function is called on the adapter. * * Note that setting the returned pointer as the data of a #GstBuffer is * incorrect for general-purpose plugins. The reason is that if a downstream * element stores the buffer so that it has access to it outside of the bounds * of its chain function, the buffer will have an invalid data pointer after * your element flushes the bytes. In that case you should use * gst_adapter_take(), which returns a freshly-allocated buffer that you can set * as #GstBuffer memory or the potentially more performant * gst_adapter_take_buffer(). * * Returns %NULL if @size bytes are not available. * * Returns: (transfer none) (array length=size) (element-type guint8) (nullable): * a pointer to the first @size bytes of data, or %NULL */ gconstpointer gst_adapter_map (GstAdapter * adapter, gsize size) { GstBuffer *cur; gsize skip, csize; gsize toreuse, tocopy; guint8 *data; g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); g_return_val_if_fail (size > 0, NULL); if (adapter->info.memory) gst_adapter_unmap (adapter); /* we don't have enough data, return NULL. This is unlikely * as one usually does an _available() first instead of peeking a * random size. */ if (G_UNLIKELY (size > adapter->size)) return NULL; /* we have enough assembled data, return it */ if (adapter->assembled_len >= size) return adapter->assembled_data; #if 0 do { #endif cur = adapter->buflist->data; skip = adapter->skip; csize = gst_buffer_get_size (cur); if (csize >= size + skip) { if (!gst_buffer_map (cur, &adapter->info, GST_MAP_READ)) return FALSE; return (guint8 *) adapter->info.data + skip; } /* We may be able to efficiently merge buffers in our pool to * gather a big enough chunk to return it from the head buffer directly */ #if 0 } while (gst_adapter_try_to_merge_up (adapter, size)); #endif /* see how much data we can reuse from the assembled memory and how much * we need to copy */ toreuse = adapter->assembled_len; tocopy = size - toreuse; /* Gonna need to copy stuff out */ if (G_UNLIKELY (adapter->assembled_size < size)) { adapter->assembled_size = (size / DEFAULT_SIZE + 1) * DEFAULT_SIZE; GST_DEBUG_OBJECT (adapter, "resizing internal buffer to %" G_GSIZE_FORMAT, adapter->assembled_size); if (toreuse == 0) { GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "alloc new buffer"); /* no g_realloc to avoid a memcpy that is not desired here since we are * not going to reuse any data here */ g_free (adapter->assembled_data); adapter->assembled_data = g_malloc (adapter->assembled_size); } else { /* we are going to reuse all data, realloc then */ GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "reusing %" G_GSIZE_FORMAT " bytes", toreuse); adapter->assembled_data = g_realloc (adapter->assembled_data, adapter->assembled_size); } } GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy remaining %" G_GSIZE_FORMAT " bytes from adapter", tocopy); data = adapter->assembled_data; copy_into_unchecked (adapter, data + toreuse, skip + toreuse, tocopy); adapter->assembled_len = size; return adapter->assembled_data; }
/** * inf_tcp_connection_get_remote_address: * @connection: A #InfTcpConnection. * * Returns the IP address of the remote site. * * Returns: (transfer none): A #InfIpAddress owned by @connection. You do not * need to free it, but need to make your own copy if you want to keep it * longer than @connection's lifetime. **/ InfIpAddress* inf_tcp_connection_get_remote_address(InfTcpConnection* connection) { g_return_val_if_fail(INF_IS_TCP_CONNECTION(connection), NULL); return INF_TCP_CONNECTION_PRIVATE(connection)->remote_address; }
/** * inf_tcp_connection_get_keepalive: * @connection: A #InfTcpConnection. * * Returns the current keepalive settings for @connection. * * Returns: The current keepalive configuration for @connection, owned by * @connection. */ const InfKeepalive* inf_tcp_connection_get_keepalive(InfTcpConnection* connection) { g_return_val_if_fail(INF_IS_TCP_CONNECTION(connection), NULL); return &INF_TCP_CONNECTION_PRIVATE(connection)->keepalive; }
int gui_entry_get_pos(GUI_ENTRY_REC *entry) { g_return_val_if_fail(entry != NULL, 0); return entry->pos; }
MongoUpdateFlags mongo_message_update_get_flags (MongoMessageUpdate *update) { g_return_val_if_fail(MONGO_IS_MESSAGE_UPDATE(update), 0); return update->priv->flags; }
GnmRange const * gnm_sheet_slicer_get_range (GnmSheetSlicer const *gss) { g_return_val_if_fail (GNM_IS_SHEET_SLICER (gss), NULL); return &gss->range; }
int main(void) { ZStream *input; int pair[2], status = 0; pid_t pid; gchar *line; gsize length; if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) < 0) { perror("socketpair()"); return 254; } pid = fork(); if (pid < 0) { perror("fork()"); return 254; } else if (pid != 0) { close(pair[1]); g_return_val_if_fail(write(pair[0], "1\n2\n3\n", 6) == 6, 253); g_return_val_if_fail(write(pair[0], "0123", 4) == 4, 253); g_return_val_if_fail(write(pair[0], "4567\n", 5) == 5, 253); g_return_val_if_fail(write(pair[0], "0123456789", 10) == 10, 253); g_return_val_if_fail(write(pair[0], "abc\nAabc\nabcdef\n", 16) == 16, 253); /* Because of truncate A will be eliminated */ g_return_val_if_fail(write(pair[0], "0123456789", 10) == 10, 253); g_return_val_if_fail(write(pair[0], "0123456789", 10) == 10, 253); g_return_val_if_fail(write(pair[0], "012345678\nAabcdef\n", 18) == 18, 253); /* Because of truncate A will be eliminated */ g_return_val_if_fail(write(pair[0], "012345678\nAabcdef", 17) == 17, 253); close(pair[0]); waitpid(pid, &status, 0); } else { gint rc; guint i; printf("%d\n", getpid()); sleep(1); close(pair[0]); input = z_stream_fd_new(pair[1], "sockpair input"); input = z_stream_line_new(input, 10, ZRL_EOL_NL | ZRL_TRUNCATE); i = 0; if (!z_stream_unget(input, "A", 1, NULL)) { printf("Error on unget\n"); _exit(1); } rc = z_stream_line_get(input, &line, &length, NULL); while (rc == G_IO_STATUS_NORMAL) { if (i >= (sizeof(expected_outputs) / sizeof(gchar *)) || line[0] != 'A' || strlen(expected_outputs[i]) != length - 1 || memcmp(expected_outputs[i], line + 1, length - 1) != 0) { printf("Error checking line: [%.*s] (length: %"G_GSIZE_FORMAT"), should be: %s\n", (int) length - 1, line + 1, length - 1, expected_outputs[i]); _exit(1); } else { printf("line ok: %.*s\n", (int) length, line); } if (!z_stream_unget(input, "A", 1, NULL)) { printf("Error on unget\n"); _exit(1); } rc = z_stream_line_get(input, &line, &length, NULL); i++; } if (i < (sizeof(expected_outputs) / sizeof(gchar *))) { printf("Missing output %u of %"G_GSIZE_FORMAT"\n", i, (sizeof(expected_outputs) / sizeof(gchar *))); _exit(1); } close(pair[1]); _exit(0); } return status >> 8; }
/** * g_pattern_spec_new: * @pattern: a zero-terminated UTF-8 encoded string * * Compiles a pattern to a #GPatternSpec. * * Returns: a newly-allocated #GPatternSpec **/ GPatternSpec* g_pattern_spec_new (const gchar *pattern) { GPatternSpec *pspec; gboolean seen_joker = FALSE, seen_wildcard = FALSE, more_wildcards = FALSE; gint hw_pos = -1, tw_pos = -1, hj_pos = -1, tj_pos = -1; gboolean follows_wildcard = FALSE; guint pending_jokers = 0; const gchar *s; gchar *d; guint i; g_return_val_if_fail (pattern != NULL, NULL); /* canonicalize pattern and collect necessary stats */ pspec = g_new (GPatternSpec, 1); pspec->pattern_length = strlen (pattern); pspec->min_length = 0; pspec->max_length = 0; pspec->pattern = g_new (gchar, pspec->pattern_length + 1); d = pspec->pattern; for (i = 0, s = pattern; *s != 0; s++) { switch (*s) { case '*': if (follows_wildcard) /* compress multiple wildcards */ { pspec->pattern_length--; continue; } follows_wildcard = TRUE; if (hw_pos < 0) hw_pos = i; tw_pos = i; break; case '?': pending_jokers++; pspec->min_length++; pspec->max_length += 4; /* maximum UTF-8 character length */ continue; default: for (; pending_jokers; pending_jokers--, i++) { *d++ = '?'; if (hj_pos < 0) hj_pos = i; tj_pos = i; } follows_wildcard = FALSE; pspec->min_length++; pspec->max_length++; break; } *d++ = *s; i++; } for (; pending_jokers; pending_jokers--) { *d++ = '?'; if (hj_pos < 0) hj_pos = i; tj_pos = i; } *d++ = 0; seen_joker = hj_pos >= 0; seen_wildcard = hw_pos >= 0; more_wildcards = seen_wildcard && hw_pos != tw_pos; if (seen_wildcard) pspec->max_length = G_MAXUINT; /* special case sole head/tail wildcard or exact matches */ if (!seen_joker && !more_wildcards) { if (pspec->pattern[0] == '*') { pspec->match_type = G_MATCH_TAIL; memmove (pspec->pattern, pspec->pattern + 1, --pspec->pattern_length); pspec->pattern[pspec->pattern_length] = 0; return pspec; } if (pspec->pattern_length > 0 && pspec->pattern[pspec->pattern_length - 1] == '*') { pspec->match_type = G_MATCH_HEAD; pspec->pattern[--pspec->pattern_length] = 0; return pspec; } if (!seen_wildcard) { pspec->match_type = G_MATCH_EXACT; return pspec; } } /* now just need to distinguish between head or tail match start */ tw_pos = pspec->pattern_length - 1 - tw_pos; /* last pos to tail distance */ tj_pos = pspec->pattern_length - 1 - tj_pos; /* last pos to tail distance */ if (seen_wildcard) pspec->match_type = tw_pos > hw_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL; else /* seen_joker */ pspec->match_type = tj_pos > hj_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL; if (pspec->match_type == G_MATCH_ALL_TAIL) { gchar *tmp = pspec->pattern; pspec->pattern = g_utf8_strreverse (pspec->pattern, pspec->pattern_length); g_free (tmp); } return pspec; }
char *part_property_expand_macros (Part *part, char *string) { static char mcode[] = {"@?~#&"}; char *value; char *tmp0, *temp, *qn, *q0, *t0; char *cls1, *cls2; GString *out; size_t sln; char *ret; g_return_val_if_fail (part != NULL, NULL); g_return_val_if_fail (IS_PART (part), NULL); g_return_val_if_fail (string != NULL, NULL); cls1 = cls2 = q0 = NULL; // Rules: // @<id> value of <id>. If no value, error // &<id> value of <id> if <id> is defined // ?<id>s...s text between s...s separators if <id> defined // ?<id>s...ss...s text between 1st s...s separators if <id> defined // else 2nd s...s clause // ~<id>s...s text between s...s separators if <id> undefined // ~<id>s...ss...s text between 1st s...s separators if <id> undefined // else 2nd s...s clause // #<id>s...s text between s...s separators if <id> defined, but // delete rest of tempalte if <id> undefined // Separators can be any of (, . ; / |) For an opening-closing pair of // separators the same character ahs to be used. // Examples: R^@refdes %1 %2 @value // V^@refdes %+ %- SIN(@offset @ampl @freq 0 0) // ?DC|DC @DC| tmp0 = temp = g_strdup (string); out = g_string_new (""); for (temp = string; *temp;) { // Look for any of the macro char codes. if (strchr (mcode, *temp)) { qn = get_macro_name (temp + 1, &cls1, &cls2, &sln); if (qn == NULL) return NULL; value = part_get_property (part, qn); if ((*temp == '@' || *temp == '&') && value) { out = g_string_append (out, value); } else if (*temp == '&' && !value) { g_warning ("expand macro error: macro %s undefined", qn); g_free (qn); return NULL; } else if (*temp == '?' || *temp == '~') { if (cls1 == NULL) { g_warning ("error in template: %s", temp); g_free (qn); return NULL; } q0 = (value ? (*temp == '?' ? cls1 : cls2) : (*temp == '?' ? cls2 : cls1)); if (q0) { t0 = part_property_expand_macros (part, q0); if (!t0) { g_warning ("error in template: %s", temp); g_free (qn); } else { out = g_string_append (out, t0); g_free (t0); } } } else if (*temp == '#') { if (value) { t0 = part_property_expand_macros (part, value); if (!t0) { g_warning ("error in template: %s", temp); g_free (qn); } else { out = g_string_append (out, t0); g_free (t0); } } else *(temp + sln) = 0; } temp += 1; temp += sln; if (qn) g_free (qn); if (cls1) g_free (cls1); if (cls2) g_free (cls2); } else { if (*temp == '\\') { temp++; switch (*temp) { case 'n': out = g_string_append_c (out, '\n'); break; case 't': out = g_string_append_c (out, '\t'); break; case 'r': out = g_string_append_c (out, '\r'); break; case 'f': out = g_string_append_c (out, '\f'); } temp++; } else { out = g_string_append_c (out, *temp); temp++; } } } if (tmp0) g_free (tmp0); out = g_string_append_c (out, '\0'); ret = g_strdup (out->str); g_string_free (out, TRUE); return ret; }
GtkWidget * offset_dialog_new (GimpDrawable *drawable, GimpContext *context, GtkWidget *parent) { GimpItem *item; OffsetDialog *dialog; GtkWidget *main_vbox; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *button; GtkWidget *spinbutton; GtkWidget *frame; GtkWidget *radio_button; GtkAdjustment *adjustment; gdouble xres; gdouble yres; const gchar *title = NULL; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); dialog = g_slice_new0 (OffsetDialog); dialog->context = context; dialog->fill_type = gimp_drawable_has_alpha (drawable) | WRAP_AROUND; item = GIMP_ITEM (drawable); dialog->image = gimp_item_get_image (item); gimp_image_get_resolution (dialog->image, &xres, &yres); if (GIMP_IS_LAYER (drawable)) title = _("Offset Layer"); else if (GIMP_IS_LAYER_MASK (drawable)) title = _("Offset Layer Mask"); else if (GIMP_IS_CHANNEL (drawable)) title = _("Offset Channel"); else g_warning ("%s: unexpected drawable type", G_STRFUNC); dialog->dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (drawable), context, _("Offset"), "gimp-drawable-offset", GIMP_STOCK_TOOL_MOVE, title, parent, gimp_standard_help_func, GIMP_HELP_LAYER_OFFSET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, /* offset, used as a verb */ _("_Offset"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); g_object_weak_ref (G_OBJECT (dialog->dialog), (GWeakNotify) offset_dialog_free, dialog); g_signal_connect (dialog->dialog, "response", G_CALLBACK (offset_response), dialog); main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), main_vbox, TRUE, TRUE, 0); gtk_widget_show (main_vbox); /* The offset frame */ frame = gimp_frame_new (_("Offset")); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show (vbox); adjustment = (GtkAdjustment *) gtk_adjustment_new (1, 1, 1, 1, 10, 0); spinbutton = gtk_spin_button_new (adjustment, 1.0, 2); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10); dialog->off_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a", TRUE, TRUE, FALSE, 10, GIMP_SIZE_ENTRY_UPDATE_SIZE); gtk_table_set_col_spacing (GTK_TABLE (dialog->off_se), 0, 4); gtk_table_set_col_spacing (GTK_TABLE (dialog->off_se), 1, 4); gtk_table_set_row_spacing (GTK_TABLE (dialog->off_se), 0, 2); gimp_size_entry_add_field (GIMP_SIZE_ENTRY (dialog->off_se), GTK_SPIN_BUTTON (spinbutton), NULL); gtk_table_attach_defaults (GTK_TABLE (dialog->off_se), spinbutton, 1, 2, 0, 1); gtk_widget_show (spinbutton); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (dialog->off_se), _("_X:"), 0, 0, 0.0); gimp_size_entry_attach_label (GIMP_SIZE_ENTRY (dialog->off_se), _("_Y:"), 1, 0, 0.0); gtk_box_pack_start (GTK_BOX (vbox), dialog->off_se, FALSE, FALSE, 0); gtk_widget_show (dialog->off_se); gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (dialog->off_se), GIMP_UNIT_PIXEL); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (dialog->off_se), 0, xres, FALSE); gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (dialog->off_se), 1, yres, FALSE); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (dialog->off_se), 0, - gimp_item_get_width (item), gimp_item_get_width (item)); gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (dialog->off_se), 1, - gimp_item_get_height (item), gimp_item_get_height (item)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (dialog->off_se), 0, 0, gimp_item_get_width (item)); gimp_size_entry_set_size (GIMP_SIZE_ENTRY (dialog->off_se), 1, 0, gimp_item_get_height (item)); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dialog->off_se), 0, 0); gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (dialog->off_se), 1, 0); button = gtk_button_new_with_mnemonic (_("By width/_2, height/2")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_xy_callback), dialog); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); button = gtk_button_new_with_mnemonic ("By _width/2"); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_x_callback), dialog); button = gtk_button_new_with_mnemonic ("By _height/2"); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); gtk_widget_show (button); g_signal_connect (button, "clicked", G_CALLBACK (offset_half_y_callback), dialog); /* The edge behavior frame */ frame = gimp_int_radio_group_new (TRUE, _("Edge Behavior"), G_CALLBACK (gimp_radio_button_update), &dialog->fill_type, dialog->fill_type, _("W_rap around"), WRAP_AROUND, NULL, _("Fill with _background color"), GIMP_OFFSET_BACKGROUND, NULL, _("Make _transparent"), GIMP_OFFSET_TRANSPARENT, &radio_button, NULL); if (! gimp_drawable_has_alpha (drawable)) gtk_widget_set_sensitive (radio_button, FALSE); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_widget_show (frame); return dialog->dialog; }
/** * manager_get_daemon: * @manager: A #Manager. * * Gets the daemon used by @manager. * * Returns: A #Daemon. Do not free, the object is owned by @manager. */ Daemon * manager_get_daemon (Manager *manager) { g_return_val_if_fail (COCKPIT_IS_DAEMON_MANAGER (manager), NULL); return manager->daemon; }
GList *gui_window_find_text(WINDOW_REC *window, gchar *text, GList *startline, int regexp, int fullword) { regex_t preg; GList *tmp; GList *matches; gchar *str, *ptr; gint n, size; g_return_val_if_fail(window != NULL, NULL); g_return_val_if_fail(text != NULL, NULL); matches = NULL; size = 1024; str = g_malloc(1024); if (regcomp(&preg, text, REG_ICASE|REG_EXTENDED|REG_NOSUB) != 0) return 0; if (startline == NULL) startline = WINDOW_GUI(window)->lines; for (tmp = startline; tmp != NULL; tmp = tmp->next) { LINE_REC *rec = tmp->data; for (n = 0, ptr = rec->text; ; ptr++) { if (*ptr != 0) { if (n+2 > size) { size += 1024; str = g_realloc(str, size); } str[n++] = toupper(*ptr); } else { ptr++; if ((guchar) *ptr == LINE_CMD_CONTINUE) { gchar *tmp; memcpy(&tmp, ptr+1, sizeof(gchar *)); ptr = tmp-1; } else if ((guchar) *ptr == LINE_CMD_EOL) break; else if ((guchar) *ptr == LINE_CMD_OVERFLOW) g_error("buffer overflow! (find)"); } } str[n] = '\0'; if (regexp ? regexec(&preg, str, 0, NULL, 0) == 0 : fullword ? stristr_full(str, text) != NULL : stristr(str, text) != NULL) { /* matched */ matches = g_list_append(matches, rec); } } regfree(&preg); if (str != NULL) g_free(str); return matches; }
static LINE_CACHE_REC *gui_window_line_cache(GUI_WINDOW_REC *gui, LINE_REC *line) { LINE_CACHE_REC *rec; LINE_CACHE_SUB_REC *sub; GSList *lines; unsigned char *ptr, *last_space_ptr; int xpos, pos, indent_pos, last_space, last_color, color; g_return_val_if_fail(line->text != NULL, NULL); rec = g_new(LINE_CACHE_REC, 1); rec->last_access = time(NULL); xpos = 0; color = 0; indent_pos = DEFAULT_INDENT_POS; last_space = last_color = 0; last_space_ptr = NULL; rec->count = 1; lines = NULL; for (ptr = (unsigned char *) line->text;;) { if (*ptr == '\0') { /* command */ ptr++; if (*ptr == LINE_CMD_EOL) break; if (*ptr == LINE_CMD_CONTINUE) { unsigned char *tmp; memcpy(&tmp, ptr+1, sizeof(char *)); ptr = tmp; continue; } if ((*ptr & 0x80) == 0) { /* set color */ color = (color & ATTR_UNDERLINE) | *ptr; } else switch (*ptr) { case LINE_CMD_OVERFLOW: g_error("buffer overflow! (cache)"); case LINE_CMD_UNDERLINE: color ^= ATTR_UNDERLINE; break; case LINE_CMD_COLOR8: color &= 0xfff0; color |= 8|ATTR_COLOR8; break; case LINE_CMD_INDENT: /* set indentation position here - don't do it if we're too close to right border */ if (xpos < COLS-5) indent_pos = xpos; break; } ptr++; continue; } if (xpos == COLS) { xpos = indent_pos; if (last_space > indent_pos && last_space > 10) { /* go back to last space */ color = last_color; ptr = last_space_ptr; while (*ptr == ' ') ptr++; } sub = g_new(LINE_CACHE_SUB_REC, 1); sub->start = (char *) ptr; sub->indent = indent_pos; sub->color = color; lines = g_slist_append(lines, sub); rec->count++; last_space = 0; continue; } xpos++; if (*ptr++ == ' ') { last_space = xpos-1; last_space_ptr = ptr; last_color = color; } } if (rec->count < 2) rec->lines = NULL; else { rec->lines = g_new(LINE_CACHE_SUB_REC, rec->count-1); for (pos = 0; lines != NULL; pos++) { memcpy(&rec->lines[pos], lines->data, sizeof(LINE_CACHE_SUB_REC)); g_free(lines->data); lines = g_slist_remove(lines, lines->data); } } g_hash_table_insert(gui->line_cache, line, rec); return rec; }
gboolean cam_device_open (CamDevice * device, const char *filename) { ca_caps_t ca_caps; int ret; int i; int count = 10; g_return_val_if_fail (device != NULL, FALSE); g_return_val_if_fail (device->state == CAM_DEVICE_STATE_CLOSED, FALSE); g_return_val_if_fail (filename != NULL, FALSE); GST_INFO ("opening CA device %s", filename); ret = open (filename, O_RDWR); if (ret == -1) { GST_ERROR ("can't open CA device: %s", g_strerror (errno)); return FALSE; } GST_DEBUG ("Successfully opened device %s", filename); device->fd = ret; ret = ioctl (device->fd, CA_RESET); g_usleep (G_USEC_PER_SEC / 10); while (TRUE) { /* get the capabilities of the CA */ ret = ioctl (device->fd, CA_GET_CAP, &ca_caps); if (ret == -1) { GST_ERROR ("CA_GET_CAP ioctl failed: %s", g_strerror (errno)); reset_state (device); return FALSE; } if (ca_caps.slot_num > 0) break; if (!count) { GST_ERROR ("CA_GET_CAP succeeded but not slots"); reset_state (device); return FALSE; } count--; g_usleep (G_USEC_PER_SEC / 5); } device->tl = cam_tl_new (device->fd); device->sl = cam_sl_new (device->tl); device->al = cam_al_new (device->sl); device->mgr = cam_resource_manager_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->mgr)); device->info = cam_application_info_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->info)); device->cas = cam_conditional_access_new (); cam_al_install (device->al, CAM_AL_APPLICATION (device->cas)); /* open a connection to each slot */ for (i = 0; i < ca_caps.slot_num; ++i) { CamTLConnection *connection; ret = cam_tl_create_connection (device->tl, i, &connection); if (CAM_FAILED (ret)) { /* just ignore the slot, error out later only if no connection has been * established */ GST_WARNING ("connection to slot %d failed, error: %d", i, ret); continue; } } if (g_hash_table_size (device->tl->connections) == 0) { GST_ERROR ("couldn't connect to any slot"); reset_state (device); return FALSE; } device->state = CAM_DEVICE_STATE_OPEN; device->filename = g_strdup (filename); /* poll each connection to initiate the protocol */ cam_tl_read_all (device->tl, TRUE); return TRUE; }
/** * inf_user_get_flags: * @user: A #InfUser. * * Returns the flags for the given #InfUser. * * Return Value: The user's flags. **/ InfUserFlags inf_user_get_flags(InfUser* user) { g_return_val_if_fail(INF_IS_USER(user), 0); return INF_USER_PRIVATE(user)->flags; }
/** * cong_node_properties_dialog_new: * @doc: The document being displayed. * @node: The node to display. * @parent_window: The parent window of the document. * * Create a dialog window which displays, and allows the user to edit, * the properties of the supplied node. The format of the dialog * depends on the node type. * * The main interest will be for nodes of type CONG_NODE_TYPE_ELEMENT. * If there is a plugin registered for this node then the plugin will be * used, otherwise the attributes of the node will be displayed. In the * later case, the attributes will be displayed in a "raw" form (as * a set of name and value pairs) and, if a DTD associated with this file, * using an interface that follows the DTD (e.g. will limit enumerated * values to the allowable choices only). * * For CONG_NODE_TYPE_TEXT nodes the properties of the parent node will * be displayed. This is primarily so that users can access the attributes * of span nodes, but it will work for any text node. Should there be * a way to indicate that this has happened (i.e. some indication * in the dialog that we are actually displaying the parent's * properties)? * * Other node types result in a dialog which only lists the name * and the XPath location of the node. * * At present the returned dialog window should be displayed using * gtk_widget_show() rather than gtk_dialog_run(). * * Returns: a #GtkWidget displaying the properties of the node. */ GtkWidget* cong_node_properties_dialog_new (CongDocument *doc, CongNodePtr node, GtkWindow *parent_window) { g_return_val_if_fail (doc, NULL); g_return_val_if_fail (node, NULL); /* * If this is a text node then display the properties of its * parent node instead. I do not think this can recurse "wildly" * (presumably a text node can not have a text node as its * parent). */ if (cong_node_type(node)==CONG_NODE_TYPE_TEXT) { return cong_node_properties_dialog_new (doc, cong_node_parent(node), parent_window); } /* Should we use a plugin for this node?: */ if (cong_node_type(node)==CONG_NODE_TYPE_ELEMENT) { CongDispspecElement *element; const gchar *service_id; element = cong_document_get_dispspec_element_for_node (doc, node); if (element) { service_id = cong_dispspec_element_get_property_dialog_service_id(element); /* Is there a plugin for this type of node? */ if (service_id) { CongServiceNodePropertyDialog *dialog_factory = cong_plugin_manager_locate_custom_property_dialog_by_id (cong_app_get_plugin_manager (cong_app_singleton()), service_id); if (dialog_factory) { GtkWidget *dialog = cong_custom_property_dialog_make (dialog_factory, doc, node); return dialog; } } } } /* Otherwise: */ { GtkWidget* dtd_page; GtkWidget *dialog, *vbox; GtkWidget *advanced_properties; dialog = gtk_dialog_new_with_buttons(_("Properties"), parent_window, GTK_DIALOG_MODAL, GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL); gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); vbox = GTK_DIALOG(dialog)->vbox; dtd_page = cong_node_properties_dtd_new (doc, node, TRUE); advanced_properties = cong_node_properties_dialog_advanced_new (doc, node, (dtd_page!=NULL)); gtk_widget_show (advanced_properties); if (dtd_page) { GtkWidget *notebook = gtk_notebook_new (); gtk_widget_show (notebook); gtk_box_pack_start (GTK_BOX(vbox), notebook, TRUE, TRUE, 0); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dtd_page, gtk_label_new(_("DTD")) ); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), advanced_properties, gtk_label_new(_("Advanced")) ); } else { gtk_box_pack_start (GTK_BOX(vbox), advanced_properties, TRUE, TRUE, 0); } g_signal_connect_swapped (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (dialog)); return GTK_WIDGET(dialog); } }
/** * inf_user_get_connection: * @user: A #InfUser. * * Returns a connection to the given #InfUser, or %NULL. If a non-%NULL * connection is returned, then this is the connection through which records * from that user come from. This means that, when this connection is closed, * then the user is no longer available. However, you cannot send something * to this connection expecting the user will receive it. For example, * in central messaging mode, this connection is always the publisher, because * all records from the user are relayed via the publisher. * * If this functions returns %NULL, this either means @user is a local user * (%INF_USER_LOCAL flag set) or it is not available (status is * %INF_USER_UNAVAILABLE). * * Return Value: A #InfXmlConnection, or %NULL. **/ InfXmlConnection* inf_user_get_connection(InfUser* user) { g_return_val_if_fail(INF_IS_USER(user), NULL); return INF_USER_PRIVATE(user)->connection; }
static const gchar * gdk_win32_display_get_name (GdkDisplay *display) { HDESK hdesk = GetThreadDesktop (GetCurrentThreadId ()); char dummy; char *desktop_name; HWINSTA hwinsta = GetProcessWindowStation (); char *window_station_name; DWORD n; DWORD session_id; char *display_name; static const char *display_name_cache = NULL; typedef BOOL (WINAPI *PFN_ProcessIdToSessionId) (DWORD, DWORD *); PFN_ProcessIdToSessionId processIdToSessionId; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); if (display_name_cache != NULL) return display_name_cache; n = 0; GetUserObjectInformation (hdesk, UOI_NAME, &dummy, 0, &n); if (n == 0) desktop_name = "Default"; else { n++; desktop_name = g_alloca (n + 1); memset (desktop_name, 0, n + 1); if (!GetUserObjectInformation (hdesk, UOI_NAME, desktop_name, n, &n)) desktop_name = "Default"; } n = 0; GetUserObjectInformation (hwinsta, UOI_NAME, &dummy, 0, &n); if (n == 0) window_station_name = "WinSta0"; else { n++; window_station_name = g_alloca (n + 1); memset (window_station_name, 0, n + 1); if (!GetUserObjectInformation (hwinsta, UOI_NAME, window_station_name, n, &n)) window_station_name = "WinSta0"; } processIdToSessionId = (PFN_ProcessIdToSessionId) GetProcAddress (GetModuleHandle ("kernel32.dll"), "ProcessIdToSessionId"); if (!processIdToSessionId || !processIdToSessionId (GetCurrentProcessId (), &session_id)) session_id = 0; display_name = g_strdup_printf ("%ld\\%s\\%s", session_id, window_station_name, desktop_name); GDK_NOTE (MISC, g_print ("gdk_win32_display_get_name: %s\n", display_name)); display_name_cache = display_name; return display_name_cache; }
/** * gnm_sheet_slicer_overlaps_range: * @gss: #GnmSheetSlicer * @r: #GnmRange * * Returns: %TRUE if @gss overlaps @r. **/ gboolean gnm_sheet_slicer_overlaps_range (GnmSheetSlicer const *gss, GnmRange const *r) { g_return_val_if_fail (GNM_IS_SHEET_SLICER (gss), FALSE); return range_overlap (&gss->range, r); }
OrComponentState* or_component_state_construct (GType object_type, Connection** inputWires, int inputWires_length1, Connection* outputWire, ComponentInst** ancestry, int ancestry_length1, ComponentInst* componentInst) { OrComponentState* self = NULL; Connection** _tmp0_ = NULL; gint _tmp0__length1 = 0; Connection** _tmp1_ = NULL; gint _tmp1__length1 = 0; Connection** _tmp2_ = NULL; gint _tmp2__length1 = 0; Connection* _tmp5_ = NULL; Connection* _tmp6_ = NULL; ComponentInst** _tmp7_ = NULL; gint _tmp7__length1 = 0; ComponentInst** _tmp8_ = NULL; gint _tmp8__length1 = 0; ComponentInst* _tmp9_ = NULL; ComponentInst* _tmp10_ = NULL; g_return_val_if_fail (outputWire != NULL, NULL); g_return_val_if_fail (componentInst != NULL, NULL); self = (OrComponentState*) component_state_construct (object_type); _tmp0_ = inputWires; _tmp0__length1 = inputWires_length1; _tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup32 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_); _tmp1__length1 = _tmp0__length1; self->priv->inputWires = (_vala_array_free (self->priv->inputWires, self->priv->inputWires_length1, (GDestroyNotify) connection_unref), NULL); self->priv->inputWires = _tmp1_; self->priv->inputWires_length1 = _tmp1__length1; self->priv->_inputWires_size_ = self->priv->inputWires_length1; _tmp2_ = inputWires; _tmp2__length1 = inputWires_length1; { Connection** inputWire_collection = NULL; gint inputWire_collection_length1 = 0; gint _inputWire_collection_size_ = 0; gint inputWire_it = 0; inputWire_collection = _tmp2_; inputWire_collection_length1 = _tmp2__length1; for (inputWire_it = 0; inputWire_it < _tmp2__length1; inputWire_it = inputWire_it + 1) { Connection* _tmp3_ = NULL; Connection* inputWire = NULL; _tmp3_ = _connection_ref0 (inputWire_collection[inputWire_it]); inputWire = _tmp3_; { Connection* _tmp4_ = NULL; _tmp4_ = inputWire; connection_set_affects (_tmp4_, (ComponentState*) self); _connection_unref0 (inputWire); } } } _tmp5_ = outputWire; _tmp6_ = _connection_ref0 (_tmp5_); _connection_unref0 (self->priv->outputWire); self->priv->outputWire = _tmp6_; _tmp7_ = ancestry; _tmp7__length1 = ancestry_length1; _tmp8_ = (_tmp7_ != NULL) ? _vala_array_dup33 (_tmp7_, _tmp7__length1) : ((gpointer) _tmp7_); _tmp8__length1 = _tmp7__length1; ((ComponentState*) self)->ancestry = (_vala_array_free (((ComponentState*) self)->ancestry, ((ComponentState*) self)->ancestry_length1, (GDestroyNotify) component_inst_unref), NULL); ((ComponentState*) self)->ancestry = _tmp8_; ((ComponentState*) self)->ancestry_length1 = _tmp8__length1; _tmp9_ = componentInst; _tmp10_ = _component_inst_ref0 (_tmp9_); _component_inst_unref0 (((ComponentState*) self)->componentInst); ((ComponentState*) self)->componentInst = _tmp10_; return self; }
GdaConnection * test_cnc_open_connection (const gchar *provider, const gchar *dbname, GError **error) { GdaConnection *cnc = NULL; gchar *str, *upname; const gchar *cnc_params; GdaProviderInfo *prov_info; GdaQuarkList *db_quark_list = NULL, *cnc_quark_list = NULL; gboolean db_created = FALSE; g_return_val_if_fail (dbname && *dbname, NULL); prov_info = gda_config_get_provider_info (provider); if (!prov_info) { g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "Provider '%s' not found", provider); return NULL; } /* open connection to database */ upname = prov_name_upcase (prov_info->id); str = g_strdup_printf ("%s_CNC_PARAMS", upname); cnc_params = getenv (str); g_free (str); if (cnc_params) cnc_quark_list = gda_quark_list_new_from_string (cnc_params); if (db_quark_list || cnc_quark_list) { Data1 data; data.string = g_string_new (""); data.ql = NULL; data.requested_db_name = NULL; if (db_quark_list) gda_quark_list_foreach (db_quark_list, (GHFunc) cnc_quark_foreach_func, &data); data.ql = db_quark_list; if (cnc_quark_list) gda_quark_list_foreach (cnc_quark_list, (GHFunc) cnc_quark_foreach_func, &data); if (*(data.string->str) != 0) g_string_append_c (data.string, ';'); g_string_append_printf (data.string, "DB_NAME=%s", data.requested_db_name ? data.requested_db_name : dbname); g_print ("Open connection string: %s\n", data.string->str); gchar *auth_string = NULL; GSList *current = prov_info->auth_params->holders; while (current) { GdaHolder *holder = (GdaHolder *) current->data; const gchar *id = gda_holder_get_id (holder); const gchar *env = NULL; if (g_strrstr (id, "USER") != NULL) { str = g_strdup_printf ("%s_USER", upname); env = getenv (str); g_free (str); } else if (g_strrstr (id, "PASS") != NULL) { str = g_strdup_printf ("%s_PASS", upname); env = getenv (str); g_free (str); } if (env) { str = g_strdup_printf ("%s=%s;", id, env); gchar *tmp = auth_string; auth_string = g_strconcat (auth_string, str, NULL); g_free (str); g_free (tmp); } current = g_slist_next (current); } cnc = gda_connection_open_from_string (prov_info->id, data.string->str, auth_string, GDA_CONNECTION_OPTIONS_NONE, error); g_free (auth_string); g_string_free (data.string, TRUE); } if (db_quark_list) gda_quark_list_free (db_quark_list); if (cnc_quark_list) gda_quark_list_free (cnc_quark_list); if (!cnc_params) g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "Connection parameters not specified, test not executed (define %s_CNC_PARAMS or %s_DBCREATE_PARAMS to create a test DB)\n", upname, upname); g_free (upname); return cnc; }
guint egg_tray_icon_send_message (EggTrayIcon *icon, gint timeout, const gchar *message, gint len) { guint stamp; g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); g_return_val_if_fail (timeout >= 0, 0); g_return_val_if_fail (message != NULL, 0); if (icon->manager_window == None) return 0; if (len < 0) len = strlen (message); stamp = icon->stamp++; /* Get ready to send the message */ egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, (Window)gtk_plug_get_id (GTK_PLUG (icon)), timeout, len, stamp); /* Now to send the actual message */ gdk_error_trap_push (); while (len > 0) { XClientMessageEvent ev; Display *xdisplay; #if GTK_CHECK_VERSION(2,1,0) xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); #else xdisplay = gdk_display; #endif ev.type = ClientMessage; ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon)); ev.format = 8; ev.message_type = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); if (len > 20) { memcpy (&ev.data, message, 20); len -= 20; message += 20; } else { memcpy (&ev.data, message, len); len = 0; } XSendEvent (xdisplay, icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); XSync (xdisplay, False); } gdk_error_trap_pop (); return stamp; }
const gchar * mongo_message_update_get_collection (MongoMessageUpdate *update) { g_return_val_if_fail(MONGO_IS_MESSAGE_UPDATE(update), NULL); return update->priv->collection; }
/** * inf_user_get_id: * @user: A #InfUser. * * Returns the ID of the given #InfUser. * * Return Value: A numerical User ID. **/ guint inf_user_get_id(InfUser* user) { g_return_val_if_fail(INF_IS_USER(user), 0); return INF_USER_PRIVATE(user)->id; }
MongoBson * mongo_message_update_get_update (MongoMessageUpdate *update) { g_return_val_if_fail(MONGO_IS_MESSAGE_UPDATE(update), NULL); return update->priv->update; }
/** * inf_user_get_name: * @user: A #InfUser. * * Returns the name of the given #InfUser. * * Return Value: The user's name. **/ const gchar* inf_user_get_name(InfUser* user) { g_return_val_if_fail(INF_IS_USER(user), NULL); return INF_USER_PRIVATE(user)->name; }
/** * inf_tcp_connection_get_remote_port: * @connection: A #InfTcpConnection. * * Returns the port of the remote site to which @connection is (or was) * connected or connecting. * * Returns: The port of the remote site. **/ guint inf_tcp_connection_get_remote_port(InfTcpConnection* connection) { g_return_val_if_fail(INF_IS_TCP_CONNECTION(connection), 0); return INF_TCP_CONNECTION_PRIVATE(connection)->remote_port; }
/** * inf_user_get_status: * @user: A #InfUser. * * Returns the status of the given #InfUser. * * Return Value: The user's status. **/ InfUserStatus inf_user_get_status(InfUser* user) { g_return_val_if_fail(INF_IS_USER(user), INF_USER_UNAVAILABLE); return INF_USER_PRIVATE(user)->status; }
/** * cockpit_channel_get_option: * @self: a channel * * Called by implementations to get the channel's open options. * * Returns: (transfer none): the open options, should not be NULL */ JsonObject * cockpit_channel_get_options (CockpitChannel *self) { g_return_val_if_fail (COCKPIT_IS_CHANNEL (self), NULL); return self->priv->open_options; }
/** * gst_adapter_masked_scan_uint32_peek: * @adapter: a #GstAdapter * @mask: mask to apply to data before matching against @pattern * @pattern: pattern to match (after mask is applied) * @offset: offset into the adapter data from which to start scanning, returns * the last scanned position. * @size: number of bytes to scan from offset * @value: (out) (allow-none): pointer to uint32 to return matching data * * Scan for pattern @pattern with applied mask @mask in the adapter data, * starting from offset @offset. If a match is found, the value that matched * is returned through @value, otherwise @value is left untouched. * * The bytes in @pattern and @mask are interpreted left-to-right, regardless * of endianness. All four bytes of the pattern must be present in the * adapter for it to match, even if the first or last bytes are masked out. * * It is an error to call this function without making sure that there is * enough data (offset+size bytes) in the adapter. * * Returns: offset of the first match, or -1 if no match was found. */ gssize gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask, guint32 pattern, gsize offset, gsize size, guint32 * value) { GSList *g; gsize skip, bsize, i; guint32 state; GstMapInfo info; guint8 *bdata; GstBuffer *buf; g_return_val_if_fail (size > 0, -1); g_return_val_if_fail (offset + size <= adapter->size, -1); g_return_val_if_fail (((~mask) & pattern) == 0, -1); /* we can't find the pattern with less than 4 bytes */ if (G_UNLIKELY (size < 4)) return -1; skip = offset + adapter->skip; /* first step, do skipping and position on the first buffer */ /* optimistically assume scanning continues sequentially */ if (adapter->scan_entry && (adapter->scan_offset <= skip)) { g = adapter->scan_entry; skip -= adapter->scan_offset; } else { g = adapter->buflist; adapter->scan_offset = 0; adapter->scan_entry = NULL; } buf = g->data; bsize = gst_buffer_get_size (buf); while (G_UNLIKELY (skip >= bsize)) { skip -= bsize; g = g_slist_next (g); adapter->scan_offset += bsize; adapter->scan_entry = g; buf = g->data; bsize = gst_buffer_get_size (buf); } /* get the data now */ if (!gst_buffer_map (buf, &info, GST_MAP_READ)) return -1; bdata = (guint8 *) info.data + skip; bsize = info.size - skip; skip = 0; /* set the state to something that does not match */ state = ~pattern; /* now find data */ do { bsize = MIN (bsize, size); for (i = 0; i < bsize; i++) { state = ((state << 8) | bdata[i]); if (G_UNLIKELY ((state & mask) == pattern)) { /* we have a match but we need to have skipped at * least 4 bytes to fill the state. */ if (G_LIKELY (skip + i >= 3)) { if (G_LIKELY (value)) *value = state; gst_buffer_unmap (buf, &info); return offset + skip + i - 3; } } } size -= bsize; if (size == 0) break; /* nothing found yet, go to next buffer */ skip += bsize; g = g_slist_next (g); adapter->scan_offset += info.size; adapter->scan_entry = g; gst_buffer_unmap (buf, &info); buf = g->data; if (!gst_buffer_map (buf, &info, GST_MAP_READ)) return -1; bsize = info.size; bdata = info.data; } while (TRUE); gst_buffer_unmap (buf, &info); /* nothing found */ return -1; }