FORM v5.0.0-35-g6318119
Macros | Functions
store.c File Reference
#include "form3.h"
Include dependency graph for store.c:

Go to the source code of this file.

Macros

#define SAVEREVISION   0x02
 

Functions

void OpenTemp (void)
 
void SeekScratch (FILEHANDLE *fi, POSITION *pos)
 
void SetEndScratch (FILEHANDLE *f, POSITION *position)
 
void SetEndHScratch (FILEHANDLE *f, POSITION *position)
 
void SetScratch (FILEHANDLE *f, POSITION *position)
 
int RevertScratch (void)
 
int ResetScratch (void)
 
int ReadFromScratch (FILEHANDLE *fi, POSITION *pos, UBYTE *buffer, POSITION *length)
 
int AddToScratch (FILEHANDLE *fi, POSITION *pos, UBYTE *buffer, POSITION *length, int withflush)
 
int CoSave (UBYTE *inp)
 
int CoLoad (UBYTE *inp)
 
int DeleteStore (WORD par)
 
int PutInStore (INDEXENTRY *ind, WORD num)
 
WORD GetTerm (PHEAD WORD *term)
 
WORD GetOneTerm (PHEAD WORD *term, FILEHANDLE *fi, POSITION *pos, int par)
 
WORD GetMoreTerms (WORD *term)
 
int GetMoreFromMem (WORD *term, WORD **tpoin)
 
WORD GetFromStore (WORD *to, POSITION *position, RENUMBER renumber, WORD *InCompState, WORD nexpr)
 
void DetVars (WORD *term, WORD par)
 
int ToStorage (EXPRESSIONS e, POSITION *length)
 
INDEXENTRYNextFileIndex (POSITION *indexpos)
 
int SetFileIndex (void)
 
int VarStore (UBYTE *s, WORD n, WORD name, WORD namesize)
 
int TermRenumber (WORD *term, RENUMBER renumber, WORD nexpr)
 
WORD FindrNumber (WORD n, VARRENUM *v)
 
INDEXENTRYFindInIndex (WORD expr, FILEDATA *f, WORD par, WORD mode)
 
RENUMBER GetTable (WORD expr, POSITION *position, WORD mode)
 
int CopyExpression (FILEHANDLE *from, FILEHANDLE *to)
 
LONG WriteStoreHeader (WORD handle)
 
int ReadSaveHeader (void)
 
LONG ReadSaveIndex (FILEINDEX *fileind)
 
LONG ReadSaveVariables (UBYTE *buffer, UBYTE *top, LONG *size, LONG *outsize, INDEXENTRY *ind, LONG *stage)
 
UBYTE * ReadSaveTerm32 (UBYTE *bin, UBYTE *binend, UBYTE **bout, UBYTE *boutend, UBYTE *top, int terminbuf)
 
LONG ReadSaveExpression (UBYTE *buffer, UBYTE *top, LONG *size, LONG *outsize)
 

Detailed Description

Contains all functions that deal with store-files and the system independent save-files.

Definition in file store.c.

Macro Definition Documentation

◆ SAVEREVISION

#define SAVEREVISION   0x02

Definition at line 3953 of file store.c.

Function Documentation

◆ OpenTemp()

void OpenTemp ( void  )

Definition at line 48 of file store.c.

◆ SeekScratch()

void SeekScratch ( FILEHANDLE fi,
POSITION pos 
)

Definition at line 63 of file store.c.

◆ SetEndScratch()

void SetEndScratch ( FILEHANDLE f,
POSITION position 
)

Definition at line 74 of file store.c.

◆ SetEndHScratch()

void SetEndHScratch ( FILEHANDLE f,
POSITION position 
)

Definition at line 88 of file store.c.

◆ SetScratch()

void SetScratch ( FILEHANDLE f,
POSITION position 
)

Definition at line 114 of file store.c.

◆ RevertScratch()

int RevertScratch ( void  )

Definition at line 189 of file store.c.

◆ ResetScratch()

int ResetScratch ( void  )

Definition at line 234 of file store.c.

◆ ReadFromScratch()

int ReadFromScratch ( FILEHANDLE fi,
POSITION pos,
UBYTE *  buffer,
POSITION length 
)

Definition at line 272 of file store.c.

◆ AddToScratch()

int AddToScratch ( FILEHANDLE fi,
POSITION pos,
UBYTE *  buffer,
POSITION length,
int  withflush 
)

Definition at line 299 of file store.c.

◆ CoSave()

int CoSave ( UBYTE *  inp)

Definition at line 362 of file store.c.

◆ CoLoad()

int CoLoad ( UBYTE *  inp)

Definition at line 572 of file store.c.

◆ DeleteStore()

int DeleteStore ( WORD  par)

Definition at line 772 of file store.c.

◆ PutInStore()

int PutInStore ( INDEXENTRY ind,
WORD  num 
)

Definition at line 873 of file store.c.

◆ GetTerm()

WORD GetTerm ( PHEAD WORD *  term)

Definition at line 992 of file store.c.

◆ GetOneTerm()

WORD GetOneTerm ( PHEAD WORD *  term,
FILEHANDLE fi,
POSITION pos,
int  par 
)

Definition at line 1267 of file store.c.

◆ GetMoreTerms()

WORD GetMoreTerms ( WORD *  term)

Definition at line 1425 of file store.c.

◆ GetMoreFromMem()

int GetMoreFromMem ( WORD *  term,
WORD **  tpoin 
)

Definition at line 1521 of file store.c.

◆ GetFromStore()

WORD GetFromStore ( WORD *  to,
POSITION position,
RENUMBER  renumber,
WORD *  InCompState,
WORD  nexpr 
)

Definition at line 1628 of file store.c.

◆ DetVars()

void DetVars ( WORD *  term,
WORD  par 
)

Definition at line 1829 of file store.c.

◆ ToStorage()

int ToStorage ( EXPRESSIONS  e,
POSITION length 
)

Definition at line 2016 of file store.c.

◆ NextFileIndex()

INDEXENTRY * NextFileIndex ( POSITION indexpos)

Definition at line 2257 of file store.c.

◆ SetFileIndex()

int SetFileIndex ( void  )

Reads the next file index and puts it into AR.StoreData.Index. TODO

Returns
= 0 everything okay, != 0 an error occurred

Definition at line 2320 of file store.c.

References WriteStoreHeader().

Here is the call graph for this function:

◆ VarStore()

int VarStore ( UBYTE *  s,
WORD  n,
WORD  name,
WORD  namesize 
)

Definition at line 2369 of file store.c.

◆ TermRenumber()

int TermRenumber ( WORD *  term,
RENUMBER  renumber,
WORD  nexpr 
)

!! WORD *memterm=term; static LONG ctrap=0; !!!

!! ctrap++; !!!

Definition at line 2427 of file store.c.

References ReNuMbEr::func, ReNuMbEr::funnum, ReNuMbEr::indi, ReNuMbEr::indnum, ReNuMbEr::symb, ReNuMbEr::symnum, TermRenumber(), ReNuMbEr::vecnum, and ReNuMbEr::vect.

Referenced by TermRenumber().

Here is the call graph for this function:

◆ FindrNumber()

WORD FindrNumber ( WORD  n,
VARRENUM v 
)

Definition at line 2587 of file store.c.

◆ FindInIndex()

INDEXENTRY * FindInIndex ( WORD  expr,
FILEDATA f,
WORD  par,
WORD  mode 
)

Definition at line 2664 of file store.c.

◆ GetTable()

RENUMBER GetTable ( WORD  expr,
POSITION position,
WORD  mode 
)

Definition at line 2825 of file store.c.

◆ CopyExpression()

int CopyExpression ( FILEHANDLE from,
FILEHANDLE to 
)

Definition at line 3307 of file store.c.

◆ WriteStoreHeader()

LONG WriteStoreHeader ( WORD  handle)

Writes header with information about system architecture and FORM revision to an open store file.

Called by SetFileIndex().

Parameters
handlespecifies open file to which header will be written
Returns
= 0 everything okay, != 0 an error occurred

Definition at line 3964 of file store.c.

References STOREHEADER::endianness, STOREHEADER::lenLONG, STOREHEADER::lenPOINTER, STOREHEADER::lenPOS, STOREHEADER::lenWORD, STOREHEADER::maxpower, STOREHEADER::sFun, STOREHEADER::sInd, STOREHEADER::sSym, STOREHEADER::sVec, and STOREHEADER::wildoffset.

Referenced by SetFileIndex().

◆ ReadSaveHeader()

int ReadSaveHeader ( void  )

Reads the header in the save file and sets function pointers and flags according to the information found there. Must be called before any other ReadSave... function.

Currently works only for the exchange between 32bit and 64bit machines (WORD size must be 2 or 4 bytes)!

It is called by CoLoad().

Returns
= 0 everything okay, != 0 an error occurred

Definition at line 4057 of file store.c.

◆ ReadSaveIndex()

LONG ReadSaveIndex ( FILEINDEX fileind)

Reads a FILEINDEX from the open save file specified by AO.SaveData.Handle. Translations for adjusting endianness and data sizes are done if necessary.

Depends on the assumption that sizeof(FILEINDEX) is the same everywhere. If FILEINDEX or INDEXENTRY change, then this functions has to be adjusted.

Called by CoLoad() and FindInIndex().

Parameters
fileindcontains the read FILEINDEX after successful return. must point to allocated, big enough memory.
Returns
= 0 everything okay, != 0 an error occurred

Definition at line 4175 of file store.c.

References INFILEINDEX, FiLeInDeX::next, FiLeInDeX::number, and FuNcTiOn::number.

◆ ReadSaveVariables()

LONG ReadSaveVariables ( UBYTE *  buffer,
UBYTE *  top,
LONG *  size,
LONG *  outsize,
INDEXENTRY ind,
LONG *  stage 
)

Reads the variables from the open file specified by AO.SaveData.Handle. It reads the *size bytes and writes them to the *buffer. It is called by PutInStore().

If translation is necessary, the data might shrink or grow in size, then *size is adjusted so that the reading and writing fits into the memory from the buffer to the top. The actual number of read bytes is returned in *size, the number of written bytes is returned in *outsize.

If the *size is smaller than the actual size of the variables, this function will be called several times and needs to remember the current position in the variable structure. The parameter stage does this job. When ReadSaveVariables() is called for the first time, this parameter should have the value -1.

The parameter ind is used to get the number of variables.

Parameters
bufferread variables are written into this allocated memory
topupper end of allocated memory
sizenumber of bytes to read. might return a smaller number of read bytes if translation was necessary
outsizeif translation has be done, outsize contains the number of written bytes
indpointer of INDEXENTRY for the current expression. read-only
stageshould be -1 for the first call, will be increased by ReadSaveVariables to memorize the position in the variable structure
Returns
= 0 everything okay, != 0 an error occurred

Definition at line 4361 of file store.c.

References InDeXeNtRy::nfunctions, InDeXeNtRy::nindices, InDeXeNtRy::nsymbols, InDeXeNtRy::nvectors, and FuNcTiOn::spec.

◆ ReadSaveTerm32()

UBYTE * ReadSaveTerm32 ( UBYTE *  bin,
UBYTE *  binend,
UBYTE **  bout,
UBYTE *  boutend,
UBYTE *  top,
int  terminbuf 
)

Reads a single term from the given buffer at bin and write the translated term back to this buffer at bout.

ReadSaveTerm32() is currently the only instantiation of a ReadSaveTerm-function. It only deals with data that already has the correct endianness and that is resized to 32bit words but without being renumbered or translated in any other way. It uses the compress buffer AR.CompressBuffer.

The function is reentrant in order to cope with nested function arguments. It is called by ReadSaveExpression() and itself.

The return value indicates the position in the input buffer up to which the data has already been successfully processed. The parameter bout returns the corresponding position in the output buffer.

Parameters
binstart of the input buffer
binendend of the input buffer
boutas input points to the beginning of the output buffer, as output points behind the already translated data in the output buffer
boutendend of already decompressed data in output buffer
topend of output buffer
terminbufflag whether decompressed data is already in the output buffer. used in recursive calls
Returns
pointer to the next unprocessed data in the input buffer

Definition at line 4728 of file store.c.

References ReadSaveTerm32().

Referenced by ReadSaveExpression(), and ReadSaveTerm32().

Here is the call graph for this function:

◆ ReadSaveExpression()

LONG ReadSaveExpression ( UBYTE *  buffer,
UBYTE *  top,
LONG *  size,
LONG *  outsize 
)

Reads an expression from the open file specified by AO.SaveData.Handle. The endianness flip and a resizing without renumbering is done in this function. Thereafter the buffer consists of chunks with a uniform maximal word size (32bit at the moment). The actual renumbering is then done by calling the function ReadSaveTerm32(). The result is returned in buffer.

If the translation at some point doesn't fit into the buffer anymore, the function returns and must be called again. In any case size returns the number of successfully read bytes, outsize returns the number of successfully written bytes, and the file will be positioned at the next byte after the successfully read data.

It is called by PutInStore().

Parameters
bufferoutput buffer, holds the (translated) expression
topend of buffer
sizenumber of read bytes
outsizenumber of written bytes
Returns
= 0 everything okay, != 0 an error occurred

Definition at line 5138 of file store.c.

References ReadSaveTerm32().

Here is the call graph for this function: