mv to src

This commit is contained in:
fiplox 2021-12-19 23:47:55 +01:00
parent 8a22d221dc
commit 1b3e3680f9
4 changed files with 0 additions and 281 deletions

100
cparse.c
View File

@ -1,100 +0,0 @@
#include "vec.h"
#include <errno.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int find_funcs(const char *path)
{
FILE *fp;
regex_t fdre, fcre;
int ret;
char line[1024];
char boum[1024];
regmatch_t rm[2];
const char *re_func_decl = "^(\\w+(\\s+)?\\**){2,}\\([^!@#$+%^]+?\\)\\s+";
const char *re_func_call = "([a-zA-Z_0-9]+)\\(.*\\)";
fp = fopen(path, "r");
if (fp == 0) {
fprintf(stderr, "Failed to open file %s (%d: %s)\n", path, errno, strerror(errno));
return EXIT_FAILURE;
}
ret = regcomp(&fdre, re_func_decl, REG_EXTENDED);
if (ret != 0) {
fprintf(stderr, "Failed to compile regex '%s'\n", re_func_decl);
return EXIT_FAILURE;
}
ret = regcomp(&fcre, re_func_call, REG_EXTENDED);
if (ret != 0) {
fprintf(stderr, "Failed to compile regex '%s'\n", re_func_call);
return EXIT_FAILURE;
}
bool in = false;
graph_vec g = new_graph(10);
int index;
int cur_node;
while ((fgets(line, 1024, fp)) != NULL) {
if (in && line[0] == '}') {
in = false;
}
if (in) {
if (regexec(&fcre, line, 2, rm, 0) == 0) {
// printf("Line: <<%.*s>>\n", (int)(rm[0].rm_eo - rm[0].rm_so), line + rm[0].rm_so);
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[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, 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) { // function definition
sprintf(boum, "%.*s", (int)(rm[1].rm_eo - rm[1].rm_so), line + rm[1].rm_so);
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;
}
}
// for (int j = 0; j < g.n; j++) {
// printf("NODE %d: %s\n", j, g.node[j]->func);
// }
// 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);
delete_graph(&g);
return 0;
}
int main(int argc, char *argv[])
{
find_funcs("./memline.c");
// graph_vec g = new_graph(3);
// insert_node(&g, new_node(0), "main");
// insert_node(&g, new_node(1), "main1");
// insert_node(&g, new_node(2), "main2");
// printf("%d %d %d\n", g.node[0]->num,g.node[1]->num,g.node[2]->num);
// printf("%s %s %s\n", g.func[0],g.func[1],g.func[2]);
// delete_graph(&g);
return 0;
}

View File

@ -1,13 +0,0 @@
typedef char fix_str[256];
struct edge {
int i; // noeud de depart
int j; // noeud d'arrivé
};
struct graph_mco {
int nbs; // nombre de sommets
int nba; // nombre d'aretes
fix_str *func; // noms de fonction
struct edge *vec; // vecteur d'aretes
};

139
vec.c
View File

@ -1,139 +0,0 @@
#include "vec.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
nodept new_node(int num)
{
struct node *n = malloc(sizeof(nodept));
assert(n);
// n->succ = malloc((n->cap = 8) * sizeof(nodept));
// assert(n->succ);
n->num = num;
n->nbs = 0;
return n;
}
void delete_node(struct node *n)
{
int i;
// for (i = 0; i < n->nbs; i++) {
// free(n->succ[i]);
// }
// free(n->succ);
}
void insert_succ(graph_vec *g, int i, int i1, fix_str str)
{
if (g->node[i]->nbs == g->node[i]->cap)
g->node[i]->succ = reallocarray(g->node[i]->succ, (g->node[i]->cap += 5), sizeof(nodept));
struct node *n = malloc(sizeof(struct node));
n->num = i;
n->nbs = 0;
strcpy(n->func, str);
g->node[i]->succ[i1] = n;
g->node[i]->nbs++;
}
graph_vec new_graph(int cap)
{
graph_vec g;
g.n = -1;
g.cap = cap;
// g.func = calloc(cap, sizeof(fix_str));
// g.node = calloc(cap, sizeof(nodept));
return g;
}
void insert_node(graph_vec *g, fix_str str)
{
++g->n;
struct node *n = malloc(sizeof(struct node));
n->num = g->n;
n->nbs = 0;
n->cap = 5;
n->succ = malloc(5 * sizeof(nodept));
strcpy(n->func, str);
g->node[g->n] = n;
}
void delete_graph(graph_vec *g)
{
int i, j;
for (i = 0; i <= g->n; ++i) {
if (g->node[i]) {
if (g->node[i]->succ) {
free(g->node[i]->succ);
g->node[i]->succ = NULL;
}
free(g->node[i]);
g->node[i] = NULL;
}
}
}
int is_in(graph_vec g, fix_str func)
{
int i;
for (i = 0; i < g.n; ++i) {
if (strcmp(g.node[i]->func, func) == 0)
return i;
}
return 0;
}
void print_node(nodept node)
{
int i;
printf("NODE: %s\n", node->func);
for (i = 0; i < node->nbs; ++i) {
printf("SUCC: %s\n", node->succ[i]->func);
}
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);
}

29
vec.h
View File

@ -1,29 +0,0 @@
#include <stdbool.h>
typedef char fix_str[256];
typedef struct node *nodept;
typedef struct nodes graph_vec;
struct nodes {
int n;
int cap;
nodept node[1000];
};
struct node {
int num; // le numero de noeud
int nbs; // nombre de successeurs
fix_str func; // noms de fonctions
int cap;
nodept *succ; // les successeurs
};
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, 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);