Release 4.10 tools/perf/util/strlist.c
/*
* (c) 2009 Arnaldo Carvalho de Melo <acme@redhat.com>
*
* Licensed under the GPLv2.
*/
#include "strlist.h"
#include "util.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static
struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry)
{
const char *s = entry;
struct rb_node *rc = NULL;
struct strlist *strlist = container_of(rblist, struct strlist, rblist);
struct str_node *snode = malloc(sizeof(*snode));
if (snode != NULL) {
if (strlist->dupstr) {
s = strdup(s);
if (s == NULL)
goto out_delete;
}
snode->s = s;
rc = &snode->rb_node;
}
return rc;
out_delete:
free(snode);
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 66 | 55.46% | 1 | 50.00% |
david ahern | david ahern | 53 | 44.54% | 1 | 50.00% |
| Total | 119 | 100.00% | 2 | 100.00% |
static void str_node__delete(struct str_node *snode, bool dupstr)
{
if (dupstr)
zfree((char **)&snode->s);
free(snode);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 35 | 97.22% | 3 | 75.00% |
namhyung kim | namhyung kim | 1 | 2.78% | 1 | 25.00% |
| Total | 36 | 100.00% | 4 | 100.00% |
static
void strlist__node_delete(struct rblist *rblist, struct rb_node *rb_node)
{
struct strlist *slist = container_of(rblist, struct strlist, rblist);
struct str_node *snode = container_of(rb_node, struct str_node, rb_node);
str_node__delete(snode, slist->dupstr);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david ahern | david ahern | 42 | 76.36% | 1 | 50.00% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 13 | 23.64% | 1 | 50.00% |
| Total | 55 | 100.00% | 2 | 100.00% |
static int strlist__node_cmp(struct rb_node *rb_node, const void *entry)
{
const char *str = entry;
struct str_node *snode = container_of(rb_node, struct str_node, rb_node);
return strcmp(snode->s, str);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david ahern | david ahern | 25 | 52.08% | 1 | 50.00% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 23 | 47.92% | 1 | 50.00% |
| Total | 48 | 100.00% | 2 | 100.00% |
int strlist__add(struct strlist *slist, const char *new_entry)
{
return rblist__add_node(&slist->rblist, new_entry);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david ahern | david ahern | 17 | 65.38% | 1 | 33.33% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 9 | 34.62% | 2 | 66.67% |
| Total | 26 | 100.00% | 3 | 100.00% |
int strlist__load(struct strlist *slist, const char *filename)
{
char entry[1024];
int err;
FILE *fp = fopen(filename, "r");
if (fp == NULL)
return -errno;
while (fgets(entry, sizeof(entry), fp) != NULL) {
const size_t len = strlen(entry);
if (len == 0)
continue;
entry[len - 1] = '\0';
err = strlist__add(slist, entry);
if (err != 0)
goto out;
}
err = 0;
out:
fclose(fp);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 120 | 100.00% | 3 | 100.00% |
| Total | 120 | 100.00% | 3 | 100.00% |
void strlist__remove(struct strlist *slist, struct str_node *snode)
{
rblist__remove_node(&slist->rblist, &snode->rb_node);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 17 | 60.71% | 1 | 33.33% |
suzuki k poulose | suzuki k poulose | 8 | 28.57% | 1 | 33.33% |
david ahern | david ahern | 3 | 10.71% | 1 | 33.33% |
| Total | 28 | 100.00% | 3 | 100.00% |
struct str_node *strlist__find(struct strlist *slist, const char *entry)
{
struct str_node *snode = NULL;
struct rb_node *rb_node = rblist__find(&slist->rblist, entry);
if (rb_node)
snode = container_of(rb_node, struct str_node, rb_node);
return snode;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 34 | 58.62% | 1 | 33.33% |
david ahern | david ahern | 20 | 34.48% | 1 | 33.33% |
masami hiramatsu | masami hiramatsu | 4 | 6.90% | 1 | 33.33% |
| Total | 58 | 100.00% | 3 | 100.00% |
static int strlist__parse_list_entry(struct strlist *slist, const char *s,
const char *subst_dir)
{
int err;
char *subst = NULL;
if (strncmp(s, "file://", 7) == 0)
return strlist__load(slist, s + 7);
if (subst_dir) {
err = -ENOMEM;
if (asprintf(&subst, "%s/%s", subst_dir, s) < 0)
goto out;
if (access(subst, F_OK) == 0) {
err = strlist__load(slist, subst);
goto out;
}
if (slist->file_only) {
err = -ENOENT;
goto out;
}
}
err = strlist__add(slist, s);
out:
free(subst);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 127 | 88.81% | 3 | 75.00% |
namhyung kim | namhyung kim | 16 | 11.19% | 1 | 25.00% |
| Total | 143 | 100.00% | 4 | 100.00% |
static int strlist__parse_list(struct strlist *slist, const char *s, const char *subst_dir)
{
char *sep;
int err;
while ((sep = strchr(s, ',')) != NULL) {
*sep = '\0';
err = strlist__parse_list_entry(slist, s, subst_dir);
*sep = ',';
if (err != 0)
return err;
s = sep + 1;
}
return *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 96 | 100.00% | 4 | 100.00% |
| Total | 96 | 100.00% | 4 | 100.00% |
struct strlist *strlist__new(const char *list, const struct strlist_config *config)
{
struct strlist *slist = malloc(sizeof(*slist));
if (slist != NULL) {
bool dupstr = true;
bool file_only = false;
const char *dirname = NULL;
if (config) {
dupstr = !config->dont_dupstr;
dirname = config->dirname;
file_only = config->file_only;
}
rblist__init(&slist->rblist);
slist->rblist.node_cmp = strlist__node_cmp;
slist->rblist.node_new = strlist__node_new;
slist->rblist.node_delete = strlist__node_delete;
slist->dupstr = dupstr;
slist->file_only = file_only;
if (list && strlist__parse_list(slist, list, dirname) != 0)
goto out_error;
}
return slist;
out_error:
free(slist);
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 116 | 73.89% | 5 | 62.50% |
david ahern | david ahern | 23 | 14.65% | 1 | 12.50% |
namhyung kim | namhyung kim | 17 | 10.83% | 1 | 12.50% |
ananth n. mavinakayanahalli | ananth n. mavinakayanahalli | 1 | 0.64% | 1 | 12.50% |
| Total | 157 | 100.00% | 8 | 100.00% |
void strlist__delete(struct strlist *slist)
{
if (slist != NULL)
rblist__delete(&slist->rblist);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 22 | 91.67% | 2 | 66.67% |
david ahern | david ahern | 2 | 8.33% | 1 | 33.33% |
| Total | 24 | 100.00% | 3 | 100.00% |
struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx)
{
struct str_node *snode = NULL;
struct rb_node *rb_node;
rb_node = rblist__entry(&slist->rblist, idx);
if (rb_node)
snode = container_of(rb_node, struct str_node, rb_node);
return snode;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 35 | 58.33% | 1 | 50.00% |
david ahern | david ahern | 25 | 41.67% | 1 | 50.00% |
| Total | 60 | 100.00% | 2 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnaldo carvalho de melo | arnaldo carvalho de melo | 732 | 74.01% | 8 | 57.14% |
david ahern | david ahern | 210 | 21.23% | 1 | 7.14% |
namhyung kim | namhyung kim | 34 | 3.44% | 2 | 14.29% |
suzuki k poulose | suzuki k poulose | 8 | 0.81% | 1 | 7.14% |
masami hiramatsu | masami hiramatsu | 4 | 0.40% | 1 | 7.14% |
ananth n. mavinakayanahalli | ananth n. mavinakayanahalli | 1 | 0.10% | 1 | 7.14% |
| Total | 989 | 100.00% | 14 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.