void Linker::EnterGAtom(aCHAR * abuf, int filei) { // Enter one global atom whose name is abuf int ahash; int oldhash; aCHAR *pb; const int bbufsize = TERM_BUFSIZE; //aCHAR bbuf[bbufsize+1]; aCHAR *buf; buf = abuf; #ifdef BUG_LINK fprintf(lout, "atom: %ls\n", buf); #endif oldhash = ahash = AtomHash(buf); while (GAtomTable[ahash].name) // while slot full { if (0 == Lstrcmp(buf, GAtomTable[ahash].name)) return; // symbol already installed // if collision, bump it else wrap around ahash = (ahash < eMaxAtoms - 1) ? ahash + 1 : 0; if (ahash == oldhash) // full circle abort_linker(aS("Error: Global atom table full")); } if (NULL == (pb = (aCHAR*) new aCHAR[1+Lstrlen(buf)])) abort_linker(aS("Error: Out of memory")); Lstrcpy(pb, buf); GAtomTable[ahash].name = pb; }
void Linker::initialize( void(*pfM)(aCHAR*) ) { #ifdef BUG_LINK lout = fopen("buglink.txt","w"); // printf("buglink open\n"); fprintf(lout, "** Buglink open\n"); fprintf(lout, "%s\n", __TIME__); fflush(lout); // return; #endif aCHAR outbuf[512]; #ifdef BUG_LINK pfMsg = NULL; #else pfMsg = pfM; #endif eMaxAtoms = 1024 * MAX_ATOM_TABLE_SZ; GAtomTable = NULL; LAtomTable = NULL; zero_fill(m_ver, 256); Lstrcpy(m_ver, AMZI_VERSION); Lstrncpy(outbuf, aS("\nAmzi! Prolog Linker "), 256); Lstrncat(outbuf, m_ver, 256); #ifdef BUG_LINK return; #endif output(outbuf); //output(aS("")); }
void Linker::read_l_atoms(FILE * f, aUINT16 length, int filei) { // read local atom table for predicate int i; int ccount, ichar; aCHAR *pbuf, *qbuf; const int bufsize = TERM_BUFSIZE; aCHAR abuf[bufsize+1]; //aCHAR bbuf[bufsize+1]; static int id; for(i = 0; i < eMaxAtoms; ++i) // 1st, reset local atom table from last time if (LAtomTable[i]) { delete[] LAtomTable[i]; LAtomTable[i] = NULL; } ccount = 0; if (isunicode) length = length / 2; for(i=0; i < eMaxAtoms; ++i) { if(ccount < length) // read atom table { pbuf = abuf; do { if (pbuf >= (abuf + bufsize)) { abort_linker(aS("Error: Local atom too long in code")); } if (-1 == (ichar = ISUNIGETC(f))) aborteof(aS("local atom table")); ++ccount; } while((*pbuf++ = (aCHAR) ichar) != EOS); qbuf = abuf; if (NULL == (pbuf = (aCHAR*) new aCHAR[Lstrlen(qbuf) + 1] )) abort_linker(aS("Error: Out of memory")); Lstrcpy(pbuf, qbuf); LAtomTable[i] = pbuf; } else return; } abort_linker(aS("Error: Local atom table full")); }
void Linker::initialize( void(*pfM)(char*) ) { #ifdef BUG_LINK lout = fopen("buglink.txt","w"); // printf("buglink open\n"); fprintf(lout, "** Buglink open\n"); fprintf(lout, "%s\n", __TIME__); fflush(lout); // return; #endif aCHAR outbuf[120]; pfMsgA = pfM; pfMsg = NULL; eMaxAtoms = 1024 * MAX_ATOM_TABLE_SZ; GAtomTable = NULL; LAtomTable = NULL; Lstrcpy(m_ver, AMZI_VERSION); Lstrncpy(outbuf, aS("\nAmzi! Prolog Linker "), 120); Lstrncat(outbuf, m_ver, 120); output(outbuf); }
/* ----------------- Lstrcat ------------------ */ void __CDECL Lstrcat( const PLstr to, const PLstr from ) { size_t l; if (LLEN(*from)==0) return; if (LLEN(*to)==0) { Lstrcpy( to, from ); return; } L2STR(to); L2STR(from); l = LLEN(*to)+LLEN(*from); if (LMAXLEN(*to) < l) #ifdef JCC Lfx(to, MAX(l,LMAXLEN(*to) + CAT_INC)); #else Lfx(to, l); #endif MEMCPY( LSTR(*to) + LLEN(*to), LSTR(*from), LLEN(*from) ); LLEN(*to) = l; } /* Lstrcat */