Voici la source:
// Create a variable using functions from vat.h
// Original file from Zeljko Juric
// (A bit mofified and) extended by Ordivore
// On 23,March 2003
// Version 1.00:without floating-point numbers
// maybe(but a VERY maybe!) TEXT variables to come...
//////////////////////////////////////////////////////////////////////////////////////
// Usage: //
// First use CreateFile to make your file or reopen //
// ***For Simples TIOS variables //
// 1)use either AppendStringToFile,AppendNumberToFile,or AppendFracToFile //
// 2)use CloseFile //
// ***For making List or Matrix //
// ***use AppendCharToFile to put as usual the END_TAG and LIST_TAG tags in a //
// correct sentence: [[a,b,c],[d,e,f]] is coded by END_TAG,END_TAG,f,e,d, //
// LIST_TAG,END_TAG,c,b,a,LIST_TAG,LIST_TAG //
// ***use either AppendStringToFile,AppendNumberToFile,AppendFracToFile //
// ***of course,close your file //
//////////////////////////////////////////////////////////////////////////////////////
#include <tigcclib.h> // Include All Header Files
void AppendCharToFile (HANDLE h, unsigned char c)
{
char *base = HeapDeref(h);
unsigned short len = *(unsigned short*)base;
if (len > HeapSize(h) - 10) return;
*(unsigned short*)base = len + 1;
base[len+2] = c;
}
HANDLE CreateFile (const char *FileName)
// Returns a handle, H_NULL in case of error
{
HANDLE h;
SYM_ENTRY *sym_entry;
char str[30], *sptr = str;
*sptr = 0; while ((*++sptr = *FileName++));//sptr=SYMSTR(FileName);
if (!(h = HeapAlloc (HeapMax ()))) return H_NULL;//At the moment,all rest of the memory
if (!(sym_entry = DerefSym (SymAdd (sptr))))
{
HeapFree (h);
return H_NULL;
}
*(long*) HeapDeref (sym_entry->handle = h) = 0;
AppendCharToFile(h,END_TAG);
return h;
}
void AppendBlockToFile (HANDLE h, void *addr, unsigned short len)
{
unsigned short i;
for (i = len; i; i--) AppendCharToFile (h, *((char*)addr)++);
}
void CloseFile (HANDLE h)
{
HeapUnlock (h);
HeapRealloc (h, *(unsigned short*)HeapDeref(h) + 2);
}
void AppendStringToFile(HANDLE h,void *addr,unsigned short len)
{
AppendCharToFile(h,0);
AppendBlockToFile(h,addr,len);
AppendCharToFile (h,0); AppendCharToFile (h,STR_TAG);
}
void AppendAbsNumberToFile(HANDLE h,unsigned long nbr){
if(nbr<256){
AppendCharToFile(h,nbr);
AppendCharToFile(h,1);
}
else if(nbr<0x10000){
AppendCharToFile(h,nbr%256);
AppendCharToFile(h,nbr/256);
AppendCharToFile(h,2);
}
else{
AppendCharToFile(h,(nbr%0x10000)%256);
AppendCharToFile(h,(nbr%0x10000)/256);
AppendCharToFile(h,(nbr/0x10000)%256);
AppendCharToFile(h,(nbr/0x10000)/256);
AppendCharToFile(h,4);
}
}
void AppendNumberToFile(HANDLE h,unsigned long nbr,short signe){
AppendAbsNumberToFile(h,nbr);
if(signe>=0){
AppendCharToFile(h,POSINT_TAG);
}
else{
AppendCharToFile(h,NEGINT_TAG);
}
}
void AppendFracToFile(HANDLE h,unsigned long num,unsigned long den,short signe){
AppendAbsNumberToFile(h,den);
AppendAbsNumberToFile(h,num);
if(signe>=0){
AppendCharToFile(h,POSFRAC_TAG);
}
else{
AppendCharToFile(h,NEGFRAC_TAG);
}
}
Oups!Un detail de grande importance:zeljko et moi avons oublié de verouiller le handle obtenu,il faut rajouter
40 (bis):HeapLock(h)



