static gchar * get_software_version (void) { GDataInputStream *datastream; GError *error = NULL; GFile *osrelease_file = NULL; GFileInputStream *filestream; GString *software_version; gchar *line; gchar *name = NULL; gchar *version = NULL; gchar *version_string = NULL; osrelease_file = g_file_new_for_path (OSRELEASE_FILE); filestream = g_file_read (osrelease_file, NULL, &error); if (error) { goto bailout; } datastream = g_data_input_stream_new (G_INPUT_STREAM (filestream)); while ((!name || !version) && (line = g_data_input_stream_read_line (datastream, NULL, NULL, &error))) { if (g_str_has_prefix (line, "NAME=")) { name = line; } else if (g_str_has_prefix (line, "VERSION=")) { version = line; } else { g_free (line); } } if (error) { goto bailout; } software_version = g_string_new (""); if (name) { g_string_append (software_version, name + strlen ("NAME=\"")); g_string_erase (software_version, software_version->len - 1, 1); } if (version) { if (name) { g_string_append_c (software_version, ' '); } g_string_append (software_version, version + strlen ("VERSION=\"")); g_string_erase (software_version, software_version->len - 1, 1); } version_string = g_string_free (software_version, FALSE); bailout: g_free (name); g_free (version); if (error) { g_warning ("Error reading " OSRELEASE_FILE ": %s", error->message); g_error_free (error); } g_clear_object (&datastream); g_clear_object (&filestream); g_clear_object (&osrelease_file); if (version_string) { return version_string; } else { return g_strdup (""); } }
static void file_list_ready_cb (GList *files, gpointer user_data) { NautilusFileConflictDialog *fcd = user_data; NautilusFile *src, *dest, *dest_dir; time_t src_mtime, dest_mtime; gboolean source_is_dir, dest_is_dir, should_show_type; NautilusFileConflictDialogDetails *details; char *primary_text, *message, *secondary_text; const gchar *message_extra; char *dest_name, *dest_dir_name, *edit_name; char *label_text; char *size, *date, *type = NULL; GdkPixbuf *pixbuf; GtkWidget *label; GString *str; PangoAttrList *attr_list; details = fcd->details; details->handle = NULL; dest_dir = g_list_nth_data (files, 0); dest = g_list_nth_data (files, 1); src = g_list_nth_data (files, 2); src_mtime = nautilus_file_get_mtime (src); dest_mtime = nautilus_file_get_mtime (dest); dest_name = nautilus_file_get_display_name (dest); dest_dir_name = nautilus_file_get_display_name (dest_dir); source_is_dir = nautilus_file_is_directory (src); dest_is_dir = nautilus_file_is_directory (dest); type = nautilus_file_get_mime_type (dest); should_show_type = !nautilus_file_is_mime_type (src, type); g_free (type); type = NULL; /* Set up the right labels */ if (dest_is_dir) { if (source_is_dir) { primary_text = g_strdup_printf (_("Merge folder \"%s\"?"), dest_name); message_extra = _("Merging will ask for confirmation before replacing any files in " "the folder that conflict with the files being copied."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older folder with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer folder with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { message_extra = _("Replacing it will remove all files in the folder."); primary_text = g_strdup_printf (_("Replace folder \"%s\"?"), dest_name); message = g_strdup_printf (_("A folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { primary_text = g_strdup_printf (_("Replace file \"%s\"?"), dest_name); message_extra = _("Replacing it will overwrite its content."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older file with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer file with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another file with the same name already exists in \"%s\"."), dest_dir_name); } } secondary_text = g_strdup_printf ("%s\n%s", message, message_extra); g_free (message); label = gtk_label_new (primary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); attr_list = pango_attr_list_new (); pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE)); g_object_set (label, "attributes", attr_list, NULL); pango_attr_list_unref (attr_list); label = gtk_label_new (secondary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (primary_text); g_free (secondary_text); /* Set up file icons */ pixbuf = nautilus_file_get_icon_pixbuf (dest, NAUTILUS_ICON_SIZE_LARGE, TRUE, NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS); details->dest_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->first_hbox), details->dest_image, FALSE, FALSE, 0); gtk_widget_show (details->dest_image); g_object_unref (pixbuf); pixbuf = nautilus_file_get_icon_pixbuf (src, NAUTILUS_ICON_SIZE_LARGE, TRUE, NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS); details->src_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->second_hbox), details->src_image, FALSE, FALSE, 0); gtk_widget_show (details->src_image); g_object_unref (pixbuf); /* Set up labels */ label = gtk_label_new (NULL); date = nautilus_file_get_string_attribute (dest, "date_modified"); size = nautilus_file_get_string_attribute (dest, "size"); if (should_show_type) { type = nautilus_file_get_string_attribute (dest, "type"); } str = g_string_new (NULL); g_string_append_printf (str, "<b>%s</b>\n", _("Original file")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = str->str; gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->first_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (type); g_free (date); g_string_erase (str, 0, -1); /* Second label */ label = gtk_label_new (NULL); date = nautilus_file_get_string_attribute (src, "date_modified"); size = nautilus_file_get_string_attribute (src, "size"); if (should_show_type) { type = nautilus_file_get_string_attribute (src, "type"); } g_string_append_printf (str, "<b>%s</b>\n", _("Replace with")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = g_string_free (str, FALSE); gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->second_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (date); g_free (type); g_free (label_text); /* Populate the entry */ edit_name = nautilus_file_get_edit_name (dest); details->conflict_name = edit_name; gtk_entry_set_text (GTK_ENTRY (details->entry), edit_name); if (source_is_dir && dest_is_dir) { gtk_button_set_label (GTK_BUTTON (details->replace_button), _("Merge")); } nautilus_file_monitor_add (src, fcd, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON); nautilus_file_monitor_add (dest, fcd, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON); details->src_handler_id = g_signal_connect (src, "changed", G_CALLBACK (file_icons_changed), fcd); details->dest_handler_id = g_signal_connect (dest, "changed", G_CALLBACK (file_icons_changed), fcd); }
/* * NOTE: the channel is not in nonblocking mode, thus the control channel * may block syslog-ng completely. */ static void control_connection_io_input(void *s) { ControlConnection *self = (ControlConnection *) s; GString *command = NULL; gchar *nl; gint rc; gint cmd; gint orig_len; if (self->input_buffer->len > MAX_CONTROL_LINE_LENGTH) { /* too much data in input, drop the connection */ msg_error("Too much data in the control socket input buffer", NULL); control_connection_stop_watches(self); control_connection_free(self); return; } orig_len = self->input_buffer->len; /* NOTE: plus one for the terminating NUL */ g_string_set_size(self->input_buffer, self->input_buffer->len + 128 + 1); rc = read(self->control_io.fd, self->input_buffer->str + orig_len, 128); if (rc < 0) { if (errno != EAGAIN) { msg_error("Error reading command on control channel, closing control channel", evt_tag_errno("error", errno), NULL); goto destroy_connection; } /* EAGAIN, should try again when data comes */ control_connection_update_watches(self); return; } else if (rc == 0) { msg_error("EOF on control channel, closing connection", NULL); goto destroy_connection; } else { self->input_buffer->len = orig_len + rc; self->input_buffer->str[self->input_buffer->len] = 0; } /* here we have finished reading the input, check if there's a newline somewhere */ nl = strchr(self->input_buffer->str, '\n'); if (nl) { command = g_string_sized_new(128); /* command doesn't contain NL */ g_string_assign_len(command, self->input_buffer->str, nl - self->input_buffer->str); /* strip NL */ g_string_erase(self->input_buffer, 0, command->len + 1); } else { /* no EOL in the input buffer, wait for more data */ control_connection_update_watches(self); return; } for (cmd = 0; commands[cmd].func; cmd++) { if (strncmp(commands[cmd].command, command->str, strlen(commands[cmd].command)) == 0) { commands[cmd].func(self, command); break; } } if (!commands[cmd].func) { msg_error("Unknown command read on control channel, closing control channel", evt_tag_str("command", command->str), NULL); goto destroy_connection; } control_connection_update_watches(self); g_string_free(command, TRUE); return; destroy_connection: control_connection_stop_watches(self); control_connection_free(self); }
/*! * Read a QMP message. * * \param socket \c GSocket to use. * \param expected_count Number of messages to try to receive. * \param[out] msgs List of received messages (which are of * type \c GString). * \param[out] count Number of messages saved in \p msgs. * \return \c true on success, else \c false. */ static gboolean clr_oci_qmp_msg_recv (GSocket *socket, gsize expected_count, GSList **msgs, gsize *count) { gboolean ret = false; gchar buffer[CLR_OCI_NET_BUF_SIZE]; gsize total = 0; gssize bytes; gssize msg_len; GError *error = NULL; GString *msg = NULL; GString *received = NULL; gchar *p; g_assert (socket); g_assert (expected_count); g_assert (msgs); g_assert (count); g_debug ("client expects %lu message%s", expected_count, expected_count == 1 ? "" : "s"); do { /* reset */ memset (buffer, '\0', CLR_OCI_NET_BUF_SIZE); /* read a chunk */ bytes = g_socket_receive (socket, buffer, CLR_OCI_NET_BUF_SIZE, NULL, &error); if (bytes <= 0) { g_critical ("client failed to receive: %s", error->message); g_error_free (error); goto out; } /* save the chunk */ if (! received) { received = g_string_new_len (buffer, bytes); } else { g_string_append_len (received, buffer, bytes); } total += (gsize)bytes; while (true) { if (! received->len) { /* All the data read so far has been consumed */ break; } /* Check for end of message marker to determine if a * complete message has been received yet. */ p = g_strstr_len (received->str, (gssize)total, CLR_OCI_MSG_SEPARATOR); if (! p) { /* No complete message to operate on */ break; } /* We now have (*atleast* !!) one complete message to handle */ /* Calculate the length of the message */ msg_len = p - received->str; /* Save the message */ msg = g_string_new_len (received->str, msg_len); /* Add the the complete message to the list */ *msgs = g_slist_append (*msgs, msg); (*count)++; g_debug ("client read message %lu '%s' (len=%lu)", (unsigned long int)*count, msg->str, msg->len); /* Remove the handled data * (including the message separator). */ g_string_erase (received, 0, (gssize) ((gsize)msg_len + sizeof (CLR_OCI_MSG_SEPARATOR)-1)); /* Get ready to potentially receive a new * message (caller is responsible for freeing the list). */ msg = NULL; } if (*count == expected_count) { g_debug ("found expected number of messages (%lu)", (unsigned long int)expected_count); break; } } while (true); /* All complete messages should have been added to the list */ g_assert (! msg); /* All received data should have been handled */ g_assert (! received->len); /* clean up */ g_string_free (received, true); g_debug ("client received %lu message%s " "(expected %lu) in %lu bytes", (unsigned long int)*count, *count == 1 ? "" : "s", (unsigned long int)expected_count, (unsigned long int)total); ret = *count == expected_count; out: return ret; }
static void record_chan_mode (session *sess, char sign, char mode, char *arg) { /* Somebody needed to acutally update sess->current_modes, needed to play nice with bouncers, and less mode calls. Also keeps modes up to date for scripts */ server *serv = sess->server; GString *current = g_string_new(sess->current_modes); gint mode_pos = -1; gchar *current_char = current->str; gint modes_length; gint argument_num = 0; gint argument_offset = 0; gint argument_length = 0; int i = 0; gchar *arguments_start; /* find out if the mode currently exists */ arguments_start = g_strstr_len(current->str , -1, " "); if (arguments_start) { modes_length = arguments_start - current->str; } else { modes_length = current->len; /* set this to the end of the modes */ arguments_start = current->str + current->len; } while (mode_pos == -1 && i < modes_length) { if (*current_char == mode) { mode_pos = i; } else { i++; current_char++; } } /* if the mode currently exists and has an arg, need to know where * (including leading space) */ if (mode_pos != -1 && mode_has_arg(serv, '+', mode)) { current_char = current->str; i = 0; while (i <= mode_pos) { if (mode_has_arg(serv, '+', *current_char)) argument_num++; current_char++; i++; } /* check through arguments for where to start */ current_char = arguments_start; i = 0; while (i < argument_num && *current_char != '\0') { if (*current_char == ' ') i++; if (i != argument_num) current_char++; } argument_offset = current_char - current->str; /* how long the existing argument is for this key * important for malloc and strncpy */ if (i == argument_num) { argument_length++; current_char++; while (*current_char != '\0' && *current_char != ' ') { argument_length++; current_char++; } } } /* two cases, adding and removing a mode, handled differently */ if (sign == '+') { if (mode_pos != -1) { /* if it already exists, only need to do something (change) * if there should be a param */ if (mode_has_arg(serv, sign, mode)) { /* leave the old space there */ current = g_string_erase(current, argument_offset+1, argument_length-1); current = g_string_insert(current, argument_offset+1, arg); free(sess->current_modes); sess->current_modes = g_string_free(current, FALSE); } } /* mode wasn't there before */ else { /* insert the new mode character */ current = g_string_insert_c(current, modes_length, mode); /* add the argument, with space if there is one */ if (mode_has_arg(serv, sign, mode)) { current = g_string_append_c(current, ' '); current = g_string_append(current, arg); } free(sess->current_modes); sess->current_modes = g_string_free(current, FALSE); } } else if (sign == '-' && mode_pos != -1) { /* remove the argument first if it has one*/ if (mode_has_arg(serv, '+', mode)) current = g_string_erase(current, argument_offset, argument_length); /* remove the mode character */ current = g_string_erase(current, mode_pos, 1); free(sess->current_modes); sess->current_modes = g_string_free(current, FALSE); } }
static void set_details (MucharmapCharmap *charmap, gunichar uc) { MucharmapCharmapPrivate *priv = charmap->priv; GtkTextBuffer *buffer; GtkTextIter iter; GString *gstemp; gchar *temp; const gchar *csp; gchar buf[12]; guchar utf8[7]; gint n, i; const gchar **csarr; gunichar *ucs; gunichar2 *utf16; MucharmapUnicodeVersion version; buffer = gtk_text_view_get_buffer (priv->details_view); gtk_text_buffer_set_text (buffer, "", 0); gtk_text_buffer_get_start_iter (buffer, &iter); gtk_text_buffer_place_cursor (buffer, &iter); gtk_text_buffer_insert (buffer, &iter, "\n", -1); n = mucharmap_unichar_to_printable_utf8 (uc, buf); if (n == 0) gtk_text_buffer_insert ( buffer, &iter, _("[not a printable character]"), -1); else gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, buf, n, "gimongous", NULL); gtk_text_buffer_insert (buffer, &iter, "\n\n", -1); /* character name */ temp = g_strdup_printf ("U+%4.4X %s\n", uc, mucharmap_get_unicode_name (uc)); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, temp, -1, "big", "bold", NULL); g_free (temp); insert_heading (charmap, buffer, &iter, _("General Character Properties")); /* Unicode version */ version = mucharmap_get_unicode_version (uc); if (version != MUCHARMAP_UNICODE_VERSION_UNASSIGNED) insert_vanilla_detail (charmap, buffer, &iter, _("In Unicode since:"), mucharmap_unicode_version_to_string (version)); /* character category */ insert_vanilla_detail (charmap, buffer, &iter, _("Unicode category:"), mucharmap_get_unicode_category_name (uc)); /* canonical decomposition */ conditionally_insert_canonical_decomposition (charmap, buffer, &iter, uc); /* representations */ if (g_unichar_break_type(uc) != G_UNICODE_BREAK_SURROGATE) { insert_heading (charmap, buffer, &iter, _("Various Useful Representations")); n = g_unichar_to_utf8 (uc, (gchar *)utf8); utf16 = g_ucs4_to_utf16 (&uc, 1, NULL, NULL, NULL); /* UTF-8 */ gstemp = g_string_new (NULL); for (i = 0; i < n; i++) g_string_append_printf (gstemp, "0x%2.2X ", utf8[i]); g_string_erase (gstemp, gstemp->len - 1, -1); insert_vanilla_detail (charmap, buffer, &iter, _("UTF-8:"), gstemp->str); g_string_free (gstemp, TRUE); /* UTF-16 */ gstemp = g_string_new (NULL); g_string_append_printf (gstemp, "0x%4.4X", utf16[0]); if (utf16[0] != '\0' && utf16[1] != '\0') g_string_append_printf (gstemp, " 0x%4.4X", utf16[1]); insert_vanilla_detail (charmap, buffer, &iter, _("UTF-16:"), gstemp->str); g_string_free (gstemp, TRUE); /* an empty line */ gtk_text_buffer_insert (buffer, &iter, "\n", -1); /* C octal \012\234 */ gstemp = g_string_new (NULL); for (i = 0; i < n; i++) g_string_append_printf (gstemp, "\\%3.3o", utf8[i]); insert_vanilla_detail (charmap, buffer, &iter, _("C octal escaped UTF-8:"), gstemp->str); g_string_free (gstemp, TRUE); /* XML decimal entity */ if ((0x0001 <= uc && uc <= 0xD7FF) || (0xE000 <= uc && uc <= 0xFFFD) || (0x10000 <= uc && uc <= 0x10FFFF)) { temp = g_strdup_printf ("&#%d;", uc); insert_vanilla_detail (charmap, buffer, &iter, _("XML decimal entity:"), temp); g_free (temp); } g_free(utf16); } /* annotations */ if (_mucharmap_unicode_has_nameslist_entry (uc)) { insert_heading (charmap, buffer, &iter, _("Annotations and Cross References")); /* nameslist equals (alias names) */ csarr = mucharmap_get_nameslist_equals (uc); if (csarr != NULL) { insert_chocolate_detail (charmap, buffer, &iter, _("Alias names:"), csarr, FALSE); g_free (csarr); } /* nameslist stars (notes) */ csarr = mucharmap_get_nameslist_stars (uc); if (csarr != NULL) { insert_chocolate_detail (charmap, buffer, &iter, _("Notes:"), csarr, TRUE); g_free (csarr); } /* nameslist exes (see also) */ ucs = mucharmap_get_nameslist_exes (uc); if (ucs != NULL) { insert_chocolate_detail_codepoints (charmap, buffer, &iter, _("See also:"), ucs); g_free (ucs); } /* nameslist pounds (approximate equivalents) */ csarr = mucharmap_get_nameslist_pounds (uc); if (csarr != NULL) { insert_chocolate_detail (charmap, buffer, &iter, _("Approximate equivalents:"), csarr, TRUE); g_free (csarr); } /* nameslist colons (equivalents) */ csarr = mucharmap_get_nameslist_colons (uc); if (csarr != NULL) { insert_chocolate_detail (charmap, buffer, &iter, _("Equivalents:"), csarr, TRUE); g_free (csarr); } } #if ENABLE_UNIHAN /* this isn't so bad efficiency-wise */ if (mucharmap_get_unicode_kDefinition (uc) || mucharmap_get_unicode_kCantonese (uc) || mucharmap_get_unicode_kMandarin (uc) || mucharmap_get_unicode_kJapaneseOn (uc) || mucharmap_get_unicode_kJapaneseKun (uc) || mucharmap_get_unicode_kTang (uc) || mucharmap_get_unicode_kKorean (uc)) { insert_heading (charmap, buffer, &iter, _("CJK Ideograph Information")); csp = mucharmap_get_unicode_kDefinition (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Definition in English:"), csp); csp = mucharmap_get_unicode_kMandarin (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Mandarin Pronunciation:"), csp); csp = mucharmap_get_unicode_kCantonese (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Cantonese Pronunciation:"), csp); csp = mucharmap_get_unicode_kJapaneseOn (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Japanese On Pronunciation:"), csp); csp = mucharmap_get_unicode_kJapaneseKun (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Japanese Kun Pronunciation:"), csp); csp = mucharmap_get_unicode_kTang (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Tang Pronunciation:"), csp); csp = mucharmap_get_unicode_kKorean (uc); if (csp) insert_vanilla_detail (charmap, buffer, &iter, _("Korean Pronunciation:"), csp); } #endif /* #if ENABLE_UNIHAN */ }
extern mate_config* mate_make_config(const gchar* filename, int mate_hfid) { gint* ett; avp_init(); matecfg = (mate_config *)g_malloc(sizeof(mate_config)); matecfg->hfid_mate = mate_hfid; matecfg->fields_filter = g_string_new(""); matecfg->protos_filter = g_string_new(""); matecfg->dbg_facility = NULL; matecfg->mate_lib_path = g_strdup_printf("%s%c%s%c",get_datafile_dir(),DIR_SEP,DEFAULT_MATE_LIB_PATH,DIR_SEP); matecfg->pducfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gopcfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gogcfgs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->transfs = g_hash_table_new(g_str_hash,g_str_equal); matecfg->pducfglist = g_ptr_array_new(); matecfg->gops_by_pduname = g_hash_table_new(g_str_hash,g_str_equal); matecfg->gogs_by_gopname = g_hash_table_new(g_str_hash,g_str_equal); matecfg->ett_root = -1; matecfg->hfrs = g_array_new(FALSE,FALSE,sizeof(hf_register_info)); matecfg->ett = g_array_new(FALSE,FALSE,sizeof(gint*)); matecfg->defaults.pdu.drop_unassigned = FALSE; matecfg->defaults.pdu.discard = FALSE; matecfg->defaults.pdu.last_extracted = FALSE; matecfg->defaults.pdu.match_mode = AVPL_STRICT; matecfg->defaults.pdu.replace_mode = AVPL_INSERT; /* gop prefs */ matecfg->defaults.gop.expiration = -1.0f; matecfg->defaults.gop.idle_timeout = -1.0f; matecfg->defaults.gop.lifetime = -1.0f; matecfg->defaults.gop.pdu_tree_mode = GOP_FRAME_TREE; matecfg->defaults.gop.show_times = TRUE; matecfg->defaults.gop.drop_unassigned = FALSE; /* gog prefs */ matecfg->defaults.gog.expiration = 5.0f; matecfg->defaults.gog.show_times = TRUE; matecfg->defaults.gog.gop_tree_mode = GOP_BASIC_TREE; /* what to dbgprint */ matecfg->dbg_lvl = 0; matecfg->dbg_pdu_lvl = 0; matecfg->dbg_gop_lvl = 0; matecfg->dbg_gog_lvl = 0; matecfg->config_error = g_string_new(""); ett = &matecfg->ett_root; g_array_append_val(matecfg->ett,ett); if ( mate_load_config(filename,matecfg) ) { analyze_config(); } else { report_failure("MATE failed to configure!\n" "It is recommended that you fix your config and restart Wireshark.\n" "The reported error is:\n%s\n",matecfg->config_error->str); /* if (matecfg) destroy_mate_config(matecfg,FALSE); */ matecfg = NULL; return NULL; } if (matecfg->fields_filter->len > 1) { g_string_erase(matecfg->fields_filter,0,2); g_string_erase(matecfg->protos_filter,0,2); } else { /*destroy_mate_config(matecfg,FALSE);*/ matecfg = NULL; return NULL; } matecfg->tap_filter = g_strdup_printf("(%s) && (%s)",matecfg->protos_filter->str,matecfg->fields_filter->str); return matecfg; }
/* FIXME: must also handle \r and \r\n terminators */ GnomeVFSResult mn_vfs_read_line (MNVFSReadLineContext **context, GnomeVFSHandle *handle, const char **line) { GnomeVFSResult result; gboolean first_pass = TRUE; g_return_val_if_fail(context != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS); g_return_val_if_fail(handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS); g_return_val_if_fail(line != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS); if (*context) { g_return_val_if_fail((*context)->handle == handle, GNOME_VFS_ERROR_BAD_PARAMETERS); if ((*context)->terminator) { g_string_erase((*context)->buf, 0, (*context)->terminator - (*context)->buf->str + 1); (*context)->terminator = NULL; } else if ((*context)->eof) return GNOME_VFS_ERROR_EOF; /* we're done */ } else { *context = g_new0(MNVFSReadLineContext, 1); (*context)->handle = handle; (*context)->buf = g_string_new(NULL); } while (TRUE) { if (! (*context)->buf->str[0] || ! first_pass) { char buf[READ_LINE_BLOCK_SIZE]; GnomeVFSFileSize bytes_read; result = (*context)->last_result = gnome_vfs_read(handle, buf, sizeof(buf), &bytes_read); if (result == GNOME_VFS_OK || result == GNOME_VFS_ERROR_EOF) g_string_append_len((*context)->buf, buf, bytes_read); else break; /* error */ } (*context)->terminator = strchr((*context)->buf->str, '\n'); if ((*context)->terminator || (*context)->last_result == GNOME_VFS_ERROR_EOF) { result = (*context)->last_result; if ((*context)->terminator || (*context)->buf->str[0]) { *line = (*context)->buf->str; if (result == GNOME_VFS_ERROR_EOF) result = GNOME_VFS_OK; } if ((*context)->terminator) (*context)->terminator[0] = 0; else if ((*context)->last_result == GNOME_VFS_ERROR_EOF) (*context)->eof = TRUE; break; /* line found, or last line */ } first_pass = FALSE; } return result; }
static gboolean project_import_generate_file (AnjutaPluginDescription *backend, ProjectImportDialog *import_dialog, GFile *project_file) { /* Of course we could do some more intelligent stuff here * and check which plugins are really needed */ GFile* source_file = NULL; gchar *backend_id = NULL; GError* error = NULL; if (!anjuta_plugin_description_get_string (backend, "Project", "Supported-Project-Types", &backend_id)) { if (!strcmp (backend_id, "automake")) source_file = g_file_new_for_path (AM_PROJECT_FILE); else if (!strcmp (backend_id, "make")) source_file = g_file_new_for_path (MKFILE_PROJECT_FILE); else if (!strcmp (backend_id, "directory")) source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); } g_free (backend_id); if (source_file != NULL) { /* Use a default project file */ if (!g_file_copy (source_file, project_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; g_file_copy (source_file, project_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); } g_free (prjfile); } } if (!error) { time_t ctime = time(NULL); GFileInfo* file_info = g_file_info_new(); g_file_info_set_attribute_uint64(file_info, "time::modified", ctime); g_file_info_set_attribute_uint64(file_info, "time::created", ctime); g_file_info_set_attribute_uint64(file_info, "time::access", ctime); g_file_set_attributes_from_info (project_file, file_info, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (G_OBJECT(file_info));; } } else { /* For unknown project backend we use the directory project file and * replace the backend plugin with the right one */ gchar *content; gsize length; source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); if (g_file_load_contents (source_file, NULL, &content, &length, NULL, &error)) { GString *buffer; const gchar *pos; const gchar *plugin; const gchar *end_plugin; gssize len; buffer = g_string_new_len (content, length); pos = buffer->str; len = buffer->len; for (;;) { plugin = g_strstr_len (pos, len, "<plugin "); if (plugin == NULL) break; end_plugin = g_strstr_len (plugin, len - (plugin - pos), "</plugin>"); if (end_plugin == NULL) break; if (g_strstr_len (plugin, end_plugin - plugin, "\"IAnjutaProjectBackend\"") != NULL) break; pos = end_plugin + 9; len -= (end_plugin + 9 - pos); } if ((plugin == NULL) || (end_plugin == NULL)) { g_set_error (&error, ianjuta_project_backend_error_quark(),0, "Unable to find backend plugin"); } else { /* Replace directory backend with right one */ GString *str; GFileOutputStream *stream; gchar *name = NULL; gchar *plugin_id = NULL; anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Name", &name); anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &plugin_id); str = g_string_new (NULL); g_string_printf (str, "<plugin name= \"%s\"\n" " mandatory=\"yes\">\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Location\"\n" " value=\"%s\"/>\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Interfaces\"\n" " value=\"IAnjutaProjectBackend\"/>\n" " ", name, plugin_id); g_string_erase (buffer, plugin - buffer->str, end_plugin - plugin); g_string_insert_len (buffer, plugin - buffer->str, str->str, str->len); g_string_free (str, TRUE); stream = g_file_create (project_file, G_FILE_CREATE_NONE, NULL, &error); if (stream == NULL && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; stream = g_file_replace (project_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error); } g_free (prjfile); } if (stream != NULL) { gsize written; g_output_stream_write_all (G_OUTPUT_STREAM (stream), buffer->str, buffer->len, &written, NULL, &error); g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL); } } g_string_free (buffer, TRUE); g_free (content); } } g_object_unref (source_file); if (error) { gchar *prjfile; prjfile = g_file_get_parse_name (project_file); /* show the dialog since it may be hidden */ gtk_widget_show (GTK_WIDGET (import_dialog)); anjuta_util_dialog_error (GTK_WINDOW (import_dialog), _("A file named \"%s\" cannot be written: %s. " "Check if you have write access to the project directory."), prjfile, error->message); g_free (prjfile); g_error_free (error); return FALSE; } return TRUE; }
static void gpx_end(VikTrwLayer *vtl, const char *el) { static GTimeVal tp_time; g_string_truncate ( xpath, xpath->len - strlen(el) - 1 ); switch ( current_tag ) { case tt_waypoint: case tt_wpt: if ( ! c_wp_name ) c_wp_name = g_strdup_printf("VIKING_WP%d", unnamed_waypoints++); vik_trw_layer_filein_add_waypoint ( vtl, c_wp_name, c_wp ); g_free ( c_wp_name ); c_wp = NULL; c_wp_name = NULL; break; case tt_trk: if ( ! c_tr_name ) c_tr_name = g_strdup_printf("VIKING_TR%d", unnamed_waypoints++); vik_trw_layer_filein_add_track ( vtl, c_tr_name, c_tr ); g_free ( c_tr_name ); c_tr = NULL; c_tr_name = NULL; break; case tt_wpt_name: if ( c_wp_name ) g_free ( c_wp_name ); c_wp_name = g_strdup ( c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_name: if ( c_tr_name ) g_free ( c_tr_name ); c_tr_name = g_strdup ( c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_wpt_ele: c_wp->altitude = g_ascii_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_ele: c_tp->altitude = g_ascii_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_waypoint_name: /* .loc name is really description. */ case tt_wpt_desc: vik_waypoint_set_comment ( c_wp, c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_wpt_link: vik_waypoint_set_image ( c_wp, c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_wpt_sym: { gchar *tmp_lower = g_utf8_strdown(c_cdata->str, -1); /* for things like <type>Geocache</type> */ vik_waypoint_set_symbol ( c_wp, tmp_lower ); g_free ( tmp_lower ); g_string_erase ( c_cdata, 0, -1 ); break; } case tt_trk_desc: vik_track_set_comment ( c_tr, c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_time: if ( g_time_val_from_iso8601(c_cdata->str, &tp_time) ) { c_tp->timestamp = tp_time.tv_sec; c_tp->has_timestamp = TRUE; } g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_course: c_tp->course = g_ascii_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_speed: c_tp->speed = g_ascii_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_fix: if (!strcmp("2d", c_cdata->str)) c_tp->fix_mode = VIK_GPS_MODE_2D; else if (!strcmp("3d", c_cdata->str)) c_tp->fix_mode = VIK_GPS_MODE_3D; else /* TODO: more fix modes here */ c_tp->fix_mode = VIK_GPS_MODE_NOT_SEEN; g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_sat: c_tp->nsats = atoi ( c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_hdop: c_tp->hdop = g_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_vdop: c_tp->vdop = g_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; case tt_trk_trkseg_trkpt_pdop: c_tp->pdop = g_strtod ( c_cdata->str, NULL ); g_string_erase ( c_cdata, 0, -1 ); break; default: break; } current_tag = get_tag ( xpath->str ); }
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { DocInfo *dinfo = user_data; GeanyEditor *editor; cairo_t *cr; gdouble width, height; gdouble x, y; /*gint layout_h;*/ gint count; GString *str; if (dinfo == NULL || page_nr >= dinfo->n_pages) return; editor = dinfo->doc->editor; if (dinfo->n_pages > 0) { gdouble fraction = (page_nr + 1) / (gdouble) dinfo->n_pages; gchar *text = g_strdup_printf(_("Page %d of %d"), page_nr, dinfo->n_pages); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), fraction); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text); g_free(text); } #ifdef GEANY_PRINT_DEBUG geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d", page_nr, dinfo->n_pages, dinfo->lines_per_page); #endif str = g_string_sized_new(256); cr = gtk_print_context_get_cairo_context(context); width = gtk_print_context_get_width(context); height = gtk_print_context_get_height(context); cairo_set_source_rgb(cr, 0, 0, 0); #ifdef GEANY_PRINT_DEBUG cairo_set_line_width(cr, 0.2); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); #endif cairo_move_to(cr, 0, 0); pango_layout_set_width(dinfo->layout, width * PANGO_SCALE); pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_LEFT); pango_layout_set_ellipsize(dinfo->layout, FALSE); pango_layout_set_justify(dinfo->layout, FALSE); if (printing_prefs.print_page_header) add_page_header(dinfo, cr, width, page_nr); count = 0; /* the actual line counter for the current page, might be different from * dinfo->cur_line due to possible line breaks */ while (count < dinfo->lines_per_page) { gchar c = 'a'; gint style = -1; PangoAttrList *layout_attr; PangoAttribute *attr; gint colours[3] = { 0 }; gboolean add_linenumber = TRUE; gboolean at_eol; while (count < dinfo->lines_per_page && c != '\0') { at_eol = FALSE; g_string_erase(str, 0, str->len); /* clear the string */ /* line numbers */ if (printing_prefs.print_line_numbers && add_linenumber) { /* if we had a wrapped line on the last page which needs to be continued, don't * add a line number */ if (dinfo->long_line) { add_linenumber = FALSE; } else { gchar *line_number = NULL; gint cur_line_number_margin = get_line_numbers_arity(dinfo->cur_line + 1); gchar *fill = g_strnfill( dinfo->max_line_number_margin - cur_line_number_margin - 1, ' '); line_number = g_strdup_printf("%s%d ", fill, dinfo->cur_line + 1); g_string_append(str, line_number); dinfo->cur_line++; /* increase document line */ add_linenumber = FALSE; style = STYLE_LINENUMBER; c = 'a'; /* dummy value */ g_free(fill); g_free(line_number); } } /* data */ else { style = sci_get_style_at(dinfo->doc->editor->sci, dinfo->cur_pos); c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); if (c == '\0' || style == -1) { /* if c gets 0, we are probably out of document boundaries, * so stop to break out of outer loop */ count = dinfo->lines_per_page; break; } dinfo->cur_pos++; /* convert tabs to spaces which seems to be better than using Pango tabs */ if (c == '\t') { gint tab_width = sci_get_tab_width(editor->sci); gchar *s = g_strnfill(tab_width, ' '); g_string_append(str, s); g_free(s); } /* don't add line breaks, they are handled manually below */ else if (c == '\r' || c == '\n') { gchar c_next = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); at_eol = TRUE; if (c == '\r' && c_next == '\n') dinfo->cur_pos++; /* skip LF part of CR/LF */ } else { g_string_append_c(str, c); /* finally add the character */ /* handle UTF-8: since we add char by char (better: byte by byte), we need to * keep UTF-8 characters together(e.g. two bytes for one character) * the input is always UTF-8 and c is signed, so all non-Ascii * characters are less than 0 and consist of all bytes less than 0. * style doesn't change since it is only one character with multiple bytes. */ while (c < 0) { c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos); if (c < 0) { /* only add the byte when it is part of the UTF-8 character * otherwise we could add e.g. a '\n' and it won't be visible in the * printed document */ g_string_append_c(str, c); dinfo->cur_pos++; } } } } if (! at_eol) { /* set text */ pango_layout_set_text(dinfo->layout, str->str, -1); /* attributes */ layout_attr = pango_attr_list_new(); /* foreground colour */ get_rgb_values(dinfo->styles[style][FORE], &colours[0], &colours[1], &colours[2]); attr = pango_attr_foreground_new(colours[0], colours[1], colours[2]); ADD_ATTR(layout_attr, attr); /* background colour */ get_rgb_values(dinfo->styles[style][BACK], &colours[0], &colours[1], &colours[2]); attr = pango_attr_background_new(colours[0], colours[1], colours[2]); ADD_ATTR(layout_attr, attr); /* bold text */ if (dinfo->styles[style][BOLD]) { attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD); ADD_ATTR(layout_attr, attr); } /* italic text */ if (dinfo->styles[style][ITALIC]) { attr = pango_attr_style_new(PANGO_STYLE_ITALIC); ADD_ATTR(layout_attr, attr); } pango_layout_set_attributes(dinfo->layout, layout_attr); pango_layout_context_changed(dinfo->layout); pango_attr_list_unref(layout_attr); } cairo_get_current_point(cr, &x, &y); /* normal line break at eol character in document */ if (at_eol) { /*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/ /*cairo_move_to(cr, 0, y + (gdouble)layout_h / PANGO_SCALE);*/ cairo_move_to(cr, 0, y + dinfo->line_height); count++; /* we added a new document line so request a new line number */ add_linenumber = TRUE; } else { gint x_offset = 0; /* maybe we need to force a line break because of too long line */ if (x >= (width - dinfo->font_width)) { /* don't start the line at horizontal origin because we need to skip the * line number margin */ if (printing_prefs.print_line_numbers) { x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width; } /*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/ /*cairo_move_to(cr, x_offset, y + (gdouble)layout_h / PANGO_SCALE);*/ /* this is faster but not exactly the same as above */ cairo_move_to(cr, x_offset, y + dinfo->line_height); cairo_get_current_point(cr, &x, &y); count++; } if (count < dinfo->lines_per_page) { /* str->len is counted in bytes not characters, so use g_utf8_strlen() */ x_offset = (g_utf8_strlen(str->str, -1) * dinfo->font_width); if (dinfo->long_line && count == 0) { x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width; dinfo->long_line = FALSE; } pango_cairo_show_layout(cr, dinfo->layout); cairo_move_to(cr, x + x_offset, y); } else /* we are on a wrapped line but we are out of lines on this page, so continue * the current line on the next page and remember to continue in current line */ dinfo->long_line = TRUE; } } } if (printing_prefs.print_line_numbers) { /* print a thin line between the line number margin and the data */ gint y_start = 0; if (printing_prefs.print_page_header) y_start = (dinfo->line_height * 3) - 2; /* "- 2": to connect the line number line to * the page header frame */ cairo_set_line_width(cr, 0.3); cairo_move_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y_start); cairo_line_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y + dinfo->line_height); /* y is last added line, we reuse it */ cairo_stroke(cr); } if (printing_prefs.print_page_numbers) { gchar *line = g_strdup_printf("<small>- %d -</small>", page_nr + 1); pango_layout_set_markup(dinfo->layout, line, -1); pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_CENTER); cairo_move_to(cr, 0, height - dinfo->line_height); pango_cairo_show_layout(cr, dinfo->layout); g_free(line); #ifdef GEANY_PRINT_DEBUG cairo_set_line_width(cr, 0.3); cairo_move_to(cr, 0, height - (1.25 * dinfo->line_height)); cairo_line_to(cr, width - 1, height - (1.25 * dinfo->line_height)); cairo_stroke(cr); #endif } g_string_free(str, TRUE); }
static void gpx_start(VikTrwLayer *vtl, const char *el, const char **attr) { static const gchar *tmp; g_string_append_c ( xpath, '/' ); g_string_append ( xpath, el ); current_tag = get_tag ( xpath->str ); switch ( current_tag ) { case tt_wpt: if ( set_c_ll( attr ) ) { c_wp = vik_waypoint_new (); if ( ! get_attr ( attr, "hidden" ) ) c_wp->visible = TRUE; vik_coord_load_from_latlon ( &(c_wp->coord), vik_trw_layer_get_coord_mode ( vtl ), &c_ll ); } break; case tt_trk: c_tr = vik_track_new (); if ( ! get_attr ( attr, "hidden" ) ) c_tr->visible = TRUE; break; case tt_trk_trkseg: f_tr_newseg = TRUE; break; case tt_trk_trkseg_trkpt: if ( set_c_ll( attr ) ) { c_tp = vik_trackpoint_new (); vik_coord_load_from_latlon ( &(c_tp->coord), vik_trw_layer_get_coord_mode ( vtl ), &c_ll ); if ( f_tr_newseg ) { c_tp->newsegment = TRUE; f_tr_newseg = FALSE; } c_tr->trackpoints = g_list_append ( c_tr->trackpoints, c_tp ); } break; case tt_trk_trkseg_trkpt_ele: case tt_trk_trkseg_trkpt_time: case tt_wpt_desc: case tt_wpt_name: case tt_wpt_ele: case tt_wpt_link: case tt_trk_desc: case tt_trk_name: g_string_erase ( c_cdata, 0, -1 ); /* clear the cdata buffer */ break; case tt_waypoint: c_wp = vik_waypoint_new (); c_wp->visible = TRUE; break; case tt_waypoint_coord: if ( set_c_ll( attr ) ) vik_coord_load_from_latlon ( &(c_wp->coord), vik_trw_layer_get_coord_mode ( vtl ), &c_ll ); break; case tt_waypoint_name: if ( ( tmp = get_attr(attr, "id") ) ) { if ( c_wp_name ) g_free ( c_wp_name ); c_wp_name = g_strdup ( tmp ); } g_string_erase ( c_cdata, 0, -1 ); /* clear the cdata buffer for description */ break; default: break; } }
static const gchar * get_header(Log4gLayout *base) { time_t t; gchar buffer[26]; struct Private *priv = GET_PRIVATE(base); time(&t); g_string_set_size(priv->string, 0); g_string_append(priv->string, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " "Transitional//EN " "\"http://www.w3.org/TR/html4/loose.dtd\">"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<html>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<head>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<title>"); g_string_append(priv->string, priv->title); g_string_append(priv->string, "</title>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<style type=\"text/css\">"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<!--"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "body, table {font-family: arial,sans-serif; " "font-size: x-small;}"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "th {background: #336699; color: #ffffff; " "text-align: left;}"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "-->"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "</style>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "</head>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<body bgcolor=\"#ffffff\" topmargin=\"6\" " "leftmargin=\"6\">"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<hr size=\"1\" noshade />"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, Q_("Log session start time ")); g_string_append(priv->string, ctime_r(&t, buffer)); g_string_erase(priv->string, priv->string->len - 1, 1); g_string_append(priv->string, "<br />"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<br />"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<table cellspacing=\"0\" cellpadding=\"4\" " "border=\"1\" bordercolor=\"#224466\" " "width=\"100%\">"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "<tr>"); g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP); g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("Time"), LOG4G_LAYOUT_LINE_SEP); g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("Thread"), LOG4G_LAYOUT_LINE_SEP); g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("Level"), LOG4G_LAYOUT_LINE_SEP); g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("Category"), LOG4G_LAYOUT_LINE_SEP); if (priv->info) { g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("File:Line"), LOG4G_LAYOUT_LINE_SEP); } g_string_append_printf(priv->string, "<th>%s</th>%s", Q_("Message"), LOG4G_LAYOUT_LINE_SEP); g_string_append(priv->string, "</tr>"); return priv->string->str; }
static void powerword_markup_add_text(const gchar *text, gssize length, std::string *pango, std::string::size_type &cur_pos, LinksPosList *links_list) { const gchar *p; const gchar *end; p = text; end = text + length; GString *str; str = g_string_sized_new (length); const gchar *n; bool find; bool previous_islink = false; std::string marktags; guint currentmarktag = 0; while (p != end) { const gchar *next; next = g_utf8_next_char (p); switch (*p) { case '}': if (currentmarktag==0) { g_string_append (str, "}"); previous_islink = false; } else { currentmarktag--; switch (marktags[currentmarktag]) { case 'b': case 'B': g_string_append (str, "</b>"); previous_islink = false; break; case 'I': g_string_append (str, "</i>"); previous_islink = false; break; case '+': g_string_append (str, "</sup>"); previous_islink = false; break; case '-': g_string_append (str, "</sub>"); previous_islink = false; break; case 'x': g_string_append (str, "</span>"); previous_islink = false; break; case 'l': case 'D': case 'L': case 'U': g_string_append (str, "</span>"); previous_islink = true; break; default: previous_islink = false; break; } } break; case '&': find = false; if (next!=end) { n = g_utf8_next_char(next); if (n!=end && *n == '{') { find=true; currentmarktag++; if (marktags.length()<currentmarktag) marktags+=*next; else marktags[currentmarktag-1]=*next; switch (*next) { case 'b': case 'B': g_string_append (str, "<b>"); next = n+1; break; case 'I': g_string_append (str, "<i>"); next = n+1; break; case '+': g_string_append (str, "<sup>"); next = n+1; break; case '-': g_string_append (str, "<sub>"); next = n+1; break; case 'x': g_string_append (str, "<span foreground=\"blue\" underline=\"single\">"); next = n+1; break; case 'X': case '2': { const gchar *tag_end = n+1; while (tag_end!=end) { if (*tag_end=='}') break; else tag_end++; } g_string_append (str, "<span foreground=\"blue\">"); gchar *tag_str; if (*next == 'X') { tag_str = toUtfPhonetic(n+1, tag_end - (n+1)); } else { tag_str = toUtfPhonetic2(n+1, tag_end - (n+1)); } g_string_append (str, tag_str); g_free(tag_str); g_string_append (str, "</span>"); currentmarktag--; if (tag_end!=end) next = tag_end+1; else next = end; previous_islink = false; break; } case 'l': case 'D': case 'L': case 'U': if (previous_islink) g_string_append (str, "\t"); if (*next == 'l' || *next == 'D') g_string_append (str, "<span foreground=\"blue\" underline=\"single\">"); else g_string_append (str, "<span foreground=\"#008080\" underline=\"single\">"); *pango += str->str; cur_pos += xml_strlen(str->str); g_string_erase(str, 0, -1); { const gchar *tag_end = n+1; while (tag_end!=end) { if (*tag_end=='}') break; else tag_end++; } char *tmpstr = g_markup_escape_text(n+1, tag_end - (n+1)); size_t xml_len = xml_strlen(tmpstr); std::string link("query://"); link.append(n+1, tag_end - (n+1)); links_list->push_back(LinkDesc(cur_pos, xml_len, link)); *pango += tmpstr; cur_pos += xml_len; g_free(tmpstr); g_string_append (str, "</span>"); currentmarktag--; if (tag_end!=end) next = tag_end+1; else next = end; previous_islink = true; break; } /*case ' ': case '9': case 'S':*/ default: next = n+1; break; } } } if (!find) { previous_islink = false; g_string_append (str, "&"); } break; case '<': previous_islink = false; g_string_append (str, "<"); break; case '>': previous_islink = false; g_string_append (str, ">"); break; case '\'': previous_islink = false; g_string_append (str, "'"); break; case '"': previous_islink = false; g_string_append (str, """); break; default: previous_islink = false; g_string_append_len (str, p, next - p); break; } p = next; } if (currentmarktag>0) { do { currentmarktag--; switch (marktags[currentmarktag]) { case 'b': case 'B': g_string_append (str, "</b>"); break; case 'I': g_string_append (str, "</i>"); break; case '+': g_string_append (str, "</sup>"); break; case '-': g_string_append (str, "</sub>"); break; case 'x': case 'l': case 'D': case 'L': case 'U': g_string_append (str, "</span>"); break; default: break; } } while (currentmarktag>0); } *pango += str->str; cur_pos += xml_strlen(str->str); g_string_free (str, TRUE); }
static gboolean test_case_assert_stacking (TestCase *test, char **expected_windows, int n_expected_windows, GError **error) { MetaDisplay *display = meta_get_display (); guint64 *windows; int n_windows; GString *stack_string = g_string_new (NULL); GString *expected_string = g_string_new (NULL); int i; meta_stack_tracker_get_stack (display->screen->stack_tracker, &windows, &n_windows); for (i = 0; i < n_windows; i++) { MetaWindow *window = meta_display_lookup_stack_id (display, windows[i]); if (window != NULL && window->title) { /* See comment in meta_ui_new() about why the dummy window for GTK+ theming * is managed as a MetaWindow. */ if (META_STACK_ID_IS_X11 (windows[i]) && meta_ui_window_is_dummy (display->screen->ui, windows[i])) continue; if (stack_string->len > 0) g_string_append_c (stack_string, ' '); if (g_str_has_prefix (window->title, "test/")) g_string_append (stack_string, window->title + 5); else g_string_append_printf (stack_string, "(%s)", window->title); } else if (windows[i] == display->screen->guard_window) { if (stack_string->len > 0) g_string_append_c (stack_string, ' '); g_string_append_c (stack_string, '|'); } } for (i = 0; i < n_expected_windows; i++) { if (expected_string->len > 0) g_string_append_c (expected_string, ' '); g_string_append (expected_string, expected_windows[i]); } /* Don't require '| ' as a prefix if there are no hidden windows - we * remove the prefix from the actual string instead of adding it to the * expected string for clarity of the error message */ if (index (expected_string->str, '|') == NULL && stack_string->str[0] == '|') { g_string_erase (stack_string, 0, stack_string->str[1] == ' ' ? 2 : 1); } if (strcmp (expected_string->str, stack_string->str) != 0) { g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED, "stacking: expected='%s', actual='%s'", expected_string->str, stack_string->str); } g_string_free (stack_string, TRUE); g_string_free (expected_string, TRUE); return *error == NULL; }
gboolean gebr_comm_protocol_receive_data(struct gebr_comm_protocol *protocol, GString * data) { gchar **splits; gboolean reached_end = FALSE; while (!reached_end && data->len) { gsize missing; /* if so, this is a new message; otherwise, another part * of the argument of protocol->message */ if (!protocol->message->hash) { gint erase_len; gchar *strtol_endptr; splits = g_strsplit(data->str, " ", 3); gint n_tokens = g_strv_length(splits); if (n_tokens < 2) goto err; /* code */ if (g_hash_table_lookup(gebr_comm_protocol_defs.hash_table, splits[0]) == NULL) { g_string_assign(data, ""); goto err; } protocol->message->hash = g_str_hash(splits[0]); /* argument size */ strtol_endptr = NULL; protocol->message->argument_size = strtol(splits[1], &strtol_endptr, 10); if (errno == ERANGE) goto err; /* the missing bytes to complete the read of argument */ missing = protocol->message->argument_size; /* erase code and size from data */ erase_len = strlen(splits[0]) + 1 + strlen(splits[1]) + ((n_tokens == 2) ? 0 : 1); g_string_erase(data, 0, erase_len); g_strfreev(splits); } else { missing = protocol->message->argument_size - protocol->message->argument->len; } /* if so, protocol->message has now received its * argument entirely using > because there must be a line feed. */ reached_end = data->len > missing; if (reached_end) { struct gebr_comm_message *queued; g_string_append_len(protocol->message->argument, data->str, missing); g_string_erase(data, 0, missing + 1); /* add to the list of messages */ queued = protocol->message; protocol->messages = g_list_prepend(protocol->messages, queued); protocol->message = gebr_comm_message_new(); } else { g_string_append(protocol->message->argument, data->str); g_string_erase(data, 0, -1); } } return TRUE; err: g_strfreev(splits); return FALSE; }
static int key_action_tab_comp (GtkWidget *t, GdkEventKey *entry, char *d1, char *d2, struct session *sess) { int len = 0, elen = 0, i = 0, cursor_pos, ent_start = 0, comp = 0, prefix_len, skip_len = 0; gboolean is_nick = FALSE, is_cmd = FALSE, found = FALSE, has_nick_prefix = FALSE; char ent[CHANLEN], *postfix = NULL, *result, *ch; GList *list = NULL, *tmp_list = NULL; const char *text; GCompletion *gcomp = NULL; GString *buf; /* force the IM Context to reset */ SPELL_ENTRY_SET_EDITABLE (t, FALSE); SPELL_ENTRY_SET_EDITABLE (t, TRUE); text = SPELL_ENTRY_GET_TEXT (t); if (text[0] == 0) return 1; len = g_utf8_strlen (text, -1); /* must be null terminated */ cursor_pos = SPELL_ENTRY_GET_POS (t); /* handle "nick: " or "nick " or "#channel "*/ ch = g_utf8_find_prev_char(text, g_utf8_offset_to_pointer(text,cursor_pos)); if (ch && ch[0] == ' ') { skip_len++; ch = g_utf8_find_prev_char(text, ch); if (!ch) return 2; cursor_pos = g_utf8_pointer_to_offset(text, ch); if (cursor_pos && (g_utf8_get_char_validated(ch, -1) == ':' || g_utf8_get_char_validated(ch, -1) == ',' || g_utf8_get_char_validated (ch, -1) == g_utf8_get_char_validated (prefs.hex_completion_suffix, -1))) { skip_len++; } else cursor_pos = g_utf8_pointer_to_offset(text, g_utf8_offset_to_pointer(ch, 1)); } comp = skip_len; /* store the text following the cursor for reinsertion later */ if ((cursor_pos + skip_len) < len) postfix = g_utf8_offset_to_pointer(text, cursor_pos + skip_len); for (ent_start = cursor_pos; ; --ent_start) { if (ent_start == 0) break; ch = g_utf8_offset_to_pointer(text, ent_start - 1); if (ch && ch[0] == ' ') break; } if (ent_start == 0 && text[0] == prefs.hex_input_command_char[0]) { ent_start++; is_cmd = TRUE; } else if (strchr (sess->server->chantypes, text[ent_start]) == NULL) { is_nick = TRUE; if (strchr (sess->server->nick_prefixes, text[ent_start]) != NULL) { if (ent_start == 0) has_nick_prefix = TRUE; ent_start++; } } prefix_len = ent_start; elen = cursor_pos - ent_start; g_utf8_strncpy (ent, g_utf8_offset_to_pointer (text, prefix_len), elen); if (sess->type == SESS_DIALOG && is_nick) { /* tab in a dialog completes the other person's name */ if (rfc_ncasecmp (sess->channel, ent, elen) == 0) { result = sess->channel; is_nick = FALSE; } else return 2; } else { if (is_nick) { gcomp = g_completion_new((GCompletionFunc)gcomp_nick_func); tmp_list = userlist_double_list(sess); /* create a temp list so we can free the memory */ if (prefs.hex_completion_sort == 1) /* sort in last-talk order? */ tmp_list = g_list_sort (tmp_list, (void *)talked_recent_cmp); } else { gcomp = g_completion_new (NULL); if (is_cmd) { tmp_list = cmdlist_double_list (command_list); for(i = 0; xc_cmds[i].name != NULL ; i++) { tmp_list = g_list_prepend (tmp_list, xc_cmds[i].name); } tmp_list = plugin_command_list(tmp_list); } else tmp_list = chanlist_double_list (sess_list); } tmp_list = g_list_reverse(tmp_list); /* make the comp entries turn up in the right order */ g_completion_set_compare (gcomp, (GCompletionStrncmpFunc)rfc_ncasecmp); if (tmp_list) { g_completion_add_items (gcomp, tmp_list); g_list_free (tmp_list); } if (comp && !(rfc_ncasecmp(old_gcomp.data, ent, old_gcomp.elen) == 0)) { key_action_tab_clean (); comp = 0; } list = g_completion_complete_utf8 (gcomp, comp ? old_gcomp.data : ent, &result); if (result == NULL) /* No matches found */ { g_completion_free(gcomp); return 2; } if (comp) /* existing completion */ { while(list) /* find the current entry */ { if(rfc_ncasecmp(list->data, ent, elen) == 0) { found = TRUE; break; } list = list->next; } if (found) { if (!(d1 && d1[0])) /* not holding down shift */ { if (g_list_next(list) == NULL) list = g_list_first(list); else list = g_list_next(list); } else { if (g_list_previous(list) == NULL) list = g_list_last(list); else list = g_list_previous(list); } g_free(result); result = (char*)list->data; } else { g_free(result); g_completion_free(gcomp); return 2; } } else { strcpy(old_gcomp.data, ent); old_gcomp.elen = elen; /* Get the first nick and put out the data for future nickcompletes */ if (prefs.hex_completion_amount > 0 && g_list_length (list) <= (guint) prefs.hex_completion_amount) { g_free(result); result = (char*)list->data; } else { /* bash style completion */ if (g_list_next(list) != NULL) { buf = g_string_sized_new (MAX(COMP_BUF, len + NICKLEN)); if (strlen (result) > elen) /* the largest common prefix is larger than nick, change the data */ { if (prefix_len) g_string_append_len (buf, text, offset_to_len (text, prefix_len)); g_string_append (buf, result); cursor_pos = buf->len; g_free(result); if (postfix) { g_string_append_c (buf, ' '); g_string_append (buf, postfix); } SPELL_ENTRY_SET_TEXT (t, buf->str); SPELL_ENTRY_SET_POS (t, len_to_offset (buf->str, cursor_pos)); g_string_erase (buf, 0, -1); } else g_free(result); while (list) { len = buf->len; elen = strlen (list->data); /* next item to add */ if (len + elen + 2 >= COMP_BUF) /* +2 is space + null */ { PrintText (sess, buf->str); g_string_erase (buf, 0, -1); } g_string_append (buf, (char*)list->data); g_string_append_c (buf, ' '); list = list->next; } PrintText (sess, buf->str); g_completion_free(gcomp); g_string_free (buf, TRUE); return 2; } /* Only one matching entry */ g_free(result); result = list->data; } } } if(result) { buf = g_string_sized_new (len + NICKLEN); if (prefix_len) g_string_append_len (buf, text, offset_to_len (text, prefix_len)); g_string_append (buf, result); if((!prefix_len || has_nick_prefix) && is_nick && prefs.hex_completion_suffix[0] != '\0') g_string_append_unichar (buf, g_utf8_get_char_validated (prefs.hex_completion_suffix, -1)); g_string_append_c (buf, ' '); cursor_pos = buf->len; if (postfix) g_string_append (buf, postfix); SPELL_ENTRY_SET_TEXT (t, buf->str); SPELL_ENTRY_SET_POS (t, len_to_offset (buf->str, cursor_pos)); g_string_free (buf, TRUE); } if (gcomp) g_completion_free(gcomp); return 2; }
//Read tcp requests of connected clients gboolean network_read(GIOChannel *source, GIOCondition cond, gpointer data) { GString *s = g_string_new(NULL); GError *error = NULL; GIOStatus ret = g_io_channel_read_line_string(source, s, NULL, &error); if (ret == G_IO_STATUS_ERROR) { //unref connection GSocketAddress *sockaddr = g_socket_connection_get_remote_address(data, NULL); GInetAddress *addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(sockaddr)); //Read sender ip if (verbose) { printf("App Server: Communication error.. Removing client.. ->%s\n", g_inet_address_to_string(addr)); fflush(stdout); } //Remove client remove_client(g_inet_address_to_string(addr)); //Free objects g_string_free(s, TRUE); g_object_unref(sockaddr); g_object_unref(addr); g_object_unref(data); //Return false to stop listening this socket return FALSE; } else{ //Read request command gchar *RecString; RecString=s->str; //check client password if ((strncmp(RecString, AppPass, strlen(AppPass))) == 0) { //Password ok can send command GString *incs = g_string_new(s->str); incs = g_string_erase(s,0,(strlen(AppPass)+1)); IvySendMsg("%s",incs->str); if (verbose) { printf("App Server: Command passed to ivy: %s\n",incs->str); fflush(stdout); } } //AC data request. (Ignore client password) else if ((strncmp(RecString, "getac ", strlen("getac "))) == 0) { //AC data request char AcData[BUFLEN]; //Read ac data if (get_ac_data(RecString, AcData)) { //Send requested data to client GOutputStream * ostream = g_io_stream_get_output_stream (data); g_output_stream_write(ostream, AcData, strlen(AcData), NULL, &error); } } //Waypoint data request (Ignore client password) else if ((strncmp(RecString, "getwp ", strlen("getwp "))) == 0) { char AcData[BUFLEN]; //Read wp data of ac if (get_wp_data(RecString, AcData)) { //Send requested data to client GOutputStream * ostream = g_io_stream_get_output_stream (data); g_output_stream_write(ostream, AcData, strlen(AcData), NULL, &error); } } //Waypoint data request (Ignore client password) else if ((strncmp(RecString, "getbl ", strlen("getbl "))) == 0) { char AcData[BUFLEN]; //Read block data of AC if (get_bl_data(RecString, AcData)) { //Send requested data to client GOutputStream * ostream = g_io_stream_get_output_stream (data); g_output_stream_write(ostream, AcData, strlen(AcData), NULL, &error); } } //If client sends removeme command, remove it from broadcast list else if ((strncmp( RecString, "removeme", strlen("removeme"))) == 0) { GSocketAddress *sockaddr = g_socket_connection_get_remote_address(data, NULL); GInetAddress *addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(sockaddr)); //Read sender ip if (verbose) { printf("App Server: need to remove %s\n", g_inet_address_to_string(addr)); fflush(stdout); } //Remove client remove_client(g_inet_address_to_string(addr)); //Free objects g_string_free(s, TRUE); g_object_unref(sockaddr); g_object_unref(addr); g_object_unref(data); //Return false to stop listening this socket return FALSE; } else { //Unknown command if (verbose) { printf("App Server: Client send an unknown command or wrong password: (%s)\n",RecString); fflush(stdout); } } } if (ret == G_IO_STATUS_EOF) { //Client disconnected if (verbose) { GSocketAddress *sockaddr = g_socket_connection_get_remote_address(data, NULL); GInetAddress *addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(sockaddr)); printf("App Server: Client disconnected without saying 'bye':( ->%s\n", g_inet_address_to_string(addr)); remove_client(g_inet_address_to_string(addr)); fflush(stdout); } g_string_free(s, TRUE); //Unref the socket and return false to allow the client to reconnect g_object_unref(data); return FALSE; } //None above.. Keep listening the socket g_string_free(s, TRUE); return TRUE; }
/* Parse the data section of VCD */ static void parse_contents(FILE *file, const struct sr_dev_inst *sdi, struct context *ctx) { GString *token = g_string_sized_new(32); uint64_t prev_timestamp = 0; uint64_t prev_values = 0; /* Read one space-delimited token at a time. */ while (read_until(file, NULL, 'N') && read_until(file, token, 'W')) { if (token->str[0] == '#' && g_ascii_isdigit(token->str[1])) { /* Numeric value beginning with # is a new timestamp value */ uint64_t timestamp; timestamp = strtoull(token->str + 1, NULL, 10); if (ctx->downsample > 1) timestamp /= ctx->downsample; /* Skip < 0 => skip until first timestamp. * Skip = 0 => don't skip * Skip > 0 => skip until timestamp >= skip. */ if (ctx->skip < 0) { ctx->skip = timestamp; prev_timestamp = timestamp; } else if (ctx->skip > 0 && timestamp < (uint64_t)ctx->skip) { prev_timestamp = ctx->skip; } else if (timestamp == prev_timestamp) { /* Ignore repeated timestamps (e.g. sigrok outputs these) */ } else { if (ctx->compress != 0 && timestamp - prev_timestamp > ctx->compress) { /* Compress long idle periods */ prev_timestamp = timestamp - ctx->compress; } sr_dbg("New timestamp: %" PRIu64, timestamp); /* Generate samples from prev_timestamp up to timestamp - 1. */ send_samples(sdi, prev_values, timestamp - prev_timestamp); prev_timestamp = timestamp; } } else if (token->str[0] == '$' && token->len > 1) { /* This is probably a $dumpvars, $comment or similar. * $dump* contain useful data, but other tags will be skipped until $end. */ if (g_strcmp0(token->str, "$dumpvars") == 0 || g_strcmp0(token->str, "$dumpon") == 0 || g_strcmp0(token->str, "$dumpoff") == 0 || g_strcmp0(token->str, "$end") == 0) { /* Ignore, parse contents as normally. */ } else { /* Skip until $end */ read_until(file, NULL, '$'); } } else if (strchr("bBrR", token->str[0]) != NULL) { /* A vector value. Skip it and also the following identifier. */ read_until(file, NULL, 'N'); read_until(file, NULL, 'W'); } else if (strchr("01xXzZ", token->str[0]) != NULL) { /* A new 1-bit sample value */ int i, bit; GSList *l; struct probe *probe; bit = (token->str[0] == '1'); g_string_erase(token, 0, 1); if (token->len == 0) { /* There was a space between value and identifier. * Read in the rest. */ read_until(file, NULL, 'N'); read_until(file, token, 'W'); } for (i = 0, l = ctx->probes; i < ctx->probecount && l; i++, l = l->next) { probe = l->data; if (g_strcmp0(token->str, probe->identifier) == 0) { sr_dbg("Probe %d new value %d.", i, bit); /* Found our probe */ if (bit) prev_values |= (1 << i); else prev_values &= ~(1 << i); break; } } if (i == ctx->probecount) { sr_dbg("Did not find probe for identifier '%s'.", token->str); } } else { sr_warn("Skipping unknown token '%s'.", token->str); } g_string_truncate(token, 0); } g_string_free(token, TRUE); }
static void log_handler(const char *log_domain, GLogLevelFlags log_level, const char *message, void *user_data) { const char *prefix; GString *gstr; if (log_level & G_LOG_FLAG_RECURSION) { g_print("bigboard-buttons: log recursed\n"); return; } switch (log_level & G_LOG_LEVEL_MASK) { case G_LOG_LEVEL_DEBUG: if (!log_debug_messages) return; prefix = "DEBUG: "; break; case G_LOG_LEVEL_WARNING: prefix = "WARNING: "; break; case G_LOG_LEVEL_CRITICAL: prefix = "CRITICAL: "; break; case G_LOG_LEVEL_ERROR: prefix = "ERROR: "; break; case G_LOG_LEVEL_INFO: prefix = "INFO: "; break; case G_LOG_LEVEL_MESSAGE: prefix = "MESSAGE: "; break; default: prefix = ""; break; } gstr = g_string_new(log_domain); g_string_append(gstr, " "); g_string_append(gstr, prefix); g_string_append(gstr, message); /* no newline here, the print_debug_func is supposed to add it */ if (gstr->str[gstr->len - 1] == '\n') { g_string_erase(gstr, gstr->len - 1, 1); } #ifdef GUI_LOG log_to_text_view(gstr->str); #else g_printerr("%s\n", gstr->str); #endif g_string_free(gstr, TRUE); #ifdef G_OS_WIN32 // glib will do this for us, but if we abort in our own code which has // debug symbols, visual studio gets less confused about the backtrace. // at least, that's my experience. if (log_level & G_LOG_FLAG_FATAL) { if (IsDebuggerPresent()) G_BREAKPOINT(); abort(); } #endif }
/* Given a GString containing MMD source, and optional base directory, substitute transclusion references in the source Pass the path to the current folder if available -- should be a full path. Keep track of what we're parsing to prevent recursion using stack. */ void transclude_source(GString *source, char *basedir, char *stack, int output_format, GString *manifest) { char *base = NULL; char *path = NULL; char *start; char *stop; char *temp; int curchar; size_t pos; char real[1000]; FILE *input; int offset; if (basedir == NULL) { base = strdup(""); } else { base = strdup(basedir); } GString *folder = NULL; GString *filename = NULL; GString *filebuffer = NULL; GString *stackstring = NULL; path = strdup(base); /* Look for override folder inside document */ if (has_metadata(source->str, 0x000000)) { char *meta = extract_metadata_value(source->str, 0x000000, "transcludebase"); if (meta != NULL) path = path_from_dir_base(base, meta); } if (path == NULL) { /* We have nowhere to look, so nothing to do */ free(path); free(base); return; } folder = g_string_new(path); /* Ensure that folder ends in "/" */ /* TODO: adjust for windows */ if (!(folder->str[strlen(folder->str)-1] == '/') ) { g_string_append_c(folder, '/'); } /* fprintf(stderr, "Transclude using '%s'\n", folder->str); */ /* Iterate through {{foo.txt}} and substitute contents of file without metadata */ start = strstr(source->str,"{{"); while (start != NULL) { stop = strstr(start,"}}"); if (stop == NULL) break; /* Check that we found something reasonable -- we cap at 1000 characters */ if (stop - start < 1000) { strncpy(real,start+2,stop-start-2); real[stop-start-2] = '\0'; #if defined(__WIN32) char sep = '\\'; #else char sep = '/'; #endif if (real[0] == sep) { filename = g_string_new(real); } else { filename = g_string_new(folder->str); g_string_append_printf(filename, "%s",real); } if (strcmp(filename->str,"./TOC") == 0) { pos = stop - source->str; start = strstr(source->str + pos,"{{"); g_string_free(filename, true); continue; } /* Adjust for wildcard extensions */ /* But not if output_format == 0 */ if (output_format && strncmp(&filename->str[strlen(filename->str) - 2],".*",2) == 0) { g_string_erase(filename, strlen(filename->str) - 2, 2); if (output_format == TEXT_FORMAT) { g_string_append(filename,".txt"); } else if (output_format == HTML_FORMAT) { g_string_append(filename,".html"); } else if (output_format == LATEX_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == BEAMER_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == MEMOIR_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == ODF_FORMAT) { g_string_append(filename,".fodt"); } else if (output_format == OPML_FORMAT) { g_string_append(filename,".opml"); } else if (output_format == LYX_FORMAT) { g_string_append(filename,".lyx"); } else if (output_format == RTF_FORMAT) { g_string_append(filename,".rtf"); } else { /* default extension -- in this case we only have 1 */ g_string_append(filename,".txt"); } } pos = stop - source->str; /* Add to the manifest (if not already included) */ if (manifest != NULL) { temp = strstr(manifest->str,filename->str); offset = temp - manifest->str; if ((temp != NULL) && ((temp == manifest->str) || ((manifest->str)[offset - 1] == '\n')) && (temp[strlen(filename->str)] == '\n') ){ /* Already on manifest, so don't add again */ } else { g_string_append_printf(manifest,"%s\n",filename->str); } } /* Don't reparse ourselves */ if (stack != NULL) { temp = strstr(stack,filename->str); if ((temp != NULL) && (temp[strlen(filename->str)] == '\n')){ start = strstr(source->str + pos,"{{"); g_string_free(filename, true); continue; } } /* Read file */ #if defined(__WIN32) int wchars_num = MultiByteToWideChar(CP_UTF8, 0, filename->str, -1, NULL, 0); wchar_t wstr[wchars_num]; MultiByteToWideChar(CP_UTF8, 0, filename->str, -1, wstr, wchars_num); if ((input = _wfopen(wstr, L"r")) != NULL ) { #else if ((input = fopen(filename->str, "r")) != NULL ) { #endif filebuffer = g_string_new(""); while ((curchar = fgetc(input)) != EOF) g_string_append_c(filebuffer, curchar); fclose(input); pos = start - source->str; g_string_erase(source, pos, 2 + stop - start); /* Update stack list */ stackstring = g_string_new(stack); g_string_append_printf(stackstring,"%s\n",filename->str); /* Recursively transclude files */ /* We want to reset the base directory if we enter a subdirectory */ char * new_dir; char * file_only; split_path_file(&new_dir, &file_only, filename->str); /* transclude_source(filebuffer, folder->str, stackstring->str, output_format, manifest); */ transclude_source(filebuffer, new_dir, stackstring->str, output_format, manifest); free(new_dir); free(file_only); temp = source_without_metadata(filebuffer->str, 0x000000); g_string_insert(source, pos, temp); pos += strlen(temp); g_string_free(filebuffer, true); g_string_free(stackstring, true); } else { /* fprintf(stderr, "error opening file: %s\n", filename->str); */ } g_string_free(filename, true); } else { /* Our "match" was > 1000 characters long */ pos = stop - source->str; } start = strstr(source->str + pos,"{{"); } g_string_free(folder, true); free(path); free(base); } /* Allow for a footer to specify files to be appended to the end of the text, and then transcluded. Useful for appending a list of footnotes, citations, abbreviations, etc. to each separate file, but not including multiple copies when processing the master file. */ void append_mmd_footer(GString *source) { /* Look for mmd_footer metadata */ if (has_metadata(source->str, 0x000000)) { char *meta = extract_metadata_value(source->str, 0x000000, "mmdfooter"); if (meta != NULL) g_string_append_printf(source, "\n\n{{%s}}\n", meta); } } void prepend_mmd_header(GString *source) { /* Same thing, but to be inserted after metadata and before content */ if (has_metadata(source->str, 0x000000)) { char *meta = extract_metadata_value(source->str, 0x000000, "mmdheader"); if (meta != NULL) { char *content = strstr(source->str, "\n\n"); if (content != NULL) { size_t pos = content - source->str; g_string_insert_printf(source, pos, "\n\n{{%s}}", meta); } else { g_string_append_printf(source, "\n\n{{%s}}\n", meta); } } } }
static int process_buffer(struct sr_input *in) { struct context *inc; struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; struct sr_config *src; int offset, chunk_samples, total_samples, processed, max_chunk_samples; int num_samples, i; char channelname[8]; inc = in->priv; if (!inc->started) { for (i = 0; i < inc->num_channels; i++) { snprintf(channelname, 8, "CH%d", i + 1); sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname); } std_session_send_df_header(in->sdi, LOG_PREFIX); packet.type = SR_DF_META; packet.payload = &meta; src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); sr_config_free(src); inc->started = TRUE; } if (!inc->found_data) { /* Skip past size of 'fmt ' chunk. */ i = 20 + RL32(in->buf->str + 16); offset = find_data_chunk(in->buf, i); if (offset < 0) { if (in->buf->len > MAX_DATA_CHUNK_OFFSET) { sr_err("Couldn't find data chunk."); return SR_ERR; } } inc->found_data = TRUE; } else offset = 0; /* Round off up to the last channels * unitsize boundary. */ chunk_samples = (in->buf->len - offset) / inc->num_channels / inc->unitsize; max_chunk_samples = CHUNK_SIZE / inc->num_channels / inc->unitsize; processed = 0; total_samples = chunk_samples; while (processed < total_samples) { if (chunk_samples > max_chunk_samples) num_samples = max_chunk_samples; else num_samples = chunk_samples; send_chunk(in, offset, num_samples); offset += num_samples * inc->unitsize; chunk_samples -= num_samples; processed += num_samples; } if ((unsigned int)offset < in->buf->len) { /* * The incoming buffer wasn't processed completely. Stash * the leftover data for next time. */ g_string_erase(in->buf, 0, offset); } else g_string_truncate(in->buf, 0); return SR_OK; }
static gint xmms_faad_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len, xmms_error_t *err) { xmms_faad_data_t *data; xmms_error_t error; faacDecFrameInfo frameInfo; gpointer sample_buffer; guint size, bytes_read = 0; data = xmms_xform_private_data_get (xform); g_return_val_if_fail (data, -1); size = MIN (data->outbuf->len, len); while (size == 0) { gboolean need_read; /* MP4 demuxer always gives full packets so we need different handling */ if (data->filetype == FAAD_TYPE_MP4) need_read = (data->buffer_length == 0); else need_read = (data->buffer_length < data->buffer_size); if (need_read) { bytes_read = xmms_xform_read (xform, (gchar *) data->buffer + data->buffer_length, data->buffer_size - data->buffer_length, &error); if (bytes_read <= 0 && data->buffer_length == 0) { XMMS_DBG ("EOF"); return 0; } data->buffer_length += bytes_read; } sample_buffer = faacDecDecode (data->decoder, &frameInfo, data->buffer, data->buffer_length); g_memmove (data->buffer, data->buffer + frameInfo.bytesconsumed, data->buffer_length - frameInfo.bytesconsumed); data->buffer_length -= frameInfo.bytesconsumed; bytes_read = frameInfo.samples * xmms_sample_size_get (data->sampleformat); if (bytes_read > 0 && frameInfo.error == 0) { gint32 temp, toskip = 0; if (data->samplerate != frameInfo.samplerate || data->channels != frameInfo.channels) { /* We should inform output to change parameters somehow */ XMMS_DBG ("Output format changed in the middle of a read!"); data->samplerate = frameInfo.samplerate; data->channels = frameInfo.channels; } if (xmms_xform_auxdata_get_int (xform, "frame_offset", &temp)) { toskip = (temp * frameInfo.channels * xmms_sample_size_get (data->sampleformat)); } if (xmms_xform_auxdata_get_int (xform, "frame_duration", &temp)) { bytes_read = (temp * frameInfo.channels * xmms_sample_size_get (data->sampleformat)); } g_string_append_len (data->outbuf, sample_buffer + toskip, bytes_read - toskip); } else if (frameInfo.error > 0) { XMMS_DBG ("ERROR %d in faad decoding: %s", frameInfo.error, faacDecGetErrorMessage (frameInfo.error)); return -1; } size = MIN (data->outbuf->len, len); } memcpy (buf, data->outbuf->str, size); g_string_erase (data->outbuf, 0, size); return size; }
/* Given a GString containing MMD source, and optional base directory, substitute transclusion references in the source Pass the path to the current folder if available -- should be a full path. Keep track of what we're parsing to prevent recursion using stack. */ void transclude_source(GString *source, char *basedir, char *stack, int output_format) { char *base = NULL; char *path = NULL; char *start; char *stop; char *temp; int curchar; size_t pos; char real[1000]; FILE *input; if (basedir == NULL) { base = strdup(""); } else { base = strdup(basedir); } GString *folder = NULL; GString *filename = NULL; GString *filebuffer = NULL; GString *stackstring = NULL; path = strdup(base); /* Look for override folder inside document */ if (has_metadata(source->str, 0x000000)) { char *meta = extract_metadata_value(source->str, 0x000000, "transcludebase"); if (meta != NULL) path = path_from_dir_base(base, meta); } if (path == NULL) { /* We have nowhere to look, so nothing to do */ free(path); free(base); return; } folder = g_string_new(path); /* Ensure that folder ends in "/" */ /* TODO: adjust for windows */ if (!(folder->str[strlen(folder->str)-1] == '/') ) { g_string_append_c(folder, '/'); } //fprintf(stderr, "Transclude using '%s'\n", folder->str); /* Iterate through {{foo.txt}} and substitute contents of file without metadata */ start = strstr(source->str,"{{"); while (start != NULL) { stop = strstr(start,"}}"); if (stop == NULL) break; // TODO: Need to check that we found something reasonable strncpy(real,start+2,stop-start-2); real[stop-start-2] = '\0'; filename = g_string_new(folder->str); g_string_append_printf(filename, "%s",real); /* Adjust for wildcard extensions */ /* But not if output_format == 0 */ if (output_format && strncmp(&filename->str[strlen(filename->str) - 2],".*",2) == 0) { g_string_erase(filename, strlen(filename->str) - 2, 2); if (output_format == TEXT_FORMAT) { g_string_append(filename,".txt"); } else if (output_format == HTML_FORMAT) { g_string_append(filename,".html"); } else if (output_format == LATEX_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == BEAMER_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == MEMOIR_FORMAT) { g_string_append(filename,".tex"); } else if (output_format == ODF_FORMAT) { g_string_append(filename,".fodt"); } else if (output_format == OPML_FORMAT) { g_string_append(filename,".opml"); } else if (output_format == LYX_FORMAT) { g_string_append(filename,".lyx"); } else if (output_format == RTF_FORMAT) { g_string_append(filename,".rtf"); } else { /* default extension -- in this case we only have 1 */ g_string_append(filename,".txt"); } } pos = stop - source->str; /* Don't reparse ourselves */ if (stack != NULL) { temp = strstr(stack,filename->str); if ((temp != NULL) && (temp[strlen(filename->str)] == '\n')){ start = strstr(source->str + pos,"{{"); g_string_free(filename, true); continue; } } /* Read file */ if ((input = fopen(filename->str, "r")) != NULL ) { filebuffer = g_string_new(""); while ((curchar = fgetc(input)) != EOF) g_string_append_c(filebuffer, curchar); fclose(input); pos = start - source->str; g_string_erase(source, pos, 2 + stop - start); /* Update stack list */ stackstring = g_string_new(stack); g_string_append_printf(stackstring,"%s\n",filename->str); /* Recursively transclude files */ transclude_source(filebuffer, folder->str, stackstring->str, output_format); temp = source_without_metadata(filebuffer->str, 0x000000); g_string_insert(source, pos, temp); pos += strlen(temp); g_string_free(filebuffer, true); g_string_free(stackstring, true); } else { /* fprintf(stderr, "error opening file: %s\n", filename->str); */ } start = strstr(source->str + pos,"{{"); g_string_free(filename, true); } g_string_free(folder, true); free(path); free(base); }
/* Common XML format for both Bijiben / Tomboy */ static void processNode (BijiLazyDeserializer *self) { xmlTextReaderPtr r = self->priv->r; BijiNoteObj * n = self->priv->note; xmlChar *name; GdkRGBA color; gchar *tag, *color_str; GString *norm; name = xmlTextReaderName (r); if ( g_strcmp0((gchar*)name,"title") == 0 ) biji_process_string (r, (BijiReaderFunc*) biji_note_obj_set_title, n); if ( g_strcmp0((gchar*)name,"text") == 0 ) { if (self->priv->type == BIJIBEN_1) { process_bijiben_html_content (self, r); } else if (self->priv->type == TOMBOY_1 || self->priv->type == TOMBOY_2 || self->priv->type == TOMBOY_3 ) { self->priv->content = (gchar*) xmlTextReaderReadInnerXml (r); process_tomboy_xml_content (self); } } if (g_strcmp0 ((gchar*) name, "last-change-date") == 0) { gchar *result = (gchar*) xmlTextReaderReadString (r); biji_note_obj_set_mtime (n, iso8601_to_gint64 (result)); free (result); } if (g_strcmp0 ((gchar*) name, "last-metadata-change-date") == 0) { gchar *result = (gchar*) xmlTextReaderReadString (r); biji_note_obj_set_last_metadata_change_date (n, iso8601_to_gint64 (result)); free (result); } if (g_strcmp0 ((gchar*) name, "create-date") == 0) { gchar *result = (gchar*) xmlTextReaderReadString (r); biji_note_obj_set_create_date (n, iso8601_to_gint64 (result)); free (result); } if (g_strcmp0 ((gchar*) name, "color") == 0 ) { color_str = (gchar*) xmlTextReaderReadString (r); if (gdk_rgba_parse (&color, color_str)) biji_note_obj_set_rgba (n, &color); else g_warning ("color invalid:%s", color_str); free (color_str); } if ( g_strcmp0((gchar*)name,"tag") == 0 ) { tag = (gchar*) xmlTextReaderReadString(r); if (g_str_has_prefix (tag,"system:template")) { note_obj_set_is_template(n,TRUE); } else if (g_str_has_prefix (tag,"system:notebook:")) { norm = g_string_new (tag); g_string_erase (norm,0,16); biji_item_add_notebook (BIJI_ITEM (n), NULL, norm->str); g_string_free (norm, TRUE); } free (tag); } xmlFree(name); }
gint campfire_http_response(PurpleSslConnection * gsc, CampfireSslTransaction * xaction, G_GNUC_UNUSED PurpleInputCondition cond, G_GNUC_UNUSED xmlnode ** node) { gchar buf[1024]; GString *ssl_input; gint len, errsv = 0; gint status; CampfireHttpResponse *response = &xaction->http_response; if (response->rx_state == CAMPFIRE_HTTP_RX_DONE) { purple_debug_info("campfire", "somefin aint right.\n"); return -1; } /********************************************************************** * read input from file descriptor *********************************************************************/ ssl_input = g_string_new(""); errno = 0; while ((len = purple_ssl_read(gsc, buf, sizeof(buf))) > 0) { purple_debug_info("campfire", "read %d bytes from HTTP Response, errno: %i\n", len, errno); ssl_input = g_string_append_len(ssl_input, buf, len); } errsv = errno; /********************************************************************** * handle return value of ssl input read *********************************************************************/ if (len < 0 && errsv == EAGAIN) { if (ssl_input->len == 0) { purple_debug_info("campfire", "TRY AGAIN (returning)\n"); g_string_free(ssl_input, TRUE); return 0; } else { purple_debug_info("campfire", "EAGAIN (continuing)\n"); } } else if (len == 0) { purple_debug_info("campfire", "SERVER CLOSED CONNECTION\n"); if (ssl_input->len == 0) { g_string_free(ssl_input, TRUE); return -1; } } else { purple_debug_info("campfire", "LOST CONNECTION\n"); purple_debug_info("campfire", "errno: %d\n", errsv); g_string_free(ssl_input, TRUE); return -1; } if (!response->response) { response->response = g_string_new(""); } purple_debug_info("campfire", "ssl_input:\n%s", ssl_input->str); /********************************************************************** * process input with a simple state machine *********************************************************************/ while (!ssl_input_consumed(ssl_input)) { switch (response->rx_state) { case CAMPFIRE_HTTP_RX_HEADER: purple_debug_info("campfire", "CAMPFIRE_HTTP_RX_HEADER\n"); campfire_consume_http_header(response, ssl_input); if (campfire_http_header_received(response)) { campfire_process_http_header(response); response->rx_state = CAMPFIRE_HTTP_RX_CONTENT; } break; case CAMPFIRE_HTTP_RX_CONTENT: purple_debug_info("campfire", "CAMPFIRE_HTTP_RX_CONTENT\n"); campfire_consume_http_content(response, ssl_input); if (campfire_http_content_received(response)) { campfire_process_http_content(response); response->rx_state = CAMPFIRE_HTTP_RX_DONE; } break; case CAMPFIRE_HTTP_RX_DONE: purple_debug_info("campfire", "CAMPFIRE_HTTP_RX_DONE\n"); g_string_erase(ssl_input, 0, -1); /* consume input */ break; default: g_string_erase(ssl_input, 0, -1); /* consume input */ break; } } /********************************************************************** * return http status code: -1=error, 0=input_not_received *********************************************************************/ if (response->rx_state == CAMPFIRE_HTTP_RX_DONE) { status = response->status; } else { status = 0; } g_string_free(ssl_input, TRUE); return status; }