Skip to content

Commit

Permalink
[DGFiP] Make static file more DGFiP-compatible (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck authored Feb 8, 2023
2 parents 02ed2c9 + 02a9294 commit f5f1492
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
14 changes: 3 additions & 11 deletions examples/dgfip_c/desc_static.h.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

#include "conf.h"

struct S_desc_var
{
char *nom;
int indice;
long type_donnee;
T_discord * (*verif)(T_irdata *);
};

typedef struct S_desc_contexte
{
char *nom;
Expand Down Expand Up @@ -56,7 +48,7 @@ typedef struct S_desc_revenu
int rapcat;
int sanction;
int modcat;
T_desc_var *liee;
T_var_irdata liee;
char *libelle;
char *code;
} T_desc_revenu;
Expand All @@ -78,7 +70,7 @@ typedef struct S_desc_revenu_correc
int rapcat;
int sanction;
int modcat;
T_desc_var *liee;
T_var_irdata liee;
char *libelle;
} T_desc_revenu_correc;

Expand Down Expand Up @@ -131,7 +123,7 @@ typedef struct S_desc_debug
int sanction;
int modcat;
int nat_code;
T_desc_var *liee;
T_var_irdata liee;
#ifdef FLG_EXTRACTION
int est_extraite;
#endif /* FLG_EXTRACTION */
Expand Down
33 changes: 24 additions & 9 deletions examples/dgfip_c/irdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
#include <string.h>
#include "var.h"

struct S_desc_var
{
char *nom;
int indice;
long type_donnee;
T_discord * (*verif)(T_irdata *);
};

typedef struct S_desc_var T_desc_var;

static bool alloc_tab(double **tab, char **def_tab, int taille)
{
if ((tab == NULL) || (def_tab == NULL)) {
Expand Down Expand Up @@ -154,8 +164,9 @@ void IRDATA_reset_erreur(T_irdata *irdata)
#endif /* FLG_MULTITHREAD */
}

T_discord * IRDATA_range(T_irdata *irdata, T_desc_var *desc, double valeur)
T_discord * IRDATA_range(T_irdata *irdata, T_var_irdata p_desc, double valeur)
{
T_desc_var *desc = (T_desc_var *)p_desc;
int indice = 0;
T_discord *discord = NULL;
if (valeur < 0) {
Expand All @@ -181,8 +192,9 @@ T_discord * IRDATA_range(T_irdata *irdata, T_desc_var *desc, double valeur)
return discord;
}

void IRDATA_range_base(T_irdata *irdata, T_desc_var *desc, double valeur)
void IRDATA_range_base(T_irdata *irdata, T_var_irdata p_desc, double valeur)
{
T_desc_var *desc = (T_desc_var *)p_desc;
#ifdef FLG_COMPACT
int indice = desc->indice;
irdata->defs[indice] = 1;
Expand All @@ -206,8 +218,9 @@ void IRDATA_range_base(T_irdata *irdata, T_desc_var *desc, double valeur)
#endif /* FLG_COMPACT */
}

struct S_discord * IRDATA_range_tableau(T_irdata *irdata, T_desc_var *desc, int ind, double valeur)
struct S_discord * IRDATA_range_tableau(T_irdata *irdata, T_var_irdata p_desc, int ind, double valeur)
{
T_desc_var *desc = (T_desc_var *)p_desc;
int indice = 0;
T_discord *discord = NULL;
discord = (*desc->verif)(irdata);
Expand Down Expand Up @@ -238,8 +251,9 @@ struct S_discord * IRDATA_range_tableau(T_irdata *irdata, T_desc_var *desc, int
return discord;
}

double * IRDATA_extrait_special(T_irdata *irdata, T_desc_var *desc)
double * IRDATA_extrait_special(T_irdata *irdata, T_var_irdata p_desc)
{
T_desc_var *desc = (T_desc_var *)p_desc;
double *res = NULL;
#ifdef FLG_COMPACT
int indice = desc->indice;
Expand All @@ -264,8 +278,9 @@ double * IRDATA_extrait_special(T_irdata *irdata, T_desc_var *desc)
return res;
}

double * IRDATA_extrait_tableau(T_irdata *irdata, T_desc_var *desc, int ind)
double * IRDATA_extrait_tableau(T_irdata *irdata, T_var_irdata p_desc, int ind)
{
T_desc_var *desc = (T_desc_var *)p_desc;
double *res = NULL;
#ifdef FLG_COMPACT
int indice = desc->indice + ind;
Expand All @@ -290,7 +305,7 @@ double * IRDATA_extrait_tableau(T_irdata *irdata, T_desc_var *desc, int ind)
return res;
}

static T_desc_var * cherche_desc_var(const char *nom, T_desc_var *table, int taille, int sup)
static T_var_irdata cherche_desc_var(const char *nom, T_var_irdata table, int taille, int sup)
{
T_desc_var *desc = NULL;
int res = -1, inf = 0, millieu;
Expand All @@ -302,12 +317,12 @@ static T_desc_var * cherche_desc_var(const char *nom, T_desc_var *table, int tai
else if (res > 0) inf = millieu + 1;
}
if (res == 0)
return desc;
return (T_var_irdata)desc;
else
return NULL;
}

T_desc_var * IRDATA_cherche_desc_var(const char *nom)
T_var_irdata IRDATA_cherche_desc_var(const char *nom)
{
static T_desc_var * desc[6] = {
(T_desc_var *)desc_contexte, (T_desc_var *)desc_famille, (T_desc_var *)desc_revenu,
Expand All @@ -321,7 +336,7 @@ T_desc_var * IRDATA_cherche_desc_var(const char *nom)
int i = 0;
for (i = 0; i < 6; ++i) {
T_desc_var *res = cherche_desc_var(nom, desc[i], size[i], nb[i]);
if (res != NULL) return res;
if (res != NULL) return (T_var_irdata)res;
}
return NULL;
}
15 changes: 7 additions & 8 deletions examples/dgfip_c/irdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
#define DATE (DATE_JJMMAAAA|DATE_MMAAAA|DATE_AAAA|DATE_JJMM|DATE_MM)
#define NUMERIQUE (ENTIER|REEL|REEL1|REEL2|REEL3)

#define T_var_irdata T_desc_var *
typedef void *T_var_irdata;

typedef struct S_desc_var T_desc_var;
typedef struct S_irdata T_irdata;
typedef struct S_discord T_discord;
typedef struct S_erreur T_erreur;
Expand All @@ -43,14 +42,14 @@ extern void IRDATA_recopie_irdata(T_irdata *src_irdata, T_irdata *dst_irdata);

extern void IRDATA_reset_erreur(T_irdata *irdata);

extern T_discord * IRDATA_range(T_irdata *irdata, T_desc_var *desc, double valeur);
extern void IRDATA_range_base(T_irdata *irdata, T_desc_var *desc, double valeur);
struct S_discord *IRDATA_range_tableau(T_irdata *irdata, T_desc_var *desc, int ind, double valeur);
extern T_discord * IRDATA_range(T_irdata *irdata, T_var_irdata desc, double valeur);
extern void IRDATA_range_base(T_irdata *irdata, T_var_irdata desc, double valeur);
struct S_discord *IRDATA_range_tableau(T_irdata *irdata, T_var_irdata desc, int ind, double valeur);

extern double * IRDATA_extrait_special (T_irdata *irdata, T_desc_var *desc);
double * IRDATA_extrait_tableau(T_irdata *irdata, T_desc_var *desc, int ind);
extern double * IRDATA_extrait_special (T_irdata *irdata, T_var_irdata desc);
double * IRDATA_extrait_tableau(T_irdata *irdata, T_var_irdata desc, int ind);

extern T_desc_var * IRDATA_cherche_desc_var(const char *nom);
extern T_var_irdata IRDATA_cherche_desc_var(const char *nom);

extern T_discord * err_NEGATIF(T_irdata *irdata);

Expand Down
12 changes: 12 additions & 0 deletions examples/dgfip_c/ml_primitif/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ CAMLexport value caml_alloc_some(value v)
extern T_desc_penalite desc_penalite[];
extern T_desc_debug desc_debug01[];

struct S_desc_var
{
char *nom;
int indice;
long type_donnee;
T_discord * (*verif)(T_irdata *);
};

typedef struct S_desc_var T_desc_var;

#define T_var_irdata T_desc_var *

typedef void (*ench_fun)(T_irdata *);

typedef struct ench_t {
Expand Down

0 comments on commit f5f1492

Please sign in to comment.