bridge/class-master/depend/pari/src/gp/gp_rl.c
/* Read line; returns a malloc()ed string of the user input or NULL on EOF.
   Increments the buffer size appropriately if needed; fix *endp if so. */
Read line; returns a malloc()ed string of the user input or NULL on EOF.
Increments the buffer size appropriately if needed; fix *endp if so.
Read line ; returns a malloc () ed string of the user input or NULL on EOF . Increments the buffer size appropriately if needed ; fix * endp if so .
static char *
gprl_input(char **endp, int first, input_method *IM, filtre_t *F)
{
  pari_sp av = avma;
  Buffer *b = F->buf;
  ulong used = *endp - b->buf;
  ulong left = b->len - used, l;
  const char *p;
  char *s, *t;
  if (first) p = IM->prompt;
  else {
    p = F->in_comment ? GP_DATA->prompt_comment: IM->prompt_cont;
    p = gp_format_prompt(p);
  }
  if (! (s = readline(p)) ) { avma = av; return NULL; } 
  gp_add_history(s); 
  l = strlen(s) + 1;
  t = (char*)pari_malloc(l + 1);
  memcpy(t, s, l-1);
  t[l-1] = '\n';
  t[l]   = 0; 
  if (left < l)
  {
    ulong incr = b->len;
    if (incr < l) incr = l;
    fix_buffer(b, b->len + incr);
    *endp = b->buf + used;
  }
  avma = av; return t;
}
static char * gprl_input ( char * * endp , int first , input_method * IM , filtre_t * F ) { pari_sp av = avma ; Buffer * b = F -> buf ; ulong used = * endp - b -> buf ; ulong left = b -> len - used , l ; const char * p ; char * s , * t ; if ( first ) p = IM -> prompt ; else { p = F -> in_comment ? GP_DATA -> prompt_comment : IM -> prompt_cont ; p = gp_format_prompt ( p ) ; } if ( ! ( s = readline ( p ) ) ) { avma = av ; return NULL ; } gp_add_history ( s ) ; l = strlen ( s ) + 1 ; t = ( char * ) pari_malloc ( l + 1 ) ; memcpy ( t , s , l - 1 ) ; t [ l - 1 ] = ' \n ' ; t [ l ] = 0 ; if ( left < l ) { ulong incr = b -> len ; if ( incr < l ) incr = l ; fix_buffer ( b , b -> len + incr ) ; * endp = b -> buf + used ; } avma = av ; return t ; }
Read line; returns a malloc()ed string of the user input or NULL on EOF.
Read line ; returns a malloc () ed string of the user input or NULL on EOF .
/* EOF */ /* Makes a copy */ /* put back \n that readline stripped. This is needed for
   * { print("a
   *   b"); }
   * and conforms with the other input methods anyway. */ /* equivalent to sprintf(t,"%s\n", s) */