source: editwin.c @ 004d683

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 004d683 was d43edd2, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Death to RCS keywords. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 30.3 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
[10b866d]5#include <ctype.h>
[7d4fbcd]6
[ebf0128]7#define VALID_EXCURSION (0x9a2b4729)
8
[a88f35a]9typedef struct _owl_editwin_excursion { /*noproto*/
[ebf0128]10  int valid;
11  int index;
[16cfd12a]12  int mark;
[ebf0128]13  int goal_column;
14  int lock;
[a88f35a]15  struct _owl_editwin_excursion *next;
[ebf0128]16} oe_excursion;
17
[a556caa]18struct _owl_editwin { /*noproto*/
19  char *buff;
20  owl_history *hist;
21  int bufflen;
22  int allocated;
23  int index;
[16cfd12a]24  int mark;
[a60edf2]25  char *killbuf;
[a556caa]26  int goal_column;
27  int topindex;
[ebf0128]28  int cursorx;
[a556caa]29  int winlines, wincols, fillcol, wrapcol;
30  WINDOW *curswin;
31  int style;
32  int lock;
33  int dotsend;
34  int echochar;
[ebf0128]35  oe_excursion *excursions;
[a556caa]36
37  char *command;
38  void (*callback)(struct _owl_editwin*);
39  void *cbdata;
40};
41
[e20d8179]42static void oe_reframe(owl_editwin *e);
[bab52da]43static void oe_save_excursion(owl_editwin *e, oe_excursion *x);
[ebf0128]44static void oe_release_excursion(owl_editwin *e, oe_excursion *x);
[bab52da]45static void oe_restore_excursion(owl_editwin *e, oe_excursion *x);
[a60edf2]46static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x);
[ebf0128]47static int oe_count_glyphs(char *s);
48static int oe_char_width(gunichar c, int column);
[16cfd12a]49static int oe_region_width(owl_editwin *e, int start, int end, int width);
[bab52da]50static int oe_find_display_line(owl_editwin *e, int *x, int index);
[ebf0128]51static void oe_insert_char(owl_editwin *e, gunichar c);
[bab52da]52static int owl_editwin_limit_maxcols(int v, int maxv);
53static int owl_editwin_check_dotsend(owl_editwin *e);
54static int owl_editwin_is_char_in(owl_editwin *e, char *set);
55static gunichar owl_editwin_get_char_at_point(owl_editwin *e);
[19a023f]56static int owl_editwin_replace_internal(owl_editwin *e, int replace, char *s);
[a60edf2]57static char *oe_copy_buf(owl_editwin *e, char *buf, int len);
58static int oe_copy_region(owl_editwin *e);
[77f605d]59static char *oe_chunk(owl_editwin *e, int start, int end);
[bab52da]60
[5b5f3e6]61#define INCR 4096
[7d4fbcd]62
[a556caa]63#define WHITESPACE " \n\t"
64
[bab52da]65owl_editwin *owl_editwin_allocate(void)
66{
[8321cb7]67  owl_editwin *e;
68  e = owl_malloc(sizeof(owl_editwin));
69  memset(e, 0, sizeof(*e));
70  return e;
[a556caa]71}
72
[5b5f3e6]73static int oe_count_glyphs(char *s)
74{
75  int count = 0;
76  char *p;
77
78  for(p = s; *p != 0; p = g_utf8_find_next_char(p, NULL))
79    if (!g_unichar_ismark(g_utf8_get_char(p)))
80      count++;
81
82  return count;
83}
84
[bab52da]85static inline void oe_set_index(owl_editwin *e, int index)
86{
[ebf0128]87  if (index != e->index) {
88    e->goal_column = -1;
89    e->cursorx = -1;
90  }
[521bc84]91  e->index = index;
92}
93
[7f0c26f]94static inline void oe_set_mark(owl_editwin *e, int mark)
95{
96  e->mark = mark;
97}
98
99void owl_editwin_set_mark(owl_editwin *e)
100{
101  oe_set_mark(e, e->index);
102  /* owl_function_makemsg("Mark set."); */
103}
104
[cf83b7a]105/* initialize the editwin e.
106 * 'win' is an already initialzed curses window that will be used by editwin
107 */
[c9334b1]108void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
109{
[e20d8179]110  e->buff=owl_malloc(INCR);
[7d4fbcd]111  e->buff[0]='\0';
112  e->bufflen=0;
[10b866d]113  e->hist=hist;
[7d4fbcd]114  e->allocated=INCR;
[521bc84]115  oe_set_index(e, 0);
[7f0c26f]116  oe_set_mark(e, -1);
[a60edf2]117  if (e->killbuf != NULL)
118    free(e->killbuf);
119  e->killbuf = NULL;
[a556caa]120  e->goal_column = -1;
[ebf0128]121  e->cursorx = -1;
122  e->topindex = 0;
123  e->excursions = NULL;
124  owl_editwin_set_curswin(e, win, winlines, wincols);
[7d4fbcd]125  e->style=style;
126  if ((style!=OWL_EDITWIN_STYLE_MULTILINE) &&
127      (style!=OWL_EDITWIN_STYLE_ONELINE)) {
128    e->style=OWL_EDITWIN_STYLE_MULTILINE;
129  }
130  e->lock=0;
131  e->dotsend=0;
[c9334b1]132  e->echochar='\0';
[e74c01c]133
[af1920fd]134  /* We get initialized multiple times, but we need to hold on to
135     the callbacks, so we can't NULL them here. */
[e74c01c]136  /*
137    e->command = NULL;
138    e->callback = NULL;
139    e->cbdata = NULL;
140  */
[7d4fbcd]141  if (win) werase(win);
142}
143
[c9334b1]144void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
145{
[7d4fbcd]146  e->curswin=w;
147  e->winlines=winlines;
148  e->wincols=wincols;
[9a6cc40]149  e->fillcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxfillcols(&g));
150  e->wrapcol=owl_editwin_limit_maxcols(wincols-7, owl_global_get_edit_maxwrapcols(&g));
[7d4fbcd]151}
152
[c9334b1]153/* echo the character 'ch' for each normal character keystroke,
154 * excepting locktext.  This is useful for entering passwords etc.  If
155 * ch=='\0' characters are echo'd normally
156 */
157void owl_editwin_set_echochar(owl_editwin *e, int ch)
158{
159  e->echochar=ch;
160}
161
162WINDOW *owl_editwin_get_curswin(owl_editwin *e)
163{
[060b3b4]164  return(e->curswin);
[7d4fbcd]165}
166
[c9334b1]167owl_history *owl_editwin_get_history(owl_editwin *e)
168{
[060b3b4]169  return(e->hist);
[10b866d]170}
171
[c9334b1]172void owl_editwin_set_dotsend(owl_editwin *e)
173{
[7d4fbcd]174  e->dotsend=1;
175}
176
[bab52da]177void owl_editwin_set_command(owl_editwin *e, char *command)
178{
[e74c01c]179  if(e->command) owl_free(e->command);
180  e->command = owl_strdup(command);
181}
182
[bab52da]183char *owl_editwin_get_command(owl_editwin *e)
184{
[e74c01c]185  if(e->command) return e->command;
186  return "";
187}
188
[bab52da]189void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*))
190{
[e74c01c]191  e->callback = cb;
192}
193
[bab52da]194void (*owl_editwin_get_callback(owl_editwin *e))(owl_editwin*)
195{
[e74c01c]196  return e->callback;
197}
198
[bab52da]199void owl_editwin_set_cbdata(owl_editwin *e, void *data)
200{
[e74c01c]201  e->cbdata = data;
202}
203
[a556caa]204void *owl_editwin_get_cbdata(owl_editwin *e) {
[e74c01c]205  return e->cbdata;
206}
207
208void owl_editwin_do_callback(owl_editwin *e) {
209  void (*cb)(owl_editwin*);
210  cb=owl_editwin_get_callback(e);
211  if(!cb) {
212    owl_function_error("Internal error: No editwin callback!");
213  } else {
[af1920fd]214    /* owl_function_error("text: |%s|", owl_editwin_get_text(e)); */
[e74c01c]215    cb(e);
216  }
217}
218
[bab52da]219static int owl_editwin_limit_maxcols(int v, int maxv)
[c9334b1]220{
[ebf0128]221  /* maxv > 5 ? MAX(v, vax) : v */
[d36f2cb]222  if (maxv > 5 && v > maxv) {
[060b3b4]223    return(maxv);
[d36f2cb]224  } else {
[060b3b4]225    return(v);
[d36f2cb]226  }
227}
228
[c9334b1]229/* set text to be 'locked in' at the beginning of the buffer, any
230 * previous text (including locked text) will be overwritten
231 */
232void owl_editwin_set_locktext(owl_editwin *e, char *text)
233{
[521bc84]234  oe_set_index(e, 0);
[5b5f3e6]235  e->lock = 0;
236  owl_editwin_replace(e, e->bufflen, text);
237  e->buff[e->bufflen] = 0;
238  e->lock=e->bufflen;
[521bc84]239  oe_set_index(e, e->lock);
[7d4fbcd]240  owl_editwin_redisplay(e, 0);
241}
242
[c9334b1]243int owl_editwin_get_style(owl_editwin *e)
244{
[7d4fbcd]245  return(e->style);
246}
247
[c9334b1]248void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h)
249{
[98f1e69]250  e->hist = h;
251
[7d4fbcd]252  if (e->style==newstyle) return;
253
254  if (newstyle==OWL_EDITWIN_STYLE_MULTILINE) {
255    e->style=newstyle;
256  } else if (newstyle==OWL_EDITWIN_STYLE_ONELINE) {
257    e->style=newstyle;
258
259    /* nuke everything after the first line */
[5b5f3e6]260    owl_editwin_move_to_top(e);
261    owl_editwin_move_to_end_of_line(e);
262    owl_editwin_replace(e, oe_count_glyphs(e->buff + e->index),  "");
[7d4fbcd]263  }
264}
265
[c9334b1]266/* completly reinitialize the buffer */
267void owl_editwin_fullclear(owl_editwin *e)
268{
[7d4fbcd]269  owl_free(e->buff);
[10b866d]270  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
[7d4fbcd]271}
272
[c9334b1]273/* clear all text except for locktext and put the cursor at the
274 * beginning
275 */
276void owl_editwin_clear(owl_editwin *e)
277{
278
[6073462]279  int lock = e->lock;
[10b866d]280  int dotsend=e->dotsend;
[7d4fbcd]281  char *locktext=NULL;
[cc6f009]282  char echochar=e->echochar;
[10b866d]283
[6073462]284  if (lock > 0) {
[5b5f3e6]285    locktext = owl_malloc(lock+1);
286    strncpy(locktext, e->buff, lock);
287    locktext[lock] = 0;
[7d4fbcd]288  }
289
290  owl_free(e->buff);
[10b866d]291  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
[7d4fbcd]292
293  if (lock > 0) {
294    owl_editwin_set_locktext(e, locktext);
295  }
[10b866d]296  if (dotsend) {
297    owl_editwin_set_dotsend(e);
298  }
[cc6f009]299  if (echochar) {
300    owl_editwin_set_echochar(e, echochar);
301  }
[7d4fbcd]302
[5b5f3e6]303  if (locktext)
304    owl_free(locktext);
[6073462]305
[521bc84]306  oe_set_index(e, lock);
[7d4fbcd]307}
308
[c9334b1]309void owl_editwin_recenter(owl_editwin *e)
310{
[a556caa]311  e->topindex = -1;
312}
[e20d8179]313
[a0fbdee]314static void oe_save_excursion(owl_editwin *e, oe_excursion *x)
315{
316  x->index = e->index;
[7f0c26f]317  x->mark = e->mark;
[a0fbdee]318  x->goal_column = e->goal_column;
319  x->lock = e->lock;
[ebf0128]320
321  x->valid = VALID_EXCURSION;
322  x->next = e->excursions;
323  e->excursions = x;
324}
325
326static void oe_release_excursion(owl_editwin *e, oe_excursion *x)
327{
328  oe_excursion *p;
329
330  x->valid = 0;
331  if (e->excursions == NULL)
332    /* XXX huh. */ ;
333  else if (e->excursions == x)
334    e->excursions = x->next;
335  else {
336    for (p = e->excursions; p->next != NULL; p = p->next)
337      if (p->next == x) {
338        p->next = p->next->next;
339        break;
340      }
341    /* and if we ran off the end? XXX */
342  }
[a0fbdee]343}
344
345static void oe_restore_excursion(owl_editwin *e, oe_excursion *x)
346{
[ebf0128]347  if (x->valid == VALID_EXCURSION) {
348    oe_set_index(e, x->index);
349    e->goal_column = x->goal_column;
[7f0c26f]350    e->mark = x->mark;
[ebf0128]351    e->lock = x->lock;
352
353    oe_release_excursion(e, x);
354  }
[a0fbdee]355}
356
[a60edf2]357static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x)
358{
359  if (x->valid == VALID_EXCURSION) {
360    e->mark = x->mark;
361
362    oe_release_excursion(e, x);
363  }
364}
365
[a88f35a]366/* External interface to oe_save_excursion */
367owl_editwin_excursion *owl_editwin_begin_excursion(owl_editwin *e)
368{
369  owl_editwin_excursion *x = owl_malloc(sizeof *x);
370  oe_save_excursion(e, x);
371  return x;
372}
373
374void owl_editwin_end_excursion(owl_editwin *e, owl_editwin_excursion *x)
375{
376  oe_restore_excursion(e, x);
377  owl_free(x);
378}
379
[e20d8179]380static inline char *oe_next_point(owl_editwin *e, char *p)
381{
382  char *boundary = e->buff + e->bufflen + 1;
383  char *q;
384
385  q = g_utf8_find_next_char(p, boundary);
386  while (q && g_unichar_ismark(g_utf8_get_char(q)))
387    q = g_utf8_find_next_char(q, boundary);
388
389  if (q == p)
390    return NULL;
391  return q;
392}
393
394static inline char *oe_prev_point(owl_editwin *e, char *p)
395{
396  char *boundary = e->buff + e->lock;
397
398  p = g_utf8_find_prev_char(boundary, p);
399  while (p && g_unichar_ismark(g_utf8_get_char(p)))
400    p = g_utf8_find_prev_char(boundary, p);
401
402  return p;
403}
404
[ebf0128]405static int oe_char_width(gunichar c, int column)
406{
407  int cw;
408
409  if (c == 9) /* TAB */
410    return TABSIZE - column % TABSIZE;
411
412  cw = mk_wcwidth(c);
413
414  if (cw < 0) /* control characters */
415    cw = 0;
416
417  return cw;
418}
419
[19f765d]420static int oe_find_display_line(owl_editwin *e, int *x, int index)
421{
422  int width = 0, cw;
[ebf0128]423  gunichar c;
[19f765d]424  char *p;
425
[77d4402]426  while(1) {
427    /* note the position of the dot */
[2021bea]428    if (x != NULL && index == e->index && width < e->wincols)
[19f765d]429      *x = width;
[77d4402]430
[19f765d]431    /* get the current character */
432    c = g_utf8_get_char(e->buff + index);
433
434    /* figure out how wide it is */
[ebf0128]435    cw = oe_char_width(c, width);
[19f765d]436
[77d4402]437    if (width + cw > e->wincols) {
438      if (x != NULL && *x == width)
439        *x = -1;
[19f765d]440      break;
[77d4402]441    }
[19f765d]442    width += cw;
443
444    if (c == '\n') {
[77d4402]445      if (width < e->wincols)
446        ++index; /* skip the newline */
[19f765d]447      break;
448    }
449
450    /* find the next character */
451    p = oe_next_point(e, e->buff + index);
452    if (p == NULL) { /* we ran off the end */
453      if (x != NULL && e->index > index)
454        *x = width + 1;
455      break;
456    }
457    index = p - e->buff;
[cedc95c]458
[19f765d]459  }
460  return index;
461}
462
[e20d8179]463static void oe_reframe(owl_editwin *e) {
[cedc95c]464  oe_excursion x;
465  int goal = e->winlines / 2;
466  int index;
467  int count = 0;
468  int point;
469  int n, i;
470  int last;
471
472  oe_save_excursion(e, &x);
473  /* step back line-by-line through the buffer until we have >= goal lines of
474     display text */
475  e->lock = 0; /* we can (must) tread on the locktext */
476
477  point = e->index;
478  last = -1;
479  while (count < goal) {
480    index = e->index;
481    owl_editwin_move_to_beginning_of_line(e);
482    if (last == e->index)
483      break;
484    last = e->index;
485    for (n = 0, i = e->index; i < index; n++)
486      i = oe_find_display_line(e, NULL, i);
487    count += n == 0 ? 1 : n;
488    if (count < goal)
489      owl_editwin_point_move(e, -1);
490  }
491
492  e->topindex = e->index;
[521bc84]493  /* if we overshot, backtrack */
494  for (n = 0; n < (count - goal); n++)
495    e->topindex = oe_find_display_line(e, NULL, e->topindex);
[cedc95c]496
497  oe_restore_excursion(e, &x);
[7d4fbcd]498}
499
[3e36085]500static void oe_addnec(owl_editwin *e, int count)
501{
502  int i;
503
504  for (i = 0; i < count; i++)
505    waddch(e->curswin, e->echochar);
506}
507
508static void oe_mvaddnec(owl_editwin *e, int y, int x, int count)
509{
510  wmove(e->curswin, y, x);
511  oe_addnec(e, count);
512}
513
[c9334b1]514/* regenerate the text on the curses window */
515/* if update == 1 then do a doupdate(), otherwise do not */
516void owl_editwin_redisplay(owl_editwin *e, int update)
517{
[19f765d]518  int x = -1, y = -1, t;
[77d4402]519  int line, index, lineindex, times = 0;
[7d4fbcd]520
[bd1a1ae]521  do {
[cedc95c]522    werase(e->curswin);
523
[bd1a1ae]524    if (e->topindex == -1 || e->index < e->topindex)
[e20d8179]525      oe_reframe(e);
526
[bd1a1ae]527    line = 0;
528    index = e->topindex;
529    while(line < e->winlines) {
530      lineindex = index;
[19f765d]531      t = -1;
532      index = oe_find_display_line(e, &t, lineindex);
533      if (x == -1 && t != -1)
534        x = t, y = line;
[3e36085]535      if (index - lineindex) {
536        if (!e->echochar)
537          mvwaddnstr(e->curswin, line, 0,
538                     e->buff + lineindex,
539                     index - lineindex);
540        else {
541          if(lineindex < e->lock) {
542            mvwaddnstr(e->curswin, line, 0,
543                       e->buff + lineindex,
544                       MIN(index - lineindex,
545                           e->lock - lineindex));
546            if (e->lock < index)
547              oe_addnec(e,
548                        oe_region_width(e, e->lock, index,
549                                        oe_region_width(e, lineindex, e->lock, 0)));
550          } else
551            oe_mvaddnec(e, line, 0, oe_region_width(e, line, index, 0));
552        }
553      }
[bd1a1ae]554      line++;
[a556caa]555    }
[19f765d]556    if (x == -1)
[bd1a1ae]557        e->topindex = -1; /* force a reframe */
[77d4402]558    times++;
559  } while(x == -1 && times < 3);
[e20d8179]560
[19f765d]561  wmove(e->curswin, y, x);
[ebf0128]562  e->cursorx = x;
563
[7d4fbcd]564  wnoutrefresh(e->curswin);
[a556caa]565  if (update == 1)
[7d4fbcd]566    doupdate();
567}
568
[7f0c26f]569static inline void oe_fixup(int *target, int start, int end, int change) {
570  if (*target > start) {
571    if (*target < end)
572      *target = end;
573    else
574      *target += change;
575  }
576}
577
[a88f35a]578int owl_editwin_replace_region(owl_editwin *e, char *s)
579{
580  oe_excursion x;
581  oe_save_excursion(e, &x);
582  int ret;
583
584  if(e->index > e->mark) {
585    owl_editwin_exchange_point_and_mark(e);
586  }
587
588  ret = owl_editwin_replace_internal(e, e->mark - e->index, s);
589
590  oe_restore_excursion(e, &x);
591
592  return ret;
593}
594
[19a023f]595/* replace 'replace' characters at the point with s, returning the change in size */
[77f605d]596int owl_editwin_replace(owl_editwin *e, int replace, char *s)
[ebf0128]597{
[19a023f]598  int start, end, i;
[5b5f3e6]599  char *p;
[e9bb404]600
[5b5f3e6]601  if (!g_utf8_validate(s, -1, NULL)) {
602    owl_function_debugmsg("owl_editwin_insert_string: received non-utf-8 string.");
[ebf0128]603    return 0;
[47519e1b]604  }
605
[5b5f3e6]606  start = e->index;
607  for (i = 0, p = e->buff + start; i < replace && p != NULL; i++)
608    p = oe_next_point(e, p);
609  if (p != NULL)
610    end = p - e->buff;
611  else
612    end = e->bufflen;
613
[19a023f]614  return owl_editwin_replace_internal(e, end - start, s);
615}
616
617static int owl_editwin_replace_internal(owl_editwin *e, int replace, char *s)
618{
619  int start, end, free, need, size, change;
620  oe_excursion *x;
621  char *p;
622
623  start = e->index;
624  end   = start + replace;
625
[5b5f3e6]626  free = e->allocated - e->bufflen + end - start;
627
628  need = strlen(s) - free;
629  if (need > 0) {
630    size = e->allocated + need + INCR - (need % INCR);
[a60edf2]631    p = owl_realloc(e->buff, size);
[5b5f3e6]632    if (p == NULL) {
633      /* XXX signal impending doom somehow and don't do anything */
[ebf0128]634      return 0;
[e9bb404]635    }
[5b5f3e6]636    e->buff = p;
637    e->allocated = size;
[47519e1b]638  }
[e9bb404]639
[5b5f3e6]640  memmove(e->buff + start + strlen(s), e->buff + end, e->bufflen + 1 - end);
641  memcpy(e->buff + start, s, strlen(s));
[ebf0128]642  change = start - end + strlen(s);
643  e->bufflen += change;
[5b5f3e6]644  e->index += strlen(s);
[ebf0128]645
[7f0c26f]646  /* fix up the mark */
[3e36085]647  oe_fixup(&e->mark, start, end, change);
648  oe_fixup(&e->topindex, start, end, change);
[ebf0128]649  /* fix up any saved points after the replaced area */
[7f0c26f]650  for (x = e->excursions; x != NULL; x = x->next) {
651    oe_fixup(&x->index, start, end, change);
[3e36085]652    oe_fixup(&x->mark, start, end, change);
[7f0c26f]653  }
[ebf0128]654
655  return change;
[47519e1b]656}
657
[c9334b1]658/* linewrap the word just before the cursor.
659 * returns 0 on success
660 * returns -1 if we could not wrap.
661 */
[fc2677b]662static void _owl_editwin_linewrap_word(owl_editwin *e)
[c9334b1]663{
[fc2677b]664  oe_excursion x;
[84027015]665  gunichar c;
[7d4fbcd]666
[fc2677b]667  oe_save_excursion(e, &x);
[84027015]668
[fc2677b]669  while (owl_editwin_point_move(e, -1)) {
670    c = owl_editwin_get_char_at_point(e);
671    if (owl_util_can_break_after(c) || c == '\n') {
672      if (c != '\n')
673        owl_editwin_replace(e, c != ' ' ? 0 : 1, "\n");
674      break;
[2d4ff14]675    }
[7d4fbcd]676  }
[fc2677b]677
678  oe_restore_excursion(e, &x);
[7d4fbcd]679}
680
[c9334b1]681/* delete the character at the current point, following chars
682 * shift left.
[e20d8179]683 */
[c9334b1]684void owl_editwin_delete_char(owl_editwin *e)
685{
[5b5f3e6]686  owl_editwin_replace(e, 1, "");
[7d4fbcd]687}
688
[c9334b1]689/* Swap the character at point with the character at point-1 and
690 * advance the pointer.  If point is at beginning of buffer do
691 * nothing.  If point is after the last character swap point-1 with
[e20d8179]692 * point-2.  (Behaves as observed in tcsh and emacs).
[c9334b1]693 */
694void owl_editwin_transpose_chars(owl_editwin *e)
695{
[5b5f3e6]696  char *middle, *end, *start, *tmp;
[f2e36b5]697
[47519e1b]698  if (e->bufflen == 0) return;
[e20d8179]699
[5b5f3e6]700  if (e->index == e->bufflen)
701    owl_editwin_point_move(e, -1);     /* point is after last character */
[f2e36b5]702
[5b5f3e6]703  if (owl_editwin_at_beginning_of_buffer(e))
704    return;     /* point is at beginning of buffer, do nothing */
[f2e36b5]705
[47519e1b]706  /* Transpose two utf-8 unicode glyphs. */
[5b5f3e6]707  middle = e->buff + e->index;
[47519e1b]708
[5b5f3e6]709  end = oe_next_point(e, middle);
710  if (end == NULL)
[e20d8179]711    return;
[47519e1b]712
[5b5f3e6]713  start = oe_prev_point(e, middle);
714  if (start == NULL)
[e20d8179]715    return;
[47519e1b]716
[5b5f3e6]717  tmp = owl_malloc((end - start) + 1);
718  tmp[(end - start)] = 0;
719  memcpy(tmp, middle, end - middle);
720  memcpy(tmp + (end - middle), start, middle - start);
721
722  owl_editwin_point_move(e, -1);
723  owl_editwin_replace(e, 2, tmp);
[f2e36b5]724}
725
[c9334b1]726/* insert 'string' at the current point, later text is shifted
727 * right
728 */
[5b5f3e6]729void owl_editwin_insert_string(owl_editwin *e, char *s)
[c9334b1]730{
[5b5f3e6]731  owl_editwin_replace(e, 0, s);
[7d4fbcd]732}
733
[a556caa]734/* We assume index is not set to point to a mid-char */
[bab52da]735static gunichar owl_editwin_get_char_at_point(owl_editwin *e)
[c9334b1]736{
[a556caa]737  return g_utf8_get_char(e->buff + e->index);
738}
[7d4fbcd]739
[7f0c26f]740void owl_editwin_exchange_point_and_mark(owl_editwin *e) {
741  int tmp;
742
743  if (e->mark != -1) {
744    tmp = e->mark;
745    owl_editwin_set_mark(e);
746    oe_set_index(e, tmp);
747  }
748}
749
[e20d8179]750int owl_editwin_point_move(owl_editwin *e, int delta)
[84027015]751{
[e20d8179]752  char *p;
[19f765d]753  int change, d = 0;
[a556caa]754
755  change = MAX(delta, - delta);
756  p = e->buff + e->index;
757
758  while (d < change && p != NULL) {
[e20d8179]759    if (delta > 0)
760      p = oe_next_point(e, p);
761    else
762      p = oe_prev_point(e, p);
763    if (p != NULL) {
[521bc84]764      oe_set_index(e, p - e->buff);
[e20d8179]765      d++;
[a556caa]766    }
767  }
768
769  return delta > 0 ? d : -d;
[84027015]770}
771
[a556caa]772int owl_editwin_at_beginning_of_buffer(owl_editwin *e) {
773  if (e->index == e->lock)
774    return 1;
[84027015]775
[a556caa]776  return 0;
777}
778
779int owl_at_end_of_buffer(owl_editwin *e) {
780  if (e->index == e->bufflen)
781    return 1;
782
783  return 0;
784}
785
786int owl_editwin_at_beginning_of_line(owl_editwin *e) /*noproto*/
[c9334b1]787{
[a0fbdee]788  oe_excursion x;
[a556caa]789  int ret;
[47519e1b]790
[a556caa]791  if (owl_editwin_at_beginning_of_buffer(e))
792    return 1;
[47519e1b]793
[a0fbdee]794  oe_save_excursion(e, &x);
[a556caa]795  owl_editwin_point_move(e, -1);
[bab52da]796  ret = (owl_editwin_get_char_at_point(e) == '\n');
[a0fbdee]797  oe_restore_excursion(e, &x);
[a556caa]798
799  return ret;
800}
801
[e20d8179]802static int owl_editwin_is_char_in(owl_editwin *e, char *set)
[a556caa]803{
804  char *p;
[5b5f3e6]805
806  for (p = set; *p != 0; p = g_utf8_find_next_char(p, NULL))
807    if (owl_editwin_get_char_at_point(e) == g_utf8_get_char(p))
[a556caa]808      return 1;
809  return 0;
810}
811
[e20d8179]812int owl_editwin_move_if_in(owl_editwin *e, int delta, char *set)
[a556caa]813{
814  int change, distance = 0;
[e20d8179]815  while (owl_editwin_is_char_in(e, set)) {
[a556caa]816    change = owl_editwin_point_move(e, delta);
817    distance += change;
818    if (change == 0)
819      break;
[47519e1b]820  }
[a556caa]821  return distance;
822}
823
[e20d8179]824int owl_editwin_move_if_not_in(owl_editwin *e, int delta, char *set)
[a556caa]825{
826  int change, distance = 0;
[e20d8179]827  while (!owl_editwin_is_char_in(e, set)) {
[a556caa]828    change = owl_editwin_point_move(e, delta);
829    distance += change;
830    if (change == 0)
831      break;
[7d4fbcd]832  }
[a556caa]833  return distance;
[7d4fbcd]834}
835
[e20d8179]836int owl_editwin_move_to_beginning_of_line(owl_editwin *e)
[47519e1b]837{
[a556caa]838  int distance = 0;
[47519e1b]839
[a556caa]840  if (!owl_editwin_at_beginning_of_line(e)) {
841    /* move off the \n if were at the end of a line */
842    distance += owl_editwin_point_move(e, -1);
843    distance += owl_editwin_move_if_not_in(e, -1, "\n");
844    if (distance && !owl_editwin_at_beginning_of_buffer(e))
845      distance += owl_editwin_point_move(e, 1);
[47519e1b]846  }
[77d4402]847  e->goal_column = 0; /* subtleties */
[84027015]848
[a556caa]849  return distance;
850}
[e20d8179]851
852int owl_editwin_move_to_end_of_line(owl_editwin *e)
[a556caa]853{
854  return owl_editwin_move_if_not_in(e, 1, "\n");
[47519e1b]855}
856
[e20d8179]857int owl_editwin_line_move(owl_editwin *e, int delta)
[c9334b1]858{
[d7043b4]859  int goal_column, change, ll, distance;
860  int count = 0;
[a556caa]861
862  change = MAX(delta, -delta);
863
[d7043b4]864  goal_column = e->goal_column;
865  distance = owl_editwin_move_to_beginning_of_line(e);
866  goal_column = goal_column == -1 ? -distance : goal_column;
[a556caa]867
868  while(count < change) {
869    if (delta > 0) {
870      distance += owl_editwin_move_if_not_in(e, 1, "\n");
871      distance += owl_editwin_point_move(e, 1);
872    } else {
873      /* I really want to assert delta < 0 here */
874      distance += owl_editwin_point_move(e, -1); /* to the newline on
875                                                    the previous line */
876      distance += owl_editwin_move_to_beginning_of_line(e);
877    }
878    count++;
[7d4fbcd]879  }
[a556caa]880
881  distance += (ll = owl_editwin_move_to_end_of_line(e));
882  if (ll > goal_column)
883    distance += owl_editwin_point_move(e, goal_column - ll);
884
885  e->goal_column = goal_column;
886
887  return distance;
[7d4fbcd]888}
889
[c9334b1]890void owl_editwin_backspace(owl_editwin *e)
891{
[7d4fbcd]892  /* delete the char before the current one
893   * and shift later chars left
894   */
[a556caa]895  if(owl_editwin_point_move(e, -1))
[7d4fbcd]896    owl_editwin_delete_char(e);
897}
898
[c9334b1]899void owl_editwin_key_up(owl_editwin *e)
900{
[a556caa]901  owl_editwin_line_move(e, -1);
[7d4fbcd]902}
903
[c9334b1]904void owl_editwin_key_down(owl_editwin *e)
905{
[a556caa]906  owl_editwin_line_move(e, 1);
[7d4fbcd]907}
908
[c9334b1]909void owl_editwin_key_left(owl_editwin *e)
910{
[a556caa]911  owl_editwin_point_move(e, -1);
[7d4fbcd]912}
913
[c9334b1]914void owl_editwin_key_right(owl_editwin *e)
915{
[a556caa]916  owl_editwin_point_move(e, 1);
[7d4fbcd]917}
918
[5b5f3e6]919int owl_editwin_forward_word(owl_editwin *e)
[c9334b1]920{
[5b5f3e6]921  int distance;
[7d4fbcd]922  /* if we're starting on a space, find the first non-space */
[5b5f3e6]923  distance = owl_editwin_move_if_in(e, 1, WHITESPACE);
[7d4fbcd]924
[a556caa]925  /* now find the end of this word */
[5b5f3e6]926  distance += owl_editwin_move_if_not_in(e, 1, WHITESPACE);
927
928  return distance;
929}
930
931void owl_editwin_move_to_nextword(owl_editwin *e)
932{
933  owl_editwin_forward_word(e);
[7d4fbcd]934}
935
[c9334b1]936/* go backwards to the last non-space character
937 */
[5b5f3e6]938int owl_editwin_backward_word(owl_editwin *e)
[c9334b1]939{
[a0fbdee]940  oe_excursion x;
[5b5f3e6]941  int distance = 0;
942  int further = 0;
[a556caa]943  int beginning;
944  /* if in middle of word, beginning of word */
945
946  /* if at beginning of a word, find beginning of previous word */
947
[e20d8179]948  if (owl_editwin_is_char_in(e, WHITESPACE)) {
[a556caa]949    /* if in whitespace past end of word, find a word , the find the beginning*/
[5b5f3e6]950    distance += owl_editwin_move_if_in(e, -1, WHITESPACE); /* leaves us on the last
951                                                              character of the word */
[a0fbdee]952    oe_save_excursion(e, &x);
[a556caa]953    /* are we at the beginning of a word? */
954    owl_editwin_point_move(e, -1);
[e20d8179]955    beginning = owl_editwin_is_char_in(e, WHITESPACE);
[a0fbdee]956    oe_restore_excursion(e, &x);
[a556caa]957    if (beginning)
[5b5f3e6]958      return distance;
[a556caa]959   } else {
960    /* in the middle of the word; */
[a0fbdee]961    oe_save_excursion(e, &x);
[5b5f3e6]962    further += owl_editwin_point_move(e, -1);
[e20d8179]963    if (owl_editwin_is_char_in(e, WHITESPACE)) { /* we were at the beginning */
[5b5f3e6]964      distance += owl_editwin_backward_word(e); /* previous case */
[8321cb7]965      oe_release_excursion(e, &x);
[5b5f3e6]966      return distance + further;
[a556caa]967    } else {
[a0fbdee]968      oe_restore_excursion(e, &x);
[7d4fbcd]969    }
970  }
[5b5f3e6]971  distance += owl_editwin_move_if_not_in(e, -1, WHITESPACE);
[a556caa]972  /* will go past */
973  if (e->index > e->lock)
[5b5f3e6]974    distance += owl_editwin_point_move(e, 1);
975  return distance;
976}
977
978void owl_editwin_move_to_previousword(owl_editwin *e)
979{
980  owl_editwin_backward_word(e);
[7d4fbcd]981}
982
[c9334b1]983void owl_editwin_delete_nextword(owl_editwin *e)
984{
[a0fbdee]985  oe_excursion x;
[a556caa]986
[a0fbdee]987  oe_save_excursion(e, &x);
[a60edf2]988  oe_set_mark(e, e->index);
989  owl_editwin_forward_word(e);
990  owl_editwin_kill_region(e);
991  oe_restore_mark_only(e, &x);
[7d4fbcd]992}
993
[c9334b1]994void owl_editwin_delete_previousword(owl_editwin *e)
995{
[a60edf2]996  oe_excursion x;
[b68f9cd]997
[a60edf2]998  oe_save_excursion(e, &x);
999  oe_set_mark(e, e->index);
1000  owl_editwin_backward_word(e);
1001  owl_editwin_kill_region(e);
1002  oe_restore_mark_only(e, &x);
[b68f9cd]1003}
1004
[a556caa]1005void owl_editwin_move_to_line_end(owl_editwin *e)
[c9334b1]1006{
[a556caa]1007  owl_editwin_move_to_end_of_line(e);
[7d4fbcd]1008}
1009
[a556caa]1010void owl_editwin_delete_to_endofline(owl_editwin *e)
[c9334b1]1011{
[a0fbdee]1012  oe_excursion x;
[5b5f3e6]1013  int distance;
[a556caa]1014
[a0fbdee]1015  oe_save_excursion(e, &x);
[a60edf2]1016  owl_editwin_set_mark(e);
[5b5f3e6]1017  distance = owl_editwin_move_to_end_of_line(e);
[a60edf2]1018  if (distance)
1019    owl_editwin_kill_region(e);
1020  else
1021    owl_editwin_replace(e, 1, "");
[a0fbdee]1022  oe_restore_excursion(e, &x);
[a60edf2]1023}
1024
1025void owl_editwin_yank(owl_editwin *e)
1026{
1027  if (e->killbuf != NULL)
1028    owl_editwin_replace(e, 0, e->killbuf);
1029}
1030
1031static char *oe_copy_buf(owl_editwin *e, char *buf, int len)
1032{
1033  char *p;
1034
1035  p = owl_malloc(len + 1);
1036
1037  if (p != NULL) {
1038    owl_free(e->killbuf);
1039    e->killbuf = p;
1040    memcpy(e->killbuf, buf, len);
1041    e->killbuf[len] = 0;
1042  }
1043
1044  return p;
1045}
1046
1047static int oe_copy_region(owl_editwin *e)
1048{
1049  char *p;
1050  int start, end;
1051
1052  if (e->mark == -1)
1053    return 0;
1054
1055  start = MIN(e->index, e->mark);
1056  end = MAX(e->index, e->mark);
1057
1058  p = oe_copy_buf(e, e->buff + start, end - start);
1059  if (p != NULL)
1060    return end - start;
1061  return 0;
1062}
1063
1064void owl_editwin_copy_region_as_kill(owl_editwin *e)
1065{
1066  oe_copy_region(e);
1067}
1068
1069void owl_editwin_kill_region(owl_editwin *e)
1070{
1071  if (e->index > e->mark)
1072    owl_editwin_exchange_point_and_mark(e);
1073
1074  owl_editwin_replace(e, oe_copy_region(e), "");
[7d4fbcd]1075}
1076
[c9334b1]1077void owl_editwin_move_to_line_start(owl_editwin *e)
1078{
[a556caa]1079  owl_editwin_move_to_beginning_of_line(e);
[7d4fbcd]1080}
1081
[c9334b1]1082void owl_editwin_move_to_end(owl_editwin *e)
1083{
[521bc84]1084  oe_set_index(e, e->bufflen);
[7d4fbcd]1085}
1086
[c9334b1]1087void owl_editwin_move_to_top(owl_editwin *e)
1088{
[521bc84]1089  oe_set_index(e, e->lock);
[7d4fbcd]1090}
1091
[2fc8397]1092void owl_editwin_backward_paragraph(owl_editwin *e)
1093{
1094  owl_editwin_point_move(e, -1);
1095  for (; e->index >= e->lock; owl_editwin_point_move(e, -1)) {
1096    if (e->index <= e->lock ||
1097        ((e->buff[e->index] == '\n') && (e->buff[e->index - 1]=='\n')))
1098      break;
1099  }
1100}
1101
1102void owl_editwin_forward_paragraph(owl_editwin *e)
1103{
1104  owl_editwin_point_move(e, 1);
1105  /* scan forward to the start of the next paragraph */
1106  for(; e->index < e->bufflen; owl_editwin_point_move(e, 1)) {
1107    if (e->buff[e->index -1] == '\n' && e->buff[e->index] == '\n')
1108      break;
1109  }
1110}
1111
[d41294a]1112int owl_editwin_current_column(owl_editwin *e)
[c9334b1]1113{
[a0fbdee]1114  oe_excursion x;
[fc2677b]1115  int lineindex;
[7d4fbcd]1116
[a0fbdee]1117  oe_save_excursion(e, &x);
[fc2677b]1118  owl_editwin_move_to_beginning_of_line(e);
1119  lineindex = e->index;
1120  oe_restore_excursion(e, &x);
1121  return oe_region_width(e, lineindex, e->index, 0);
1122}
[a556caa]1123
[fc2677b]1124void owl_editwin_fill_paragraph(owl_editwin *e)
1125{
1126  oe_excursion x;
1127  gunichar ch;
1128  int sentence;
[7d4fbcd]1129
[fc2677b]1130  oe_save_excursion(e, &x);
[7d4fbcd]1131
[fc2677b]1132  /* Mark the end of the paragraph */
1133  owl_editwin_forward_paragraph(e);
1134  /* Skip the trailing newline */
1135  owl_editwin_point_move(e, -1);
1136  owl_editwin_set_mark(e);
[7d4fbcd]1137
[fc2677b]1138  owl_editwin_backward_paragraph(e);
[7d4fbcd]1139
[fc2677b]1140  /* Don't mess with the leading newline */
1141  if (owl_editwin_get_char_at_point(e) == '\n')
1142    owl_editwin_point_move(e, 1);
[7d4fbcd]1143
[fc2677b]1144  /*
1145   * First pass: Scan forward replacing all series of spaces with ' '
1146   * (or nothing after CJK ideograms)
1147   */
1148  sentence = 0;
1149  for(;e->index < e->mark; owl_editwin_point_move(e, 1)) {
[50e671c]1150    /* bail if we hit a trailing dot on the buffer */
[fc2677b]1151    if (strcmp(e->buff + e->index, "\n.") == 0) {
1152      owl_editwin_set_mark(e);
[50e671c]1153      break;
[7d4fbcd]1154    }
1155
[fc2677b]1156    ch = owl_editwin_get_char_at_point(e);
[b2c1bd4]1157
[fc2677b]1158    if (owl_util_can_break_after(ch) || ch == '\n') {
1159      if (g_unichar_isspace(ch)) {
1160        owl_editwin_replace(e, 1, " ");
1161      }
1162
[bd7fb58]1163      if (sentence && g_unichar_isspace(owl_editwin_get_char_at_point(e)))
[fc2677b]1164        owl_editwin_point_move(e, 1);
1165
1166      while(g_unichar_isspace(owl_editwin_get_char_at_point(e))
1167            && e->index < e->mark) {
1168        owl_editwin_delete_char(e);
[7d4fbcd]1169      }
1170    }
[fc2677b]1171
1172    if(ch == '.' || ch == '!' || ch == '?')
1173      sentence = 1;
1174    else
1175      sentence = 0;
1176  }
1177
1178  owl_editwin_backward_paragraph(e);
1179
1180  /* Now go through inserting newlines as needed */
1181  while(e->index < e->mark) {
1182    /* if we've travelled too far, linewrap */
[d41294a]1183    if (owl_editwin_current_column(e) >= e->fillcol)
[fc2677b]1184      _owl_editwin_linewrap_word(e);
1185    owl_editwin_point_move(e, 1);
[7d4fbcd]1186  }
1187
[a0fbdee]1188  oe_restore_excursion(e, &x);
[7d4fbcd]1189}
1190
[cf83b7a]1191/* returns true if only whitespace remains */
[c9334b1]1192int owl_editwin_is_at_end(owl_editwin *e)
1193{
[a556caa]1194  return (only_whitespace(e->buff + e->index));
[217a43e]1195}
1196
[bab52da]1197static int owl_editwin_check_dotsend(owl_editwin *e)
[c9334b1]1198{
[dc7884d]1199  int zdot = 0;
[72ab15f]1200  oe_excursion x;
[7d4fbcd]1201
1202  if (!e->dotsend) return(0);
[72ab15f]1203  if (e->index != e->bufflen) return (0);
[47519e1b]1204
[72ab15f]1205  oe_save_excursion(e, &x);
1206
1207  owl_editwin_point_move(e, -3);
1208
[dc7884d]1209  if(strcmp(e->buff + e->index, "\n.\n") == 0) {
1210    owl_editwin_point_move(e, 1);
1211    owl_editwin_replace(e, 2, "");
1212    zdot = 1;
1213  }
[72ab15f]1214
1215  oe_restore_excursion(e, &x);
1216
1217  return zdot;
[7d4fbcd]1218}
1219
[fac5463]1220void owl_editwin_post_process_char(owl_editwin *e, owl_input j)
[c9334b1]1221{
[a556caa]1222  /* XXX force a redisplay? */
[fac5463]1223  if ((j.ch==13 || j.ch==10) && owl_editwin_check_dotsend(e)) {
[435d6b2]1224    owl_command_edit_done(e);
[7d4fbcd]1225    return;
1226  }
[e20d8179]1227  owl_editwin_redisplay(e, 0);
[7d4fbcd]1228}
1229
[3e36085]1230static int oe_region_width(owl_editwin *e, int start, int end, int offset)
[16cfd12a]1231{
1232  char *p;
[3e36085]1233  int width = offset;
1234 
[16cfd12a]1235  for(p = e->buff + start;
1236      p < e->buff + end;
1237      p = g_utf8_find_next_char(p, NULL))
1238    width += oe_char_width(g_utf8_get_char(p), width);
1239
[3e36085]1240  return width - offset;
[16cfd12a]1241}
1242
[ebf0128]1243static void oe_insert_char(owl_editwin *e, gunichar c)
[fac5463]1244{
[16cfd12a]1245  oe_excursion x;
[5b5f3e6]1246  char tmp[7];
[16cfd12a]1247  int replaced = -1;
[5b5f3e6]1248
[ebf0128]1249  if (c == '\r') /* translate CRs to NLs */
1250    c = '\n';
1251
[16cfd12a]1252  if (!g_unichar_iscntrl(c) || c == '\n' || c== '\t' ) {
[ebf0128]1253    memset(tmp, 0, 7);
1254
1255    if (c == '\n' && e->style == OWL_EDITWIN_STYLE_ONELINE) {
1256      return;
1257    }
1258
[16cfd12a]1259    if (e->cursorx != -1 && e->cursorx + oe_char_width(c, e->cursorx) > e->wrapcol) {
1260      /* XXX this is actually wrong:
1261       * + If the line has been been wrapped, we can be past the wrap column but
1262       *   e->cursorx be much smaller.
1263       * + If the user went back and inserted a bunch of stuff in the middle of
1264       *   the line, there may be more than one word past the wrap column.
1265       */
1266      oe_save_excursion(e, &x);
1267
1268      if (c == ' ' || c == '\t') {
1269        owl_editwin_point_move(e, -1);
1270        replaced = -owl_editwin_move_if_in(e, -1, " \t");
1271        if (!replaced) {
1272          c = '\n';
1273          replaced = -1;
1274        }
1275      } else {
1276        while(!owl_editwin_at_beginning_of_line(e)) {
1277          owl_editwin_point_move(e, -1);
1278          if (owl_util_can_break_after(owl_editwin_get_char_at_point(e))) {
1279            replaced = -owl_editwin_move_if_in(e, -1, " \t");
1280            break;
1281          }
1282        }
1283        if (owl_editwin_at_beginning_of_line(e))
1284          replaced = -1;
1285      }
1286      if (replaced && !owl_editwin_at_beginning_of_line(e))
1287        owl_editwin_point_move(e, 1);
1288      if (replaced >= 0) {
1289        owl_editwin_replace(e, replaced, "\n");
1290      }
1291      oe_restore_excursion(e, &x);
1292    }
1293
1294    if (replaced >= 0 && (c == ' ' || c == '\t'))
1295      return; /* our work here is done */
1296
[ebf0128]1297    g_unichar_to_utf8(c, tmp);
1298    owl_editwin_replace(e, 0, tmp);
1299  }
1300}
1301
1302void owl_editwin_process_char(owl_editwin *e, owl_input j)
1303{
[5b5f3e6]1304  if (j.ch == ERR)
1305    return;
[fac5463]1306  /* Ignore ncurses control characters. */
[e20d8179]1307  if (j.ch < 0x100) {
[ebf0128]1308    oe_insert_char(e, j.uch);
[fac5463]1309  }
1310}
1311
[c9334b1]1312char *owl_editwin_get_text(owl_editwin *e)
1313{
[7d4fbcd]1314  return(e->buff+e->lock);
1315}
1316
[d41294a]1317char *owl_editwin_get_region(owl_editwin *e)
1318{
1319  int start, end;
1320  start = e->index;
1321  end   = e->mark;
1322  if(start > end) {
1323    int tmp = end;
1324    end = start;
1325    start = tmp;
1326  }
1327
1328  return oe_chunk(e, start, end);
1329}
1330
[77f605d]1331int owl_editwin_get_echochar(owl_editwin *e)
1332{
[a556caa]1333  return e->echochar;
1334}
[77f605d]1335
1336static char *oe_chunk(owl_editwin *e, int start, int end)
1337{
1338  char *p;
1339 
1340  p = owl_malloc(end - start + 1);
1341  memcpy(p, e->buff + start, end - start);
1342  p[end - start] = 0;
1343
1344  return p;
1345}
1346
[d41294a]1347/*
1348 * The only guarantee made about these values is that comparisons
1349 * between them, as well as comparison between multiple calls to these
1350 * functions without modifying the editwin in-between, are meaningful.
1351 */
1352
1353int owl_editwin_get_point(owl_editwin *e)
1354{
1355  return e->index;
1356}
1357
1358int owl_editwin_get_mark(owl_editwin *e)
1359{
1360  return e->mark;
1361}
1362
[2f21a41]1363
1364/*
1365 * Local Variables:
1366 * mode:C
1367 * c-basic-offset:2
1368 * End:
1369 */
Note: See TracBrowser for help on using the repository browser.