static gchar * parse_time (const gchar *response, const gchar *regex, const gchar *tag, GError **error) { GRegex *r; GMatchInfo *match_info = NULL; GError *match_error = NULL; guint year, month, day, hour, minute, second; gchar *result = NULL; r = g_regex_new (regex, 0, 0, NULL); g_assert (r != NULL); if (!g_regex_match_full (r, response, -1, 0, 0, &match_info, &match_error)) { if (match_error) { g_propagate_error (error, match_error); g_prefix_error (error, "Could not parse %s results: ", tag); } else { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't match %s reply", tag); } } else { if (mm_get_uint_from_match_info (match_info, 1, &year) && mm_get_uint_from_match_info (match_info, 2, &month) && mm_get_uint_from_match_info (match_info, 3, &day) && mm_get_uint_from_match_info (match_info, 4, &hour) && mm_get_uint_from_match_info (match_info, 5, &minute) && mm_get_uint_from_match_info (match_info, 6, &second)) { /* Return ISO-8601 format date/time string */ result = g_strdup_printf ("%04d/%02d/%02d %02d:%02d:%02d", year, month, day, hour, minute, second); } else { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Failed to parse %s reply", tag); } } if (match_info) g_match_info_free (match_info); g_regex_unref (r); return result; }
// 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; }
gboolean kms_utils_contains_proto (const gchar * search_term, const gchar * proto) { gchar *pattern; GRegex *regex; gboolean ret; pattern = g_strdup_printf ("(%s|.+/%s|%s/.+|.+/%s/.+)", proto, proto, proto, proto); regex = g_regex_new (pattern, 0, 0, NULL); ret = g_regex_match (regex, search_term, G_REGEX_MATCH_ANCHORED, NULL); g_regex_unref (regex); g_free (pattern); return ret; }
static void gth_template_editor_dialog_finalize (GObject *object) { GthTemplateEditorDialog *dialog; dialog = GTH_TEMPLATE_EDITOR_DIALOG (object); if (dialog->priv != NULL) { if (dialog->priv->re != NULL) g_regex_unref (dialog->priv->re); g_free (dialog->priv); dialog->priv = NULL; } G_OBJECT_CLASS (gth_template_editor_dialog_parent_class)->finalize (object); }
gchar * cut_utils_regex_replace (const gchar *pattern, const gchar *string, const gchar *replacement, GError **error) { GRegex *regex; gchar *replaced; regex = g_regex_new(pattern, G_REGEX_MULTILINE, 0, error); if (!regex) return NULL; replaced = g_regex_replace(regex, string, -1, 0, replacement, 0, error); g_regex_unref(regex); return replaced; }
static gboolean is_channel_playlist_url_valid (RequestData *request_data) { GRegex *regex; gboolean result; regex = g_regex_new ("^/[^/]*/encoder/[0-9]/playlist.m3u8$", G_REGEX_OPTIMIZE, 0, NULL); if (g_regex_match (regex, request_data->uri, 0, NULL)) { result = TRUE; } else { result = FALSE; } g_regex_unref (regex); return result; }
int helper_parse_setup ( char * string, char ***output, int *length, ... ) { GError *error = NULL; GHashTable *h; h = g_hash_table_new ( g_str_hash, g_str_equal ); // By default, we insert terminal and ssh-client g_hash_table_insert ( h, "{terminal}", config.terminal_emulator ); g_hash_table_insert ( h, "{ssh-client}", config.ssh_client ); // Add list from variable arguments. va_list ap; va_start ( ap, length ); while ( 1 ) { char * key = va_arg ( ap, char * ); if ( key == NULL ) { break; } char *value = va_arg ( ap, char * ); if ( value == NULL ) { break; } g_hash_table_insert ( h, key, value ); } va_end ( ap ); // Replace hits within {-\w+}. GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL ); char *res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb, h, NULL ); // Free regex. g_regex_unref ( reg ); // Destroy key-value storage. g_hash_table_destroy ( h ); // Parse the string into shell arguments. if ( g_shell_parse_argv ( res, length, output, &error ) ) { g_free ( res ); return TRUE; } g_free ( res ); // Throw error if shell parsing fails. if ( error ) { char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, error->message ); error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); } return FALSE; }
gboolean falcon_filter_unregister(gboolean is_dir, const gchar *pattern, falcon_filter_func func) { GRegex *regex = NULL; GRegex *key = NULL; GSList *list = NULL; GSList *target = NULL; falcon_filter_t filter = {is_dir, func}; if (!pattern) { g_warning(_("Failed to unregister filter with no pattern.")); return FALSE; } regex = falcon_filter_regex_new(pattern); if (!regex) return FALSE; g_mutex_lock(lock); if (!registry) { g_critical(_("Filter registry uninitialized." " Failed to unregister filter with pattern %s"), pattern); g_mutex_unlock(lock); return FALSE; } if (!g_hash_table_lookup_extended(registry, regex, (gpointer *)&key, (gpointer *)&list)) { g_mutex_unlock(lock); return FALSE; } target = g_slist_find_custom(list, &filter, falcon_filter_compare); if (target) { g_free(target->data); list = g_slist_delete_link(list, target); } if (list == NULL) g_hash_table_remove(registry, key); else g_hash_table_insert(registry, key, list); g_regex_unref(regex); g_mutex_unlock(lock); return TRUE; }
//! //! @brief Frees often used prebuilt regex expressions //! void lw_regex_free () { if (_regex_expressions_reference_count < 1) return; _regex_expressions_reference_count--; //Declarations gint i = 0; //Setup the built in regexes while (i++ < LW_RE_TOTAL) { if (_cached_regexes[i] != NULL) g_regex_unref (_cached_regexes[i]); } memset(_cached_regexes, 0, sizeof(GRegex*) * LW_RE_TOTAL); }
/** * ufo_messenger_create: * @address: (transfer none) (type utf8): listen address for the messenger * @error: A #GError used to report errors during messenger creation * * Create a new #UfoMessenger basend on the PROTOCOL:// of the given @address * * Returns: (transfer full) (allow-none): A new #UfoMessenger or %NULL in case of * error. */ UfoMessenger * ufo_messenger_create (const gchar *address, GError **error) { UfoMessenger *msgr_out = NULL; GError *error_internal = NULL; GRegex *regex = g_regex_new ("^[a-z A-Z]+://[a-z A-Z 0-9 \\.]+:[0-9]{1,5}", \ 0, G_REGEX_MATCH_NOTEMPTY, &error_internal); if (error_internal) { g_propagate_error (error, error_internal); return NULL; } if (g_regex_match_all (regex, address, 0, NULL)) { gchar **protocol = g_strsplit (address, ":", 2); g_debug ("Creating messenger for `%s'", protocol[0]); #ifdef WITH_ZMQ if (!g_strcmp0 (protocol[0], "tcp")) { msgr_out = UFO_MESSENGER (ufo_zmq_messenger_new ()); goto done; } #endif #ifdef WITH_MPI if (!g_strcmp0 (protocol[0], "mpi")) { msgr_out = UFO_MESSENGER (ufo_mpi_messenger_new ()); goto done; } #endif g_set_error (error, UFO_MESSENGER_ERROR, UFO_MESSENGER_UNKNOWN_PROTOCOL, "Don't know how to handle protocol '%s://'", protocol[0]); #if defined(WITH_ZMQ) || (WITH_MPI) done: #endif g_strfreev (protocol); } else { g_set_error (error, UFO_MESSENGER_ERROR, UFO_MESSENGER_INVALID_ADDRESS, "Given address has invalid format, expecting `<protocol>://<address | device>:<port>'."); } g_regex_unref (regex); return msgr_out; }
GRegex * terminal_search_dialog_get_regex (GtkWidget *dialog) { TerminalSearchDialogPrivate *priv; GRegexCompileFlags compile_flags; const char *text, *pattern; g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); priv = TERMINAL_SEARCH_DIALOG_GET_PRIVATE (dialog); g_return_val_if_fail (priv, NULL); pattern = text = terminal_search_dialog_get_search_text (dialog); compile_flags = G_REGEX_OPTIMIZE; if (!GET_FLAG (match_case_checkbutton)) compile_flags |= G_REGEX_CASELESS; if (GET_FLAG (regex_checkbutton)) compile_flags |= G_REGEX_MULTILINE; else pattern = g_regex_escape_string (text, -1); if (GET_FLAG (entire_word_checkbutton)) { const char *old_pattern = pattern; pattern = g_strdup_printf ("\\b%s\\b", pattern); if (old_pattern != text) g_free ((char *) old_pattern); } if (!priv->regex || priv->regex_compile_flags != compile_flags || g_strcmp0 (pattern, g_regex_get_pattern (priv->regex)) != 0) { priv->regex_compile_flags = compile_flags; if (priv->regex) g_regex_unref (priv->regex); /* TODO Error handling */ priv->regex = g_regex_new (pattern, compile_flags, 0, NULL); } if (pattern != text) g_free ((char *) pattern); return priv->regex; }
static gboolean kms_sdp_rtp_savp_media_handler_manage_protocol (KmsSdpMediaHandler * handler, const gchar * protocol) { GRegex *regex; gboolean ret; /* Support both RTP/SAVP and UDP/TLS/RTP/SAVP */ regex = g_regex_new ("(" SDP_MEDIA_UDP_TLS_PROTO_INFO ")?" SDP_MEDIA_RTP_SAVP_PROTO, 0, 0, NULL); ret = g_regex_match (regex, protocol, G_REGEX_MATCH_ANCHORED, NULL); g_regex_unref (regex); return ret; }
static void exec_cmd_entry ( DRunModeEntry *e ) { GError *error = NULL; GRegex *reg = g_regex_new ( "%[a-zA-Z]", 0, 0, &error ); if ( error != NULL ) { fprintf ( stderr, "Internal error, failed to create regex: %s.\n", error->message ); g_error_free ( error ); return; } struct RegexEvalArg earg = { .e = e, .success = TRUE }; char *str = g_regex_replace_eval ( reg, e->exec, -1, 0, 0, drun_helper_eval_cb, &earg, &error ); if ( error != NULL ) { fprintf ( stderr, "Internal error, failed replace field codes: %s.\n", error->message ); g_error_free ( error ); return; } g_regex_unref ( reg ); if ( earg.success == FALSE ) { fprintf ( stderr, "Invalid field code in Exec line: %s.\n", e->exec );; return; } if ( str == NULL ) { fprintf ( stderr, "Nothing to execute after processing: %s.\n", e->exec );; return; } gchar *fp = rofi_expand_path ( g_strstrip ( str ) ); gchar *exec_path = g_key_file_get_string ( e->key_file, "Desktop Entry", "Path", NULL ); if ( exec_path != NULL && strlen ( exec_path ) == 0 ) { // If it is empty, ignore this property. (#529) g_free ( exec_path ); exec_path = NULL; } // Returns false if not found, if key not found, we don't want run in terminal. gboolean terminal = g_key_file_get_boolean ( e->key_file, "Desktop Entry", "Terminal", NULL ); if ( helper_execute_command ( exec_path, fp, terminal ) ) { char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL ); char *key = g_strdup_printf ( "%s:::%s", e->root, e->path ); history_set ( path, key ); g_free ( key ); g_free ( path ); } g_free ( exec_path ); g_free ( str ); g_free ( fp ); }
static gboolean redirect_rule_parse(liServer *srv, GString *regex, GString *str, redirect_rule *rule) { gchar *pattern_str = str->str; rule->pattern = NULL; rule->regex = NULL; rule->type = REDIRECT_ABSOLUTE_URI; if (pattern_str[0] == '/') { rule->type = REDIRECT_ABSOLUTE_PATH; } else if (pattern_str[0] == '?') { rule->type = REDIRECT_RELATIVE_QUERY; } else if (g_str_has_prefix(pattern_str, "./")) { pattern_str += 2; rule->type = REDIRECT_RELATIVE_PATH; } rule->pattern = li_pattern_new(srv, pattern_str); if (NULL == rule->pattern) { goto error; } if (NULL != regex) { GError *err = NULL; rule->regex = g_regex_new(regex->str, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); if (NULL == rule->regex || NULL != err) { ERROR(srv, "redirect: error compiling regex \"%s\": %s", regex->str, NULL != err ? err->message : "unknown error"); g_error_free(err); goto error; } } return TRUE; error: if (NULL != rule->pattern) { li_pattern_free(rule->pattern); rule->pattern = NULL; } if (NULL != rule->regex) { g_regex_unref(rule->regex); rule->regex = NULL; } return FALSE; }
static void git_status_command_finalize (GObject *object) { GitStatusCommand *self; self = GIT_STATUS_COMMAND (object); git_status_command_clear_output (self); git_status_command_stop_automatic_monitor (ANJUTA_COMMAND (self)); g_queue_free (self->priv->status_queue); g_regex_unref (self->priv->status_regex); g_free (self->priv); G_OBJECT_CLASS (git_status_command_parent_class)->finalize (object); }
/** * gstreamill_get_encoder_output: * @uri: (in): access uri, e.g. /live/test/encoder/0 * * Get the EncoderOutput by access uri. * * Returns: the encoder output */ EncoderOutput * gstreamill_get_encoder_output (Gstreamill *gstreamill, gchar *uri) { Job *job; guint index; GRegex *regex = NULL; GMatchInfo *match_info = NULL; gchar *e; index = -1; regex = g_regex_new ("^/(live|dvr)/.*/encoder/(?<encoder>[0-9]+).*", G_REGEX_OPTIMIZE, 0, NULL); g_regex_match (regex, uri, 0, &match_info); if (g_match_info_matches (match_info)) { e = g_match_info_fetch_named (match_info, "encoder"); index = g_ascii_strtoll (e, NULL, 10); g_free (e); } if (match_info != NULL) { g_match_info_free (match_info); } if (regex != NULL) { g_regex_unref (regex); } if (index == -1) { GST_INFO ("Not a encoder uri: %s", uri); return NULL; } job = gstreamill_get_job (gstreamill, uri); if (job == NULL) { GST_ERROR ("Job %s not found.", uri); return NULL; } if (*(job->output->state) != JOB_STATE_PLAYING) { GST_ERROR ("FATAL: Job %s state is not playing", job->name); return NULL; } if (index >= job->output->encoder_count) { GST_ERROR ("Encoder %s not found.", uri); return NULL; } g_mutex_lock (&(job->access_mutex)); job->current_access += 1; g_mutex_unlock (&(job->access_mutex)); return &job->output->encoders[index]; }
void _gtk_source_regex_unref (GtkSourceRegex *regex) { if (regex != NULL && --regex->ref_count == 0) { if (regex->resolved) { g_regex_unref (regex->u.regex.regex); if (regex->u.regex.match) g_match_info_free (regex->u.regex.match); } else { g_free (regex->u.info.pattern); } g_slice_free (GtkSourceRegex, regex); } }
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; }
void LcmTunnel::init_regex(const char *lcm_channel) { if (lcm_channel && strlen(lcm_channel)) { char *rchannel = (char*) calloc(strlen(lcm_channel) + 3, sizeof(char)); sprintf(rchannel, "%c%s%c", '^', lcm_channel, '$'); if (regex != NULL) { if (verbose) printf("Replacing regex with \"%s\"\n", rchannel); g_regex_unref(regex); } GError *rerr = NULL; regex = g_regex_new(rchannel, (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, &rerr); if (rerr != NULL) fprintf(stderr, "Invalid regex: \"%s\"\n", rchannel); free(rchannel); } }
static void redirect_free(liServer *srv, gpointer param) { guint i; redirect_data *rd = param; UNUSED(srv); for (i = 0; i < rd->rules->len; i++) { redirect_rule *rule = &g_array_index(rd->rules, redirect_rule, i); li_pattern_free(rule->pattern); if (NULL != rule->regex) g_regex_unref(rule->regex); } g_array_free(rd->rules, TRUE); g_slice_free(redirect_data, rd); }
void tokenize_free ( char ** tokens ) { if ( config.glob ) { for ( size_t i = 0; tokens && tokens[i]; i++ ) { g_pattern_spec_free ( (GPatternSpec *) tokens[i] ); } g_free ( tokens ); } else if ( config.regex ) { for ( size_t i = 0; tokens && tokens[i]; i++ ) { g_regex_unref ( (GRegex *) tokens[i] ); } g_free ( tokens ); } else { g_strfreev ( tokens ); } }
void trg_rss_model_update(TrgRssModel * model) { TrgRssModelPrivate *priv = TRG_RSS_MODEL_GET_PRIVATE(model); TrgPrefs *prefs = trg_client_get_prefs(priv->client); JsonArray *feeds = trg_prefs_get_rss(prefs); GRegex *cookie_regex; GList *li; if (!feeds) return; cookie_regex = g_regex_new("(.*):COOKIE:(.*)", 0, 0, NULL); for (li = json_array_get_elements(feeds); li != NULL; li = g_list_next(li)) { JsonObject *feed = json_node_get_object((JsonNode *) li->data); const gchar *feed_url = json_object_get_string_member(feed, "url"); const gchar *id = json_object_get_string_member(feed, "id"); feed_update *update; GMatchInfo *match; if (!feed_url || !id) continue; update = g_new0(feed_update, 1); update->feed_id = g_strdup(id); update->model = model; if (g_regex_match (cookie_regex, feed_url, 0, &match)) { update->feed_url = g_match_info_fetch(match, 1); update->feed_cookie = g_match_info_fetch(match, 2); g_match_info_free(match); } else { update->feed_url = g_strdup(feed_url); } async_http_request(priv->client, update->feed_url, update->feed_cookie, on_rss_receive, update); } g_regex_unref(cookie_regex); /*trg_model_remove_removed(GTK_LIST_STORE(model), RSSCOL_UPDATESERIAL, updateSerial);*/ }
PhotosQuery * photos_query_builder_single_query (PhotosSearchContextState *state, gint flags, const gchar *resource) { GRegex *regex; gchar *replacement; gchar *sparql; gchar *tmp; tmp = photos_query_builder_query (state, FALSE, flags, NULL); regex = g_regex_new ("\\?urn", 0, 0, NULL); replacement = g_strconcat ("<", resource, ">", NULL); sparql = g_regex_replace (regex, tmp, -1, 0, replacement, 0, NULL); g_free (replacement); g_free (tmp); g_regex_unref (regex); return photos_query_new (state, sparql); }
static gchar* apedax_format_date(const gchar* datefield) { GRegex *re; gchar *result; GError *re_err = NULL; gwy_debug("Compiling the Regular expression."); re = g_regex_new(REGPATTERN, 0, 0, &re_err); g_assert(!re_err); result = g_regex_replace(re, datefield, -1, 0, "\\3-\\2-\\1 \\4 \\5", 0, &re_err); if (re_err) { g_warning("Invalid date field (%s)", re_err->message); g_clear_error(&re_err); } g_regex_unref(re); return result; }
static void list_files(gchar *base, const gchar *filter) { GDir *dir; gchar const *file_name; dir = g_dir_open(base, 0, NULL); gchar *display_base = g_strconcat(base, G_DIR_SEPARATOR_S, NULL); GString *g_display_base = g_string_new(display_base); utils_string_replace_first(g_display_base, base_directory, ""); g_free(display_base); GRegex *regex = g_regex_new(filter, G_REGEX_CASELESS, 0, NULL); foreach_dir(file_name, dir) { if(row_pos > MAX_LIST) { break; } gchar *path = g_build_path(G_DIR_SEPARATOR_S, base, file_name, NULL); if(g_file_test(path, G_FILE_TEST_IS_DIR)) { if(g_regex_match(pathRegexSetting.regex, file_name, 0, NULL)) { g_free(path); continue; } list_files(path, filter); } else { if(g_regex_match(nameRegexSetting.regex, file_name, 0, NULL)) { g_free(path); continue; } if(regex != NULL && g_regex_match(regex, include_path ? path : file_name, 0, NULL)) { gtk_tree_store_append(list, &row, NULL); gtk_tree_store_set(list, &row, 0, g_display_base->str, 1, file_name, -1); row_pos++; } } g_free(path); } g_string_free(g_display_base, TRUE); g_dir_close(dir); g_regex_unref(regex); }
static gboolean check_regex (LogviewFilterManager *manager, const gchar *regex) { GtkWidget *dialog; GError *error = NULL; GRegex *reg; if (!strlen (regex)) { dialog = gtk_message_dialog_new (GTK_WINDOW(manager), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Regular expression is empty!")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return FALSE; } reg = g_regex_new (regex, 0, 0, &error); if (error) { dialog = gtk_message_dialog_new (GTK_WINDOW (manager), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Regular expression is invalid: %s"), error->message); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free (error); return FALSE; } g_regex_unref (reg); return TRUE; }
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); }
static int regexpdone(struct objlist *obj,N_VALUE *inst,N_VALUE *rval,int argc,char **argv) { struct oregexp_local *local; if (_exeparent(obj,(char *)argv[1],inst,rval,argc,argv)) return 1; _getobj(obj, "_local", inst, &local); if (local->regexp) { g_regex_unref(local->regexp); } if (local->array) { del_array_element(local->array); arrayfree(local->array); } return 0; }
static void vhost_map_regex_free(liServer *srv, gpointer param) { guint i; vhost_map_regex_data *mrd = param; GArray *list = mrd->list; UNUSED(srv); for (i = 0; i < list->len; i++) { vhost_map_regex_entry *entry = &g_array_index(list, vhost_map_regex_entry, i); g_regex_unref(entry->regex); li_value_free(entry->action); } g_array_free(list, TRUE); if (NULL != mrd->default_action) { li_value_free(mrd->default_action); } g_slice_free(vhost_map_regex_data, mrd); }
/* Implementation of GObject stuff */ static void gm_entry_dispose (GObject* obj) { GmEntryPrivate *priv = GM_ENTRY (obj)->priv; if (priv->regex) { g_regex_unref (priv->regex); priv->regex = NULL; } if (priv->regex_string) { g_free (priv->regex_string); priv->regex_string = NULL; } if (priv->activate_icon) { g_free (priv->activate_icon); priv->activate_icon = NULL; } G_OBJECT_CLASS (gm_entry_parent_class)->dispose (obj); }