char * gth_script_get_command_line (GthScript *script, GtkWindow *parent, GList *file_list /* GthFileData */, GError **error) { ReplaceData *replace_data; GRegex *qre; GRegex *re; char **a; GString *command_line; int i; char *result; replace_data = g_new0 (ReplaceData, 1); replace_data->parent = parent; replace_data->script = script; replace_data->file_list = file_list; replace_data->error = error; re = g_regex_new ("%U|%F|%B|%N|%E|%P|%ask(\\{[^}]+\\}(\\{[^}]+\\})?)?|%attr\\{[^}]+\\}", 0, 0, NULL); replace_data->quote_values = FALSE; command_line = g_string_new (""); qre = g_regex_new ("%quote\\{([^}]+)\\}", 0, 0, NULL); a = g_regex_split (qre, script->priv->command, 0); for (i = 0; a[i] != NULL; i++) { if (i % 2 == 1) { char *sub_result; char *quoted; sub_result = g_regex_replace_eval (re, a[i], -1, 0, 0, command_line_eval_cb, replace_data, error); quoted = g_shell_quote (g_strstrip (sub_result)); g_string_append (command_line, quoted); g_free (quoted); g_free (sub_result); } else g_string_append (command_line, a[i]); } replace_data->quote_values = TRUE; result = g_regex_replace_eval (re, command_line->str, -1, 0, 0, command_line_eval_cb, replace_data, error); g_free (replace_data); g_string_free (command_line, TRUE); g_regex_unref (qre); g_regex_unref (re); return result; }
static void translate(gchar **str, gint regp_id, gint service) { gchar *newstr; eval_data *data = g_new0(eval_data, 1); data->which = regp_id; data->service = service; newstr = g_regex_replace_eval(regp[regp_id], /* compiled regex */ *str, /* subject string */ -1, /* length of the subject string */ 0, /* start position */ 0, /* match options */ eval, /* function to be called for each match */ data, /* user data */ NULL); /* error handler */ g_free(data); data = NULL; twitter_debug("which = %d *str = %s newstr = %s\n", regp_id, *str, newstr); g_free(*str); *str = newstr; }
static gchar * pub_encode (const gchar *d) { gchar *htm; static GRegex *reg = NULL; static GHashTable *hash = NULL; if (reg == NULL) { reg = g_regex_new ("&", 0, 0, NULL); } g_return_val_if_fail (reg, NULL); if (hash == NULL) { hash = g_hash_table_new (g_str_hash, g_str_equal); if (hash) { g_hash_table_insert (hash, "&", "%28"); } } g_return_val_if_fail (hash, NULL); htm = g_regex_replace_eval (reg, d, -1, 0, 0, eval_cb, hash, NULL); if (htm == NULL) { g_error ("convert body to desc html chars failed"); return NULL; } return htm; }
static void ggp_message_format_from_gg(ggp_message_got_data *msg, const gchar *text) { gchar *text_new, *tmp; if (text == NULL) { msg->text = g_strdup(""); return; } text_new = g_strdup(text); purple_str_strip_char(text_new, '\r'); tmp = text_new; text_new = purple_strreplace(text_new, GGP_GG10_DEFAULT_FORMAT, GGP_GG10_DEFAULT_FORMAT_REPLACEMENT); g_free(tmp); tmp = text_new; text_new = g_regex_replace_eval(global_data.re_gg_img, text_new, -1, 0, 0, ggp_message_format_from_gg_found_img, msg, NULL); g_free(tmp); msg->text = text_new; }
/** * _gtk_source_regex_resolve: * @regex: a #GtkSourceRegex. * @start_regex: a #GtkSourceRegex. * @matched_text: the text matched against @start_regex. * * If the regular expression does not contain references to the start * regular expression, the functions increases the reference count * of @regex and returns it. * * If the regular expression contains references to the start regular * expression in the form "\%{start_sub_pattern@start}", it replaces * them (they are extracted from @start_regex and @matched_text) and * returns the new regular expression. * * Returns: a #GtkSourceRegex. */ GtkSourceRegex * _gtk_source_regex_resolve (GtkSourceRegex *regex, GtkSourceRegex *start_regex, const gchar *matched_text) { gchar *expanded_regex; GtkSourceRegex *new_regex; struct RegexResolveData data; if (regex == NULL || regex->resolved) return _gtk_source_regex_ref (regex); data.start_regex = start_regex; data.matched_text = matched_text; expanded_regex = g_regex_replace_eval (get_start_ref_regex (), regex->u.info.pattern, -1, 0, 0, replace_start_regex, &data, NULL); new_regex = _gtk_source_regex_new (expanded_regex, regex->u.info.flags, NULL); if (new_regex == NULL || !new_regex->resolved) { _gtk_source_regex_unref (new_regex); g_warning ("Regular expression %s cannot be expanded.", regex->u.info.pattern); /* Returns a regex that nevers matches. */ new_regex = _gtk_source_regex_new ("$never-match^", 0, NULL); } g_free (expanded_regex); return new_regex; }
/// Writes to espeak's stdin. static gpointer worker_writer (WorkerData *data) { GError *error = NULL; GMatchInfo *match_info; while (stardict_iterator_get_offset (data->iterator) != data->end_entry) { g_mutex_lock (data->dict_mutex); const gchar *word = stardict_iterator_get_word (data->iterator); g_mutex_unlock (data->dict_mutex); word += strspn (word, LINE_SPLITTING_CHARS " \t"); gchar *x = g_strdup (word); // Cut the word if needed be error = NULL; if (g_regex_match_full (data->re_stop, x, -1, 0, 0, &match_info, &error)) { gint start_pos; g_match_info_fetch_pos (match_info, 0, &start_pos, NULL); x[start_pos] = 0; } g_match_info_free (match_info); // Change acronyms so that they're not pronounced as words if (!error && !data->ignore_acronyms) { char *tmp = g_regex_replace_eval (data->re_acronym, x, -1, 0, 0, writer_acronym_cb, NULL, &error); g_free (x); x = tmp; } if (error) { g_printerr ("Notice: error processing '%s': %s\n", word, error->message); g_clear_error (&error); *x = 0; } // We might have accidentally cut off everything if (!*x) { g_free (x); x = g_strdup (VOID_ENTRY); } stardict_iterator_next (data->iterator); if (fprintf (data->child_stdin, "%s\n", x) < 0) g_error ("write to eSpeak failed: %s", strerror (errno)); g_free (x); } g_object_unref (data->iterator); return GINT_TO_POINTER (fclose (data->child_stdin)); }
static gchar * expand_regex_vars (ParserState *parser_state, gchar *regex, gint len, GError **error) { /* This is the commented regex without the doubled escape needed * in a C string: * * (?<!\\)(\\\\)*\\%\{([^@]*?)\} * |------------||---||------||-| * | | | | * | the string | the ending * | "\%{" | bracket "}" * | | * a even sequence | * of escapes or the id of the * a char that included regex * is not an (not greedy) * escape (this * is not matched) * * The first block is needed to ensure that the sequence is * not escaped. * Matches with an id containing a "@" sign are ignored and * passed to the engine because they are references to subpatterns * in a different regex (i.e. in the start regex while we are in the * end regex.) * The sub pattern containing the id is the second. */ const gchar *re = "(?<!\\\\)(\\\\\\\\)*\\\\%\\{([^@]*?)\\}"; gchar *expanded_regex; GRegex *egg_re; struct ReplaceByIdData data; if (regex == NULL) return NULL; egg_re = g_regex_new (re, G_REGEX_NEWLINE_LF, 0, NULL); data.parser_state = parser_state; data.error = NULL; expanded_regex = g_regex_replace_eval (egg_re, regex, len, 0, 0, replace_by_id, &data, NULL); if (data.error == NULL) { DEBUG (g_message ("expanded regex vars '%s' to '%s'", regex, expanded_regex)); } g_regex_unref (egg_re); if (data.error != NULL) { g_free (expanded_regex); g_propagate_error (error, data.error); return NULL; } return expanded_regex; }
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 ); #ifdef error_dialog error_dialog ( msg ); #else fputs ( msg, stderr ); #endif g_free ( msg ); // print error. g_error_free ( error ); } return FALSE; }
static void scenario_add_part_from_file( Scenario* scenario, const char* name, const char* target, const char* filename ) { ScenarioPart* part = g_new0(ScenarioPart, 1); part->scenario = scenario; part->name = g_strdup(name); part->events = g_ptr_array_new(); gchar* content = NULL; GError* error = NULL; if (!g_file_get_contents(filename, &content, NULL, &error) || error) { g_critical("failed to read %s: %s", filename, error->message); exit(1); } gchar** urls = g_strsplit(content, "\n", -1); g_free(content); GRegex* pattern = g_regex_new("\\${([^}]+)}", 0, 0, &error); if (error || !pattern) { g_critical("failed to compile regex: %s", error->message); exit(1); } for (int i = 0; urls[i]; ++i) { gchar* url = g_regex_replace_eval( pattern, /* pattern to match */ urls[i], -1, /* content to match on, and strlen */ 0, /* start position */ 0, /* match options */ replace_find_var, NULL, /* eval callback, user arg to callback */ &error ); if (error) { g_critical("regex replace failure in %s - '%s':\n%s", filename, url, error->message); exit(1); } g_ptr_array_add(part->events, event_new_with_url(part, url)); } g_strfreev(urls); g_regex_unref(pattern); scenario->parts = g_list_append(scenario->parts, part); }
static void parse_unsolicited (MMPortSerial *port, GByteArray *response) { MMPortSerialAt *self = MM_PORT_SERIAL_AT (port); GSList *iter; /* Remove echo */ if (self->priv->remove_echo) mm_port_serial_at_remove_echo (response); for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) { MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data; GMatchInfo *match_info; gboolean matches; if (!handler->enable) continue; matches = g_regex_match_full (handler->regex, (const char *) response->data, response->len, 0, 0, &match_info, NULL); if (handler->callback) { while (g_match_info_matches (match_info)) { handler->callback (self, match_info, handler->user_data); g_match_info_next (match_info, NULL); } } g_match_info_free (match_info); if (matches) { /* Remove matches */ char *str; int result_len = response->len; str = g_regex_replace_eval (handler->regex, (const char *) response->data, response->len, 0, 0, remove_eval_cb, &result_len, NULL); g_byte_array_remove_range (response, 0, response->len); g_byte_array_append (response, (const guint8 *) str, result_len); g_free (str); } } }
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 ); }
gchar* misc_macro_expand(const GRegex* regex, const gchar *string, const GHashTable *table) { MiscMacroExpandData data; data.table = table; return g_regex_replace_eval( regex, /* regex */ string, /* string */ -1, /* string_len */ 0, /* start_position */ 0, /* match_options */ misc_macro_expand_cb, /* eval */ &table, /* user_data */ NULL /* error */ ); }
static void parse_unsolicited (MMSerialPort *port, GByteArray *response) { MMAtSerialPort *self = MM_AT_SERIAL_PORT (port); MMAtSerialPortPrivate *priv = MM_AT_SERIAL_PORT_GET_PRIVATE (self); GSList *iter; for (iter = priv->unsolicited_msg_handlers; iter; iter = iter->next) { MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data; GMatchInfo *match_info; gboolean matches; matches = g_regex_match_full (handler->regex, (const char *) response->data, response->len, 0, 0, &match_info, NULL); if (handler->callback) { while (g_match_info_matches (match_info)) { handler->callback (self, match_info, handler->user_data); g_match_info_next (match_info, NULL); } } g_match_info_free (match_info); if (matches) { /* Remove matches */ char *str; int result_len = response->len; str = g_regex_replace_eval (handler->regex, (const char *) response->data, response->len, 0, 0, remove_eval_cb, &result_len, NULL); g_byte_array_remove_range (response, 0, response->len); g_byte_array_append (response, (const guint8 *) str, result_len); g_free (str); } } }
static gchar * expand_regex_delimiters (ParserState *parser_state, gchar *regex, gint len) { /* This is the commented regex without the doubled escape needed * in a C string: * * (?<!\\)(\\\\)*\\%([\[|\]) * |------------||---------| * | | * | the strings * | "\%[" or "\%]" * | * a even sequence of escapes or * a char that is not an escape * (this is not matched) * * The first block is needed to ensure that the sequence is * not escaped. */ const gchar *re = "(?<!\\\\)(\\\\\\\\)*\\\\%(\\[|\\])"; gchar *expanded_regex; static GRegex *egg_re; if (regex == NULL) return NULL; if (egg_re == NULL) egg_re = g_regex_new (re, G_REGEX_NEWLINE_LF | G_REGEX_OPTIMIZE, 0, NULL); expanded_regex = g_regex_replace_eval (egg_re, regex, len, 0, 0, replace_delimiter, parser_state, NULL); DEBUG (g_message ("expanded regex delims '%s' to '%s'", regex, expanded_regex)); return expanded_regex; }
static gchar * prepare_query (gchar *query, GList *entries) { GRegex *regex; GMatchInfo *match; GError *error = NULL; gchar *rval; regex = g_regex_new("\\$(\\w+)\\[(\\d+)\\]\\.(\\w+)", 0, 0, &error); if (error) { HASHFS_DEBUG("Failed to create regex: %s", error->message); g_error_free(error); return NULL; } rval = g_regex_replace_eval(regex, query, -1, 0, 0, eval_cb, entries, NULL); g_regex_unref(regex); return rval; }
static void exec_cmd_entry ( DRunModeEntry *e ) { GError *error = NULL; GRegex *reg = g_regex_new ( "%[a-zA-Z]", 0, 0, &error ); if ( error != NULL ) { g_warning ( "Internal error, failed to create regex: %s.", 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 ) { g_warning ( "Internal error, failed replace field codes: %s.", error->message ); g_error_free ( error ); return; } g_regex_unref ( reg ); if ( earg.success == FALSE ) { g_warning ( "Invalid field code in Exec line: %s.", e->exec );; return; } if ( str == NULL ) { g_warning ( "Nothing to execute after processing: %s.", e->exec );; return; } const gchar *fp = 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; } RofiHelperExecuteContext context = { .name = e->name, .icon = e->icon_name, .app_id = e->app_id, }; gboolean sn = g_key_file_get_boolean ( e->key_file, "Desktop Entry", "StartupNotify", NULL ); gchar *wmclass = NULL; if ( sn && g_key_file_has_key ( e->key_file, "Desktop Entry", "StartupWMClass", NULL ) ) { context.wmclass = wmclass = g_key_file_get_string ( e->key_file, "Desktop Entry", "StartupWMClass", 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, sn ? &context : NULL ) ) { 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 ( wmclass ); g_free ( exec_path ); g_free ( str ); } /** * This function absorbs/freeś path, so this is no longer available afterwards. */ static gboolean read_desktop_file ( DRunModePrivateData *pd, const char *root, const char *path, const gchar *basename ) { // Create ID on stack. // We know strlen (path ) > strlen(root)+1 const ssize_t id_len = strlen ( path ) - strlen ( root ); char id[id_len]; g_strlcpy ( id, &( path[strlen ( root ) + 1] ), id_len ); for ( int index = 0; index < id_len; index++ ) { if ( id[index] == '/' ) { id[index] = '-'; } } // Check if item is on disabled list. if ( g_hash_table_contains ( pd->disabled_entries, id ) ) { g_debug ( "Skipping: %s, was previously seen.", id ); return TRUE; } GKeyFile *kf = g_key_file_new (); GError *error = NULL; g_key_file_load_from_file ( kf, path, 0, &error ); // If error, skip to next entry if ( error != NULL ) { g_debug ( "Failed to parse desktop file: %s because: %s", path, error->message ); g_error_free ( error ); g_key_file_free ( kf ); return FALSE; } // Skip non Application entries. gchar *key = g_key_file_get_string ( kf, "Desktop Entry", "Type", NULL ); if ( key == NULL ) { // No type? ignore. g_debug ( "Skipping desktop file: %s because: No type indicated", path ); g_key_file_free ( kf ); return FALSE; } if ( g_strcmp0 ( key, "Application" ) ) { g_debug ( "Skipping desktop file: %s because: Not of type application (%s)", path, key ); g_free ( key ); g_key_file_free ( kf ); return FALSE; } g_free ( key ); // Name key is required. if ( !g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) { g_debug ( "Invalid DesktopFile: '%s', no 'Name' key present.", path ); g_key_file_free ( kf ); return FALSE; } // Skip hidden entries. if ( g_key_file_get_boolean ( kf, "Desktop Entry", "Hidden", NULL ) ) { g_debug ( "Adding desktop file: %s to disabled list because: Hdden", path ); g_key_file_free ( kf ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); return FALSE; } // Skip entries that have NoDisplay set. if ( g_key_file_get_boolean ( kf, "Desktop Entry", "NoDisplay", NULL ) ) { g_debug ( "Adding desktop file: %s to disabled list because: NoDisplay", path ); g_key_file_free ( kf ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); return FALSE; } // We need Exec, don't support DBusActivatable if ( !g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) { g_debug ( "Unsupported DesktopFile: '%s', no 'Exec' key present.", path ); g_key_file_free ( kf ); return FALSE; } if ( g_key_file_has_key ( kf, "Desktop Entry", "TryExec", NULL ) ) { char *te = g_key_file_get_string ( kf, "Desktop Entry", "TryExec", NULL ); if ( !g_path_is_absolute ( te ) ) { char *fp = g_find_program_in_path ( te ); if ( fp == NULL ) { g_free ( te ); g_key_file_free ( kf ); return FALSE; } g_free ( fp ); } else { if ( g_file_test ( te, G_FILE_TEST_IS_EXECUTABLE ) == FALSE ) { g_free ( te ); g_key_file_free ( kf ); return FALSE; } } g_free ( te ); } size_t nl = ( ( pd->cmd_list_length ) + 1 ); if ( nl >= pd->cmd_list_length_actual ) { pd->cmd_list_length_actual += 256; pd->entry_list = g_realloc ( pd->entry_list, pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) ); } pd->entry_list[pd->cmd_list_length].icon_size = 0; pd->entry_list[pd->cmd_list_length].root = g_strdup ( root ); pd->entry_list[pd->cmd_list_length].path = g_strdup ( path ); pd->entry_list[pd->cmd_list_length].app_id = g_strndup ( basename, strlen ( basename ) - strlen ( ".desktop" ) ); gchar *n = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL ); pd->entry_list[pd->cmd_list_length].name = n; gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL ); pd->entry_list[pd->cmd_list_length].generic_name = gn; pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, "Desktop Entry", "Categories", NULL, NULL, NULL ); pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL ); if ( config.show_icons ) { pd->entry_list[pd->cmd_list_length].icon_name = g_key_file_get_locale_string ( kf, "Desktop Entry", "Icon", NULL, NULL ); } else{ pd->entry_list[pd->cmd_list_length].icon_name = NULL; } pd->entry_list[pd->cmd_list_length].icon = NULL; // Keep keyfile around. pd->entry_list[pd->cmd_list_length].key_file = kf; // We don't want to parse items with this id anymore. g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); ( pd->cmd_list_length )++; return TRUE; } /** * Internal spider used to get list of executables. */ static void walk_dir ( DRunModePrivateData *pd, const char *root, const char *dirname ) { DIR *dir; g_debug ( "Checking directory %s for desktop files.", dirname ); dir = opendir ( dirname ); if ( dir == NULL ) { return; } struct dirent *file; gchar *filename = NULL; struct stat st; while ( ( file = readdir ( dir ) ) != NULL ) { if ( file->d_name[0] == '.' ) { continue; } switch ( file->d_type ) { case DT_LNK: case DT_REG: case DT_DIR: case DT_UNKNOWN: filename = g_build_filename ( dirname, file->d_name, NULL ); break; default: continue; } // On a link, or if FS does not support providing this information // Fallback to stat method. if ( file->d_type == DT_LNK || file->d_type == DT_UNKNOWN ) { file->d_type = DT_UNKNOWN; if ( stat ( filename, &st ) == 0 ) { if ( S_ISDIR ( st.st_mode ) ) { file->d_type = DT_DIR; } else if ( S_ISREG ( st.st_mode ) ) { file->d_type = DT_REG; } } } switch ( file->d_type ) { case DT_REG: // Skip files not ending on .desktop. if ( g_str_has_suffix ( file->d_name, ".desktop" ) ) { read_desktop_file ( pd, root, filename, file->d_name ); } break; case DT_DIR: walk_dir ( pd, root, filename ); break; default: break; } g_free ( filename ); } closedir ( dir ); }
static VALUE rg_replace(gint argc, VALUE *argv, VALUE self) { VALUE rb_string; VALUE rb_replacement; VALUE rb_options; VALUE rb_start_position; VALUE rb_match_options; VALUE rb_literal; GError *error = NULL; gchar *modified_string; const gchar *string; const gchar *replacement; gssize string_len = -1; gint start_position = 0; GRegexMatchFlags match_options = 0; if (rb_block_given_p()) { RGRegexEvalCallbackData data; rb_scan_args(argc, argv, "11", &rb_string, &rb_options); rbg_scan_options(rb_options, "start_position", &rb_start_position, "match_options", &rb_match_options, NULL); string = RVAL2CSTR(rb_string); string_len = RSTRING_LEN(rb_string); if (!NIL_P(rb_start_position)) start_position = NUM2INT(rb_start_position); if (!NIL_P(rb_match_options)) match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options); data.callback = rb_block_proc(); data.status = 0; modified_string = g_regex_replace_eval(_SELF(self), string, string_len, start_position, match_options, rg_regex_eval_callback, &data, &error); if (!(data.status == 0 || data.status == RUBY_TAG_BREAK)) { if (error) g_error_free(error); g_free(modified_string); rb_jump_tag(data.status); } } else { rb_scan_args(argc, argv, "21", &rb_string, &rb_replacement, &rb_options); rbg_scan_options(rb_options, "start_position", &rb_start_position, "match_options", &rb_match_options, "literal", &rb_literal, NULL); string = RVAL2CSTR(rb_string); string_len = RSTRING_LEN(rb_string); replacement = RVAL2CSTR(rb_replacement); if (!NIL_P(rb_start_position)) start_position = NUM2INT(rb_start_position); if (!NIL_P(rb_match_options)) match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options); if (RVAL2CBOOL(rb_literal)) { modified_string = g_regex_replace_literal(_SELF(self), string, string_len, start_position, replacement, match_options, &error); } else { modified_string = g_regex_replace(_SELF(self), string, string_len, start_position, replacement, match_options, &error); } } if (error) RAISE_GERROR(error); return CSTR2RVAL_FREE(modified_string); }