static gboolean SearchFile(const gchar *path, // IN const gchar *fname, // IN GList **list) // OUT { gboolean ret = FALSE; gchar *pattern; GRegex *regExpr; GDir *dir = NULL; GError *error = NULL; pattern = g_strdup_printf("%s.[0-9]+", fname); regExpr = g_regex_new(pattern, 0, 0, &error); if (!regExpr) { Error("Failed to compile %s: %s.\n", pattern, error->message); goto exit; } dir = g_dir_open(path, 0, &error); if (!dir) { Error("Failed to open %s: %s.\n", path, error->message); goto exit; } *list = MatchFile(dir, regExpr); ret = TRUE; exit: g_free(pattern); g_clear_error(&error); if (dir) { g_dir_close(dir); } if (regExpr) { g_regex_unref(regExpr); } return ret; }
string GFlagsHandler::GetFlags( const vector<pair<string, string> >& target_files) { vector<CommandLineFlagInfo> flags_info; // This function is thread safe google::GetAllFlags(&flags_info); string response; bool is_file_name_matched = false; string current_file_name; for (vector<CommandLineFlagInfo>::const_iterator iter = flags_info.begin(); iter != flags_info.end(); ++iter) { const string& file_name = iter->filename; if (current_file_name == file_name) { // If 'target_files' are specified, only print flags of 'target_files' if (is_file_name_matched) { AppendFlagInfo(iter->name, iter->current_value, &response); continue; } } current_file_name = file_name; // Should flags of this file be presented? is_file_name_matched = MatchFile(target_files, file_name); if (!is_file_name_matched) { continue; } AppendFileName(file_name, &response); AppendFlagInfo(iter->name, iter->current_value, &response); } return response; }