FORM 4.3
tools.c File Reference
#include "form3.h"
#include <sys/timeb.h>

Go to the source code of this file.

Macros

#define FILLVALUE   0
 
#define COPYFILEBUFSIZE   40960L
 
#define TERMMEMSTARTNUM   16
 
#define TERMEXTRAWORDS   10
 
#define NUMBERMEMSTARTNUM   16
 
#define NUMBEREXTRAWORDS   10L
 
#define DODOUBLE(x)
 
#define DOEXPAND(x)
 

Functions

UBYTE * LoadInputFile (UBYTE *filename, int type)
 
UBYTE ReadFromStream (STREAM *stream)
 
UBYTE GetFromStream (STREAM *stream)
 
UBYTE LookInStream (STREAM *stream)
 
STREAMOpenStream (UBYTE *name, int type, int prevarmode, int raiselow)
 
int LocateFile (UBYTE **name, int type)
 
STREAMCloseStream (STREAM *stream)
 
STREAMCreateStream (UBYTE *where)
 
LONG GetStreamPosition (STREAM *stream)
 
VOID PositionStream (STREAM *stream, LONG position)
 
int ReverseStatements (STREAM *stream)
 
VOID StartFiles ()
 
int OpenFile (char *name)
 
int OpenAddFile (char *name)
 
int ReOpenFile (char *name)
 
int CreateFile (char *name)
 
int CreateLogFile (char *name)
 
VOID CloseFile (int handle)
 
int CopyFile (char *source, char *dest)
 
int CreateHandle ()
 
LONG ReadFile (int handle, UBYTE *buffer, LONG size)
 
LONG ReadPosFile (PHEAD FILEHANDLE *fi, UBYTE *buffer, LONG size, POSITION *pos)
 
LONG WriteFileToFile (int handle, UBYTE *buffer, LONG size)
 
VOID SeekFile (int handle, POSITION *offset, int origin)
 
LONG TellFile (int handle)
 
VOID TELLFILE (int handle, POSITION *position)
 
void FlushFile (int handle)
 
int GetPosFile (int handle, fpos_t *pospointer)
 
int SetPosFile (int handle, fpos_t *pospointer)
 
VOID SynchFile (int handle)
 
VOID TruncateFile (int handle)
 
int GetChannel (char *name, int mode)
 
int GetAppendChannel (char *name)
 
int CloseChannel (char *name)
 
void UpdateMaxSize ()
 
int StrCmp (UBYTE *s1, UBYTE *s2)
 
int StrICmp (UBYTE *s1, UBYTE *s2)
 
int StrHICmp (UBYTE *s1, UBYTE *s2)
 
int StrICont (UBYTE *s1, UBYTE *s2)
 
int CmpArray (WORD *t1, WORD *t2, WORD n)
 
int ConWord (UBYTE *s1, UBYTE *s2)
 
int StrLen (UBYTE *s)
 
VOID NumToStr (UBYTE *s, LONG x)
 
VOID WriteString (int type, UBYTE *str, int num)
 
VOID WriteUnfinString (int type, UBYTE *str, int num)
 
UBYTE * AddToString (UBYTE *outstring, UBYTE *extrastring, int par)
 
UBYTE * strDup1 (UBYTE *instring, char *ifwrong)
 
UBYTE * EndOfToken (UBYTE *s)
 
UBYTE * ToToken (UBYTE *s)
 
UBYTE * SkipField (UBYTE *s, int level)
 
WORD ReadSnum (UBYTE **p)
 
UBYTE * NumCopy (WORD y, UBYTE *to)
 
char * LongCopy (LONG y, char *to)
 
char * LongLongCopy (off_t *y, char *to)
 
UBYTE * MakeDate ()
 
int set_in (UBYTE ch, set_of_char set)
 
one_byte set_set (UBYTE ch, set_of_char set)
 
one_byte set_del (UBYTE ch, set_of_char set)
 
one_byte set_sub (set_of_char set, set_of_char set1, set_of_char set2)
 
VOID iniTools (VOID)
 
VOID * Malloc (LONG size)
 
VOID * Malloc1 (LONG size, const char *messageifwrong)
 
void M_free (VOID *x, const char *where)
 
void M_check1 ()
 
void M_print ()
 
VOID TermMallocAddMemory (PHEAD0)
 
VOID NumberMallocAddMemory (PHEAD0)
 
VOID CacheNumberMallocAddMemory (PHEAD0)
 
VOID * FromList (LIST *L)
 
VOID * From0List (LIST *L)
 
VOID * FromVarList (LIST *L)
 
int DoubleList (VOID ***lijst, int *oldsize, int objectsize, char *nameoftype)
 
int DoubleLList (VOID ***lijst, LONG *oldsize, int objectsize, char *nameoftype)
 
void DoubleBuffer (void **start, void **stop, int size, char *text)
 
void ExpandBuffer (void **buffer, LONG *oldsize, int type)
 
LONG iexp (LONG x, int p)
 
void ToGeneral (WORD *r, WORD *m, WORD par)
 
int ToFast (WORD *r, WORD *m)
 
WORD ToPolyFunGeneral (PHEAD WORD *term)
 
int IsLikeVector (WORD *arg)
 
int AreArgsEqual (WORD *arg1, WORD *arg2)
 
int CompareArgs (WORD *arg1, WORD *arg2)
 
int CompArg (WORD *s1, WORD *s2)
 
LONG TimeWallClock (WORD par)
 
LONG TimeChildren (WORD par)
 
LONG TimeCPU (WORD par)
 
int Crash ()
 
int TestTerm (WORD *term)
 

Variables

FILES ** filelist
 
int numinfilelist = 0
 
int filelistsize = 0
 
WRITEFILE WriteFile = &WriteFileToFile
 

Detailed Description

Low level routines for many types of task. There are routines for manipulating the input system (streams and files) routines for string manipulation, the memory allocation interface, and the clock. The last is the most sensitive to ports. In the past nearly every port to another OS or computer gave trouble. Nowadays it is slightly better but the poor POSIX compliance of LINUX again gave problems for the multithreaded version.

Definition in file tools.c.

Macro Definition Documentation

◆ FILLVALUE

#define FILLVALUE   0

Definition at line 49 of file tools.c.

◆ TERMMEMSTARTNUM

#define TERMMEMSTARTNUM   16

Provides memory for one term (or one small polynomial) This means that the memory is limited to a buffer of size AM.MaxTer plus a few extra words. In parallel versions, each worker has its own memory pool.

The way we use the memory is by: term = TermMalloc(BHEAD0); and later we free it by TermFree(BHEAD term);

Layout: We have a list of available pointers to buffers: AT.TermMemHeap Its size is AT.TermMemMax We take from the top (indicated by AT.TermMemTop). When we run out of buffers we assign new ones (doubling the amount) and we have to extend the AT.TermMemHeap array. Important: There is no checking that the returned memory is legal, ie is memory that was handed out earlier.

Definition at line 2546 of file tools.c.

◆ TERMEXTRAWORDS

#define TERMEXTRAWORDS   10

Definition at line 2547 of file tools.c.

◆ NUMBERMEMSTARTNUM

#define NUMBERMEMSTARTNUM   16

Provides memory for one Long number This means that the memory is limited to a buffer of size AM.MaxTal In parallel versions, each worker has its own memory pool.

The way we use the memory is by: num = NumberMalloc(BHEAD0); Number = AT.NumberMemHeap[num]; and later we free it by NumberFree(BHEAD num);

Layout: We have a list of available pointers to buffers: AT.NumberMemHeap Its size is AT.NumberMemMax We take from the top (indicated by AT.NumberMemTop). When we run out of buffers we assign new ones (doubling the amount) and we have to extend the AT.NumberMemHeap array. Important: There is no checking on the returned memory!!!!

Definition at line 2646 of file tools.c.

◆ NUMBEREXTRAWORDS

#define NUMBEREXTRAWORDS   10L

Definition at line 2647 of file tools.c.

◆ DODOUBLE

#define DODOUBLE ( x)
Value:
{ x *s, *t, *u; if ( *start ) { \
oldsize = *(x **)stop - *(x **)start; newsize = 2*oldsize; \
t = u = (x *)Malloc1(newsize*sizeof(x),text); s = *(x **)start; \
for ( i = 0; i < oldsize; i++ ) *t++ = *s++; M_free(*start,"double"); } \
else { newsize = 100; u = (x *)Malloc1(newsize*sizeof(x),text); } \
*start = (void *)u; *stop = (void *)(u+newsize); }

Definition at line 2969 of file tools.c.

◆ DOEXPAND

#define DOEXPAND ( x)
Value:
{ x *newbuffer, *t, *m; \
t = newbuffer = (x *)Malloc1((newsize+2)*type,"ExpandBuffer"); \
if ( *buffer ) { m = (x *)*buffer; i = *oldsize; \
while ( --i >= 0 ) *t++ = *m++; M_free(*buffer,"ExpandBuffer"); \
} *buffer = newbuffer; *oldsize = newsize; }

Definition at line 2995 of file tools.c.

Function Documentation

◆ LoadInputFile()

UBYTE * LoadInputFile ( UBYTE * filename,
int type )

Definition at line 112 of file tools.c.

◆ ReadFromStream()

UBYTE ReadFromStream ( STREAM * stream)

Definition at line 151 of file tools.c.

◆ GetFromStream()

UBYTE GetFromStream ( STREAM * stream)

Definition at line 286 of file tools.c.

◆ LookInStream()

UBYTE LookInStream ( STREAM * stream)

Definition at line 309 of file tools.c.

◆ OpenStream()

STREAM * OpenStream ( UBYTE * name,
int type,
int prevarmode,
int raiselow )

Definition at line 321 of file tools.c.

◆ LocateFile()

int LocateFile ( UBYTE ** name,
int type )

Definition at line 576 of file tools.c.

◆ CloseStream()

STREAM * CloseStream ( STREAM * stream)

Definition at line 663 of file tools.c.

◆ CreateStream()

STREAM * CreateStream ( UBYTE * where)

Definition at line 782 of file tools.c.

◆ GetStreamPosition()

LONG GetStreamPosition ( STREAM * stream)

Definition at line 813 of file tools.c.

◆ PositionStream()

VOID PositionStream ( STREAM * stream,
LONG position )

Definition at line 823 of file tools.c.

◆ ReverseStatements()

int ReverseStatements ( STREAM * stream)

Definition at line 855 of file tools.c.

◆ StartFiles()

VOID StartFiles ( )

Definition at line 956 of file tools.c.

◆ OpenFile()

int OpenFile ( char * name)

Definition at line 983 of file tools.c.

◆ OpenAddFile()

int OpenAddFile ( char * name)

Definition at line 1002 of file tools.c.

◆ ReOpenFile()

int ReOpenFile ( char * name)

Definition at line 1023 of file tools.c.

◆ CreateFile()

int CreateFile ( char * name)

Definition at line 1043 of file tools.c.

◆ CreateLogFile()

int CreateLogFile ( char * name)

Definition at line 1060 of file tools.c.

◆ CloseFile()

VOID CloseFile ( int handle)

Definition at line 1078 of file tools.c.

◆ CopyFile()

int CopyFile ( char * source,
char * dest )

Copies a file with name *source to a file named *dest. The involved files must not be open. Returns non-zero if an error occurred. Uses if possible the combined large and small sorting buffers as cache.

Definition at line 1101 of file tools.c.

Referenced by DoRecovery().

◆ CreateHandle()

int CreateHandle ( )

Definition at line 1162 of file tools.c.

◆ ReadFile()

LONG ReadFile ( int handle,
UBYTE * buffer,
LONG size )

Definition at line 1217 of file tools.c.

◆ ReadPosFile()

LONG ReadPosFile ( PHEAD FILEHANDLE * fi,
UBYTE * buffer,
LONG size,
POSITION * pos )

Definition at line 1267 of file tools.c.

◆ WriteFileToFile()

LONG WriteFileToFile ( int handle,
UBYTE * buffer,
LONG size )

Definition at line 1333 of file tools.c.

◆ SeekFile()

VOID SeekFile ( int handle,
POSITION * offset,
int origin )

Definition at line 1371 of file tools.c.

◆ TellFile()

LONG TellFile ( int handle)

Definition at line 1396 of file tools.c.

◆ TELLFILE()

VOID TELLFILE ( int handle,
POSITION * position )

Definition at line 1406 of file tools.c.

◆ FlushFile()

void FlushFile ( int handle)

Definition at line 1420 of file tools.c.

◆ GetPosFile()

int GetPosFile ( int handle,
fpos_t * pospointer )

Definition at line 1434 of file tools.c.

◆ SetPosFile()

int SetPosFile ( int handle,
fpos_t * pospointer )

Definition at line 1448 of file tools.c.

◆ SynchFile()

VOID SynchFile ( int handle)

Definition at line 1468 of file tools.c.

◆ TruncateFile()

VOID TruncateFile ( int handle)

Definition at line 1490 of file tools.c.

◆ GetChannel()

int GetChannel ( char * name,
int mode )

Definition at line 1510 of file tools.c.

◆ GetAppendChannel()

int GetAppendChannel ( char * name)

Definition at line 1546 of file tools.c.

◆ CloseChannel()

int CloseChannel ( char * name)

Definition at line 1576 of file tools.c.

◆ UpdateMaxSize()

void UpdateMaxSize ( )

Definition at line 1610 of file tools.c.

◆ StrCmp()

int StrCmp ( UBYTE * s1,
UBYTE * s2 )

Definition at line 1700 of file tools.c.

◆ StrICmp()

int StrICmp ( UBYTE * s1,
UBYTE * s2 )

Definition at line 1711 of file tools.c.

◆ StrHICmp()

int StrHICmp ( UBYTE * s1,
UBYTE * s2 )

Definition at line 1722 of file tools.c.

◆ StrICont()

int StrICont ( UBYTE * s1,
UBYTE * s2 )

Definition at line 1733 of file tools.c.

◆ CmpArray()

int CmpArray ( WORD * t1,
WORD * t2,
WORD n )

Definition at line 1745 of file tools.c.

◆ ConWord()

int ConWord ( UBYTE * s1,
UBYTE * s2 )

Definition at line 1759 of file tools.c.

◆ StrLen()

int StrLen ( UBYTE * s)

Definition at line 1771 of file tools.c.

◆ NumToStr()

VOID NumToStr ( UBYTE * s,
LONG x )

Definition at line 1783 of file tools.c.

◆ WriteString()

VOID WriteString ( int type,
UBYTE * str,
int num )

Definition at line 1807 of file tools.c.

◆ WriteUnfinString()

VOID WriteUnfinString ( int type,
UBYTE * str,
int num )

Definition at line 1841 of file tools.c.

◆ AddToString()

UBYTE * AddToString ( UBYTE * outstring,
UBYTE * extrastring,
int par )

Definition at line 1866 of file tools.c.

◆ strDup1()

UBYTE * strDup1 ( UBYTE * instring,
char * ifwrong )

Definition at line 1904 of file tools.c.

◆ EndOfToken()

UBYTE * EndOfToken ( UBYTE * s)

Definition at line 1919 of file tools.c.

◆ ToToken()

UBYTE * ToToken ( UBYTE * s)

Definition at line 1931 of file tools.c.

◆ SkipField()

UBYTE * SkipField ( UBYTE * s,
int level )

Definition at line 1946 of file tools.c.

◆ ReadSnum()

WORD ReadSnum ( UBYTE ** p)

Definition at line 1973 of file tools.c.

◆ NumCopy()

UBYTE * NumCopy ( WORD y,
UBYTE * to )

Definition at line 1997 of file tools.c.

◆ LongCopy()

char * LongCopy ( LONG y,
char * to )

Definition at line 2024 of file tools.c.

◆ LongLongCopy()

char * LongLongCopy ( off_t * y,
char * to )

Definition at line 2051 of file tools.c.

◆ MakeDate()

UBYTE * MakeDate ( )

Definition at line 2090 of file tools.c.

◆ set_in()

int set_in ( UBYTE ch,
set_of_char set )

Definition at line 2112 of file tools.c.

◆ set_set()

one_byte set_set ( UBYTE ch,
set_of_char set )

Definition at line 2132 of file tools.c.

◆ set_del()

one_byte set_del ( UBYTE ch,
set_of_char set )

Definition at line 2153 of file tools.c.

◆ set_sub()

one_byte set_sub ( set_of_char set,
set_of_char set1,
set_of_char set2 )

Definition at line 2175 of file tools.c.

◆ iniTools()

VOID iniTools ( VOID )

Definition at line 2201 of file tools.c.

◆ Malloc()

VOID * Malloc ( LONG size)

Definition at line 2221 of file tools.c.

◆ Malloc1()

VOID * Malloc1 ( LONG size,
const char * messageifwrong )

Definition at line 2303 of file tools.c.

◆ M_free()

void M_free ( VOID * x,
const char * where )

Definition at line 2382 of file tools.c.

◆ M_check1()

void M_check1 ( )

Definition at line 2515 of file tools.c.

◆ M_print()

void M_print ( )

Definition at line 2516 of file tools.c.

◆ TermMallocAddMemory()

VOID TermMallocAddMemory ( PHEAD0 )

Definition at line 2549 of file tools.c.

◆ NumberMallocAddMemory()

VOID NumberMallocAddMemory ( PHEAD0 )

Definition at line 2653 of file tools.c.

◆ CacheNumberMallocAddMemory()

VOID CacheNumberMallocAddMemory ( PHEAD0 )

Definition at line 2727 of file tools.c.

◆ FromList()

VOID * FromList ( LIST * L)

Definition at line 2779 of file tools.c.

◆ From0List()

VOID * From0List ( LIST * L)

Definition at line 2805 of file tools.c.

◆ FromVarList()

VOID * FromVarList ( LIST * L)

Definition at line 2834 of file tools.c.

◆ DoubleList()

int DoubleList ( VOID *** lijst,
int * oldsize,
int objectsize,
char * nameoftype )

Definition at line 2876 of file tools.c.

◆ DoubleLList()

int DoubleLList ( VOID *** lijst,
LONG * oldsize,
int objectsize,
char * nameoftype )

Definition at line 2928 of file tools.c.

◆ DoubleBuffer()

void DoubleBuffer ( void ** start,
void ** stop,
int size,
char * text )

Definition at line 2976 of file tools.c.

◆ ExpandBuffer()

void ExpandBuffer ( void ** buffer,
LONG * oldsize,
int type )

Definition at line 3001 of file tools.c.

◆ iexp()

LONG iexp ( LONG x,
int p )

Definition at line 3025 of file tools.c.

◆ ToGeneral()

void ToGeneral ( WORD * r,
WORD * m,
WORD par )

Definition at line 3056 of file tools.c.

◆ ToFast()

int ToFast ( WORD * r,
WORD * m )

Definition at line 3100 of file tools.c.

◆ ToPolyFunGeneral()

WORD ToPolyFunGeneral ( PHEAD WORD * term)

Definition at line 3153 of file tools.c.

◆ IsLikeVector()

int IsLikeVector ( WORD * arg)

Definition at line 3228 of file tools.c.

◆ AreArgsEqual()

int AreArgsEqual ( WORD * arg1,
WORD * arg2 )

Definition at line 3256 of file tools.c.

◆ CompareArgs()

int CompareArgs ( WORD * arg1,
WORD * arg2 )

Definition at line 3275 of file tools.c.

◆ CompArg()

int CompArg ( WORD * s1,
WORD * s2 )

Definition at line 3306 of file tools.c.

◆ TimeWallClock()

LONG TimeWallClock ( WORD par)

Returns the wall-clock time.

Parameters
parIf zero, the wall-clock time will be reset to 0.
Returns
The wall-clock time in centiseconds.

Definition at line 3476 of file tools.c.

Referenced by DoCheckpoint(), DoRecovery(), find_Horner_MCTS(), optimize_expression_given_Horner(), optimize_greedy(), and WriteStats().

◆ TimeChildren()

LONG TimeChildren ( WORD par)

Definition at line 3532 of file tools.c.

◆ TimeCPU()

LONG TimeCPU ( WORD par)

Returns the CPU time.

Parameters
parIf zero, the CPU time will be reset to 0.
Returns
The CPU time in milliseconds.

Definition at line 3550 of file tools.c.

Referenced by PF_GetSlaveTimes(), PF_Processor(), and WriteStats().

◆ Crash()

int Crash ( )

Definition at line 3833 of file tools.c.

◆ TestTerm()

int TestTerm ( WORD * term)

Tests the consistency of the term. Returns 0 when the term is OK. Any nonzero value is trouble. In the current version the testing isn't 100% complete. For instance, we don't check the validity of the symbols nor do we check the range of their powers. Etc. This should be extended when the need is there.

Parameters
termthe term to be tested

Definition at line 3861 of file tools.c.

References TestTerm().

Referenced by TestTerm().

Variable Documentation

◆ filelist

FILES** filelist

Definition at line 65 of file tools.c.

◆ numinfilelist

int numinfilelist = 0

Definition at line 66 of file tools.c.

◆ filelistsize

int filelistsize = 0

Definition at line 67 of file tools.c.

◆ WriteFile

WRITEFILE WriteFile = &WriteFileToFile

Definition at line 1357 of file tools.c.