-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcommand.c
820 lines (699 loc) · 19.6 KB
/
command.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
/*
* command.c, femto, Hugh Barney, Public Domain, 2017
* Derived from: Anthony's Editor January 93, (Public Domain 1991, 1993 by Anthony Howe)
*/
#include "header.h"
void beginning_of_buffer()
{
curbp->b_point = 0;
}
void end_of_buffer()
{
curbp->b_point = pos(curbp, curbp->b_ebuf);
if (curbp->b_epage < pos(curbp, curbp->b_ebuf)) curbp->b_reframe = 1;
}
void quit_ask()
{
if (modified_buffers() > 0) {
mvaddstr(MSGLINE, 0, str_modified_buffers);
clrtoeol();
if (!yesno(FALSE))
return;
}
quit();
}
/* flag = default answer, FALSE=n, TRUE=y */
int yesno(int flag)
{
int ch;
addstr(flag ? str_yes : str_no);
refresh();
ch = getch();
if (ch == '\r' || ch == '\n')
return (flag);
return (tolower(ch) == str_yes[1]);
}
void quit()
{
done = 1;
}
void redraw()
{
clear();
mark_all_windows();
update_display();
}
void left()
{
int n = prev_utf8_char_size();
while (0 < curbp->b_point && n-- > 0)
--curbp->b_point;
}
void right()
{
int n = utf8_size(*ptr(curbp,curbp->b_point));
while ((curbp->b_point < pos(curbp, curbp->b_ebuf)) && n-- > 0)
++curbp->b_point;
}
/*
* work out number of bytes based on first byte
*
* 1 byte utf8 starts 0xxxxxxx 00 - 7F : 000 - 127
* 2 byte utf8 starts 110xxxxx C0 - DF : 192 - 223
* 3 byte utf8 starts 1110xxxx E0 - EF : 224 - 239
* 4 byte utf8 starts 11110xxx F0 - F7 : 240 - 247
*
*/
int utf8_size(char_t c)
{
if (c >= 192 && c < 224) return 2;
if (c >= 224 && c < 240) return 3;
if (c >= 240 && c < 248) return 4;
return 1; /* if in doubt it is 1 */
}
int prev_utf8_char_size()
{
int n;
for (n=2;n<5;n++)
if (-1 < curbp->b_point - n && (utf8_size(*(ptr(curbp, curbp->b_point - n))) == n))
return n;
return 1;
}
void up()
{
curbp->b_point = lncolumn(curbp, upup(curbp, curbp->b_point),curbp->b_col);
}
void down()
{
curbp->b_point = lncolumn(curbp, dndn(curbp, curbp->b_point),curbp->b_col);
}
void lnbegin()
{
curbp->b_point = segstart(curbp, lnstart(curbp,curbp->b_point), curbp->b_point);
}
void lnend()
{
if (curbp->b_point == pos(curbp, curbp->b_ebuf)) return; /* do nothing if EOF */
curbp->b_point = dndn(curbp, curbp->b_point);
point_t p = curbp->b_point;
left();
curbp->b_point = (*ptr(curbp, curbp->b_point) == '\n') ? curbp->b_point : p;
}
void backward_word()
{
char_t *p;
while (!isspace(*(p = ptr(curbp, curbp->b_point))) && curbp->b_buf < p)
--curbp->b_point;
while (isspace(*(p = ptr(curbp, curbp->b_point))) && curbp->b_buf < p)
--curbp->b_point;
}
void forward_page()
{
curbp->b_page = curbp->b_point = upup(curbp, curbp->b_epage);
while (0 < curbp->b_row--)
down();
/* this stops a reframe in display(), and epage is recalculated during display() */
curbp->b_epage = pos(curbp, curbp->b_ebuf);
}
void backward_page()
{
int i = curwp->w_rows;
while (0 < --i) {
curbp->b_page = upup(curbp, curbp->b_page);
up();
}
}
void forward_word()
{
char_t *p;
while (!isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
++curbp->b_point;
while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
++curbp->b_point;
}
/* standard insert at the keyboard */
void insert()
{
char_t the_char[2]; /* the inserted char plus a null */
assert(curbp->b_gap <= curbp->b_egap);
if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
return;
curbp->b_point = movegap(curbp, curbp->b_point);
/* overwrite if mid line, not EOL or EOF, CR will insert as normal */
if ((curbp->b_flags & B_OVERWRITE) && *input != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
*(ptr(curbp, curbp->b_point)) = *input;
if (curbp->b_point < pos(curbp, curbp->b_ebuf))
++curbp->b_point;
/* FIXME - overwite mode not handled properly for undo yet */
} else {
the_char[0] = *input == '\r' ? '\n' : *input;
the_char[1] = '\0'; /* null terminate */
*curbp->b_gap++ = the_char[0];
curbp->b_point = pos(curbp, curbp->b_egap);
/* the point is set so that and undo will backspace over the char */
add_undo(curbp, UNDO_T_INSERT, curbp->b_point, the_char, NULL);
}
add_mode(curbp, B_MODIFIED);
}
/*
* A special insert used as the undo of delete char (C-d or DEL)
* this is where the char is inserted at the point and the cursor
* is NOT moved on 1 char. This MUST be a seperate function so that
* INSERT + BACKSPACE are matching undo pairs
* INSERT_AT + DELETE are matching undo pairs
* Note: This function is only ever called by execute_undo to undo a DEL.
*/
void insert_at()
{
char_t the_char[2]; /* the inserted char plus a null */
assert(curbp->b_gap <= curbp->b_egap);
if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
return;
curbp->b_point = movegap(curbp, curbp->b_point);
/* overwrite if mid line, not EOL or EOF, CR will insert as normal */
if ((curbp->b_flags & B_OVERWRITE) && *input != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
*(ptr(curbp, curbp->b_point)) = *input;
if (curbp->b_point < pos(curbp, curbp->b_ebuf))
++curbp->b_point;
/* FIXME - overwite mode not handled properly for undo yet */
} else {
the_char[0] = *input == '\r' ? '\n' : *input;
the_char[1] = '\0'; /* null terminate */
*curbp->b_gap++ = the_char[0];
curbp->b_point = pos(curbp, curbp->b_egap);
curbp->b_point--; /* move point back to where it was before, should always be safe */
/* the point is set so that and undo will DELETE the char */
add_undo(curbp, UNDO_T_INSAT, curbp->b_point, the_char, NULL);
}
add_mode(curbp, B_MODIFIED);
}
void backspace()
{
char_t the_char[7]; /* the deleted char, allow 6 unsigned chars plus a null */
int n = prev_utf8_char_size();
curbp->b_point = movegap(curbp, curbp->b_point);
if (curbp->b_buf < (curbp->b_gap - (n - 1)) ) {
curbp->b_gap -= n; /* increase start of gap by size of char */
add_mode(curbp, B_MODIFIED);
/* record the backspaced chars in the undo structure */
memcpy(the_char, curbp->b_gap, n);
the_char[n] = '\0'; /* null terminate, the backspaced char(s) */
curbp->b_point = pos(curbp, curbp->b_egap);
//debug("point after bs = %ld\n", curbp->b_point);
add_undo(curbp, UNDO_T_BACKSPACE, curbp->b_point, the_char, NULL);
}
curbp->b_point = pos(curbp, curbp->b_egap);
}
void delete()
{
char_t the_char[7]; /* the deleted char, allow 6 unsigned chars plus a null */
int n;
curbp->b_point = movegap(curbp, curbp->b_point);
n = utf8_size(*(ptr(curbp, curbp->b_point)));
if (curbp->b_egap < curbp->b_ebuf) {
/* record the deleted chars in the undo structure */
memcpy(the_char, curbp->b_egap, n);
the_char[n] = '\0'; /* null terminate, the deleted char(s) */
//debug("deleted = '%s'\n", the_char);
curbp->b_egap += n;
curbp->b_point = pos(curbp, curbp->b_egap);
add_mode(curbp, B_MODIFIED);
add_undo(curbp, UNDO_T_DELETE, curbp->b_point, the_char, NULL);
}
}
void i_gotoline()
{
int line;
if (getinput(m_goto, (char*)response_buf, STRBUF_S, F_CLEAR)) {
line = atoi(response_buf);
goto_line(line);
}
}
int goto_line(int line)
{
point_t p;
p = line_to_point(line);
if (p != -1) {
curbp->b_point = p;
msg(m_line, line);
return 1;
} else {
msg(m_lnot_found, line);
return 0;
}
}
void i_readfile()
{
if (FALSE == getfilename(str_read, (char*)response_buf, NAME_MAX))
return;
readfile(response_buf);
}
void readfile(char *fname)
{
buffer_t *bp = find_buffer_by_fname(fname);
disassociate_b(curwp); /* we are leaving the old buffer for a new one */
curbp = bp;
associate_b2w(curbp, curwp);
/* load the file if not already loaded */
if (bp != NULL && bp->b_fname[0] == '\0') {
if (!e_load_file(fname)) {
msg(m_newfile, fname);
}
safe_strncpy(curbp->b_fname, fname, NAME_MAX);
}
}
void savebuffer()
{
if (curbp->b_fname[0] != '\0') {
save_buffer(curbp, curbp->b_fname);
return;
} else {
writefile();
}
refresh();
}
char *rename_current_buffer(char *bname)
{
char bufn[NBUFN];
strcpy(bufn, bname);
make_buffer_name_uniq(bufn);
strcpy(curbp->b_bname, bufn);
return curbp->b_bname;
}
void writefile()
{
safe_strncpy(response_buf, curbp->b_fname, NAME_MAX);
if (getinput(str_write, (char*)response_buf, NAME_MAX, F_NONE)) {
if (save_buffer(curbp, response_buf) == TRUE) {
safe_strncpy(curbp->b_fname, response_buf, NAME_MAX);
// FIXME - what if name already exists, in editor
// FIXME? - do we want to change the name of the buffer when we save_as ?
make_buffer_name(curbp->b_bname, curbp->b_fname);
}
}
}
void kill_buffer()
{
buffer_t *kill_bp = curbp;
int bcount = count_buffers();
/* do nothing if only buffer left is the scratch buffer */
if (bcount == 1 && 0 == strcmp(get_buffer_name(curbp), str_scratch))
return;
if (!(curbp->b_flags & B_SPECIAL) && curbp->b_flags & B_MODIFIED) {
mvaddstr(MSGLINE, 0, str_notsaved);
clrtoeol();
if (!yesno(FALSE))
return;
}
/* create a scratch buffer */
if (bcount == 1) {
(void)find_buffer(str_scratch, TRUE);
}
next_buffer();
assert(kill_bp != curbp);
delete_buffer(kill_bp);
}
void i_set_mark()
{
set_mark();
msg(str_mark);
}
void set_mark()
{
curbp->b_mark = (curbp->b_mark == curbp->b_point ? NOMARK : curbp->b_point);
}
void unmark()
{
assert(curbp != NULL);
curbp->b_mark = NOMARK;
}
void toggle_overwrite_mode() {
if (curbp->b_flags & B_OVERWRITE)
curbp->b_flags &= ~B_OVERWRITE;
else
curbp->b_flags |= B_OVERWRITE;
}
int i_check_region()
{
if (curbp->b_mark == NOMARK) {
msg(m_nomark);
return FALSE;
}
if (curbp->b_point == curbp->b_mark) {
msg(m_noregion);
return FALSE;
}
return TRUE;
}
void copy_region() {
if (i_check_region() == FALSE) return;
copy_cut(FALSE);
}
void kill_region() {
if (i_check_region() == FALSE) return;
copy_cut(TRUE);
}
void copy_cut(int cut)
{
char_t *p;
/* if no mark or point == marker, nothing doing */
if (curbp->b_mark == NOMARK || curbp->b_point == curbp->b_mark)
return;
if (scrap != NULL) {
free(scrap);
scrap = NULL;
}
if (curbp->b_point < curbp->b_mark) {
/* point above mark: move gap under point, region = mark - point */
(void) movegap(curbp, curbp->b_point);
/* moving the gap can impact the pointer so sure get the pointer after the move */
p = ptr(curbp, curbp->b_point);
nscrap = curbp->b_mark - curbp->b_point;
} else {
/* if point below mark: move gap under mark, region = point - mark */
(void) movegap(curbp, curbp->b_mark);
/* moving the gap can impact the pointer so sure get the pointer after the move */
p = ptr(curbp, curbp->b_mark);
nscrap = curbp->b_point - curbp->b_mark;
}
if ((scrap = (char_t*) malloc(nscrap + 1)) == NULL) {
msg(m_alloc);
} else {
(void) memcpy(scrap, p, nscrap * sizeof (char_t));
*(scrap + nscrap) = '\0'; /* null terminate for insert_string */
if (cut) {
//debug("CUT: pt=%ld nscrap=%d\n", curbp->b_point, nscrap);
add_undo(curbp, UNDO_T_KILL, (curbp->b_point < curbp->b_mark ? curbp->b_point : curbp->b_mark), scrap, NULL);
curbp->b_egap += nscrap; /* if cut expand gap down */
curbp->b_point = pos(curbp, curbp->b_egap); /* set point to after region */
add_mode(curbp, B_MODIFIED);
msg(m_cut, nscrap);
} else {
msg(m_copied, nscrap);
}
unmark();
}
}
/* safe interface to clipboard so we dont pass a NULL pointer to lisp */
char *get_clipboard()
{
static char empty_string[] = "";
if (scrap == NULL) return empty_string;
return (char *)scrap;
}
unsigned char *get_scrap()
{
return scrap;
}
/*
* set the scrap pointer, a setter for external interface code
* ptr must be a pointer to a malloc'd NULL terminated string
*/
void set_scrap(unsigned char *ptr)
{
if (scrap != NULL) free(scrap);
assert(ptr != NULL);
scrap = ptr;
}
void yank()
{
insert_string((char *)scrap);
}
void insert_string(char *str)
{
int len = (str == NULL) ? 0 : strlen(str);
if (curbp->b_flags & B_OVERWRITE)
return;
if (len <= 0) {
msg(m_empty);
} else if (len < curbp->b_egap - curbp->b_gap || growgap(curbp, len)) {
curbp->b_point = movegap(curbp, curbp->b_point);
//debug("INS STR: pt=%ld len=%d\n", curbp->b_point, strlen((char *)str));
add_undo(curbp, UNDO_T_YANK, curbp->b_point, (char_t *)str, NULL);
memcpy(curbp->b_gap, str, len * sizeof (char_t));
curbp->b_gap += len;
curbp->b_point = pos(curbp, curbp->b_egap);
add_mode(curbp, B_MODIFIED);
}
}
/*
* append a string to the end of a buffer
*/
void append_string(buffer_t *bp, char *str)
{
int len = (str == NULL) ? 0 : strlen(str);
assert(bp != NULL);
if (len == 0) return;
/* goto end of buffer */
bp->b_epage = bp->b_point = pos(bp, bp->b_ebuf);
if (len < bp->b_egap - bp->b_gap || growgap(bp, len)) {
bp->b_point = movegap(bp, bp->b_point);
memcpy(bp->b_gap, str, len * sizeof (char_t));
bp->b_gap += len;
bp->b_point = pos(bp, bp->b_egap);
add_mode(curbp, B_MODIFIED);
bp->b_epage = bp->b_point = pos(bp, bp->b_ebuf); /* goto end of buffer */
/* if window is displayed mark all windows for update */
if (bp->b_cnt > 0) {
b2w_all_windows(bp);
mark_all_windows();
}
}
}
void log_debug_message(char *format, ...)
{
char buffer[256];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
log_message(buffer);
}
void log_message(char *str)
{
buffer_t *bp = find_buffer("*messages*", TRUE);
assert(bp != NULL);
append_string(bp, str);
}
void cursor_position()
{
int current, lastln;
point_t end_p = pos(curbp, curbp->b_ebuf);
get_line_stats(¤t, &lastln);
if (curbp->b_point == end_p) {
msg(str_endpos, current, lastln,
curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
} else {
msg(str_pos, unctrl(*(ptr(curbp, curbp->b_point))), *(ptr(curbp, curbp->b_point)),
current, lastln,
curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
}
}
char* get_temp_file()
{
int result = 0;
static char temp_file[] = TEMPFILE;
strcpy(temp_file, TEMPFILE);
result = mkstemp(temp_file);
if (result == -1)
{
printf("Failed to create temp file\n");
exit(1);
}
return temp_file;
}
void match_parens()
{
assert(curwp != NULL);
buffer_t *bp = curwp->w_bufp;
assert(bp != NULL);
if (buffer_is_empty(bp))
return;
char p = *ptr(bp, bp->b_point);
switch(p) {
case '{':
match_paren_forwards(bp, '{', '}');
break;
case '[':
match_paren_forwards(bp, '[', ']');
break;
case '(':
match_paren_forwards(bp, '(', ')');
break;
case '}':
match_paren_backwards(bp, '{', '}');
break;
case ']':
match_paren_backwards(bp, '[', ']');
break;
case ')':
match_paren_backwards(bp, '(', ')');
break;
default:
bp->b_paren = NOPAREN;
break;
}
}
void match_paren_forwards(buffer_t *bp, char open_paren, char close_paren)
{
int lcount = 0;
int rcount = 0;
point_t end = pos(bp, bp->b_ebuf);
point_t position = bp->b_point;
char c;
while (position <= end) {
c = *ptr(bp, position);
if (c == open_paren)
lcount++;
if (c == close_paren)
rcount++;
if (lcount == rcount && lcount > 0) {
bp->b_paren = position;
return;
}
position++;
}
bp->b_paren = NOPAREN;
}
void match_paren_backwards(buffer_t *bp, char open_paren, char close_paren)
{
int lcount = 0;
int rcount = 0;
point_t start = 0;
point_t position = bp->b_point;
char c;
while (position >= start) {
c = *ptr(bp, position);
if (c == open_paren)
lcount++;
if (c == close_paren)
rcount++;
if (lcount == rcount && lcount > 0) {
bp->b_paren = position;
return;
}
position--;
}
bp->b_paren = NOPAREN;
}
int add_mode_global(char *mode_name)
{
if (0 == strcmp(mode_name, "undo")) {
global_undo_mode = 1;
return 1;
}
return 0;
}
void version()
{
msg(m_version);
}
char *get_version_string()
{
return m_version;
}
void log_debug(char *s)
{
debug(s);
}
void resize_terminal()
{
one_window(curwp);
}
/* return char at current point */
char *get_char()
{
static char ch[2] = "\0\0";
ch[0] = (char)*(ptr(curbp, curbp->b_point));
return ch;
}
void set_point(point_t p)
{
if (p < 0 || p > pos(curbp, curbp->b_ebuf)) return;
curbp->b_point = p;
}
/* return mark in current buffer */
point_t get_mark()
{
return curbp->b_mark;
}
/* return point in current buffer */
point_t get_point()
{
return curbp->b_point;
}
/* return point in current buffer */
point_t get_point_max()
{
return pos(curbp, curbp->b_ebuf);
}
/*
* execute a lisp command typed in at the command prompt >
* send any output to the message line. This avoids text
* being sent to the current buffer which means the file
* contents could get corrupted if you are running commands
* on the buffers etc.
*
* If the output is too big for the message line then send it to
* a temp buffer called *lisp_output* and popup the window
*
*/
void repl()
{
char *output;
buffer_t *bp;
if (getinput("> ", response_buf, TEMPBUF, F_CLEAR)) {
output = call_lisp(response_buf);
if (strlen(output) < 60) {
msg(output);
} else {
bp = find_buffer("*lisp_output*", TRUE);
append_string(bp, output);
(void)popup_window(bp->b_bname);
}
}
}
/*
* evaluate a block between mark and point
*/
void eval_block()
{
char *output;
if (curbp->b_mark == NOMARK || curbp->b_mark >= curbp->b_point) {
msg("no block defined");
return;
}
copy_region();
assert(scrap != NULL);
assert(strlen((char *)scrap) > 0);
output = call_lisp((char *)scrap);
insert_string("\n");
insert_string(output);
}
/* this is called for every user key setup by a call to set_key */
void user_func()
{
char *output;
char funcname[80];
assert(key_return != NULL);
if (0 == strcmp(key_return->k_funcname, E_NOT_BOUND)) {
msg(E_NOT_BOUND);
return;
}
sprintf(funcname, "(%s)", key_return->k_funcname);
output = call_lisp(funcname);
/* show errors on message line */
if (NULL != strstr(output, "error:")) {
char buf[81];
strncpy(buf, output, 80);
buf[80] ='\0';
msg(buf);
}
}
/*
* Local Variables:
* c-file-style: "k&r"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/