source: functions.c @ f73e519

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f73e519 was f73e519, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
Added simple implementation of smartnarrow-to-admin that creates a "type-admin" autofilter. This was done mostly so that M-C-n and M-C-p do something sane on admin messages.
  • Property mode set to 100644
File size: 54.1 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <signal.h>
5#include <string.h>
6#include <com_err.h>
7#include <time.h>
8#include "owl.h"
9
10static const char fileIdent[] = "$Id$";
11
12void owl_function_noop(void) {
13  return;
14}
15
16char *owl_function_command(char *cmdbuff) {
17  owl_function_debugmsg("executing command: %s", cmdbuff);
18  return owl_cmddict_execute(owl_global_get_cmddict(&g), 
19                             owl_global_get_context(&g), cmdbuff);
20}
21
22void owl_function_command_norv(char *cmdbuff) {
23  char *rv;
24  rv = owl_function_command(cmdbuff);
25  if (rv) owl_free(rv);
26}
27
28void owl_function_command_alias(char *alias_from, char *alias_to) {
29  owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to);
30}
31
32owl_cmd *owl_function_get_cmd(char *name) {
33  return owl_cmddict_find(owl_global_get_cmddict(&g), name);
34}
35
36void owl_function_show_commands() {
37  owl_list l;
38  owl_fmtext fm;
39
40  owl_fmtext_init_null(&fm);
41  owl_fmtext_append_bold(&fm, "Commands:  ");
42  owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n");
43  owl_cmddict_get_names(owl_global_get_cmddict(&g), &l);
44  owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe);
45  owl_fmtext_append_normal(&fm, "\n");
46  owl_function_popless_fmtext(&fm);
47  owl_cmddict_namelist_free(&l);
48  owl_fmtext_free(&fm);
49}
50
51char *owl_function_cmd_describe(void *name) {
52  owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name);
53  if (cmd) return owl_cmd_describe(cmd);
54  else return(NULL);
55}
56
57void owl_function_show_command(char *name) {
58  owl_function_help_for_command(name);
59}
60
61void owl_function_adminmsg(char *header, char *body) {
62  owl_message *m;
63  int followlast;
64
65  followlast=owl_global_should_followlast(&g);
66  m=owl_malloc(sizeof(owl_message));
67  owl_message_create_admin(m, header, body);
68  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
69  owl_view_consider_message(owl_global_get_current_view(&g), m);
70
71  if (followlast) owl_function_lastmsg_noredisplay();
72
73  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
74  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
75    owl_popwin_refresh(owl_global_get_popwin(&g));
76  }
77 
78  wnoutrefresh(owl_global_get_curs_recwin(&g));
79  owl_global_set_needrefresh(&g);
80}
81
82void owl_function_adminmsg_outgoing(char *header, char *body, char *zwriteline) {
83  owl_message *m;
84  int followlast;
85 
86  followlast=owl_global_should_followlast(&g);
87  m=owl_malloc(sizeof(owl_message));
88  owl_message_create_admin(m, header, body);
89  owl_message_set_admin_outgoing(m, zwriteline);
90  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
91  owl_view_consider_message(owl_global_get_current_view(&g), m);
92
93  if (followlast) owl_function_lastmsg_noredisplay();
94
95  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
96  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
97    owl_popwin_refresh(owl_global_get_popwin(&g));
98  }
99 
100  wnoutrefresh(owl_global_get_curs_recwin(&g));
101  owl_global_set_needrefresh(&g);
102}
103
104void owl_function_zwrite_setup(char *line) {
105  owl_editwin *e;
106  char buff[1024];
107  owl_zwrite z;
108  int ret;
109
110  /* check the arguments */
111  ret=owl_zwrite_create_from_line(&z, line);
112  if (ret) {
113    owl_function_makemsg("Error in zwrite arugments");
114    owl_zwrite_free(&z);
115    return;
116  }
117
118  /* send a ping if necessary */
119  if (owl_global_is_txping(&g)) {
120    owl_zwrite_send_ping(&z);
121  }
122  owl_zwrite_free(&z);
123
124  /* create and setup the editwin */
125  e=owl_global_get_typwin(&g);
126  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
127                        owl_global_get_msg_history(&g));
128
129  if (!owl_global_get_lockout_ctrld(&g)) {
130    owl_function_makemsg("Type your zephyr below.  End with ^D or a dot on a line by itself.  ^C will quit.");
131  } else {
132    owl_function_makemsg("Type your zephyr below.  End with a dot on a line by itself.  ^C will quit.");
133  }
134
135  owl_editwin_clear(e);
136  owl_editwin_set_dotsend(e);
137  strcpy(buff, "----> ");
138  strcat(buff, line);
139  strcat(buff, "\n");
140  owl_editwin_set_locktext(e, buff);
141
142  /* make it active */
143  owl_global_set_typwin_active(&g);
144}
145
146void owl_function_zwrite(char *line) {
147  char *tmpbuff, buff[1024];
148  owl_zwrite z;
149  int i, j;
150
151  /* create the zwrite and send the message */
152  owl_zwrite_create_from_line(&z, line);
153  owl_zwrite_send_message(&z, owl_editwin_get_text(owl_global_get_typwin(&g)));
154  owl_function_makemsg("Waiting for ack...");
155
156  /* display the message as an admin message in the receive window */
157  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
158    owl_zwrite_get_recipstr(&z, buff);
159    tmpbuff = owl_sprintf("Message sent to %s", buff);
160    owl_function_adminmsg_outgoing(tmpbuff, owl_editwin_get_text(owl_global_get_typwin(&g)), line);
161    owl_free(tmpbuff);
162  }
163
164  /* log it if we have logging turned on */
165  if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
166    j=owl_zwrite_get_numrecips(&z);
167    for (i=0; i<j; i++) {
168      owl_log_outgoing(owl_zwrite_get_recip_n(&z, i),
169                       owl_editwin_get_text(owl_global_get_typwin(&g)));
170    }
171  }
172
173  /* free the zwrite */
174  owl_zwrite_free(&z);
175}
176
177
178/* If filter is non-null, looks for the next message matching
179 * that filter.  If skip_deleted, skips any deleted messages.
180 * If last_if_none, will stop at the last message in the view
181 * if no matching messages are found.  */
182void owl_function_nextmsg_full(char *filter, int skip_deleted, int last_if_none) {
183  int curmsg, i, viewsize, found;
184  owl_view *v;
185  owl_filter *f = NULL;
186  owl_message *m;
187
188  v=owl_global_get_current_view(&g);
189
190  if (filter) {
191    f=owl_global_get_filter(&g, filter);
192    if (!f) {
193      owl_function_makemsg("No %s filter defined", filter);
194      return;
195    }
196  }
197
198  curmsg=owl_global_get_curmsg(&g);
199  viewsize=owl_view_get_size(v);
200  found=0;
201
202  /* just check to make sure we're in bounds... */
203  if (curmsg>viewsize-1) curmsg=viewsize-1;
204  if (curmsg<0) curmsg=0;
205
206  for (i=curmsg+1; i<viewsize; i++) {
207    m=owl_view_get_element(v, i);
208    if (skip_deleted && owl_message_is_delete(m)) continue;
209    if (f && !owl_filter_message_match(f, m)) continue;
210    found = 1;
211    break;
212  }
213
214  if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1;
215
216  if (!found) {
217    owl_function_makemsg("already at last%s message%s%s",
218                         skip_deleted?" non-deleted":"",
219                         filter?" in ":"", filter?filter:"");
220    if (!skip_deleted) owl_function_beep();
221  }
222
223  if (last_if_none || found) {
224    owl_global_set_curmsg(&g, i);
225    owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
226    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
227    owl_global_set_direction_downwards(&g);
228  }
229}
230
231void owl_function_prevmsg_full(char *filter, int skip_deleted, int first_if_none) {
232  int curmsg, i, viewsize, found;
233  owl_view *v;
234  owl_filter *f = NULL;
235  owl_message *m;
236
237  v=owl_global_get_current_view(&g);
238
239  if (filter) {
240    f=owl_global_get_filter(&g, filter);
241    if (!f) {
242      owl_function_makemsg("No %s filter defined", filter);
243      return;
244    }
245  }
246
247  curmsg=owl_global_get_curmsg(&g);
248  viewsize=owl_view_get_size(v);
249  found=0;
250
251  /* just check to make sure we're in bounds... */
252  if (curmsg>viewsize-1) curmsg=viewsize-1;
253  if (curmsg<0) curmsg=0;
254
255  for (i=curmsg-1; i>=0; i--) {
256    m=owl_view_get_element(v, i);
257    if (skip_deleted && owl_message_is_delete(m)) continue;
258    if (f && !owl_filter_message_match(f, m)) continue;
259    found = 1;
260    break;
261  }
262
263  if (i<0) i=0;
264
265  if (!found) {
266    owl_function_makemsg("already at first%s message%s%s",
267                         skip_deleted?" non-deleted":"",
268                         filter?" in ":"", filter?filter:"");
269    if (!skip_deleted) owl_function_beep();
270  }
271
272  if (first_if_none || found) {
273    owl_global_set_curmsg(&g, i);
274    owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS);
275    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
276    owl_global_set_direction_upwards(&g);
277  }
278}
279
280void owl_function_nextmsg() {
281  owl_function_nextmsg_full(NULL, 0, 1);
282}
283
284
285void owl_function_prevmsg() {
286  owl_function_prevmsg_full(NULL, 0, 1);
287}
288
289void owl_function_nextmsg_notdeleted() {
290  owl_function_nextmsg_full(NULL, 1, 1);
291}
292
293
294void owl_function_prevmsg_notdeleted() {
295  owl_function_prevmsg_full(NULL, 1, 1);
296}
297
298
299void owl_function_nextmsg_personal() {
300  owl_function_nextmsg_full("personal", 0, 0);
301}
302
303void owl_function_prevmsg_personal() {
304  owl_function_prevmsg_full("personal", 0, 0);
305}
306
307
308/* if move_after is 1, moves after the delete */
309void owl_function_deletecur(int move_after) {
310  int curmsg;
311  owl_view *v;
312
313  v=owl_global_get_current_view(&g);
314
315  /* bail if there's no current message */
316  if (owl_view_get_size(v) < 1) {
317    owl_function_makemsg("No current message to delete");
318    return;
319  }
320
321  /* mark the message for deletion */
322  curmsg=owl_global_get_curmsg(&g);
323  owl_view_delete_element(v, curmsg);
324
325  if (move_after) {
326    /* move the poiner in the appropriate direction
327     * to the next undeleted msg */
328    if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
329      owl_function_prevmsg_notdeleted();
330    } else {
331      owl_function_nextmsg_notdeleted();
332    }
333  }
334}
335
336
337void owl_function_undeletecur(int move_after) {
338  int curmsg;
339  owl_view *v;
340
341  v=owl_global_get_current_view(&g);
342 
343  if (owl_view_get_size(v) < 1) {
344    owl_function_makemsg("No current message to undelete");
345    return;
346  }
347  curmsg=owl_global_get_curmsg(&g);
348
349  owl_view_undelete_element(v, curmsg);
350
351  if (move_after) {
352    if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
353      if (curmsg>0) {
354        owl_function_prevmsg();
355      } else {
356        owl_function_nextmsg();
357      }
358    } else {
359      owl_function_nextmsg();
360    }
361  }
362
363  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
364}
365
366
367void owl_function_expunge() {
368  int curmsg;
369  owl_message *m;
370  owl_messagelist *ml;
371  owl_view *v;
372  int i, j;
373
374  curmsg=owl_global_get_curmsg(&g);
375  v=owl_global_get_current_view(&g);
376  ml=owl_global_get_msglist(&g);
377
378  /* first try to move to an undeleted message in the view*/
379  m=owl_view_get_element(v, curmsg);
380  if (owl_message_is_delete(m)) {
381    /* try to find the next undeleted message */
382    j=owl_view_get_size(v);
383    for (i=curmsg; i<j; i++) {
384      if (!owl_message_is_delete(owl_view_get_element(v, i))) {
385        owl_global_set_curmsg(&g, i);
386        break;
387      }
388    }
389
390    /* if we weren't successful try to find one backwards */
391    curmsg=owl_global_get_curmsg(&g);
392    if (owl_message_is_delete(owl_view_get_element(v, curmsg))) {
393      for (i=curmsg; i>0; i--) {
394        if (!owl_message_is_delete(owl_view_get_element(v, i))) {
395          owl_global_set_curmsg(&g, i);
396          break;
397        }
398      }
399    }
400  }
401
402  /* expunge the message list */
403  owl_messagelist_expunge(ml);
404
405  /* update all views (we only have one right now) */
406  owl_view_recalculate(v);
407
408  if (curmsg>owl_view_get_size(v)-1) {
409    owl_global_set_curmsg(&g, owl_view_get_size(v)-1);
410    if (owl_global_get_curmsg(&g)<0) {
411      owl_global_set_curmsg(&g, 0);
412    }
413    owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
414  }
415
416  /* if there are no messages set the direction to down in case we
417     delete everything upwards */
418  owl_global_set_direction_downwards(&g);
419 
420  owl_function_makemsg("Messages expunged");
421  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
422}
423
424
425void owl_function_firstmsg() {
426  owl_global_set_curmsg(&g, 0);
427  owl_global_set_topmsg(&g, 0);
428  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
429  owl_global_set_direction_downwards(&g);
430}
431
432void owl_function_lastmsg_noredisplay() {
433  int curmsg;
434  owl_view *v;
435
436  v=owl_global_get_current_view(&g);
437 
438  curmsg=owl_view_get_size(v)-1;
439  if (curmsg<0) curmsg=0;
440  owl_global_set_curmsg(&g, curmsg);
441  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
442  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
443  owl_global_set_direction_downwards(&g);
444}
445
446void owl_function_lastmsg() {
447  owl_function_lastmsg_noredisplay();
448  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
449}
450
451void owl_function_shift_right() {
452  owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10);
453  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
454  owl_global_set_needrefresh(&g);
455}
456
457
458void owl_function_shift_left() {
459  int shift;
460
461  shift=owl_global_get_rightshift(&g);
462  if (shift>=10) {
463    owl_global_set_rightshift(&g, shift-10);
464    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
465    owl_global_set_needrefresh(&g);
466  } else {
467    owl_function_beep();
468    owl_function_makemsg("Already full left");
469  }
470}
471
472
473void owl_function_unsuball() {
474  unsuball();
475  owl_function_makemsg("Unsubscribed from all messages.");
476}
477
478void owl_function_loadsubs(char *file) {
479  int ret;
480  ret=owl_zephyr_loadsubs(file);
481  if (ret==0) {
482    owl_function_makemsg("Subscribed to messages from file.");
483  } else if (ret==-1) {
484    owl_function_makemsg("Could not open file.");
485  } else {
486    owl_function_makemsg("Error subscribing to messages from file.");
487  }
488}
489
490void owl_function_suspend() {
491  endwin();
492  printf("\n");
493  kill(getpid(), SIGSTOP);
494
495  /* resize to reinitialize all the windows when we come back */
496  owl_command_resize();
497}
498
499void owl_function_zaway_toggle() {
500  if (!owl_global_is_zaway(&g)) {
501    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
502    owl_function_zaway_on();
503  } else {
504    owl_function_zaway_off();
505  }
506}
507
508void owl_function_zaway_on() {
509  owl_global_set_zaway_on(&g);
510  owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g));
511}
512
513void owl_function_zaway_off() {
514  owl_global_set_zaway_off(&g);
515  owl_function_makemsg("zaway off");
516}
517
518void owl_function_quit() {
519  char *ret;
520 
521  /* zlog out if we need to */
522  if (owl_global_is_shutdownlogout(&g)) {
523    owl_function_zlog_out();
524  }
525
526  /* execute the commands in shutdown */
527  ret = owl_config_execute("owl::shutdown();");
528  if (ret) owl_free(ret);
529
530  /* final clean up */
531  unsuball();
532  ZClosePort();
533  endwin();
534  owl_function_debugmsg("Quitting Owl");
535  exit(0);
536}
537
538
539void owl_function_zlog_in() {
540  char *exposure, *eset;
541  int ret;
542
543  eset=EXPOSE_REALMVIS;
544  exposure=ZGetVariable("exposure");
545  if (exposure==NULL) {
546    eset=EXPOSE_REALMVIS;
547  } else if (!strcasecmp(exposure,EXPOSE_NONE)) {
548    eset = EXPOSE_NONE;
549  } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) {
550    eset = EXPOSE_OPSTAFF;
551  } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) {
552    eset = EXPOSE_REALMVIS;
553  } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) {
554    eset = EXPOSE_REALMANN;
555  } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) {
556    eset = EXPOSE_NETVIS;
557  } else if (!strcasecmp(exposure,EXPOSE_NETANN)) {
558    eset = EXPOSE_NETANN;
559  }
560   
561  ret=ZSetLocation(eset);
562  if (ret != ZERR_NONE) {
563    /*
564      char buff[LINE];
565      sprintf(buff, "Error setting location: %s", error_message(ret));
566      owl_function_makemsg(buff);
567    */
568  }
569}
570
571void owl_function_zlog_out() {
572  int ret;
573 
574  ret=ZUnsetLocation();
575  if (ret != ZERR_NONE) {
576    /*
577      char buff[LINE];
578      sprintf(buff, "Error unsetting location: %s", error_message(ret));
579      owl_function_makemsg(buff);
580    */
581  }
582}
583
584
585void owl_function_makemsg(char *fmt, ...) {
586  va_list ap;
587  char buff[2048];
588
589  va_start(ap, fmt);
590  werase(owl_global_get_curs_msgwin(&g));
591 
592  vsnprintf(buff, 2048, fmt, ap);
593  owl_function_debugmsg("makemsg: %s", buff);
594  waddstr(owl_global_get_curs_msgwin(&g), buff); 
595  wnoutrefresh(owl_global_get_curs_msgwin(&g));
596  owl_global_set_needrefresh(&g);
597  va_end(ap);
598}
599
600void owl_function_errormsg(char *fmt, ...) {
601  va_list ap;
602  char buff[2048];
603
604  va_start(ap, fmt);
605  werase(owl_global_get_curs_msgwin(&g));
606 
607  vsnprintf(buff, 2048, fmt, ap);
608  owl_function_debugmsg("ERROR: %s", buff);
609  waddstr(owl_global_get_curs_msgwin(&g), buff); 
610  waddstr(owl_global_get_curs_msgwin(&g), "ERROR: "); 
611  wnoutrefresh(owl_global_get_curs_msgwin(&g));
612  owl_global_set_needrefresh(&g);
613  va_end(ap);
614}
615
616
617void owl_function_openurl() {
618  /* visit the first url in the current message */
619  owl_message *m;
620  owl_view *v;
621  char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
622  int webbrowser;
623
624  webbrowser = owl_global_get_webbrowser(&g);
625
626  if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
627    owl_function_makemsg("No browser selected");
628    return;
629  }
630
631  v=owl_global_get_current_view(&g);
632 
633  if (owl_view_get_size(v)==0) {
634    owl_function_makemsg("No current message selected");
635    return;
636  }
637
638  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
639  text=owl_message_get_text(m);
640
641  /* First look for a good URL */ 
642  if ((ptr1=strstr(text, "http://"))!=NULL) {
643    ptr2=strpbrk(ptr1, " \n\t");
644    if (ptr2) {
645      strncpy(url, ptr1, ptr2-ptr1+1);
646      url[ptr2-ptr1+1]='\0';
647    } else {
648      strcpy(url, ptr1);
649    }
650
651    /* if we had <http strip a trailing > */
652    if (ptr1>text && ptr1[-1]=='<') {
653      if (url[strlen(url)-1]=='>') {
654        url[strlen(url)-1]='\0';
655      }
656    }
657  } else if ((ptr1=strstr(text, "https://"))!=NULL) {
658    /* Look for an https URL */ 
659    ptr2=strpbrk(ptr1, " \n\t");
660    if (ptr2) {
661      strncpy(url, ptr1, ptr2-ptr1+1);
662      url[ptr2-ptr1+1]='\0';
663    } else {
664      strcpy(url, ptr1);
665    }
666   
667    /* if we had <http strip a trailing > */
668    if (ptr1>text && ptr1[-1]=='<') {
669      if (url[strlen(url)-1]=='>') {
670        url[strlen(url)-1]='\0';
671      }
672    }
673  } else if ((ptr1=strstr(text, "www."))!=NULL) {
674    /* if we can't find a real url look for www.something */
675    ptr2=strpbrk(ptr1, " \n\t");
676    if (ptr2) {
677      strncpy(url, ptr1, ptr2-ptr1+1);
678      url[ptr2-ptr1+1]='\0';
679    } else {
680      strcpy(url, ptr1);
681    }
682  } else {
683    owl_function_beep();
684    owl_function_makemsg("Could not find URL to open.");
685    return;
686  }
687
688  /* Make sure there aren't any quotes or \'s in the url */
689  for (ptr1 = url; *ptr1; ptr1++) {
690    if (*ptr1 == '"' || *ptr1 == '\\') {
691      owl_function_beep();
692      owl_function_makemsg("URL contains invalid characters.");
693      return;
694    }
695  }
696 
697  /* NOTE: There are potentially serious security issues here... */
698
699  /* open the page */
700  owl_function_makemsg("Opening %s", url);
701  if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {
702    snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);
703    system(tmpbuff); 
704  } else if (webbrowser == OWL_WEBBROWSER_GALEON) {
705    snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);
706    system(tmpbuff); 
707  }
708}
709
710void owl_function_calculate_topmsg(int direction) {
711  int recwinlines, y, savey, i, j, topmsg, curmsg, foo;
712  owl_mainwin *mw;
713  owl_view *v;
714
715  mw=owl_global_get_mainwin(&g);
716
717  topmsg=owl_global_get_topmsg(&g);
718  curmsg=owl_global_get_curmsg(&g);
719  v=owl_global_get_current_view(&g);
720  recwinlines=owl_global_get_recwin_lines(&g);
721
722  if (owl_view_get_size(v) < 1) {
723    return;
724  }
725 
726  /* Find number of lines from top to bottom of curmsg (store in savey) */
727  savey=0;
728  for (i=topmsg; i<=curmsg; i++) {
729    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
730  }
731
732  /* If the direction is DOWNWARDS but we're off the bottom of the
733   *  screen, then set the topmsg to curmsg and scroll UPWARDS
734   */
735  if (direction == OWL_DIRECTION_DOWNWARDS) {
736    if (savey > recwinlines) {
737      topmsg=curmsg;
738      savey=owl_message_get_numlines(owl_view_get_element(v, i));
739      direction=OWL_DIRECTION_UPWARDS;
740    }
741  }
742
743  /* If our bottom line is less than 1/4 down the screen then scroll up */
744  if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) {
745    if (savey < (recwinlines / 4)) {
746      y=0;
747      for (j=curmsg; j>=0; j--) {
748        foo=owl_message_get_numlines(owl_view_get_element(v, j));
749        /* will we run the curmsg off the screen? */
750        if ((foo+y) >= recwinlines) {
751          j++;
752          if (j>curmsg) j=curmsg;
753          break;
754        }
755        /* have saved 1/2 the screen space? */
756        y+=foo;
757        if (y > (recwinlines / 2)) break;
758      }
759      if (j<0) j=0;
760      owl_global_set_topmsg(&g, j);
761      return;
762    }
763  }
764
765  if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) {
766    /* If curmsg bottom line is more than 3/4 down the screen then scroll down */
767    if (savey > ((recwinlines * 3)/4)) {
768      y=0;
769      /* count lines from the top until we can save 1/2 the screen size */
770      for (j=topmsg; j<curmsg; j++) {
771        y+=owl_message_get_numlines(owl_view_get_element(v, j));
772        if (y > (recwinlines / 2)) break;
773      }
774      if (j==curmsg) {
775        j--;
776      }
777      owl_global_set_topmsg(&g, j+1);
778      return;
779    }
780  }
781}
782
783
784void owl_function_resize() {
785  owl_global_set_resize_pending(&g);
786}
787
788
789void owl_function_run_buffercommand() {
790  char *buff;
791
792  buff=owl_global_get_buffercommand(&g);
793  if (!strncmp(buff, "zwrite ", 7)) {
794
795    owl_function_zwrite(buff);
796  }
797}
798
799void owl_function_debugmsg(char *fmt, ...) {
800  FILE *file;
801  time_t now;
802  char buff1[LINE], buff2[LINE];
803  va_list ap;
804  va_start(ap, fmt);
805
806  if (!owl_global_is_debug_fast(&g)) return;
807
808  file=fopen(owl_global_get_debug_file(&g), "a");
809  if (!file) return;
810
811  now=time(NULL);
812  strcpy(buff1, ctime(&now));
813  buff1[strlen(buff1)-1]='\0';
814
815  owl_global_get_runtime_string(&g, buff2);
816 
817  fprintf(file, "[%i -  %s - %s]: ", (int) getpid(), buff1, buff2);
818  vfprintf(file, fmt, ap);
819  fprintf(file, "\n");
820  fclose(file);
821
822  va_end(ap);
823}
824
825
826void owl_function_refresh() {
827  owl_function_resize();
828}
829
830void owl_function_beep() {
831  if (owl_global_is_bell(&g)) {
832    beep();
833  }
834}
835
836
837void owl_function_subscribe(char *class, char *inst, char *recip) {
838  int ret;
839
840  ret=owl_zephyr_sub(class, inst, recip);
841  if (ret) {
842    owl_function_makemsg("Error subscribing.");
843  } else {
844    owl_function_makemsg("Subscribed.");
845  }
846}
847
848
849void owl_function_unsubscribe(char *class, char *inst, char *recip) {
850  int ret;
851
852  ret=owl_zephyr_unsub(class, inst, recip);
853  if (ret) {
854    owl_function_makemsg("Error subscribing.");
855  } else {
856    owl_function_makemsg("Unsubscribed.");
857  }
858}
859
860
861void owl_function_set_cursor(WINDOW *win) {
862  wnoutrefresh(win);
863}
864
865
866void owl_function_full_redisplay() {
867  redrawwin(owl_global_get_curs_recwin(&g));
868  redrawwin(owl_global_get_curs_sepwin(&g));
869  redrawwin(owl_global_get_curs_typwin(&g));
870  redrawwin(owl_global_get_curs_msgwin(&g));
871
872  wnoutrefresh(owl_global_get_curs_recwin(&g));
873  wnoutrefresh(owl_global_get_curs_sepwin(&g));
874  wnoutrefresh(owl_global_get_curs_typwin(&g));
875  wnoutrefresh(owl_global_get_curs_msgwin(&g));
876 
877  sepbar("");
878  owl_function_makemsg("");
879
880  owl_global_set_needrefresh(&g);
881}
882
883
884void owl_function_popless_text(char *text) {
885  owl_popwin *pw;
886  owl_viewwin *v;
887
888  pw=owl_global_get_popwin(&g);
889  v=owl_global_get_viewwin(&g);
890
891  owl_popwin_up(pw);
892  owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
893                        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
894                        text);
895  owl_popwin_refresh(pw);
896  owl_viewwin_redisplay(v, 0);
897  owl_global_set_needrefresh(&g);
898}
899
900
901void owl_function_popless_fmtext(owl_fmtext *fm) {
902  owl_popwin *pw;
903  owl_viewwin *v;
904
905  pw=owl_global_get_popwin(&g);
906  v=owl_global_get_viewwin(&g);
907
908  owl_popwin_up(pw);
909  owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
910                   owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
911                   fm);
912  owl_popwin_refresh(pw);
913  owl_viewwin_redisplay(v, 0);
914  owl_global_set_needrefresh(&g);
915}
916
917void owl_function_about() {
918  char buff[5000];
919
920  sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING);
921  strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n");
922  strcat(buff, "Institute of Technology.  The first version, 0.5, was\n");
923  strcat(buff, "released in March 2002\n");
924  strcat(buff, "\n");
925  strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n");
926  strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n");
927  strcat(buff, "between Witches and Wizards.\n");
928  strcat(buff, "\n");
929  strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n");
930  strcat(buff, "\n");
931  strcat(buff, "Permission to use, copy, modify, and distribute this\n");
932  strcat(buff, "software and its documentation for any purpose and without\n");
933  strcat(buff, "fee is hereby granted, provided that the above copyright\n");
934  strcat(buff, "notice and this permission notice appear in all copies\n");
935  strcat(buff, "and in supporting documentation.  No representation is\n");
936  strcat(buff, "made about the suitability of this software for any\n");
937  strcat(buff, "purpose.  It is provided \"as is\" without express\n");
938  strcat(buff, "or implied warranty.\n");
939  owl_function_popless_text(buff);
940}
941
942void owl_function_info() {
943  owl_message *m;
944  ZNotice_t *n;
945  char buff[2048], tmpbuff[1024];
946  char *ptr;
947  int i, j, fields, len;
948  owl_view *v;
949
950  v=owl_global_get_current_view(&g);
951 
952  if (owl_view_get_size(v)==0) {
953    owl_function_makemsg("No message selected\n");
954    return;
955  }
956
957  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
958  if (!owl_message_is_zephyr(m)) {
959    sprintf(buff,   "Owl Message Id: %i\n", owl_message_get_id(m));
960    sprintf(buff, "%sTime          : %s\n", buff, owl_message_get_timestr(m));
961    owl_function_popless_text(buff);
962    return;
963  }
964
965  n=owl_message_get_notice(m);
966
967  sprintf(buff,   "Owl Msg ID: %i\n", owl_message_get_id(m));
968  sprintf(buff, "%sClass     : %s\n", buff, n->z_class);
969  sprintf(buff, "%sInstance  : %s\n", buff, n->z_class_inst);
970  sprintf(buff, "%sSender    : %s\n", buff, n->z_sender);
971  sprintf(buff, "%sRecip     : %s\n", buff, n->z_recipient);
972  sprintf(buff, "%sOpcode    : %s\n", buff, n->z_opcode);
973  strcat(buff,    "Kind      : ");
974  if (n->z_kind==UNSAFE) {
975    strcat(buff, "UNSAFE\n");
976  } else if (n->z_kind==UNACKED) {
977    strcat(buff, "UNACKED\n");
978  } else if (n->z_kind==ACKED) {
979    strcat(buff, "ACKED\n");
980  } else if (n->z_kind==HMACK) {
981    strcat(buff, "HMACK\n");
982  } else if (n->z_kind==HMCTL) {
983    strcat(buff, "HMCTL\n");
984  } else if (n->z_kind==SERVACK) {
985    strcat(buff, "SERVACK\n");
986  } else if (n->z_kind==SERVNAK) {
987    strcat(buff, "SERVNAK\n");
988  } else if (n->z_kind==CLIENTACK) {
989    strcat(buff, "CLIENTACK\n");
990  } else if (n->z_kind==STAT) {
991    strcat(buff, "STAT\n");
992  } else {
993    strcat(buff, "ILLEGAL VALUE\n");
994  }
995  sprintf(buff, "%sTime      : %s\n", buff, owl_message_get_timestr(m));
996  sprintf(buff, "%sHost      : %s\n", buff, owl_message_get_hostname(m));
997  sprintf(buff, "%sPort      : %i\n", buff, n->z_port);
998  strcat(buff,    "Auth      : ");
999  if (n->z_auth == ZAUTH_FAILED) {
1000    strcat(buff, "FAILED\n");
1001  } else if (n->z_auth == ZAUTH_NO) {
1002    strcat(buff, "NO\n");
1003  } else if (n->z_auth == ZAUTH_YES) {
1004    strcat(buff, "YES\n");
1005  } else {
1006    sprintf(buff, "%sUnknown State (%i)\n", buff, n->z_auth);
1007  }
1008  sprintf(buff, "%sCheckd Ath: %i\n", buff, n->z_checked_auth);
1009  sprintf(buff, "%sMulti notc: %s\n", buff, n->z_multinotice);
1010  sprintf(buff, "%sNum other : %i\n", buff, n->z_num_other_fields);
1011  sprintf(buff, "%sMsg Len   : %i\n", buff, n->z_message_len);
1012
1013  sprintf(buff, "%sFields    : %i\n", buff, owl_zephyr_get_num_fields(n));
1014
1015  fields=owl_zephyr_get_num_fields(n);
1016  for (i=0; i<fields; i++) {
1017    sprintf(buff, "%sField %i   : ", buff, i+1);
1018
1019    ptr=owl_zephyr_get_field(n, i+1, &len);
1020    if (!ptr) break;
1021    if (len<30) {
1022      strncpy(tmpbuff, ptr, len);
1023      tmpbuff[len]='\0';
1024    } else {
1025      strncpy(tmpbuff, ptr, 30);
1026      tmpbuff[30]='\0';
1027      strcat(tmpbuff, "...");
1028    }
1029
1030    /* just for testing for now */
1031    for (j=0; j<strlen(tmpbuff); j++) {
1032      if (tmpbuff[j]=='\n') tmpbuff[j]='~';
1033      if (tmpbuff[j]=='\r') tmpbuff[j]='!';
1034    }
1035
1036    strcat(buff, tmpbuff);
1037    strcat(buff, "\n");
1038  }
1039  sprintf(buff, "%sDefault Fm: %s\n", buff, n->z_default_format);
1040       
1041  owl_function_popless_text(buff);
1042}
1043
1044
1045void owl_function_curmsg_to_popwin() {
1046  owl_popwin *pw;
1047  owl_view *v;
1048  owl_message *m;
1049
1050  v = owl_global_get_current_view(&g);
1051
1052  pw=owl_global_get_popwin(&g);
1053
1054  if (owl_view_get_size(v)==0) {
1055    owl_function_makemsg("No current message");
1056    return;
1057  }
1058
1059  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1060  owl_function_popless_fmtext(owl_message_get_fmtext(m));
1061}
1062
1063
1064void owl_function_page_curmsg(int step) {
1065  /* scroll down or up within the current message IF the message is truncated */
1066
1067  int offset, curmsg, lines;
1068  owl_view *v;
1069  owl_message *m;
1070
1071  offset=owl_global_get_curmsg_vert_offset(&g);
1072  v=owl_global_get_current_view(&g);
1073  if (owl_view_get_size(v)==0) return;
1074  curmsg=owl_global_get_curmsg(&g);
1075  m=owl_view_get_element(v, curmsg);
1076  lines=owl_message_get_numlines(m);
1077
1078  if (offset==0) {
1079    /* Bail if the curmsg isn't the last one displayed */
1080    if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) {
1081      owl_function_makemsg("The entire message is already displayed");
1082      return;
1083    }
1084   
1085    /* Bail if we're not truncated */
1086    if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
1087      owl_function_makemsg("The entire message is already displayed");
1088      return;
1089    }
1090  }
1091 
1092 
1093  /* don't scroll past the last line */
1094  if (step>0) {
1095    if (offset+step > lines-1) {
1096      owl_global_set_curmsg_vert_offset(&g, lines-1);
1097    } else {
1098      owl_global_set_curmsg_vert_offset(&g, offset+step);
1099    }
1100  }
1101
1102  /* would we be before the beginning of the message? */
1103  if (step<0) {
1104    if (offset+step<0) {
1105      owl_global_set_curmsg_vert_offset(&g, 0);
1106    } else {
1107      owl_global_set_curmsg_vert_offset(&g, offset+step);
1108    }
1109  }
1110 
1111  /* redisplay */
1112  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1113  owl_global_set_needrefresh(&g);
1114}
1115
1116void owl_function_resize_typwin(int newsize) {
1117  owl_global_set_typwin_lines(&g, newsize);
1118  owl_function_resize();
1119}
1120
1121void owl_function_typwin_grow() {
1122  int i;
1123
1124  i=owl_global_get_typwin_lines(&g);
1125  owl_function_resize_typwin(i+1);
1126}
1127
1128void owl_function_typwin_shrink() {
1129  int i;
1130
1131  i=owl_global_get_typwin_lines(&g);
1132  if (i>2) {
1133    owl_function_resize_typwin(i-1);
1134  }
1135}
1136
1137void owl_function_mainwin_pagedown() {
1138  int i;
1139
1140  i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g));
1141  if (i<0) return;
1142
1143  owl_global_set_curmsg(&g, i);
1144  owl_function_nextmsg();
1145}
1146
1147void owl_function_mainwin_pageup() {
1148  owl_global_set_curmsg(&g, owl_global_get_topmsg(&g));
1149  owl_function_prevmsg();
1150}
1151
1152void owl_function_getsubs() {
1153  int ret, num, i, one;
1154  ZSubscription_t sub;
1155  char *buff;
1156
1157  one = 1;
1158
1159  ret=ZRetrieveSubscriptions(0, &num);
1160  if (ret == ZERR_TOOMANYSUBS) {
1161
1162  }
1163
1164  buff=owl_malloc(num*200);
1165  strcpy(buff, "");
1166  for (i=0; i<num; i++) {
1167    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
1168      /* deal with error */
1169    } else {
1170      sprintf(buff, "%s<%s,%s,%s>\n", buff, sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient);
1171    }
1172  }
1173
1174  owl_function_popless_text(buff);
1175  owl_free(buff);
1176  ZFlushSubscriptions();
1177}
1178
1179#define PABUFLEN 5000
1180void owl_function_printallvars() {
1181  char buff[PABUFLEN], *pos, *name;
1182  owl_list varnames;
1183  int i, numvarnames, rem;
1184
1185  pos = buff;
1186  pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");
1187  pos += sprintf(pos, "%-20s   %s\n",  "--------", "-----");
1188  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1189  rem = (buff+PABUFLEN)-pos-1;
1190  numvarnames = owl_list_get_size(&varnames);
1191  for (i=0; i<numvarnames; i++) {
1192    name = owl_list_get_element(&varnames, i);
1193    if (name && name[0]!='_') {
1194      rem = (buff+PABUFLEN)-pos-1;   
1195      pos += snprintf(pos, rem, "\n%-20s = ", name);
1196      rem = (buff+PABUFLEN)-pos-1;   
1197      owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem);
1198      pos = buff+strlen(buff);
1199    }
1200  }
1201  rem = (buff+PABUFLEN)-pos-1;   
1202  snprintf(pos, rem, "\n");
1203  owl_variable_dict_namelist_free(&varnames);
1204 
1205  owl_function_popless_text(buff);
1206}
1207
1208void owl_function_show_variables() {
1209  owl_list varnames;
1210  owl_fmtext fm; 
1211  int i, numvarnames;
1212  char *varname;
1213
1214  owl_fmtext_init_null(&fm);
1215  owl_fmtext_append_bold(&fm, 
1216      "Variables: (use 'show variable <name>' for details)\n");
1217  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1218  owl_variable_get_summaryheader(&fm);
1219  numvarnames = owl_list_get_size(&varnames);
1220  for (i=0; i<numvarnames; i++) {
1221    varname = owl_list_get_element(&varnames, i);
1222    if (varname && varname[0]!='_') {
1223      owl_variable_get_summary(owl_global_get_vardict(&g), varname, &fm);
1224    }
1225  }
1226  owl_variable_dict_namelist_free(&varnames);
1227  owl_function_popless_fmtext(&fm);
1228  owl_fmtext_free(&fm);
1229}
1230
1231void owl_function_show_variable(char *name) {
1232  owl_fmtext fm; 
1233
1234  owl_fmtext_init_null(&fm);
1235  owl_variable_get_help(owl_global_get_vardict(&g), name, &fm);
1236  owl_function_popless_fmtext(&fm);
1237  owl_fmtext_free(&fm); 
1238}
1239
1240/* note: this applies to global message list, not to view.
1241 * If flag is 1, deletes.  If flag is 0, undeletes. */
1242void owl_function_delete_by_id(int id, int flag) {
1243  owl_messagelist *ml;
1244  owl_message *m;
1245  ml = owl_global_get_msglist(&g);
1246  m = owl_messagelist_get_by_id(ml, id);
1247  if (m) {
1248    if (flag == 1) {
1249      owl_message_mark_delete(m);
1250    } else if (flag == 0) {
1251      owl_message_unmark_delete(m);
1252    }
1253    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1254    owl_global_set_needrefresh(&g);
1255  } else {
1256    owl_function_makemsg("No message with id %d: unable to mark for (un)delete",id);
1257  }
1258}
1259
1260void owl_function_delete_automsgs() {
1261  /* mark for deletion all messages in the current view that match the
1262   * 'trash' filter */
1263
1264  int i, j, count;
1265  owl_message *m;
1266  owl_view *v;
1267  owl_filter *f;
1268
1269  /* get the trash filter */
1270  f=owl_global_get_filter(&g, "trash");
1271  if (!f) {
1272    owl_function_makemsg("No trash filter defined");
1273    return;
1274  }
1275
1276  v=owl_global_get_current_view(&g);
1277
1278  count=0;
1279  j=owl_view_get_size(v);
1280  for (i=0; i<j; i++) {
1281    m=owl_view_get_element(v, i);
1282    if (owl_filter_message_match(f, m)) {
1283      count++;
1284      owl_message_mark_delete(m);
1285    }
1286  }
1287  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1288  owl_function_makemsg("%i messages marked for deletion", count);
1289  owl_global_set_needrefresh(&g);
1290}
1291
1292
1293void owl_function_status() {
1294  char buff[5000];
1295  time_t start;
1296  int up, days, hours, minutes;
1297
1298  start=owl_global_get_starttime(&g);
1299
1300  sprintf(buff, "Version: %s\n", OWL_VERSION_STRING);
1301  sprintf(buff, "%sScreen size: %i lines, %i columns\n", buff, owl_global_get_lines(&g), owl_global_get_cols(&g));
1302  sprintf(buff, "%sStartup Arugments: %s\n", buff, owl_global_get_startupargs(&g));
1303  sprintf(buff, "%sStartup Time: %s", buff, ctime(&start));
1304
1305  up=owl_global_get_runtime(&g);
1306  days=up/86400;
1307  up-=days*86400;
1308  hours=up/3600;
1309  up-=hours*3600;
1310  minutes=up/60;
1311  up-=minutes*60;
1312  sprintf(buff, "%sRun Time: %i days %2.2i:%2.2i:%2.2i\n", buff, days, hours, minutes, up);
1313
1314  if (owl_global_get_hascolors(&g)) {
1315    sprintf(buff, "%sColor: Yes, %i color pairs.\n", buff, owl_global_get_colorpairs(&g));
1316  } else {
1317    strcat(buff, "Color: No.\n");
1318  }
1319 
1320  owl_function_popless_text(buff);
1321}
1322
1323void owl_function_show_term() {
1324  owl_fmtext fm;
1325  char buff[LINE];
1326
1327  owl_fmtext_init_null(&fm);
1328  sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",
1329          owl_global_get_lines(&g),
1330          owl_global_get_cols(&g));
1331  owl_fmtext_append_normal(&fm, buff);
1332
1333  if (owl_global_get_hascolors(&g)) {
1334    owl_fmtext_append_normal(&fm, "Color: Yes\n");
1335    sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
1336    owl_fmtext_append_normal(&fm, buff);
1337    sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
1338    owl_fmtext_append_normal(&fm, buff);
1339  } else {
1340    owl_fmtext_append_normal(&fm, "Color: No\n");
1341  }
1342
1343  owl_function_popless_fmtext(&fm);
1344  owl_fmtext_free(&fm);
1345}
1346
1347
1348void owl_function_reply(int type, int enter) {
1349  /* if type = 0 then normal reply.
1350   * if type = 1 then it's a reply to sender
1351   * if enter = 0 then allow the command to be edited
1352   * if enter = 1 then don't wait for editing
1353   */
1354  char buff[1024];
1355  owl_message *m;
1356  owl_filter *f;
1357 
1358  if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
1359    owl_function_makemsg("No message selected");
1360  } else {
1361    char *class, *inst, *to;
1362   
1363    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
1364
1365    /* first check if we catch the reply-lockout filter */
1366    f=owl_global_get_filter(&g, "reply-lockout");
1367    if (f) {
1368      if (owl_filter_message_match(f, m)) {
1369        owl_function_makemsg("Sorry, replies to this message have been disabled by the reply-lockout filter");
1370        return;
1371      }
1372    }
1373   
1374    if (owl_message_is_admin(m)) {
1375      if (owl_message_get_admintype(m)==OWL_MESSAGE_ADMINTYPE_OUTGOING) {
1376        owl_function_zwrite_setup(owl_message_get_zwriteline(m));
1377        owl_global_set_buffercommand(&g, owl_message_get_zwriteline(m));
1378      } else {
1379        owl_function_makemsg("You cannot reply to this admin message");
1380      }
1381    } else {
1382      if (owl_message_is_login(m)) {
1383        class="MESSAGE";
1384        inst="PERSONAL";
1385        to=owl_message_get_sender(m);
1386      } else if (type==1) {
1387        class="MESSAGE";
1388        inst="PERSONAL";
1389        to=owl_message_get_sender(m);
1390      } else {
1391        class=owl_message_get_class(m);
1392        inst=owl_message_get_instance(m);
1393        to=owl_message_get_recipient(m);
1394        if (!strcmp(to, "") || !strcmp(to, "*")) {
1395          to="";
1396        } else if (to[0]=='@') {
1397          /* leave it, to get the realm */
1398        } else {
1399          to=owl_message_get_sender(m);
1400        }
1401      }
1402     
1403      /* create the command line */
1404      strcpy(buff, "zwrite");
1405      if (strcasecmp(class, "message")) {
1406        sprintf(buff, "%s -c %s%s%s", buff, owl_getquoting(class), class, owl_getquoting(class));
1407      }
1408      if (strcasecmp(inst, "personal")) {
1409        sprintf(buff, "%s -i %s%s%s", buff, owl_getquoting(inst), inst, owl_getquoting(inst));
1410      }
1411      if (*to != '\0') {
1412        char *tmp;
1413        tmp=pretty_sender(to);
1414        sprintf(buff, "%s %s", buff, tmp);
1415        owl_free(tmp);
1416      }
1417
1418      if (enter) {
1419        owl_history *hist = owl_global_get_cmd_history(&g);
1420        owl_history_store(hist, buff);
1421        owl_history_reset(hist);
1422        owl_function_command_norv(buff);
1423      } else {
1424        owl_function_start_command(buff);
1425      }
1426    }
1427  }
1428}
1429
1430void owl_function_zlocate(char *user, int auth) {
1431  char buff[LINE], myuser[LINE];
1432  char *ptr;
1433
1434  strcpy(myuser, user);
1435  ptr=strchr(myuser, '@');
1436  if (!ptr) {
1437    strcat(myuser, "@");
1438    strcat(myuser, ZGetRealm());
1439  }
1440
1441  owl_zephyr_zlocate(myuser, buff, auth);
1442  owl_function_popless_text(buff);
1443}
1444
1445void owl_function_start_command(char *line) {
1446  int i, j;
1447  owl_editwin *tw;
1448
1449  tw=owl_global_get_typwin(&g);
1450  owl_global_set_typwin_active(&g);
1451  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
1452                        owl_global_get_cmd_history(&g));
1453
1454  owl_editwin_set_locktext(tw, "command: ");
1455  owl_global_set_needrefresh(&g);
1456
1457  j=strlen(line);
1458  for (i=0; i<j; i++) {
1459    owl_editwin_process_char(tw, line[i]);
1460  }
1461  owl_editwin_redisplay(tw, 0);
1462}
1463
1464char *owl_function_exec(int argc, char **argv, char *buff, int type) {
1465  /* if type == 1 display in a popup
1466   * if type == 2 display an admin messages
1467   * if type == 0 return output
1468   * else display in a popup
1469   */
1470  char *newbuff, *redirect = " 2>&1 < /dev/null";
1471  char *out, buff2[1024];
1472  int size;
1473  FILE *p;
1474
1475  if (argc<2) {
1476    owl_function_makemsg("Wrong number of arguments to the pexec command");
1477    return NULL;
1478  }
1479
1480  buff = skiptokens(buff, 1);
1481  newbuff = owl_malloc(strlen(buff)+strlen(redirect)+1);
1482  strcpy(newbuff, buff);
1483  strcat(newbuff, redirect);
1484
1485  p=popen(newbuff, "r");
1486  out=owl_malloc(1024);
1487  size=1024;
1488  strcpy(out, "");
1489  while (fgets(buff2, 1024, p)!=NULL) {
1490    size+=1024;
1491    out=owl_realloc(out, size);
1492    strcat(out, buff2);
1493  }
1494  pclose(p);
1495
1496  if (type==1) {
1497    owl_function_popless_text(out);
1498  } else if (type==0) {
1499    return out;
1500  } else if (type==2) {
1501    owl_function_adminmsg(buff, out);
1502  } else {
1503    owl_function_popless_text(out);
1504  }
1505  owl_free(out);
1506  return NULL;
1507}
1508
1509
1510char *owl_function_perl(int argc, char **argv, char *buff, int type) {
1511  /* if type == 1 display in a popup
1512   * if type == 2 display an admin messages
1513   * if type == 0 return output
1514   * else display in a popup
1515   */
1516  char *perlout;
1517
1518  if (argc<2) {
1519    owl_function_makemsg("Wrong number of arguments to perl command");
1520    return NULL;
1521  }
1522
1523  /* consume first token (argv[0]) */
1524  buff = skiptokens(buff, 1);
1525
1526  perlout = owl_config_execute(buff);
1527  if (perlout) { 
1528    if (type==1) {
1529      owl_function_popless_text(perlout);
1530    } else if (type==2) {
1531      owl_function_adminmsg(buff, perlout);
1532    } else if (type==0) {
1533      return perlout;
1534    } else {
1535      owl_function_popless_text(perlout);
1536    }
1537    owl_free(perlout);
1538  }
1539  return NULL;
1540}
1541
1542
1543void owl_function_change_view(char *filtname) {
1544  owl_view *v;
1545  owl_filter *f;
1546
1547  v=owl_global_get_current_view(&g);
1548  f=owl_global_get_filter(&g, filtname);
1549  if (!f) {
1550    owl_function_makemsg("Unknown filter");
1551    return;
1552  }
1553
1554  owl_view_free(v);
1555  owl_view_create(v, f);
1556
1557  owl_global_set_curmsg(&g, 0);
1558  owl_global_set_curmsg_vert_offset(&g, 0);
1559  owl_global_set_direction_downwards(&g);
1560  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
1561  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1562}
1563
1564void owl_function_create_filter(int argc, char **argv) {
1565  owl_filter *f;
1566  owl_view *v;
1567  int ret, inuse=0;
1568
1569  if (argc < 2) {
1570    owl_function_makemsg("Wrong number of arguments to filter command");
1571    return;
1572  }
1573
1574  v=owl_global_get_current_view(&g);
1575
1576  /* don't touch the all filter */
1577  if (!strcmp(argv[1], "all")) {
1578    owl_function_makemsg("You may not change the 'all' filter.");
1579    return;
1580  }
1581
1582  /* deal with the case of trying change the filter color */
1583  if (argc==4 && !strcmp(argv[2], "-c")) {
1584    f=owl_global_get_filter(&g, argv[1]);
1585    if (!f) {
1586      owl_function_makemsg("The filter '%s' does not exist.", argv[1]);
1587      return;
1588    }
1589    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
1590    owl_global_set_needrefresh(&g);
1591    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1592    return;
1593  }
1594
1595  /* create the filter and check for errors */
1596  f=owl_malloc(sizeof(owl_filter));
1597  ret=owl_filter_init(f, argv[1], argc-2, argv+2);
1598  if (ret==-1) {
1599    owl_free(f);
1600    owl_function_makemsg("Invalid filter syntax");
1601    return;
1602  }
1603
1604  /* if the named filter is in use by the current view, remember it */
1605  if (!strcmp(owl_view_get_filtname(v), argv[1])) {
1606    inuse=1;
1607  }
1608
1609  /* if the named filter already exists, nuke it */
1610  if (owl_global_get_filter(&g, argv[1])) {
1611    owl_global_remove_filter(&g, argv[1]);
1612  }
1613
1614  /* add the filter */
1615  owl_global_add_filter(&g, f);
1616
1617  /* if it was in use by the current view then update */
1618  if (inuse) {
1619    owl_function_change_view(argv[1]);
1620  }
1621  owl_global_set_needrefresh(&g);
1622  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1623}
1624
1625void owl_function_show_filters() {
1626  owl_list *l;
1627  owl_filter *f;
1628  int i, j;
1629  owl_fmtext fm;
1630
1631  owl_fmtext_init_null(&fm);
1632
1633  l=owl_global_get_filterlist(&g);
1634  j=owl_list_get_size(l);
1635
1636  owl_fmtext_append_bold(&fm, "Filters:\n");
1637
1638  for (i=0; i<j; i++) {
1639    f=owl_list_get_element(l, i);
1640    owl_fmtext_append_normal(&fm, "   ");
1641    if (owl_global_get_hascolors(&g)) {
1642      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
1643    } else {
1644      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
1645    }
1646    owl_fmtext_append_normal(&fm, "\n");
1647  }
1648  owl_function_popless_fmtext(&fm);
1649  owl_fmtext_free(&fm);
1650}
1651
1652void owl_function_show_filter(char *name) {
1653  owl_filter *f;
1654  char buff[5000];
1655
1656  f=owl_global_get_filter(&g, name);
1657  if (!f) {
1658    owl_function_makemsg("There is no filter with that name");
1659    return;
1660  }
1661  owl_filter_print(f, buff);
1662  owl_function_popless_text(buff);
1663}
1664
1665void owl_function_show_zpunts() {
1666  owl_filter *f;
1667  owl_list *fl;
1668  char buff[5000];
1669  owl_fmtext fm;
1670  int i, j;
1671
1672  owl_fmtext_init_null(&fm);
1673
1674  fl=owl_global_get_puntlist(&g);
1675  j=owl_list_get_size(fl);
1676  owl_fmtext_append_bold(&fm, "Active zpunt filters:\n");
1677
1678  for (i=0; i<j; i++) {
1679    f=owl_list_get_element(fl, i);
1680    owl_filter_print(f, buff);
1681    owl_fmtext_append_normal(&fm, buff);
1682  }
1683  owl_function_popless_fmtext(&fm);
1684  owl_fmtext_free(&fm);
1685}
1686
1687char *owl_function_fastclassinstfilt(char *class, char *instance) {
1688  /* creates a filter for a class, instance if one doesn't exist.
1689   * If instance is null then apply for all messgaes in the class.
1690   * returns the name of the filter, which the caller must free.*/
1691  owl_list *fl;
1692  owl_filter *f;
1693  char *argbuff, *filtname;
1694  int len;
1695
1696  fl=owl_global_get_filterlist(&g);
1697
1698  /* name for the filter */
1699  len=strlen(class)+30;
1700  if (instance) len+=strlen(instance);
1701  filtname=owl_malloc(len);
1702  if (!instance) {
1703    sprintf(filtname, "class-%s", class);
1704  } else {
1705    sprintf(filtname, "class-%s-instance-%s", class, instance);
1706  }
1707  downstr(filtname);
1708
1709  /* if it already exists then go with it.  This lets users override */
1710  if (owl_global_get_filter(&g, filtname)) {
1711    return filtname;
1712  }
1713
1714  /* create the new filter */
1715  argbuff=owl_malloc(len+20);
1716  sprintf(argbuff, "( class ^%s$ )", class);
1717  if (instance) {
1718    sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, instance);
1719  }
1720
1721  f=owl_malloc(sizeof(owl_filter));
1722  owl_filter_init_fromstring(f, filtname, argbuff);
1723
1724  /* add it to the global list */
1725  owl_global_add_filter(&g, f);
1726
1727  owl_free(argbuff);
1728  return filtname;
1729}
1730
1731char *owl_function_fastuserfilt(char *user) {
1732  owl_filter *f;
1733  char *argbuff, *longuser, *shortuser, *filtname;
1734
1735  /* stick the local realm on if it's not there */
1736  longuser=long_sender(user);
1737  shortuser=pretty_sender(user);
1738
1739  /* name for the filter */
1740  filtname=owl_malloc(strlen(shortuser)+20);
1741  sprintf(filtname, "user-%s", shortuser);
1742
1743  /* if it already exists then go with it.  This lets users override */
1744  if (owl_global_get_filter(&g, filtname)) {
1745    return filtname;
1746  }
1747
1748  /* create the new-internal filter */
1749  f=owl_malloc(sizeof(owl_filter));
1750
1751  argbuff=owl_malloc(strlen(longuser)+200);
1752  sprintf(argbuff, "( ( class ^message$ ) and ( instance ^personal$ ) and ( sender ^%s$ ) )", longuser);
1753  sprintf(argbuff, "%s or ( ( type ^admin$ ) and ( recipient %s ) )", argbuff, shortuser);
1754  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) )", argbuff, longuser);
1755
1756  owl_filter_init_fromstring(f, filtname, argbuff);
1757
1758  /* add it to the global list */
1759  owl_global_add_filter(&g, f);
1760
1761  /* free stuff */
1762  owl_free(argbuff);
1763  owl_free(longuser);
1764  owl_free(shortuser);
1765
1766  return filtname;
1767}
1768
1769char *owl_function_fasttypefilt(char *type) {
1770  owl_filter *f;
1771  char *argbuff, *filtname;
1772
1773  /* name for the filter */
1774  filtname=owl_sprintf("type-%s", type);
1775
1776  /* if it already exists then go with it.  This lets users override */
1777  if (owl_global_get_filter(&g, filtname)) {
1778    return filtname;
1779  }
1780
1781  /* create the new-internal filter */
1782  f=owl_malloc(sizeof(owl_filter));
1783
1784  argbuff = owl_sprintf("type ^%s$", type);
1785
1786  owl_filter_init_fromstring(f, filtname, argbuff);
1787
1788  /* add it to the global list */
1789  owl_global_add_filter(&g, f);
1790
1791  /* free stuff */
1792  owl_free(argbuff);
1793
1794  return filtname;
1795}
1796
1797/* If flag is 1, marks for deletion.  If flag is 0,
1798 * unmarks for deletion. */
1799void owl_function_delete_curview_msgs(int flag) {
1800  owl_view *v;
1801  int i, j;
1802
1803  v=owl_global_get_current_view(&g);
1804  j=owl_view_get_size(v);
1805  for (i=0; i<j; i++) {
1806    if (flag == 1) {
1807      owl_message_mark_delete(owl_view_get_element(v, i));
1808    } else if (flag == 0) {
1809      owl_message_unmark_delete(owl_view_get_element(v, i));
1810    }
1811  }
1812
1813  owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un");
1814
1815  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
1816}
1817
1818char *owl_function_smartfilter(int type) {
1819  /* Returns the name of a filter, or null.  The caller
1820   * must free this name.  */
1821  /* if the curmsg is a personal message return a filter name
1822   *    to the converstaion with that user.
1823   * If the curmsg is a class message, instance foo, recip *
1824   *    message, return a filter name to the class, inst.
1825   * If the curmsg is a class message and type==0 then
1826   *    return a filter name for just the class.
1827   * If the curmsg is a class message and type==1 then
1828   *    return a filter name for the class and instance.
1829   */
1830  owl_view *v;
1831  owl_message *m;
1832  char *sender, *filtname=NULL;
1833 
1834  v=owl_global_get_current_view(&g);
1835  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1836
1837  if (owl_view_get_size(v)==0) {
1838    owl_function_makemsg("No message selected\n");
1839    return NULL;
1840  }
1841
1842  /* very simple handling of admin messages for now */
1843  if (owl_message_is_admin(m)) {
1844    return owl_function_fasttypefilt("admin");
1845  }
1846
1847  /* narrow personal and login messages to the sender */
1848  if (owl_message_is_personal(m) || owl_message_is_login(m)) {
1849    if (owl_message_is_zephyr(m)) {
1850      sender=pretty_sender(owl_message_get_sender(m));
1851      filtname = owl_function_fastuserfilt(sender);
1852      owl_free(sender);
1853      return filtname;
1854    }
1855    return NULL;
1856  }
1857
1858  /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
1859  if (!strcasecmp(owl_message_get_class(m), "message") &&
1860      !owl_message_is_personal(m)) {
1861    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
1862    return filtname;
1863  }
1864
1865  /* otherwise narrow to the class */
1866  if (type==0) {
1867    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), NULL);
1868  } else if (type==1) {
1869    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
1870  }
1871  return filtname;
1872}
1873
1874void owl_function_smartzpunt(int type) {
1875  /* Starts a zpunt command based on the current class,instance pair.
1876   * If type=0, uses just class.  If type=1, uses instance as well. */
1877  owl_view *v;
1878  owl_message *m;
1879  char *cmd, *cmdprefix, *mclass, *minst;
1880 
1881  v=owl_global_get_current_view(&g);
1882  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1883
1884  if (owl_view_get_size(v)==0) {
1885    owl_function_makemsg("No message selected\n");
1886    return;
1887  }
1888
1889  /* for now we skip admin messages. */
1890  if (owl_message_is_admin(m)
1891      || owl_message_is_login(m)
1892      || !owl_message_is_zephyr(m)) {
1893    owl_function_makemsg("smartzpunt doesn't support this message type.");
1894    return;
1895  }
1896
1897  mclass = owl_message_get_class(m);
1898  minst = owl_message_get_instance(m);
1899  if (!mclass || !*mclass || *mclass==' '
1900      || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal"))
1901      || (type && (!minst || !*minst|| *minst==' '))) {
1902    owl_function_makemsg("smartzpunt can't safely do this for <%s,%s>",
1903                         mclass, minst);
1904  } else {
1905    cmdprefix = "start-command zpunt ";
1906    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+3);
1907    strcpy(cmd, cmdprefix);
1908    strcat(cmd, mclass);
1909    if (type) {
1910      strcat(cmd, " ");
1911      strcat(cmd, minst);
1912    } else {
1913      strcat(cmd, " *");
1914    }
1915    owl_function_command(cmd);
1916    owl_free(cmd);
1917  }
1918}
1919
1920
1921
1922void owl_function_color_current_filter(char *color) {
1923  owl_filter *f;
1924  char *name;
1925
1926  name=owl_view_get_filtname(owl_global_get_current_view(&g));
1927  f=owl_global_get_filter(&g, name);
1928  if (!f) {
1929    owl_function_makemsg("Unknown filter");
1930    return;
1931  }
1932
1933  /* don't touch the all filter */
1934  if (!strcmp(name, "all")) {
1935    owl_function_makemsg("You may not change the 'all' filter.");
1936    return;
1937  }
1938
1939  /* deal with the case of trying change the filter color */
1940  owl_filter_set_color(f, owl_util_string_to_color(color));
1941  owl_global_set_needrefresh(&g);
1942  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1943}
1944
1945void owl_function_show_colors() {
1946  owl_fmtext fm;
1947
1948  owl_fmtext_init_null(&fm);
1949  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
1950  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
1951  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
1952  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
1953  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
1954  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
1955  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
1956  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
1957
1958  owl_function_popless_fmtext(&fm);
1959  owl_fmtext_free(&fm);
1960}
1961
1962void owl_function_zpunt(char *class, char *inst, char *recip, int direction) {
1963  /* add the given class, inst, recip to the punt list for filtering.
1964   *   if direction==0 then punt
1965   *   if direction==1 then unpunt */
1966  owl_filter *f;
1967  owl_list *fl;
1968  char *buff;
1969  int ret, i, j;
1970
1971  fl=owl_global_get_puntlist(&g);
1972
1973  /* first, create the filter */
1974  f=malloc(sizeof(owl_filter));
1975  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
1976  if (!strcmp(recip, "*")) {
1977    sprintf(buff, "class ^%s$ and instance ^%s$", class, inst);
1978  } else {
1979    sprintf(buff, "class ^%s$ and instance ^%s$ and recipient %s", class, inst, recip);
1980  }
1981  owl_function_debugmsg("About to filter %s", buff);
1982  ret=owl_filter_init_fromstring(f, "punt-filter", buff);
1983  owl_free(buff);
1984  if (ret) {
1985    owl_function_makemsg("Error creating filter for zpunt");
1986    owl_filter_free(f);
1987    return;
1988  }
1989
1990  /* Check for an identical filter */
1991  j=owl_list_get_size(fl);
1992  for (i=0; i<j; i++) {
1993    if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
1994      /* if we're punting, then just silently bow out on this duplicate */
1995      if (direction==0) {
1996        owl_filter_free(f);
1997        return;
1998      }
1999
2000      /* if we're unpunting, then remove this filter from the puntlist */
2001      if (direction==1) {
2002        owl_filter_free(owl_list_get_element(fl, i));
2003        owl_list_remove_element(fl, i);
2004        return;
2005      }
2006    }
2007  }
2008
2009  /* If we're punting, add the filter to the global punt list */
2010  if (direction==0) {
2011    owl_list_append_element(fl, f);
2012  }
2013}
2014
2015void owl_function_activate_keymap(char *keymap) {
2016  if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
2017    owl_function_makemsg("Unable to activate keymap '%s'", keymap);
2018  }
2019}
2020
2021
2022void owl_function_show_keymaps() {
2023  owl_list l;
2024  owl_fmtext fm;
2025  owl_keymap *km;
2026  owl_keyhandler *kh;
2027  int i, numkm;
2028  char *kmname;
2029
2030  kh = owl_global_get_keyhandler(&g);
2031  owl_fmtext_init_null(&fm);
2032  owl_fmtext_append_bold(&fm, "Keymaps:   ");
2033  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
2034  owl_keyhandler_get_keymap_names(kh, &l);
2035  owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
2036  owl_fmtext_append_normal(&fm, "\n");
2037
2038  numkm = owl_list_get_size(&l);
2039  for (i=0; i<numkm; i++) {
2040    kmname = owl_list_get_element(&l, i);
2041    km = owl_keyhandler_get_keymap(kh, kmname);
2042    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
2043    owl_keymap_get_details(km, &fm);   
2044  }
2045  owl_fmtext_append_normal(&fm, "\n");
2046 
2047  owl_function_popless_fmtext(&fm);
2048  owl_keyhandler_keymap_namelist_free(&l);
2049  owl_fmtext_free(&fm);
2050}
2051
2052char *owl_function_keymap_summary(void *name) {
2053  owl_keymap *km
2054    = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2055  if (km) return owl_keymap_summary(km);
2056  else return(NULL);
2057}
2058
2059/* TODO: implement for real */
2060void owl_function_show_keymap(char *name) {
2061  owl_fmtext  fm;
2062  owl_keymap *km;
2063
2064  owl_fmtext_init_null(&fm);
2065  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2066  if (km) {
2067    owl_keymap_get_details(km, &fm);
2068  } else {
2069    owl_fmtext_append_normal(&fm, "No such keymap...\n");
2070  } 
2071  owl_function_popless_fmtext(&fm);
2072  owl_fmtext_free(&fm);
2073}
2074
2075
2076void owl_function_help_for_command(char *cmdname) {
2077  owl_fmtext   fm;
2078
2079  owl_fmtext_init_null(&fm);
2080  owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm);
2081  owl_function_popless_fmtext(&fm); 
2082  owl_fmtext_free(&fm);
2083}
Note: See TracBrowser for help on using the repository browser.