Fossil

Diff
Login

Differences From Artifact [27272ce1c4]:

To Artifact [760398793f]:


219
220
221
222
223
224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239
219
220
221
222
223
224
225

226



227
228

229
230
231
232
233
234
235







-

-
-
-
+

-







*/
static void thBufferWriteResize(
  Th_Interp *interp,
  Buffer *pBuffer,
  const char *zAdd,
  int nAdd
){
  char *zNew;
  int nNew = (pBuffer->nBuf+nAdd)*2+32;
  zNew = (char *)Th_Malloc(interp, nNew);
  th_memcpy(zNew, pBuffer->zBuf, pBuffer->nBuf);
  Th_Free(interp, pBuffer->zBuf);
  pBuffer->zBuf = Th_Realloc(interp, pBuffer->zBuf, nNew);
  pBuffer->nBufAlloc = nNew;
  pBuffer->zBuf = zNew;
  th_memcpy(&pBuffer->zBuf[pBuffer->nBuf], zAdd, nAdd);
  pBuffer->nBuf += nAdd;
}
static void thBufferWriteFast(
  Th_Interp *interp,
  Buffer *pBuffer,
  const char *zAdd,
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1533
1534
1535
1536
1537
1538
1539

















1540
1541
1542
1543
1544
1545
1546







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







    pInterp->nResult = 0;
    return zResult;
  }else{
    return (char *)Th_Malloc(pInterp, 1);
  }
}


/*
** Wrappers around the supplied malloc() and free()
*/
void *Th_Malloc(Th_Interp *pInterp, int nByte){
  void *p = pInterp->pVtab->xMalloc(nByte);
  if( p ){
    memset(p, 0, nByte);
  }
  return p;
}
void Th_Free(Th_Interp *pInterp, void *z){
  if( z ){
    pInterp->pVtab->xFree(z);
  }
}

/*
** Install a new th1 command.
**
** If a command of the same name already exists, it is deleted automatically.
*/
int Th_CreateCommand(
  Th_Interp *interp,
1840
1841
1842
1843
1844
1845
1846
1847

1848
1849
1850
1851

1852
1853
1854
1855
1856
1857
1858
1859
1860
1819
1820
1821
1822
1823
1824
1825

1826
1827
1828
1829

1830
1831

1832
1833
1834
1835
1836
1837
1838







-
+



-
+

-







  /* Delete the interpreter structure itself. */
  Th_Free(interp, (void *)interp);
}

/*
** Create a new interpreter.
*/
Th_Interp * Th_CreateInterp(Th_Vtab *pVtab){
Th_Interp * Th_CreateInterp(void){
  Th_Interp *p;

  /* Allocate and initialise the interpreter and the global frame */
  p = pVtab->xMalloc(sizeof(Th_Interp) + sizeof(Th_Frame));
  p = Th_Malloc(0, sizeof(Th_Interp) + sizeof(Th_Frame));
  memset(p, 0, sizeof(Th_Interp));
  p->pVtab = pVtab;
  p->paCmd = Th_HashNew(p);
  thPushFrame(p, (Th_Frame *)&p[1]);
  thInitialize(p);

  return p;
}