source: functions.c @ e50cd56

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since e50cd56 was e50cd56, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
Fixed some buffer overruns in the "reply" command. When repying to "all" on a message that begins with "CC:" (eg, sent with "zwrite -C", the reply line will be constructed from the sender and the usernames on the CC: line of the message being replied to. There is no such thing as C-R, so left C-r as it is but added: M-r --- edit reply to all M-R --- edit reply to sender
  • Property mode set to 100644
File size: 54.6 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  } else if (webbrowser == OWL_WEBBROWSER_OPERA) {
708    snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);
709    system(tmpbuff); 
710  }
711}
712
713void owl_function_calculate_topmsg(int direction) {
714  int recwinlines, y, savey, i, j, topmsg, curmsg, foo;
715  owl_mainwin *mw;
716  owl_view *v;
717
718  mw=owl_global_get_mainwin(&g);
719
720  topmsg=owl_global_get_topmsg(&g);
721  curmsg=owl_global_get_curmsg(&g);
722  v=owl_global_get_current_view(&g);
723  recwinlines=owl_global_get_recwin_lines(&g);
724
725  if (owl_view_get_size(v) < 1) {
726    return;
727  }
728 
729  /* Find number of lines from top to bottom of curmsg (store in savey) */
730  savey=0;
731  for (i=topmsg; i<=curmsg; i++) {
732    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
733  }
734
735  /* If the direction is DOWNWARDS but we're off the bottom of the
736   *  screen, then set the topmsg to curmsg and scroll UPWARDS
737   */
738  if (direction == OWL_DIRECTION_DOWNWARDS) {
739    if (savey > recwinlines) {
740      topmsg=curmsg;
741      savey=owl_message_get_numlines(owl_view_get_element(v, i));
742      direction=OWL_DIRECTION_UPWARDS;
743    }
744  }
745
746  /* If our bottom line is less than 1/4 down the screen then scroll up */
747  if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) {
748    if (savey < (recwinlines / 4)) {
749      y=0;
750      for (j=curmsg; j>=0; j--) {
751        foo=owl_message_get_numlines(owl_view_get_element(v, j));
752        /* will we run the curmsg off the screen? */
753        if ((foo+y) >= recwinlines) {
754          j++;
755          if (j>curmsg) j=curmsg;
756          break;
757        }
758        /* have saved 1/2 the screen space? */
759        y+=foo;
760        if (y > (recwinlines / 2)) break;
761      }
762      if (j<0) j=0;
763      owl_global_set_topmsg(&g, j);
764      return;
765    }
766  }
767
768  if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) {
769    /* If curmsg bottom line is more than 3/4 down the screen then scroll down */
770    if (savey > ((recwinlines * 3)/4)) {
771      y=0;
772      /* count lines from the top until we can save 1/2 the screen size */
773      for (j=topmsg; j<curmsg; j++) {
774        y+=owl_message_get_numlines(owl_view_get_element(v, j));
775        if (y > (recwinlines / 2)) break;
776      }
777      if (j==curmsg) {
778        j--;
779      }
780      owl_global_set_topmsg(&g, j+1);
781      return;
782    }
783  }
784}
785
786
787void owl_function_resize() {
788  owl_global_set_resize_pending(&g);
789}
790
791
792void owl_function_run_buffercommand() {
793  char *buff;
794
795  buff=owl_global_get_buffercommand(&g);
796  if (!strncmp(buff, "zwrite ", 7)) {
797
798    owl_function_zwrite(buff);
799  }
800}
801
802void owl_function_debugmsg(char *fmt, ...) {
803  FILE *file;
804  time_t now;
805  char buff1[LINE], buff2[LINE];
806  va_list ap;
807  va_start(ap, fmt);
808
809  if (!owl_global_is_debug_fast(&g)) return;
810
811  file=fopen(owl_global_get_debug_file(&g), "a");
812  if (!file) return;
813
814  now=time(NULL);
815  strcpy(buff1, ctime(&now));
816  buff1[strlen(buff1)-1]='\0';
817
818  owl_global_get_runtime_string(&g, buff2);
819 
820  fprintf(file, "[%i -  %s - %s]: ", (int) getpid(), buff1, buff2);
821  vfprintf(file, fmt, ap);
822  fprintf(file, "\n");
823  fclose(file);
824
825  va_end(ap);
826}
827
828
829void owl_function_refresh() {
830  owl_function_resize();
831}
832
833void owl_function_beep() {
834  if (owl_global_is_bell(&g)) {
835    beep();
836  }
837}
838
839
840void owl_function_subscribe(char *class, char *inst, char *recip) {
841  int ret;
842
843  ret=owl_zephyr_sub(class, inst, recip);
844  if (ret) {
845    owl_function_makemsg("Error subscribing.");
846  } else {
847    owl_function_makemsg("Subscribed.");
848  }
849}
850
851
852void owl_function_unsubscribe(char *class, char *inst, char *recip) {
853  int ret;
854
855  ret=owl_zephyr_unsub(class, inst, recip);
856  if (ret) {
857    owl_function_makemsg("Error subscribing.");
858  } else {
859    owl_function_makemsg("Unsubscribed.");
860  }
861}
862
863
864void owl_function_set_cursor(WINDOW *win) {
865  wnoutrefresh(win);
866}
867
868
869void owl_function_full_redisplay() {
870  redrawwin(owl_global_get_curs_recwin(&g));
871  redrawwin(owl_global_get_curs_sepwin(&g));
872  redrawwin(owl_global_get_curs_typwin(&g));
873  redrawwin(owl_global_get_curs_msgwin(&g));
874
875  wnoutrefresh(owl_global_get_curs_recwin(&g));
876  wnoutrefresh(owl_global_get_curs_sepwin(&g));
877  wnoutrefresh(owl_global_get_curs_typwin(&g));
878  wnoutrefresh(owl_global_get_curs_msgwin(&g));
879 
880  sepbar("");
881  owl_function_makemsg("");
882
883  owl_global_set_needrefresh(&g);
884}
885
886
887void owl_function_popless_text(char *text) {
888  owl_popwin *pw;
889  owl_viewwin *v;
890
891  pw=owl_global_get_popwin(&g);
892  v=owl_global_get_viewwin(&g);
893
894  owl_popwin_up(pw);
895  owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
896                        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
897                        text);
898  owl_popwin_refresh(pw);
899  owl_viewwin_redisplay(v, 0);
900  owl_global_set_needrefresh(&g);
901}
902
903
904void owl_function_popless_fmtext(owl_fmtext *fm) {
905  owl_popwin *pw;
906  owl_viewwin *v;
907
908  pw=owl_global_get_popwin(&g);
909  v=owl_global_get_viewwin(&g);
910
911  owl_popwin_up(pw);
912  owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
913                   owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
914                   fm);
915  owl_popwin_refresh(pw);
916  owl_viewwin_redisplay(v, 0);
917  owl_global_set_needrefresh(&g);
918}
919
920void owl_function_about() {
921  char buff[5000];
922
923  sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING);
924  strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n");
925  strcat(buff, "Institute of Technology.  The first version, 0.5, was\n");
926  strcat(buff, "released in March 2002\n");
927  strcat(buff, "\n");
928  strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n");
929  strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n");
930  strcat(buff, "between Witches and Wizards.\n");
931  strcat(buff, "\n");
932  strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n");
933  strcat(buff, "\n");
934  strcat(buff, "Permission to use, copy, modify, and distribute this\n");
935  strcat(buff, "software and its documentation for any purpose and without\n");
936  strcat(buff, "fee is hereby granted, provided that the above copyright\n");
937  strcat(buff, "notice and this permission notice appear in all copies\n");
938  strcat(buff, "and in supporting documentation.  No representation is\n");
939  strcat(buff, "made about the suitability of this software for any\n");
940  strcat(buff, "purpose.  It is provided \"as is\" without express\n");
941  strcat(buff, "or implied warranty.\n");
942  owl_function_popless_text(buff);
943}
944
945void owl_function_info() {
946  owl_message *m;
947  ZNotice_t *n;
948  char buff[2048], tmpbuff[1024];
949  char *ptr;
950  int i, j, fields, len;
951  owl_view *v;
952
953  v=owl_global_get_current_view(&g);
954 
955  if (owl_view_get_size(v)==0) {
956    owl_function_makemsg("No message selected\n");
957    return;
958  }
959
960  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
961  if (!owl_message_is_zephyr(m)) {
962    sprintf(buff,   "Owl Message Id: %i\n", owl_message_get_id(m));
963    sprintf(buff, "%sTime          : %s\n", buff, owl_message_get_timestr(m));
964    owl_function_popless_text(buff);
965    return;
966  }
967
968  n=owl_message_get_notice(m);
969
970  sprintf(buff,   "Owl Msg ID: %i\n", owl_message_get_id(m));
971  sprintf(buff, "%sClass     : %s\n", buff, n->z_class);
972  sprintf(buff, "%sInstance  : %s\n", buff, n->z_class_inst);
973  sprintf(buff, "%sSender    : %s\n", buff, n->z_sender);
974  sprintf(buff, "%sRecip     : %s\n", buff, n->z_recipient);
975  sprintf(buff, "%sOpcode    : %s\n", buff, n->z_opcode);
976  strcat(buff,    "Kind      : ");
977  if (n->z_kind==UNSAFE) {
978    strcat(buff, "UNSAFE\n");
979  } else if (n->z_kind==UNACKED) {
980    strcat(buff, "UNACKED\n");
981  } else if (n->z_kind==ACKED) {
982    strcat(buff, "ACKED\n");
983  } else if (n->z_kind==HMACK) {
984    strcat(buff, "HMACK\n");
985  } else if (n->z_kind==HMCTL) {
986    strcat(buff, "HMCTL\n");
987  } else if (n->z_kind==SERVACK) {
988    strcat(buff, "SERVACK\n");
989  } else if (n->z_kind==SERVNAK) {
990    strcat(buff, "SERVNAK\n");
991  } else if (n->z_kind==CLIENTACK) {
992    strcat(buff, "CLIENTACK\n");
993  } else if (n->z_kind==STAT) {
994    strcat(buff, "STAT\n");
995  } else {
996    strcat(buff, "ILLEGAL VALUE\n");
997  }
998  sprintf(buff, "%sTime      : %s\n", buff, owl_message_get_timestr(m));
999  sprintf(buff, "%sHost      : %s\n", buff, owl_message_get_hostname(m));
1000  sprintf(buff, "%sPort      : %i\n", buff, n->z_port);
1001  strcat(buff,    "Auth      : ");
1002  if (n->z_auth == ZAUTH_FAILED) {
1003    strcat(buff, "FAILED\n");
1004  } else if (n->z_auth == ZAUTH_NO) {
1005    strcat(buff, "NO\n");
1006  } else if (n->z_auth == ZAUTH_YES) {
1007    strcat(buff, "YES\n");
1008  } else {
1009    sprintf(buff, "%sUnknown State (%i)\n", buff, n->z_auth);
1010  }
1011  sprintf(buff, "%sCheckd Ath: %i\n", buff, n->z_checked_auth);
1012  sprintf(buff, "%sMulti notc: %s\n", buff, n->z_multinotice);
1013  sprintf(buff, "%sNum other : %i\n", buff, n->z_num_other_fields);
1014  sprintf(buff, "%sMsg Len   : %i\n", buff, n->z_message_len);
1015
1016  sprintf(buff, "%sFields    : %i\n", buff, owl_zephyr_get_num_fields(n));
1017
1018  fields=owl_zephyr_get_num_fields(n);
1019  for (i=0; i<fields; i++) {
1020    sprintf(buff, "%sField %i   : ", buff, i+1);
1021
1022    ptr=owl_zephyr_get_field(n, i+1, &len);
1023    if (!ptr) break;
1024    if (len<30) {
1025      strncpy(tmpbuff, ptr, len);
1026      tmpbuff[len]='\0';
1027    } else {
1028      strncpy(tmpbuff, ptr, 30);
1029      tmpbuff[30]='\0';
1030      strcat(tmpbuff, "...");
1031    }
1032
1033    /* just for testing for now */
1034    for (j=0; j<strlen(tmpbuff); j++) {
1035      if (tmpbuff[j]=='\n') tmpbuff[j]='~';
1036      if (tmpbuff[j]=='\r') tmpbuff[j]='!';
1037    }
1038
1039    strcat(buff, tmpbuff);
1040    strcat(buff, "\n");
1041  }
1042  sprintf(buff, "%sDefault Fm: %s\n", buff, n->z_default_format);
1043       
1044  owl_function_popless_text(buff);
1045}
1046
1047
1048void owl_function_curmsg_to_popwin() {
1049  owl_popwin *pw;
1050  owl_view *v;
1051  owl_message *m;
1052
1053  v = owl_global_get_current_view(&g);
1054
1055  pw=owl_global_get_popwin(&g);
1056
1057  if (owl_view_get_size(v)==0) {
1058    owl_function_makemsg("No current message");
1059    return;
1060  }
1061
1062  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1063  owl_function_popless_fmtext(owl_message_get_fmtext(m));
1064}
1065
1066
1067void owl_function_page_curmsg(int step) {
1068  /* scroll down or up within the current message IF the message is truncated */
1069
1070  int offset, curmsg, lines;
1071  owl_view *v;
1072  owl_message *m;
1073
1074  offset=owl_global_get_curmsg_vert_offset(&g);
1075  v=owl_global_get_current_view(&g);
1076  if (owl_view_get_size(v)==0) return;
1077  curmsg=owl_global_get_curmsg(&g);
1078  m=owl_view_get_element(v, curmsg);
1079  lines=owl_message_get_numlines(m);
1080
1081  if (offset==0) {
1082    /* Bail if the curmsg isn't the last one displayed */
1083    if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) {
1084      owl_function_makemsg("The entire message is already displayed");
1085      return;
1086    }
1087   
1088    /* Bail if we're not truncated */
1089    if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
1090      owl_function_makemsg("The entire message is already displayed");
1091      return;
1092    }
1093  }
1094 
1095 
1096  /* don't scroll past the last line */
1097  if (step>0) {
1098    if (offset+step > lines-1) {
1099      owl_global_set_curmsg_vert_offset(&g, lines-1);
1100    } else {
1101      owl_global_set_curmsg_vert_offset(&g, offset+step);
1102    }
1103  }
1104
1105  /* would we be before the beginning of the message? */
1106  if (step<0) {
1107    if (offset+step<0) {
1108      owl_global_set_curmsg_vert_offset(&g, 0);
1109    } else {
1110      owl_global_set_curmsg_vert_offset(&g, offset+step);
1111    }
1112  }
1113 
1114  /* redisplay */
1115  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1116  owl_global_set_needrefresh(&g);
1117}
1118
1119void owl_function_resize_typwin(int newsize) {
1120  owl_global_set_typwin_lines(&g, newsize);
1121  owl_function_resize();
1122}
1123
1124void owl_function_typwin_grow() {
1125  int i;
1126
1127  i=owl_global_get_typwin_lines(&g);
1128  owl_function_resize_typwin(i+1);
1129}
1130
1131void owl_function_typwin_shrink() {
1132  int i;
1133
1134  i=owl_global_get_typwin_lines(&g);
1135  if (i>2) {
1136    owl_function_resize_typwin(i-1);
1137  }
1138}
1139
1140void owl_function_mainwin_pagedown() {
1141  int i;
1142
1143  i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g));
1144  if (i<0) return;
1145
1146  owl_global_set_curmsg(&g, i);
1147  owl_function_nextmsg();
1148}
1149
1150void owl_function_mainwin_pageup() {
1151  owl_global_set_curmsg(&g, owl_global_get_topmsg(&g));
1152  owl_function_prevmsg();
1153}
1154
1155void owl_function_getsubs() {
1156  int ret, num, i, one;
1157  ZSubscription_t sub;
1158  char *buff;
1159
1160  one = 1;
1161
1162  ret=ZRetrieveSubscriptions(0, &num);
1163  if (ret == ZERR_TOOMANYSUBS) {
1164
1165  }
1166
1167  buff=owl_malloc(num*200);
1168  strcpy(buff, "");
1169  for (i=0; i<num; i++) {
1170    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
1171      /* deal with error */
1172    } else {
1173      sprintf(buff, "%s<%s,%s,%s>\n", buff, sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient);
1174    }
1175  }
1176
1177  owl_function_popless_text(buff);
1178  owl_free(buff);
1179  ZFlushSubscriptions();
1180}
1181
1182#define PABUFLEN 5000
1183void owl_function_printallvars() {
1184  char buff[PABUFLEN], *pos, *name;
1185  owl_list varnames;
1186  int i, numvarnames, rem;
1187
1188  pos = buff;
1189  pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");
1190  pos += sprintf(pos, "%-20s   %s\n",  "--------", "-----");
1191  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1192  rem = (buff+PABUFLEN)-pos-1;
1193  numvarnames = owl_list_get_size(&varnames);
1194  for (i=0; i<numvarnames; i++) {
1195    name = owl_list_get_element(&varnames, i);
1196    if (name && name[0]!='_') {
1197      rem = (buff+PABUFLEN)-pos-1;   
1198      pos += snprintf(pos, rem, "\n%-20s = ", name);
1199      rem = (buff+PABUFLEN)-pos-1;   
1200      owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem);
1201      pos = buff+strlen(buff);
1202    }
1203  }
1204  rem = (buff+PABUFLEN)-pos-1;   
1205  snprintf(pos, rem, "\n");
1206  owl_variable_dict_namelist_free(&varnames);
1207 
1208  owl_function_popless_text(buff);
1209}
1210
1211void owl_function_show_variables() {
1212  owl_list varnames;
1213  owl_fmtext fm; 
1214  int i, numvarnames;
1215  char *varname;
1216
1217  owl_fmtext_init_null(&fm);
1218  owl_fmtext_append_bold(&fm, 
1219      "Variables: (use 'show variable <name>' for details)\n");
1220  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1221  owl_variable_get_summaryheader(&fm);
1222  numvarnames = owl_list_get_size(&varnames);
1223  for (i=0; i<numvarnames; i++) {
1224    varname = owl_list_get_element(&varnames, i);
1225    if (varname && varname[0]!='_') {
1226      owl_variable_get_summary(owl_global_get_vardict(&g), varname, &fm);
1227    }
1228  }
1229  owl_variable_dict_namelist_free(&varnames);
1230  owl_function_popless_fmtext(&fm);
1231  owl_fmtext_free(&fm);
1232}
1233
1234void owl_function_show_variable(char *name) {
1235  owl_fmtext fm; 
1236
1237  owl_fmtext_init_null(&fm);
1238  owl_variable_get_help(owl_global_get_vardict(&g), name, &fm);
1239  owl_function_popless_fmtext(&fm);
1240  owl_fmtext_free(&fm); 
1241}
1242
1243/* note: this applies to global message list, not to view.
1244 * If flag is 1, deletes.  If flag is 0, undeletes. */
1245void owl_function_delete_by_id(int id, int flag) {
1246  owl_messagelist *ml;
1247  owl_message *m;
1248  ml = owl_global_get_msglist(&g);
1249  m = owl_messagelist_get_by_id(ml, id);
1250  if (m) {
1251    if (flag == 1) {
1252      owl_message_mark_delete(m);
1253    } else if (flag == 0) {
1254      owl_message_unmark_delete(m);
1255    }
1256    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1257    owl_global_set_needrefresh(&g);
1258  } else {
1259    owl_function_makemsg("No message with id %d: unable to mark for (un)delete",id);
1260  }
1261}
1262
1263void owl_function_delete_automsgs() {
1264  /* mark for deletion all messages in the current view that match the
1265   * 'trash' filter */
1266
1267  int i, j, count;
1268  owl_message *m;
1269  owl_view *v;
1270  owl_filter *f;
1271
1272  /* get the trash filter */
1273  f=owl_global_get_filter(&g, "trash");
1274  if (!f) {
1275    owl_function_makemsg("No trash filter defined");
1276    return;
1277  }
1278
1279  v=owl_global_get_current_view(&g);
1280
1281  count=0;
1282  j=owl_view_get_size(v);
1283  for (i=0; i<j; i++) {
1284    m=owl_view_get_element(v, i);
1285    if (owl_filter_message_match(f, m)) {
1286      count++;
1287      owl_message_mark_delete(m);
1288    }
1289  }
1290  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1291  owl_function_makemsg("%i messages marked for deletion", count);
1292  owl_global_set_needrefresh(&g);
1293}
1294
1295
1296void owl_function_status() {
1297  char buff[5000];
1298  time_t start;
1299  int up, days, hours, minutes;
1300
1301  start=owl_global_get_starttime(&g);
1302
1303  sprintf(buff, "Version: %s\n", OWL_VERSION_STRING);
1304  sprintf(buff, "%sScreen size: %i lines, %i columns\n", buff, owl_global_get_lines(&g), owl_global_get_cols(&g));
1305  sprintf(buff, "%sStartup Arugments: %s\n", buff, owl_global_get_startupargs(&g));
1306  sprintf(buff, "%sStartup Time: %s", buff, ctime(&start));
1307
1308  up=owl_global_get_runtime(&g);
1309  days=up/86400;
1310  up-=days*86400;
1311  hours=up/3600;
1312  up-=hours*3600;
1313  minutes=up/60;
1314  up-=minutes*60;
1315  sprintf(buff, "%sRun Time: %i days %2.2i:%2.2i:%2.2i\n", buff, days, hours, minutes, up);
1316
1317  if (owl_global_get_hascolors(&g)) {
1318    sprintf(buff, "%sColor: Yes, %i color pairs.\n", buff, owl_global_get_colorpairs(&g));
1319  } else {
1320    strcat(buff, "Color: No.\n");
1321  }
1322 
1323  owl_function_popless_text(buff);
1324}
1325
1326void owl_function_show_term() {
1327  owl_fmtext fm;
1328  char buff[LINE];
1329
1330  owl_fmtext_init_null(&fm);
1331  sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",
1332          owl_global_get_lines(&g),
1333          owl_global_get_cols(&g));
1334  owl_fmtext_append_normal(&fm, buff);
1335
1336  if (owl_global_get_hascolors(&g)) {
1337    owl_fmtext_append_normal(&fm, "Color: Yes\n");
1338    sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
1339    owl_fmtext_append_normal(&fm, buff);
1340    sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
1341    owl_fmtext_append_normal(&fm, buff);
1342  } else {
1343    owl_fmtext_append_normal(&fm, "Color: No\n");
1344  }
1345
1346  owl_function_popless_fmtext(&fm);
1347  owl_fmtext_free(&fm);
1348}
1349
1350
1351void owl_function_reply(int type, int enter) {
1352  /* if type = 0 then normal reply.
1353   * if type = 1 then it's a reply to sender
1354   * if enter = 0 then allow the command to be edited
1355   * if enter = 1 then don't wait for editing
1356   */
1357  char *buff, *oldbuff;
1358  owl_message *m;
1359  owl_filter *f;
1360 
1361  if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
1362    owl_function_makemsg("No message selected");
1363  } else {
1364    char *class, *inst, *to, *cc=NULL;
1365   
1366    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
1367
1368    /* first check if we catch the reply-lockout filter */
1369    f=owl_global_get_filter(&g, "reply-lockout");
1370    if (f) {
1371      if (owl_filter_message_match(f, m)) {
1372        owl_function_makemsg("Sorry, replies to this message have been disabled by the reply-lockout filter");
1373        return;
1374      }
1375    }
1376   
1377    if (owl_message_is_admin(m)) {
1378      if (owl_message_get_admintype(m)==OWL_MESSAGE_ADMINTYPE_OUTGOING) {
1379        owl_function_zwrite_setup(owl_message_get_zwriteline(m));
1380        owl_global_set_buffercommand(&g, owl_message_get_zwriteline(m));
1381      } else {
1382        owl_function_makemsg("You cannot reply to this admin message");
1383      }
1384    } else {
1385      if (owl_message_is_login(m)) {
1386        class="MESSAGE";
1387        inst="PERSONAL";
1388        to=owl_message_get_sender(m);
1389      } else if (type==1) {
1390        class="MESSAGE";
1391        inst="PERSONAL";
1392        to=owl_message_get_sender(m);
1393      } else {
1394        class=owl_message_get_class(m);
1395        inst=owl_message_get_instance(m);
1396        to=owl_message_get_recipient(m);
1397        cc=owl_message_get_cc(m);
1398        if (!strcmp(to, "") || !strcmp(to, "*")) {
1399          to="";
1400        } else if (to[0]=='@') {
1401          /* leave it, to get the realm */
1402        } else {
1403          to=owl_message_get_sender(m);
1404        }
1405      }
1406     
1407      /* create the command line */
1408      buff = owl_strdup("zwrite");
1409      if (strcasecmp(class, "message")) {
1410        buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
1411        owl_free(oldbuff);
1412      }
1413      if (strcasecmp(inst, "personal")) {
1414        buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst));
1415        owl_free(oldbuff);
1416      }
1417      if (*to != '\0') {
1418        char *tmp, *oldtmp;
1419        tmp=pretty_sender(to);
1420        if (cc) {
1421          tmp = owl_util_uniq(oldtmp=tmp, cc, "-");
1422          owl_free(oldtmp);
1423          buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp);
1424          owl_free(oldbuff);
1425        } else {
1426          tmp=pretty_sender(to);
1427          buff = owl_sprintf("%s %s", oldbuff=buff, tmp);
1428          owl_free(oldbuff);
1429        }
1430        owl_free(tmp);
1431      }
1432      if (cc) owl_free(cc);
1433
1434      if (enter) {
1435        owl_history *hist = owl_global_get_cmd_history(&g);
1436        owl_history_store(hist, buff);
1437        owl_history_reset(hist);
1438        owl_function_command_norv(buff);
1439      } else {
1440        owl_function_start_command(buff);
1441      }
1442      owl_free(buff);
1443    }
1444  }
1445}
1446
1447void owl_function_zlocate(char *user, int auth) {
1448  char buff[LINE], myuser[LINE];
1449  char *ptr;
1450
1451  strcpy(myuser, user);
1452  ptr=strchr(myuser, '@');
1453  if (!ptr) {
1454    strcat(myuser, "@");
1455    strcat(myuser, ZGetRealm());
1456  }
1457
1458  owl_zephyr_zlocate(myuser, buff, auth);
1459  owl_function_popless_text(buff);
1460}
1461
1462void owl_function_start_command(char *line) {
1463  int i, j;
1464  owl_editwin *tw;
1465
1466  tw=owl_global_get_typwin(&g);
1467  owl_global_set_typwin_active(&g);
1468  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
1469                        owl_global_get_cmd_history(&g));
1470
1471  owl_editwin_set_locktext(tw, "command: ");
1472  owl_global_set_needrefresh(&g);
1473
1474  j=strlen(line);
1475  for (i=0; i<j; i++) {
1476    owl_editwin_process_char(tw, line[i]);
1477  }
1478  owl_editwin_redisplay(tw, 0);
1479}
1480
1481char *owl_function_exec(int argc, char **argv, char *buff, int type) {
1482  /* if type == 1 display in a popup
1483   * if type == 2 display an admin messages
1484   * if type == 0 return output
1485   * else display in a popup
1486   */
1487  char *newbuff, *redirect = " 2>&1 < /dev/null";
1488  char *out, buff2[1024];
1489  int size;
1490  FILE *p;
1491
1492  if (argc<2) {
1493    owl_function_makemsg("Wrong number of arguments to the pexec command");
1494    return NULL;
1495  }
1496
1497  buff = skiptokens(buff, 1);
1498  newbuff = owl_malloc(strlen(buff)+strlen(redirect)+1);
1499  strcpy(newbuff, buff);
1500  strcat(newbuff, redirect);
1501
1502  p=popen(newbuff, "r");
1503  out=owl_malloc(1024);
1504  size=1024;
1505  strcpy(out, "");
1506  while (fgets(buff2, 1024, p)!=NULL) {
1507    size+=1024;
1508    out=owl_realloc(out, size);
1509    strcat(out, buff2);
1510  }
1511  pclose(p);
1512
1513  if (type==1) {
1514    owl_function_popless_text(out);
1515  } else if (type==0) {
1516    return out;
1517  } else if (type==2) {
1518    owl_function_adminmsg(buff, out);
1519  } else {
1520    owl_function_popless_text(out);
1521  }
1522  owl_free(out);
1523  return NULL;
1524}
1525
1526
1527char *owl_function_perl(int argc, char **argv, char *buff, int type) {
1528  /* if type == 1 display in a popup
1529   * if type == 2 display an admin messages
1530   * if type == 0 return output
1531   * else display in a popup
1532   */
1533  char *perlout;
1534
1535  if (argc<2) {
1536    owl_function_makemsg("Wrong number of arguments to perl command");
1537    return NULL;
1538  }
1539
1540  /* consume first token (argv[0]) */
1541  buff = skiptokens(buff, 1);
1542
1543  perlout = owl_config_execute(buff);
1544  if (perlout) { 
1545    if (type==1) {
1546      owl_function_popless_text(perlout);
1547    } else if (type==2) {
1548      owl_function_adminmsg(buff, perlout);
1549    } else if (type==0) {
1550      return perlout;
1551    } else {
1552      owl_function_popless_text(perlout);
1553    }
1554    owl_free(perlout);
1555  }
1556  return NULL;
1557}
1558
1559
1560void owl_function_change_view(char *filtname) {
1561  owl_view *v;
1562  owl_filter *f;
1563
1564  v=owl_global_get_current_view(&g);
1565  f=owl_global_get_filter(&g, filtname);
1566  if (!f) {
1567    owl_function_makemsg("Unknown filter");
1568    return;
1569  }
1570
1571  owl_view_free(v);
1572  owl_view_create(v, f);
1573
1574  owl_global_set_curmsg(&g, 0);
1575  owl_global_set_curmsg_vert_offset(&g, 0);
1576  owl_global_set_direction_downwards(&g);
1577  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
1578  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1579}
1580
1581void owl_function_create_filter(int argc, char **argv) {
1582  owl_filter *f;
1583  owl_view *v;
1584  int ret, inuse=0;
1585
1586  if (argc < 2) {
1587    owl_function_makemsg("Wrong number of arguments to filter command");
1588    return;
1589  }
1590
1591  v=owl_global_get_current_view(&g);
1592
1593  /* don't touch the all filter */
1594  if (!strcmp(argv[1], "all")) {
1595    owl_function_makemsg("You may not change the 'all' filter.");
1596    return;
1597  }
1598
1599  /* deal with the case of trying change the filter color */
1600  if (argc==4 && !strcmp(argv[2], "-c")) {
1601    f=owl_global_get_filter(&g, argv[1]);
1602    if (!f) {
1603      owl_function_makemsg("The filter '%s' does not exist.", argv[1]);
1604      return;
1605    }
1606    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
1607    owl_global_set_needrefresh(&g);
1608    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1609    return;
1610  }
1611
1612  /* create the filter and check for errors */
1613  f=owl_malloc(sizeof(owl_filter));
1614  ret=owl_filter_init(f, argv[1], argc-2, argv+2);
1615  if (ret==-1) {
1616    owl_free(f);
1617    owl_function_makemsg("Invalid filter syntax");
1618    return;
1619  }
1620
1621  /* if the named filter is in use by the current view, remember it */
1622  if (!strcmp(owl_view_get_filtname(v), argv[1])) {
1623    inuse=1;
1624  }
1625
1626  /* if the named filter already exists, nuke it */
1627  if (owl_global_get_filter(&g, argv[1])) {
1628    owl_global_remove_filter(&g, argv[1]);
1629  }
1630
1631  /* add the filter */
1632  owl_global_add_filter(&g, f);
1633
1634  /* if it was in use by the current view then update */
1635  if (inuse) {
1636    owl_function_change_view(argv[1]);
1637  }
1638  owl_global_set_needrefresh(&g);
1639  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1640}
1641
1642void owl_function_show_filters() {
1643  owl_list *l;
1644  owl_filter *f;
1645  int i, j;
1646  owl_fmtext fm;
1647
1648  owl_fmtext_init_null(&fm);
1649
1650  l=owl_global_get_filterlist(&g);
1651  j=owl_list_get_size(l);
1652
1653  owl_fmtext_append_bold(&fm, "Filters:\n");
1654
1655  for (i=0; i<j; i++) {
1656    f=owl_list_get_element(l, i);
1657    owl_fmtext_append_normal(&fm, "   ");
1658    if (owl_global_get_hascolors(&g)) {
1659      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
1660    } else {
1661      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
1662    }
1663    owl_fmtext_append_normal(&fm, "\n");
1664  }
1665  owl_function_popless_fmtext(&fm);
1666  owl_fmtext_free(&fm);
1667}
1668
1669void owl_function_show_filter(char *name) {
1670  owl_filter *f;
1671  char buff[5000];
1672
1673  f=owl_global_get_filter(&g, name);
1674  if (!f) {
1675    owl_function_makemsg("There is no filter with that name");
1676    return;
1677  }
1678  owl_filter_print(f, buff);
1679  owl_function_popless_text(buff);
1680}
1681
1682void owl_function_show_zpunts() {
1683  owl_filter *f;
1684  owl_list *fl;
1685  char buff[5000];
1686  owl_fmtext fm;
1687  int i, j;
1688
1689  owl_fmtext_init_null(&fm);
1690
1691  fl=owl_global_get_puntlist(&g);
1692  j=owl_list_get_size(fl);
1693  owl_fmtext_append_bold(&fm, "Active zpunt filters:\n");
1694
1695  for (i=0; i<j; i++) {
1696    f=owl_list_get_element(fl, i);
1697    owl_filter_print(f, buff);
1698    owl_fmtext_append_normal(&fm, buff);
1699  }
1700  owl_function_popless_fmtext(&fm);
1701  owl_fmtext_free(&fm);
1702}
1703
1704char *owl_function_fastclassinstfilt(char *class, char *instance) {
1705  /* creates a filter for a class, instance if one doesn't exist.
1706   * If instance is null then apply for all messgaes in the class.
1707   * returns the name of the filter, which the caller must free.*/
1708  owl_list *fl;
1709  owl_filter *f;
1710  char *argbuff, *filtname;
1711  int len;
1712
1713  fl=owl_global_get_filterlist(&g);
1714
1715  /* name for the filter */
1716  len=strlen(class)+30;
1717  if (instance) len+=strlen(instance);
1718  filtname=owl_malloc(len);
1719  if (!instance) {
1720    sprintf(filtname, "class-%s", class);
1721  } else {
1722    sprintf(filtname, "class-%s-instance-%s", class, instance);
1723  }
1724  downstr(filtname);
1725
1726  /* if it already exists then go with it.  This lets users override */
1727  if (owl_global_get_filter(&g, filtname)) {
1728    return filtname;
1729  }
1730
1731  /* create the new filter */
1732  argbuff=owl_malloc(len+20);
1733  sprintf(argbuff, "( class ^%s$ )", class);
1734  if (instance) {
1735    sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, instance);
1736  }
1737
1738  f=owl_malloc(sizeof(owl_filter));
1739  owl_filter_init_fromstring(f, filtname, argbuff);
1740
1741  /* add it to the global list */
1742  owl_global_add_filter(&g, f);
1743
1744  owl_free(argbuff);
1745  return filtname;
1746}
1747
1748char *owl_function_fastuserfilt(char *user) {
1749  owl_filter *f;
1750  char *argbuff, *longuser, *shortuser, *filtname;
1751
1752  /* stick the local realm on if it's not there */
1753  longuser=long_sender(user);
1754  shortuser=pretty_sender(user);
1755
1756  /* name for the filter */
1757  filtname=owl_malloc(strlen(shortuser)+20);
1758  sprintf(filtname, "user-%s", shortuser);
1759
1760  /* if it already exists then go with it.  This lets users override */
1761  if (owl_global_get_filter(&g, filtname)) {
1762    return filtname;
1763  }
1764
1765  /* create the new-internal filter */
1766  f=owl_malloc(sizeof(owl_filter));
1767
1768  argbuff=owl_malloc(strlen(longuser)+200);
1769  sprintf(argbuff, "( ( class ^message$ ) and ( instance ^personal$ ) and ( sender ^%s$ ) )", longuser);
1770  sprintf(argbuff, "%s or ( ( type ^admin$ ) and ( recipient %s ) )", argbuff, shortuser);
1771  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) )", argbuff, longuser);
1772
1773  owl_filter_init_fromstring(f, filtname, argbuff);
1774
1775  /* add it to the global list */
1776  owl_global_add_filter(&g, f);
1777
1778  /* free stuff */
1779  owl_free(argbuff);
1780  owl_free(longuser);
1781  owl_free(shortuser);
1782
1783  return filtname;
1784}
1785
1786char *owl_function_fasttypefilt(char *type) {
1787  owl_filter *f;
1788  char *argbuff, *filtname;
1789
1790  /* name for the filter */
1791  filtname=owl_sprintf("type-%s", type);
1792
1793  /* if it already exists then go with it.  This lets users override */
1794  if (owl_global_get_filter(&g, filtname)) {
1795    return filtname;
1796  }
1797
1798  /* create the new-internal filter */
1799  f=owl_malloc(sizeof(owl_filter));
1800
1801  argbuff = owl_sprintf("type ^%s$", type);
1802
1803  owl_filter_init_fromstring(f, filtname, argbuff);
1804
1805  /* add it to the global list */
1806  owl_global_add_filter(&g, f);
1807
1808  /* free stuff */
1809  owl_free(argbuff);
1810
1811  return filtname;
1812}
1813
1814/* If flag is 1, marks for deletion.  If flag is 0,
1815 * unmarks for deletion. */
1816void owl_function_delete_curview_msgs(int flag) {
1817  owl_view *v;
1818  int i, j;
1819
1820  v=owl_global_get_current_view(&g);
1821  j=owl_view_get_size(v);
1822  for (i=0; i<j; i++) {
1823    if (flag == 1) {
1824      owl_message_mark_delete(owl_view_get_element(v, i));
1825    } else if (flag == 0) {
1826      owl_message_unmark_delete(owl_view_get_element(v, i));
1827    }
1828  }
1829
1830  owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un");
1831
1832  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
1833}
1834
1835char *owl_function_smartfilter(int type) {
1836  /* Returns the name of a filter, or null.  The caller
1837   * must free this name.  */
1838  /* if the curmsg is a personal message return a filter name
1839   *    to the converstaion with that user.
1840   * If the curmsg is a class message, instance foo, recip *
1841   *    message, return a filter name to the class, inst.
1842   * If the curmsg is a class message and type==0 then
1843   *    return a filter name for just the class.
1844   * If the curmsg is a class message and type==1 then
1845   *    return a filter name for the class and instance.
1846   */
1847  owl_view *v;
1848  owl_message *m;
1849  char *sender, *filtname=NULL;
1850 
1851  v=owl_global_get_current_view(&g);
1852  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1853
1854  if (owl_view_get_size(v)==0) {
1855    owl_function_makemsg("No message selected\n");
1856    return NULL;
1857  }
1858
1859  /* very simple handling of admin messages for now */
1860  if (owl_message_is_admin(m)) {
1861    return owl_function_fasttypefilt("admin");
1862  }
1863
1864  /* narrow personal and login messages to the sender */
1865  if (owl_message_is_personal(m) || owl_message_is_login(m)) {
1866    if (owl_message_is_zephyr(m)) {
1867      sender=pretty_sender(owl_message_get_sender(m));
1868      filtname = owl_function_fastuserfilt(sender);
1869      owl_free(sender);
1870      return filtname;
1871    }
1872    return NULL;
1873  }
1874
1875  /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
1876  if (!strcasecmp(owl_message_get_class(m), "message") &&
1877      !owl_message_is_personal(m)) {
1878    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
1879    return filtname;
1880  }
1881
1882  /* otherwise narrow to the class */
1883  if (type==0) {
1884    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), NULL);
1885  } else if (type==1) {
1886    filtname = owl_function_fastclassinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
1887  }
1888  return filtname;
1889}
1890
1891void owl_function_smartzpunt(int type) {
1892  /* Starts a zpunt command based on the current class,instance pair.
1893   * If type=0, uses just class.  If type=1, uses instance as well. */
1894  owl_view *v;
1895  owl_message *m;
1896  char *cmd, *cmdprefix, *mclass, *minst;
1897 
1898  v=owl_global_get_current_view(&g);
1899  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1900
1901  if (owl_view_get_size(v)==0) {
1902    owl_function_makemsg("No message selected\n");
1903    return;
1904  }
1905
1906  /* for now we skip admin messages. */
1907  if (owl_message_is_admin(m)
1908      || owl_message_is_login(m)
1909      || !owl_message_is_zephyr(m)) {
1910    owl_function_makemsg("smartzpunt doesn't support this message type.");
1911    return;
1912  }
1913
1914  mclass = owl_message_get_class(m);
1915  minst = owl_message_get_instance(m);
1916  if (!mclass || !*mclass || *mclass==' '
1917      || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal"))
1918      || (type && (!minst || !*minst|| *minst==' '))) {
1919    owl_function_makemsg("smartzpunt can't safely do this for <%s,%s>",
1920                         mclass, minst);
1921  } else {
1922    cmdprefix = "start-command zpunt ";
1923    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+3);
1924    strcpy(cmd, cmdprefix);
1925    strcat(cmd, mclass);
1926    if (type) {
1927      strcat(cmd, " ");
1928      strcat(cmd, minst);
1929    } else {
1930      strcat(cmd, " *");
1931    }
1932    owl_function_command(cmd);
1933    owl_free(cmd);
1934  }
1935}
1936
1937
1938
1939void owl_function_color_current_filter(char *color) {
1940  owl_filter *f;
1941  char *name;
1942
1943  name=owl_view_get_filtname(owl_global_get_current_view(&g));
1944  f=owl_global_get_filter(&g, name);
1945  if (!f) {
1946    owl_function_makemsg("Unknown filter");
1947    return;
1948  }
1949
1950  /* don't touch the all filter */
1951  if (!strcmp(name, "all")) {
1952    owl_function_makemsg("You may not change the 'all' filter.");
1953    return;
1954  }
1955
1956  /* deal with the case of trying change the filter color */
1957  owl_filter_set_color(f, owl_util_string_to_color(color));
1958  owl_global_set_needrefresh(&g);
1959  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1960}
1961
1962void owl_function_show_colors() {
1963  owl_fmtext fm;
1964
1965  owl_fmtext_init_null(&fm);
1966  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
1967  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
1968  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
1969  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
1970  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
1971  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
1972  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
1973  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
1974
1975  owl_function_popless_fmtext(&fm);
1976  owl_fmtext_free(&fm);
1977}
1978
1979void owl_function_zpunt(char *class, char *inst, char *recip, int direction) {
1980  /* add the given class, inst, recip to the punt list for filtering.
1981   *   if direction==0 then punt
1982   *   if direction==1 then unpunt */
1983  owl_filter *f;
1984  owl_list *fl;
1985  char *buff;
1986  int ret, i, j;
1987
1988  fl=owl_global_get_puntlist(&g);
1989
1990  /* first, create the filter */
1991  f=malloc(sizeof(owl_filter));
1992  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
1993  if (!strcmp(recip, "*")) {
1994    sprintf(buff, "class ^%s$ and instance ^%s$", class, inst);
1995  } else {
1996    sprintf(buff, "class ^%s$ and instance ^%s$ and recipient %s", class, inst, recip);
1997  }
1998  owl_function_debugmsg("About to filter %s", buff);
1999  ret=owl_filter_init_fromstring(f, "punt-filter", buff);
2000  owl_free(buff);
2001  if (ret) {
2002    owl_function_makemsg("Error creating filter for zpunt");
2003    owl_filter_free(f);
2004    return;
2005  }
2006
2007  /* Check for an identical filter */
2008  j=owl_list_get_size(fl);
2009  for (i=0; i<j; i++) {
2010    if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
2011      /* if we're punting, then just silently bow out on this duplicate */
2012      if (direction==0) {
2013        owl_filter_free(f);
2014        return;
2015      }
2016
2017      /* if we're unpunting, then remove this filter from the puntlist */
2018      if (direction==1) {
2019        owl_filter_free(owl_list_get_element(fl, i));
2020        owl_list_remove_element(fl, i);
2021        return;
2022      }
2023    }
2024  }
2025
2026  /* If we're punting, add the filter to the global punt list */
2027  if (direction==0) {
2028    owl_list_append_element(fl, f);
2029  }
2030}
2031
2032void owl_function_activate_keymap(char *keymap) {
2033  if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
2034    owl_function_makemsg("Unable to activate keymap '%s'", keymap);
2035  }
2036}
2037
2038
2039void owl_function_show_keymaps() {
2040  owl_list l;
2041  owl_fmtext fm;
2042  owl_keymap *km;
2043  owl_keyhandler *kh;
2044  int i, numkm;
2045  char *kmname;
2046
2047  kh = owl_global_get_keyhandler(&g);
2048  owl_fmtext_init_null(&fm);
2049  owl_fmtext_append_bold(&fm, "Keymaps:   ");
2050  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
2051  owl_keyhandler_get_keymap_names(kh, &l);
2052  owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
2053  owl_fmtext_append_normal(&fm, "\n");
2054
2055  numkm = owl_list_get_size(&l);
2056  for (i=0; i<numkm; i++) {
2057    kmname = owl_list_get_element(&l, i);
2058    km = owl_keyhandler_get_keymap(kh, kmname);
2059    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
2060    owl_keymap_get_details(km, &fm);   
2061  }
2062  owl_fmtext_append_normal(&fm, "\n");
2063 
2064  owl_function_popless_fmtext(&fm);
2065  owl_keyhandler_keymap_namelist_free(&l);
2066  owl_fmtext_free(&fm);
2067}
2068
2069char *owl_function_keymap_summary(void *name) {
2070  owl_keymap *km
2071    = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2072  if (km) return owl_keymap_summary(km);
2073  else return(NULL);
2074}
2075
2076/* TODO: implement for real */
2077void owl_function_show_keymap(char *name) {
2078  owl_fmtext  fm;
2079  owl_keymap *km;
2080
2081  owl_fmtext_init_null(&fm);
2082  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2083  if (km) {
2084    owl_keymap_get_details(km, &fm);
2085  } else {
2086    owl_fmtext_append_normal(&fm, "No such keymap...\n");
2087  } 
2088  owl_function_popless_fmtext(&fm);
2089  owl_fmtext_free(&fm);
2090}
2091
2092
2093void owl_function_help_for_command(char *cmdname) {
2094  owl_fmtext   fm;
2095
2096  owl_fmtext_init_null(&fm);
2097  owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm);
2098  owl_function_popless_fmtext(&fm); 
2099  owl_fmtext_free(&fm);
2100}
Note: See TracBrowser for help on using the repository browser.