57 int numinfilelist = 0;
60 #define BANNER (4*sizeof(LONG)) 61 void *malloclist[60000];
62 LONG mallocsizes[60000];
63 char *mallocstrings[60000];
64 int nummalloclist = 0;
68 extern "C" getdtablesize();
81 #error "MALLOCPROTECT": undefine "TRAPSIGNALS" in unix.h first! 83 #include "mallocprotect.h" 89 #define M_alloc mprotectMalloc 99 UBYTE *LoadInputFile(UBYTE *filename,
int type)
103 UBYTE *buffer, *name = filename;
105 handle = LocateFile(&name,type);
106 if ( handle < 0 )
return(0);
108 SeekFile(handle,&scrpos,SEEK_END);
109 TELLFILE(handle,&scrpos);
110 filesize = BASEPOSITION(scrpos);
112 SeekFile(handle,&scrpos,SEEK_SET);
113 buffer = (UBYTE *)Malloc1(filesize+1,
"LoadInputFile");
114 if ( ReadFile(handle,buffer,filesize) != filesize ) {
115 Error1(
"Read error for file ",name);
116 M_free(buffer,
"LoadInputFile");
121 buffer[filesize] = 0;
130 UBYTE ReadFromStream(
STREAM *stream)
135 if ( stream->type == PIPESTREAM ) {
139 RWLOCKR(AM.handlelock);
140 f = (FILE *)(filelist[stream->handle]);
141 UNRWLOCK(AM.handlelock);
143 if ( cc == EOF )
return(ENDOFSTREAM);
149 if ( PF.me == MASTER ) {
152 RWLOCKR(AM.handlelock);
153 f = (FILE *)filelist[stream->handle];
154 UNRWLOCK(AM.handlelock);
156 end = stream->
buffer + stream->buffersize;
174 stream->inbuffer = len;
175 stream->
top = stream->
buffer + stream->inbuffer;
176 if ( stream->
pointer == stream->
top )
return ENDOFSTREAM;
180 if ( stream->eqnum == 1 ) { stream->eqnum = 0; stream->linenumber++; }
181 if ( c == LINEFEED ) stream->eqnum = 1;
186 #ifdef WITHEXTERNALCHANNEL 187 if ( stream->type == EXTERNALCHANNELSTREAM ) {
189 cc = getcFromExtChannel();
196 Error0(
"No current external channel");
202 if ( stream->eqnum == 1 ) { stream->eqnum = 0; stream->linenumber++; }
203 if ( c == LINEFEED ) stream->eqnum = 1;
209 if ( stream->type != FILESTREAM )
return(ENDOFSTREAM);
210 if ( stream->fileposition != stream->bufferposition+stream->inbuffer ) {
211 stream->fileposition = stream->bufferposition+stream->inbuffer;
212 SETBASEPOSITION(scrpos,stream->fileposition);
213 SeekFile(stream->handle,&scrpos,SEEK_SET);
215 stream->bufferposition = stream->fileposition;
216 stream->inbuffer = ReadFile(stream->handle,
217 stream->
buffer,stream->buffersize);
218 if ( stream->inbuffer <= 0 )
return(ENDOFSTREAM);
219 stream->
top = stream->
buffer + stream->inbuffer;
221 stream->fileposition = stream->bufferposition + stream->inbuffer;
223 if ( stream->eqnum == 1 ) { stream->eqnum = 0; stream->linenumber++; }
225 if ( c == LINEFEED ) stream->eqnum = 1;
234 UBYTE GetFromStream(
STREAM *stream)
237 if ( stream->isnextchar > 0 ) {
238 return(stream->nextchar[--stream->isnextchar]);
240 c1 = ReadFromStream(stream);
241 if ( c1 == LINEFEED || c1 == CARRIAGERETURN ) {
242 c2 = ReadFromStream(stream);
243 if ( c2 == c1 || ( c2 != LINEFEED && c2 != CARRIAGERETURN ) ) {
244 stream->isnextchar = 1;
245 stream->nextchar[0] = c2;
257 UBYTE LookInStream(
STREAM *stream)
259 UBYTE c = GetFromStream(stream);
260 UngetFromStream(stream,c);
269 STREAM *OpenStream(UBYTE *name,
int type,
int prevarmode,
int raiselow)
272 UBYTE *rhsofvariable, *s, *newname, c;
284 handle = LocateFile(&newname,-1);
285 if ( handle < 0 )
return(0);
287 SeekFile(handle,&scrpos,SEEK_END);
288 TELLFILE(handle,&scrpos);
289 filesize = BASEPOSITION(scrpos);
291 SeekFile(handle,&scrpos,SEEK_SET);
292 if ( filesize > AM.MaxStreamSize ) filesize = AM.MaxStreamSize;
293 stream = CreateStream((UBYTE *)
"filestream");
294 stream->
buffer = (UBYTE *)Malloc1(filesize,
"name of input stream");
295 stream->inbuffer = ReadFile(handle,stream->
buffer,filesize);
296 stream->
top = stream->
buffer + stream->inbuffer;
298 stream->handle = handle;
299 stream->buffersize = filesize;
300 stream->fileposition = stream->inbuffer;
301 if ( newname != name ) stream->
name = newname;
302 else if ( name ) stream->
name = strDup1(name,
"name of input stream");
305 stream->prevline = stream->linenumber = 1;
309 if ( ( rhsofvariable = GetPreVar(name,WITHERROR) ) == 0 )
return(0);
310 stream = CreateStream((UBYTE *)
"var-stream");
314 stream->inbuffer = s - stream->
buffer;
315 stream->
name = AC.CurrentStream->name;
316 stream->linenumber = AC.CurrentStream->linenumber;
317 stream->prevline = AC.CurrentStream->prevline;
318 stream->eqnum = AC.CurrentStream->eqnum;
319 stream->
pname = strDup1(name,
"stream->pname");
320 stream->olddelay = AP.AllowDelay;
321 s = stream->
pname;
while ( *s ) s++;
322 while ( s[-1] ==
'+' || s[-1] ==
'-' ) s--;
327 if ( ( num = GetDollar(name) ) < 0 ) {
333 s = name;
while ( *s && *s !=
'[' ) s++;
334 if ( *s == 0 )
return(0);
336 if ( ( num = GetDollar(name) ) < 0 )
return(0);
339 if ( *s == 0 || FG.cTable[*s] != 1 || *s ==
']' ) {
340 MesPrint(
"@Illegal factor number for dollar variable");
343 while ( *s && FG.cTable[*s] == 1 ) {
344 numfac = 10*numfac+*s++-
'0';
346 if ( *s !=
']' || s[1] != 0 ) {
347 MesPrint(
"@Illegal factor number for $ variable");
350 stream = CreateStream((UBYTE *)
"dollar-stream");
351 stream->
buffer = stream->
pointer = s = WriteDollarFactorToBuffer(num,numfac,1);
354 stream = CreateStream((UBYTE *)
"dollar-stream");
355 stream->
buffer = stream->
pointer = s = WriteDollarToBuffer(num,1);
359 stream->inbuffer = s - stream->
buffer;
360 stream->
name = AC.CurrentStream->name;
361 stream->linenumber = AC.CurrentStream->linenumber;
362 stream->prevline= AC.CurrentStream->prevline;
363 stream->eqnum = AC.CurrentStream->eqnum;
364 stream->
pname = strDup1(name,
"stream->pname");
365 s = stream->
pname;
while ( *s ) s++;
366 while ( s[-1] ==
'+' || s[-1] ==
'-' ) s--;
369 AO.DollarOutSizeBuffer = 0;
370 AO.DollarOutBuffer = 0;
371 AO.DollarInOutBuffer = 0;
377 stream = CreateStream((UBYTE *)
"calculator");
381 stream->inbuffer = s - stream->
buffer;
382 stream->
name = AC.CurrentStream->name;
383 stream->linenumber = AC.CurrentStream->linenumber;
384 stream->prevline = AC.CurrentStream->prevline;
389 stream = CreateStream((UBYTE *)
"pipe");
393 if ( ( f = popen((
char *)name,
"r") ) == 0 ) {
394 Error0(
"@Cannot create pipe");
396 stream->handle = CreateHandle();
397 RWLOCKW(AM.handlelock);
398 filelist[stream->handle] = (FILES *)f;
399 UNRWLOCK(AM.handlelock);
402 stream->inbuffer = 0;
407 if ( PF.me == MASTER ) {
408 f = popen((
char *)name,
"r");
410 if ( f == 0 ) Error0(
"@Cannot create pipe");
416 stream->handle = CreateHandle();
417 RWLOCKW(AM.handlelock);
418 filelist[stream->handle] = (FILES *)f;
419 UNRWLOCK(AM.handlelock);
422 stream->buffersize = AM.MaxStreamSize;
423 stream->
buffer = (UBYTE *)Malloc1(stream->buffersize,
"pipe buffer");
424 stream->inbuffer = 0;
428 stream->
name = strDup1((UBYTE *)
"pipe",
"pipe");
429 stream->prevline = stream->linenumber = 1;
434 #ifdef WITHEXTERNALCHANNEL 435 case EXTERNALCHANNELSTREAM:
438 if( (n=getCurrentExternalChannel()) == 0 )
439 Error0(
"@No current extrenal channel");
440 stream = CreateStream((UBYTE *)
"externalchannel");
441 stream->handle = CreateHandle();
442 tmpn = (
int *)Malloc1(
sizeof(
int),
"external channel handle");
444 RWLOCKW(AM.handlelock);
445 filelist[stream->handle] = (FILES *)tmpn;
446 UNRWLOCK(AM.handlelock);
449 stream->inbuffer = 0;
450 stream->
name = strDup1((UBYTE *)
"externalchannel",
"externalchannel");
451 stream->prevline = stream->linenumber = 1;
459 stream->bufferposition = 0;
460 stream->isnextchar = 0;
462 stream->previousNoShowInput = AC.NoShowInput;
463 stream->afterwards = raiselow;
464 if ( AC.CurrentStream ) stream->previous = AC.CurrentStream - AC.Streams;
465 else stream->previous = -1;
467 if ( prevarmode == 0 ) stream->prevars = -1;
468 else if ( prevarmode > 0 ) stream->prevars = NumPre;
469 else if ( prevarmode < 0 ) stream->prevars = -prevarmode-1;
470 AC.CurrentStream = stream;
471 if ( type == PREREADSTREAM || type == PREREADSTREAM3 || type == PRECALCSTREAM
472 || type == DOLLARSTREAM ) AC.NoShowInput = 1;
481 int LocateFile(UBYTE **name,
int type)
483 int handle, namesize, i;
484 UBYTE *s, *to, *u1, *u2, *newname, *indir;
485 handle = OpenFile((
char *)(*name));
486 if ( handle >= 0 )
return(handle);
487 if ( type == SETUPFILE && AM.SetupFile ) {
488 handle = OpenFile((
char *)(AM.SetupFile));
489 if ( handle >= 0 )
return(handle);
490 MesPrint(
"Could not open setup file %s",(
char *)(AM.SetupFile));
492 namesize = 2; s = *name;
493 while ( *s ) { s++; namesize++; }
494 if ( type == SETUPFILE ) indir = AM.SetupDir;
495 else indir = AM.IncDir;
499 while ( *s ) { s++; i++; }
500 newname = (UBYTE *)Malloc1(namesize+i,
"LocateFile");
501 s = indir; to = newname;
502 while ( *s ) *to++ = *s++;
503 if ( to > newname && to[-1] != SEPARATOR ) *to++ = SEPARATOR;
505 while ( *s ) *to++ = *s++;
507 handle = OpenFile((
char *)newname);
512 M_free(newname,
"LocateFile, incdir/file");
514 if ( type == SETUPFILE ) {
515 handle = OpenFile(setupfilename);
516 if ( handle >= 0 )
return(handle);
517 s = (UBYTE *)getenv(
"FORMSETUP");
519 handle = OpenFile((
char *)s);
520 if ( handle >= 0 )
return(handle);
521 MesPrint(
"Could not open setup file %s",s);
524 if ( type != SETUPFILE && AM.Path ) {
529 while ( *u1 && *u1 !=
';' ) {
533 while ( *u1 && *u1 !=
':' ) {
534 if ( *u1 ==
'\\' ) u1++;
538 newname = (UBYTE *)Malloc1(namesize+i,
"LocateFile");
539 s = u2; to = newname;
542 if ( *s ==
'\\' ) s++;
546 if ( to > newname && to[-1] != SEPARATOR ) *to++ = SEPARATOR;
548 while ( *s ) *to++ = *s++;
550 handle = OpenFile((
char *)newname);
555 M_free(newname,
"LocateFile Path/file");
559 if ( type != SETUPFILE ) Error1(
"LocateFile: Cannot find file",*name);
570 int newstr = stream->previous, sgn;
571 UBYTE *t, numbuf[24];
574 M_free(stream->
FoldName,
"stream->FoldName");
577 if ( stream->type == FILESTREAM ) {
578 CloseFile(stream->handle);
579 if ( stream->
buffer != 0 ) M_free(stream->
buffer,
"name of input stream");
583 else if ( stream->type == PIPESTREAM ) {
584 RWLOCKW(AM.handlelock);
586 if ( PF.me == MASTER )
588 pclose((FILE *)(filelist[stream->handle]));
589 filelist[stream->handle] = 0;
591 UNRWLOCK(AM.handlelock);
593 if ( stream->
buffer != 0 ) {
594 M_free(stream->
buffer,
"pipe buffer");
601 #ifdef WITHEXTERNALCHANNEL 602 else if ( stream->type == EXTERNALCHANNELSTREAM ) {
604 RWLOCKW(AM.handlelock);
605 tmpn = (
int *)(filelist[stream->handle]);
606 filelist[stream->handle] = 0;
608 UNRWLOCK(AM.handlelock);
609 M_free(tmpn,
"external channel handle");
613 else if ( stream->type == PREVARSTREAM && (
614 stream->afterwards == PRERAISEAFTER || stream->afterwards == PRELOWERAFTER ) ) {
615 t = stream->
buffer; x = 0; sgn = 1;
616 while ( *t ==
'-' || *t ==
'+' ) {
617 if ( *t ==
'-' ) sgn = -sgn;
620 if ( FG.cTable[*t] == 1 ) {
621 while ( *t && FG.cTable[*t] == 1 ) x = 10*x + *t++ -
'0';
623 if ( stream->afterwards == PRERAISEAFTER ) x = sgn*x + 1;
630 else if ( stream->type == DOLLARSTREAM && (
631 stream->afterwards == PRERAISEAFTER || stream->afterwards == PRELOWERAFTER ) ) {
632 if ( stream->afterwards == PRERAISEAFTER ) x = 1;
634 DollarRaiseLow(stream->
pname,x);
636 else if ( stream->type == PRECALCSTREAM || stream->type == DOLLARSTREAM ) {
637 if ( stream->
buffer ) M_free(stream->
buffer,
"stream->buffer");
640 if ( stream->
name && stream->type != PREVARSTREAM
641 && stream->type != PREREADSTREAM && stream->type != PREREADSTREAM2 && stream->type != PREREADSTREAM3
642 && stream->type != PRECALCSTREAM && stream->type != DOLLARSTREAM ) {
643 M_free(stream->
name,
"stream->name");
647 AC.NoShowInput = stream->previousNoShowInput;
653 if ( stream->prevars >= 0 ) {
654 while ( NumPre > stream->prevars ) {
656 M_free(PreVar[NumPre].name,
"PreVar[NumPre].name");
657 PreVar[NumPre].name = PreVar[NumPre].value = 0;
660 if ( stream->type == PREVARSTREAM ) {
661 AP.AllowDelay = stream->olddelay;
662 ClearMacro(stream->
pname);
663 M_free(stream->
pname,
"stream->pname");
665 else if ( stream->type == DOLLARSTREAM ) {
666 M_free(stream->
pname,
"stream->pname");
669 if ( newstr >= 0 )
return(AC.Streams + newstr);
678 STREAM *CreateStream(UBYTE *where)
683 if ( AC.NumStreams >= AC.MaxNumStreams ) {
684 if ( AC.MaxNumStreams == 0 ) numnewstreams = 10;
685 else numnewstreams = 2*AC.MaxNumStreams;
686 newstreams = (
STREAM *)Malloc1(
sizeof(
STREAM)*(numnewstreams+1),
"CreateStream");
687 if ( AC.MaxNumStreams > 0 ) {
688 offset = AC.CurrentStream - AC.Streams;
689 for ( i = 0; i < AC.MaxNumStreams; i++ ) {
690 newstreams[i] = AC.Streams[i];
692 AC.CurrentStream = newstreams + offset;
694 else newstreams[0].previous = -1;
695 AC.MaxNumStreams = numnewstreams;
696 if ( AC.Streams ) M_free(AC.Streams,(
char *)where);
697 AC.Streams = newstreams;
699 newstreams = AC.Streams+AC.NumStreams++;
700 newstreams->
name = 0;
709 LONG GetStreamPosition(
STREAM *stream)
711 return(stream->bufferposition + ((LONG)stream->
pointer-(LONG)stream->
buffer));
719 VOID PositionStream(
STREAM *stream, LONG position)
722 if ( position >= stream->bufferposition
723 && position < stream->bufferposition + stream->inbuffer ) {
724 stream->
pointer = stream->
buffer + (position-stream->bufferposition);
726 else if ( stream->type == FILESTREAM ) {
727 SETBASEPOSITION(scrpos,position);
728 SeekFile(stream->handle,&scrpos,SEEK_SET);
729 stream->inbuffer = ReadFile(stream->handle,stream->
buffer,stream->buffersize);
731 stream->
top = stream->
buffer + stream->inbuffer;
732 stream->bufferposition = position;
733 stream->fileposition = position + stream->inbuffer;
734 stream->isnextchar = 0;
737 Error0(
"Illegal position for stream");
751 int i = CreateHandle();
752 filelist[i] = Ustdout;
757 AR.Fscr[0].handle = -1;
758 AR.Fscr[1].handle = -1;
759 AR.Fscr[2].handle = -1;
760 AR.FoStage4[0].handle = -1;
761 AR.FoStage4[1].handle = -1;
762 AR.infile = &(AR.Fscr[0]);
763 AR.outfile = &(AR.Fscr[1]);
764 AR.hidefile = &(AR.Fscr[2]);
765 AR.StoreData.Handle = -1;
768 AC.MaxNumStreams = 0;
776 int OpenFile(
char *name)
781 if ( ( f = Uopen(name,
"rb") ) == 0 )
return(-1);
784 RWLOCKW(AM.handlelock);
786 UNRWLOCK(AM.handlelock);
795 int OpenAddFile(
char *name)
800 if ( ( f = Uopen(name,
"a+b") ) == 0 )
return(-1);
803 RWLOCKW(AM.handlelock);
805 UNRWLOCK(AM.handlelock);
807 SeekFile(i,&scrpos,SEEK_SET);
816 int ReOpenFile(
char *name)
821 if ( ( f = Uopen(name,
"r+b") ) == 0 )
return(-1);
823 RWLOCKW(AM.handlelock);
825 UNRWLOCK(AM.handlelock);
827 SeekFile(i,&scrpos,SEEK_SET);
836 int CreateFile(
char *name)
840 if ( ( f = Uopen(name,
"w+b") ) == 0 )
return(-1);
842 RWLOCKW(AM.handlelock);
844 UNRWLOCK(AM.handlelock);
853 int CreateLogFile(
char *name)
857 if ( ( f = Uopen(name,
"w+b") ) == 0 )
return(-1);
860 RWLOCKW(AM.handlelock);
862 UNRWLOCK(AM.handlelock);
871 VOID CloseFile(
int handle)
875 RWLOCKW(AM.handlelock);
876 f = filelist[handle];
877 filelist[handle] = 0;
879 UNRWLOCK(AM.handlelock);
896 #define COPYFILEBUFSIZE 40960L 898 size_t countin, countout, sumcount;
901 sumcount = (AM.S0->LargeSize+AM.S0->SmallEsize)*
sizeof(WORD);
902 if ( sumcount <= COPYFILEBUFSIZE ) {
903 sumcount = COPYFILEBUFSIZE;
904 buffer = (
char*)Malloc1(sumcount,
"file copy buffer");
907 buffer = (
char *)(AM.S0->lBuffer);
910 in = fopen(source,
"rb");
912 perror(
"CopyFile: ");
915 out = fopen(dest,
"wb");
917 perror(
"CopyFile: ");
921 while ( !feof(in) ) {
922 countin = fread(buffer, 1, sumcount, in);
923 if ( countin != sumcount ) {
925 perror(
"CopyFile: ");
929 countout = fwrite(buffer, 1, countin, out);
930 if ( countin != countout ) {
931 perror(
"CopyFile: ");
938 if ( sumcount <= COPYFILEBUFSIZE ) {
939 M_free(buffer,
"file copy buffer");
959 RWLOCKW(AM.handlelock);
961 if ( filelistsize == 0 ) {
963 filelist = (FILES **)Malloc1(
sizeof(FILES *)*filelistsize,
"file handle");
964 for ( j = 0; j < filelistsize; j++ ) filelist[j] = 0;
968 else if ( numinfilelist >= filelistsize ) {
969 VOID **fl = (VOID **)filelist;
971 if ( DoubleList((VOID ***)(&fl),&filelistsize,(
int)
sizeof(FILES *),
972 "list of open files") != 0 ) Terminate(-1);
973 filelist = (FILES **)fl;
974 for ( j = i; j < filelistsize; j++ ) filelist[j] = 0;
975 numinfilelist = i + 1;
979 for ( j = 0; j < filelistsize; j++ ) {
980 if ( filelist[j] == 0 ) { i = j;
break; }
984 filelist[i] = (FILES *)(filelist);
990 if ( numinfilelist > MAX_OPEN_FILES ) {
992 UNRWLOCK(AM.handlelock);
994 MesPrint(
"More than %d open files",MAX_OPEN_FILES);
995 Error0(
"System limit. This limit is not due to FORM!");
999 UNRWLOCK(AM.handlelock);
1010 LONG ReadFile(
int handle, UBYTE *buffer, LONG size)
1017 RWLOCKR(AM.handlelock);
1018 f = filelist[handle];
1019 UNRWLOCK(AM.handlelock);
1023 r = Uread(b,1,size,f);
1024 if ( r < 0 )
return(r);
1025 if ( r == 0 )
return(inbuf);
1027 if ( r == size )
return(inbuf);
1028 if ( r > size )
return(-1);
1064 WORD *b = (WORD *)buffer, *t;
1066 if ( fi->handle < 0 ) {
1067 fi->POfill = (WORD *)((UBYTE *)(fi->PObuffer) + BASEPOSITION(*pos));
1069 while ( size > 0 && fi->POfill < fi->POfull ) { *b++ = *t++; size--; }
1072 if ( ISLESSPOS(*pos,fi->POposition) || ISGEPOSINC(*pos,fi->POposition,
1073 ((UBYTE *)(fi->POfull)-(UBYTE *)(fi->PObuffer))) ) {
1078 fi->POposition = *pos;
1079 LOCK(AS.inputslock);
1080 SeekFile(fi->handle,pos,SEEK_SET);
1081 retval = ReadFile(fi->handle,(UBYTE *)(fi->PObuffer),fi->POsize);
1082 UNLOCK(AS.inputslock);
1083 fi->POfull = fi->PObuffer+retval/
sizeof(WORD);
1084 fi->POfill = fi->PObuffer;
1085 if ( fi != AR.hidefile ) AR.InInBuf = retval/
sizeof(WORD);
1086 else AR.InHiBuf = retval/
sizeof(WORD);
1089 fi->POfill = (WORD *)((UBYTE *)(fi->PObuffer) + DIFBASE(*pos,fi->POposition));
1091 if ( fi->POfill + size <= fi->POfull ) {
1093 while ( size > 0 ) { *b++ = *t++; size--; }
1097 i = fi->POfull - fi->POfill; t = fi->POfill;
1098 if ( i > size ) i = size;
1100 while ( --i >= 0 ) *b++ = *t++;
1101 if ( size == 0 )
break;
1102 ADDPOS(fi->POposition,(UBYTE *)(fi->POfull)-(UBYTE *)(fi->PObuffer));
1103 LOCK(AS.inputslock);
1104 SeekFile(fi->handle,&(fi->POposition),SEEK_SET);
1105 retval = ReadFile(fi->handle,(UBYTE *)(fi->PObuffer),fi->POsize);
1106 UNLOCK(AS.inputslock);
1107 fi->POfull = fi->PObuffer+retval/
sizeof(WORD);
1108 fi->POfill = fi->PObuffer;
1109 if ( fi != AR.hidefile ) AR.InInBuf = retval/
sizeof(WORD);
1110 else AR.InHiBuf = retval/
sizeof(WORD);
1111 if ( retval == 0 ) { t = fi->POfill;
break; }
1115 retval = (UBYTE *)b - buffer;
1117 ADDPOS(*pos,retval);
1126 LONG WriteFileToFile(
int handle, UBYTE *buffer, LONG size)
1129 LONG retval, totalwritten = 0, stilltowrite;
1130 RWLOCKR(AM.handlelock);
1131 f = filelist[handle];
1132 UNRWLOCK(AM.handlelock);
1133 while ( totalwritten < size ) {
1134 stilltowrite = size - totalwritten;
1138 retval = Uwrite((
char *)buffer+totalwritten,1,stilltowrite,f);
1139 if ( retval < 0 )
return(retval);
1140 if ( retval == 0 )
return(totalwritten);
1141 totalwritten += retval;
1143 return(totalwritten);
1147 WRITEFILE WriteFile = &WriteFileToFile;
1161 VOID SeekFile(
int handle,
POSITION *offset,
int origin)
1164 RWLOCKR(AM.handlelock);
1165 f = filelist[handle];
1166 UNRWLOCK(AM.handlelock);
1170 if ( origin == SEEK_SET ) {
1171 Useek(f,BASEPOSITION(*offset),origin);
1172 SETBASEPOSITION(*offset,(Utell(f)));
1175 else if ( origin == SEEK_END ) {
1178 SETBASEPOSITION(*offset,(Utell(f)));
1186 LONG TellFile(
int handle)
1189 TELLFILE(handle,&pos);
1193 return(BASEPOSITION(pos));
1196 VOID TELLFILE(
int handle,
POSITION *position)
1199 RWLOCKR(AM.handlelock);
1200 f = filelist[handle];
1201 UNRWLOCK(AM.handlelock);
1202 SETBASEPOSITION(*position,(Utell(f)));
1210 void FlushFile(
int handle)
1213 RWLOCKR(AM.handlelock);
1214 f = filelist[handle];
1215 UNRWLOCK(AM.handlelock);
1224 int GetPosFile(
int handle, fpos_t *pospointer)
1227 RWLOCKR(AM.handlelock);
1228 f = filelist[handle];
1229 UNRWLOCK(AM.handlelock);
1230 return(Ugetpos(f,pospointer));
1238 int SetPosFile(
int handle, fpos_t *pospointer)
1241 RWLOCKR(AM.handlelock);
1242 f = filelist[handle];
1243 UNRWLOCK(AM.handlelock);
1244 return(Usetpos(f,(fpos_t *)pospointer));
1258 VOID SynchFile(
int handle)
1261 if ( handle >= 0 ) {
1262 RWLOCKR(AM.handlelock);
1263 f = filelist[handle];
1264 UNRWLOCK(AM.handlelock);
1280 VOID TruncateFile(
int handle)
1283 if ( handle >= 0 ) {
1284 RWLOCKR(AM.handlelock);
1285 f = filelist[handle];
1286 UNRWLOCK(AM.handlelock);
1299 int GetChannel(
char *name)
1304 for ( i = 0; i < NumOutputChannels; i++ ) {
1305 if ( channels[i].name == 0 )
continue;
1306 if ( StrCmp((UBYTE *)name,(UBYTE *)(channels[i].name)) == 0 )
return(channels[i].handle);
1308 for ( i = 0; i < NumOutputChannels; i++ ) {
1309 if ( channels[i].name == 0 )
break;
1311 if ( i < NumOutputChannels ) { ch = &(channels[i]); }
1312 else { ch = (
CHANNEL *)FromList(&AC.ChannelList); }
1313 ch->
name = (
char *)strDup1((UBYTE *)name,
"name of channel");
1314 ch->
handle = CreateFile(name);
1315 RWLOCKR(AM.handlelock);
1316 f = filelist[ch->
handle];
1317 UNRWLOCK(AM.handlelock);
1330 int GetAppendChannel(
char *name)
1335 for ( i = 0; i < NumOutputChannels; i++ ) {
1336 if ( channels[i].name == 0 )
continue;
1337 if ( StrCmp((UBYTE *)name,(UBYTE *)(channels[i].name)) == 0 )
return(channels[i].handle);
1339 for ( i = 0; i < NumOutputChannels; i++ ) {
1340 if ( channels[i].name == 0 )
break;
1342 if ( i < NumOutputChannels ) { ch = &(channels[i]); }
1343 else { ch = (
CHANNEL *)FromList(&AC.ChannelList); }
1344 ch->
name = (
char *)strDup1((UBYTE *)name,
"name of channel");
1345 ch->
handle = OpenAddFile(name);
1346 RWLOCKR(AM.handlelock);
1347 f = filelist[ch->
handle];
1348 UNRWLOCK(AM.handlelock);
1360 int CloseChannel(
char *name)
1363 for ( i = 0; i < NumOutputChannels; i++ ) {
1364 if ( channels[i].name == 0 )
continue;
1365 if ( channels[i].name[0] == 0 )
continue;
1366 if ( StrCmp((UBYTE *)name,(UBYTE *)(channels[i].name)) == 0 ) {
1367 CloseFile(channels[i].handle);
1368 M_free(channels[i].name,
"CloseChannel");
1369 channels[i].name = 0;
1394 void UpdateMaxSize()
1402 if ( PF.me != MASTER )
return;
1405 if ( AM.PrintTotalSize ) {
1410 scr = AB[0]->R.Fscr;
1414 for ( i = 0; i <=2; i++ ) {
1415 if ( scr[i].handle < 0 ) {
1416 SETBASEPOSITION(position,(scr[i].POfull-scr[i].PObuffer)*
sizeof(WORD));
1419 position = scr[i].filesize;
1421 ADD2POS(sumsize,position);
1430 for ( j = 0; j < AM.totalnumberofthreads; j++ ) {
1432 if ( AT.SS && AT.SS->file.handle >= 0 ) {
1433 position = AT.SS->file.filesize;
1439 ADD2POS(sumsize,position);
1441 if ( AR.FoStage4[0].handle >= 0 ) {
1442 position = AR.FoStage4[0].filesize;
1443 ADD2POS(sumsize,position);
1448 if ( AT.SS && AT.SS->file.handle >= 0 ) {
1449 position = AT.SS->file.filesize;
1450 ADD2POS(sumsize,position);
1452 if ( AR.FoStage4[0].handle >= 0 ) {
1453 position = AR.FoStage4[0].filesize;
1454 ADD2POS(sumsize,position);
1460 ADD2POS(sumsize,AC.StoreFileSize);
1464 if ( ISLESSPOS(AS.MaxExprSize,sumsize) ) {
1466 LOCK(AS.MaxExprSizeLock);
1467 if ( ISLESSPOS(AS.MaxExprSize,sumsize) ) AS.MaxExprSize = sumsize;
1468 UNLOCK(AS.MaxExprSizeLock);
1470 AS.MaxExprSize = sumsize;
1484 int StrCmp(UBYTE *s1, UBYTE *s2)
1486 while ( *s1 && *s1 == *s2 ) { s1++; s2++; }
1487 return((
int)*s1-(
int)*s2);
1495 int StrICmp(UBYTE *s1, UBYTE *s2)
1497 while ( *s1 && tolower(*s1) == tolower(*s2) ) { s1++; s2++; }
1498 return((
int)tolower(*s1)-(
int)tolower(*s2));
1506 int StrHICmp(UBYTE *s1, UBYTE *s2)
1508 while ( *s1 && tolower(*s1) == *s2 ) { s1++; s2++; }
1509 return((
int)tolower(*s1)-(
int)(*s2));
1517 int StrICont(UBYTE *s1, UBYTE *s2)
1519 while ( *s1 && tolower(*s1) == tolower(*s2) ) { s1++; s2++; }
1520 if ( *s1 == 0 )
return(0);
1521 return((
int)tolower(*s1)-(
int)tolower(*s2));
1529 int ConWord(UBYTE *s1, UBYTE *s2)
1531 while ( *s1 && ( tolower(*s1) == tolower(*s2) ) ) { s1++; s2++; }
1532 if ( *s1 == 0 )
return(1);
1541 int StrLen(UBYTE *s)
1544 while ( *s ) { s++; i++; }
1553 VOID NumToStr(UBYTE *s, LONG x)
1558 if ( x < 0 ) { *s++ =
'-'; xx = -x; }
1561 *t++ = xx % 10 +
'0';
1564 while ( t > str ) *s++ = *--t;
1577 VOID WriteString(
int type, UBYTE *str,
int num)
1581 if ( num > 0 && str[num-1] == 0 ) { num--; }
1582 else if ( num <= 0 || str[num-1] != LINEFEED ) {
1583 AddLineFeed(str,num);
1586 if(type == EXTERNALCHANNELOUT){
1587 if(WriteFile(0,str,num) != num) error = 1;
1590 if ( AM.silent == 0 || type == ERROROUT ) {
1591 if ( type == INPUTOUT ) {
1592 if ( !AM.FileOnlyFlag && WriteFile(AM.StdOut,(UBYTE *)
" ",4) != 4 ) error = 1;
1593 if ( AC.LogHandle >= 0 && WriteFile(AC.LogHandle,(UBYTE *)
" ",4) != 4 ) error = 1;
1595 if ( !AM.FileOnlyFlag && WriteFile(AM.StdOut,str,num) != num ) error = 1;
1596 if ( AC.LogHandle >= 0 && WriteFile(AC.LogHandle,str,num) != num ) error = 1;
1598 if ( error ) Terminate(-1);
1611 VOID WriteUnfinString(
int type, UBYTE *str,
int num)
1616 if(type == EXTERNALCHANNELOUT){
1617 if(WriteFile(0,str,num) != num) error = 1;
1620 if ( AM.silent == 0 || type == ERROROUT ) {
1621 if ( type == INPUTOUT ) {
1622 if ( !AM.FileOnlyFlag && WriteFile(AM.StdOut,(UBYTE *)
" ",4) != 4 ) error = 1;
1623 if ( AC.LogHandle >= 0 && WriteFile(AC.LogHandle,(UBYTE *)
" ",4) != 4 ) error = 1;
1625 if ( !AM.FileOnlyFlag && WriteFile(AM.StdOut,str,num) != num ) error = 1;
1626 if ( AC.LogHandle >= 0 && WriteFile(AC.LogHandle,str,num) != num ) error = 1;
1628 if ( error ) Terminate(-1);
1640 UBYTE *strDup1(UBYTE *instring,
char *ifwrong)
1642 UBYTE *s = instring, *to;
1644 to = s = (UBYTE *)Malloc1((s-instring)+1,ifwrong);
1645 while ( *instring ) *to++ = *instring++;
1655 UBYTE *EndOfToken(UBYTE *s)
1658 while ( ( c = (UBYTE)(FG.cTable[*s]) ) == 0 || c == 1 ) s++;
1667 UBYTE *ToToken(UBYTE *s)
1670 while ( *s && ( c = (UBYTE)(FG.cTable[*s]) ) != 0 && c != 1 ) s++;
1682 UBYTE *SkipField(UBYTE *s,
int level)
1685 if ( *s ==
',' && level == 0 )
return(s);
1686 if ( *s ==
'(' ) level++;
1687 else if ( *s ==
')' ) { level--;
if ( level < 0 ) level = 0; }
1688 else if ( *s ==
'[' ) {
1691 else if ( *s ==
'{' ) {
1709 WORD ReadSnum(UBYTE **p)
1714 if ( FG.cTable[*s] == 1 ) {
1716 x = ( x << 3 ) + ( x << 1 ) + ( *s++ -
'0' );
1717 if ( x > MAXPOSITIVE )
return(-1);
1718 }
while ( FG.cTable[*s] == 1 );
1733 UBYTE *NumCopy(WORD x, UBYTE *to)
1737 if ( x < 0 ) { x = -x; *to++ =
'-'; }
1739 do { *s++ = (UBYTE)((x % 10)+
'0'); i++; }
while ( ( x /= 10 ) != 0 );
1743 i = to[j]; to[j] = s[-j]; s[-j] = (UBYTE)i; j--;
1756 char *LongCopy(LONG x,
char *to)
1760 if ( x < 0 ) { x = -x; *to++ =
'-'; }
1762 do { *s++ = (x % 10)+
'0'; i++; }
while ( ( x /= 10 ) != 0 );
1766 i = to[j]; to[j] = s[-j]; s[-j] = (char)i; j--;
1779 char *LongLongCopy(off_t *y,
char *to)
1784 if ( x < 0 ) { x = -x; *to++ =
'-'; }
1786 do { *s++ = (x % 10)+
'0'; i++; }
while ( ( x /= 10 ) != 0 );
1790 i = to[j]; to[j] = s[-j]; s[-j] = (char)i; j--;
1806 static char notime[] =
"";
1815 return((UBYTE *)ctime(&tp));
1820 return((UBYTE *)ctime(&tp));
1822 return((UBYTE *)notime);
1836 case 0:
return(set->bit_0);
1837 case 1:
return(set->bit_1);
1838 case 2:
return(set->bit_2);
1839 case 3:
return(set->bit_3);
1840 case 4:
return(set->bit_4);
1841 case 5:
return(set->bit_5);
1842 case 6:
return(set->bit_6);
1843 case 7:
return(set->bit_7);
1857 case 0:
set->bit_0=1;
break;
1858 case 1:
set->bit_1=1;
break;
1859 case 2:
set->bit_2=1;
break;
1860 case 3:
set->bit_3=1;
break;
1861 case 4:
set->bit_4=1;
break;
1862 case 5:
set->bit_5=1;
break;
1863 case 6:
set->bit_6=1;
break;
1864 case 7:
set->bit_7=1;
break;
1878 case 0:
set->bit_0=0;
break;
1879 case 1:
set->bit_1=0;
break;
1880 case 2:
set->bit_2=0;
break;
1881 case 3:
set->bit_3=0;
break;
1882 case 4:
set->bit_4=0;
break;
1883 case 5:
set->bit_5=0;
break;
1884 case 6:
set->bit_6=0;
break;
1885 case 7:
set->bit_7=0;
break;
1902 case 0:
set->bit_0=(set1->bit_0&&(!set2->bit_0));
break;
1903 case 1:
set->bit_1=(set1->bit_1&&(!set2->bit_1));
break;
1904 case 2:
set->bit_2=(set1->bit_2&&(!set2->bit_2));
break;
1905 case 3:
set->bit_3=(set1->bit_3&&(!set2->bit_3));
break;
1906 case 4:
set->bit_4=(set1->bit_4&&(!set2->bit_4));
break;
1907 case 5:
set->bit_5=(set1->bit_5&&(!set2->bit_5));
break;
1908 case 6:
set->bit_6=(set1->bit_6&&(!set2->bit_6));
break;
1909 case 7:
set->bit_7=(set1->bit_7&&(!set2->bit_7));
break;
1910 case 8:
set++;set1++;set2++;
1923 #ifdef MALLOCPROTECT 1924 if ( mprotectInit() ) exit(0);
1937 char *dummymessage =
"Malloc";
1938 INILOCK(MallocLock);
1941 VOID *Malloc(LONG size)
1950 MesPrint(
"Asking for 0 bytes in Malloc");
1953 if ( ( size & 7 ) != 0 ) { size = size - ( size&7 ) + 8; }
1957 mem = (VOID *)M_alloc(size);
1960 MLOCK(ErrorMessageLock);
1962 Error0(
"No memory!");
1964 MUNLOCK(ErrorMessageLock);
1974 mallocsizes[nummalloclist] = size;
1975 mallocstrings[nummalloclist] = dummymessage;
1976 malloclist[nummalloclist++] = mem;
1977 if ( filelist ) MesPrint(
"Mem0 at 0x%x, %l bytes",mem,size);
1979 int i = nummalloclist-1;
1980 while ( --i >= 0 ) {
1981 if ( (
char *)mem < (((
char *)malloclist[i]) + mallocsizes[i])
1982 && (
char *)(malloclist[i]) < ((
char *)mem + size) ) {
1983 if ( filelist ) MesPrint(
"This memory overlaps with the block at 0x%x" 1990 for ( i = 0; i < (int)BANNER; i++ ) { *t++ = 0; *--u = 0; }
1993 int j = nummalloclist-1, i;
1994 while ( --j >= 0 ) {
1995 t = (
char *)(malloclist[j]);
1996 u = t + mallocsizes[j];
1997 for ( i = 0; i < (int)BANNER; i++ ) {
1999 if ( *t != 0 || *u != 0 ) {
2000 MesPrint(
"Writing outside memory for %s",malloclist[i]);
2023 VOID *Malloc1(LONG size,
const char *messageifwrong)
2032 MesPrint(
"%wAsking for 0 bytes in Malloc1");
2038 if ( ( size & 7 ) != 0 ) { size = size - ( size&7 ) + 8; }
2042 mem = (VOID *)M_alloc(size);
2045 MLOCK(ErrorMessageLock);
2047 Error1(
"No memory while allocating ",(UBYTE *)messageifwrong);
2049 MUNLOCK(ErrorMessageLock);
2059 mallocsizes[nummalloclist] = size;
2060 mallocstrings[nummalloclist] = (
char *)messageifwrong;
2061 malloclist[nummalloclist++] = mem;
2062 if ( AC.MemDebugFlag && filelist ) MesPrint(
"%wMem1 at 0x%x: %l bytes. %s",mem,size,messageifwrong);
2064 int i = nummalloclist-1;
2065 while ( --i >= 0 ) {
2066 if ( (
char *)mem < (((
char *)malloclist[i]) + mallocsizes[i])
2067 && (
char *)(malloclist[i]) < ((
char *)mem + size) ) {
2068 if ( filelist ) MesPrint(
"This memory overlaps with the block at 0x%x" 2074 #ifdef MALLOCDEBUGOUTPUT 2075 printf (
"Malloc1: %s, allocated %li bytes at %.8lx\n",messageifwrong,size,(
unsigned long)mem);
2081 for ( i = 0; i < (int)BANNER; i++ ) { *t++ = 0; *--u = 0; }
2096 void M_free(VOID *x,
const char *where)
2099 char *t = (
char *)x;
2102 x = (
void *)(((
char *)x)-BANNER);
2104 if ( AC.MemDebugFlag ) MesPrint(
"%wFreeing 0x%x: %s",x,where);
2106 for ( i = nummalloclist-1; i >= 0; i-- ) {
2107 if ( x == malloclist[i] ) {
2108 size = mallocsizes[i];
2109 for ( j = i+1; j < nummalloclist; j++ ) {
2110 malloclist[j-1] = malloclist[j];
2111 mallocsizes[j-1] = mallocsizes[j];
2112 mallocstrings[j-1] = mallocstrings[j];
2119 unsigned int xx = ((ULONG)x);
2120 printf(
"Error returning non-allocated address: 0x%x from %s\n" 2127 for ( k = 0, j = 0; k < (int)BANNER; k++ ) {
2131 LONG *tt = (LONG *)x;
2132 MesPrint(
"%w!!!!! Banner has been written in !!!!!: %x %x %x %x",
2133 tt[0],tt[1],tt[2],tt[3]);
2136 for ( k = 0, j = 0; k < (int)BANNER; k++ ) {
2140 LONG *tt = (LONG *)x;
2141 MesPrint(
"%w!!!!! Tail has been written in !!!!!: %x %x %x %x",
2142 tt[0],tt[1],tt[2],tt[3]);
2155 #ifdef MALLOCDEBUGOUTPUT 2156 printf (
"M_free: %s, memory freed at %.8lx\n",where,(
unsigned long)x);
2160 #ifdef MALLOCPROTECT 2161 mprotectFree((
void *)x);
2175 void M_check1() { MesPrint(
"Checking Malloc"); M_check(); }
2179 int i,j,k,error = 0;
2182 for ( i = 0; i < nummalloclist; i++ ) {
2183 t = (
char *)(malloclist[i]);
2184 for ( k = 0, j = 0; k < (int)BANNER; k++ ) {
2188 tt = (LONG *)(malloclist[i]);
2189 MesPrint(
"%w!!!!! Banner %d (%s) has been written in !!!!!: %x %x %x %x",
2190 i,mallocstrings[i],tt[0],tt[1],tt[2],tt[3]);
2191 tt[0] = tt[1] = tt[2] = tt[3] = 0;
2194 t = (
char *)(malloclist[i]) + mallocsizes[i];
2195 for ( k = 0, j = 0; k < (int)BANNER; k++ ) {
2200 MesPrint(
"%w!!!!! Tail %d (%s) has been written in !!!!!: %x %x %x %x",
2201 i,mallocstrings[i],tt[0],tt[1],tt[2],tt[3]);
2202 tt[0] = tt[1] = tt[2] = tt[3] = 0;
2205 if ( ( mallocstrings[i][0] ==
' ' ) || ( mallocstrings[i][0] ==
'#' ) ) {
2206 MesPrint(
"%w!!!!! Funny mallocstring");
2221 MesPrint(
"We have the following memory allocations left:");
2222 for ( i = 0; i < nummalloclist; i++ ) {
2223 MesPrint(
"0x%x: %l bytes. number %d: '%s'",malloclist[i],mallocsizes[i],i,mallocstrings[i]);
2260 #define TERMMEMSTARTNUM 16 2261 #define TERMEXTRAWORDS 10 2263 VOID TermMallocAddMemory(PHEAD0)
2268 else extra = AT.TermMemMax;
2269 if ( AT.TermMemHeap ) M_free(AT.TermMemHeap,
"TermMalloc");
2270 newbufs = (WORD *)Malloc1(extra*(AM.MaxTer+TERMEXTRAWORDS*
sizeof(WORD)),
"TermMalloc");
2271 AT.TermMemHeap = (WORD **)Malloc1((extra+AT.TermMemMax)*
sizeof(WORD *),
"TermMalloc");
2272 for ( i = 0; i < extra; i++ ) {
2273 AT.TermMemHeap[i] = newbufs + i*(AM.MaxTer/
sizeof(WORD)+TERMEXTRAWORDS);
2275 AT.TermMemTop = extra;
2276 AT.TermMemMax += extra;
2282 #ifndef MEMORYMACROS 2284 WORD *TermMalloc2(
PHEAD char *text)
2286 if ( AT.TermMemTop <= 0 ) TermMallocAddMemory(BHEAD0);
2288 #ifdef MALLOCDEBUGOUTPUT 2289 MesPrint(
"TermMalloc: %s, %l/%l (%x)",text,AT.TermMemTop,AT.TermMemMax,AT.TermMemHeap[AT.TermMemTop-1]);
2292 return(AT.TermMemHeap[--AT.TermMemTop]);
2295 VOID TermFree2(
PHEAD WORD *TermMem,
char *text)
2297 AT.TermMemHeap[AT.TermMemTop++] = TermMem;
2299 #ifdef MALLOCDEBUGOUTPUT 2300 MesPrint(
"TermFree: %s, %l/%l (%x)",text,AT.TermMemTop,AT.TermMemMax,TermMem);
2330 #define NUMBERMEMSTARTNUM 16 2331 #define NUMBEREXTRAWORDS 10L 2333 VOID NumberMallocAddMemory(PHEAD0)
2339 else extra = AT.NumberMemMax;
2340 if ( AT.NumberMemHeap ) M_free(AT.NumberMemHeap,
"NumberMalloc");
2341 newbufs = (UWORD *)Malloc1(extra*(AM.MaxTal+NUMBEREXTRAWORDS)*
sizeof(UWORD),
"NumberMalloc");
2342 AT.NumberMemHeap = (UWORD **)Malloc1((extra+AT.NumberMemMax)*
sizeof(UWORD *),
"NumberMalloc");
2343 for ( i = 0; i < extra; i++ ) {
2344 AT.NumberMemHeap[i] = newbufs + i*(LONG)(AM.MaxTal+NUMBEREXTRAWORDS);
2346 AT.NumberMemTop = extra;
2347 AT.NumberMemMax += extra;
2353 #ifndef MEMORYMACROS 2355 UWORD *NumberMalloc2(
PHEAD char *text)
2357 if ( AT.NumberMemTop <= 0 ) NumberMallocAddMemory(BHEAD0);
2359 #ifdef MALLOCDEBUGOUTPUT 2360 MesPrint(
"NumberMalloc: %s, %l/%l (%x)",text,AT.NumberMemTop,AT.NumberMemMax,AT.NumberMemHeap[AT.NumberMemTop-1]);
2363 return(AT.NumberMemHeap[--AT.NumberMemTop]);
2366 VOID NumberFree2(
PHEAD UWORD *NumberMem,
char *text)
2368 AT.NumberMemHeap[AT.NumberMemTop++] = NumberMem;
2370 #ifdef MALLOCDEBUGOUTPUT 2371 MesPrint(
"NumberFree: %s, %l/%l (%x)",text,AT.NumberMemTop,AT.NumberMemMax,NumberMem);
2386 VOID *FromList(
LIST *L)
2395 i = ( L->
num * L->
size ) /
sizeof(
int);
2396 old = (
int *)L->
lijst; newL = (
int *)newlist;
2397 while ( --i >= 0 ) *newL++ = *old++;
2398 if ( L->
lijst ) M_free(L->
lijst,
"L->lijst FromList");
2412 VOID *From0List(
LIST *L)
2420 i = ( L->
num * L->
size ) /
sizeof(
int);
2421 old = (
int *)(L->
lijst); newL = (
int *)newlist;
2422 while ( --i >= 0 ) *newL++ = *old++;
2423 i = ( L->
maxnum - L->
num ) /
sizeof(
int);
2424 while ( --i >= 0 ) *newL++ = 0;
2425 if ( L->
lijst ) M_free(L->
lijst,
"L->lijst From0List");
2441 VOID *FromVarList(
LIST *L)
2447 else if ( L->
lijst ) {
2449 if ( L == &(AP.DollarList) ) {
2450 if ( L->
maxnum > MAXDOLLARVARIABLES ) L->
maxnum = MAXDOLLARVARIABLES;
2451 if ( L->
num >= MAXDOLLARVARIABLES ) {
2452 MesPrint(
"!!!More than %l objects in list of $-variables",
2453 MAXDOLLARVARIABLES);
2458 if ( L->
maxnum > MAXVARIABLES ) L->
maxnum = MAXVARIABLES;
2459 if ( L->
num >= MAXVARIABLES ) {
2460 MesPrint(
"!!!More than %l objects in list of variables",
2468 i = ( L->
num * L->
size ) /
sizeof(
int);
2469 old = (
int *)(L->
lijst); newL = (
int *)newlist;
2470 while ( --i >= 0 ) *newL++ = *old++;
2471 if ( L->
lijst ) M_free(L->
lijst,
"L->lijst from VarList");
2475 return( ((
char *)(L->
lijst)) + L->
size * ((L->
num)++) );
2483 int DoubleList(VOID ***lijst,
int *oldsize,
int objectsize,
char *nameoftype)
2486 LONG i, newsize, fullsize;
2488 static LONG maxlistsize = (LONG)(MAXPOSITIVE);
2489 if ( *lijst == 0 ) {
2490 if ( *oldsize > 0 ) newsize = *oldsize;
2493 else newsize = *oldsize * 2;
2494 if ( newsize > maxlistsize ) {
2495 if ( *oldsize == maxlistsize ) {
2496 MesPrint(
"No memory for extra space in %s",nameoftype);
2499 newsize = maxlistsize;
2501 fullsize = ( newsize * objectsize +
sizeof(VOID *)-1 ) & (-
sizeof(VOID *));
2502 newlist = (VOID **)Malloc1(fullsize,nameoftype);
2504 to = newlist; from = *lijst; i = (*oldsize * objectsize)/
sizeof(VOID *);
2511 while ( --i >= 0 ) *to++ = *from++;
2513 if ( *lijst ) M_free(*lijst,
"DoubleLList");
2535 int DoubleLList(VOID ***lijst, LONG *oldsize,
int objectsize,
char *nameoftype)
2538 LONG i, newsize, fullsize;
2540 static LONG maxlistsize = (LONG)(MAXLONG);
2541 if ( *lijst == 0 ) {
2542 if ( *oldsize > 0 ) newsize = *oldsize;
2545 else newsize = *oldsize * 2;
2546 if ( newsize > maxlistsize ) {
2547 if ( *oldsize == maxlistsize ) {
2548 MesPrint(
"No memory for extra space in %s",nameoftype);
2551 newsize = maxlistsize;
2553 fullsize = ( newsize * objectsize +
sizeof(VOID *)-1 ) & (-
sizeof(VOID *));
2554 newlist = (VOID **)Malloc1(fullsize,nameoftype);
2556 to = newlist; from = *lijst; i = (*oldsize * objectsize)/
sizeof(VOID *);
2563 while ( --i >= 0 ) *to++ = *from++;
2565 if ( *lijst ) M_free(*lijst,
"DoubleLList");
2576 #define DODOUBLE(x) { x *s, *t, *u; if ( *start ) { \ 2577 oldsize = *(x **)stop - *(x **)start; newsize = 2*oldsize; \ 2578 t = u = (x *)Malloc1(newsize*sizeof(x),text); s = *(x **)start; \ 2579 for ( i = 0; i < oldsize; i++ ) *t++ = *s++; M_free(*start,"double"); } \ 2580 else { newsize = 100; u = (x *)Malloc1(newsize*sizeof(x),text); } \ 2581 *start = (void *)u; *stop = (void *)(u+newsize); } 2583 void DoubleBuffer(
void **start,
void **stop,
int size,
char *text)
2585 LONG oldsize, newsize, i;
2586 if ( size ==
sizeof(
char) ) DODOUBLE(
char)
2587 else if ( size ==
sizeof(
short) ) DODOUBLE(
short)
2588 else if ( size ==
sizeof(
int) ) DODOUBLE(
int)
2589 else if ( size ==
sizeof(LONG) ) DODOUBLE(LONG)
2590 else if ( size %
sizeof(
int) == 0 ) DODOUBLE(
int)
2592 MesPrint(
"---Cannot handle doubling buffers of size %d",size);
2602 #define DOEXPAND(x) { x *newbuffer, *t, *m; \ 2603 t = newbuffer = (x *)Malloc1((newsize+2)*type,"ExpandBuffer"); \ 2604 if ( *buffer ) { m = (x *)*buffer; i = *oldsize; \ 2605 while ( --i >= 0 ) *t++ = *m++; M_free(*buffer,"ExpandBuffer"); \ 2606 } *buffer = newbuffer; *oldsize = newsize; } 2608 void ExpandBuffer(
void **buffer, LONG *oldsize,
int type)
2611 if ( *oldsize <= 0 ) { newsize = 100; }
2612 else newsize = 2*(*oldsize);
2613 if ( type ==
sizeof(
char) ) DOEXPAND(
char)
2614 else if ( type ==
sizeof(
short) ) DOEXPAND(
short)
2615 else if ( type ==
sizeof(
int) ) DOEXPAND(
int)
2616 else if ( type ==
sizeof(LONG) ) DOEXPAND(LONG)
2619 MesPrint(
"---Cannot handle expanding buffers with objects of size %d",type);
2632 LONG iexp(LONG x,
int p)
2636 if ( x == 0 )
return(0);
2637 if ( p == 0 )
return(1);
2638 if ( x < 0 ) { sign = -1; x = -x; }
2640 if ( sign < 0 && ( p & 1 ) == 0 ) sign = 1;
2641 if ( x == 1 )
return(sign);
2642 if ( p < 0 )
return(0);
2645 if ( ( p & 1 ) != 0 ) y *= x;
2649 if ( sign < 0 ) y = -y;
2662 void ToGeneral(WORD *r, WORD *m, WORD par)
2666 else m += ARGHEAD + 1;
2669 if ( j >= FUNCTION ) { *m++ = j; *m++ = 2; }
2672 case SYMBOL: *m++ = j; *m++ = 4; *m++ = *r++; *m++ = 1;
break;
2674 if ( *r > 0 ) { *m++ = *r; *m++ = 1; *m++ = 3; }
2675 else if ( *r == 0 ) { m--; }
2676 else { *m++ = -*r; *m++ = 1; *m++ = -3; }
2678 case MINVECTOR: k = -k;
2680 case VECTOR: *m++ = INDEX; *m++ = 3; *m++ = *r++;
break;
2683 *m++ = 1; *m++ = 1; *m++ = k;
2686 if ( !par ) mm[ARGHEAD] = *mm-ARGHEAD;
2701 int ToFast(WORD *r, WORD *m)
2704 if ( *r == ARGHEAD ) { *m++ = -SNUMBER; *m++ = 0;
return(1); }
2705 if ( *r != r[ARGHEAD]+ARGHEAD )
return(0);
2708 if ( r[2] != 1 || r[1] <= 0 )
return(0);
2709 *m++ = -SNUMBER; *m = ( r[3] < 0 ) ? -r[1] : r[1];
return(1);
2712 if ( r[i-1] != 1 || r[i-2] != 1 )
return(0);
2714 if ( r[i] == -3 && r[2] == *r-4 && r[2] == 3 && r[1] == INDEX
2715 && r[3] < MINSPEC ) {}
2718 else if ( r[2] != *r - 4 )
return(0);
2720 if ( *r >= FUNCTION ) {
2721 if ( r[1] <= FUNHEAD ) { *m++ = -*r;
return(1); }
2723 else if ( *r == SYMBOL ) {
2724 if ( r[1] == 4 && r[3] == 1 )
2725 { *m++ = -SYMBOL; *m++ = r[2];
return(1); }
2727 else if ( *r == INDEX ) {
2729 if ( r[2] >= MINSPEC ) {
2730 if ( r[2] >= 0 && r[2] < AM.OffsetIndex ) *m++ = -SNUMBER;
2734 if ( r[5] == -3 ) *m++ = -MINVECTOR;
2735 else *m++ = -VECTOR;
2754 int IsLikeVector(WORD *arg)
2756 WORD *sstop, *t, *tstop;
2758 if ( *arg == -VECTOR || *arg == -INDEX )
return(1);
2759 if ( *arg == -SNUMBER && arg[1] >= 0 && arg[1] < AM.OffsetIndex )
2763 sstop = arg + *arg; arg += ARGHEAD;
2764 while ( arg < sstop ) {
2766 tstop = t - ABS(t[-1]);
2768 while ( arg < tstop ) {
2769 if ( *arg == INDEX )
return(1);
2782 int AreArgsEqual(WORD *arg1, WORD *arg2)
2785 if ( *arg2 != *arg1 )
return(0);
2788 while ( --i > 0 ) {
if ( arg1[i] != arg2[i] )
return(0); }
2791 else if ( *arg1 <= -FUNCTION )
return(1);
2792 else if ( arg1[1] == arg2[1] )
return(1);
2801 int CompareArgs(WORD *arg1, WORD *arg2)
2805 if ( *arg2 < 0 )
return(-1);
2806 i1 = *arg1-ARGHEAD; arg1 += ARGHEAD;
2807 i2 = *arg2-ARGHEAD; arg2 += ARGHEAD;
2808 while ( i1 > 0 && i2 > 0 ) {
2809 if ( *arg1 != *arg2 )
return((
int)(*arg1)-(
int)(*arg2));
2810 i1--; i2--; arg1++; arg2++;
2814 else if ( *arg2 > 0 )
return(1);
2816 if ( *arg1 != *arg2 ) {
2817 if ( *arg1 < *arg2 )
return(-1);
2820 if ( *arg1 <= -FUNCTION )
return(0);
2821 return((
int)(arg1[1])-(
int)(arg2[1]));
2832 int CompArg(WORD *s1, WORD *s2)
2835 WORD *st1, *st2, x[7];
2839 if ( *s1 <= -FUNCTION && *s2 <= -FUNCTION ) {
2840 if ( *s1 > *s2 )
return(-1);
2841 if ( *s1 < *s2 )
return(1);
2844 if ( *s1 > *s2 )
return(1);
2845 if ( *s1 < *s2 )
return(-1);
2846 if ( *s1 <= -FUNCTION )
return(0);
2848 if ( *s1 > *s2 )
return(1);
2849 if ( *s1 < *s2 )
return(-1);
2852 x[1] = AT.comsym[3];
2853 x[2] = AT.comnum[1];
2854 x[3] = AT.comnum[3];
2855 x[4] = AT.comind[3];
2856 x[5] = AT.comind[6];
2857 x[6] = AT.comfun[1];
2858 if ( *s1 == -SYMBOL ) {
2859 AT.comsym[3] = s1[1];
2860 st1 = AT.comsym+8; s1 = AT.comsym;
2862 else if ( *s1 == -SNUMBER ) {
2864 AT.comnum[1] = -s1[1]; AT.comnum[3] = -3;
2867 AT.comnum[1] = s1[1]; AT.comnum[3] = 3;
2872 else if ( *s1 == -INDEX || *s1 == -VECTOR ) {
2873 AT.comind[3] = s1[1]; AT.comind[6] = 3;
2874 st1 = AT.comind+7; s1 = AT.comind;
2876 else if ( *s1 == -MINVECTOR ) {
2877 AT.comind[3] = s1[1]; AT.comind[6] = -3;
2878 st1 = AT.comind+7; s1 = AT.comind;
2880 else if ( *s1 <= -FUNCTION ) {
2881 AT.comfun[1] = -*s1;
2882 st1 = AT.comfun+FUNHEAD+4; s1 = AT.comfun;
2888 else if ( *s1 == -ARGWILD ) {
2891 else {
goto argerror; }
2892 st2 = s2 + *s2; s2 += ARGHEAD;
2895 else if ( *s2 < 0 ) {
2896 x[1] = AT.comsym[3];
2897 x[2] = AT.comnum[1];
2898 x[3] = AT.comnum[3];
2899 x[4] = AT.comind[3];
2900 x[5] = AT.comind[6];
2901 x[6] = AT.comfun[1];
2902 if ( *s2 == -SYMBOL ) {
2903 AT.comsym[3] = s2[1];
2904 st2 = AT.comsym+8; s2 = AT.comsym;
2906 else if ( *s2 == -SNUMBER ) {
2908 AT.comnum[1] = -s2[1]; AT.comnum[3] = -3;
2911 else if ( s2[1] == 0 ) {
2912 st2 = AT.comnum+4; s2 = st2;
2915 AT.comnum[1] = s2[1]; AT.comnum[3] = 3;
2920 else if ( *s2 == -INDEX || *s2 == -VECTOR ) {
2921 AT.comind[3] = s2[1]; AT.comind[6] = 3;
2922 st2 = AT.comind+7; s2 = AT.comind;
2924 else if ( *s2 == -MINVECTOR ) {
2925 AT.comind[3] = s2[1]; AT.comind[6] = -3;
2926 st2 = AT.comind+7; s2 = AT.comind;
2928 else if ( *s2 <= -FUNCTION ) {
2929 AT.comfun[1] = -*s2;
2930 st2 = AT.comfun+FUNHEAD+4; s2 = AT.comfun;
2936 else if ( *s2 == -ARGWILD ) {
2939 else {
goto argerror; }
2940 st1 = s1 + *s1; s1 += ARGHEAD;
2944 x[1] = AT.comsym[3];
2945 x[2] = AT.comnum[1];
2946 x[3] = AT.comnum[3];
2947 x[4] = AT.comind[3];
2948 x[5] = AT.comind[6];
2949 x[6] = AT.comfun[1];
2950 st1 = s1 + *s1; st2 = s2 + *s2;
2951 s1 += ARGHEAD; s2 += ARGHEAD;
2953 while ( s1 < st1 && s2 < st2 ) {
2954 if ( ( k = CompareTerms(BHEAD s1,s2,(WORD)2) ) != 0 ) {
2955 AT.comsym[3] = x[1];
2956 AT.comnum[1] = x[2];
2957 AT.comnum[3] = x[3];
2958 AT.comind[3] = x[4];
2959 AT.comind[6] = x[5];
2960 AT.comfun[1] = x[6];
2963 s1 += *s1; s2 += *s2;
2965 AT.comsym[3] = x[1];
2966 AT.comnum[1] = x[2];
2967 AT.comnum[3] = x[3];
2968 AT.comind[3] = x[4];
2969 AT.comind[6] = x[5];
2970 AT.comfun[1] = x[6];
2971 if ( s1 < st1 )
return(1);
2972 if ( s2 < st2 )
return(-1);
2977 MesPrint(
"Illegal type of short function argument in Normalize");
2978 Terminate(-1);
return(0);
2986 #include <sys/timeb.h> 2988 LONG TimeWallClock(WORD par)
2993 return(((LONG)(tp.time)-AM.OldSecTime)*100 +
2994 ((LONG)(tp.millitm)-AM.OldMilliTime)/10);
2997 AM.OldSecTime = (LONG)(tp.time);
2998 AM.OldMilliTime = (LONG)(tp.millitm);
3008 LONG TimeChildren(WORD par)
3010 if ( par )
return(Timer(1)-AM.OldChildTime);
3011 AM.OldChildTime = Timer(1);
3020 LONG TimeCPU(WORD par)
3023 if ( par )
return(Timer(0)-AR.OldTime);
3024 AR.OldTime = Timer(0);
3032 #if defined(WINDOWS) 3036 #ifndef WITHPTHREADS 3037 static int initialized = 0;
3038 static HANDLE hProcess;
3039 FILETIME ftCreate, ftExit, ftKernel, ftUser;
3042 if ( !initialized ) {
3043 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
3045 if ( GetProcessTimes(hProcess, &ftCreate, &ftExit, &ftKernel, &ftUser) ) {
3046 PFILETIME pftKernel = &ftKernel;
3047 PFILETIME pftUser = &ftUser;
3048 __int64 t = *(__int64 *)pftKernel + *(__int64 *)pftUser;
3049 return (LONG)(t / 10000);
3055 FILETIME ftCreate, ftExit, ftKernel, ftUser;
3058 hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE, GetCurrentThreadId());
3060 if ( GetThreadTimes(hThread, &ftCreate, &ftExit, &ftKernel, &ftUser) ) {
3061 PFILETIME pftKernel = &ftKernel;
3062 PFILETIME pftUser = &ftUser;
3063 __int64 t = *(__int64 *)pftKernel + *(__int64 *)pftUser;
3064 lResult = (LONG)(t / 10000);
3066 CloseHandle(hThread);
3073 #include <sys/time.h> 3074 #include <sys/resource.h> 3075 #ifdef WITHPOSIXCLOCK 3084 #ifdef WITHPOSIXCLOCK 3103 if ( clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t) ) {
3104 MesPrint(
"Error in getting timing information");
3106 return (LONG)t.tv_sec * 1000 + (LONG)t.tv_nsec / 1000000;
3110 struct rusage rusage;
3112 getrusage(RUSAGE_CHILDREN,&rusage);
3113 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3114 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3117 getrusage(RUSAGE_SELF,&rusage);
3118 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3119 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3126 #include <sys/time.h> 3127 #include <sys/resource.h> 3131 struct rusage rusage;
3133 getrusage(RUSAGE_CHILDREN,&rusage);
3134 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3135 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3138 getrusage(RUSAGE_SELF,&rusage);
3139 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3140 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3145 #include <sys/time.h> 3146 #include <sys/resource.h> 3150 struct rusage rusage;
3152 getrusage(RUSAGE_CHILDREN,&rusage);
3153 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3154 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3157 getrusage(RUSAGE_SELF,&rusage);
3158 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3159 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3175 #include <sys/time.h> 3176 #include <sys/resource.h> 3177 struct rusage rusage;
3179 getrusage(RUSAGE_CHILDREN,&rusage);
3180 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3181 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3184 getrusage(RUSAGE_SELF,&rusage);
3185 return(((LONG)(rusage.ru_utime.tv_sec)+(LONG)(rusage.ru_stime.tv_sec))*1000
3186 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3190 clock_t tikken = clock();
3191 return((LONG)tikken/1000);
3193 clock_t t, tikken = clock();
3194 t = tikken % CLK_TCK;
3197 tikken += (t*1000)/CLK_TCK;
3205 void times(tbuffer_t *buffer);
3211 if ( par == 1 ) {
return(0); }
3214 return(buffer.proc_user_time * 10);
3227 #include <sys/types.h> 3228 #include <sys/times.h> 3233 #include <sys/time.h> 3234 #include <sys/resource.h> 3242 if ( par == 1 ) {
return(0); }
3244 if ( ( AO.wrapnum & 1 ) != 0 ) t ^= 0x80000000;
3250 return(AO.wrap+(t/1000));
3255 ULONG a1, a2, a3, a4;
3256 if ( par == 1 ) {
return(0); }
3258 a1 = (ULONG)buffer.tms_utime;
3262 a2 = 1000*a2 + (a3 >> 16);
3267 ret = (LONG)((a4 << 16) + a3 / CLK_TCK);
3273 struct timezone tzp;
3274 if ( par == 1 ) {
return(0); }
3275 gettimeofday(&tp,&tzp); */
3276 return(tp.tv_sec*1000+tp.tv_usec/1000);
3278 struct rusage rusage;
3280 getrusage(RUSAGE_CHILDREN,&rusage);
3281 return((rusage.ru_utime.tv_sec+rusage.ru_stime.tv_sec)*1000
3282 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3285 getrusage(RUSAGE_SELF,&rusage);
3286 return((rusage.ru_utime.tv_sec+rusage.ru_stime.tv_sec)*1000
3287 +(rusage.ru_utime.tv_usec/1000+rusage.ru_stime.tv_usec/1000));
3333 int errorcode = 0, coeffsize;
3334 WORD *t, *tt, *tstop, *endterm, *targ, *targstop, *funstop, *argterm;
3335 endterm = term + *term;
3336 coeffsize = ABS(endterm[-1]);
3337 if ( coeffsize >= *term ) {
3338 MLOCK(ErrorMessageLock);
3339 MesPrint(
"TestTerm: Internal inconsistency in term. Coefficient too big.");
3340 MUNLOCK(ErrorMessageLock);
3344 if ( ( coeffsize < 3 ) || ( ( coeffsize & 1 ) != 1 ) ) {
3345 MLOCK(ErrorMessageLock);
3346 MesPrint(
"TestTerm: Internal inconsistency in term. Wrong size coefficient.");
3347 MUNLOCK(ErrorMessageLock);
3352 tstop = endterm - coeffsize;
3353 while ( t < tstop ) {
3364 MLOCK(ErrorMessageLock);
3365 MesPrint(
"TestTerm: Internal inconsistency in term. L or S number");
3366 MUNLOCK(ErrorMessageLock);
3372 case DOLLAREXPRESSION:
3385 MLOCK(ErrorMessageLock);
3386 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal subterm.");
3387 MUNLOCK(ErrorMessageLock);
3395 MLOCK(ErrorMessageLock);
3396 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal subterm number.");
3397 MUNLOCK(ErrorMessageLock);
3404 if ( *t-FUNCTION >= NumFunctions ) {
3405 MLOCK(ErrorMessageLock);
3406 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal function number");
3407 MUNLOCK(ErrorMessageLock);
3412 if ( funstop > tstop )
goto subtermsize;
3414 MLOCK(ErrorMessageLock);
3415 MesPrint(
"TestTerm: Internal inconsistency in term. Dirty flag nonzero.");
3416 MUNLOCK(ErrorMessageLock);
3421 if ( targ > funstop ) {
3422 MLOCK(ErrorMessageLock);
3423 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal function size.");
3424 MUNLOCK(ErrorMessageLock);
3428 if ( functions[*t-FUNCTION].spec >= TENSORFUNCTION ) {
3431 while ( targ < funstop ) {
3433 if ( *targ <= -(FUNCTION+NumFunctions) ) {
3434 MLOCK(ErrorMessageLock);
3435 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal function number in argument.");
3436 MUNLOCK(ErrorMessageLock);
3440 if ( *targ <= -FUNCTION ) { targ++; }
3442 if ( ( *targ != -SYMBOL ) && ( *targ != -VECTOR )
3443 && ( *targ != -MINVECTOR )
3444 && ( *targ != -SNUMBER )
3445 && ( *targ != -ARGWILD )
3446 && ( *targ != -INDEX ) ) {
3447 MLOCK(ErrorMessageLock);
3448 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal object in argument.");
3449 MUNLOCK(ErrorMessageLock);
3456 else if ( ( *targ < ARGHEAD ) || ( targ+*targ > funstop ) ) {
3457 MLOCK(ErrorMessageLock);
3458 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal size of argument.");
3459 MUNLOCK(ErrorMessageLock);
3463 else if ( targ[1] != 0 ) {
3464 MLOCK(ErrorMessageLock);
3465 MesPrint(
"TestTerm: Internal inconsistency in term. Dirty flag in argument.");
3466 MUNLOCK(ErrorMessageLock);
3471 targstop = targ + *targ;
3472 argterm = targ + ARGHEAD;
3473 while ( argterm < targstop ) {
3474 if ( ( *argterm < 4 ) || ( argterm + *argterm > targstop ) ) {
3475 MLOCK(ErrorMessageLock);
3476 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal termsize in argument.");
3477 MUNLOCK(ErrorMessageLock);
3482 MLOCK(ErrorMessageLock);
3483 MesPrint(
"TestTerm: Internal inconsistency in term. Called from TestTerm.");
3484 MUNLOCK(ErrorMessageLock);
3488 argterm += *argterm;
3499 MLOCK(ErrorMessageLock);
3500 MesPrint(
"TestTerm: Internal inconsistency in term. Illegal subterm size.");
3501 MUNLOCK(ErrorMessageLock);
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
LONG PF_BroadcastNumber(LONG x)
int PF_Bcast(void *buffer, int count)
struct bit_field * one_byte
LONG PF_WriteFileToFile(int handle, UBYTE *buffer, LONG size)
struct bit_field set_of_char[32]