exe/lua/src/lua.c
/* Add prefix + string + suffix to list and compute common prefix. */
Add prefix + string + suffix to list and compute common prefix.
Add prefix + string + suffix to list and compute common prefix .
static int lua_rl_dmadd(dmlist *ml, const char *p, size_t pn, const char *s,
			int suf)
{
  char *t = NULL;
  if (ml->idx+1 >= ml->allocated &&
      !(ml->list = (char **)realloc(ml->list, sizeof(char *)*(ml->allocated += 32))))
    return -1;
  if (s) {
    size_t n = strlen(s);
    if (!(t = (char *)malloc(sizeof(char)*(pn+n+(suf?2:1))))) return 1;
    memcpy(t, p, pn);
    memcpy(t+pn, s, n);
    n += pn;
    t[n] = suf;
    if (suf) t[++n] = '\0';
    if (ml->idx == 0) {
      ml->matchlen = n;
    } else {
      size_t i;
      for (i = 0; i < ml->matchlen && i < n && ml->list[1][i] == t[i]; i++) ;
      ml->matchlen = i;  
    }
  }
  ml->list[++ml->idx] = t;
  return 0;
}
static int lua_rl_dmadd ( dmlist * ml , const char * p , size_t pn , const char * s , int suf ) { char * t = NULL ; if ( ml -> idx + 1 >= ml -> allocated && ! ( ml -> list = ( char * * ) realloc ( ml -> list , sizeof ( char * ) * ( ml -> allocated += 32 ) ) ) ) return -1 ; if ( s ) { size_t n = strlen ( s ) ; if ( ! ( t = ( char * ) malloc ( sizeof ( char ) * ( pn + n + ( suf ? 2 : 1 ) ) ) ) ) return 1 ; memcpy ( t , p , pn ) ; memcpy ( t + pn , s , n ) ; n += pn ; t [ n ] = suf ; if ( suf ) t [ ++ n ] = ' \0 ' ; if ( ml -> idx == 0 ) { ml -> matchlen = n ; } else { size_t i ; for ( i = 0 ; i < ml -> matchlen && i < n && ml -> list [ 1 ] [ i ] == t [ i ] ; i ++ ) ; ml -> matchlen = i ; } } ml -> list [ ++ ml -> idx ] = t ; return 0 ; }
Add prefix + string + suffix to list and compute common prefix.
Add prefix + string + suffix to list and compute common prefix .
/* Set matchlen to common prefix. */