source: functions.c @ d9b0b972

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since d9b0b972 was d9b0b972, checked in by James M. Kretchmar <kretch@mit.edu>, 20 years ago
Fixed missing word in startup message Better 'status' command
  • Property mode set to 100644
File size: 88.7 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <signal.h>
5#include <string.h>
6#include <time.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <sys/wait.h>
10#include <errno.h>
11#include <signal.h>
12#include "owl.h"
13
14static const char fileIdent[] = "$Id$";
15
16void owl_function_noop(void)
17{
18  return;
19}
20
21char *owl_function_command(char *cmdbuff)
22{
23  owl_function_debugmsg("executing command: %s", cmdbuff);
24  return owl_cmddict_execute(owl_global_get_cmddict(&g), 
25                             owl_global_get_context(&g), cmdbuff);
26}
27
28void owl_function_command_norv(char *cmdbuff)
29{
30  char *rv;
31  rv=owl_function_command(cmdbuff);
32  if (rv) owl_free(rv);
33}
34
35void owl_function_command_alias(char *alias_from, char *alias_to)
36{
37  owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to);
38}
39
40owl_cmd *owl_function_get_cmd(char *name)
41{
42  return owl_cmddict_find(owl_global_get_cmddict(&g), name);
43}
44
45void owl_function_show_commands()
46{
47  owl_list l;
48  owl_fmtext fm;
49
50  owl_fmtext_init_null(&fm);
51  owl_fmtext_append_bold(&fm, "Commands:  ");
52  owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n");
53  owl_cmddict_get_names(owl_global_get_cmddict(&g), &l);
54  owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe);
55  owl_fmtext_append_normal(&fm, "\n");
56  owl_function_popless_fmtext(&fm);
57  owl_cmddict_namelist_free(&l);
58  owl_fmtext_free(&fm);
59}
60
61void owl_function_show_view(char *viewname)
62{
63  owl_view *v;
64  owl_fmtext fm;
65
66  /* we only have the one view right now */
67  v=owl_global_get_current_view(&g);
68  if (viewname && strcmp(viewname, owl_view_get_name(v))) {
69    owl_function_error("No view named '%s'", viewname);
70    return;
71  }
72
73  owl_fmtext_init_null(&fm);
74  owl_view_to_fmtext(v, &fm);
75  owl_function_popless_fmtext(&fm);
76  owl_fmtext_free(&fm);
77}
78
79void owl_function_show_styles() {
80  owl_list l;
81  owl_fmtext fm;
82
83  owl_fmtext_init_null(&fm);
84  owl_fmtext_append_bold(&fm, "Styles:\n");
85  owl_global_get_style_names(&g, &l);
86  owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe);
87  owl_fmtext_append_normal(&fm, "\n");
88  owl_function_popless_fmtext(&fm);
89  owl_list_free_all(&l, owl_free);
90  owl_fmtext_free(&fm);
91}
92
93char *owl_function_style_describe(void *name) {
94  char *desc, *s;
95  owl_style *style;
96  style = owl_global_get_style_by_name(&g, name);
97  if (style) {
98    desc = owl_style_get_description(style);
99  } else {
100    desc = "???";
101  }
102  s = owl_sprintf("%-20s - %s%s", name, 
103                  0==owl_style_validate(style)?"":"[INVALID] ",
104                  desc);
105  return s;
106}
107
108char *owl_function_cmd_describe(void *name)
109{
110  owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name);
111  if (cmd) return owl_cmd_describe(cmd);
112  else return(NULL);
113}
114
115void owl_function_show_command(char *name)
116{
117  owl_function_help_for_command(name);
118}
119
120void owl_function_adminmsg(char *header, char *body)
121{
122  owl_message *m;
123  int followlast;
124
125  followlast=owl_global_should_followlast(&g);
126  m=owl_malloc(sizeof(owl_message));
127  owl_message_create_admin(m, header, body);
128  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
129  owl_view_consider_message(owl_global_get_current_view(&g), m);
130
131  if (followlast) owl_function_lastmsg_noredisplay();
132
133  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
134  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
135    owl_popwin_refresh(owl_global_get_popwin(&g));
136  }
137 
138  wnoutrefresh(owl_global_get_curs_recwin(&g));
139  owl_global_set_needrefresh(&g);
140}
141
142void owl_function_make_outgoing_zephyr(char *body, char *zwriteline, char *zsig)
143{
144  owl_message *m;
145  int followlast;
146  owl_zwrite z;
147 
148  followlast=owl_global_should_followlast(&g);
149
150  /* create a zwrite for the purpose of filling in other message fields */
151  owl_zwrite_create_from_line(&z, zwriteline);
152
153  /* create the message */
154  m=owl_malloc(sizeof(owl_message));
155  owl_message_create_from_zwriteline(m, zwriteline, body, zsig);
156
157  /* add it to the global list and current view */
158  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
159  owl_view_consider_message(owl_global_get_current_view(&g), m);
160
161  if (followlast) owl_function_lastmsg_noredisplay();
162
163  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
164  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
165    owl_popwin_refresh(owl_global_get_popwin(&g));
166  }
167 
168  wnoutrefresh(owl_global_get_curs_recwin(&g));
169  owl_global_set_needrefresh(&g);
170  owl_zwrite_free(&z);
171}
172
173int owl_function_make_outgoing_aim(char *body, char *to)
174{
175  owl_message *m;
176  int followlast;
177
178
179  if (!owl_global_is_aimloggedin(&g)) {
180    return(-1);
181  }
182 
183  followlast=owl_global_should_followlast(&g);
184
185  /* create the message */
186  m=owl_malloc(sizeof(owl_message));
187  owl_message_create_aim(m,
188                         owl_global_get_aim_screenname(&g),
189                         to,
190                         body,
191                         OWL_MESSAGE_DIRECTION_OUT,
192                         0);
193
194  /* add it to the global list and current view */
195  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
196  owl_view_consider_message(owl_global_get_current_view(&g), m);
197
198  if (followlast) owl_function_lastmsg_noredisplay();
199
200  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
201  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
202    owl_popwin_refresh(owl_global_get_popwin(&g));
203  }
204 
205  wnoutrefresh(owl_global_get_curs_recwin(&g));
206  owl_global_set_needrefresh(&g);
207  return(0);
208}
209
210int owl_function_make_outgoing_loopback(char *body)
211{
212  owl_message *m;
213  int followlast;
214
215  followlast=owl_global_should_followlast(&g);
216
217  /* create the message */
218  m=owl_malloc(sizeof(owl_message));
219  owl_message_create_loopback(m, body);
220  owl_message_set_direction_out(m);
221
222  /* add it to the global list and current view */
223  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
224  owl_view_consider_message(owl_global_get_current_view(&g), m);
225
226  if (followlast) owl_function_lastmsg_noredisplay();
227
228  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
229  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
230    owl_popwin_refresh(owl_global_get_popwin(&g));
231  }
232 
233  wnoutrefresh(owl_global_get_curs_recwin(&g));
234  owl_global_set_needrefresh(&g);
235  return(0);
236}
237
238void owl_function_zwrite_setup(char *line)
239{
240  owl_editwin *e;
241  char buff[1024];
242  owl_zwrite z;
243  int ret;
244
245  /* check the arguments */
246  ret=owl_zwrite_create_from_line(&z, line);
247  if (ret) {
248    owl_function_error("Error in zwrite arugments");
249    owl_zwrite_free(&z);
250    return;
251  }
252
253  /* send a ping if necessary */
254  if (owl_global_is_txping(&g)) {
255    owl_zwrite_send_ping(&z);
256  }
257  owl_zwrite_free(&z);
258
259  /* create and setup the editwin */
260  e=owl_global_get_typwin(&g);
261  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
262
263  if (!owl_global_get_lockout_ctrld(&g)) {
264    owl_function_makemsg("Type your zephyr below.  End with ^D or a dot on a line by itself.  ^C will quit.");
265  } else {
266    owl_function_makemsg("Type your zephyr below.  End with a dot on a line by itself.  ^C will quit.");
267  }
268
269  owl_editwin_clear(e);
270  owl_editwin_set_dotsend(e);
271  strcpy(buff, "----> ");
272  strcat(buff, line);
273  strcat(buff, "\n");
274  owl_editwin_set_locktext(e, buff);
275
276  /* make it active */
277  owl_global_set_typwin_active(&g);
278
279  owl_global_set_buffercommand(&g, line);
280}
281
282void owl_function_aimwrite_setup(char *line)
283{
284  owl_editwin *e;
285  char buff[1024];
286
287  /* check the arguments */
288
289  /* create and setup the editwin */
290  e=owl_global_get_typwin(&g);
291  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
292
293  if (!owl_global_get_lockout_ctrld(&g)) {
294    owl_function_makemsg("Type your message below.  End with ^D or a dot on a line by itself.  ^C will quit.");
295  } else {
296    owl_function_makemsg("Type your message below.  End with a dot on a line by itself.  ^C will quit.");
297  }
298
299  owl_editwin_clear(e);
300  owl_editwin_set_dotsend(e);
301  strcpy(buff, "----> ");
302  strcat(buff, line);
303  strcat(buff, "\n");
304  owl_editwin_set_locktext(e, buff);
305
306  /* make it active */
307  owl_global_set_typwin_active(&g);
308
309  owl_global_set_buffercommand(&g, line);
310}
311
312void owl_function_loopwrite_setup()
313{
314  owl_editwin *e;
315
316  /* create and setup the editwin */
317  e=owl_global_get_typwin(&g);
318  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
319
320  if (!owl_global_get_lockout_ctrld(&g)) {
321    owl_function_makemsg("Type your message below.  End with ^D or a dot on a line by itself.  ^C will quit.");
322  } else {
323    owl_function_makemsg("Type your message below.  End with a dot on a line by itself.  ^C will quit.");
324  }
325
326  owl_editwin_clear(e);
327  owl_editwin_set_dotsend(e);
328  owl_editwin_set_locktext(e, "----> loopwrite\n");
329
330  /* make it active */
331  owl_global_set_typwin_active(&g);
332
333  owl_global_set_buffercommand(&g, "loopwrite");
334}
335
336/* send, log and display an outgoing zephyr.  If 'msg' is NULL
337 * the message is expected to be set from the zwrite line itself
338 */
339void owl_function_zwrite(char *line, char *msg)
340{
341  owl_zwrite z;
342  int i, j;
343  char *mymsg;
344
345  /* create the zwrite and send the message */
346  owl_zwrite_create_from_line(&z, line);
347  if (msg) {
348    owl_zwrite_set_message(&z, msg);
349  }
350
351  owl_zwrite_send_message(&z);
352  owl_function_makemsg("Waiting for ack...");
353
354  mymsg=owl_zwrite_get_message(&z);
355
356  /* display the message as an outgoing message in the receive window */
357  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
358    owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
359  }
360
361  /* log it if we have logging turned on */
362  if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
363    j=owl_zwrite_get_numrecips(&z);
364    for (i=0; i<j; i++) {
365      owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i), mymsg);
366    }
367  }
368
369  /* free the zwrite */
370  owl_zwrite_free(&z);
371}
372
373/* send, log and display an outgoing zcrypt zephyr.  If 'msg' is NULL
374 * the message is expected to be set from the zwrite line itself
375 */
376void owl_function_zcrypt(char *line, char *msg)
377{
378  owl_zwrite z;
379  int i, j;
380  char *mymsg;
381  char *cryptmsg;
382#ifdef OWL_ENABLE_ZCRYPT
383  int ret;
384#endif
385
386  /* create the zwrite and send the message */
387  owl_zwrite_create_from_line(&z, line);
388  if (msg) {
389    owl_zwrite_set_message(&z, msg);
390  }
391
392  mymsg=owl_zwrite_get_message(&z);
393#ifdef OWL_ENABLE_ZCRYPT
394  cryptmsg=owl_malloc(strlen(mymsg)*4);
395  ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z));
396  if (ret) {
397    owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
398    owl_function_beep();
399    owl_free(cryptmsg);
400    return;
401  }
402#else
403  cryptmsg=owl_strdup(mymsg);
404#endif
405
406  owl_zwrite_set_message(&z, cryptmsg);
407  owl_zwrite_set_opcode(&z, "crypt");
408  mymsg=cryptmsg;
409   
410  owl_zwrite_send_message(&z);
411  owl_function_makemsg("Waiting for ack...");
412
413  /* display the message as an outgoing message in the receive window */
414  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
415    owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
416  }
417
418  /* log it if we have logging turned on */
419  if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
420    j=owl_zwrite_get_numrecips(&z);
421    for (i=0; i<j; i++) {
422      owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i), mymsg);
423    }
424  }
425
426  /* free the zwrite */
427  owl_free(cryptmsg);
428  owl_zwrite_free(&z);
429}
430
431void owl_function_aimwrite(char *to)
432{
433  int ret;
434  char *msg, *format_msg;
435
436  /* make a formatted copy of the message */
437  msg=owl_editwin_get_text(owl_global_get_typwin(&g));
438  format_msg=owl_strdup(msg);
439  owl_text_wordunwrap(format_msg);
440 
441  /* send the message */
442  ret=owl_aim_send_im(to, format_msg);
443  if (!ret) {
444    owl_function_makemsg("AIM message sent.");
445  } else {
446    owl_function_error("Could not send AIM message.");
447  }
448
449  /* display the message as an outgoing message in the receive window */
450  if (owl_global_is_displayoutgoing(&g)) {
451    owl_function_make_outgoing_aim(msg, to);
452  }
453
454  /* log it if we have logging turned on */
455  if (owl_global_is_logging(&g)) {
456    owl_log_outgoing_aim(to, msg);
457  }
458
459  owl_free(format_msg);
460}
461
462void owl_function_loopwrite()
463{
464  owl_message *m;
465
466  /* create a message and put it on the message queue.  This simulates
467   * an incoming message */
468  m=owl_malloc(sizeof(owl_message));
469  owl_message_create_loopback(m, owl_editwin_get_text(owl_global_get_typwin(&g)));
470  owl_message_set_direction_in(m);
471  owl_global_messagequeue_addmsg(&g, m);
472
473  /* display the message as an outgoing message in the receive window */
474  if (owl_global_is_displayoutgoing(&g)) {
475    owl_function_make_outgoing_loopback(owl_editwin_get_text(owl_global_get_typwin(&g)));
476  }
477
478  /* fake a makemsg */
479  owl_function_makemsg("loopback message sent");
480
481  /* log it if we have logging turned on */
482  if (owl_global_is_logging(&g)) {
483    owl_log_outgoing_loopback(owl_editwin_get_text(owl_global_get_typwin(&g)));
484  }
485}
486
487/* If filter is non-null, looks for the next message matching
488 * that filter.  If skip_deleted, skips any deleted messages.
489 * If last_if_none, will stop at the last message in the view
490 * if no matching messages are found.  */
491void owl_function_nextmsg_full(char *filter, int skip_deleted, int last_if_none)
492{
493  int curmsg, i, viewsize, found;
494  owl_view *v;
495  owl_filter *f = NULL;
496  owl_message *m;
497
498  v=owl_global_get_current_view(&g);
499
500  if (filter) {
501    f=owl_global_get_filter(&g, filter);
502    if (!f) {
503      owl_function_error("No %s filter defined", filter);
504      return;
505    }
506  }
507
508  curmsg=owl_global_get_curmsg(&g);
509  viewsize=owl_view_get_size(v);
510  found=0;
511
512  /* just check to make sure we're in bounds... */
513  if (curmsg>viewsize-1) curmsg=viewsize-1;
514  if (curmsg<0) curmsg=0;
515
516  for (i=curmsg+1; i<viewsize; i++) {
517    m=owl_view_get_element(v, i);
518    if (skip_deleted && owl_message_is_delete(m)) continue;
519    if (f && !owl_filter_message_match(f, m)) continue;
520    found = 1;
521    break;
522  }
523
524  if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1;
525
526  if (!found) {
527    owl_function_makemsg("already at last%s message%s%s",
528                         skip_deleted?" non-deleted":"",
529                         filter?" in ":"", filter?filter:"");
530    /* if (!skip_deleted) owl_function_beep(); */
531  }
532
533  if (last_if_none || found) {
534    owl_global_set_curmsg(&g, i);
535    owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
536    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
537    owl_global_set_direction_downwards(&g);
538  }
539}
540
541void owl_function_prevmsg_full(char *filter, int skip_deleted, int first_if_none)
542{
543  int curmsg, i, viewsize, found;
544  owl_view *v;
545  owl_filter *f = NULL;
546  owl_message *m;
547
548  v=owl_global_get_current_view(&g);
549
550  if (filter) {
551    f=owl_global_get_filter(&g, filter);
552    if (!f) {
553      owl_function_error("No %s filter defined", filter);
554      return;
555    }
556  }
557
558  curmsg=owl_global_get_curmsg(&g);
559  viewsize=owl_view_get_size(v);
560  found=0;
561
562  /* just check to make sure we're in bounds... */
563  if (curmsg<0) curmsg=0;
564
565  for (i=curmsg-1; i>=0; i--) {
566    m=owl_view_get_element(v, i);
567    if (skip_deleted && owl_message_is_delete(m)) continue;
568    if (f && !owl_filter_message_match(f, m)) continue;
569    found = 1;
570    break;
571  }
572
573  if (i<0) i=0;
574
575  if (!found) {
576    owl_function_makemsg("already at first%s message%s%s",
577                         skip_deleted?" non-deleted":"",
578                         filter?" in ":"", filter?filter:"");
579    /* if (!skip_deleted) owl_function_beep(); */
580  }
581
582  if (first_if_none || found) {
583    owl_global_set_curmsg(&g, i);
584    owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS);
585    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
586    owl_global_set_direction_upwards(&g);
587  }
588}
589
590void owl_function_nextmsg()
591{
592  owl_function_nextmsg_full(NULL, 0, 1);
593}
594
595void owl_function_prevmsg()
596{
597  owl_function_prevmsg_full(NULL, 0, 1);
598}
599
600void owl_function_nextmsg_notdeleted()
601{
602  owl_function_nextmsg_full(NULL, 1, 1);
603}
604
605void owl_function_prevmsg_notdeleted()
606{
607  owl_function_prevmsg_full(NULL, 1, 1);
608}
609
610void owl_function_nextmsg_personal()
611{
612  owl_function_nextmsg_full("personal", 0, 0);
613}
614
615void owl_function_prevmsg_personal()
616{
617  owl_function_prevmsg_full("personal", 0, 0);
618}
619
620
621/* if move_after is 1, moves after the delete */
622void owl_function_deletecur(int move_after)
623{
624  int curmsg;
625  owl_view *v;
626
627  v=owl_global_get_current_view(&g);
628
629  /* bail if there's no current message */
630  if (owl_view_get_size(v) < 1) {
631    owl_function_error("No current message to delete");
632    return;
633  }
634
635  /* mark the message for deletion */
636  curmsg=owl_global_get_curmsg(&g);
637  owl_view_delete_element(v, curmsg);
638
639  if (move_after) {
640    /* move the poiner in the appropriate direction
641     * to the next undeleted msg */
642    if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
643      owl_function_prevmsg_notdeleted();
644    } else {
645      owl_function_nextmsg_notdeleted();
646    }
647  }
648}
649
650void owl_function_undeletecur(int move_after)
651{
652  int curmsg;
653  owl_view *v;
654
655  v=owl_global_get_current_view(&g);
656 
657  if (owl_view_get_size(v) < 1) {
658    owl_function_error("No current message to undelete");
659    return;
660  }
661  curmsg=owl_global_get_curmsg(&g);
662
663  owl_view_undelete_element(v, curmsg);
664
665  if (move_after) {
666    if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
667      if (curmsg>0) {
668        owl_function_prevmsg();
669      } else {
670        owl_function_nextmsg();
671      }
672    } else {
673      owl_function_nextmsg();
674    }
675  }
676
677  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
678}
679
680void owl_function_expunge()
681{
682  int curmsg;
683  owl_message *m;
684  owl_messagelist *ml;
685  owl_view *v;
686  int lastmsgid=0;
687
688  curmsg=owl_global_get_curmsg(&g);
689  v=owl_global_get_current_view(&g);
690  ml=owl_global_get_msglist(&g);
691
692  m=owl_view_get_element(v, curmsg);
693  if (m) lastmsgid = owl_message_get_id(m);
694
695  /* expunge the message list */
696  owl_messagelist_expunge(ml);
697
698  /* update all views (we only have one right now) */
699  owl_view_recalculate(v);
700
701  /* find where the new position should be
702     (as close as possible to where we last where) */
703  curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid);
704  if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1;
705  if (curmsg<0) curmsg = 0;
706  owl_global_set_curmsg(&g, curmsg);
707  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
708  /* if there are no messages set the direction to down in case we
709     delete everything upwards */
710  owl_global_set_direction_downwards(&g);
711 
712  owl_function_makemsg("Messages expunged");
713  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
714}
715
716void owl_function_firstmsg()
717{
718  owl_global_set_curmsg(&g, 0);
719  owl_global_set_topmsg(&g, 0);
720  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
721  owl_global_set_direction_downwards(&g);
722}
723
724void owl_function_lastmsg_noredisplay()
725{
726  int oldcurmsg, curmsg;
727  owl_view *v;
728
729  v=owl_global_get_current_view(&g);
730  oldcurmsg=owl_global_get_curmsg(&g);
731  curmsg=owl_view_get_size(v)-1; 
732  if (curmsg<0) curmsg=0;
733  owl_global_set_curmsg(&g, curmsg);
734  if (oldcurmsg < curmsg) {
735    owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
736  } else if (curmsg<owl_view_get_size(v)) {
737    /* If already at the end, blank the screen and move curmsg
738     * past the end of the messages. */
739    owl_global_set_topmsg(&g, curmsg+1);
740    owl_global_set_curmsg(&g, curmsg+1);
741  } 
742  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
743  owl_global_set_direction_downwards(&g);
744}
745
746void owl_function_lastmsg()
747{
748  owl_function_lastmsg_noredisplay();
749  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
750}
751
752void owl_function_shift_right()
753{
754  owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10);
755  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
756  owl_global_set_needrefresh(&g);
757}
758
759void owl_function_shift_left()
760{
761  int shift;
762
763  shift=owl_global_get_rightshift(&g);
764  if (shift>=10) {
765    owl_global_set_rightshift(&g, shift-10);
766    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
767    owl_global_set_needrefresh(&g);
768  } else {
769    owl_function_beep();
770    owl_function_makemsg("Already full left");
771  }
772}
773
774void owl_function_unsuball()
775{
776  unsuball();
777  owl_function_makemsg("Unsubscribed from all messages.");
778}
779
780void owl_function_loadsubs(char *file)
781{
782  int ret;
783
784  ret=owl_zephyr_loadsubs(file);
785
786  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
787  if (ret==0) {
788    owl_function_makemsg("Subscribed to messages from file.");
789  } else if (ret==-1) {
790    owl_function_error("Could not open file.");
791  } else {
792    owl_function_error("Error subscribing to messages from file.");
793  }
794}
795
796void owl_function_loadloginsubs(char *file)
797{
798  int ret;
799
800  ret=owl_zephyr_loadloginsubs(file);
801
802  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
803  if (ret==0) {
804    owl_function_makemsg("Subscribed to login messages from file.");
805  } else if (ret==-1) {
806    owl_function_error("Could not open file for login subscriptions.");
807  } else {
808    owl_function_error("Error subscribing to login messages from file.");
809  }
810}
811
812void owl_function_suspend()
813{
814  endwin();
815  printf("\n");
816  kill(getpid(), SIGSTOP);
817
818  /* resize to reinitialize all the windows when we come back */
819  owl_command_resize();
820}
821
822void owl_function_zaway_toggle()
823{
824  if (!owl_global_is_zaway(&g)) {
825    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
826    owl_function_zaway_on();
827  } else {
828    owl_function_zaway_off();
829  }
830}
831
832void owl_function_zaway_on()
833{
834  owl_global_set_zaway_on(&g);
835  owl_aim_set_awaymsg(owl_global_get_zaway_msg(&g));
836  owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g));
837}
838
839void owl_function_zaway_off()
840{
841  owl_global_set_zaway_off(&g);
842  owl_function_makemsg("zaway off");
843}
844
845void owl_function_quit()
846{
847  char *ret;
848 
849  /* zlog out if we need to */
850  if (owl_global_is_shutdownlogout(&g)) {
851    owl_zephyr_zlog_out();
852  }
853
854  /* execute the commands in shutdown */
855  ret = owl_perlconfig_execute("owl::shutdown();");
856  if (ret) owl_free(ret);
857
858  /* signal our child process, if any */
859  if (owl_global_get_newmsgproc_pid(&g)) {
860    kill(owl_global_get_newmsgproc_pid(&g), SIGHUP);
861  }
862
863  /* final clean up */
864  owl_zephyr_shutdown();
865  endwin();
866  owl_function_debugmsg("Quitting Owl");
867  exit(0);
868}
869
870void owl_function_openurl()
871{
872  /* visit the first url in the current message */
873  owl_message *m;
874  owl_view *v;
875  char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
876  int webbrowser;
877
878  webbrowser = owl_global_get_webbrowser(&g);
879
880  if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
881    owl_function_error("No browser selected");
882    return;
883  }
884
885  v=owl_global_get_current_view(&g);
886 
887  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
888
889  if (!m || owl_view_get_size(v)==0) {
890    owl_function_error("No current message selected");
891    return;
892  }
893
894  text=owl_message_get_text(m);
895
896  /* First look for a good URL */ 
897  if ((ptr1=strstr(text, "http://"))!=NULL) {
898    ptr2=strpbrk(ptr1, " \n\t");
899    if (ptr2) {
900      strncpy(url, ptr1, ptr2-ptr1+1);
901      url[ptr2-ptr1+1]='\0';
902    } else {
903      strcpy(url, ptr1);
904    }
905
906    /* if we had <http strip a trailing > */
907    if (ptr1>text && ptr1[-1]=='<') {
908      if (url[strlen(url)-1]=='>') {
909        url[strlen(url)-1]='\0';
910      }
911    }
912  } else if ((ptr1=strstr(text, "https://"))!=NULL) {
913    /* Look for an https URL */ 
914    ptr2=strpbrk(ptr1, " \n\t");
915    if (ptr2) {
916      strncpy(url, ptr1, ptr2-ptr1+1);
917      url[ptr2-ptr1+1]='\0';
918    } else {
919      strcpy(url, ptr1);
920    }
921   
922    /* if we had <http strip a trailing > */
923    if (ptr1>text && ptr1[-1]=='<') {
924      if (url[strlen(url)-1]=='>') {
925        url[strlen(url)-1]='\0';
926      }
927    }
928  } else if ((ptr1=strstr(text, "www."))!=NULL) {
929    /* if we can't find a real url look for www.something */
930    ptr2=strpbrk(ptr1, " \n\t");
931    if (ptr2) {
932      strncpy(url, ptr1, ptr2-ptr1+1);
933      url[ptr2-ptr1+1]='\0';
934    } else {
935      strcpy(url, ptr1);
936    }
937  } else {
938    owl_function_beep();
939    owl_function_error("Could not find URL to open.");
940    return;
941  }
942
943  /* Make sure there aren't any quotes or \'s in the url */
944  for (ptr1 = url; *ptr1; ptr1++) {
945    if (*ptr1 == '"' || *ptr1 == '\\') {
946      owl_function_beep();
947      owl_function_error("URL contains invalid characters.");
948      return;
949    }
950  }
951 
952  /* NOTE: There are potentially serious security issues here... */
953
954  /* open the page */
955  owl_function_makemsg("Opening %s", url);
956  if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {
957    snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);
958    system(tmpbuff); 
959  } else if (webbrowser == OWL_WEBBROWSER_GALEON) {
960    snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);
961    system(tmpbuff); 
962  } else if (webbrowser == OWL_WEBBROWSER_OPERA) {
963    snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);
964    system(tmpbuff); 
965  }
966}
967
968void owl_function_calculate_topmsg(int direction)
969{
970  int recwinlines, topmsg, curmsg;
971  owl_view *v;
972
973  v=owl_global_get_current_view(&g);
974  curmsg=owl_global_get_curmsg(&g);
975  topmsg=owl_global_get_topmsg(&g);
976  recwinlines=owl_global_get_recwin_lines(&g);
977
978  /*
979  if (owl_view_get_size(v) < 1) {
980    return;
981  }
982  */
983
984  switch (owl_global_get_scrollmode(&g)) {
985  case OWL_SCROLLMODE_TOP:
986    topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines);
987    break;
988  case OWL_SCROLLMODE_NEARTOP:
989    topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines);
990    break;
991  case OWL_SCROLLMODE_CENTER:
992    topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines);
993    break;
994  case OWL_SCROLLMODE_PAGED:
995    topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0);
996    break;
997  case OWL_SCROLLMODE_PAGEDCENTER:
998    topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1);
999    break;
1000  case OWL_SCROLLMODE_NORMAL:
1001  default:
1002    topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines);
1003  }
1004  owl_function_debugmsg("Calculated a topmsg of %i", topmsg);
1005  owl_global_set_topmsg(&g, topmsg);
1006}
1007
1008/* Returns what the new topmsg should be. 
1009 * Passed the last direction of movement,
1010 * the current view,
1011 * the current message number in the view,
1012 * the top message currently being displayed,
1013 * and the number of lines in the recwin.
1014 */
1015int owl_function_calculate_topmsg_top(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1016{
1017  return(curmsg);
1018}
1019
1020int owl_function_calculate_topmsg_neartop(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1021{
1022  if (curmsg>0 
1023      && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1))
1024          <  recwinlines/2)) {
1025    return(curmsg-1);
1026  } else {
1027    return(curmsg);
1028  }
1029}
1030 
1031int owl_function_calculate_topmsg_center(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1032{
1033  int i, last, lines;
1034
1035  last = curmsg;
1036  lines = 0;
1037  for (i=curmsg-1; i>=0; i--) {
1038    lines += owl_message_get_numlines(owl_view_get_element(v, i));
1039    if (lines > recwinlines/2) break;
1040    last = i;
1041  }
1042  return(last);
1043}
1044 
1045int owl_function_calculate_topmsg_paged(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page)
1046{
1047  int i, last, lines, savey;
1048 
1049  /* If we're off the top of the screen, scroll up such that the
1050   * curmsg is near the botton of the screen. */
1051  if (curmsg < topmsg) {
1052    last = curmsg;
1053    lines = 0;
1054    for (i=curmsg; i>=0; i--) {
1055      lines += owl_message_get_numlines(owl_view_get_element(v, i));
1056      if (lines > recwinlines) break;
1057    last = i;
1058    }
1059    if (center_on_page) {
1060      return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines));
1061    } else {
1062      return(last);
1063    }
1064  }
1065
1066  /* Find number of lines from top to bottom of curmsg (store in savey) */
1067  savey=0;
1068  for (i=topmsg; i<=curmsg; i++) {
1069    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
1070  }
1071
1072  /* if we're off the bottom of the screen, scroll down */
1073  if (savey > recwinlines) {
1074    if (center_on_page) {
1075      return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines));
1076    } else {
1077      return(curmsg);
1078    }
1079  }
1080
1081  /* else just stay as we are... */
1082  return(topmsg);
1083}
1084
1085int owl_function_calculate_topmsg_normal(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1086{
1087  int savey, j, i, foo, y;
1088
1089  if (curmsg<0) return(topmsg);
1090   
1091  /* If we're off the top of the screen then center */
1092  if (curmsg<topmsg) {
1093    topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines);
1094  }
1095
1096  /* Find number of lines from top to bottom of curmsg (store in savey) */
1097  savey=0;
1098  for (i=topmsg; i<=curmsg; i++) {
1099    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
1100  }
1101
1102  /* If we're off the bottom of the screen, set the topmsg to curmsg
1103   * and scroll upwards */
1104  if (savey > recwinlines) {
1105    topmsg=curmsg;
1106    savey=owl_message_get_numlines(owl_view_get_element(v, i));
1107    direction=OWL_DIRECTION_UPWARDS;
1108  }
1109 
1110  /* If our bottom line is less than 1/4 down the screen then scroll up */
1111  if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) {
1112    if (savey < (recwinlines / 4)) {
1113      y=0;
1114      for (j=curmsg; j>=0; j--) {
1115        foo=owl_message_get_numlines(owl_view_get_element(v, j));
1116        /* will we run the curmsg off the screen? */
1117        if ((foo+y) >= recwinlines) {
1118          j++;
1119          if (j>curmsg) j=curmsg;
1120          break;
1121        }
1122        /* have saved 1/2 the screen space? */
1123        y+=foo;
1124        if (y > (recwinlines / 2)) break;
1125      }
1126      if (j<0) j=0;
1127      return(j);
1128    }
1129  }
1130
1131  if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) {
1132    /* If curmsg bottom line is more than 3/4 down the screen then scroll down */
1133    if (savey > ((recwinlines * 3)/4)) {
1134      y=0;
1135      /* count lines from the top until we can save 1/2 the screen size */
1136      for (j=topmsg; j<curmsg; j++) {
1137        y+=owl_message_get_numlines(owl_view_get_element(v, j));
1138        if (y > (recwinlines / 2)) break;
1139      }
1140      if (j==curmsg) {
1141        j--;
1142      }
1143      return(j+1);
1144    }
1145  }
1146
1147  return(topmsg);
1148}
1149
1150void owl_function_resize()
1151{
1152  owl_global_set_resize_pending(&g);
1153}
1154
1155void owl_function_run_buffercommand()
1156{
1157  char *buff, *ptr;
1158
1159  buff=owl_global_get_buffercommand(&g);
1160  if (!strncmp(buff, "zwrite ", 7)) {
1161    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
1162  } else if (!strncmp(buff, "zcrypt ", 7)) {
1163    owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
1164  } else if (!strncmp(buff, "aimwrite ", 9)) {
1165    owl_function_aimwrite(buff+9);
1166  } else if (!strncmp(buff, "loopwrite", 9) || !strncmp(buff, "loopwrite ", 10)) {
1167    owl_function_loopwrite();
1168  } else if (!strncmp(buff, "aimlogin ", 9)) {
1169    ptr=owl_sprintf("%s %s", buff, owl_global_get_response(&g));
1170    owl_function_command(ptr);
1171    owl_free(ptr);
1172  } else {
1173    owl_function_error("Internal error: invalid buffercommand %s", buff);
1174  }
1175}
1176
1177void owl_function_debugmsg(char *fmt, ...)
1178{
1179  FILE *file;
1180  time_t now;
1181  char buff1[LINE], buff2[LINE];
1182  va_list ap;
1183  va_start(ap, fmt);
1184
1185  if (!owl_global_is_debug_fast(&g)) return;
1186
1187  file=fopen(owl_global_get_debug_file(&g), "a");
1188  if (!file) return;
1189
1190  now=time(NULL);
1191  strcpy(buff1, ctime(&now));
1192  buff1[strlen(buff1)-1]='\0';
1193
1194  owl_global_get_runtime_string(&g, buff2);
1195 
1196  fprintf(file, "[%i -  %s - %s]: ", (int) getpid(), buff1, buff2);
1197  vfprintf(file, fmt, ap);
1198  fprintf(file, "\n");
1199  fclose(file);
1200
1201  va_end(ap);
1202}
1203
1204void owl_function_refresh()
1205{
1206  owl_function_resize();
1207}
1208
1209void owl_function_beep()
1210{
1211  if (owl_global_is_bell(&g)) {
1212    beep();
1213    owl_global_set_needrefresh(&g); /* do we really need this? */
1214  }
1215}
1216
1217void owl_function_subscribe(char *class, char *inst, char *recip)
1218{
1219  int ret;
1220
1221  ret=owl_zephyr_sub(class, inst, recip);
1222  if (ret) {
1223    owl_function_error("Error subscribing.");
1224  } else {
1225    owl_function_makemsg("Subscribed.");
1226  }
1227}
1228
1229void owl_function_unsubscribe(char *class, char *inst, char *recip)
1230{
1231  int ret;
1232
1233  ret=owl_zephyr_unsub(class, inst, recip);
1234  if (ret) {
1235    owl_function_error("Error subscribing.");
1236  } else {
1237    owl_function_makemsg("Unsubscribed.");
1238  }
1239}
1240
1241void owl_function_set_cursor(WINDOW *win)
1242{
1243  wnoutrefresh(win);
1244}
1245
1246void owl_function_full_redisplay()
1247{
1248  redrawwin(owl_global_get_curs_recwin(&g));
1249  redrawwin(owl_global_get_curs_sepwin(&g));
1250  redrawwin(owl_global_get_curs_typwin(&g));
1251  redrawwin(owl_global_get_curs_msgwin(&g));
1252
1253  wnoutrefresh(owl_global_get_curs_recwin(&g));
1254  wnoutrefresh(owl_global_get_curs_sepwin(&g));
1255  wnoutrefresh(owl_global_get_curs_typwin(&g));
1256  wnoutrefresh(owl_global_get_curs_msgwin(&g));
1257 
1258  sepbar("");
1259  owl_function_makemsg("");
1260
1261  owl_global_set_needrefresh(&g);
1262}
1263
1264void owl_function_popless_text(char *text)
1265{
1266  owl_popwin *pw;
1267  owl_viewwin *v;
1268
1269  pw=owl_global_get_popwin(&g);
1270  v=owl_global_get_viewwin(&g);
1271
1272  owl_popwin_up(pw);
1273  owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
1274                        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
1275                        text);
1276  owl_popwin_refresh(pw);
1277  owl_viewwin_redisplay(v, 0);
1278  owl_global_set_needrefresh(&g);
1279}
1280
1281void owl_function_popless_fmtext(owl_fmtext *fm)
1282{
1283  owl_popwin *pw;
1284  owl_viewwin *v;
1285
1286  pw=owl_global_get_popwin(&g);
1287  v=owl_global_get_viewwin(&g);
1288
1289  owl_popwin_up(pw);
1290  owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
1291                   owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
1292                   fm);
1293  owl_popwin_refresh(pw);
1294  owl_viewwin_redisplay(v, 0);
1295  owl_global_set_needrefresh(&g);
1296}
1297
1298void owl_function_popless_file(char *filename)
1299{
1300  owl_fmtext fm;
1301  FILE *file;
1302  char buff[1024];
1303
1304  file=fopen(filename, "r");
1305  if (!file) {
1306    owl_function_error("Could not open file: %s", filename);
1307    return;
1308  }
1309
1310  owl_fmtext_init_null(&fm);
1311  while (fgets(buff, 1024, file)) {
1312    owl_fmtext_append_normal(&fm, buff);
1313    owl_fmtext_append_normal(&fm, "\n");
1314  }
1315
1316  owl_function_popless_fmtext(&fm);
1317  owl_fmtext_free(&fm);
1318  fclose(file);
1319}
1320
1321void owl_function_about()
1322{
1323  char buff[5000];
1324
1325  sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING);
1326  strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n");
1327  strcat(buff, "Institute of Technology.  The first version, 0.5, was\n");
1328  strcat(buff, "released in March 2002.\n");
1329  strcat(buff, "\n");
1330  strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n");
1331  strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n");
1332  strcat(buff, "between Witches and Wizards.\n");
1333  strcat(buff, "\n");
1334  strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n");
1335  strcat(buff, "\n");
1336  strcat(buff, "Permission to use, copy, modify, and distribute this\n");
1337  strcat(buff, "software and its documentation for any purpose and without\n");
1338  strcat(buff, "fee is hereby granted, provided that the above copyright\n");
1339  strcat(buff, "notice and this permission notice appear in all copies\n");
1340  strcat(buff, "and in supporting documentation.  No representation is\n");
1341  strcat(buff, "made about the suitability of this software for any\n");
1342  strcat(buff, "purpose.  It is provided \"as is\" without express\n");
1343  strcat(buff, "or implied warranty.\n");
1344  owl_function_popless_text(buff);
1345}
1346
1347void owl_function_info()
1348{
1349  owl_message *m;
1350  owl_fmtext fm, attrfm;
1351  char buff[10000];
1352  owl_view *v;
1353#ifdef HAVE_LIBZEPHYR
1354  ZNotice_t *n;
1355#endif
1356
1357  owl_fmtext_init_null(&fm);
1358 
1359  v=owl_global_get_current_view(&g);
1360  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1361  if (!m || owl_view_get_size(v)==0) {
1362    owl_function_error("No message selected\n");
1363    return;
1364  }
1365
1366  owl_fmtext_append_bold(&fm, "General Information:\n");
1367  owl_fmtext_append_normal(&fm, "  Msg Id    : ");
1368  sprintf(buff, "%i", owl_message_get_id(m));
1369  owl_fmtext_append_normal(&fm, buff);
1370  owl_fmtext_append_normal(&fm, "\n");
1371
1372  owl_fmtext_append_normal(&fm, "  Type      : ");
1373  owl_fmtext_append_bold(&fm, owl_message_get_type(m));
1374  owl_fmtext_append_normal(&fm, "\n");
1375
1376  if (owl_message_is_direction_in(m)) {
1377    owl_fmtext_append_normal(&fm, "  Direction : in\n");
1378  } else if (owl_message_is_direction_out(m)) {
1379    owl_fmtext_append_normal(&fm, "  Direction : out\n");
1380  } else if (owl_message_is_direction_none(m)) {
1381    owl_fmtext_append_normal(&fm, "  Direction : none\n");
1382  } else {
1383    owl_fmtext_append_normal(&fm, "  Direction : unknown\n");
1384  }
1385
1386  owl_fmtext_append_normal(&fm, "  Time      : ");
1387  owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
1388  owl_fmtext_append_normal(&fm, "\n");
1389
1390  if (!owl_message_is_type_admin(m)) {
1391    owl_fmtext_append_normal(&fm, "  Sender    : ");
1392    owl_fmtext_append_normal(&fm, owl_message_get_sender(m));
1393    owl_fmtext_append_normal(&fm, "\n");
1394   
1395    owl_fmtext_append_normal(&fm, "  Recipient : ");
1396    owl_fmtext_append_normal(&fm, owl_message_get_recipient(m));
1397    owl_fmtext_append_normal(&fm, "\n");
1398  }
1399   
1400  if (owl_message_is_type_zephyr(m)) {
1401    owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n");
1402   
1403    owl_fmtext_append_normal(&fm, "  Class     : ");
1404    owl_fmtext_append_normal(&fm, owl_message_get_class(m));
1405    owl_fmtext_append_normal(&fm, "\n");
1406    owl_fmtext_append_normal(&fm, "  Instance  : ");
1407    owl_fmtext_append_normal(&fm, owl_message_get_instance(m));
1408    owl_fmtext_append_normal(&fm, "\n");
1409    owl_fmtext_append_normal(&fm, "  Opcode    : ");
1410    owl_fmtext_append_normal(&fm, owl_message_get_opcode(m));
1411    owl_fmtext_append_normal(&fm, "\n");
1412   
1413    owl_fmtext_append_normal(&fm, "  Time      : ");
1414    owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
1415    owl_fmtext_append_normal(&fm, "\n");
1416#ifdef HAVE_LIBZEPHYR
1417    if (owl_message_is_direction_in(m)) {
1418      char *ptr, tmpbuff[1024];
1419      int i, j, fields, len;
1420
1421      n=owl_message_get_notice(m);
1422
1423      owl_fmtext_append_normal(&fm, "  Kind      : ");
1424      if (n->z_kind==UNSAFE) {
1425        owl_fmtext_append_normal(&fm, "UNSAFE\n");
1426      } else if (n->z_kind==UNACKED) {
1427        owl_fmtext_append_normal(&fm, "UNACKED\n");
1428      } else if (n->z_kind==ACKED) {
1429        owl_fmtext_append_normal(&fm, "ACKED\n");
1430      } else if (n->z_kind==HMACK) {
1431        owl_fmtext_append_normal(&fm, "HMACK\n");
1432      } else if (n->z_kind==HMCTL) {
1433        owl_fmtext_append_normal(&fm, "HMCTL\n");
1434      } else if (n->z_kind==SERVACK) {
1435        owl_fmtext_append_normal(&fm, "SERVACK\n");
1436      } else if (n->z_kind==SERVNAK) {
1437        owl_fmtext_append_normal(&fm, "SERVNACK\n");
1438      } else if (n->z_kind==CLIENTACK) {
1439        owl_fmtext_append_normal(&fm, "CLIENTACK\n");
1440      } else if (n->z_kind==STAT) {
1441        owl_fmtext_append_normal(&fm, "STAT\n");
1442      } else {
1443        owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n");
1444      }
1445      owl_fmtext_append_normal(&fm, "  Host      : ");
1446      owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
1447      owl_fmtext_append_normal(&fm, "\n");
1448      sprintf(buff, "  Port      : %i\n", n->z_port);
1449      owl_fmtext_append_normal(&fm, buff);
1450
1451      owl_fmtext_append_normal(&fm,    "  Auth      : ");
1452      owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n));
1453      owl_fmtext_append_normal(&fm, "\n");
1454
1455      /* fix this */
1456      sprintf(buff, "  Checkd Ath: %i\n", n->z_checked_auth);
1457      sprintf(buff, "%s  Multi notc: %s\n", buff, n->z_multinotice);
1458      sprintf(buff, "%s  Num other : %i\n", buff, n->z_num_other_fields);
1459      sprintf(buff, "%s  Msg Len   : %i\n", buff, n->z_message_len);
1460      owl_fmtext_append_normal(&fm, buff);
1461     
1462      sprintf(buff, "  Fields    : %i\n", owl_zephyr_get_num_fields(n));
1463      owl_fmtext_append_normal(&fm, buff);
1464     
1465      fields=owl_zephyr_get_num_fields(n);
1466      for (i=0; i<fields; i++) {
1467        sprintf(buff, "  Field %i   : ", i+1);
1468       
1469        ptr=owl_zephyr_get_field(n, i+1, &len);
1470        if (!ptr) break;
1471        if (len<30) {
1472          strncpy(tmpbuff, ptr, len);
1473          tmpbuff[len]='\0';
1474        } else {
1475          strncpy(tmpbuff, ptr, 30);
1476          tmpbuff[30]='\0';
1477          strcat(tmpbuff, "...");
1478        }
1479       
1480        for (j=0; j<strlen(tmpbuff); j++) {
1481          if (tmpbuff[j]=='\n') tmpbuff[j]='~';
1482          if (tmpbuff[j]=='\r') tmpbuff[j]='!';
1483        }
1484       
1485        strcat(buff, tmpbuff);
1486        strcat(buff, "\n");
1487        owl_fmtext_append_normal(&fm, buff);
1488      }
1489      owl_fmtext_append_normal(&fm, "  Default Fm:");
1490      owl_fmtext_append_normal(&fm, n->z_default_format);
1491    }
1492#endif   
1493  }
1494
1495  if (owl_message_is_type_aim(m)) {
1496    owl_fmtext_append_bold(&fm, "\nAIM Specific Information:\n");
1497  }
1498
1499  owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n");
1500  owl_message_attributes_tofmtext(m, &attrfm);
1501  owl_fmtext_append_fmtext(&fm, &attrfm);
1502 
1503  owl_function_popless_fmtext(&fm);
1504  owl_fmtext_free(&fm);
1505  owl_fmtext_free(&attrfm);
1506}
1507
1508/* print the current message in a popup window.
1509 * Use the 'default' style regardless of whatever
1510 * style the user may be using
1511 */
1512void owl_function_curmsg_to_popwin()
1513{
1514  owl_popwin *pw;
1515  owl_view *v;
1516  owl_message *m;
1517  owl_style *s;
1518  owl_fmtext fm;
1519
1520  v=owl_global_get_current_view(&g);
1521  s=owl_global_get_style_by_name(&g, "default");
1522  pw=owl_global_get_popwin(&g);
1523
1524  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1525
1526  if (!m || owl_view_get_size(v)==0) {
1527    owl_function_error("No current message");
1528    return;
1529  }
1530
1531  owl_fmtext_init_null(&fm);
1532  owl_style_get_formattext(s, &fm, m);
1533
1534  owl_function_popless_fmtext(&fm);
1535  owl_fmtext_free(&fm);
1536}
1537
1538void owl_function_page_curmsg(int step)
1539{
1540  /* scroll down or up within the current message IF the message is truncated */
1541
1542  int offset, curmsg, lines;
1543  owl_view *v;
1544  owl_message *m;
1545
1546  offset=owl_global_get_curmsg_vert_offset(&g);
1547  v=owl_global_get_current_view(&g);
1548  curmsg=owl_global_get_curmsg(&g);
1549  m=owl_view_get_element(v, curmsg);
1550  if (!m || owl_view_get_size(v)==0) return;
1551  lines=owl_message_get_numlines(m);
1552
1553  if (offset==0) {
1554    /* Bail if the curmsg isn't the last one displayed */
1555    if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) {
1556      owl_function_makemsg("The entire message is already displayed");
1557      return;
1558    }
1559   
1560    /* Bail if we're not truncated */
1561    if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
1562      owl_function_makemsg("The entire message is already displayed");
1563      return;
1564    }
1565  }
1566 
1567 
1568  /* don't scroll past the last line */
1569  if (step>0) {
1570    if (offset+step > lines-1) {
1571      owl_global_set_curmsg_vert_offset(&g, lines-1);
1572    } else {
1573      owl_global_set_curmsg_vert_offset(&g, offset+step);
1574    }
1575  }
1576
1577  /* would we be before the beginning of the message? */
1578  if (step<0) {
1579    if (offset+step<0) {
1580      owl_global_set_curmsg_vert_offset(&g, 0);
1581    } else {
1582      owl_global_set_curmsg_vert_offset(&g, offset+step);
1583    }
1584  }
1585 
1586  /* redisplay */
1587  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1588  owl_global_set_needrefresh(&g);
1589}
1590
1591void owl_function_resize_typwin(int newsize)
1592{
1593  owl_global_set_typwin_lines(&g, newsize);
1594  owl_function_resize();
1595}
1596
1597void owl_function_typwin_grow()
1598{
1599  int i;
1600
1601  i=owl_global_get_typwin_lines(&g);
1602  owl_function_resize_typwin(i+1);
1603}
1604
1605void owl_function_typwin_shrink()
1606{
1607  int i;
1608
1609  i=owl_global_get_typwin_lines(&g);
1610  if (i>2) {
1611    owl_function_resize_typwin(i-1);
1612  }
1613}
1614
1615void owl_function_mainwin_pagedown()
1616{
1617  int i;
1618
1619  i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g));
1620  if (i<0) return;
1621  if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g))
1622      && (owl_global_get_curmsg(&g) < i)
1623      && (i>0)) {
1624    i--;
1625  }
1626  owl_global_set_curmsg(&g, i);
1627  owl_function_nextmsg();
1628}
1629
1630void owl_function_mainwin_pageup()
1631{
1632  owl_global_set_curmsg(&g, owl_global_get_topmsg(&g));
1633  owl_function_prevmsg();
1634}
1635
1636void owl_function_getsubs()
1637{
1638  char *buff;
1639
1640  buff=owl_zephyr_getsubs();
1641
1642  if (buff) {
1643    owl_function_popless_text(buff);
1644  } else {
1645    owl_function_popless_text("Error getting subscriptions");
1646  }
1647           
1648  owl_free(buff);
1649}
1650
1651#define PABUFLEN 5000
1652void owl_function_printallvars()
1653{
1654  char buff[PABUFLEN], *pos, *name;
1655  owl_list varnames;
1656  int i, numvarnames, rem;
1657
1658  pos = buff;
1659  pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");
1660  pos += sprintf(pos, "%-20s   %s\n",  "--------", "-----");
1661  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1662  rem = (buff+PABUFLEN)-pos-1;
1663  numvarnames = owl_list_get_size(&varnames);
1664  for (i=0; i<numvarnames; i++) {
1665    name = owl_list_get_element(&varnames, i);
1666    if (name && name[0]!='_') {
1667      rem = (buff+PABUFLEN)-pos-1;   
1668      pos += snprintf(pos, rem, "\n%-20s = ", name);
1669      rem = (buff+PABUFLEN)-pos-1;   
1670      owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem);
1671      pos = buff+strlen(buff);
1672    }
1673  }
1674  rem = (buff+PABUFLEN)-pos-1;   
1675  snprintf(pos, rem, "\n");
1676  owl_variable_dict_namelist_free(&varnames);
1677 
1678  owl_function_popless_text(buff);
1679}
1680
1681void owl_function_show_variables()
1682{
1683  owl_list varnames;
1684  owl_fmtext fm; 
1685  int i, numvarnames;
1686  char *varname;
1687
1688  owl_fmtext_init_null(&fm);
1689  owl_fmtext_append_bold(&fm, 
1690      "Variables: (use 'show variable <name>' for details)\n");
1691  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1692  numvarnames = owl_list_get_size(&varnames);
1693  for (i=0; i<numvarnames; i++) {
1694    varname = owl_list_get_element(&varnames, i);
1695    if (varname && varname[0]!='_') {
1696      owl_variable_describe(owl_global_get_vardict(&g), varname, &fm);
1697    }
1698  }
1699  owl_variable_dict_namelist_free(&varnames);
1700  owl_function_popless_fmtext(&fm);
1701  owl_fmtext_free(&fm);
1702}
1703
1704void owl_function_show_variable(char *name)
1705{
1706  owl_fmtext fm; 
1707
1708  owl_fmtext_init_null(&fm);
1709  owl_variable_get_help(owl_global_get_vardict(&g), name, &fm);
1710  owl_function_popless_fmtext(&fm);
1711  owl_fmtext_free(&fm); 
1712}
1713
1714/* note: this applies to global message list, not to view.
1715 * If flag is 1, deletes.  If flag is 0, undeletes. */
1716void owl_function_delete_by_id(int id, int flag)
1717{
1718  owl_messagelist *ml;
1719  owl_message *m;
1720  ml = owl_global_get_msglist(&g);
1721  m = owl_messagelist_get_by_id(ml, id);
1722  if (m) {
1723    if (flag == 1) {
1724      owl_message_mark_delete(m);
1725    } else if (flag == 0) {
1726      owl_message_unmark_delete(m);
1727    }
1728    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1729    owl_global_set_needrefresh(&g);
1730  } else {
1731    owl_function_error("No message with id %d: unable to mark for (un)delete",id);
1732  }
1733}
1734
1735void owl_function_delete_automsgs()
1736{
1737  /* mark for deletion all messages in the current view that match the
1738   * 'trash' filter */
1739
1740  int i, j, count;
1741  owl_message *m;
1742  owl_view *v;
1743  owl_filter *f;
1744
1745  /* get the trash filter */
1746  f=owl_global_get_filter(&g, "trash");
1747  if (!f) {
1748    owl_function_error("No trash filter defined");
1749    return;
1750  }
1751
1752  v=owl_global_get_current_view(&g);
1753
1754  count=0;
1755  j=owl_view_get_size(v);
1756  for (i=0; i<j; i++) {
1757    m=owl_view_get_element(v, i);
1758    if (owl_filter_message_match(f, m)) {
1759      count++;
1760      owl_message_mark_delete(m);
1761    }
1762  }
1763  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1764  owl_function_makemsg("%i messages marked for deletion", count);
1765  owl_global_set_needrefresh(&g);
1766}
1767
1768void owl_function_status()
1769{
1770  char buff[5000];
1771  time_t start;
1772  int up, days, hours, minutes;
1773  owl_fmtext fm;
1774
1775  owl_fmtext_init_null(&fm);
1776
1777  start=owl_global_get_starttime(&g);
1778
1779  owl_fmtext_append_normal(&fm, "General Information:\n");
1780
1781  owl_fmtext_append_normal(&fm, "  Version: ");
1782  owl_fmtext_append_normal(&fm, OWL_VERSION_STRING);
1783  owl_fmtext_append_normal(&fm, "\n");
1784
1785  owl_fmtext_append_normal(&fm, "  Startup Arugments: ");
1786  owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g));
1787  owl_fmtext_append_normal(&fm, "\n");
1788  sprintf(buff, "  Startup Time: %s", ctime(&start));
1789  owl_fmtext_append_normal(&fm, buff);
1790
1791  up=owl_global_get_runtime(&g);
1792  days=up/86400;
1793  up-=days*86400;
1794  hours=up/3600;
1795  up-=hours*3600;
1796  minutes=up/60;
1797  up-=minutes*60;
1798  sprintf(buff, "  Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up);
1799  owl_fmtext_append_normal(&fm, buff);
1800
1801  owl_fmtext_append_normal(&fm, "\nProtocol Options:\n");
1802  owl_fmtext_append_normal(&fm, "  Zephyr included    : ");
1803  if (owl_global_is_havezephyr(&g)) {
1804    owl_fmtext_append_normal(&fm, "yes\n");
1805  } else {
1806    owl_fmtext_append_normal(&fm, "no\n");
1807  }
1808  owl_fmtext_append_normal(&fm, "  AIM included       : yes\n");
1809  owl_fmtext_append_normal(&fm, "  Loopback included  : yes\n");
1810
1811
1812  owl_fmtext_append_normal(&fm, "\nBuild Options:\n");
1813  owl_fmtext_append_normal(&fm, "  Stderr redirection : ");
1814#if OWL_STDERR_REDIR
1815  owl_fmtext_append_normal(&fm, "yes\n");
1816#else
1817  owl_fmtext_append_normal(&fm, "no\n");
1818#endif
1819 
1820
1821  owl_fmtext_append_normal(&fm, "\nMemory Usage:\n");
1822  owl_fmtext_append_normal(&fm, "  Not currently available.\n");
1823  /*
1824  sprintf(buff, "%sMemory Malloced: %i\n", buff, owl_global_get_malloced(&g));
1825  sprintf(buff, "%sMemory Freed: %i\n", buff, owl_global_get_freed(&g));
1826  sprintf(buff, "%sMemory In Use: %i\n", buff, owl_global_get_meminuse(&g));
1827  */
1828
1829  owl_fmtext_append_normal(&fm, "\nAIM Status:\n");
1830  owl_fmtext_append_normal(&fm, "  Logged in: ");
1831  if (owl_global_is_aimloggedin(&g)) {
1832    owl_fmtext_append_normal(&fm, owl_global_get_aim_screenname(&g));
1833    owl_fmtext_append_normal(&fm, "\n");
1834  } else {
1835    owl_fmtext_append_normal(&fm, "(not logged in)\n");
1836  }
1837
1838  owl_fmtext_append_normal(&fm, "  Processing events: ");
1839  if (owl_global_is_doaimevents(&g)) {
1840    owl_fmtext_append_normal(&fm, "yes\n");
1841  } else {
1842    owl_fmtext_append_normal(&fm, "no\n");
1843  }
1844
1845  owl_function_popless_fmtext(&fm);
1846  owl_fmtext_free(&fm);
1847}
1848
1849void owl_function_show_term()
1850{
1851  owl_fmtext fm;
1852  char buff[LINE];
1853
1854  owl_fmtext_init_null(&fm);
1855  sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",
1856          owl_global_get_lines(&g),
1857          owl_global_get_cols(&g));
1858  owl_fmtext_append_normal(&fm, buff);
1859
1860  if (owl_global_get_hascolors(&g)) {
1861    owl_fmtext_append_normal(&fm, "Color: Yes\n");
1862    sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
1863    owl_fmtext_append_normal(&fm, buff);
1864    sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
1865    owl_fmtext_append_normal(&fm, buff);
1866  } else {
1867    owl_fmtext_append_normal(&fm, "Color: No\n");
1868  }
1869
1870  owl_function_popless_fmtext(&fm);
1871  owl_fmtext_free(&fm);
1872}
1873
1874/* if type = 0 then normal reply.
1875 * if type = 1 then it's a reply to sender
1876 * if enter = 0 then allow the command to be edited
1877 * if enter = 1 then don't wait for editing
1878 */
1879void owl_function_reply(int type, int enter)
1880{
1881  char *buff=NULL, *oldbuff;
1882  owl_message *m;
1883  owl_filter *f;
1884 
1885  if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
1886    owl_function_error("No message selected");
1887  } else {
1888    char *class, *inst, *to, *cc=NULL;
1889   
1890    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
1891    if (!m) {
1892      owl_function_error("No message selected");
1893      return;
1894    }
1895
1896    /* first check if we catch the reply-lockout filter */
1897    f=owl_global_get_filter(&g, "reply-lockout");
1898    if (f) {
1899      if (owl_filter_message_match(f, m)) {
1900        owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter");
1901        return;
1902      }
1903    }
1904
1905    /* admin */
1906    if (owl_message_is_type_admin(m)) {
1907      owl_function_error("You cannot reply to an admin message");
1908      return;
1909    }
1910
1911    /* loopback */
1912    if (owl_message_is_type_loopback(m)) {
1913      owl_function_loopwrite_setup();
1914      return;
1915    }
1916
1917    /* zephyr */
1918    if (owl_message_is_type_zephyr(m)) {
1919      /* if it's a zephyr we sent, send it out the same way again */
1920      if (owl_message_is_direction_out(m)) {
1921        owl_function_zwrite_setup(owl_message_get_zwriteline(m));
1922        owl_global_set_buffercommand(&g, owl_message_get_zwriteline(m));
1923        return;
1924      }
1925
1926      /* Special case a personal reply to a webzephyr user on a class */
1927      if ((type==1) && !strcasecmp(owl_message_get_opcode(m), OWL_WEBZEPHYR_OPCODE)) {
1928        class=OWL_WEBZEPHYR_CLASS;
1929        inst=owl_message_get_sender(m);
1930        to=OWL_WEBZEPHYR_PRINCIPAL;
1931      } else if (!strcasecmp(owl_message_get_class(m), OWL_WEBZEPHYR_CLASS) && owl_message_is_loginout(m)) {
1932        /* Special case LOGIN/LOGOUT notifications on class "webzephyr" */
1933        class=OWL_WEBZEPHYR_CLASS;
1934        inst=owl_message_get_instance(m);
1935        to=OWL_WEBZEPHYR_PRINCIPAL;
1936      } else if (owl_message_is_loginout(m)) {
1937        /* Normal LOGIN/LOGOUT messages */
1938        class="MESSAGE";
1939        inst="PERSONAL";
1940        to=owl_message_get_sender(m);
1941      } else if (type==1) {
1942        /* Personal reply */
1943        class="MESSAGE";
1944        inst="PERSONAL";
1945        to=owl_message_get_sender(m);
1946      } else {
1947        /* General reply */
1948        class=owl_message_get_class(m);
1949        inst=owl_message_get_instance(m);
1950        to=owl_message_get_recipient(m);
1951        cc=owl_message_get_cc(m);
1952        if (!strcmp(to, "") || !strcmp(to, "*")) {
1953          to="";
1954        } else if (to[0]=='@') {
1955          /* leave it, to get the realm */
1956        } else {
1957          to=owl_message_get_sender(m);
1958        }
1959      }
1960       
1961      /* create the command line */
1962      if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
1963        buff=owl_strdup("zcrypt");
1964      } else {
1965        buff = owl_strdup("zwrite");
1966      }
1967      if (strcasecmp(class, "message")) {
1968        buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
1969        owl_free(oldbuff);
1970      }
1971      if (strcasecmp(inst, "personal")) {
1972        buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst));
1973        owl_free(oldbuff);
1974      }
1975      if (*to != '\0') {
1976        char *tmp, *oldtmp, *tmp2;
1977        tmp=short_zuser(to);
1978        if (cc) {
1979          tmp = owl_util_uniq(oldtmp=tmp, cc, "-");
1980          owl_free(oldtmp);
1981          buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp);
1982          owl_free(oldbuff);
1983        } else {
1984          if (owl_global_is_smartstrip(&g)) {
1985            tmp2=tmp;
1986            tmp=owl_zephyr_smartstripped_user(tmp2);
1987            owl_free(tmp2);
1988          }
1989          buff = owl_sprintf("%s %s", oldbuff=buff, tmp);
1990          owl_free(oldbuff);
1991        }
1992        owl_free(tmp);
1993      }
1994      if (cc) owl_free(cc);
1995    }
1996
1997    /* aim */
1998    if (owl_message_is_type_aim(m)) {
1999      if (owl_message_is_direction_out(m)) {
2000        buff=owl_sprintf("aimwrite %s", owl_message_get_recipient(m));
2001      } else {
2002        buff=owl_sprintf("aimwrite %s", owl_message_get_sender(m));
2003      }
2004    }
2005   
2006    if (enter) {
2007      owl_history *hist = owl_global_get_cmd_history(&g);
2008      owl_history_store(hist, buff);
2009      owl_history_reset(hist);
2010      owl_function_command_norv(buff);
2011    } else {
2012      owl_function_start_command(buff);
2013    }
2014    owl_free(buff);
2015  }
2016}
2017
2018void owl_function_zlocate(int argc, char **argv, int auth)
2019{
2020  owl_fmtext fm;
2021  char *ptr, buff[LINE];
2022  int i;
2023
2024  owl_fmtext_init_null(&fm);
2025
2026  for (i=0; i<argc; i++) {
2027    ptr=long_zuser(argv[i]);
2028    owl_zephyr_zlocate(ptr, buff, auth);
2029    owl_fmtext_append_normal(&fm, buff);
2030    owl_free(ptr);
2031  }
2032
2033  owl_function_popless_fmtext(&fm);
2034  owl_fmtext_free(&fm);
2035}
2036
2037void owl_function_start_command(char *line)
2038{
2039  int i, j;
2040  owl_editwin *tw;
2041
2042  tw=owl_global_get_typwin(&g);
2043  owl_global_set_typwin_active(&g);
2044  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
2045                        owl_global_get_cmd_history(&g));
2046
2047  owl_editwin_set_locktext(tw, "command: ");
2048  owl_global_set_needrefresh(&g);
2049
2050  j=strlen(line);
2051  for (i=0; i<j; i++) {
2052    owl_editwin_process_char(tw, line[i]);
2053  }
2054  owl_editwin_redisplay(tw, 0);
2055
2056  owl_context_set_editline(owl_global_get_context(&g), tw);
2057  owl_function_activate_keymap("editline");
2058}
2059
2060void owl_function_start_question(char *line)
2061{
2062  owl_editwin *tw;
2063
2064  tw=owl_global_get_typwin(&g);
2065  owl_global_set_typwin_active(&g);
2066  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
2067
2068  owl_editwin_set_locktext(tw, line);
2069  owl_global_set_needrefresh(&g);
2070
2071  owl_editwin_redisplay(tw, 0);
2072
2073  owl_context_set_editresponse(owl_global_get_context(&g), tw);
2074  owl_function_activate_keymap("editresponse");
2075}
2076
2077void owl_function_start_password(char *line)
2078{
2079  owl_editwin *tw;
2080
2081  tw=owl_global_get_typwin(&g);
2082  owl_global_set_typwin_active(&g);
2083  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
2084  owl_editwin_set_echochar(tw, '*');
2085
2086  owl_editwin_set_locktext(tw, line);
2087  owl_global_set_needrefresh(&g);
2088
2089  owl_editwin_redisplay(tw, 0);
2090
2091  owl_context_set_editresponse(owl_global_get_context(&g), tw);
2092  owl_function_activate_keymap("editresponse");
2093}
2094
2095char *owl_function_exec(int argc, char **argv, char *buff, int type)
2096{
2097  /* if type == 1 display in a popup
2098   * if type == 2 display an admin messages
2099   * if type == 0 return output
2100   * else display in a popup
2101   */
2102  char *newbuff, *redirect = " 2>&1 < /dev/null";
2103  char *out, buff2[1024];
2104  int size;
2105  FILE *p;
2106
2107#if OWL_STDERR_REDIR
2108  redirect = " < /dev/null";
2109#endif
2110
2111  if (argc<2) {
2112    owl_function_error("Wrong number of arguments to the exec command");
2113    return NULL;
2114  }
2115
2116  buff = skiptokens(buff, 1);
2117  newbuff = owl_malloc(strlen(buff)+strlen(redirect)+1);
2118  strcpy(newbuff, buff);
2119  strcat(newbuff, redirect);
2120
2121  p=popen(newbuff, "r");
2122  out=owl_malloc(1024);
2123  size=1024;
2124  strcpy(out, "");
2125  while (fgets(buff2, 1024, p)!=NULL) {
2126    size+=1024;
2127    out=owl_realloc(out, size);
2128    strcat(out, buff2);
2129  }
2130  pclose(p);
2131
2132  if (type==1) {
2133    owl_function_popless_text(out);
2134  } else if (type==0) {
2135    return out;
2136  } else if (type==2) {
2137    owl_function_adminmsg(buff, out);
2138  } else {
2139    owl_function_popless_text(out);
2140  }
2141  owl_free(out);
2142  return NULL;
2143}
2144
2145char *owl_function_perl(int argc, char **argv, char *buff, int type)
2146{
2147  /* if type == 1 display in a popup
2148   * if type == 2 display an admin messages
2149   * if type == 0 return output
2150   * else display in a popup
2151   */
2152  char *perlout;
2153
2154  if (argc<2) {
2155    owl_function_error("Wrong number of arguments to perl command");
2156    return NULL;
2157  }
2158
2159  /* consume first token (argv[0]) */
2160  buff = skiptokens(buff, 1);
2161
2162  perlout = owl_perlconfig_execute(buff);
2163  if (perlout) { 
2164    if (type==1) {
2165      owl_function_popless_text(perlout);
2166    } else if (type==2) {
2167      owl_function_adminmsg(buff, perlout);
2168    } else if (type==0) {
2169      return perlout;
2170    } else {
2171      owl_function_popless_text(perlout);
2172    }
2173    owl_free(perlout);
2174  }
2175  return NULL;
2176}
2177
2178#if 0
2179void owl_function_change_view_old(char *filtname)
2180{
2181  owl_view *v;
2182  owl_filter *f;
2183  int curid=-1, newpos, curmsg;
2184  owl_message *curm=NULL;
2185
2186  v=owl_global_get_current_view(&g);
2187  curmsg=owl_global_get_curmsg(&g);
2188  if (curmsg==-1) {
2189    owl_function_debugmsg("Hit the curmsg==-1 case in change_view");
2190  } else {
2191    curm=owl_view_get_element(v, curmsg);
2192    if (curm) {
2193      curid=owl_message_get_id(curm);
2194      owl_view_save_curmsgid(v, curid);
2195    }
2196  }
2197
2198  /* grab the filter */;
2199  f=owl_global_get_filter(&g, filtname);
2200  if (!f) {
2201    owl_function_error("Unknown filter %s", filtname);
2202    return;
2203  }
2204
2205  /* free the existing view and create a new one based on the filter */
2206  owl_view_free(v);
2207  owl_view_create(v, f);
2208
2209  /* Figure out what to set the current message to.
2210   * - If the view we're leaving has messages in it, go to the closest message
2211   *   to the last message pointed to in that view.
2212   * - If the view we're leaving is empty, try to restore the position
2213   *   from the last time we were in the new view.  */
2214  if (curm) {
2215    newpos = owl_view_get_nearest_to_msgid(v, curid);
2216  } else {
2217    newpos = owl_view_get_nearest_to_saved(v);
2218  }
2219
2220  owl_global_set_curmsg(&g, newpos);
2221
2222  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
2223  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2224  owl_global_set_direction_downwards(&g);
2225}
2226#endif
2227
2228void owl_function_change_view(char *filtname)
2229{
2230  owl_view *v;
2231  owl_filter *f;
2232  int curid=-1, newpos, curmsg;
2233  owl_message *curm=NULL;
2234
2235  v=owl_global_get_current_view(&g);
2236
2237  curmsg=owl_global_get_curmsg(&g);
2238  if (curmsg==-1) {
2239    owl_function_debugmsg("Hit the curmsg==-1 case in change_view");
2240  } else {
2241    curm=owl_view_get_element(v, curmsg);
2242    if (curm) {
2243      curid=owl_message_get_id(curm);
2244      owl_view_save_curmsgid(v, curid);
2245    }
2246  }
2247
2248  f=owl_global_get_filter(&g, filtname);
2249  if (!f) {
2250    owl_function_error("Unknown filter %s", filtname);
2251    return;
2252  }
2253
2254  owl_view_new_filter(v, f);
2255
2256  /* Figure out what to set the current message to.
2257   * - If the view we're leaving has messages in it, go to the closest message
2258   *   to the last message pointed to in that view.
2259   * - If the view we're leaving is empty, try to restore the position
2260   *   from the last time we were in the new view.  */
2261  if (curm) {
2262    newpos = owl_view_get_nearest_to_msgid(v, curid);
2263  } else {
2264    newpos = owl_view_get_nearest_to_saved(v);
2265  }
2266
2267  owl_global_set_curmsg(&g, newpos);
2268  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
2269  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2270  owl_global_set_direction_downwards(&g);
2271}
2272
2273void owl_function_create_filter(int argc, char **argv)
2274{
2275  owl_filter *f;
2276  owl_view *v;
2277  int ret, inuse=0;
2278
2279  if (argc < 2) {
2280    owl_function_error("Wrong number of arguments to filter command");
2281    return;
2282  }
2283
2284  v=owl_global_get_current_view(&g);
2285
2286  /* don't touch the all filter */
2287  if (!strcmp(argv[1], "all")) {
2288    owl_function_error("You may not change the 'all' filter.");
2289    return;
2290  }
2291
2292  /* deal with the case of trying change the filter color */
2293  if (argc==4 && !strcmp(argv[2], "-c")) {
2294    f=owl_global_get_filter(&g, argv[1]);
2295    if (!f) {
2296      owl_function_error("The filter '%s' does not exist.", argv[1]);
2297      return;
2298    }
2299    if (owl_util_string_to_color(argv[3])==-1) {
2300      owl_function_error("The color '%s' is not available.", argv[3]);
2301      return;
2302    }
2303    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
2304    owl_global_set_needrefresh(&g);
2305    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2306    return;
2307  }
2308
2309  /* create the filter and check for errors */
2310  f=owl_malloc(sizeof(owl_filter));
2311  ret=owl_filter_init(f, argv[1], argc-2, argv+2);
2312  if (ret==-1) {
2313    owl_free(f);
2314    owl_function_error("Invalid filter syntax");
2315    return;
2316  }
2317
2318  /* if the named filter is in use by the current view, remember it */
2319  if (!strcmp(owl_view_get_filtname(v), argv[1])) {
2320    inuse=1;
2321  }
2322
2323  /* if the named filter already exists, nuke it */
2324  if (owl_global_get_filter(&g, argv[1])) {
2325    owl_global_remove_filter(&g, argv[1]);
2326  }
2327
2328  /* add the filter */
2329  owl_global_add_filter(&g, f);
2330
2331  /* if it was in use by the current view then update */
2332  if (inuse) {
2333    owl_function_change_view(argv[1]);
2334  }
2335  owl_global_set_needrefresh(&g);
2336  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2337}
2338
2339void owl_function_show_filters()
2340{
2341  owl_list *l;
2342  owl_filter *f;
2343  int i, j;
2344  owl_fmtext fm;
2345
2346  owl_fmtext_init_null(&fm);
2347
2348  l=owl_global_get_filterlist(&g);
2349  j=owl_list_get_size(l);
2350
2351  owl_fmtext_append_bold(&fm, "Filters:\n");
2352
2353  for (i=0; i<j; i++) {
2354    f=owl_list_get_element(l, i);
2355    owl_fmtext_append_normal(&fm, "   ");
2356    if (owl_global_get_hascolors(&g)) {
2357      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
2358    } else {
2359      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
2360    }
2361    owl_fmtext_append_normal(&fm, "\n");
2362  }
2363  owl_function_popless_fmtext(&fm);
2364  owl_fmtext_free(&fm);
2365}
2366
2367void owl_function_show_filter(char *name)
2368{
2369  owl_filter *f;
2370  char buff[5000];
2371
2372  f=owl_global_get_filter(&g, name);
2373  if (!f) {
2374    owl_function_error("There is no filter named %s", name);
2375    return;
2376  }
2377  owl_filter_print(f, buff);
2378  owl_function_popless_text(buff);
2379}
2380
2381void owl_function_show_zpunts()
2382{
2383  owl_filter *f;
2384  owl_list *fl;
2385  char buff[5000];
2386  owl_fmtext fm;
2387  int i, j;
2388
2389  owl_fmtext_init_null(&fm);
2390
2391  fl=owl_global_get_puntlist(&g);
2392  j=owl_list_get_size(fl);
2393  owl_fmtext_append_bold(&fm, "Active zpunt filters:\n");
2394
2395  for (i=0; i<j; i++) {
2396    f=owl_list_get_element(fl, i);
2397    owl_filter_print(f, buff);
2398    owl_fmtext_append_normal(&fm, buff);
2399  }
2400  owl_function_popless_fmtext(&fm);
2401  owl_fmtext_free(&fm);
2402}
2403
2404/* Create a filter for a class, instance if one doesn't exist.  If
2405 * instance is NULL then catch all messgaes in the class.  Returns the
2406 * name of the filter, which the caller must free.
2407 */
2408char *owl_function_classinstfilt(char *class, char *instance) 
2409{
2410  owl_list *fl;
2411  owl_filter *f;
2412  char *argbuff, *filtname;
2413  char *tmpclass, *tmpinstance = NULL;
2414  int len;
2415
2416  fl=owl_global_get_filterlist(&g);
2417
2418  /* name for the filter */
2419  len=strlen(class)+30;
2420  if (instance) len+=strlen(instance);
2421  filtname=owl_malloc(len);
2422  if (!instance) {
2423    sprintf(filtname, "class-%s", class);
2424  } else {
2425    sprintf(filtname, "class-%s-instance-%s", class, instance);
2426  }
2427  /* downcase it */
2428  downstr(filtname);
2429  /* turn spaces into dots */
2430  owl_text_tr(filtname, ' ', '.');
2431 
2432  /* if it already exists then go with it.  This lets users override */
2433  if (owl_global_get_filter(&g, filtname)) {
2434    return(filtname);
2435  }
2436
2437  /* create the new filter */
2438  argbuff=owl_malloc(len+20);
2439  tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2440  owl_text_tr(tmpclass, ' ', '.');
2441  if (instance) {
2442    tmpinstance=owl_text_quote(instance, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2443    owl_text_tr(tmpinstance, ' ', '.');
2444  }
2445  sprintf(argbuff, "( class ^%s$ )", tmpclass);
2446  if (tmpinstance) {
2447    sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, tmpinstance);
2448  }
2449  owl_free(tmpclass);
2450  if (tmpinstance) owl_free(tmpinstance);
2451
2452  f=owl_malloc(sizeof(owl_filter));
2453  owl_filter_init_fromstring(f, filtname, argbuff);
2454
2455  /* add it to the global list */
2456  owl_global_add_filter(&g, f);
2457
2458  owl_free(argbuff);
2459  return(filtname);
2460}
2461
2462/* Create a filter for personal zephyrs to or from the specified
2463 * zephyr user.  Includes login/logout notifications for the user.
2464 * The name of the filter will be 'user-<user>'.  If a filter already
2465 * exists with this name, no new filter will be created.  This allows
2466 * the configuration to override this function.  Returns the name of
2467 * the filter, which the caller must free.
2468 */
2469char *owl_function_zuserfilt(char *user)
2470{
2471  owl_filter *f;
2472  char *argbuff, *longuser, *shortuser, *filtname;
2473
2474  /* stick the local realm on if it's not there */
2475  longuser=long_zuser(user);
2476  shortuser=short_zuser(user);
2477
2478  /* name for the filter */
2479  filtname=owl_malloc(strlen(shortuser)+20);
2480  sprintf(filtname, "user-%s", shortuser);
2481
2482  /* if it already exists then go with it.  This lets users override */
2483  if (owl_global_get_filter(&g, filtname)) {
2484    return(owl_strdup(filtname));
2485  }
2486
2487  /* create the new-internal filter */
2488  f=owl_malloc(sizeof(owl_filter));
2489
2490  argbuff=owl_malloc(strlen(longuser)+1000);
2491  sprintf(argbuff, "( type ^zephyr$ and ( class ^message$ and instance ^personal$ and ");
2492  sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser);
2493  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) ) )", argbuff, longuser);
2494
2495  owl_filter_init_fromstring(f, filtname, argbuff);
2496
2497  /* add it to the global list */
2498  owl_global_add_filter(&g, f);
2499
2500  /* free stuff */
2501  owl_free(argbuff);
2502  owl_free(longuser);
2503  owl_free(shortuser);
2504
2505  return(filtname);
2506}
2507
2508/* Create a filter for AIM IM messages to or from the specified
2509 * screenname.  The name of the filter will be 'aimuser-<user>'.  If a
2510 * filter already exists with this name, no new filter will be
2511 * created.  This allows the configuration to override this function.
2512 * Returns the name of the filter, which the caller must free.
2513 */
2514char *owl_function_aimuserfilt(char *user)
2515{
2516  owl_filter *f;
2517  char *argbuff, *filtname;
2518
2519  /* name for the filter */
2520  filtname=owl_malloc(strlen(user)+40);
2521  sprintf(filtname, "aimuser-%s", user);
2522
2523  /* if it already exists then go with it.  This lets users override */
2524  if (owl_global_get_filter(&g, filtname)) {
2525    return(owl_strdup(filtname));
2526  }
2527
2528  /* create the new-internal filter */
2529  f=owl_malloc(sizeof(owl_filter));
2530
2531  argbuff=owl_malloc(1000);
2532  sprintf(argbuff,
2533          "( type ^aim$ and ( ( sender ^%s$ and recipient ^%s$ ) or ( sender ^%s$ and recipient ^%s$ ) ) )",
2534          user, owl_global_get_aim_screenname(&g), owl_global_get_aim_screenname(&g), user);
2535
2536  owl_filter_init_fromstring(f, filtname, argbuff);
2537
2538  /* add it to the global list */
2539  owl_global_add_filter(&g, f);
2540
2541  /* free stuff */
2542  owl_free(argbuff);
2543
2544  return(filtname);
2545}
2546
2547char *owl_function_typefilt(char *type)
2548{
2549  owl_filter *f;
2550  char *argbuff, *filtname;
2551
2552  /* name for the filter */
2553  filtname=owl_sprintf("type-%s", type);
2554
2555  /* if it already exists then go with it.  This lets users override */
2556  if (owl_global_get_filter(&g, filtname)) {
2557    return filtname;
2558  }
2559
2560  /* create the new-internal filter */
2561  f=owl_malloc(sizeof(owl_filter));
2562
2563  argbuff = owl_sprintf("type ^%s$", type);
2564
2565  owl_filter_init_fromstring(f, filtname, argbuff);
2566
2567  /* add it to the global list */
2568  owl_global_add_filter(&g, f);
2569
2570  /* free stuff */
2571  owl_free(argbuff);
2572
2573  return filtname;
2574}
2575
2576/* If flag is 1, marks for deletion.  If flag is 0,
2577 * unmarks for deletion. */
2578void owl_function_delete_curview_msgs(int flag)
2579{
2580  owl_view *v;
2581  int i, j;
2582
2583  v=owl_global_get_current_view(&g);
2584  j=owl_view_get_size(v);
2585  for (i=0; i<j; i++) {
2586    if (flag == 1) {
2587      owl_message_mark_delete(owl_view_get_element(v, i));
2588    } else if (flag == 0) {
2589      owl_message_unmark_delete(owl_view_get_element(v, i));
2590    }
2591  }
2592
2593  owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un");
2594
2595  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
2596}
2597
2598/* Create a filter based on the current message.  Returns the name of
2599 * a filter or null.  The caller must free this name.
2600 *
2601 * if the curmsg is a personal zephyr return a filter name
2602 *    to the zephyr converstaion with that user.
2603 * If the curmsg is a zephyr class message, instance foo, recip *,
2604 *    return a filter name to the class, inst.
2605 * If the curmsg is a zephyr class message and type==0 then
2606 *    return a filter name for just the class.
2607 * If the curmsg is a zephyr class message and type==1 then
2608 *    return a filter name for the class and instance.
2609 * If the curmsg is a personal AIM message returna  filter
2610 *    name to the AIM conversation with that user
2611 */
2612char *owl_function_smartfilter(int type)
2613{
2614  owl_view *v;
2615  owl_message *m;
2616  char *zperson, *filtname=NULL;
2617 
2618  v=owl_global_get_current_view(&g);
2619  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
2620
2621  if (!m || owl_view_get_size(v)==0) {
2622    owl_function_error("No message selected\n");
2623    return(NULL);
2624  }
2625
2626  /* very simple handling of admin messages for now */
2627  if (owl_message_is_type_admin(m)) {
2628    return(owl_function_typefilt("admin"));
2629  }
2630
2631  /* very simple handling of loopback messages for now */
2632  if (owl_message_is_type_loopback(m)) {
2633    return(owl_function_typefilt("loopback"));
2634  }
2635
2636  /* aim messages */
2637  if (owl_message_is_type_aim(m)) {
2638    if (owl_message_is_direction_in(m)) {
2639      filtname=owl_function_aimuserfilt(owl_message_get_sender(m));
2640    } else if (owl_message_is_direction_out(m)) {
2641      filtname=owl_function_aimuserfilt(owl_message_get_recipient(m));
2642    }
2643    return(filtname);
2644  }
2645
2646  /* narrow personal and login messages to the sender or recip as appropriate */
2647  if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
2648    if (owl_message_is_type_zephyr(m)) {
2649      if (owl_message_is_direction_in(m)) {
2650        zperson=short_zuser(owl_message_get_sender(m));
2651      } else {
2652        zperson=short_zuser(owl_message_get_recipient(m));
2653      }
2654      filtname=owl_function_zuserfilt(zperson);
2655      owl_free(zperson);
2656      return(filtname);
2657    }
2658    return(NULL);
2659  }
2660
2661  /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
2662  if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
2663    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
2664    return(filtname);
2665  }
2666
2667  /* otherwise narrow to the class */
2668  if (type==0) {
2669    filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
2670  } else if (type==1) {
2671    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
2672  }
2673  return(filtname);
2674}
2675
2676void owl_function_smartzpunt(int type)
2677{
2678  /* Starts a zpunt command based on the current class,instance pair.
2679   * If type=0, uses just class.  If type=1, uses instance as well. */
2680  owl_view *v;
2681  owl_message *m;
2682  char *cmd, *cmdprefix, *mclass, *minst;
2683 
2684  v=owl_global_get_current_view(&g);
2685  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
2686
2687  if (!m || owl_view_get_size(v)==0) {
2688    owl_function_error("No message selected\n");
2689    return;
2690  }
2691
2692  /* for now we skip admin messages. */
2693  if (owl_message_is_type_admin(m)
2694      || owl_message_is_loginout(m)
2695      || !owl_message_is_type_zephyr(m)) {
2696    owl_function_error("smartzpunt doesn't support this message type.");
2697    return;
2698  }
2699
2700  mclass = owl_message_get_class(m);
2701  minst = owl_message_get_instance(m);
2702  if (!mclass || !*mclass || *mclass==' '
2703      || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal"))
2704      || (type && (!minst || !*minst|| *minst==' '))) {
2705    owl_function_error("smartzpunt can't safely do this for <%s,%s>",
2706                         mclass, minst);
2707  } else {
2708    cmdprefix = "start-command zpunt ";
2709    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10);
2710    strcpy(cmd, cmdprefix);
2711    strcat(cmd, owl_getquoting(mclass));
2712    strcat(cmd, mclass);
2713    strcat(cmd, owl_getquoting(mclass));
2714    if (type) {
2715      strcat(cmd, " ");
2716      strcat(cmd, owl_getquoting(minst));
2717      strcat(cmd, minst);
2718      strcat(cmd, owl_getquoting(minst));
2719    } else {
2720      strcat(cmd, " *");
2721    }
2722    owl_function_command(cmd);
2723    owl_free(cmd);
2724  }
2725}
2726
2727void owl_function_color_current_filter(char *color)
2728{
2729  owl_filter *f;
2730  char *name;
2731
2732  name=owl_view_get_filtname(owl_global_get_current_view(&g));
2733  f=owl_global_get_filter(&g, name);
2734  if (!f) {
2735    owl_function_error("Unknown filter");
2736    return;
2737  }
2738
2739  /* don't touch the all filter */
2740  if (!strcmp(name, "all")) {
2741    owl_function_error("You may not change the 'all' filter.");
2742    return;
2743  }
2744
2745  /* deal with the case of trying change the filter color */
2746  if (owl_util_string_to_color(color)==-1) {
2747    owl_function_error("No color named '%s' avilable.");
2748    return;
2749  }
2750  owl_filter_set_color(f, owl_util_string_to_color(color));
2751  owl_global_set_needrefresh(&g);
2752  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2753}
2754
2755void owl_function_show_colors()
2756{
2757  owl_fmtext fm;
2758
2759  owl_fmtext_init_null(&fm);
2760  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
2761  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
2762  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
2763  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
2764  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
2765  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
2766  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
2767  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
2768
2769  owl_function_popless_fmtext(&fm);
2770  owl_fmtext_free(&fm);
2771}
2772
2773/* add the given class, inst, recip to the punt list for filtering.
2774 *   if direction==0 then punt
2775 *   if direction==1 then unpunt
2776 */
2777void owl_function_zpunt(char *class, char *inst, char *recip, int direction)
2778{
2779  owl_filter *f;
2780  owl_list *fl;
2781  char *buff;
2782  char *quoted;
2783  int ret, i, j;
2784
2785  fl=owl_global_get_puntlist(&g);
2786
2787  /* first, create the filter */
2788  f=malloc(sizeof(owl_filter));
2789  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
2790  strcpy(buff, "class");
2791  if (!strcmp(class, "*")) {
2792    strcat(buff, " .*");
2793  } else {
2794    quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2795    owl_text_tr(quoted, ' ', '.');
2796    sprintf(buff, "%s ^%s$", buff, quoted);
2797    owl_free(quoted);
2798  }
2799  if (!strcmp(inst, "*")) {
2800    strcat(buff, " and instance .*");
2801  } else {
2802    quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2803    owl_text_tr(quoted, ' ', '.');
2804    sprintf(buff, "%s and instance ^%s$", buff, quoted);
2805    owl_free(quoted);
2806  }
2807  if (strcmp(recip, "*")) {
2808    quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2809    owl_text_tr(quoted, ' ', '.');
2810    sprintf(buff, "%s and recipient ^%s$", buff, quoted);
2811    owl_free(quoted);
2812  }
2813 
2814  owl_function_debugmsg("About to filter %s", buff);
2815  ret=owl_filter_init_fromstring(f, "punt-filter", buff);
2816  owl_free(buff);
2817  if (ret) {
2818    owl_function_error("Error creating filter for zpunt");
2819    owl_filter_free(f);
2820    return;
2821  }
2822
2823  /* Check for an identical filter */
2824  j=owl_list_get_size(fl);
2825  for (i=0; i<j; i++) {
2826    if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
2827      /* if we're punting, then just silently bow out on this duplicate */
2828      if (direction==0) {
2829        owl_filter_free(f);
2830        return;
2831      }
2832
2833      /* if we're unpunting, then remove this filter from the puntlist */
2834      if (direction==1) {
2835        owl_filter_free(owl_list_get_element(fl, i));
2836        owl_list_remove_element(fl, i);
2837        return;
2838      }
2839    }
2840  }
2841
2842  /* If we're punting, add the filter to the global punt list */
2843  if (direction==0) {
2844    owl_list_append_element(fl, f);
2845  }
2846}
2847
2848void owl_function_activate_keymap(char *keymap)
2849{
2850  if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
2851    owl_function_error("Unable to activate keymap '%s'", keymap);
2852  }
2853}
2854
2855void owl_function_show_keymaps()
2856{
2857  owl_list l;
2858  owl_fmtext fm;
2859  owl_keymap *km;
2860  owl_keyhandler *kh;
2861  int i, numkm;
2862  char *kmname;
2863
2864  kh = owl_global_get_keyhandler(&g);
2865  owl_fmtext_init_null(&fm);
2866  owl_fmtext_append_bold(&fm, "Keymaps:   ");
2867  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
2868  owl_keyhandler_get_keymap_names(kh, &l);
2869  owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
2870  owl_fmtext_append_normal(&fm, "\n");
2871
2872  numkm = owl_list_get_size(&l);
2873  for (i=0; i<numkm; i++) {
2874    kmname = owl_list_get_element(&l, i);
2875    km = owl_keyhandler_get_keymap(kh, kmname);
2876    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
2877    owl_keymap_get_details(km, &fm);   
2878  }
2879  owl_fmtext_append_normal(&fm, "\n");
2880 
2881  owl_function_popless_fmtext(&fm);
2882  owl_keyhandler_keymap_namelist_free(&l);
2883  owl_fmtext_free(&fm);
2884}
2885
2886char *owl_function_keymap_summary(void *name)
2887{
2888  owl_keymap *km
2889    = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2890  if (km) return owl_keymap_summary(km);
2891  else return(NULL);
2892}
2893
2894/* TODO: implement for real */
2895void owl_function_show_keymap(char *name)
2896{
2897  owl_fmtext fm;
2898  owl_keymap *km;
2899
2900  owl_fmtext_init_null(&fm);
2901  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2902  if (km) {
2903    owl_keymap_get_details(km, &fm);
2904  } else {
2905    owl_fmtext_append_normal(&fm, "No such keymap...\n");
2906  } 
2907  owl_function_popless_fmtext(&fm);
2908  owl_fmtext_free(&fm);
2909}
2910
2911void owl_function_help_for_command(char *cmdname)
2912{
2913  owl_fmtext fm;
2914
2915  owl_fmtext_init_null(&fm);
2916  owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm);
2917  owl_function_popless_fmtext(&fm); 
2918  owl_fmtext_free(&fm);
2919}
2920
2921void owl_function_search_start(char *string, int direction)
2922{
2923  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
2924  owl_global_set_search_active(&g, string);
2925  owl_function_search_helper(0, direction);
2926}
2927
2928void owl_function_search_continue(int direction)
2929{
2930  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
2931  owl_function_search_helper(1, direction);
2932}
2933
2934void owl_function_search_helper(int mode, int direction)
2935{
2936  /* move to a message that contains the string.  If direction is
2937   * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is
2938   * OWL_DIRECTION_UPWARDS then search backwards.
2939   *
2940   * If mode==0 then it will stay on the current message if it
2941   * contains the string.
2942   */
2943
2944  owl_view *v;
2945  int viewsize, i, curmsg, start;
2946  owl_message *m;
2947
2948  v=owl_global_get_current_view(&g);
2949  viewsize=owl_view_get_size(v);
2950  curmsg=owl_global_get_curmsg(&g);
2951 
2952  if (viewsize==0) {
2953    owl_function_error("No messages present");
2954    return;
2955  }
2956
2957  if (mode==0) {
2958    start=curmsg;
2959  } else if (direction==OWL_DIRECTION_DOWNWARDS) {
2960    start=curmsg+1;
2961  } else {
2962    start=curmsg-1;
2963  }
2964
2965  /* bounds check */
2966  if (start>=viewsize || start<0) {
2967    owl_function_error("No further matches found");
2968    return;
2969  }
2970
2971  for (i=start; i<viewsize && i>=0;) {
2972    m=owl_view_get_element(v, i);
2973    if (owl_message_search(m, owl_global_get_search_string(&g))) {
2974      owl_global_set_curmsg(&g, i);
2975      owl_function_calculate_topmsg(direction);
2976      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2977      if (direction==OWL_DIRECTION_DOWNWARDS) {
2978        owl_global_set_direction_downwards(&g);
2979      } else {
2980        owl_global_set_direction_upwards(&g);
2981      }
2982      return;
2983    }
2984    if (direction==OWL_DIRECTION_DOWNWARDS) {
2985      i++;
2986    } else {
2987      i--;
2988    }
2989  }
2990  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2991  owl_function_error("No matches found");
2992}
2993
2994/* strips formatting from ztext and returns the unformatted text.
2995 * caller is responsible for freeing. */
2996char *owl_function_ztext_stylestrip(char *zt)
2997{
2998  owl_fmtext fm;
2999  char *plaintext;
3000
3001  owl_fmtext_init_null(&fm);
3002  owl_fmtext_append_ztext(&fm, zt);
3003  plaintext = owl_fmtext_print_plain(&fm);
3004  owl_fmtext_free(&fm);
3005  return(plaintext);
3006}
3007
3008/* Popup a buddylisting.  If file is NULL use the default .anyone */
3009void owl_function_buddylist(int aim, int zephyr, char *file)
3010{
3011  int i, j, idle;
3012  owl_fmtext fm;
3013  owl_buddylist *bl;
3014  owl_buddy *b;
3015  char *foo, *timestr;
3016#ifdef HAVE_LIBZEPHYR
3017  char *ourfile, *tmp, buff[LINE], *line;
3018  ZLocations_t location[200];
3019  FILE *f;
3020  int numlocs, ret;
3021#endif
3022
3023  owl_fmtext_init_null(&fm);
3024
3025  /* AIM first */
3026  if (aim && owl_global_is_aimloggedin(&g)) {
3027    bl=owl_global_get_buddylist(&g);
3028
3029    owl_fmtext_append_bold(&fm, "AIM users logged in:\n");
3030    /* we're assuming AIM for now */
3031    j=owl_buddylist_get_size(bl);
3032    for (i=0; i<j; i++) {
3033      b=owl_buddylist_get_buddy_n(bl, i);
3034      idle=owl_buddy_get_idle_time(b);
3035      if (idle!=0) {
3036        timestr=owl_util_minutes_to_timestr(idle);
3037      } else {
3038        timestr=owl_strdup("");
3039      }
3040      foo=owl_sprintf("  %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr);
3041      owl_fmtext_append_normal(&fm, foo);
3042      owl_free(timestr);
3043      owl_free(foo);
3044    }
3045  }
3046
3047#ifdef HAVE_LIBZEPHYR
3048  if (zephyr) {
3049    if (file==NULL) {
3050      tmp=owl_global_get_homedir(&g);
3051      ourfile=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
3052    } else {
3053      ourfile=owl_strdup(file);
3054    }
3055
3056    owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n");
3057    f=fopen(ourfile, "r");
3058    if (!f) {
3059      owl_fmtext_append_normal(&fm, "  Error opening file ");
3060      owl_fmtext_append_normal(&fm, ourfile);
3061      owl_fmtext_append_normal(&fm, "\n");
3062      owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : "");
3063    } else {
3064      while (fgets(buff, LINE, f)!=NULL) {
3065        /* ignore comments, blank lines etc. */
3066        if (buff[0]=='#') continue;
3067        if (buff[0]=='\n') continue;
3068        if (buff[0]=='\0') continue;
3069       
3070        /* strip the \n */
3071        buff[strlen(buff)-1]='\0';
3072       
3073        /* ingore from # on */
3074        tmp=strchr(buff, '#');
3075        if (tmp) tmp[0]='\0';
3076       
3077        /* ingore from SPC */
3078        tmp=strchr(buff, ' ');
3079        if (tmp) tmp[0]='\0';
3080       
3081        /* stick on the local realm. */
3082        if (!strchr(buff, '@')) {
3083          strcat(buff, "@");
3084          strcat(buff, ZGetRealm());
3085        }
3086       
3087        ret=ZLocateUser(buff, &numlocs, ZAUTH);
3088        if (ret!=ZERR_NONE) {
3089          owl_function_error("Error getting location for %s", buff);
3090          continue;
3091        }
3092       
3093        numlocs=200;
3094        ret=ZGetLocations(location, &numlocs);
3095        if (ret==0) {
3096          for (i=0; i<numlocs; i++) {
3097            line=malloc(strlen(location[i].host)+strlen(location[i].time)+strlen(location[i].tty)+100);
3098            tmp=short_zuser(buff);
3099            sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
3100                    tmp,
3101                    location[i].host,
3102                    location[i].tty,
3103                    location[i].time);
3104            owl_fmtext_append_normal(&fm, line);
3105            owl_free(tmp);
3106          }
3107          if (numlocs>=200) {
3108            owl_fmtext_append_normal(&fm, "  Too many locations found for this user, truncating.\n");
3109          }
3110        }
3111      }
3112      fclose(f);
3113    }
3114    owl_free(ourfile);
3115  }
3116#endif
3117 
3118  owl_function_popless_fmtext(&fm);
3119  owl_fmtext_free(&fm);
3120}
3121
3122void owl_function_dump(char *filename) 
3123{
3124  int i, j, count;
3125  owl_message *m;
3126  owl_view *v;
3127  FILE *file;
3128  /* struct stat sbuf; */
3129
3130  v=owl_global_get_current_view(&g);
3131
3132  /* in the future make it ask yes/no */
3133  /*
3134  ret=stat(filename, &sbuf);
3135  if (!ret) {
3136    ret=owl_function_askyesno("File exists, continue? [Y/n]");
3137    if (!ret) return;
3138  }
3139  */
3140
3141  file=fopen(filename, "w");
3142  if (!file) {
3143    owl_function_error("Error opening file");
3144    return;
3145  }
3146
3147  count=0;
3148  j=owl_view_get_size(v);
3149  for (i=0; i<j; i++) {
3150    m=owl_view_get_element(v, i);
3151    fputs(owl_message_get_text(m), file);
3152  }
3153  fclose(file);
3154}
3155
3156void owl_function_do_newmsgproc(void)
3157{
3158  if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) {
3159    /* if there's a process out there, we need to check on it */
3160    if (owl_global_get_newmsgproc_pid(&g)) {
3161      owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g));
3162      owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG));
3163      waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG);
3164      if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) {
3165        /* it exited */
3166        owl_global_set_newmsgproc_pid(&g, 0);
3167        owl_function_debugmsg("newmsgproc exited");
3168      } else {
3169        owl_function_debugmsg("newmsgproc did not exit");
3170      }
3171    }
3172   
3173    /* if it exited, fork & exec a new one */
3174    if (owl_global_get_newmsgproc_pid(&g)==0) {
3175      int i, myargc;
3176      i=fork();
3177      if (i) {
3178        /* parent set the child's pid */
3179        owl_global_set_newmsgproc_pid(&g, i);
3180        owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
3181      } else {
3182        /* child exec's the program */
3183        char **parsed;
3184        parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
3185        if (myargc < 0) {
3186          owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g));
3187        }
3188        if (myargc <= 0) {
3189          _exit(127);
3190        }
3191        parsed=realloc(parsed, sizeof(*parsed) * (myargc+1));
3192        parsed[myargc] = NULL;
3193       
3194        owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc);
3195       
3196        execvp(parsed[0], parsed);
3197       
3198       
3199        /* was there an error exec'ing? */
3200        owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s", 
3201                              owl_global_get_newmsgproc(&g), parsed[0], strerror(errno));
3202        _exit(127);
3203      }
3204    }
3205  }
3206}
3207
3208/* print the xterm escape sequence to raise the window */
3209void owl_function_xterm_raise(void)
3210{
3211  printf("\033[5t");
3212}
3213
3214/* print the xterm escape sequence to deiconify the window */
3215void owl_function_xterm_deiconify(void)
3216{
3217  printf("\033[1t");
3218}
3219
3220/* Add the specified command to the startup file.  Eventually this
3221 * should be clever, and rewriting settings that will obviosly
3222 * override earlier settings with 'set' 'bindkey' and 'alias'
3223 * commands.  For now though we just remove any line that would
3224 * duplicate this one and then append this line to the end of
3225 * startupfile.
3226 */
3227void owl_function_addstartup(char *buff)
3228{
3229  FILE *file;
3230  char *filename;
3231
3232  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3233  file=fopen(filename, "a");
3234  if (!file) {
3235    owl_function_error("Error opening startupfile for new command");
3236    owl_free(filename);
3237    return;
3238  }
3239
3240  /* delete earlier copies */
3241  owl_util_file_deleteline(filename, buff, 1);
3242  owl_free(filename);
3243
3244  /* add this line */
3245  fprintf(file, "%s\n", buff);
3246
3247  fclose(file);
3248}
3249
3250/* Remove the specified command from the startup file. */
3251void owl_function_delstartup(char *buff)
3252{
3253  char *filename;
3254  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3255  owl_util_file_deleteline(filename, buff, 1);
3256  owl_free(filename);
3257}
3258
3259/* Execute owl commands from the given filename.  If the filename
3260 * is NULL, use the default owl startup commands file.
3261 */
3262void owl_function_source(char *filename)
3263{
3264  FILE *file;
3265  char buff[LINE];
3266
3267  if (!filename) {
3268    filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3269    file=fopen(filename, "r");
3270    owl_free(filename);
3271  } else {
3272    file=fopen(filename, "r");
3273  }
3274  if (!file) {
3275    /* just fail silently if it doesn't exist */
3276    return;
3277  }
3278  while (fgets(buff, LINE, file)!=NULL) {
3279    buff[strlen(buff)-1]='\0';
3280    owl_function_command(buff);
3281  }
3282  fclose(file);
3283}
3284
3285void owl_function_change_style(owl_view *v, char *stylename)
3286{
3287  owl_style *s;
3288
3289  s=owl_global_get_style_by_name(&g, stylename);
3290  if (!s) {
3291    owl_function_error("No style named %s", stylename);
3292    return;
3293  }
3294  owl_view_set_style(v, s);
3295  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
3296  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
3297  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
3298}
3299
3300void owl_function_toggleoneline()
3301{
3302  owl_view *v;
3303  owl_style *s;
3304
3305  v=owl_global_get_current_view(&g);
3306  s=owl_view_get_style(v);
3307
3308  if (!owl_style_matches_name(s, "oneline")) {
3309    owl_function_change_style(v, "oneline");
3310  } else {
3311    owl_function_change_style(v, owl_global_get_default_style(&g));
3312  }
3313
3314  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
3315  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
3316  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
3317}
3318
3319void owl_function_error(char *fmt, ...)
3320{
3321  va_list ap;
3322  char buff[2048], buff2[2048];
3323  char *date;
3324  time_t now;
3325
3326  now=time(NULL);
3327  date=owl_strdup(ctime(&now));
3328  date[strlen(date)-1]='\0';
3329
3330  va_start(ap, fmt);
3331
3332  vsnprintf(buff, 2048, fmt, ap);
3333  sprintf(buff2, "%s %s", date, buff);
3334  owl_function_debugmsg("ERROR: %s", buff);
3335  if (owl_global_get_curs_msgwin(&g)) {
3336    werase(owl_global_get_curs_msgwin(&g));
3337    waddstr(owl_global_get_curs_msgwin(&g), buff); 
3338    wnoutrefresh(owl_global_get_curs_msgwin(&g));
3339    owl_global_set_needrefresh(&g);
3340  }
3341  owl_errqueue_append_err(owl_global_get_errqueue(&g), buff2);
3342  va_end(ap);
3343  owl_free(date);
3344}
3345
3346void owl_function_showerrs()
3347{
3348  owl_fmtext fm;
3349
3350  owl_fmtext_init_null(&fm);
3351  owl_fmtext_append_normal(&fm, "Errors:\n\n");
3352  owl_errqueue_to_fmtext(owl_global_get_errqueue(&g), &fm);
3353  owl_function_popless_fmtext(&fm);
3354}
3355
3356void owl_function_makemsg(char *fmt, ...)
3357{
3358  va_list ap;
3359  char buff[2048];
3360
3361  if (!owl_global_get_curs_msgwin(&g)) return;
3362
3363  va_start(ap, fmt);
3364  werase(owl_global_get_curs_msgwin(&g));
3365 
3366  vsnprintf(buff, 2048, fmt, ap);
3367  owl_function_debugmsg("makemsg: %s", buff);
3368  waddstr(owl_global_get_curs_msgwin(&g), buff); 
3369  wnoutrefresh(owl_global_get_curs_msgwin(&g));
3370  owl_global_set_needrefresh(&g);
3371  va_end(ap);
3372}
Note: See TracBrowser for help on using the repository browser.