Changeset c9334b1 for editwin.c


Ignore:
Timestamp:
Jun 30, 2003, 5:19:35 PM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
cf83b7a
Parents:
6a87084
Message:
Reformatted editwin.c and added capability of doing password echoing
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    rd09e5a1 rc9334b1  
    99#define INCR 5000
    1010
    11 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) {
     11void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
     12{
    1213  /* initialize the editwin e.
    1314   * 'win' is an already initialzed curses window that will be used by editwin
     
    3536  e->lock=0;
    3637  e->dotsend=0;
     38  e->echochar='\0';
    3739  if (win) werase(win);
    3840}
    3941
    40 void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols) {
     42void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
     43{
    4144  e->curswin=w;
    4245  e->winlines=winlines;
     
    4851}
    4952
    50 WINDOW *owl_editwin_get_curswin(owl_editwin *e) {
     53/* echo the character 'ch' for each normal character keystroke,
     54 * excepting locktext.  This is useful for entering passwords etc.  If
     55 * ch=='\0' characters are echo'd normally
     56 */
     57void owl_editwin_set_echochar(owl_editwin *e, int ch)
     58{
     59  e->echochar=ch;
     60}
     61
     62WINDOW *owl_editwin_get_curswin(owl_editwin *e)
     63{
    5164  return(e->curswin);
    5265}
    5366
    54 void owl_editwin_set_history(owl_editwin *e, owl_history *h) {
     67void owl_editwin_set_history(owl_editwin *e, owl_history *h)
     68{
    5569  e->hist=h;
    5670}
    5771
    58 owl_history *owl_editwin_get_history(owl_editwin *e) {
     72owl_history *owl_editwin_get_history(owl_editwin *e)
     73{
    5974  return(e->hist);
    6075}
    6176
    62 void owl_editwin_set_dotsend(owl_editwin *e) {
     77void owl_editwin_set_dotsend(owl_editwin *e)
     78{
    6379  e->dotsend=1;
    6480}
    6581
    66 int owl_editwin_limit_maxcols(int v, int maxv) {
     82int owl_editwin_limit_maxcols(int v, int maxv)
     83{
    6784  if (maxv > 5 && v > maxv) {
    6885    return(maxv);
     
    7289}
    7390
    74 void owl_editwin_set_locktext(owl_editwin *e, char *text) {
    75   /* set text to be 'locked in' at the beginning of the buffer, any
    76      previous text (including locked text) will be overwritten */
     91/* set text to be 'locked in' at the beginning of the buffer, any
     92 * previous text (including locked text) will be overwritten
     93 */
     94void owl_editwin_set_locktext(owl_editwin *e, char *text)
     95{
    7796 
    7897  int x, y;
     
    91110}
    92111
    93 int owl_editwin_get_style(owl_editwin *e) {
     112int owl_editwin_get_style(owl_editwin *e)
     113{
    94114  return(e->style);
    95115}
    96116
    97 void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h) {
     117void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h)
     118{
    98119  char *ptr;
    99120
     
    119140}
    120141
    121 void owl_editwin_fullclear(owl_editwin *e) {
    122   /* completly reinitialize the buffer */
     142/* completly reinitialize the buffer */
     143void owl_editwin_fullclear(owl_editwin *e)
     144{
    123145  owl_free(e->buff);
    124146  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    125147}
    126148
    127 void owl_editwin_clear(owl_editwin *e) {
    128   /* clear all text except for locktext and put the cursor at the beginning */
     149/* clear all text except for locktext and put the cursor at the
     150 * beginning
     151 */
     152void owl_editwin_clear(owl_editwin *e)
     153{
     154
    129155  int lock;
    130156  int dotsend=e->dotsend;
     
    155181
    156182
    157 void _owl_editwin_addspace(owl_editwin *e) {
    158   /* malloc more space for the buffer */
     183/* malloc more space for the buffer */
     184void _owl_editwin_addspace(owl_editwin *e)
     185{
    159186  e->buff=owl_realloc(e->buff, e->allocated+INCR);
    160187  if (!e->buff) {
     
    165192}
    166193
    167 void owl_editwin_recenter(owl_editwin *e) {
     194void owl_editwin_recenter(owl_editwin *e)
     195{
    168196  e->topline=e->buffy-(e->winlines/2);
    169197  if (e->topline<0) e->topline=0;
     
    171199}
    172200
    173 void owl_editwin_redisplay(owl_editwin *e, int update) {
    174   /* regenerate the text on the curses window */
    175   /* if update == 1 then do a doupdate(), otherwise do not */
     201/* regenerate the text on the curses window */
     202/* if update == 1 then do a doupdate(), otherwise do not */
     203void owl_editwin_redisplay(owl_editwin *e, int update)
     204{
    176205 
    177206  char *ptr1, *ptr2, *ptr3, *buff;
    178   int i;
     207  int i, j;
    179208
    180209  werase(e->curswin);
     
    212241  strncpy(buff, ptr1, ptr3-ptr1);
    213242  buff[ptr3-ptr1]='\0';
    214   waddstr(e->curswin, buff);
     243  if (e->echochar=='\0') {
     244    waddstr(e->curswin, buff);
     245  } else {
     246    /* translate to echochar, *except* for the locktext */
     247    int len;
     248    int dolocklen=e->lock-(ptr1-e->buff);
     249
     250    for (i=0; i<dolocklen; i++) {
     251      waddch(e->curswin, buff[i]);
     252    }
     253    len=strlen(buff);
     254    for (i=0; i<len-dolocklen; i++) {
     255      waddch(e->curswin, e->echochar);
     256    }
     257  }
    215258  wmove(e->curswin, e->buffy-e->topline, e->buffx);
    216259  wnoutrefresh(e->curswin);
     
    222265
    223266
    224 int _owl_editwin_linewrap_word(owl_editwin *e) {
    225   /* linewrap the word just before the cursor.
    226    * returns 0 on success
    227    * returns -1 if we could not wrap.
    228    */
    229 
     267/* linewrap the word just before the cursor.
     268 * returns 0 on success
     269 * returns -1 if we could not wrap.
     270 */
     271int _owl_editwin_linewrap_word(owl_editwin *e)
     272{
    230273  int i, z;
    231274
     
    250293}
    251294
    252 void owl_editwin_insert_char(owl_editwin *e, char c) {
    253   /* insert a character at the current point (shift later
    254    * characters over) */
     295/* insert a character at the current point (shift later
     296 * characters over)
     297 */
     298void owl_editwin_insert_char(owl_editwin *e, char c)
     299{
    255300 
    256301  int z, i, ret;
     
    306351}
    307352
    308 void owl_editwin_overwrite_char(owl_editwin *e, char c) {
    309   /* overwrite the character at the current point with 'c' */
     353/* overwrite the character at the current point with 'c' */
     354void owl_editwin_overwrite_char(owl_editwin *e, char c)
     355{
    310356  int z;
    311357 
     
    348394}
    349395
    350 void owl_editwin_delete_char(owl_editwin *e) {
    351   /* delete the character at the current point, following chars
    352    * shift left.
    353    */
     396/* delete the character at the current point, following chars
     397 * shift left.
     398 */
     399void owl_editwin_delete_char(owl_editwin *e)
     400{
    354401  int z, i;
    355402
     
    368415}
    369416
    370 void owl_editwin_transpose_chars(owl_editwin *e) {
    371   /* Swap the character at point with the character at point-1 and
    372    * advance the pointer.  If point is at beginning of buffer do
    373    * nothing.  If point is after the last character swap point-1 with
    374    * point-2.  (Behaves as observed in tcsh and emacs). 
    375    */
    376 
     417/* Swap the character at point with the character at point-1 and
     418 * advance the pointer.  If point is at beginning of buffer do
     419 * nothing.  If point is after the last character swap point-1 with
     420 * point-2.  (Behaves as observed in tcsh and emacs). 
     421 */
     422void owl_editwin_transpose_chars(owl_editwin *e)
     423{
    377424  int z;
    378425  char tmp;
     
    399446}
    400447
    401 void owl_editwin_insert_string(owl_editwin *e, char *string) {
    402   /* insert 'string' at the current point, later text is shifted
    403    * right
    404    */
     448/* insert 'string' at the current point, later text is shifted
     449 * right
     450 */
     451void owl_editwin_insert_string(owl_editwin *e, char *string)
     452{
    405453  int i, j;
    406454
     
    411459}
    412460
    413 void owl_editwin_overwrite_string(owl_editwin *e, char *string) {
     461/* write 'string' at the current point, overwriting text that is
     462 * already there
     463 */
     464
     465void owl_editwin_overwrite_string(owl_editwin *e, char *string)
     466{
    414467  int i, j;
    415   /* write 'string' at the current point, overwriting text that is
    416    * already there
    417    */
    418468
    419469  j=strlen(string);
     
    423473}
    424474
    425 int _owl_editwin_get_index_from_xy(owl_editwin *e) {
    426   /* get the index into e->buff for the current cursor
    427    * position.
    428    */
     475/* get the index into e->buff for the current cursor
     476 * position.
     477 */
     478int _owl_editwin_get_index_from_xy(owl_editwin *e)
     479{
    429480  int i;
    430481  char *ptr1, *ptr2;
     
    459510}
    460511
    461 void _owl_editwin_set_xy_by_index(owl_editwin *e, int index) {
     512void _owl_editwin_set_xy_by_index(owl_editwin *e, int index)
     513{
    462514  int z, i;
    463515
     
    474526}
    475527
    476 void owl_editwin_adjust_for_locktext(owl_editwin *e) {
     528void owl_editwin_adjust_for_locktext(owl_editwin *e)
     529{
    477530  /* if we happen to have the cursor over locked text
    478531   * move it to be out of the locktext region */
     
    482535}
    483536
    484 void owl_editwin_backspace(owl_editwin *e) {
     537void owl_editwin_backspace(owl_editwin *e)
     538{
    485539  /* delete the char before the current one
    486540   * and shift later chars left
     
    493547}
    494548
    495 void owl_editwin_key_up(owl_editwin *e) {
     549void owl_editwin_key_up(owl_editwin *e)
     550{
    496551  if (e->buffy > 0) e->buffy--;
    497552  if (e->buffx >= owl_editwin_get_numchars_on_line(e, e->buffy)) {
     
    507562}
    508563
    509 void owl_editwin_key_down(owl_editwin *e) {
     564void owl_editwin_key_down(owl_editwin *e)
     565{
    510566  /* move down if we can */
    511567  if (e->buffy+1 < owl_editwin_get_numlines(e)) e->buffy++;
     
    525581}
    526582
    527 void owl_editwin_key_left(owl_editwin *e) {
     583void owl_editwin_key_left(owl_editwin *e)
     584{
    528585  /* move left if we can, and maybe up a line */
    529586  if (e->buffx>0) {
     
    543600}
    544601
    545 void owl_editwin_key_right(owl_editwin *e) {
     602void owl_editwin_key_right(owl_editwin *e)
     603{
    546604  int i;
    547605
     
    564622}
    565623
    566 void owl_editwin_move_to_nextword(owl_editwin *e) {
     624void owl_editwin_move_to_nextword(owl_editwin *e)
     625{
    567626  int i, x;
    568627
     
    600659}
    601660
    602 void owl_editwin_move_to_previousword(owl_editwin *e) {
    603   /* go backwards to the last non-space character */
     661/* go backwards to the last non-space character
     662 */
     663void owl_editwin_move_to_previousword(owl_editwin *e)
     664{
    604665  int i, x;
    605666
     
    635696
    636697
    637 void owl_editwin_delete_nextword(owl_editwin *e) {
     698void owl_editwin_delete_nextword(owl_editwin *e)
     699{
    638700  int z;
    639701
     
    660722}
    661723
    662 void owl_editwin_delete_previousword(owl_editwin *e) {
     724void owl_editwin_delete_previousword(owl_editwin *e)
     725{
    663726  /* go backwards to the last non-space character, then delete chars */
    664727  int i, startpos, endpos;
     
    672735}
    673736
    674 void owl_editwin_delete_to_endofline(owl_editwin *e) {
     737void owl_editwin_delete_to_endofline(owl_editwin *e)
     738{
    675739  int i;
    676740
     
    694758}
    695759
    696 void owl_editwin_move_to_line_end(owl_editwin *e) {
     760void owl_editwin_move_to_line_end(owl_editwin *e)
     761{
    697762  e->buffx=owl_editwin_get_numchars_on_line(e, e->buffy);
    698763}
    699764
    700 void owl_editwin_move_to_line_start(owl_editwin *e) {
     765void owl_editwin_move_to_line_start(owl_editwin *e)
     766{
    701767  e->buffx=0;
    702768  owl_editwin_adjust_for_locktext(e);
    703769}
    704770
    705 void owl_editwin_move_to_end(owl_editwin *e) {
     771void owl_editwin_move_to_end(owl_editwin *e)
     772{
    706773  /* go to last char */
    707774  e->buffy=owl_editwin_get_numlines(e)-1;
     
    715782}
    716783
    717 void owl_editwin_move_to_top(owl_editwin *e) {
     784void owl_editwin_move_to_top(owl_editwin *e)
     785{
    718786  _owl_editwin_set_xy_by_index(e, 0);
    719787
     
    724792}
    725793
    726 void owl_editwin_fill_paragraph(owl_editwin *e) {
     794void owl_editwin_fill_paragraph(owl_editwin *e)
     795{
    727796  int i, save;
    728797
     
    787856
    788857/* returns if only whitespace remains */
    789 int owl_editwin_is_at_end(owl_editwin *e) {
     858int owl_editwin_is_at_end(owl_editwin *e)
     859{
    790860  int cur=_owl_editwin_get_index_from_xy(e);
    791   return only_whitespace(e->buff+cur);
    792 }
    793 
    794 int owl_editwin_check_dotsend(owl_editwin *e) {
     861  return (only_whitespace(e->buff+cur));
     862}
     863
     864int owl_editwin_check_dotsend(owl_editwin *e)
     865{
    795866  int i;
    796867
     
    811882}
    812883
    813 void owl_editwin_post_process_char(owl_editwin *e, int j) {
     884void owl_editwin_post_process_char(owl_editwin *e, int j)
     885{
    814886  /* check if we need to scroll down */
    815887  if (e->buffy-e->topline >= e->winlines) {
     
    823895}
    824896
    825 void owl_editwin_process_char(owl_editwin *e, int j) {
     897void owl_editwin_process_char(owl_editwin *e, int j)
     898{
    826899  if (j == ERR) return;
    827900  if (j>127 || ((j<32) && (j!=10) && (j!=13))) {
     
    832905}
    833906
    834 char *owl_editwin_get_text(owl_editwin *e) {
     907char *owl_editwin_get_text(owl_editwin *e)
     908{
    835909  return(e->buff+e->lock);
    836910}
    837911
    838 int owl_editwin_get_numchars_on_line(owl_editwin *e, int line) {
     912int owl_editwin_get_numchars_on_line(owl_editwin *e, int line)
     913{
    839914  int i;
    840915  char *ptr1, *ptr2;
     
    861936}
    862937
    863 int owl_editwin_get_numlines(owl_editwin *e) {
     938int owl_editwin_get_numlines(owl_editwin *e)
     939{
    864940  return(owl_text_num_lines(e->buff));
    865941}
Note: See TracChangeset for help on using the changeset viewer.