Bladeren bron

Version 0.51

pull/1/head
Patrick H. E. Foubet 10 jaren geleden
bovenliggende
commit
883b36abe8
22 gewijzigde bestanden met toevoegingen van 828 en 129 verwijderingen
  1. +10
    -0
      NEWS
  2. +10
    -10
      configure
  3. +1
    -1
      configure.ac
  4. +1
    -1
      src/conf.h
  5. +3
    -3
      src/debug.c
  6. +2
    -1
      src/err.c
  7. +3
    -3
      src/gplot.c
  8. +6
    -5
      src/histo.c
  9. +23
    -0
      src/lib.c
  10. +3
    -0
      src/lib.h
  11. +92
    -14
      src/nife.c
  12. +4
    -0
      src/nife.h
  13. +40
    -0
      src/stackC.c
  14. +5
    -0
      src/stackC.h
  15. +242
    -15
      src/stackF.c
  16. +2
    -0
      src/stackF.h
  17. +21
    -0
      src/stackL.c
  18. +4
    -0
      src/stackL.h
  19. +108
    -1
      src/stackN.c
  20. +23
    -17
      src/stackN.h
  21. +220
    -58
      src/stackV.c
  22. +5
    -0
      src/stackV.h

+ 10
- 0
NEWS Bestand weergeven

@@ -1,5 +1,15 @@
History of Nife releases :

2014-08-31 - Nife 0.51 is released.
* Finalising the version 1.0 of the functions dump and restore with the
definition of the NBLF, Nife Binary Linkable Format.
* Modify some labels to clarify the perception of internal mechanisms.
* Some modifications to avoid unnecessary warnings at compilation.
* Temporary suspension of some functions related to the dynamic aspect
of the language because, used improperly, it could be dangerous.
These functions will be include again, but with more explanations and
examples.

2014-06-27 - Nife 0.49 is released.
* Add DEC, HEX, OCT and BIN functions to define the print mode for the
integers. The default is decimal.


+ 10
- 10
configure Bestand weergeven

@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for nife 0.49.
# Generated by GNU Autoconf 2.69 for nife 0.51.
#
# Report bugs to <nife@seriane.fr>.
#
@@ -580,8 +580,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='nife'
PACKAGE_TARNAME='nife'
PACKAGE_VERSION='0.49'
PACKAGE_STRING='nife 0.49'
PACKAGE_VERSION='0.51'
PACKAGE_STRING='nife 0.51'
PACKAGE_BUGREPORT='nife@seriane.fr'
PACKAGE_URL=''

@@ -1262,7 +1262,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures nife 0.49 to adapt to many kinds of systems.
\`configure' configures nife 0.51 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

@@ -1328,7 +1328,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of nife 0.49:";;
short | recursive ) echo "Configuration of nife 0.51:";;
esac
cat <<\_ACEOF

@@ -1415,7 +1415,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
nife configure 0.49
nife configure 0.51
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1838,7 +1838,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by nife $as_me 0.49, which was
It was created by nife $as_me 0.51, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ $0 $@
@@ -2653,7 +2653,7 @@ fi

# Define the identity of the package.
PACKAGE='nife'
VERSION='0.49'
VERSION='0.51'


cat >>confdefs.h <<_ACEOF
@@ -5480,7 +5480,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by nife $as_me 0.49, which was
This file was extended by nife $as_me 0.51, which was
generated by GNU Autoconf 2.69. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
@@ -5546,7 +5546,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
nife config.status 0.49
nife config.status 0.51
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"



+ 1
- 1
configure.ac Bestand weergeven

@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.67])
AC_INIT([nife], [0.49], [nife@seriane.fr])
AC_INIT([nife], [0.51], [nife@seriane.fr])
AM_INIT_AUTOMAKE

AC_CONFIG_SRCDIR([src/tasks.c])


+ 1
- 1
src/conf.h Bestand weergeven

@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#else
#define VERSION "0.47"
#define VERSION "0.51"
#endif

#ifdef HAVE_COMEDILIB_H


+ 3
- 3
src/debug.c Bestand weergeven

@@ -32,9 +32,9 @@ int Debug=1; /* OK by default */

void D_Reset(void)
{
int fd;
int fd, nc;
char NF[24];
chdir(".nife");
nc=chdir(".nife");
if (Debug) {
sprintf(NF,".nife_%d.log",getpid());
if ((fd=open(NF,O_CREAT|O_RDWR|O_TRUNC,0644)) < 0) perror(NF);
@@ -43,7 +43,7 @@ char NF[24];
close(fd);
}
} else dup2(1,2);
chdir("..");
nc=chdir("..");
}

void D_Update(void)


+ 2
- 1
src/err.c Bestand weergeven

@@ -134,6 +134,7 @@ void stopErr(char *M, char *F)

static void traiteErr(int n, char * L)
{
int v;
ERROR=n;
if (D_Cod==0) {
if (ECHOOFF) printf("\n");
@@ -155,7 +156,7 @@ static void traiteErr(int n, char * L)
if (iTERM) {
printf("In loading stdin : line %d !\n", getFDlig());
close(FD_IN); /* pipe ou autre */
dup(iTERM); /* stdin on term */
v = dup(iTERM); /* stdin on term */
iTERM = 0;
}
}


+ 3
- 3
src/gplot.c Bestand weergeven

@@ -52,13 +52,13 @@ static void *stackGP = VIDE;
/* file manipulations */
static void GPF_init(char *f)
{
int fd, r;
int fd, r, nc;
r = chdir(".nife");
if ((fd = creat(f,0600)) != -1) {
write(fd,"# Nife auto-generated GNUplot file !\n",37);
nc=write(fd,"# Nife auto-generated GNUplot file !\n",37);
close(fd);
}
if (r==0) chdir("..");
if (r==0) r=chdir("..");
}

static void GPF_del(char *f)


+ 6
- 5
src/histo.c Bestand weergeven

@@ -157,6 +157,7 @@ int iTERM=0;

void termInit(void)
{
int nc;
for (iTERM=0; iTERM<3; iTERM++) {
if (tcgetattr(iTERM, &t0) != -1) break;
if (iTERM<2) continue;
@@ -174,7 +175,7 @@ void termInit(void)
t1.c_cflag |= CS8;
if (tcsetattr(iTERM, TCSAFLUSH, &t1) == -1) perror("tcsetattr"); /* raw */
/* clear screen */
system("clear");
nc=system("clear");
}

void termReset(void)
@@ -204,7 +205,7 @@ int lireLigne(int fd, char *b, char *s, int nc)
nc = nb de caracteres possible (longueur du buffer */
{
char *d, *f, c, c2, c3, *h, *w, *Wl, *rac;
int n, i, l, ls=0, ins=0, ignTild=0, nbT=0;
int n, i, l, ls=0, ins=0, ignTild=0, nbT=0, Nc;
unsigned int j;
/* printf("lireLigne ... \n"); */
d = b;
@@ -330,8 +331,8 @@ unsigned int j;
/* gestion des caracteres speciaux */
case '\033': /* ESCAPE */
ignTild=1;
read(fd,&c2,1);
read(fd,&c3,1);
Nc=read(fd,&c2,1);
Nc=read(fd,&c3,1);
if (c2 == '[') {
switch(c3) {
case '2' : /* Insert */
@@ -441,7 +442,7 @@ finBoucle:
}
if ((n<1) && iTERM) {
close(FD_IN); /* pipe ou autre */
dup(iTERM); /* stdin on term */
Nc=dup(iTERM); /* stdin on term */
iTERM = 0;
if (ECHOOFF) printf("\n");
return 0;


+ 23
- 0
src/lib.c Bestand weergeven

@@ -83,6 +83,12 @@ char *LMax;
pLibs += strlen(l);
*pLibs++ = '\0';
}

void rmAllFonU(void)
{
while (Fonctions[NBFonc-1].fam == F_USR) NBFonc--;
}

static void addFonc(char *l, void (*f)(void))
{
addFoncT(l,f,0,F_CORE);
@@ -351,9 +357,11 @@ void initLib(void)
addFonP("install",IF_INSTALL);
addFonP("install_f",IF_INSTALLF);
addFonP("install_v",IF_INSTALLV);
/* pas pour le moment !!
addFonP("df_init",IF_DF_INIT);
addFonP("df_start",IF_DF_START);
addFonP("df_stop",IF_DF_STOP);
****************/
addFonc("?ls",IF_show_stackL);
addFonc("?s",IF_show_stack);
/* addFonc("?libX",show_lib_addr); for debugging */
@@ -544,6 +552,10 @@ int i;
}
return VIDE;
}
void * libByInd(long i)
{
return((void*)Fonctions[i].fct);
}

int execLibNrpc(char *C)
{
@@ -666,3 +678,14 @@ int i;
return NULL;
}

long iLibByAddr(void *A)
{
PFC f;
int i;
f = (PFC)A;
for (i=0;i<NBFonc;i++) {
if (f == (PFC)(Fonctions[i].fct)) return (long)i;
}
return 0L;
}


+ 3
- 0
src/lib.h Bestand weergeven

@@ -24,10 +24,13 @@ extern int InstallOn;
extern void initLib(void);
extern int execLibNrpc(char * C);
extern int execLib(char * C);
extern void * libByInd(long i);
extern char * libByAddr(void *A);
extern long iLibByAddr(void *A);
extern void listLibBegin(char *b);
extern char * getLibBegin(char *b);
extern int nbLibBegin(char *b, char **rac);
extern void addFonU(char *l, void *A);
extern void rmAllFonU(void);

#endif

+ 92
- 14
src/nife.c Bestand weergeven

@@ -208,54 +208,132 @@ int i=0;

struct DumpEnt {
double V;
char L[4];
long Scs;
char L[8];
uint32_t Scs;
};

/* Dump and Restore Nblf : Nife Binary Linkable Format */
#define LENT 20
#define LMARK 3

char * DumpRest_ext(char * L)
{
void * M;
char *F;
if ((M = malloc(strlen(L)+5)) == NULL) stopErr("DumpRest_ext","malloc");
F = (char*)M;
sprintf(F,"%s.nblf",L);
return F;
}

void dump_marque(int fd, char C)
{
char b[LMARK+1];
sprintf(b,"<%c>",C);
if ((write (fd, (void*)b, LMARK)) != LMARK)
stopErr("dump","marque");
}

void restore_marque(int fd, char C)
{
char b[LMARK+1];
/* printf("Restore %c ! \n", C); */
if ((read(fd, (void*)b, LMARK)) == LMARK)
if (b[1] == C) return;
stopErr("restore","marque");
}

void rest_links_pr(int i, char *O, char *C)
{
if (i) {
printf("Linking %d %s", i, O);
if (i > 1) printf("s");
printf(" to %s stack.\n",C);
}
}

void dump_rest_pr(int T, int N, char * L) /* T=0 dump, T=1 restore */
{
if (T==0) printf("Dump ");
printf("%d elt",N);
if (N>1) printf("s");
printf(" for %s stack",L);
if (T) printf(" restored");
printf(".\n");
}

static void restoreFic(char *L)
{
int fd;
struct DumpEnt E;
char * F;

dropTrSuite();
if ((fd = open(L,O_RDONLY)) == -1) {
perror(L);
F = DumpRest_ext(L);
if ((fd = open(F,O_RDONLY)) == -1) {
perror(F);
messErr(43);
} else {
if (read(fd,(void*)&E, sizeof(E)) != sizeof(E)) {
if (read(fd,(void*)&E, LENT) != LENT) {
printf("File too small !\n");
messErr(59);
} else {
if (strncmp(E.L,"Nblf", 4) == 0) {
if (strncmp(E.L,"Nblf010", 7) == 0) {
if (E.Scs == (long)getScs()) {
if (E.V == atof(VERSION)) {
restore_marque(fd, 'N');
restore_stackN(fd);
restore_marque(fd, 'C');
restore_stackC(fd);
restore_marque(fd, 'L');
restore_stackL(fd);
restore_marque(fd, 'V');
restore_stackV(fd);
restore_links_stackN();
restore_marque(fd, 'F');
restore_stackF(fd);
restore_marque(fd, 'X');
restore_links_stackV();
} else printf("This file is just available for Nife v %g !\n",E.V);
} else printf("This file have another SCS !\n");
} else printf("Not a NBLF File !\n");
close(fd);
}

}
free((void*)F);
}

static void dumpFic(char *L)
{
int fd;
struct DumpEnt E;
char * F;

dropTrSuite();
if ((fd = open(L,O_CREAT|O_WRONLY,0600)) == -1) {
perror(L);
F = DumpRest_ext(L);
if ((fd = open(F,O_CREAT|O_WRONLY,0600)) == -1) {
perror(F);
messErr(58);
} else {
strncpy(E.L,"Nblf", 4);
strncpy(E.L,"Nblf010", 7);
E.V=atof(VERSION);
E.Scs=(long)getScs();
write(fd,(void*)&E, sizeof(E));
dump_stackV(fd);
dump_stackF(fd);
close(fd);
if ((write(fd,(void*)&E, LENT)) == LENT) {
dump_marque(fd, 'N');
dump_stackN(fd);
dump_marque(fd, 'C');
dump_stackC(fd);
dump_marque(fd, 'L');
dump_stackL(fd);
dump_marque(fd, 'V');
dump_stackV(fd);
dump_marque(fd, 'F');
dump_stackF(fd);
dump_marque(fd, 'X');
close(fd);
} else messErr(58);
}
free((void*)F);
}

static void lectFic(char *L)


+ 4
- 0
src/nife.h Bestand weergeven

@@ -42,5 +42,9 @@ extern void putTrSuite(PFC);
extern void dropTrSuite(void);
extern void compileFile(char *);
extern PFC getTrSuite(void);
extern void dump_marque(int fd, char C);
extern void restore_marque(int fd, char C);
extern void dump_rest_pr(int T, int N, char * L);
extern void rest_links_pr(int i, char *O, char *C);

#endif

+ 40
- 0
src/stackC.c Bestand weergeven

@@ -241,3 +241,43 @@ void IF_debString(void)
_MODIF_stringEnCours_(1);
}

void dump_eltC(int fd, char *A)
{
uint32_t l;
l=strlen(A);
write(fd, (void*)&l, sizeof(l));
write(fd, A, l+1);
}

void dump_stackC(int fd)
{
uint32_t n, i, l;
n = i_StackC;
write(fd, (void*)&n, sizeof(n));
for (i=0; i<n; i++) dump_eltC(fd, stackC[i]);
dump_rest_pr(0,n,"character");
}

char * restore_eltC(int fd)
{
uint32_t l;
void * M;
read(fd, (void*)&l, sizeof(l));
if ((M = malloc(l+1)) == NULL) stopErr("restore_eltC","malloc");
read(fd, M, l+1);
return (char*)M;
}

void restore_stackC(int fd)
{
uint32_t n=0, i, j;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
IF_stackC_clear();
for (i=0; i<n; i++) {
j = i_StackC;
stackC[j++] = restore_eltC(fd);
_MODIF_i_StackC_(j);
}
dump_rest_pr(1,n,"character");
}


+ 5
- 0
src/stackC.h Bestand weergeven

@@ -35,4 +35,9 @@ extern void IF_dateC(void);
extern void IF_show_stackC(void);
extern void IF_debString(void);

extern void dump_eltC(int fd, char*A);
extern char * restore_eltC(int fd);
extern void dump_stackC(int fd);
extern void restore_stackC(int fd);

#endif

+ 242
- 15
src/stackF.c Bestand weergeven

@@ -109,6 +109,7 @@ int i,n;
char *C, *E;
void *A, *W;
struct Fct *F, *FD;
if (AF == VIDE) return;
F = (struct Fct *)AF;
/* printf("updDynFct(%s) at 0x%lx\n", F->l, (long)F); */
if (F->c == VIDE) return;
@@ -227,7 +228,7 @@ char Ctyp;
printf(" %-25s%c %d octets\n",N->l,Ctyp,*((int*)N->c));
Next = N->n;
}
printf("<end of function list>\n");
printf("<end of functions stack>\n");
}

static char cod[MAXCODE];
@@ -921,6 +922,36 @@ struct Fct * N;
return VIDE;
}

void * codFctByInd(long i)
{
void * Next;
struct Fct * N;
long j=0;
Next = stackF;
while (Next != VIDE) {
N = (struct Fct*) Next;
j++;
if (i==j) return (N->c);
Next = N->n;
}
return VIDE;
}

void * fctByInd(long i)
{
void * Next;
struct Fct * N;
long j=0;
Next = stackF;
while (Next != VIDE) {
N = (struct Fct*) Next;
j++;
if (i==j) return Next;
Next = N->n;
}
return VIDE;
}

void * fctByCode(void * C)
{
void * Next;
@@ -1003,6 +1034,36 @@ struct Fct * N;
return NULL;
}

long iFctByCode(void * A)
{
void * Next;
struct Fct * N;
long i=0;
Next = stackF;
while (Next != VIDE) {
i++;
N = (struct Fct*) Next;
if (N->c==A) return i;
Next = N->n;
}
return 0L;
}

long iFctByAddr(void * A)
{
void * Next;
struct Fct * N;
long i=0;
Next = stackF;
while (Next != VIDE) {
i++;
N = (struct Fct*) Next;
if (Next==A) return i;
Next = N->n;
}
return 0L;
}

char * codByAddr(void * A)
{
void * Next;
@@ -1330,13 +1391,74 @@ void IF_debBackC1(void)
putTrSuite(suiteBackC1);
}

void dump_code(int fd, char * C)
{
void * A;
uint32_t i;
write(fd, C, 1);
bcopy((void*)(C+1),(void*)&A,sizeof(A));
switch((Code)*C) {
case T_ONER :
case T_RET :
case T_END :
case T_JEND :
case T_NOP :
case T_DO_I :
case T_DO_J :
case T_DO_K :
case T_LOOP :
case T_PLOO :
case T_EXEK :
break; /* nothing */
case T_NUM :
dump_eltN(fd, A, 0);
break;
case T_CHA :
case T_BKC :
case T_BKC1 :
dump_eltC(fd, (char*)A);
break;
case T_LIB :
i = iLibByAddr(A);
write(fd, (void*)&i, sizeof(i));
break;
case T_FCT :
i = iFctByCode(A);
write(fd, (void*)&i, sizeof(i));
break;
case T_VAR :
i = iVarByAddr(A);
write(fd, (void*)&i, sizeof(i));
break;
case T_IF :
case T_IFN :
case T_DO :
case T_IFD :
case T_JMP :
case T_GOTO :
bcopy((void*)(C+1),(void*)&i,sizeof(i));
write(fd, (void*)&i, sizeof(i));
break;
/* en principe pas possible !!!
case T_FCTP :
i = iFctByAddr(A);
write(fd, (void*)&i, sizeof(i));
break;
*********************/
default :
printf("dump_code : Code %d inconnu !\n",(int)(*C));
messErr(58);
}
}

void dump_stackF(int fd)
{
long n=0, i, j, v, vi;
uint32_t n=0, vv;
long v, vi, i, j, pas, t;
int *av;
void *Next, *A;
struct Fct * N;
char * C, *F, *D;
char * C, *F;
Next = stackF;
while (Next != VIDE) {
N = (struct Fct*) Next;
@@ -1344,6 +1466,7 @@ char * C, *F, *D;
Next = N->n;
}
write(fd, (void*)&n, sizeof(n));
t = sizeof(A) + 1;
for (i=n; i>0; i--) {
Next = stackF;
j=0;
@@ -1353,35 +1476,139 @@ char * C, *F, *D;
if (i==j) break;
Next = N->n;
}
updDynFct(Next,0);
write(fd, (void*)&(N->typ), sizeof(N->typ));
write(fd, (void*)(N->l), strlen(N->l)+1);
dump_eltC(fd, N->l);
A = N->c;
av = (int*)A;
vi = (long)*av++; /* i */
write(fd, (void*)&v, sizeof(v));
vv = vi / t;
write(fd, (void*)&vv, sizeof(vv));
v = (long)*av++; /* ea */
write(fd, (void*)&v, sizeof(v));
vv = v / t;
write(fd, (void*)&vv, sizeof(vv));
v = (long)*av++; /* Ea */
write(fd, (void*)&v, sizeof(v));
vv = v / t;
write(fd, (void*)&vv, sizeof(vv));
C = (char*)A+(3*sizeof(int));
D = C;
F = C+vi;
pas = sizeof(A) + 1;
while (C < F) {
dump_code(fd, C);
C += pas;
}
}
dump_rest_pr(0,n,"user functions");
}

void restore_links_stackF(void)
{
void **ANext, *A;
return;
}

static int NbARIV, NbARIL, NbARIF;
void restore_code(int fd, char * b, long delta)
{
void * A;
uint32_t i;
int nc;
if ((read(fd, (void*)b, 1)) != 1) return;
switch((Code)*b) {
case T_NUM :
A = restore_eltN(fd);
bcopy((void*)(&A),(void*)(b+1),sizeof(A));
break;
case T_CHA :
case T_BKC :
case T_BKC1 :
A = (void*)restore_eltC(fd);
bcopy((void*)(&A),(void*)(b+1),sizeof(A));
break;
case T_LIB :
nc = read(fd, (void*)&i, sizeof(i));
A = libByInd(i);
bcopy((void*)(&A),(void*)(b+1),sizeof(A));
NbARIL++;
break;
case T_FCT :
nc = read(fd, (void*)&i, sizeof(i));
A = codFctByInd(i-delta);
/* printf("i=%d delta=%d A=%lx\n",i,delta,(long)A); */
bcopy((void*)(&A),(void*)(b+1),sizeof(A));
NbARIF++;
break;
case T_VAR :
nc = read(fd, (void*)&i, sizeof(i));
A = varAddrByInd(i);
bcopy((void*)(&A),(void*)(b+1),sizeof(A));
NbARIV++;
break;
case T_IF :
case T_IFN :
case T_DO :
case T_IFD :
case T_JMP :
case T_GOTO :
nc = read(fd, (void*)&i, sizeof(i));
bcopy((void*)(&i),(void*)(b+1),sizeof(i));
break;
default :
break;
}
/* printf("\tCODE=%d i=%d\n", (int)*b, (int)i); */
}

void restore_stackF(int fd)
{
long n=0, i;
uint32_t n=0, vv;
long i, vi, v, pas, t;
short typ;
char Lib[LDFLT+2], *b;
char *Lib, *C, *F;
void * M;
struct Fct *Elt;
int *bi, nc;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
/* printf("Il y a %ld fonctions !\n",n); */
/* suppress all fcts */
rmAllFonU();
while (stackF != VIDE) {
Elt = (struct Fct *)stackF;
stackF = Elt->n;
eraseFct(Elt);
}
/* printf("Nb fct : %d\n", n); */
NbARIV=NbARIF=NbARIL=0;
t = sizeof(M) + 1;
for (i=0; i<n; i++) {
read(fd, (void*)&typ, sizeof(typ));
b=Lib;
while(*b != '\0') read(fd,++b,1);
/* printf("Fct %s (%d)\n", Lib+1, typ); */
nc = read(fd, (void*)&typ, sizeof(typ));
Lib = restore_eltC(fd);
initFct(Lib,typ);
nc=read(fd, (void*)&vv, sizeof(vv));
vi = vv * t;
if ((M = malloc((3*sizeof(int))+vi)) == NULL)
stopErr("restore_stackF","malloc");
bi = (int*)M;
*bi++ = (int)vi;
nc=read(fd, (void*)&vv, sizeof(vv));
v = vv * t;
*bi++ = (int)v;
/* printf("Nom=<%s> type=%d vi=%d v1=%d", Lib, typ, (int)vi, (int)v); */
nc=read(fd, (void*)&vv, sizeof(vv));
v = vv * t;
*bi = (int)v;
/* printf(" v2=%d\n", (int)v); */
C = (char*)M+(3*sizeof(int));
F = C+vi;
pas = sizeof(M) + 1;
putCodeFct(M);
while (C < F) {
restore_code(fd, C, n-(i+1));
C += pas;
}
}
dump_rest_pr(1,n,"user functions");
rest_links_pr(NbARIV, "variable", "user functions");
rest_links_pr(NbARIL, "library function", "user functions");
rest_links_pr(NbARIF, "user function", "user functions");
}


+ 2
- 0
src/stackF.h Bestand weergeven

@@ -82,9 +82,11 @@ extern void IF_DO_Next(void);
extern void IF_DO_Show(void);
extern void execCode(void *C);
extern void * fctByName(char *L);
extern void * fctByInd(long i);
extern void * fctByCode(void *C);
extern void execFctV(void * A);
extern char * fctByAddr(void *A);
extern long iFctByAddr(void *A);
extern char * codByAddr(void *A);
extern void IF_nDO(void);



+ 21
- 0
src/stackL.c Bestand weergeven

@@ -178,3 +178,24 @@ char s;
} else printf("<end of logical stack>\n");
}


void dump_stackL(int fd)
{
uint32_t n;
n = i_StackL;
write(fd, (void*)&n, sizeof(n));
if (n) write(fd, (void*)stackL, n);
dump_rest_pr(0,n,"logical");
}

void restore_stackL(int fd)
{
uint32_t n=0;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
IF_stackL_clear();
if (n) {
read(fd, (void*)stackL, n);
_MODIF_i_StackL_(n);
}
dump_rest_pr(1,n,"logical");
}

+ 4
- 0
src/stackL.h Bestand weergeven

@@ -37,4 +37,8 @@ extern void IF_true(void);
extern void IF_false(void);
extern void IF_show_stackL(void);

extern void dump_stackL(int fd);
extern void restore_stackL(int fd);


#endif

+ 108
- 1
src/stackN.c Bestand weergeven

@@ -494,7 +494,6 @@ int s;
NElt->n = StackN;
NElt->t = Elt->t & ~MSK_V; /* au cas ou Var */
_MODIF_STACKN_(M);
;
}

void IF_dup(void)
@@ -1958,3 +1957,111 @@ void IF_TABProd(void) { TAB_Fct('*'); }
void IF_TABSum(void) { TAB_Fct('+'); }
void IF_TABMinMax(void) { TAB_Fct('E'); }

#define LENT 20
void dump_eltN(int fd, void *A, uint32_t MSK)
{
struct Num * N;
long l;
long long v;
uint32_t t;
N = (struct Num*)A;
t = N->t;
if ((MSK) && (t & MSK_V)) {
v = (long long)iVarByAddrA(A);
t = 1 | MSK_V;
write(fd, (void*)&t, sizeof(t));
write(fd, (void*)&v, sizeof(v));
} else {
/* t &= ~MSK_V; */
write(fd, (void*)&t, sizeof(t));
l = t & MSK_T;
write(fd, (void*)&(N->l), (size_t)(l*sizeof(double)));
}
}

static int NbARIV;
void restore_links_stackN(void)
{
void **ANext, *A;
struct Num * N, *T;
if (NbARIV == 0) return;
ANext = &StackN;
while (*ANext != VIDE) {
N = (struct Num*) *ANext;
if (N->t & MSK_V) {
A = varAddrAByInd(N->l);
T = (struct Num*) A;
T->n = N->n;
*ANext = A;
free((void*)N);
}
ANext = &(N->n);
}
rest_links_pr(NbARIV, "variable", "numerical");
}

void dump_stackN(int fd)
{
void * Next;
struct Num * N;
uint32_t n=0;
int i,j;
Next = StackN;
while (Next != VIDE) {
N = (struct Num*) Next;
n++;
Next = N->n;
}
write(fd, (void*)&n, sizeof(n));
for (i=n; i>0; i--) {
Next = StackN;
j=0;
while (Next != VIDE) {
N = (struct Num*) Next;
j++;
if (i==j) break;
Next = N->n;
}
dump_eltN(fd, Next, MSK_V);
}
dump_rest_pr(0,n,"numerical");
}

static void * restore_eltN_l(int fd, int K)
{
uint32_t t, u;
int s;
void * M;
struct Num * N;
read(fd, (void*)&t, sizeof(t));
u = t & MSK_T;
if ((t & MSK_V) && K) NbARIV++;
/* printf("%u : %d\n", u, NbARIV); /* debug */
s = sizeof(struct Num)+((u-1)*(sizeof(double)));
if ((M = malloc(s)) == NULL) stopErr("restore_eltN","malloc");
N = (struct Num*)M;
N->t = t;
N->n = StackN;
read(fd, (void*)&(N->l), u*sizeof(double));
return M;
}

void * restore_eltN(int fd)
{
return restore_eltN_l(fd,0);
}

void restore_stackN(int fd)
{
uint32_t n=0, i;
void * M;
NbARIV = 0;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
IF_stack_clear();
for (i=0; i<n; i++) {
M = restore_eltN_l(fd,1);
_MODIF_STACKN_(M);
}
dump_rest_pr(1,n,"numerical");
}


+ 23
- 17
src/stackN.h Bestand weergeven

@@ -91,23 +91,23 @@ extern void IF_Linfeg(void);
extern void IF_inFile_1(FILE * fd);
extern void IF_inFile_1d(FILE * fd, char delim, int virg);
extern void IF_inFile_2(FILE * fd);
void IF_TShiftR(void);
void IF_TShiftL(void);
void IF_NTShiftR(void);
void IF_NTShiftL(void);
void IF_TNShiftR(void);
void IF_TNShiftL(void);
void IF_NTNShiftR(void);
void IF_NTNShiftL(void);
void IF_subTab(void);
void IF_subTabR(void);
void IF_NsubTab(void);
void IF_NsubTabR(void);
void IF_TabRev(void);
void IF_NTabRev(void);
void IF_TabTransp(void);
void IF_TabTranspN(void);
void IF_TabTranspT(void);
extern void IF_TShiftR(void);
extern void IF_TShiftL(void);
extern void IF_NTShiftR(void);
extern void IF_NTShiftL(void);
extern void IF_TNShiftR(void);
extern void IF_TNShiftL(void);
extern void IF_NTNShiftR(void);
extern void IF_NTNShiftL(void);
extern void IF_subTab(void);
extern void IF_subTabR(void);
extern void IF_NsubTab(void);
extern void IF_NsubTabR(void);
extern void IF_TabRev(void);
extern void IF_NTabRev(void);
extern void IF_TabTransp(void);
extern void IF_TabTranspN(void);
extern void IF_TabTranspT(void);
extern int is1Tab(void);
extern int is2Tab(void);
extern int isNTabSameDim(int n);
@@ -117,6 +117,12 @@ extern void IF_TABProd(void);
extern void IF_TABSum(void);
extern void IF_TABMinMax(void);

extern void dump_eltN(int fd, void *A, uint32_t M);
extern void * restore_eltN(int fd);
extern void dump_stackN(int fd);
extern void restore_stackN(int fd);
extern void restore_links_stackN(void);

/* net functions */
extern void IF_NetKey(void);
extern void IF_NetErrVal(void);


+ 220
- 58
src/stackV.c Bestand weergeven

@@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define VT_N 3 /* NUMBER */
#define VT_L 4 /* LIB FUNCTION */
#define VT_F 5 /* USER FUNCTION */
#define VT_XF 15 /* USER FUNCTION NOT IDENTIFIED during restore */

#define VT_V 9 /* VARIABLE (for "install_v ... in" only) */

@@ -73,20 +74,26 @@ struct Var *vS, *vD;
vD->a = duplicateNum(vS->a, 0);
}

void initVar(char *Lib)
void initVarSL(char *L)
{
void * M, *L;
void * M;
struct Var * N;
if ((M = malloc(sizeof(struct Var))) == NULL) stopErr("initVar","malloc");
if ((L = malloc(strlen(Lib)+1)) == NULL) stopErr("initVar","malloc");
strcpy((char*)L,Lib);
if ((M = malloc(sizeof(struct Var))) == NULL) stopErr("initVarSL","malloc");
N = (struct Var*)M;
N->l = (char*)L;
N->l = L;
N->n = stackV;
N->t = VT_I;
stackV = M;
}

void initVar(char *Lib)
{
void *L;
if ((L = malloc(strlen(Lib)+1)) == NULL) stopErr("initVar","malloc");
strcpy((char*)L,Lib);
initVarSL((char*)L);
}

static void setCodeVar(struct Var * Elt, short t, void* A)
{
switch (Elt->t) { /* TODO VT_F */
@@ -147,49 +154,13 @@ struct Var * N;
case VT_F :
printf("User Fct. %s", fctByAddr(N->a));
break;
default :
printf("Undefined (%d) !??", N->t);
}
printf("\n");
Next = N->n;
}
printf("<end of variable list>\n");
}

void dump_stackV(int fd)
{
void * Next, *A;
char * noms, *pn;
struct Var * N;
long n, l, i;
n=l=0;
Next = stackV;
while (Next != VIDE) {
N = (struct Var*) Next;
n++;
l += (strlen(N->l)+1);
Next = N->n;
}
l++;
write(fd, (void*)&n, sizeof(n));
if (n>0) {
if ((A = malloc(l)) == NULL) stopErr("dump_stackV","malloc");
noms = (char*)A;
pn = noms;
Next = stackV;
while (Next != VIDE) {
N = (struct Var*) Next;
strcpy(pn,N->l);
pn += (strlen(N->l)+1);
Next = N->n;
}
/* on remonte la liste */
while (pn > noms) {
pn -= 2;
while (*pn != '\0') pn--;
pn++;
write (fd,pn,strlen(pn)+1);
}
free(A);
}
printf("<end of variables stack>\n");
}

static void newVar(char * S)
@@ -201,19 +172,6 @@ char Lib[LDFLT+1];
dropTrSuite();
}

void restore_stackV(int fd)
{
long n=0, i;
char Lib[LDFLT+2], *b;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
*Lib=' ';
for (i=0; i<n; i++) {
b=Lib;
while(*b != '\0') read(fd,++b,1);
initVar(Lib+1);
}
}

void IF_debVar(void)
{
putTrSuite(newVar);
@@ -267,6 +225,66 @@ struct Var * N;
return NULL;
}

long iVarByAddr(void * A)
{
void * Next;
struct Var * N;
long i=0;
Next = stackV;
while (Next != VIDE) {
i++;
if (Next==A) return(i);
N = (struct Var*) Next;
Next = N->n;
}
return 0L;
}

long iVarByAddrA(void * A)
{
void * Next;
struct Var * N;
long i=0;
Next = stackV;
while (Next != VIDE) {
i++;
N = (struct Var*) Next;
if (N->a==A) return(i);
Next = N->n;
}
return 0L;
}

void * varAddrByInd(long i)
{
void * Next;
struct Var * N;
long j=0;
Next = stackV;
while (Next != VIDE) {
j++;
if (i==j) return(Next);
N = (struct Var*) Next;
Next = N->n;
}
return NULL;
}

void * varAddrAByInd(long i)
{
void * Next;
struct Var * N;
long j=0;
Next = stackV;
while (Next != VIDE) {
j++;
N = (struct Var*) Next;
if (i==j) return(N->a);
Next = N->n;
}
return NULL;
}

int isVarChar(void * A)
{
struct Var * N;
@@ -440,3 +458,147 @@ struct Var * N;
return 0;
}

void dump_eltV(int fd, void *A)
{
struct Var * N;
uint32_t a;
int nc;
N = (struct Var*)A;
nc = write(fd, (void*)&(N->t), sizeof(N->t));
dump_eltC(fd, N->l);
switch(N->t) {
case VT_I :
break;
case VT_B :
nc = write(fd, (void*)&(N->b), sizeof(N->b));
break;
case VT_C :
dump_eltC(fd, (char*)N->a);
break;
case VT_N :
dump_eltN(fd, N->a, 0);
break;
case VT_L :
a = iLibByAddr(N->a);
nc = write(fd, (void*)&a, sizeof(a));
break;
case VT_F :
a = iFctByAddr(N->a);
nc = write(fd, (void*)&a, sizeof(a));
break;
default :
printf("Var type %d !?\n", N->t);
break;
}
}

void dump_stackV(int fd)
{
void * Next, *A;
struct Var * N;
uint32_t n=0;
long l, i, j;
int nc;
Next = stackV;
while (Next != VIDE) {
N = (struct Var*) Next;
n++;
Next = N->n;
}
nc = write(fd, (void*)&n, sizeof(n));
for (i=n; i>0; i--) {
Next = stackV;
j=0;
while (Next != VIDE) {
N = (struct Var*) Next;
j++;
if (i==j) break;
Next = N->n;
}
dump_eltV(fd, Next);
}
dump_rest_pr(0,n,"variables");
}

void restore_links_stackV(void)
{
void * Next;
struct Var * N;
long i, j=0;
Next = stackV;
while (Next != VIDE) {
N = (struct Var*) Next;
if (N->t == VT_XF) {
i = (long)(N->a);
N->a = fctByInd(i);
N->t = VT_F;
j++;
}
Next = N->n;
}
rest_links_pr(j, "user function", "variables");
}

static int NbARIL;
void restore_eltV(int fd)
{
struct Var * N;
short t;
char *L;
void *A;
bool b;
uint32_t i;
long Vi;
int nc;
if (read(fd, (void*)&t, sizeof(t)) != sizeof(t)) return;
L = restore_eltC(fd);
initVarSL(L);
/* printf("Var %s %d\n", L, t); */
N = (struct Var *)stackV;
switch(t) {
case VT_I :
A = VIDE;
break;
case VT_B :
A = VIDE;
nc = read(fd, (void*)&b, sizeof(b));
break;
case VT_C :
A = (void*) restore_eltC(fd);
break;
case VT_N :
A = restore_eltN(fd);
break;
case VT_L :
nc = read(fd, (void*)&i, sizeof(i));
A = libByInd(i);
NbARIL++;
break;
case VT_F :
nc = read(fd, (void*)&i, sizeof(i));
/* A = fctByInd(i); not possible ! */
Vi = (long)i;
A = (void*)Vi;
t = VT_XF;
break;
default :
printf("Var type %d !?\n", N->t);
break;
}
setCodeVar(N, t, A);
if (t == VT_B) N->b = b;
}

void restore_stackV(int fd)
{
uint32_t n=0, i;
if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
NbARIL=0;
while (stackV != VIDE) rmVar(&stackV, (struct Var *)stackV);
for (i=0; i<n; i++) {
restore_eltV(fd);
}
dump_rest_pr(1,n,"variables");
rest_links_pr(NbARIL, "library function", "variables");
}


+ 5
- 0
src/stackV.h Bestand weergeven

@@ -24,12 +24,17 @@ extern void IF_show_stackV(void);
extern void IF_delVar(void);
extern void dump_stackV(int fd);
extern void restore_stackV(int fd);
extern void restore_links_stackV(void);
extern void rmLastVar(void);
extern int IF_execVar(char *L);
extern int isVarChar(void *A);
extern void * varByName(char *L);
extern char * varByAddr(void *A);
extern char * varByAddrA(void *A);
extern long iVarByAddrA(void *A);
extern long iVarByAddr(void *A);
extern void * varAddrByInd(long i);
extern void * varAddrAByInd(long i);
extern void putInVar(void *A, short t);
extern void IF_setVarI(void);
extern void IF_setVarB(void);


Laden…
Annuleren
Opslaan