static Atom* parse_line(const gchar* ln) { static GRegex* re = NULL; GMatchInfo* mi = NULL; Atom* rv = NULL; if ( !re ) { re = g_regex_new("(-*)([A-Z]+)(?:\\((.+)*\\))?", G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL); } if ( g_regex_match(re, ln, 0, &mi) ) { gchar* dashes = g_match_info_fetch(mi, 1); rv = atom_new( identify(g_match_info_fetch(mi, 2)), dashes ? strlen(dashes) : 0, build_args(g_match_info_fetch(mi, 3))); g_match_info_free(mi); } return rv; }
static void scan_matches(GRegex *regex, const char *string, GPtrArray *dst) { GMatchInfo *match_info; char *match; g_regex_match(regex, string, G_REGEX_MATCH_NOTEMPTY, &match_info); while (g_match_info_matches(match_info)) { match = g_match_info_fetch(match_info, 1); g_ptr_array_add(dst, match); g_match_info_next(match_info, NULL); } g_match_info_free(match_info); }
static const gchar *regex_match(const gchar *pattern, const gchar *string) { g_autoptr(GRegex) regex = NULL; g_autoptr(GMatchInfo) match = NULL; g_return_val_if_fail(pattern, NULL); g_return_val_if_fail(string, NULL); regex = g_regex_new(pattern, 0, 0, NULL); if (g_regex_match(regex, string, 0, &match)) return g_match_info_fetch(match, 1); return NULL; }
static void git_stash_list_command_handle_output (GitCommand *git_command, const gchar *output) { GitStashListCommand *self; GMatchInfo *match_info; gchar *stash_id; gchar *stash_number; gchar *stash_message; GitStash *stash; self = GIT_STASH_LIST_COMMAND (git_command); match_info = NULL; stash_id = NULL; stash_message = NULL; stash = NULL; if (g_regex_match (self->priv->stash_regex, output, 0, &match_info)) { stash_id = g_match_info_fetch (match_info, 1); stash_number = g_match_info_fetch (match_info, 2); stash_message = g_match_info_fetch (match_info, 3); stash = git_stash_new (stash_id, stash_message, atoi (stash_number)); g_free (stash_id); g_free (stash_number); g_free (stash_message); g_queue_push_head (self->priv->output, stash); anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); } if (match_info) g_match_info_free (match_info); }
static gboolean misc_macro_expand_cb(const GMatchInfo *info, GString *result, gpointer user_data) { gchar *value = NULL; if (user_data != NULL) { MiscMacroExpandData *data = (MiscMacroExpandData*) user_data; if (data->table != NULL) { gchar *name = g_match_info_fetch(info, 1); if (name != NULL) { value = g_hash_table_lookup(data->table, name); g_free(name); } } } if (value != NULL) { g_string_append(result, value); } else { gchar *macro = g_match_info_fetch(info, 0); g_string_append(result, macro); g_free(macro); } return FALSE; }
static gboolean eval_cb (const GMatchInfo *info, GString *res, gpointer data) { gchar *var; gchar *n; gchar *key; gint nth; var = g_match_info_fetch(info, 1); n = g_match_info_fetch(info, 2); key = g_match_info_fetch(info, 3); nth = atoi(n); if (g_strcmp0(var, "prev") == 0) { GList *last = g_list_last(data); GList *item = g_list_nth_prev(last, nth - 1); if (item) { const gchar *val; hashfs_db_entry_t *entry = item->data; if (g_strcmp0(key, "pkey") == 0) { val = hashfs_db_entry_pkey(entry); g_string_append(res, val); } else { if (hashfs_db_entry_lookup(entry, key, &val)) g_string_append(res, val); } } } g_free(var); g_free(n); g_free(key); return FALSE; }
static gboolean parse_kernel_cmdline (gboolean *force_igpu) { gboolean ret = TRUE; GRegex *regex; GMatchInfo *match; char *contents; char *word; const char *arg; if (!g_file_get_contents ("/proc/cmdline", &contents, NULL, NULL)) return FALSE; regex = g_regex_new ("xdg.force_integrated=(\\S+)", 0, G_REGEX_MATCH_NOTEMPTY, NULL); if (!g_regex_match (regex, contents, G_REGEX_MATCH_NOTEMPTY, &match)) { ret = FALSE; goto out; } word = g_match_info_fetch (match, 0); g_debug ("Found command-line match '%s'", word); arg = word + strlen ("xdg.force_integrated="); if (*arg == '0' || *arg == '1') { *force_igpu = atoi (arg); } else if (g_ascii_strcasecmp (arg, "true") == 0 || g_ascii_strcasecmp (arg, "on") == 0) { *force_igpu = TRUE; } else if (g_ascii_strcasecmp (arg, "false") == 0 || g_ascii_strcasecmp (arg, "off") == 0) { *force_igpu = FALSE; } else { g_warning ("Invalid value '%s' for xdg.force_integrated passed in kernel command line.\n", arg); ret = FALSE; } g_free (word); out: g_match_info_free (match); g_regex_unref (regex); g_free (contents); if (ret) g_debug ("Kernel command-line parsed to %d", *force_igpu); else g_debug ("Could not parse kernel command-line"); return ret; }
int twitter_url_len_diff(gchar *msg, unsigned int target_len) { int url_len_diff = 0; static GRegex *regex = NULL; GMatchInfo *match_info; if (regex == NULL) regex = g_regex_new("(^|\\s)(http(s)?://[^\\s$]+)", 0, 0, NULL); g_regex_match(regex, msg, 0, &match_info); while (g_match_info_matches(match_info)) { gchar *url = g_match_info_fetch(match_info, 2); url_len_diff += target_len - g_utf8_strlen(url, -1); /* Add another character for https://t.co/... URLs */ if (g_match_info_fetch(match_info, 3) != NULL) url_len_diff += 1; g_free(url); g_match_info_next(match_info, NULL); } g_match_info_free(match_info); return url_len_diff; }
static void option_3g_tech_changed (MMPortSerialAt *port, GMatchInfo *match_info, MMBroadbandModemOption *self) { MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN; gchar *str; str = g_match_info_fetch (match_info, 1); if (str && owcti_to_mm (str[0], &act)) mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self), act, MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK); g_free (str); }
/** * Extract the host name and the remote file path from a URL. * @param remotePath [in] Remote filename as a URL. * @param hostname [out] Pointer to where the hostname is stored. * @param filename [out] Pointer to where the filepath is stored. * @return \a true if the host and file path could be extracted, or \a false * otherwise. * Test: unit test (test-uploadqueue.c). */ STATIC bool ExtractHostAndFilepath( const char *remotePath, char **hostname, char **filepath ) { GMatchInfo *matchInfo; /* Grep the hostname. */ g_regex_ref( regexes.hostname ); g_regex_match( regexes.hostname, remotePath, 0, &matchInfo ); *hostname = g_match_info_fetch( matchInfo, 2 ); g_match_info_free( matchInfo ); g_regex_unref( regexes.hostname ); /* Grep the file path. */ g_regex_ref( regexes.removeHost ); g_regex_match( regexes.removeHost, remotePath, 0, &matchInfo ); *filepath = g_match_info_fetch( matchInfo, 1 ); g_match_info_free( matchInfo ); g_regex_unref( regexes.removeHost ); return( true ); }
static int init_srvinfo(const gchar *sid, service_info_t *si) { GMatchInfo *mi = NULL; if (!g_regex_match(regex_svc, sid, 0, &mi)) { g_printerr("Unrecognized pattern for service id [%s]\n", sid); return -1; } else { gchar *str_ns, *str_type, *str_addr; str_ns = g_match_info_fetch(mi, 1); str_type = g_match_info_fetch(mi, 2); str_addr = g_match_info_fetch(mi, 3); g_free(mi); g_strlcpy(si->type, str_type, sizeof(si->type)-1); g_free(str_type); g_strlcpy(si->ns_name, str_ns, sizeof(si->ns_name)-1); g_free(str_ns); if (!l4_address_init_with_url(&(si->addr), str_addr, NULL)) { g_printerr("Invalid service address [%s]", str_addr); return -1; } g_free(str_addr); } if (!si->tags) si->tags = g_ptr_array_sized_new(6); service_tag_set_value_macro ( service_info_ensure_tag (si->tags, "stat.cpu"), NAME_MACRO_CPU_TYPE, NULL); return 0; }
static gboolean parse_http_status(MegaHttpClient* http_client, const gchar* line, gint* status, gchar** message) { MegaHttpClientPrivate* priv = http_client->priv; GMatchInfo *match_info = NULL; if (g_regex_match(priv->regex_status, line, 0, &match_info)) { if (status) { gchar* status_str = g_match_info_fetch(match_info, 2); *status = atoi(status_str); g_free(status_str); } if (message) *message = g_match_info_fetch(match_info, 3); g_match_info_free(match_info); return TRUE; } g_match_info_free(match_info); return FALSE; }
// Parse NCBI GIs from refseq descriptions and store GI to refseq mapping in a hashtable. // // bam_header Pointer to the header for one of the alignment BAM files. // refseq_gids Stored NCBI GI for each target sequence in the bam_header. // // Returns a GHashTable mapping reference sequence NCBI GI to BAM header index // (i.e., an index into bam_header->target_name). // GHashTable *build_refseq_hash(bam_header_t *bam_header, int **refseq_gids, gboolean verbose) { // mapping from target sequence GI to BAM header refseq index // NOTE: some target sequences appear more than once in the HMP files. In those // cases the BAM header refseq index will be the index of the _first_ one found // with that GI. GHashTable *refseq_gi_ht = g_hash_table_new(g_int_hash, g_int_equal); // regex to parse GI from refseq/refseq name GRegex *refseq_gi_re = g_regex_new("^[A-Z\\d_]+\\|gi\\|(\\d+)\\|.*", 0, 0, NULL); GMatchInfo *match_info = NULL; int gid; // HACK: this array (refseq_inds) is not currently freed anywhere int *refseq_inds = g_malloc(sizeof(int) * bam_header->n_targets); *refseq_gids = g_malloc(sizeof(int) * bam_header->n_targets); int *refseq_gids_a = *refseq_gids; int i; for (i = 0;i < bam_header->n_targets; ++i) { refseq_inds[i] = i; // parse target sequence GI and insert it into the hash table if (g_regex_match(refseq_gi_re, bam_header->target_name[i], 0, &match_info)) { while (g_match_info_matches(match_info)) { gchar *gi_str = g_match_info_fetch(match_info, 1); sscanf(gi_str, "%d", &gid); g_free(gi_str); refseq_gids_a[i] = gid; // check for duplicate gids if (g_hash_table_lookup(refseq_gi_ht, &gid) != NULL) { if (verbose) fprintf(stderr, "WARN - duplicate gid=%d found in target %d: %s\n", gid, i, bam_header->target_name[i]); } // store mapping from gid to (first) target index (since there can be multiple targets with the same gi) else { g_hash_table_insert(refseq_gi_ht, &refseq_gids_a[i], &refseq_inds[i]); } g_match_info_next(match_info, NULL); } } // if no GI can be parsed, generate a dummy one else { refseq_gids_a[i] = new_gi--; } g_match_info_free(match_info); } g_regex_unref(refseq_gi_re); return refseq_gi_ht; }
gchar * sdp_set_video_codec(const gchar * sdp_offer, idilia_codec video_codec) { gchar * sdp_answer = NULL; gint current_codec_pt = sdp_get_codec_pt_for_type(sdp_offer, "video"); gint desired_codec_pt = sdp_get_codec_pt(sdp_offer, video_codec); /* do nothing in case the preferred codec is already selected, or if it does not exist in the SDP */ if (current_codec_pt == desired_codec_pt || video_codec == IDILIA_CODEC_INVALID) { return g_strdup(sdp_offer); } else { gchar *result = NULL; GRegex *regex = g_regex_new("m=video[ \t]+[0-9]+[ \t]+UDP/TLS/RTP/SAVPF[ \t]+[0-9]+[ \t]+[0-9]+", 0, 0, NULL); gint codec1 = -1, codec2 = -1; gint port_video = -1; if (regex != NULL) { GMatchInfo *matchInfo; g_regex_match(regex, sdp_offer, 0, &matchInfo); if (g_match_info_matches(matchInfo)) { result = g_match_info_fetch(matchInfo, 0); if (result) { sscanf(result,"m=video%*[ \t]%d%*[ \t]UDP/TLS/RTP/SAVPF%*[ \t]%d%*[ \t]%d" ,&port_video,&codec1,&codec2); if (codec2 != desired_codec_pt) { codec1 = codec2; } gchar *new_line = g_strdup_printf("m=video %d UDP/TLS/RTP/SAVPF %d %d",port_video, desired_codec_pt, codec1); sdp_answer = str_replace_once(sdp_offer, result, new_line); g_free(new_line); g_free(result); } } else { sdp_answer = g_strdup(sdp_offer); } g_regex_unref(regex); } } return sdp_answer; }
/** * Replace the entries */ static gboolean helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data ) { gchar *match; gchar *r; match = g_match_info_fetch ( info, 0 ); r = g_hash_table_lookup ( (GHashTable *) data, match ); if ( r != NULL ) { g_string_append ( res, r ); g_free ( match ); } return FALSE; }
static void handle_1x_quality_change (MMAtSerialPort *port, GMatchInfo *match_info, gpointer user_data) { MMModemHuaweiCdma *self = MM_MODEM_HUAWEI_CDMA (user_data); char *str; gint quality; str = g_match_info_fetch (match_info, 1); quality = parse_quality (str, "1X signal quality"); g_free (str); if (quality >= 0) mm_generic_cdma_update_cdma1x_quality (MM_GENERIC_CDMA (self), (guint32) quality); }
static int recv_stat_u128x(const struct sr_dev_inst *sdi, GMatchInfo *match) { struct dev_context *devc; char *s; devc = sdi->priv; s = g_match_info_fetch(match, 1); sr_spew("STAT response '%s'.", s); /* Max, Min or Avg mode -- no way to tell which, so we'll * set both flags to denote it's not a normal measurement. */ if (s[0] == '1') devc->cur_mqflags[0] |= SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG; else devc->cur_mqflags[0] &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN | SR_MQFLAG_AVG); /* dBm/dBV modes. */ if ((s[2] & ~0x20) == 'M') devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_MW; else if ((s[2] & ~0x20) == 'V') devc->mode_dbm_dbv = devc->cur_unit[0] = SR_UNIT_DECIBEL_VOLT; else devc->mode_dbm_dbv = 0; /* Peak hold mode. */ if (s[4] == '4') devc->cur_mqflags[0] |= SR_MQFLAG_MAX; else devc->cur_mqflags[0] &= ~SR_MQFLAG_MAX; /* Null function. */ if (s[1] == '1') devc->cur_mqflags[0] |= SR_MQFLAG_RELATIVE; else devc->cur_mqflags[0] &= ~SR_MQFLAG_RELATIVE; /* Triggered or auto hold modes. */ if (s[7] == '1' || s[11] == '1') devc->cur_mqflags[0] |= SR_MQFLAG_HOLD; else devc->cur_mqflags[0] &= ~SR_MQFLAG_HOLD; g_free(s); return JOB_STAT; }
static gboolean check_target_compat (GSSDPResourceBrowser *resource_browser, const char *st) { GSSDPResourceBrowserPrivate *priv; GMatchInfo *info; int version; char *tmp; priv = gssdp_resource_browser_get_instance_private (resource_browser); if (g_str_equal (priv->target, GSSDP_ALL_RESOURCES)) return TRUE; if (!g_regex_match (priv->target_regex, st, 0, &info)) { g_match_info_free (info); return FALSE; } /* If there was no version to match, we're done */ if (priv->version == 0) { g_match_info_free (info); return TRUE; } if (g_match_info_get_match_count (info) != 2) { g_match_info_free (info); return FALSE; } version = atoi ((tmp = g_match_info_fetch (info, 1))); g_free (tmp); g_match_info_free (info); if (version < 0) { return FALSE; } return (guint) version >= priv->version; }
static gboolean command_line_eval_cb (const GMatchInfo *info, GString *res, gpointer data) { ReplaceData *replace_data = data; char *r = NULL; char *match; match = g_match_info_fetch (info, 0); if (strcmp (match, "%U") == 0) r = create_file_list (replace_data->file_list, get_uri_func, replace_data->quote_values); else if (strcmp (match, "%F") == 0) r = create_file_list (replace_data->file_list, get_filename_func, replace_data->quote_values); else if (strcmp (match, "%B") == 0) r = create_file_list (replace_data->file_list, get_basename_func, replace_data->quote_values); else if (strcmp (match, "%N") == 0) r = create_file_list (replace_data->file_list, get_basename_wo_ext_func, replace_data->quote_values); else if (strcmp (match, "%E") == 0) r = create_file_list (replace_data->file_list, get_ext_func, replace_data->quote_values); else if (strcmp (match, "%P") == 0) r = create_file_list (replace_data->file_list, get_parent_func, replace_data->quote_values); else if (strncmp (match, "%attr", 5) == 0) { r = create_attribute_list (replace_data->file_list, match, replace_data->quote_values); if (r == NULL) *replace_data->error = g_error_new_literal (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, _("Malformed command")); } else if (strncmp (match, "%ask", 4) == 0) { r = ask_value (replace_data, match, replace_data->error); if ((r != NULL) && replace_data->quote_values) { char *q; q = g_shell_quote (r); g_free (r); r = q; } } if (r != NULL) g_string_append (res, r); g_free (r); g_free (match); return FALSE; }
static gboolean parse_app_version (const char *name, guint *out_version, GError **error) { gboolean ret = FALSE; GMatchInfo *match = NULL; static gsize regex_initialized; static GRegex *regex; int ret_version; if (g_once_init_enter (®ex_initialized)) { regex = g_regex_new (APP_VERSION_REGEXP, 0, 0, NULL); g_assert (regex); g_once_init_leave (®ex_initialized, 1); } if (!g_regex_match (regex, name, 0, &match)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid app link %s", name); goto out; } { g_autofree char *version_str = g_match_info_fetch (match, 1); ret_version = g_ascii_strtoull (version_str, NULL, 10); switch (ret_version) { case 0: case 1: break; default: g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid version in app link %s", name); goto out; } } ret = TRUE; *out_version = ret_version; out: return ret; }
redirect_cb(WebKitWebView* web_view, WebKitPolicyDecision* decision, WebKitPolicyDecisionType type, gpointer udata) #endif { GtTwitchLoginDlg* self = GT_TWITCH_LOGIN_DLG(udata); GtTwitchLoginDlgPrivate* priv = gt_twitch_login_dlg_get_instance_private(self); GMatchInfo* match_info = NULL; const gchar* uri = NULL; #ifdef USE_DEPRECATED_WEBKIT uri = webkit_network_request_get_uri(request); #else if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { WebKitNavigationAction* action = webkit_navigation_policy_decision_get_navigation_action( WEBKIT_NAVIGATION_POLICY_DECISION(decision)); WebKitURIRequest* request = webkit_navigation_action_get_request(action); uri = webkit_uri_request_get_uri(request); } #endif if (uri == NULL || strlen(uri) == 0) return FALSE; MESSAGE("Redirect uri is '%s'", uri); g_regex_match(priv->token_redirect_regex, uri, 0, &match_info); if (g_match_info_matches(match_info)) { g_autofree gchar* token = g_match_info_fetch(match_info, 1); MESSAGEF("Successfully got OAuth token '%s'", token); gt_twitch_fetch_oauth_info_async(main_app->twitch, token, fetch_oauth_info_cb, priv->cancel, self); } else if (g_str_has_prefix(uri, "http://localhost/?error=access_denied")) WARNING("Error logging in or login cancelled"); g_match_info_unref(match_info); return FALSE; }
gchar *flist_parse_FLS_cookie(const gchar *data) { //Set-Cookie: FLS=6da62d9f586c83dd6f946f1213abf486b3887d988847c4255c8f0502d9824df2; expires=Mon, 14-Mar-2011 13:28:07 GMT; path=/ GError *error = NULL; GRegex *regex = g_regex_new("^Set-Cookie:\\s*FLS=([^;]*)(?:;|$).*", G_REGEX_CASELESS | G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, G_REGEX_MATCH_NEWLINE_CRLF, &error); GMatchInfo *match = NULL; gchar *ret = NULL; g_regex_match(regex, data, G_REGEX_MATCH_NEWLINE_CRLF, &match); if(g_match_info_matches(match)) { ret = g_match_info_fetch (match, 1); } g_match_info_free(match); g_regex_unref(regex); if(error) g_error_free(error); return ret; }
/** * @param info To Match information on. * @param res The string being generated. * @param data User data * * Replace the entries. This function gets called by g_regex_replace_eval. * * @returns TRUE to stop replacement, FALSE to continue */ static gboolean helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data ) { gchar *match; // Get the match match = g_match_info_fetch ( info, 0 ); if ( match != NULL ) { // Lookup the match, so we can replace it. gchar *r = g_hash_table_lookup ( (GHashTable *) data, match ); if ( r != NULL ) { // Append the replacement to the string. g_string_append ( res, r ); } // Free match. g_free ( match ); } // Continue replacement. return FALSE; }
static gboolean ggp_message_format_from_gg_found_img(const GMatchInfo *info, GString *res, gpointer data) { ggp_message_got_data *msg = data; gchar *name, *replacement; int64_t id; int stored_id; name = g_match_info_fetch(info, 1); if (sscanf(name, "%" G_GINT64_MODIFIER "x", &id) != 1) id = 0; g_free(name); if (!id) { g_string_append(res, "["); g_string_append(res, _("broken image")); g_string_append(res, "]"); return FALSE; } stored_id = ggp_image_get_cached(msg->gc, id); if (stored_id > 0) { purple_debug_info("gg", "ggp_message_format_from_gg_found_img: " "getting image " GGP_IMAGE_ID_FORMAT " from cache\n", id); replacement = g_strdup_printf(GGP_IMAGE_DESTINATION, stored_id); g_string_append(res, replacement); g_free(replacement); return FALSE; } if (NULL == g_list_find_custom(msg->pending_images, &id, ggp_int64_compare)) { msg->pending_images = g_list_append(msg->pending_images, ggp_uint64dup(id)); } replacement = g_strdup_printf(GGP_IMAGE_REPLACEMENT, id); g_string_append(res, replacement); g_free(replacement); return FALSE; }
static gboolean match_info_to_ip4_addr (GMatchInfo *match_info, guint match_index, guint *out_addr) { gchar *s, *bin = NULL; gchar buf[9]; gsize len, bin_len; gboolean success = FALSE; s = g_match_info_fetch (match_info, match_index); g_return_val_if_fail (s != NULL, FALSE); len = strlen (s); if (len == 1 && s[0] == '0') { *out_addr = 0; success = TRUE; goto done; } if (len < 7 || len > 8) goto done; /* Handle possibly missing leading zero */ memset (buf, 0, sizeof (buf)); if (len == 7) { strcpy (&buf[1], s); buf[0] = '0'; } else if (len == 8) strcpy (buf, s); else g_assert_not_reached (); bin = mm_utils_hexstr2bin (buf, &bin_len); if (!bin || bin_len != 4) goto done; *out_addr = GUINT32_SWAP_LE_BE (*((guint32 *) bin)); success = TRUE; done: g_free (s); g_free (bin); return success; }
static int recv_stat_u123x(const struct sr_dev_inst *sdi, GMatchInfo *match) { struct dev_context *devc; char *s; devc = sdi->priv; s = g_match_info_fetch(match, 1); sr_spew("STAT response '%s'.", s); /* Max, Min or Avg mode -- no way to tell which, so we'll * set both flags to denote it's not a normal measurement. */ if (s[0] == '1') devc->cur_mqflags |= SR_MQFLAG_MAX | SR_MQFLAG_MIN; else devc->cur_mqflags &= ~(SR_MQFLAG_MAX | SR_MQFLAG_MIN); if (s[1] == '1') devc->cur_mqflags |= SR_MQFLAG_RELATIVE; else devc->cur_mqflags &= ~SR_MQFLAG_RELATIVE; /* Triggered or auto hold modes. */ if (s[2] == '1' || s[3] == '1') devc->cur_mqflags |= SR_MQFLAG_HOLD; else devc->cur_mqflags &= ~SR_MQFLAG_HOLD; /* Temp/aux mode. */ if (s[7] == '1') devc->mode_tempaux = TRUE; else devc->mode_tempaux = FALSE; /* Continuity mode. */ if (s[16] == '1') devc->mode_continuity = TRUE; else devc->mode_continuity = FALSE; g_free(s); return SR_OK; }
static gboolean uint_from_match_item (GMatchInfo *match_info, guint32 num, guint32 *val) { long int tmp; char *str; gboolean success = FALSE; str = g_match_info_fetch (match_info, num); g_return_val_if_fail (str != NULL, FALSE); errno = 0; tmp = strtol (str, NULL, 10); if (errno == 0 && tmp >= 0 && tmp <= G_MAXUINT) { *val = (guint32) tmp; success = TRUE; } g_free (str); return success; }
static int recv_conf(const struct sr_dev_inst *sdi, GMatchInfo *match) { struct dev_context *devc; char *mstr; sr_spew("CONF? response '%s'.", g_match_info_get_string(match)); devc = sdi->priv; mstr = g_match_info_fetch(match, 1); if (!strcmp(mstr, "DIOD")) { devc->cur_mq = SR_MQ_VOLTAGE; devc->cur_unit = SR_UNIT_VOLT; devc->cur_mqflags = SR_MQFLAG_DIODE; devc->cur_divider = 0; } else sr_dbg("Unknown single argument."); g_free(mstr); return SR_OK; }
static OwrLocalMediaSource *maybe_create_source_from_filename(const gchar *name) { static GRegex *regex; GMatchInfo *match_info = NULL; OwrLocalMediaSource *source = NULL; gchar *index_str; gint index; gchar *filename; gchar *device_name; if (g_once_init_enter(®ex)) { GRegex *r; r = g_regex_new("^video(0|[1-9][0-9]*)$", G_REGEX_OPTIMIZE, 0, NULL); g_assert(r); g_once_init_leave(®ex, r); } if (g_regex_match(regex, name, 0, &match_info)) { index_str = g_match_info_fetch(match_info, 1); index = g_ascii_strtoll(index_str, NULL, 10); g_free(index_str); filename = g_strdup_printf("/dev/%s", name); device_name = get_v4l2_device_name(filename); g_free(filename); filename = NULL; if (!device_name) return NULL; source = _owr_local_media_source_new_cached(index, device_name, OWR_MEDIA_TYPE_VIDEO, OWR_SOURCE_TYPE_CAPTURE); g_debug("v4l: filename match: %s", device_name); g_free(device_name); } g_match_info_free(match_info); return source; }
static void get_address_from_ip(const char *text, std::string &ipstr, std::string &address) { GMatchInfo *match_info; GRegex *regex = g_regex_new ("(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))", (GRegexCompileFlags)0, (GRegexMatchFlags)0, NULL); g_regex_match (regex, text, (GRegexMatchFlags)0, &match_info); if (g_match_info_matches(match_info)) { gchar *word = g_match_info_fetch (match_info, 0); ipstr = word; g_free (word); } g_match_info_free (match_info); g_regex_unref (regex); if (ipstr.empty()) return; std::string datafilename = plugin_info->datadir; datafilename += G_DIR_SEPARATOR_S "data" G_DIR_SEPARATOR_S "QQWry.Dat"; FILE *fp = g_fopen(datafilename.c_str(), "rb"); if (!fp) { gchar *msg = g_strdup_printf(_("Error: Open file %s failed!"), datafilename.c_str()); address = msg; g_free(msg); return; } unsigned long index_start,index_end; getHead(fp,&index_start,&index_end); unsigned long ip = getIP(ipstr.c_str()); unsigned long current=searchIP(fp,index_start,index_end,ip); std::string country,location; getAddress(fp,getValue(fp,current+4,3),country,location); gchar *c = g_convert(country.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL); if (c) { address += c; address += ' '; g_free(c); } gchar *l = g_convert(location.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL); if (l) { address += l; g_free(l); } fclose(fp); }