working vec for one file
This commit is contained in:
parent
268b92edcd
commit
8d9e2416f2
52
cparse.c
52
cparse.c
@ -14,7 +14,7 @@ int find_funcs(const char *path)
|
||||
char line[1024];
|
||||
char boum[1024];
|
||||
regmatch_t rm[2];
|
||||
const char *re_func_decl = "^(\\w+(\\s+)?){2,}\\([^!@#$+%^]+?\\)\\s+";
|
||||
const char *re_func_decl = "^(\\w+(\\s+)?\\**){2,}\\([^!@#$+%^]+?\\)\\s+";
|
||||
const char *re_func_call = "([a-zA-Z_0-9]+)\\(.*\\)";
|
||||
|
||||
fp = fopen(path, "r");
|
||||
@ -32,11 +32,10 @@ int find_funcs(const char *path)
|
||||
fprintf(stderr, "Failed to compile regex '%s'\n", re_func_call);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int i = 0;
|
||||
bool in = false;
|
||||
graph_vec g = new_graph(10);
|
||||
int index;
|
||||
int i1, i2 = -1;
|
||||
int cur_node;
|
||||
while ((fgets(line, 1024, fp)) != NULL) {
|
||||
if (in && line[0] == '}') {
|
||||
in = false;
|
||||
@ -47,38 +46,39 @@ int find_funcs(const char *path)
|
||||
sprintf(boum, "%.*s", (int)(rm[1].rm_eo - rm[1].rm_so), line + rm[1].rm_so);
|
||||
// printf("%.*s\n", (int)(rm[1].rm_eo - rm[1].rm_so), line + rm[1].rm_so);
|
||||
if ((index = is_in(g, boum))) {
|
||||
if (g.node[i2]->nbs == g.node[i2]->cap)
|
||||
g.node[i2]->succ = reallocarray(g.node[i2]->succ, (g.node[i2]->cap += 5), sizeof(nodept));
|
||||
g.node[i2]->succ[i1] = g.node[index];
|
||||
g.node[i2]->nbs++;
|
||||
i1++;
|
||||
if (g.node[cur_node]->nbs == g.node[cur_node]->cap)
|
||||
g.node[cur_node]->succ = reallocarray(g.node[cur_node]->succ, (g.node[cur_node]->cap += 5), sizeof(nodept));
|
||||
g.node[cur_node]->succ[g.node[cur_node]->nbs] = g.node[index];
|
||||
g.node[cur_node]->nbs++;
|
||||
} else {
|
||||
insert_node(&g, i, boum, false);
|
||||
if (g.node[i2]->nbs == g.node[i2]->cap)
|
||||
g.node[i2]->succ = reallocarray(g.node[i2]->succ, (g.node[i2]->cap += 5), sizeof(nodept));
|
||||
g.node[i2]->succ[i1] = g.node[i];
|
||||
g.node[i2]->nbs++;
|
||||
i1++;
|
||||
i++;
|
||||
insert_node(&g, boum);
|
||||
if (g.node[cur_node]->nbs == g.node[cur_node]->cap)
|
||||
g.node[cur_node]->succ = reallocarray(g.node[cur_node]->succ, (g.node[cur_node]->cap += 5), sizeof(nodept));
|
||||
g.node[cur_node]->succ[g.node[cur_node]->nbs] = g.node[g.n];
|
||||
g.node[cur_node]->nbs++;
|
||||
}
|
||||
}
|
||||
} else if (regexec(&fdre, line, 2, rm, 0) == 0) {
|
||||
} else if (regexec(&fdre, line, 2, rm, 0) == 0) { // function definition
|
||||
sprintf(boum, "%.*s", (int)(rm[1].rm_eo - rm[1].rm_so), line + rm[1].rm_so);
|
||||
// printf("%.*s\n", (int)(rm[1].rm_eo - rm[1].rm_so), line + rm[1].rm_so);
|
||||
insert_node(&g, i, boum, true);
|
||||
i++;
|
||||
i2++;
|
||||
if ((index = is_in(g, boum))) {
|
||||
cur_node = index;
|
||||
} else {
|
||||
insert_node(&g, boum);
|
||||
cur_node = g.n;
|
||||
}
|
||||
// if (strcmp(boum, "ml_new_data") == 0)
|
||||
// printf("%d\n", cur_node);
|
||||
in = true;
|
||||
i1 = 0;
|
||||
}
|
||||
}
|
||||
// for (int j = 0; j < i; j++) {
|
||||
// for (int j = 0; j < g.n; j++) {
|
||||
// printf("NODE %d: %s\n", j, g.node[j]->func);
|
||||
// for (int n = 0; n < g.node[j]->nbs; n++) {
|
||||
// printf("SUCC %d: %s\n", j, g.node[j]->succ[n]->func);
|
||||
// }
|
||||
// }
|
||||
print_node(g.node[0]);
|
||||
// print_node(g.node[0]);
|
||||
dot_graph(g.node[0]);
|
||||
// int test = is_in(g, "ml_new_data");
|
||||
// printf("%s\n", g.node[14]->func);
|
||||
// printf("%d\n", g.node[14]->nbs);
|
||||
regfree(&fdre);
|
||||
regfree(&fcre);
|
||||
fclose(fp);
|
||||
|
188
graph.dot
Normal file
188
graph.dot
Normal file
@ -0,0 +1,188 @@
|
||||
digraph main {
|
||||
ml_open -> mf_open;
|
||||
ml_open -> mf_new;
|
||||
ml_open -> iemsg;
|
||||
ml_open -> xstrlcpy;
|
||||
ml_open -> long_to_char;
|
||||
ml_open -> get_fileformat;
|
||||
ml_open -> set_b0_fname;
|
||||
ml_open -> os_get_user_name;
|
||||
ml_open -> os_get_hostname;
|
||||
ml_open -> long_to_char;
|
||||
ml_open -> findswapname;
|
||||
ml_open -> mf_put;
|
||||
ml_open -> B_SPELL;
|
||||
ml_open -> mf_sync;
|
||||
ml_open -> ml_new_ptr;
|
||||
ml_open -> iemsg;
|
||||
ml_open -> mf_put;
|
||||
ml_open -> ml_new_data;
|
||||
ml_open -> iemsg;
|
||||
ml_open -> mf_put;
|
||||
ml_open -> mf_close;
|
||||
set_b0_fname -> home_replace;
|
||||
set_b0_fname -> os_get_user_name;
|
||||
set_b0_fname -> STRLEN;
|
||||
set_b0_fname -> STRLEN;
|
||||
set_b0_fname -> STRLCPY;
|
||||
set_b0_fname -> memmove;
|
||||
set_b0_fname -> memmove;
|
||||
set_b0_fname -> os_fileinfo;
|
||||
set_b0_fname -> long_to_char;
|
||||
set_b0_fname -> long_to_char;
|
||||
set_b0_fname -> buf_store_file_info;
|
||||
set_b0_fname -> long_to_char;
|
||||
set_b0_fname -> long_to_char;
|
||||
set_b0_fname -> add_b0_fenc;
|
||||
add_b0_fenc -> STRLEN;
|
||||
add_b0_fenc -> STRLEN;
|
||||
add_b0_fenc -> memmove;
|
||||
findswapname -> FUNC_ATTR_NONNULL_ARG;
|
||||
findswapname -> strlen;
|
||||
findswapname -> xmalloc;
|
||||
findswapname -> copy_option_part;
|
||||
findswapname -> makeswapname;
|
||||
findswapname -> strlen;
|
||||
findswapname -> XFREE_CLEAR;
|
||||
findswapname -> os_fileinfo_link;
|
||||
findswapname -> fnamecmp;
|
||||
findswapname -> os_open;
|
||||
findswapname -> read_eintr;
|
||||
findswapname -> fnamecmp;
|
||||
findswapname -> path_tail;
|
||||
findswapname -> same_directory;
|
||||
findswapname -> expand_env;
|
||||
findswapname -> char_to_long;
|
||||
findswapname -> expand_env;
|
||||
findswapname -> char_to_long;
|
||||
findswapname -> close;
|
||||
findswapname -> vim_strchr;
|
||||
findswapname -> os_path_exists;
|
||||
findswapname -> verb_msg;
|
||||
findswapname -> has_autocmd;
|
||||
findswapname -> do_swapexists;
|
||||
findswapname -> attention_message;
|
||||
findswapname -> flush_buffers;
|
||||
findswapname -> _;
|
||||
findswapname -> _;
|
||||
findswapname -> strlen;
|
||||
findswapname -> strlen;
|
||||
findswapname -> strlen;
|
||||
findswapname -> xmalloc;
|
||||
findswapname -> memcpy;
|
||||
findswapname -> home_replace;
|
||||
findswapname -> xstrlcat;
|
||||
findswapname -> do_dialog;
|
||||
findswapname -> xfree;
|
||||
findswapname -> msg_reset_scroll;
|
||||
findswapname -> os_remove;
|
||||
findswapname -> os_path_exists;
|
||||
findswapname -> msg_puts;
|
||||
findswapname -> wait_return;
|
||||
findswapname -> emsg;
|
||||
findswapname -> XFREE_CLEAR;
|
||||
findswapname -> os_isdir;
|
||||
findswapname -> os_mkdir_recurse;
|
||||
findswapname -> os_strerror;
|
||||
findswapname -> xfree;
|
||||
findswapname -> xfree;
|
||||
makeswapname -> resolve_symlink;
|
||||
makeswapname -> STRLEN;
|
||||
makeswapname -> after_pathsep;
|
||||
makeswapname -> make_percent_swname;
|
||||
makeswapname -> modname;
|
||||
makeswapname -> xfree;
|
||||
makeswapname -> modname;
|
||||
makeswapname -> get_file_in_dir;
|
||||
makeswapname -> xfree;
|
||||
resolve_symlink -> STRLCPY;
|
||||
resolve_symlink -> semsg;
|
||||
resolve_symlink -> readlink;
|
||||
resolve_symlink -> vim_FullName;
|
||||
resolve_symlink -> path_is_absolute;
|
||||
resolve_symlink -> STRCPY;
|
||||
resolve_symlink -> path_tail;
|
||||
resolve_symlink -> STRLEN;
|
||||
resolve_symlink -> STRCPY;
|
||||
resolve_symlink -> vim_FullName;
|
||||
make_percent_swname -> FUNC_ATTR_NONNULL_ARG;
|
||||
make_percent_swname -> fix_fname;
|
||||
make_percent_swname -> xstrdup;
|
||||
make_percent_swname -> MB_PTR_ADV;
|
||||
make_percent_swname -> vim_ispathsep;
|
||||
make_percent_swname -> concat_fnames;
|
||||
make_percent_swname -> xfree;
|
||||
make_percent_swname -> xfree;
|
||||
do_swapexists -> set_vim_var_string;
|
||||
do_swapexists -> set_vim_var_string;
|
||||
do_swapexists -> apply_autocmds;
|
||||
do_swapexists -> set_vim_var_string;
|
||||
do_swapexists -> get_vim_var_str;
|
||||
attention_message -> assert;
|
||||
attention_message -> emsg;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_home_replace;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> swapfile_info;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_outtrans;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> os_fileinfo;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_outtrans;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_puts;
|
||||
attention_message -> msg_outtrans;
|
||||
attention_message -> msg_puts;
|
||||
swapfile_info -> assert;
|
||||
swapfile_info -> os_fileinfo;
|
||||
swapfile_info -> os_get_uname;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_outtrans;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> os_open;
|
||||
swapfile_info -> read_eintr;
|
||||
swapfile_info -> STRNCMP;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> ml_check_b0_id;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> ml_check_b0_strings;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_outtrans;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_outtrans;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_outtrans;
|
||||
swapfile_info -> char_to_long;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_outnum;
|
||||
swapfile_info -> os_proc_running;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> b0_magic_wrong;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> close;
|
||||
swapfile_info -> msg_puts;
|
||||
swapfile_info -> msg_putchar;
|
||||
ml_check_b0_strings -> memchr;
|
||||
ml_check_b0_strings -> memchr;
|
||||
ml_check_b0_strings -> memchr;
|
||||
ml_check_b0_strings -> memchr;
|
||||
ml_new_ptr -> mf_new;
|
||||
ml_new_ptr -> sizeof;
|
||||
ml_new_data -> assert;
|
||||
ml_new_data -> mf_new;
|
||||
}
|
47
test.c
Normal file
47
test.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int aurevoir(void)
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
void bonjour(void)
|
||||
{
|
||||
puts("Bonjour !");
|
||||
aurevoir();
|
||||
}
|
||||
|
||||
void bye(void)
|
||||
{
|
||||
puts("Byte...");
|
||||
}
|
||||
|
||||
void hello(void)
|
||||
{
|
||||
puts("Hello, world!");
|
||||
bye();
|
||||
bonjour();
|
||||
}
|
||||
|
||||
void foo(void)
|
||||
{
|
||||
hello();
|
||||
}
|
||||
|
||||
int add(int a, int b)
|
||||
{
|
||||
aurevoir();
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
foo();
|
||||
|
||||
res = add(21, 21);
|
||||
printf("%i\n", res);
|
||||
|
||||
return 0;
|
||||
}
|
52
vec.c
52
vec.c
@ -46,11 +46,11 @@ graph_vec new_graph(int cap)
|
||||
return g;
|
||||
}
|
||||
|
||||
void insert_node(graph_vec *g, int i, fix_str str, bool intern)
|
||||
void insert_node(graph_vec *g, fix_str str)
|
||||
{
|
||||
++g->n;
|
||||
struct node *n = malloc(sizeof(struct node));
|
||||
n->num = i;
|
||||
n->num = g->n;
|
||||
n->nbs = 0;
|
||||
n->cap = 5;
|
||||
n->succ = malloc(5 * sizeof(nodept));
|
||||
@ -87,11 +87,53 @@ void print_node(nodept node)
|
||||
{
|
||||
int i;
|
||||
printf("NODE: %s\n", node->func);
|
||||
for (int i = 0; i < node->nbs; ++i) {
|
||||
for (i = 0; i < node->nbs; ++i) {
|
||||
printf("SUCC: %s\n", node->succ[i]->func);
|
||||
}
|
||||
for (int i = 0; i < node->nbs; ++i) {
|
||||
if (node->succ[i]->intern)
|
||||
for (i = 0; i < node->nbs; ++i) {
|
||||
if (node->succ[i] != node && node->succ[i]->nbs != 0)
|
||||
print_node(node->succ[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// fprintf(fp, "\t%s -> %s;\n", node->func, node->succ[i]->func);
|
||||
void write_node_dot(FILE *fp, nodept node)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < node->nbs; ++i) {
|
||||
fprintf(fp, "\t%s -> %s;\n", node->func, node->succ[i]->func);
|
||||
}
|
||||
for (i = 0; i < node->nbs; ++i) {
|
||||
if (node->succ[i] != node && node->succ[i]->nbs != 0)
|
||||
write_node_dot(fp, node->succ[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void dot_graph(nodept node)
|
||||
{
|
||||
FILE *fp;
|
||||
int i;
|
||||
|
||||
fp = fopen("graph.dot", "w");
|
||||
|
||||
fprintf(fp, "digraph main {\n");
|
||||
write_node_dot(fp, node);
|
||||
// for (i = 0; i < node->nbs; ++i) {
|
||||
// fprintf(fp, "\t%s -> %s;\n", node->func, node->succ[i]->func);
|
||||
// }
|
||||
// for (i = 0; i < node->nbs; ++i) {
|
||||
// if (node->succ[i] != node && node->succ[i]->nbs != 0) {
|
||||
// write_node_dot(fp, node->succ[i]);
|
||||
// fprintf(fp, "\n\t%s ", node->succ[i]->func);
|
||||
//
|
||||
// for (int j = 0; j < node->succ[i]->nbs; ++j) {
|
||||
// fprintf(fp, "-> %s ", node->succ[i]->succ[j]->func);
|
||||
// }
|
||||
//
|
||||
// fprintf(fp, ";\n");
|
||||
// }
|
||||
// }
|
||||
fprintf(fp, "}");
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
4
vec.h
4
vec.h
@ -11,7 +11,6 @@ struct nodes {
|
||||
};
|
||||
|
||||
struct node {
|
||||
bool intern;
|
||||
int num; // le numero de noeud
|
||||
int nbs; // nombre de successeurs
|
||||
fix_str func; // noms de fonctions
|
||||
@ -23,7 +22,8 @@ struct node *new_node(int num);
|
||||
void delete_node(struct node *n);
|
||||
void insert_succ(graph_vec *g, int i, int i1, fix_str str);
|
||||
graph_vec new_graph(int cap);
|
||||
void insert_node(graph_vec *g, int i, fix_str str, bool intern);
|
||||
void insert_node(graph_vec *g, fix_str str);
|
||||
void delete_graph(graph_vec *g);
|
||||
int is_in(graph_vec g, fix_str func);
|
||||
void print_node(nodept node);
|
||||
void dot_graph(nodept node);
|
||||
|
Loading…
Reference in New Issue
Block a user