pike.git / lib / modules / Stdio.pmod / Readline.pike

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Readline.pike:1: - // $Id: Readline.pike,v 1.43 2002/11/26 15:06:46 jhs Exp $ + // $Id: Readline.pike,v 1.44 2003/01/20 17:44:01 nilsson Exp $   #pike __REAL_VERSION__      class OutputController   {    static private object(Stdio.File) outfd;    static private object(Stdio.Terminfo.Termcap) term;    static private int xpos = 0, columns = 0;    static private mapping oldattrs = 0;      #define BLINK 1
pike.git/lib/modules/Stdio.pmod/Readline.pike:158: Inside #if 1
   "^@","^A","^B","^C","^D","^E","^F","^G",    "^H","^I","^J","^K","^L","^M","^N","^O",    "^P","^Q","^R","^S","^T","^U","^V","^W",    "^X","^Y","^Z","^[","^\\","^]","^^","^_",    "^?",    "~@","~A","~B","~C","~D","~E","~F","~G",    "~H","~I","~J","~K","~L","~M","~N","~O",    "~P","~Q","~R","~S","~T","~U","~V","~W",    "~X","~Y","~Z","~[","~\\","~]","~^","~_",    })); -  return hide ? "*"*strlen(s) : s; +  return hide ? "*"*sizeof(s) : s;   #else    -  for(int i=0; i<strlen(s); i++) +  for(int i=0; i<sizeof(s); i++)    if(s[i]<' ')    s = s[..i-1]+sprintf("^%c", s[i]+'@')+s[i+1..];    else if(s[i]==127)    s = s[..i-1]+"^?"+s[i+1..];    else if(s[i]>=128 && s[i]<160)    s = s[..i-1]+sprintf("~%c", s[i]-128+'@')+s[i+1..];    return s;   #endif    }          static int width(string s)    { -  return strlen(s); +  return sizeof(s);    }       static int escapified_width(string s)    {    return width(escapify(s));    }       void low_write(string s, void|int word_break)    {    int n = width(s);
pike.git/lib/modules/Stdio.pmod/Readline.pike:205:    {    while(xpos+n>=columns)    {    int l = columns-xpos;    string line=s[..l-1];    int spos=search(reverse(line)," ");    if(spos==-1)    {    outfd->write(line);    }else{ -  l=strlen(line)-spos; +  l=sizeof(line)-spos;    outfd->write(line[..l-2]);    }    s=s[l..];    n-=l;    xpos+=l;    if(xpos<columns || !term->tgetflag("am"))    outfd->write((term->put("cr")||"")+(term->put("do")||"\n"));    xpos = 0;    }    }else{
pike.git/lib/modules/Stdio.pmod/Readline.pike:757:       void backward_delete_char()    {    int p = _readline->getcursorpos();    _readline->delete(p-1,p);    }       void delete_char_or_eof()    {    int p = _readline->getcursorpos(); -  if (p<strlen(_readline->gettext())) +  if (p<sizeof(_readline->gettext()))    _readline->delete(p,p+1); -  else if(!strlen(_readline->gettext())) +  else if(!sizeof(_readline->gettext()))    _readline->eof();    }       void forward_char()    {    _readline->setcursorpos(_readline->getcursorpos()+1);    }       void backward_char()    {    _readline->setcursorpos(_readline->getcursorpos()-1);    }       void beginning_of_line()    {    _readline->setcursorpos(0);    }       void end_of_line()    { -  _readline->setcursorpos(strlen(_readline->gettext())); +  _readline->setcursorpos(sizeof(_readline->gettext()));    }       void transpose_chars()    {    int p = _readline->getcursorpos(); -  if (p<0 || p>=strlen(_readline->gettext())) +  if (p<0 || p>=sizeof(_readline->gettext()))    return;    string c = _readline->gettext()[p-1..p];    _readline->delete(p-1, p+1);    _readline->insert(reverse(c), p-1);    }       static array find_word_to_manipulate()    {    int p = _readline->getcursorpos();    int ep;    string line = _readline->gettext(); -  while(word_break_chars[ line[p..p] ] && p < strlen(line)) +  while(word_break_chars[ line[p..p] ] && p < sizeof(line))    p++; -  if(p >= strlen(line)) { +  if(p >= sizeof(line)) {    _readline->setcursorpos(p);    return ({ 0, 0 });    }    ep = forward_find_word();    _readline->delete(p, ep);    return ({ line[p..ep-1], p });    }       void capitalize_word()    {
pike.git/lib/modules/Stdio.pmod/Readline.pike:846:    if(n) break;    } else n = 1;    }    return p;    }       static int backward_find_word()    {    int p = _readline->getcursorpos()-1;    string line = _readline->gettext(); -  if(p >= strlen(line)) p = strlen(line) - 1; +  if(p >= sizeof(line)) p = sizeof(line) - 1;    while(word_break_chars[ line[p..p] ] && p >= 0)    // find first "non break char"    p--;    for(;p >= 0; p--)    if(word_break_chars[ line[p..p] ]) {    p++; // We want to be one char before the break char.    break;    }    return p;    }
pike.git/lib/modules/Stdio.pmod/Readline.pike:884:    {    int sp = backward_find_word();    int ep = _readline->getcursorpos();    if((ep - sp) == 0)    sp--;    _readline->kill(sp, ep);    }       void kill_line()    { -  _readline->kill(_readline->getcursorpos(), strlen(_readline->gettext())); +  _readline->kill(_readline->getcursorpos(), sizeof(_readline->gettext()));    }       void kill_whole_line()    { -  _readline->kill(0, strlen(_readline->gettext())); +  _readline->kill(0, sizeof(_readline->gettext()));    }       void yank()    {    _readline->setmark(_readline->getcursorpos());    _readline->insert(_readline->kill_ring_yank(),_readline->getcursorpos());    }       void kill_ring_save()    {
pike.git/lib/modules/Stdio.pmod/Readline.pike:1157:   {    return cursorpos;   }      //! @fixme   //! Document this function   int setcursorpos(int p)   {    if (p<0)    p = 0; -  if (p>strlen(text)) -  p = strlen(text); +  if (p>sizeof(text)) +  p = sizeof(text);    if (p<cursorpos)    {    if(!input_controller->dumb)    output_controller->move_backward(text[p..cursorpos-1]);    cursorpos = p;    }    else if (p>cursorpos)    {    if(!input_controller->dumb)    output_controller->move_forward(text[cursorpos..p-1]);
pike.git/lib/modules/Stdio.pmod/Readline.pike:1180:    }    return cursorpos;   }      //! @fixme   //! Document this function   int setmark(int p)   {    if (p<0)    p = 0; -  if (p>strlen(text)) -  p = strlen(text); +  if (p>sizeof(text)) +  p = sizeof(text);    mark=p;   }      //! @fixme   //! Document this function   int getmark()   {    return mark;   }      //! @fixme   //! Document this function   void insert(string s, int p)   {    if (p<0)    p = 0; -  if (p>strlen(text)) -  p = strlen(text); +  if (p>sizeof(text)) +  p = sizeof(text);    setcursorpos(p);    if(!input_controller->dumb)    output_controller->write(s,0,hide); -  cursorpos += strlen(s); +  cursorpos += sizeof(s);    string rest = text[p..]; -  if (strlen(rest) && !input_controller->dumb) +  if (sizeof(rest) && !input_controller->dumb)    {    output_controller->write(rest,0,hide);    output_controller->move_backward(rest);    }    text = text[..p-1]+s+rest;    -  if (mark>p) mark+=strlen(s); +  if (mark>p) mark+=sizeof(s);   }      //! @fixme   //! Document this function   void delete(int p1, int p2)   {    if (p1<0)    p1 = 0; -  if (p2>strlen(text)) -  p2 = strlen(text); +  if (p2>sizeof(text)) +  p2 = sizeof(text);    setcursorpos(p1);    if (p1>=p2)    return;    if(!input_controller->dumb) {    output_controller->write(text[p2..],0,hide);    output_controller->erase(text[p1..p2-1]);    }    text = text[..p1-1]+text[p2..];       if (mark>p2) mark-=(p2-p1);    else if (mark>p1) mark=p1;    -  cursorpos = strlen(text); +  cursorpos = sizeof(text);    setcursorpos(p1);   }      //! @fixme   //! Document this function   array(int) pointmark() // returns point and mark in numeric order   {    int p1,p2;    p1=getcursorpos(),p2=getmark();    if (p1>p2) return ({p2,p1});
pike.git/lib/modules/Stdio.pmod/Readline.pike:1265:    else [p1,p2]=pointmark();    return text[p1..p2-1];   }      //! @fixme   //! Document this function   void kill(int p1, int p2)   {    if (p1<0)    p1 = 0; -  if (p2>strlen(text)) -  p2 = strlen(text); +  if (p2>sizeof(text)) +  p2 = sizeof(text);    if (p1>=p2)    return;    add_to_kill_ring(text[p1..p2-1]);    delete(p1,p2);   }      //! @fixme   //! Document this function   void add_to_kill_ring(string s)   {
pike.git/lib/modules/Stdio.pmod/Readline.pike:1295:    if (!sizeof(kill_ring)) return "";    return kill_ring[-1];   }      //! @fixme   //! Document this function   void history(int n)   {    if(historyobj) {    string h = historyobj->history(n, text); -  delete(0, strlen(text)+strlen(prompt)); +  delete(0, sizeof(text)+sizeof(prompt));    insert(h, 0);    }   }      //! Changes the line to a line from the history @[d] steps from the   //! current entry (0 being the current line, negative values older,   //! and positive values newer).   //! @note   //! Only effective if you have a history object.   void delta_history(int d)
pike.git/lib/modules/Stdio.pmod/Readline.pike:1379:    historyobj->finishline(text);    initline();    if(newline_func)    newline_func(0);   }      //! Print a message to the output device   void message(string msg)   {    int p = cursorpos; -  setcursorpos(strlen(text)); +  setcursorpos(sizeof(text));    output_controller->newline();    foreach(msg/"\n", string l) {    output_controller->write(l);    output_controller->newline();    }    redisplay(0, 1);    setcursorpos(p);   }      //! @fixme
pike.git/lib/modules/Stdio.pmod/Readline.pike:1407:    output_controller->clear(1);    }    array(string) tmp=msg/"\n";    foreach(tmp[..sizeof(tmp)-2],string l)    {    output_controller->write(l,word_wrap);    output_controller->newline();    }    output_controller->write(tmp[-1],word_wrap);    -  cursorpos=strlen(text); +  cursorpos=sizeof(text);    redisplay(0, 1);    setcursorpos(p);   }      //! @fixme   //! Document this function   void list_completions(array(string) c)   {    message(sprintf("%-*#s",output_controller->get_number_of_columns(),    c*"\n"));
pike.git/lib/modules/Stdio.pmod/Readline.pike:1461:   //! Document this function   void set_blocking()   {    set_nonblocking(0);   }      //! @fixme   //! Document this function   string edit(string data, string|void local_prompt, array(string)|void attrs)   { -  if(data && strlen(data) && input_controller->dumb) +  if(data && sizeof(data) && input_controller->dumb)    {    string ret=edit("", (local_prompt || get_prompt()) +"["+data+"] ", attrs); -  return (!ret || !strlen(ret))?data:ret; +  return (!ret || !sizeof(ret))?data:ret;    }    string old_prompt;    array(string) old_attrs;       if(newline_func == read_newline)    return 0;       if(local_prompt)    {    old_prompt = get_prompt();