source: functions.c @ 8c46404

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8c46404 was 8c46404, checked in by James M. Kretchmar <kretch@mit.edu>, 17 years ago
Massive changes to AIM. Feel the burn.
  • Property mode set to 100644
File size: 89.1 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <signal.h>
5#include <string.h>
6#include <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  /* Quit zephyr */
864  owl_zephyr_shutdown();
865
866 
867  /* Quit AIM */
868  if (owl_global_is_aimloggedin(&g)) {
869    owl_aim_logout();
870  }
871
872  /* final clean up */
873  endwin();
874  owl_function_debugmsg("Quitting Owl");
875  exit(0);
876}
877
878void owl_function_openurl()
879{
880  /* visit the first url in the current message */
881  owl_message *m;
882  owl_view *v;
883  char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
884  int webbrowser;
885
886  webbrowser = owl_global_get_webbrowser(&g);
887
888  if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
889    owl_function_error("No browser selected");
890    return;
891  }
892
893  v=owl_global_get_current_view(&g);
894 
895  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
896
897  if (!m || owl_view_get_size(v)==0) {
898    owl_function_error("No current message selected");
899    return;
900  }
901
902  text=owl_message_get_text(m);
903
904  /* First look for a good URL */ 
905  if ((ptr1=strstr(text, "http://"))!=NULL) {
906    ptr2=strpbrk(ptr1, " \n\t");
907    if (ptr2) {
908      strncpy(url, ptr1, ptr2-ptr1+1);
909      url[ptr2-ptr1+1]='\0';
910    } else {
911      strcpy(url, ptr1);
912    }
913
914    /* if we had <http strip a trailing > */
915    if (ptr1>text && ptr1[-1]=='<') {
916      if (url[strlen(url)-1]=='>') {
917        url[strlen(url)-1]='\0';
918      }
919    }
920  } else if ((ptr1=strstr(text, "https://"))!=NULL) {
921    /* Look for an https URL */ 
922    ptr2=strpbrk(ptr1, " \n\t");
923    if (ptr2) {
924      strncpy(url, ptr1, ptr2-ptr1+1);
925      url[ptr2-ptr1+1]='\0';
926    } else {
927      strcpy(url, ptr1);
928    }
929   
930    /* if we had <http strip a trailing > */
931    if (ptr1>text && ptr1[-1]=='<') {
932      if (url[strlen(url)-1]=='>') {
933        url[strlen(url)-1]='\0';
934      }
935    }
936  } else if ((ptr1=strstr(text, "www."))!=NULL) {
937    /* if we can't find a real url look for www.something */
938    ptr2=strpbrk(ptr1, " \n\t");
939    if (ptr2) {
940      strncpy(url, ptr1, ptr2-ptr1+1);
941      url[ptr2-ptr1+1]='\0';
942    } else {
943      strcpy(url, ptr1);
944    }
945  } else {
946    owl_function_beep();
947    owl_function_error("Could not find URL to open.");
948    return;
949  }
950
951  /* Make sure there aren't any quotes or \'s in the url */
952  for (ptr1 = url; *ptr1; ptr1++) {
953    if (*ptr1 == '"' || *ptr1 == '\\') {
954      owl_function_beep();
955      owl_function_error("URL contains invalid characters.");
956      return;
957    }
958  }
959 
960  /* NOTE: There are potentially serious security issues here... */
961
962  /* open the page */
963  owl_function_makemsg("Opening %s", url);
964  if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {
965    snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);
966    system(tmpbuff); 
967  } else if (webbrowser == OWL_WEBBROWSER_GALEON) {
968    snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);
969    system(tmpbuff); 
970  } else if (webbrowser == OWL_WEBBROWSER_OPERA) {
971    snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);
972    system(tmpbuff); 
973  }
974}
975
976void owl_function_calculate_topmsg(int direction)
977{
978  int recwinlines, topmsg, curmsg;
979  owl_view *v;
980
981  v=owl_global_get_current_view(&g);
982  curmsg=owl_global_get_curmsg(&g);
983  topmsg=owl_global_get_topmsg(&g);
984  recwinlines=owl_global_get_recwin_lines(&g);
985
986  /*
987  if (owl_view_get_size(v) < 1) {
988    return;
989  }
990  */
991
992  switch (owl_global_get_scrollmode(&g)) {
993  case OWL_SCROLLMODE_TOP:
994    topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines);
995    break;
996  case OWL_SCROLLMODE_NEARTOP:
997    topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines);
998    break;
999  case OWL_SCROLLMODE_CENTER:
1000    topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines);
1001    break;
1002  case OWL_SCROLLMODE_PAGED:
1003    topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0);
1004    break;
1005  case OWL_SCROLLMODE_PAGEDCENTER:
1006    topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1);
1007    break;
1008  case OWL_SCROLLMODE_NORMAL:
1009  default:
1010    topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines);
1011  }
1012  owl_function_debugmsg("Calculated a topmsg of %i", topmsg);
1013  owl_global_set_topmsg(&g, topmsg);
1014}
1015
1016/* Returns what the new topmsg should be. 
1017 * Passed the last direction of movement,
1018 * the current view,
1019 * the current message number in the view,
1020 * the top message currently being displayed,
1021 * and the number of lines in the recwin.
1022 */
1023int owl_function_calculate_topmsg_top(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1024{
1025  return(curmsg);
1026}
1027
1028int owl_function_calculate_topmsg_neartop(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1029{
1030  if (curmsg>0 
1031      && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1))
1032          <  recwinlines/2)) {
1033    return(curmsg-1);
1034  } else {
1035    return(curmsg);
1036  }
1037}
1038 
1039int owl_function_calculate_topmsg_center(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1040{
1041  int i, last, lines;
1042
1043  last = curmsg;
1044  lines = 0;
1045  for (i=curmsg-1; i>=0; i--) {
1046    lines += owl_message_get_numlines(owl_view_get_element(v, i));
1047    if (lines > recwinlines/2) break;
1048    last = i;
1049  }
1050  return(last);
1051}
1052 
1053int owl_function_calculate_topmsg_paged(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page)
1054{
1055  int i, last, lines, savey;
1056 
1057  /* If we're off the top of the screen, scroll up such that the
1058   * curmsg is near the botton of the screen. */
1059  if (curmsg < topmsg) {
1060    last = curmsg;
1061    lines = 0;
1062    for (i=curmsg; i>=0; i--) {
1063      lines += owl_message_get_numlines(owl_view_get_element(v, i));
1064      if (lines > recwinlines) break;
1065    last = i;
1066    }
1067    if (center_on_page) {
1068      return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines));
1069    } else {
1070      return(last);
1071    }
1072  }
1073
1074  /* Find number of lines from top to bottom of curmsg (store in savey) */
1075  savey=0;
1076  for (i=topmsg; i<=curmsg; i++) {
1077    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
1078  }
1079
1080  /* if we're off the bottom of the screen, scroll down */
1081  if (savey > recwinlines) {
1082    if (center_on_page) {
1083      return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines));
1084    } else {
1085      return(curmsg);
1086    }
1087  }
1088
1089  /* else just stay as we are... */
1090  return(topmsg);
1091}
1092
1093int owl_function_calculate_topmsg_normal(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines)
1094{
1095  int savey, j, i, foo, y;
1096
1097  if (curmsg<0) return(topmsg);
1098   
1099  /* If we're off the top of the screen then center */
1100  if (curmsg<topmsg) {
1101    topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines);
1102  }
1103
1104  /* Find number of lines from top to bottom of curmsg (store in savey) */
1105  savey=0;
1106  for (i=topmsg; i<=curmsg; i++) {
1107    savey+=owl_message_get_numlines(owl_view_get_element(v, i));
1108  }
1109
1110  /* If we're off the bottom of the screen, set the topmsg to curmsg
1111   * and scroll upwards */
1112  if (savey > recwinlines) {
1113    topmsg=curmsg;
1114    savey=owl_message_get_numlines(owl_view_get_element(v, i));
1115    direction=OWL_DIRECTION_UPWARDS;
1116  }
1117 
1118  /* If our bottom line is less than 1/4 down the screen then scroll up */
1119  if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) {
1120    if (savey < (recwinlines / 4)) {
1121      y=0;
1122      for (j=curmsg; j>=0; j--) {
1123        foo=owl_message_get_numlines(owl_view_get_element(v, j));
1124        /* will we run the curmsg off the screen? */
1125        if ((foo+y) >= recwinlines) {
1126          j++;
1127          if (j>curmsg) j=curmsg;
1128          break;
1129        }
1130        /* have saved 1/2 the screen space? */
1131        y+=foo;
1132        if (y > (recwinlines / 2)) break;
1133      }
1134      if (j<0) j=0;
1135      return(j);
1136    }
1137  }
1138
1139  if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) {
1140    /* If curmsg bottom line is more than 3/4 down the screen then scroll down */
1141    if (savey > ((recwinlines * 3)/4)) {
1142      y=0;
1143      /* count lines from the top until we can save 1/2 the screen size */
1144      for (j=topmsg; j<curmsg; j++) {
1145        y+=owl_message_get_numlines(owl_view_get_element(v, j));
1146        if (y > (recwinlines / 2)) break;
1147      }
1148      if (j==curmsg) {
1149        j--;
1150      }
1151      return(j+1);
1152    }
1153  }
1154
1155  return(topmsg);
1156}
1157
1158void owl_function_resize()
1159{
1160  owl_global_set_resize_pending(&g);
1161}
1162
1163void owl_function_run_buffercommand()
1164{
1165  char *buff, *ptr;
1166
1167  buff=owl_global_get_buffercommand(&g);
1168  if (!strncmp(buff, "zwrite ", 7)) {
1169    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
1170  } else if (!strncmp(buff, "zcrypt ", 7)) {
1171    owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
1172  } else if (!strncmp(buff, "aimwrite ", 9)) {
1173    owl_function_aimwrite(buff+9);
1174  } else if (!strncmp(buff, "loopwrite", 9) || !strncmp(buff, "loopwrite ", 10)) {
1175    owl_function_loopwrite();
1176  } else if (!strncmp(buff, "aimlogin ", 9)) {
1177    ptr=owl_sprintf("%s %s", buff, owl_global_get_response(&g));
1178    owl_function_command(ptr);
1179    owl_free(ptr);
1180  } else {
1181    owl_function_error("Internal error: invalid buffercommand %s", buff);
1182  }
1183}
1184
1185void owl_function_debugmsg(char *fmt, ...)
1186{
1187  FILE *file;
1188  time_t now;
1189  char buff1[LINE], buff2[LINE];
1190  va_list ap;
1191  va_start(ap, fmt);
1192
1193  if (!owl_global_is_debug_fast(&g)) return;
1194
1195  file=fopen(owl_global_get_debug_file(&g), "a");
1196  if (!file) return;
1197
1198  now=time(NULL);
1199  strcpy(buff1, ctime(&now));
1200  buff1[strlen(buff1)-1]='\0';
1201
1202  owl_global_get_runtime_string(&g, buff2);
1203 
1204  fprintf(file, "[%i -  %s - %s]: ", (int) getpid(), buff1, buff2);
1205  vfprintf(file, fmt, ap);
1206  fprintf(file, "\n");
1207  fclose(file);
1208
1209  va_end(ap);
1210}
1211
1212void owl_function_refresh()
1213{
1214  owl_function_resize();
1215}
1216
1217void owl_function_beep()
1218{
1219  if (owl_global_is_bell(&g)) {
1220    beep();
1221    owl_global_set_needrefresh(&g); /* do we really need this? */
1222  }
1223}
1224
1225void owl_function_subscribe(char *class, char *inst, char *recip)
1226{
1227  int ret;
1228
1229  ret=owl_zephyr_sub(class, inst, recip);
1230  if (ret) {
1231    owl_function_error("Error subscribing.");
1232  } else {
1233    owl_function_makemsg("Subscribed.");
1234  }
1235}
1236
1237void owl_function_unsubscribe(char *class, char *inst, char *recip)
1238{
1239  int ret;
1240
1241  ret=owl_zephyr_unsub(class, inst, recip);
1242  if (ret) {
1243    owl_function_error("Error subscribing.");
1244  } else {
1245    owl_function_makemsg("Unsubscribed.");
1246  }
1247}
1248
1249void owl_function_set_cursor(WINDOW *win)
1250{
1251  wnoutrefresh(win);
1252}
1253
1254void owl_function_full_redisplay()
1255{
1256  redrawwin(owl_global_get_curs_recwin(&g));
1257  redrawwin(owl_global_get_curs_sepwin(&g));
1258  redrawwin(owl_global_get_curs_typwin(&g));
1259  redrawwin(owl_global_get_curs_msgwin(&g));
1260
1261  wnoutrefresh(owl_global_get_curs_recwin(&g));
1262  wnoutrefresh(owl_global_get_curs_sepwin(&g));
1263  wnoutrefresh(owl_global_get_curs_typwin(&g));
1264  wnoutrefresh(owl_global_get_curs_msgwin(&g));
1265 
1266  sepbar("");
1267  owl_function_makemsg("");
1268
1269  owl_global_set_needrefresh(&g);
1270}
1271
1272void owl_function_popless_text(char *text)
1273{
1274  owl_popwin *pw;
1275  owl_viewwin *v;
1276
1277  pw=owl_global_get_popwin(&g);
1278  v=owl_global_get_viewwin(&g);
1279
1280  owl_popwin_up(pw);
1281  owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
1282                        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
1283                        text);
1284  owl_popwin_refresh(pw);
1285  owl_viewwin_redisplay(v, 0);
1286  owl_global_set_needrefresh(&g);
1287}
1288
1289void owl_function_popless_fmtext(owl_fmtext *fm)
1290{
1291  owl_popwin *pw;
1292  owl_viewwin *v;
1293
1294  pw=owl_global_get_popwin(&g);
1295  v=owl_global_get_viewwin(&g);
1296
1297  owl_popwin_up(pw);
1298  owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
1299                   owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
1300                   fm);
1301  owl_popwin_refresh(pw);
1302  owl_viewwin_redisplay(v, 0);
1303  owl_global_set_needrefresh(&g);
1304}
1305
1306void owl_function_popless_file(char *filename)
1307{
1308  owl_fmtext fm;
1309  FILE *file;
1310  char buff[1024];
1311
1312  file=fopen(filename, "r");
1313  if (!file) {
1314    owl_function_error("Could not open file: %s", filename);
1315    return;
1316  }
1317
1318  owl_fmtext_init_null(&fm);
1319  while (fgets(buff, 1024, file)) {
1320    owl_fmtext_append_normal(&fm, buff);
1321    owl_fmtext_append_normal(&fm, "\n");
1322  }
1323
1324  owl_function_popless_fmtext(&fm);
1325  owl_fmtext_free(&fm);
1326  fclose(file);
1327}
1328
1329void owl_function_about()
1330{
1331  char buff[5000];
1332
1333  sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING);
1334  strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n");
1335  strcat(buff, "Institute of Technology.  The first version, 0.5, was\n");
1336  strcat(buff, "released in March 2002.\n");
1337  strcat(buff, "\n");
1338  strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n");
1339  strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n");
1340  strcat(buff, "between Witches and Wizards.\n");
1341  strcat(buff, "\n");
1342  strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n");
1343  strcat(buff, "\n");
1344  strcat(buff, "Permission to use, copy, modify, and distribute this\n");
1345  strcat(buff, "software and its documentation for any purpose and without\n");
1346  strcat(buff, "fee is hereby granted, provided that the above copyright\n");
1347  strcat(buff, "notice and this permission notice appear in all copies\n");
1348  strcat(buff, "and in supporting documentation.  No representation is\n");
1349  strcat(buff, "made about the suitability of this software for any\n");
1350  strcat(buff, "purpose.  It is provided \"as is\" without express\n");
1351  strcat(buff, "or implied warranty.\n");
1352  owl_function_popless_text(buff);
1353}
1354
1355void owl_function_info()
1356{
1357  owl_message *m;
1358  owl_fmtext fm, attrfm;
1359  char buff[10000];
1360  owl_view *v;
1361#ifdef HAVE_LIBZEPHYR
1362  ZNotice_t *n;
1363#endif
1364
1365  owl_fmtext_init_null(&fm);
1366 
1367  v=owl_global_get_current_view(&g);
1368  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1369  if (!m || owl_view_get_size(v)==0) {
1370    owl_function_error("No message selected\n");
1371    return;
1372  }
1373
1374  owl_fmtext_append_bold(&fm, "General Information:\n");
1375  owl_fmtext_append_normal(&fm, "  Msg Id    : ");
1376  sprintf(buff, "%i", owl_message_get_id(m));
1377  owl_fmtext_append_normal(&fm, buff);
1378  owl_fmtext_append_normal(&fm, "\n");
1379
1380  owl_fmtext_append_normal(&fm, "  Type      : ");
1381  owl_fmtext_append_bold(&fm, owl_message_get_type(m));
1382  owl_fmtext_append_normal(&fm, "\n");
1383
1384  if (owl_message_is_direction_in(m)) {
1385    owl_fmtext_append_normal(&fm, "  Direction : in\n");
1386  } else if (owl_message_is_direction_out(m)) {
1387    owl_fmtext_append_normal(&fm, "  Direction : out\n");
1388  } else if (owl_message_is_direction_none(m)) {
1389    owl_fmtext_append_normal(&fm, "  Direction : none\n");
1390  } else {
1391    owl_fmtext_append_normal(&fm, "  Direction : unknown\n");
1392  }
1393
1394  owl_fmtext_append_normal(&fm, "  Time      : ");
1395  owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
1396  owl_fmtext_append_normal(&fm, "\n");
1397
1398  if (!owl_message_is_type_admin(m)) {
1399    owl_fmtext_append_normal(&fm, "  Sender    : ");
1400    owl_fmtext_append_normal(&fm, owl_message_get_sender(m));
1401    owl_fmtext_append_normal(&fm, "\n");
1402   
1403    owl_fmtext_append_normal(&fm, "  Recipient : ");
1404    owl_fmtext_append_normal(&fm, owl_message_get_recipient(m));
1405    owl_fmtext_append_normal(&fm, "\n");
1406  }
1407   
1408  if (owl_message_is_type_zephyr(m)) {
1409    owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n");
1410   
1411    owl_fmtext_append_normal(&fm, "  Class     : ");
1412    owl_fmtext_append_normal(&fm, owl_message_get_class(m));
1413    owl_fmtext_append_normal(&fm, "\n");
1414    owl_fmtext_append_normal(&fm, "  Instance  : ");
1415    owl_fmtext_append_normal(&fm, owl_message_get_instance(m));
1416    owl_fmtext_append_normal(&fm, "\n");
1417    owl_fmtext_append_normal(&fm, "  Opcode    : ");
1418    owl_fmtext_append_normal(&fm, owl_message_get_opcode(m));
1419    owl_fmtext_append_normal(&fm, "\n");
1420   
1421    owl_fmtext_append_normal(&fm, "  Time      : ");
1422    owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
1423    owl_fmtext_append_normal(&fm, "\n");
1424#ifdef HAVE_LIBZEPHYR
1425    if (owl_message_is_direction_in(m)) {
1426      char *ptr, tmpbuff[1024];
1427      int i, j, fields, len;
1428
1429      n=owl_message_get_notice(m);
1430
1431      owl_fmtext_append_normal(&fm, "  Kind      : ");
1432      if (n->z_kind==UNSAFE) {
1433        owl_fmtext_append_normal(&fm, "UNSAFE\n");
1434      } else if (n->z_kind==UNACKED) {
1435        owl_fmtext_append_normal(&fm, "UNACKED\n");
1436      } else if (n->z_kind==ACKED) {
1437        owl_fmtext_append_normal(&fm, "ACKED\n");
1438      } else if (n->z_kind==HMACK) {
1439        owl_fmtext_append_normal(&fm, "HMACK\n");
1440      } else if (n->z_kind==HMCTL) {
1441        owl_fmtext_append_normal(&fm, "HMCTL\n");
1442      } else if (n->z_kind==SERVACK) {
1443        owl_fmtext_append_normal(&fm, "SERVACK\n");
1444      } else if (n->z_kind==SERVNAK) {
1445        owl_fmtext_append_normal(&fm, "SERVNACK\n");
1446      } else if (n->z_kind==CLIENTACK) {
1447        owl_fmtext_append_normal(&fm, "CLIENTACK\n");
1448      } else if (n->z_kind==STAT) {
1449        owl_fmtext_append_normal(&fm, "STAT\n");
1450      } else {
1451        owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n");
1452      }
1453      owl_fmtext_append_normal(&fm, "  Host      : ");
1454      owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
1455      owl_fmtext_append_normal(&fm, "\n");
1456      sprintf(buff, "  Port      : %i\n", n->z_port);
1457      owl_fmtext_append_normal(&fm, buff);
1458
1459      owl_fmtext_append_normal(&fm,    "  Auth      : ");
1460      owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n));
1461      owl_fmtext_append_normal(&fm, "\n");
1462
1463      /* fix this */
1464      sprintf(buff, "  Checkd Ath: %i\n", n->z_checked_auth);
1465      sprintf(buff, "%s  Multi notc: %s\n", buff, n->z_multinotice);
1466      sprintf(buff, "%s  Num other : %i\n", buff, n->z_num_other_fields);
1467      sprintf(buff, "%s  Msg Len   : %i\n", buff, n->z_message_len);
1468      owl_fmtext_append_normal(&fm, buff);
1469     
1470      sprintf(buff, "  Fields    : %i\n", owl_zephyr_get_num_fields(n));
1471      owl_fmtext_append_normal(&fm, buff);
1472     
1473      fields=owl_zephyr_get_num_fields(n);
1474      for (i=0; i<fields; i++) {
1475        sprintf(buff, "  Field %i   : ", i+1);
1476       
1477        ptr=owl_zephyr_get_field(n, i+1, &len);
1478        if (!ptr) break;
1479        if (len<30) {
1480          strncpy(tmpbuff, ptr, len);
1481          tmpbuff[len]='\0';
1482        } else {
1483          strncpy(tmpbuff, ptr, 30);
1484          tmpbuff[30]='\0';
1485          strcat(tmpbuff, "...");
1486        }
1487       
1488        for (j=0; j<strlen(tmpbuff); j++) {
1489          if (tmpbuff[j]=='\n') tmpbuff[j]='~';
1490          if (tmpbuff[j]=='\r') tmpbuff[j]='!';
1491        }
1492       
1493        strcat(buff, tmpbuff);
1494        strcat(buff, "\n");
1495        owl_fmtext_append_normal(&fm, buff);
1496      }
1497      owl_fmtext_append_normal(&fm, "  Default Fm:");
1498      owl_fmtext_append_normal(&fm, n->z_default_format);
1499    }
1500#endif   
1501  }
1502
1503  if (owl_message_is_type_aim(m)) {
1504    owl_fmtext_append_bold(&fm, "\nAIM Specific Information:\n");
1505  }
1506
1507  owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n");
1508  owl_message_attributes_tofmtext(m, &attrfm);
1509  owl_fmtext_append_fmtext(&fm, &attrfm);
1510 
1511  owl_function_popless_fmtext(&fm);
1512  owl_fmtext_free(&fm);
1513  owl_fmtext_free(&attrfm);
1514}
1515
1516/* print the current message in a popup window.
1517 * Use the 'default' style regardless of whatever
1518 * style the user may be using
1519 */
1520void owl_function_curmsg_to_popwin()
1521{
1522  owl_popwin *pw;
1523  owl_view *v;
1524  owl_message *m;
1525  owl_style *s;
1526  owl_fmtext fm;
1527
1528  v=owl_global_get_current_view(&g);
1529  s=owl_global_get_style_by_name(&g, "default");
1530  pw=owl_global_get_popwin(&g);
1531
1532  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
1533
1534  if (!m || owl_view_get_size(v)==0) {
1535    owl_function_error("No current message");
1536    return;
1537  }
1538
1539  owl_fmtext_init_null(&fm);
1540  owl_style_get_formattext(s, &fm, m);
1541
1542  owl_function_popless_fmtext(&fm);
1543  owl_fmtext_free(&fm);
1544}
1545
1546void owl_function_page_curmsg(int step)
1547{
1548  /* scroll down or up within the current message IF the message is truncated */
1549
1550  int offset, curmsg, lines;
1551  owl_view *v;
1552  owl_message *m;
1553
1554  offset=owl_global_get_curmsg_vert_offset(&g);
1555  v=owl_global_get_current_view(&g);
1556  curmsg=owl_global_get_curmsg(&g);
1557  m=owl_view_get_element(v, curmsg);
1558  if (!m || owl_view_get_size(v)==0) return;
1559  lines=owl_message_get_numlines(m);
1560
1561  if (offset==0) {
1562    /* Bail if the curmsg isn't the last one displayed */
1563    if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) {
1564      owl_function_makemsg("The entire message is already displayed");
1565      return;
1566    }
1567   
1568    /* Bail if we're not truncated */
1569    if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {
1570      owl_function_makemsg("The entire message is already displayed");
1571      return;
1572    }
1573  }
1574 
1575 
1576  /* don't scroll past the last line */
1577  if (step>0) {
1578    if (offset+step > lines-1) {
1579      owl_global_set_curmsg_vert_offset(&g, lines-1);
1580    } else {
1581      owl_global_set_curmsg_vert_offset(&g, offset+step);
1582    }
1583  }
1584
1585  /* would we be before the beginning of the message? */
1586  if (step<0) {
1587    if (offset+step<0) {
1588      owl_global_set_curmsg_vert_offset(&g, 0);
1589    } else {
1590      owl_global_set_curmsg_vert_offset(&g, offset+step);
1591    }
1592  }
1593 
1594  /* redisplay */
1595  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1596  owl_global_set_needrefresh(&g);
1597}
1598
1599void owl_function_resize_typwin(int newsize)
1600{
1601  owl_global_set_typwin_lines(&g, newsize);
1602  owl_function_resize();
1603}
1604
1605void owl_function_typwin_grow()
1606{
1607  int i;
1608
1609  i=owl_global_get_typwin_lines(&g);
1610  owl_function_resize_typwin(i+1);
1611}
1612
1613void owl_function_typwin_shrink()
1614{
1615  int i;
1616
1617  i=owl_global_get_typwin_lines(&g);
1618  if (i>2) {
1619    owl_function_resize_typwin(i-1);
1620  }
1621}
1622
1623void owl_function_mainwin_pagedown()
1624{
1625  int i;
1626
1627  i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g));
1628  if (i<0) return;
1629  if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g))
1630      && (owl_global_get_curmsg(&g) < i)
1631      && (i>0)) {
1632    i--;
1633  }
1634  owl_global_set_curmsg(&g, i);
1635  owl_function_nextmsg();
1636}
1637
1638void owl_function_mainwin_pageup()
1639{
1640  owl_global_set_curmsg(&g, owl_global_get_topmsg(&g));
1641  owl_function_prevmsg();
1642}
1643
1644void owl_function_getsubs()
1645{
1646  char *buff;
1647
1648  buff=owl_zephyr_getsubs();
1649
1650  if (buff) {
1651    owl_function_popless_text(buff);
1652  } else {
1653    owl_function_popless_text("Error getting subscriptions");
1654  }
1655           
1656  owl_free(buff);
1657}
1658
1659#define PABUFLEN 5000
1660void owl_function_printallvars()
1661{
1662  char buff[PABUFLEN], *pos, *name;
1663  owl_list varnames;
1664  int i, numvarnames, rem;
1665
1666  pos = buff;
1667  pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");
1668  pos += sprintf(pos, "%-20s   %s\n",  "--------", "-----");
1669  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1670  rem = (buff+PABUFLEN)-pos-1;
1671  numvarnames = owl_list_get_size(&varnames);
1672  for (i=0; i<numvarnames; i++) {
1673    name = owl_list_get_element(&varnames, i);
1674    if (name && name[0]!='_') {
1675      rem = (buff+PABUFLEN)-pos-1;   
1676      pos += snprintf(pos, rem, "\n%-20s = ", name);
1677      rem = (buff+PABUFLEN)-pos-1;   
1678      owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem);
1679      pos = buff+strlen(buff);
1680    }
1681  }
1682  rem = (buff+PABUFLEN)-pos-1;   
1683  snprintf(pos, rem, "\n");
1684  owl_variable_dict_namelist_free(&varnames);
1685 
1686  owl_function_popless_text(buff);
1687}
1688
1689void owl_function_show_variables()
1690{
1691  owl_list varnames;
1692  owl_fmtext fm; 
1693  int i, numvarnames;
1694  char *varname;
1695
1696  owl_fmtext_init_null(&fm);
1697  owl_fmtext_append_bold(&fm, 
1698      "Variables: (use 'show variable <name>' for details)\n");
1699  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
1700  numvarnames = owl_list_get_size(&varnames);
1701  for (i=0; i<numvarnames; i++) {
1702    varname = owl_list_get_element(&varnames, i);
1703    if (varname && varname[0]!='_') {
1704      owl_variable_describe(owl_global_get_vardict(&g), varname, &fm);
1705    }
1706  }
1707  owl_variable_dict_namelist_free(&varnames);
1708  owl_function_popless_fmtext(&fm);
1709  owl_fmtext_free(&fm);
1710}
1711
1712void owl_function_show_variable(char *name)
1713{
1714  owl_fmtext fm; 
1715
1716  owl_fmtext_init_null(&fm);
1717  owl_variable_get_help(owl_global_get_vardict(&g), name, &fm);
1718  owl_function_popless_fmtext(&fm);
1719  owl_fmtext_free(&fm); 
1720}
1721
1722/* note: this applies to global message list, not to view.
1723 * If flag is 1, deletes.  If flag is 0, undeletes. */
1724void owl_function_delete_by_id(int id, int flag)
1725{
1726  owl_messagelist *ml;
1727  owl_message *m;
1728  ml = owl_global_get_msglist(&g);
1729  m = owl_messagelist_get_by_id(ml, id);
1730  if (m) {
1731    if (flag == 1) {
1732      owl_message_mark_delete(m);
1733    } else if (flag == 0) {
1734      owl_message_unmark_delete(m);
1735    }
1736    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1737    owl_global_set_needrefresh(&g);
1738  } else {
1739    owl_function_error("No message with id %d: unable to mark for (un)delete",id);
1740  }
1741}
1742
1743void owl_function_delete_automsgs()
1744{
1745  /* mark for deletion all messages in the current view that match the
1746   * 'trash' filter */
1747
1748  int i, j, count;
1749  owl_message *m;
1750  owl_view *v;
1751  owl_filter *f;
1752
1753  /* get the trash filter */
1754  f=owl_global_get_filter(&g, "trash");
1755  if (!f) {
1756    owl_function_error("No trash filter defined");
1757    return;
1758  }
1759
1760  v=owl_global_get_current_view(&g);
1761
1762  count=0;
1763  j=owl_view_get_size(v);
1764  for (i=0; i<j; i++) {
1765    m=owl_view_get_element(v, i);
1766    if (owl_filter_message_match(f, m)) {
1767      count++;
1768      owl_message_mark_delete(m);
1769    }
1770  }
1771  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1772  owl_function_makemsg("%i messages marked for deletion", count);
1773  owl_global_set_needrefresh(&g);
1774}
1775
1776void owl_function_status()
1777{
1778  char buff[5000];
1779  time_t start;
1780  int up, days, hours, minutes;
1781  owl_fmtext fm;
1782
1783  owl_fmtext_init_null(&fm);
1784
1785  start=owl_global_get_starttime(&g);
1786
1787  owl_fmtext_append_normal(&fm, "General Information:\n");
1788
1789  owl_fmtext_append_normal(&fm, "  Version: ");
1790  owl_fmtext_append_normal(&fm, OWL_VERSION_STRING);
1791  owl_fmtext_append_normal(&fm, "\n");
1792
1793  owl_fmtext_append_normal(&fm, "  Startup Arugments: ");
1794  owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g));
1795  owl_fmtext_append_normal(&fm, "\n");
1796
1797  owl_fmtext_append_normal(&fm, "  Current Directory: ");
1798  (void) getcwd(buff, MAXPATHLEN);
1799  owl_fmtext_append_normal(&fm, buff);
1800  owl_fmtext_append_normal(&fm, "\n");
1801
1802  sprintf(buff, "  Startup Time: %s", ctime(&start));
1803  owl_fmtext_append_normal(&fm, buff);
1804
1805  up=owl_global_get_runtime(&g);
1806  days=up/86400;
1807  up-=days*86400;
1808  hours=up/3600;
1809  up-=hours*3600;
1810  minutes=up/60;
1811  up-=minutes*60;
1812  sprintf(buff, "  Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up);
1813  owl_fmtext_append_normal(&fm, buff);
1814
1815  owl_fmtext_append_normal(&fm, "\nProtocol Options:\n");
1816  owl_fmtext_append_normal(&fm, "  Zephyr included    : ");
1817  if (owl_global_is_havezephyr(&g)) {
1818    owl_fmtext_append_normal(&fm, "yes\n");
1819  } else {
1820    owl_fmtext_append_normal(&fm, "no\n");
1821  }
1822  owl_fmtext_append_normal(&fm, "  AIM included       : yes\n");
1823  owl_fmtext_append_normal(&fm, "  Loopback included  : yes\n");
1824
1825
1826  owl_fmtext_append_normal(&fm, "\nBuild Options:\n");
1827  owl_fmtext_append_normal(&fm, "  Stderr redirection : ");
1828#if OWL_STDERR_REDIR
1829  owl_fmtext_append_normal(&fm, "yes\n");
1830#else
1831  owl_fmtext_append_normal(&fm, "no\n");
1832#endif
1833 
1834
1835  owl_fmtext_append_normal(&fm, "\nMemory Usage:\n");
1836  owl_fmtext_append_normal(&fm, "  Not currently available.\n");
1837  /*
1838  sprintf(buff, "%sMemory Malloced: %i\n", buff, owl_global_get_malloced(&g));
1839  sprintf(buff, "%sMemory Freed: %i\n", buff, owl_global_get_freed(&g));
1840  sprintf(buff, "%sMemory In Use: %i\n", buff, owl_global_get_meminuse(&g));
1841  */
1842
1843  owl_fmtext_append_normal(&fm, "\nAIM Status:\n");
1844  owl_fmtext_append_normal(&fm, "  Logged in: ");
1845  if (owl_global_is_aimloggedin(&g)) {
1846    owl_fmtext_append_normal(&fm, owl_global_get_aim_screenname(&g));
1847    owl_fmtext_append_normal(&fm, "\n");
1848  } else {
1849    owl_fmtext_append_normal(&fm, "(not logged in)\n");
1850  }
1851
1852  owl_fmtext_append_normal(&fm, "  Processing events: ");
1853  if (owl_global_is_doaimevents(&g)) {
1854    owl_fmtext_append_normal(&fm, "yes\n");
1855  } else {
1856    owl_fmtext_append_normal(&fm, "no\n");
1857  }
1858
1859  owl_function_popless_fmtext(&fm);
1860  owl_fmtext_free(&fm);
1861}
1862
1863void owl_function_show_term()
1864{
1865  owl_fmtext fm;
1866  char buff[LINE];
1867
1868  owl_fmtext_init_null(&fm);
1869  sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",
1870          owl_global_get_lines(&g),
1871          owl_global_get_cols(&g));
1872  owl_fmtext_append_normal(&fm, buff);
1873
1874  if (owl_global_get_hascolors(&g)) {
1875    owl_fmtext_append_normal(&fm, "Color: Yes\n");
1876    sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
1877    owl_fmtext_append_normal(&fm, buff);
1878    sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
1879    owl_fmtext_append_normal(&fm, buff);
1880  } else {
1881    owl_fmtext_append_normal(&fm, "Color: No\n");
1882  }
1883
1884  owl_function_popless_fmtext(&fm);
1885  owl_fmtext_free(&fm);
1886}
1887
1888/* if type = 0 then normal reply.
1889 * if type = 1 then it's a reply to sender
1890 * if enter = 0 then allow the command to be edited
1891 * if enter = 1 then don't wait for editing
1892 */
1893void owl_function_reply(int type, int enter)
1894{
1895  char *buff=NULL, *oldbuff;
1896  owl_message *m;
1897  owl_filter *f;
1898 
1899  if (owl_view_get_size(owl_global_get_current_view(&g))==0) {
1900    owl_function_error("No message selected");
1901  } else {
1902    char *class, *inst, *to, *cc=NULL;
1903   
1904    m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g));
1905    if (!m) {
1906      owl_function_error("No message selected");
1907      return;
1908    }
1909
1910    /* first check if we catch the reply-lockout filter */
1911    f=owl_global_get_filter(&g, "reply-lockout");
1912    if (f) {
1913      if (owl_filter_message_match(f, m)) {
1914        owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter");
1915        return;
1916      }
1917    }
1918
1919    /* admin */
1920    if (owl_message_is_type_admin(m)) {
1921      owl_function_error("You cannot reply to an admin message");
1922      return;
1923    }
1924
1925    /* loopback */
1926    if (owl_message_is_type_loopback(m)) {
1927      owl_function_loopwrite_setup();
1928      return;
1929    }
1930
1931    /* zephyr */
1932    if (owl_message_is_type_zephyr(m)) {
1933      /* if it's a zephyr we sent, send it out the same way again */
1934      if (owl_message_is_direction_out(m)) {
1935        owl_function_zwrite_setup(owl_message_get_zwriteline(m));
1936        owl_global_set_buffercommand(&g, owl_message_get_zwriteline(m));
1937        return;
1938      }
1939
1940      /* Special case a personal reply to a webzephyr user on a class */
1941      if ((type==1) && !strcasecmp(owl_message_get_opcode(m), OWL_WEBZEPHYR_OPCODE)) {
1942        class=OWL_WEBZEPHYR_CLASS;
1943        inst=owl_message_get_sender(m);
1944        to=OWL_WEBZEPHYR_PRINCIPAL;
1945      } else if (!strcasecmp(owl_message_get_class(m), OWL_WEBZEPHYR_CLASS) && owl_message_is_loginout(m)) {
1946        /* Special case LOGIN/LOGOUT notifications on class "webzephyr" */
1947        class=OWL_WEBZEPHYR_CLASS;
1948        inst=owl_message_get_instance(m);
1949        to=OWL_WEBZEPHYR_PRINCIPAL;
1950      } else if (owl_message_is_loginout(m)) {
1951        /* Normal LOGIN/LOGOUT messages */
1952        class="MESSAGE";
1953        inst="PERSONAL";
1954        to=owl_message_get_sender(m);
1955      } else if (type==1) {
1956        /* Personal reply */
1957        class="MESSAGE";
1958        inst="PERSONAL";
1959        to=owl_message_get_sender(m);
1960      } else {
1961        /* General reply */
1962        class=owl_message_get_class(m);
1963        inst=owl_message_get_instance(m);
1964        to=owl_message_get_recipient(m);
1965        cc=owl_message_get_cc(m);
1966        if (!strcmp(to, "") || !strcmp(to, "*")) {
1967          to="";
1968        } else if (to[0]=='@') {
1969          /* leave it, to get the realm */
1970        } else {
1971          to=owl_message_get_sender(m);
1972        }
1973      }
1974       
1975      /* create the command line */
1976      if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
1977        buff=owl_strdup("zcrypt");
1978      } else {
1979        buff = owl_strdup("zwrite");
1980      }
1981      if (strcasecmp(class, "message")) {
1982        buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
1983        owl_free(oldbuff);
1984      }
1985      if (strcasecmp(inst, "personal")) {
1986        buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst));
1987        owl_free(oldbuff);
1988      }
1989      if (*to != '\0') {
1990        char *tmp, *oldtmp, *tmp2;
1991        tmp=short_zuser(to);
1992        if (cc) {
1993          tmp = owl_util_uniq(oldtmp=tmp, cc, "-");
1994          owl_free(oldtmp);
1995          buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp);
1996          owl_free(oldbuff);
1997        } else {
1998          if (owl_global_is_smartstrip(&g)) {
1999            tmp2=tmp;
2000            tmp=owl_zephyr_smartstripped_user(tmp2);
2001            owl_free(tmp2);
2002          }
2003          buff = owl_sprintf("%s %s", oldbuff=buff, tmp);
2004          owl_free(oldbuff);
2005        }
2006        owl_free(tmp);
2007      }
2008      if (cc) owl_free(cc);
2009    }
2010
2011    /* aim */
2012    if (owl_message_is_type_aim(m)) {
2013      if (owl_message_is_direction_out(m)) {
2014        buff=owl_sprintf("aimwrite %s", owl_message_get_recipient(m));
2015      } else {
2016        buff=owl_sprintf("aimwrite %s", owl_message_get_sender(m));
2017      }
2018    }
2019   
2020    if (enter) {
2021      owl_history *hist = owl_global_get_cmd_history(&g);
2022      owl_history_store(hist, buff);
2023      owl_history_reset(hist);
2024      owl_function_command_norv(buff);
2025    } else {
2026      owl_function_start_command(buff);
2027    }
2028    owl_free(buff);
2029  }
2030}
2031
2032void owl_function_zlocate(int argc, char **argv, int auth)
2033{
2034  owl_fmtext fm;
2035  char *ptr, buff[LINE];
2036  int i;
2037
2038  owl_fmtext_init_null(&fm);
2039
2040  for (i=0; i<argc; i++) {
2041    ptr=long_zuser(argv[i]);
2042    owl_zephyr_zlocate(ptr, buff, auth);
2043    owl_fmtext_append_normal(&fm, buff);
2044    owl_free(ptr);
2045  }
2046
2047  owl_function_popless_fmtext(&fm);
2048  owl_fmtext_free(&fm);
2049}
2050
2051void owl_function_start_command(char *line)
2052{
2053  int i, j;
2054  owl_editwin *tw;
2055
2056  tw=owl_global_get_typwin(&g);
2057  owl_global_set_typwin_active(&g);
2058  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, 
2059                        owl_global_get_cmd_history(&g));
2060
2061  owl_editwin_set_locktext(tw, "command: ");
2062  owl_global_set_needrefresh(&g);
2063
2064  j=strlen(line);
2065  for (i=0; i<j; i++) {
2066    owl_editwin_process_char(tw, line[i]);
2067  }
2068  owl_editwin_redisplay(tw, 0);
2069
2070  owl_context_set_editline(owl_global_get_context(&g), tw);
2071  owl_function_activate_keymap("editline");
2072}
2073
2074void owl_function_start_question(char *line)
2075{
2076  owl_editwin *tw;
2077
2078  tw=owl_global_get_typwin(&g);
2079  owl_global_set_typwin_active(&g);
2080  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
2081
2082  owl_editwin_set_locktext(tw, line);
2083  owl_global_set_needrefresh(&g);
2084
2085  owl_editwin_redisplay(tw, 0);
2086
2087  owl_context_set_editresponse(owl_global_get_context(&g), tw);
2088  owl_function_activate_keymap("editresponse");
2089}
2090
2091void owl_function_start_password(char *line)
2092{
2093  owl_editwin *tw;
2094
2095  tw=owl_global_get_typwin(&g);
2096  owl_global_set_typwin_active(&g);
2097  owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
2098  owl_editwin_set_echochar(tw, '*');
2099
2100  owl_editwin_set_locktext(tw, line);
2101  owl_global_set_needrefresh(&g);
2102
2103  owl_editwin_redisplay(tw, 0);
2104
2105  owl_context_set_editresponse(owl_global_get_context(&g), tw);
2106  owl_function_activate_keymap("editresponse");
2107}
2108
2109char *owl_function_exec(int argc, char **argv, char *buff, int type)
2110{
2111  /* if type == 1 display in a popup
2112   * if type == 2 display an admin messages
2113   * if type == 0 return output
2114   * else display in a popup
2115   */
2116  char *newbuff, *redirect = " 2>&1 < /dev/null";
2117  char *out, buff2[1024];
2118  int size;
2119  FILE *p;
2120
2121#if OWL_STDERR_REDIR
2122  redirect = " < /dev/null";
2123#endif
2124
2125  if (argc<2) {
2126    owl_function_error("Wrong number of arguments to the exec command");
2127    return NULL;
2128  }
2129
2130  buff = skiptokens(buff, 1);
2131  newbuff = owl_malloc(strlen(buff)+strlen(redirect)+1);
2132  strcpy(newbuff, buff);
2133  strcat(newbuff, redirect);
2134
2135  p=popen(newbuff, "r");
2136  out=owl_malloc(1024);
2137  size=1024;
2138  strcpy(out, "");
2139  while (fgets(buff2, 1024, p)!=NULL) {
2140    size+=1024;
2141    out=owl_realloc(out, size);
2142    strcat(out, buff2);
2143  }
2144  pclose(p);
2145
2146  if (type==1) {
2147    owl_function_popless_text(out);
2148  } else if (type==0) {
2149    return out;
2150  } else if (type==2) {
2151    owl_function_adminmsg(buff, out);
2152  } else {
2153    owl_function_popless_text(out);
2154  }
2155  owl_free(out);
2156  return NULL;
2157}
2158
2159char *owl_function_perl(int argc, char **argv, char *buff, int type)
2160{
2161  /* if type == 1 display in a popup
2162   * if type == 2 display an admin messages
2163   * if type == 0 return output
2164   * else display in a popup
2165   */
2166  char *perlout;
2167
2168  if (argc<2) {
2169    owl_function_error("Wrong number of arguments to perl command");
2170    return NULL;
2171  }
2172
2173  /* consume first token (argv[0]) */
2174  buff = skiptokens(buff, 1);
2175
2176  perlout = owl_perlconfig_execute(buff);
2177  if (perlout) { 
2178    if (type==1) {
2179      owl_function_popless_text(perlout);
2180    } else if (type==2) {
2181      owl_function_adminmsg(buff, perlout);
2182    } else if (type==0) {
2183      return perlout;
2184    } else {
2185      owl_function_popless_text(perlout);
2186    }
2187    owl_free(perlout);
2188  }
2189  return NULL;
2190}
2191
2192#if 0
2193void owl_function_change_view_old(char *filtname)
2194{
2195  owl_view *v;
2196  owl_filter *f;
2197  int curid=-1, newpos, curmsg;
2198  owl_message *curm=NULL;
2199
2200  v=owl_global_get_current_view(&g);
2201  curmsg=owl_global_get_curmsg(&g);
2202  if (curmsg==-1) {
2203    owl_function_debugmsg("Hit the curmsg==-1 case in change_view");
2204  } else {
2205    curm=owl_view_get_element(v, curmsg);
2206    if (curm) {
2207      curid=owl_message_get_id(curm);
2208      owl_view_save_curmsgid(v, curid);
2209    }
2210  }
2211
2212  /* grab the filter */;
2213  f=owl_global_get_filter(&g, filtname);
2214  if (!f) {
2215    owl_function_error("Unknown filter %s", filtname);
2216    return;
2217  }
2218
2219  /* free the existing view and create a new one based on the filter */
2220  owl_view_free(v);
2221  owl_view_create(v, f);
2222
2223  /* Figure out what to set the current message to.
2224   * - If the view we're leaving has messages in it, go to the closest message
2225   *   to the last message pointed to in that view.
2226   * - If the view we're leaving is empty, try to restore the position
2227   *   from the last time we were in the new view.  */
2228  if (curm) {
2229    newpos = owl_view_get_nearest_to_msgid(v, curid);
2230  } else {
2231    newpos = owl_view_get_nearest_to_saved(v);
2232  }
2233
2234  owl_global_set_curmsg(&g, newpos);
2235
2236  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
2237  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2238  owl_global_set_direction_downwards(&g);
2239}
2240#endif
2241
2242void owl_function_change_view(char *filtname)
2243{
2244  owl_view *v;
2245  owl_filter *f;
2246  int curid=-1, newpos, curmsg;
2247  owl_message *curm=NULL;
2248
2249  v=owl_global_get_current_view(&g);
2250
2251  curmsg=owl_global_get_curmsg(&g);
2252  if (curmsg==-1) {
2253    owl_function_debugmsg("Hit the curmsg==-1 case in change_view");
2254  } else {
2255    curm=owl_view_get_element(v, curmsg);
2256    if (curm) {
2257      curid=owl_message_get_id(curm);
2258      owl_view_save_curmsgid(v, curid);
2259    }
2260  }
2261
2262  f=owl_global_get_filter(&g, filtname);
2263  if (!f) {
2264    owl_function_error("Unknown filter %s", filtname);
2265    return;
2266  }
2267
2268  owl_view_new_filter(v, f);
2269
2270  /* Figure out what to set the current message to.
2271   * - If the view we're leaving has messages in it, go to the closest message
2272   *   to the last message pointed to in that view.
2273   * - If the view we're leaving is empty, try to restore the position
2274   *   from the last time we were in the new view.  */
2275  if (curm) {
2276    newpos = owl_view_get_nearest_to_msgid(v, curid);
2277  } else {
2278    newpos = owl_view_get_nearest_to_saved(v);
2279  }
2280
2281  owl_global_set_curmsg(&g, newpos);
2282  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
2283  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2284  owl_global_set_direction_downwards(&g);
2285}
2286
2287void owl_function_create_filter(int argc, char **argv)
2288{
2289  owl_filter *f;
2290  owl_view *v;
2291  int ret, inuse=0;
2292
2293  if (argc < 2) {
2294    owl_function_error("Wrong number of arguments to filter command");
2295    return;
2296  }
2297
2298  v=owl_global_get_current_view(&g);
2299
2300  /* don't touch the all filter */
2301  if (!strcmp(argv[1], "all")) {
2302    owl_function_error("You may not change the 'all' filter.");
2303    return;
2304  }
2305
2306  /* deal with the case of trying change the filter color */
2307  if (argc==4 && !strcmp(argv[2], "-c")) {
2308    f=owl_global_get_filter(&g, argv[1]);
2309    if (!f) {
2310      owl_function_error("The filter '%s' does not exist.", argv[1]);
2311      return;
2312    }
2313    if (owl_util_string_to_color(argv[3])==-1) {
2314      owl_function_error("The color '%s' is not available.", argv[3]);
2315      return;
2316    }
2317    owl_filter_set_color(f, owl_util_string_to_color(argv[3]));
2318    owl_global_set_needrefresh(&g);
2319    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2320    return;
2321  }
2322
2323  /* create the filter and check for errors */
2324  f=owl_malloc(sizeof(owl_filter));
2325  ret=owl_filter_init(f, argv[1], argc-2, argv+2);
2326  if (ret==-1) {
2327    owl_free(f);
2328    owl_function_error("Invalid filter syntax");
2329    return;
2330  }
2331
2332  /* if the named filter is in use by the current view, remember it */
2333  if (!strcmp(owl_view_get_filtname(v), argv[1])) {
2334    inuse=1;
2335  }
2336
2337  /* if the named filter already exists, nuke it */
2338  if (owl_global_get_filter(&g, argv[1])) {
2339    owl_global_remove_filter(&g, argv[1]);
2340  }
2341
2342  /* add the filter */
2343  owl_global_add_filter(&g, f);
2344
2345  /* if it was in use by the current view then update */
2346  if (inuse) {
2347    owl_function_change_view(argv[1]);
2348  }
2349  owl_global_set_needrefresh(&g);
2350  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2351}
2352
2353void owl_function_show_filters()
2354{
2355  owl_list *l;
2356  owl_filter *f;
2357  int i, j;
2358  owl_fmtext fm;
2359
2360  owl_fmtext_init_null(&fm);
2361
2362  l=owl_global_get_filterlist(&g);
2363  j=owl_list_get_size(l);
2364
2365  owl_fmtext_append_bold(&fm, "Filters:\n");
2366
2367  for (i=0; i<j; i++) {
2368    f=owl_list_get_element(l, i);
2369    owl_fmtext_append_normal(&fm, "   ");
2370    if (owl_global_get_hascolors(&g)) {
2371      owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f));
2372    } else {
2373      owl_fmtext_append_normal(&fm, owl_filter_get_name(f));
2374    }
2375    owl_fmtext_append_normal(&fm, "\n");
2376  }
2377  owl_function_popless_fmtext(&fm);
2378  owl_fmtext_free(&fm);
2379}
2380
2381void owl_function_show_filter(char *name)
2382{
2383  owl_filter *f;
2384  char buff[5000];
2385
2386  f=owl_global_get_filter(&g, name);
2387  if (!f) {
2388    owl_function_error("There is no filter named %s", name);
2389    return;
2390  }
2391  owl_filter_print(f, buff);
2392  owl_function_popless_text(buff);
2393}
2394
2395void owl_function_show_zpunts()
2396{
2397  owl_filter *f;
2398  owl_list *fl;
2399  char buff[5000];
2400  owl_fmtext fm;
2401  int i, j;
2402
2403  owl_fmtext_init_null(&fm);
2404
2405  fl=owl_global_get_puntlist(&g);
2406  j=owl_list_get_size(fl);
2407  owl_fmtext_append_bold(&fm, "Active zpunt filters:\n");
2408
2409  for (i=0; i<j; i++) {
2410    f=owl_list_get_element(fl, i);
2411    owl_filter_print(f, buff);
2412    owl_fmtext_append_normal(&fm, buff);
2413  }
2414  owl_function_popless_fmtext(&fm);
2415  owl_fmtext_free(&fm);
2416}
2417
2418/* Create a filter for a class, instance if one doesn't exist.  If
2419 * instance is NULL then catch all messgaes in the class.  Returns the
2420 * name of the filter, which the caller must free.
2421 */
2422char *owl_function_classinstfilt(char *class, char *instance) 
2423{
2424  owl_list *fl;
2425  owl_filter *f;
2426  char *argbuff, *filtname;
2427  char *tmpclass, *tmpinstance = NULL;
2428  int len;
2429
2430  fl=owl_global_get_filterlist(&g);
2431
2432  /* name for the filter */
2433  len=strlen(class)+30;
2434  if (instance) len+=strlen(instance);
2435  filtname=owl_malloc(len);
2436  if (!instance) {
2437    sprintf(filtname, "class-%s", class);
2438  } else {
2439    sprintf(filtname, "class-%s-instance-%s", class, instance);
2440  }
2441  /* downcase it */
2442  downstr(filtname);
2443  /* turn spaces into dots */
2444  owl_text_tr(filtname, ' ', '.');
2445 
2446  /* if it already exists then go with it.  This lets users override */
2447  if (owl_global_get_filter(&g, filtname)) {
2448    return(filtname);
2449  }
2450
2451  /* create the new filter */
2452  argbuff=owl_malloc(len+20);
2453  tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2454  owl_text_tr(tmpclass, ' ', '.');
2455  if (instance) {
2456    tmpinstance=owl_text_quote(instance, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2457    owl_text_tr(tmpinstance, ' ', '.');
2458  }
2459  sprintf(argbuff, "( class ^%s$ )", tmpclass);
2460  if (tmpinstance) {
2461    sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, tmpinstance);
2462  }
2463  owl_free(tmpclass);
2464  if (tmpinstance) owl_free(tmpinstance);
2465
2466  f=owl_malloc(sizeof(owl_filter));
2467  owl_filter_init_fromstring(f, filtname, argbuff);
2468
2469  /* add it to the global list */
2470  owl_global_add_filter(&g, f);
2471
2472  owl_free(argbuff);
2473  return(filtname);
2474}
2475
2476/* Create a filter for personal zephyrs to or from the specified
2477 * zephyr user.  Includes login/logout notifications for the user.
2478 * The name of the filter will be 'user-<user>'.  If a filter already
2479 * exists with this name, no new filter will be created.  This allows
2480 * the configuration to override this function.  Returns the name of
2481 * the filter, which the caller must free.
2482 */
2483char *owl_function_zuserfilt(char *user)
2484{
2485  owl_filter *f;
2486  char *argbuff, *longuser, *shortuser, *filtname;
2487
2488  /* stick the local realm on if it's not there */
2489  longuser=long_zuser(user);
2490  shortuser=short_zuser(user);
2491
2492  /* name for the filter */
2493  filtname=owl_malloc(strlen(shortuser)+20);
2494  sprintf(filtname, "user-%s", shortuser);
2495
2496  /* if it already exists then go with it.  This lets users override */
2497  if (owl_global_get_filter(&g, filtname)) {
2498    return(owl_strdup(filtname));
2499  }
2500
2501  /* create the new-internal filter */
2502  f=owl_malloc(sizeof(owl_filter));
2503
2504  argbuff=owl_malloc(strlen(longuser)+1000);
2505  sprintf(argbuff, "( type ^zephyr$ and ( class ^message$ and instance ^personal$ and ");
2506  sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser);
2507  sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) ) )", argbuff, longuser);
2508
2509  owl_filter_init_fromstring(f, filtname, argbuff);
2510
2511  /* add it to the global list */
2512  owl_global_add_filter(&g, f);
2513
2514  /* free stuff */
2515  owl_free(argbuff);
2516  owl_free(longuser);
2517  owl_free(shortuser);
2518
2519  return(filtname);
2520}
2521
2522/* Create a filter for AIM IM messages to or from the specified
2523 * screenname.  The name of the filter will be 'aimuser-<user>'.  If a
2524 * filter already exists with this name, no new filter will be
2525 * created.  This allows the configuration to override this function.
2526 * Returns the name of the filter, which the caller must free.
2527 */
2528char *owl_function_aimuserfilt(char *user)
2529{
2530  owl_filter *f;
2531  char *argbuff, *filtname;
2532
2533  /* name for the filter */
2534  filtname=owl_malloc(strlen(user)+40);
2535  sprintf(filtname, "aimuser-%s", user);
2536
2537  /* if it already exists then go with it.  This lets users override */
2538  if (owl_global_get_filter(&g, filtname)) {
2539    return(owl_strdup(filtname));
2540  }
2541
2542  /* create the new-internal filter */
2543  f=owl_malloc(sizeof(owl_filter));
2544
2545  argbuff=owl_malloc(1000);
2546  sprintf(argbuff,
2547          "( type ^aim$ and ( ( sender ^%s$ and recipient ^%s$ ) or ( sender ^%s$ and recipient ^%s$ ) ) )",
2548          user, owl_global_get_aim_screenname(&g), owl_global_get_aim_screenname(&g), user);
2549
2550  owl_filter_init_fromstring(f, filtname, argbuff);
2551
2552  /* add it to the global list */
2553  owl_global_add_filter(&g, f);
2554
2555  /* free stuff */
2556  owl_free(argbuff);
2557
2558  return(filtname);
2559}
2560
2561char *owl_function_typefilt(char *type)
2562{
2563  owl_filter *f;
2564  char *argbuff, *filtname;
2565
2566  /* name for the filter */
2567  filtname=owl_sprintf("type-%s", type);
2568
2569  /* if it already exists then go with it.  This lets users override */
2570  if (owl_global_get_filter(&g, filtname)) {
2571    return filtname;
2572  }
2573
2574  /* create the new-internal filter */
2575  f=owl_malloc(sizeof(owl_filter));
2576
2577  argbuff = owl_sprintf("type ^%s$", type);
2578
2579  owl_filter_init_fromstring(f, filtname, argbuff);
2580
2581  /* add it to the global list */
2582  owl_global_add_filter(&g, f);
2583
2584  /* free stuff */
2585  owl_free(argbuff);
2586
2587  return filtname;
2588}
2589
2590/* If flag is 1, marks for deletion.  If flag is 0,
2591 * unmarks for deletion. */
2592void owl_function_delete_curview_msgs(int flag)
2593{
2594  owl_view *v;
2595  int i, j;
2596
2597  v=owl_global_get_current_view(&g);
2598  j=owl_view_get_size(v);
2599  for (i=0; i<j; i++) {
2600    if (flag == 1) {
2601      owl_message_mark_delete(owl_view_get_element(v, i));
2602    } else if (flag == 0) {
2603      owl_message_unmark_delete(owl_view_get_element(v, i));
2604    }
2605  }
2606
2607  owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un");
2608
2609  owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
2610}
2611
2612/* Create a filter based on the current message.  Returns the name of
2613 * a filter or null.  The caller must free this name.
2614 *
2615 * if the curmsg is a personal zephyr return a filter name
2616 *    to the zephyr converstaion with that user.
2617 * If the curmsg is a zephyr class message, instance foo, recip *,
2618 *    return a filter name to the class, inst.
2619 * If the curmsg is a zephyr class message and type==0 then
2620 *    return a filter name for just the class.
2621 * If the curmsg is a zephyr class message and type==1 then
2622 *    return a filter name for the class and instance.
2623 * If the curmsg is a personal AIM message returna  filter
2624 *    name to the AIM conversation with that user
2625 */
2626char *owl_function_smartfilter(int type)
2627{
2628  owl_view *v;
2629  owl_message *m;
2630  char *zperson, *filtname=NULL;
2631 
2632  v=owl_global_get_current_view(&g);
2633  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
2634
2635  if (!m || owl_view_get_size(v)==0) {
2636    owl_function_error("No message selected\n");
2637    return(NULL);
2638  }
2639
2640  /* very simple handling of admin messages for now */
2641  if (owl_message_is_type_admin(m)) {
2642    return(owl_function_typefilt("admin"));
2643  }
2644
2645  /* very simple handling of loopback messages for now */
2646  if (owl_message_is_type_loopback(m)) {
2647    return(owl_function_typefilt("loopback"));
2648  }
2649
2650  /* aim messages */
2651  if (owl_message_is_type_aim(m)) {
2652    if (owl_message_is_direction_in(m)) {
2653      filtname=owl_function_aimuserfilt(owl_message_get_sender(m));
2654    } else if (owl_message_is_direction_out(m)) {
2655      filtname=owl_function_aimuserfilt(owl_message_get_recipient(m));
2656    }
2657    return(filtname);
2658  }
2659
2660  /* narrow personal and login messages to the sender or recip as appropriate */
2661  if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
2662    if (owl_message_is_type_zephyr(m)) {
2663      if (owl_message_is_direction_in(m)) {
2664        zperson=short_zuser(owl_message_get_sender(m));
2665      } else {
2666        zperson=short_zuser(owl_message_get_recipient(m));
2667      }
2668      filtname=owl_function_zuserfilt(zperson);
2669      owl_free(zperson);
2670      return(filtname);
2671    }
2672    return(NULL);
2673  }
2674
2675  /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
2676  if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
2677    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
2678    return(filtname);
2679  }
2680
2681  /* otherwise narrow to the class */
2682  if (type==0) {
2683    filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
2684  } else if (type==1) {
2685    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
2686  }
2687  return(filtname);
2688}
2689
2690void owl_function_smartzpunt(int type)
2691{
2692  /* Starts a zpunt command based on the current class,instance pair.
2693   * If type=0, uses just class.  If type=1, uses instance as well. */
2694  owl_view *v;
2695  owl_message *m;
2696  char *cmd, *cmdprefix, *mclass, *minst;
2697 
2698  v=owl_global_get_current_view(&g);
2699  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
2700
2701  if (!m || owl_view_get_size(v)==0) {
2702    owl_function_error("No message selected\n");
2703    return;
2704  }
2705
2706  /* for now we skip admin messages. */
2707  if (owl_message_is_type_admin(m)
2708      || owl_message_is_loginout(m)
2709      || !owl_message_is_type_zephyr(m)) {
2710    owl_function_error("smartzpunt doesn't support this message type.");
2711    return;
2712  }
2713
2714  mclass = owl_message_get_class(m);
2715  minst = owl_message_get_instance(m);
2716  if (!mclass || !*mclass || *mclass==' '
2717      || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal"))
2718      || (type && (!minst || !*minst|| *minst==' '))) {
2719    owl_function_error("smartzpunt can't safely do this for <%s,%s>",
2720                         mclass, minst);
2721  } else {
2722    cmdprefix = "start-command zpunt ";
2723    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10);
2724    strcpy(cmd, cmdprefix);
2725    strcat(cmd, owl_getquoting(mclass));
2726    strcat(cmd, mclass);
2727    strcat(cmd, owl_getquoting(mclass));
2728    if (type) {
2729      strcat(cmd, " ");
2730      strcat(cmd, owl_getquoting(minst));
2731      strcat(cmd, minst);
2732      strcat(cmd, owl_getquoting(minst));
2733    } else {
2734      strcat(cmd, " *");
2735    }
2736    owl_function_command(cmd);
2737    owl_free(cmd);
2738  }
2739}
2740
2741void owl_function_color_current_filter(char *color)
2742{
2743  owl_filter *f;
2744  char *name;
2745
2746  name=owl_view_get_filtname(owl_global_get_current_view(&g));
2747  f=owl_global_get_filter(&g, name);
2748  if (!f) {
2749    owl_function_error("Unknown filter");
2750    return;
2751  }
2752
2753  /* don't touch the all filter */
2754  if (!strcmp(name, "all")) {
2755    owl_function_error("You may not change the 'all' filter.");
2756    return;
2757  }
2758
2759  /* deal with the case of trying change the filter color */
2760  if (owl_util_string_to_color(color)==-1) {
2761    owl_function_error("No color named '%s' avilable.");
2762    return;
2763  }
2764  owl_filter_set_color(f, owl_util_string_to_color(color));
2765  owl_global_set_needrefresh(&g);
2766  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2767}
2768
2769void owl_function_show_colors()
2770{
2771  owl_fmtext fm;
2772
2773  owl_fmtext_init_null(&fm);
2774  owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT);
2775  owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED);
2776  owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN);
2777  owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW);
2778  owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE);
2779  owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA);
2780  owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN);
2781  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE);
2782
2783  owl_function_popless_fmtext(&fm);
2784  owl_fmtext_free(&fm);
2785}
2786
2787/* add the given class, inst, recip to the punt list for filtering.
2788 *   if direction==0 then punt
2789 *   if direction==1 then unpunt
2790 */
2791void owl_function_zpunt(char *class, char *inst, char *recip, int direction)
2792{
2793  owl_filter *f;
2794  owl_list *fl;
2795  char *buff;
2796  char *quoted;
2797  int ret, i, j;
2798
2799  fl=owl_global_get_puntlist(&g);
2800
2801  /* first, create the filter */
2802  f=malloc(sizeof(owl_filter));
2803  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
2804  strcpy(buff, "class");
2805  if (!strcmp(class, "*")) {
2806    strcat(buff, " .*");
2807  } else {
2808    quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2809    owl_text_tr(quoted, ' ', '.');
2810    sprintf(buff, "%s ^%s$", buff, quoted);
2811    owl_free(quoted);
2812  }
2813  if (!strcmp(inst, "*")) {
2814    strcat(buff, " and instance .*");
2815  } else {
2816    quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2817    owl_text_tr(quoted, ' ', '.');
2818    sprintf(buff, "%s and instance ^%s$", buff, quoted);
2819    owl_free(quoted);
2820  }
2821  if (strcmp(recip, "*")) {
2822    quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
2823    owl_text_tr(quoted, ' ', '.');
2824    sprintf(buff, "%s and recipient ^%s$", buff, quoted);
2825    owl_free(quoted);
2826  }
2827 
2828  owl_function_debugmsg("About to filter %s", buff);
2829  ret=owl_filter_init_fromstring(f, "punt-filter", buff);
2830  owl_free(buff);
2831  if (ret) {
2832    owl_function_error("Error creating filter for zpunt");
2833    owl_filter_free(f);
2834    return;
2835  }
2836
2837  /* Check for an identical filter */
2838  j=owl_list_get_size(fl);
2839  for (i=0; i<j; i++) {
2840    if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
2841      /* if we're punting, then just silently bow out on this duplicate */
2842      if (direction==0) {
2843        owl_filter_free(f);
2844        return;
2845      }
2846
2847      /* if we're unpunting, then remove this filter from the puntlist */
2848      if (direction==1) {
2849        owl_filter_free(owl_list_get_element(fl, i));
2850        owl_list_remove_element(fl, i);
2851        return;
2852      }
2853    }
2854  }
2855
2856  /* If we're punting, add the filter to the global punt list */
2857  if (direction==0) {
2858    owl_list_append_element(fl, f);
2859  }
2860}
2861
2862void owl_function_activate_keymap(char *keymap)
2863{
2864  if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) {
2865    owl_function_error("Unable to activate keymap '%s'", keymap);
2866  }
2867}
2868
2869void owl_function_show_keymaps()
2870{
2871  owl_list l;
2872  owl_fmtext fm;
2873  owl_keymap *km;
2874  owl_keyhandler *kh;
2875  int i, numkm;
2876  char *kmname;
2877
2878  kh = owl_global_get_keyhandler(&g);
2879  owl_fmtext_init_null(&fm);
2880  owl_fmtext_append_bold(&fm, "Keymaps:   ");
2881  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
2882  owl_keyhandler_get_keymap_names(kh, &l);
2883  owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
2884  owl_fmtext_append_normal(&fm, "\n");
2885
2886  numkm = owl_list_get_size(&l);
2887  for (i=0; i<numkm; i++) {
2888    kmname = owl_list_get_element(&l, i);
2889    km = owl_keyhandler_get_keymap(kh, kmname);
2890    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
2891    owl_keymap_get_details(km, &fm);   
2892  }
2893  owl_fmtext_append_normal(&fm, "\n");
2894 
2895  owl_function_popless_fmtext(&fm);
2896  owl_keyhandler_keymap_namelist_free(&l);
2897  owl_fmtext_free(&fm);
2898}
2899
2900char *owl_function_keymap_summary(void *name)
2901{
2902  owl_keymap *km
2903    = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2904  if (km) return owl_keymap_summary(km);
2905  else return(NULL);
2906}
2907
2908/* TODO: implement for real */
2909void owl_function_show_keymap(char *name)
2910{
2911  owl_fmtext fm;
2912  owl_keymap *km;
2913
2914  owl_fmtext_init_null(&fm);
2915  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name);
2916  if (km) {
2917    owl_keymap_get_details(km, &fm);
2918  } else {
2919    owl_fmtext_append_normal(&fm, "No such keymap...\n");
2920  } 
2921  owl_function_popless_fmtext(&fm);
2922  owl_fmtext_free(&fm);
2923}
2924
2925void owl_function_help_for_command(char *cmdname)
2926{
2927  owl_fmtext fm;
2928
2929  owl_fmtext_init_null(&fm);
2930  owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm);
2931  owl_function_popless_fmtext(&fm); 
2932  owl_fmtext_free(&fm);
2933}
2934
2935void owl_function_search_start(char *string, int direction)
2936{
2937  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
2938  owl_global_set_search_active(&g, string);
2939  owl_function_search_helper(0, direction);
2940}
2941
2942void owl_function_search_continue(int direction)
2943{
2944  /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */
2945  owl_function_search_helper(1, direction);
2946}
2947
2948void owl_function_search_helper(int mode, int direction)
2949{
2950  /* move to a message that contains the string.  If direction is
2951   * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is
2952   * OWL_DIRECTION_UPWARDS then search backwards.
2953   *
2954   * If mode==0 then it will stay on the current message if it
2955   * contains the string.
2956   */
2957
2958  owl_view *v;
2959  int viewsize, i, curmsg, start;
2960  owl_message *m;
2961
2962  v=owl_global_get_current_view(&g);
2963  viewsize=owl_view_get_size(v);
2964  curmsg=owl_global_get_curmsg(&g);
2965 
2966  if (viewsize==0) {
2967    owl_function_error("No messages present");
2968    return;
2969  }
2970
2971  if (mode==0) {
2972    start=curmsg;
2973  } else if (direction==OWL_DIRECTION_DOWNWARDS) {
2974    start=curmsg+1;
2975  } else {
2976    start=curmsg-1;
2977  }
2978
2979  /* bounds check */
2980  if (start>=viewsize || start<0) {
2981    owl_function_error("No further matches found");
2982    return;
2983  }
2984
2985  for (i=start; i<viewsize && i>=0;) {
2986    m=owl_view_get_element(v, i);
2987    if (owl_message_search(m, owl_global_get_search_string(&g))) {
2988      owl_global_set_curmsg(&g, i);
2989      owl_function_calculate_topmsg(direction);
2990      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2991      if (direction==OWL_DIRECTION_DOWNWARDS) {
2992        owl_global_set_direction_downwards(&g);
2993      } else {
2994        owl_global_set_direction_upwards(&g);
2995      }
2996      return;
2997    }
2998    if (direction==OWL_DIRECTION_DOWNWARDS) {
2999      i++;
3000    } else {
3001      i--;
3002    }
3003  }
3004  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
3005  owl_function_error("No matches found");
3006}
3007
3008/* strips formatting from ztext and returns the unformatted text.
3009 * caller is responsible for freeing. */
3010char *owl_function_ztext_stylestrip(char *zt)
3011{
3012  owl_fmtext fm;
3013  char *plaintext;
3014
3015  owl_fmtext_init_null(&fm);
3016  owl_fmtext_append_ztext(&fm, zt);
3017  plaintext = owl_fmtext_print_plain(&fm);
3018  owl_fmtext_free(&fm);
3019  return(plaintext);
3020}
3021
3022/* Popup a buddylisting.  If file is NULL use the default .anyone */
3023void owl_function_buddylist(int aim, int zephyr, char *file)
3024{
3025  int i, j, idle;
3026  owl_fmtext fm;
3027  owl_buddylist *bl;
3028  owl_buddy *b;
3029  char *foo, *timestr;
3030#ifdef HAVE_LIBZEPHYR
3031  char *ourfile, *tmp, buff[LINE], *line;
3032  ZLocations_t location[200];
3033  FILE *f;
3034  int numlocs, ret;
3035#endif
3036
3037  owl_fmtext_init_null(&fm);
3038
3039  /* AIM first */
3040  if (aim && owl_global_is_aimloggedin(&g)) {
3041    bl=owl_global_get_buddylist(&g);
3042
3043    owl_fmtext_append_bold(&fm, "AIM users logged in:\n");
3044    /* we're assuming AIM for now */
3045    j=owl_buddylist_get_size(bl);
3046    for (i=0; i<j; i++) {
3047      b=owl_buddylist_get_buddy_n(bl, i);
3048      idle=owl_buddy_get_idle_time(b);
3049      if (idle!=0) {
3050        timestr=owl_util_minutes_to_timestr(idle);
3051      } else {
3052        timestr=owl_strdup("");
3053      }
3054      foo=owl_sprintf("  %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr);
3055      owl_fmtext_append_normal(&fm, foo);
3056      owl_free(timestr);
3057      owl_free(foo);
3058    }
3059  }
3060
3061#ifdef HAVE_LIBZEPHYR
3062  if (zephyr) {
3063    if (file==NULL) {
3064      tmp=owl_global_get_homedir(&g);
3065      ourfile=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
3066    } else {
3067      ourfile=owl_strdup(file);
3068    }
3069
3070    owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n");
3071    f=fopen(ourfile, "r");
3072    if (!f) {
3073      owl_fmtext_append_normal(&fm, "  Error opening file ");
3074      owl_fmtext_append_normal(&fm, ourfile);
3075      owl_fmtext_append_normal(&fm, "\n");
3076      owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : "");
3077    } else {
3078      while (fgets(buff, LINE, f)!=NULL) {
3079        /* ignore comments, blank lines etc. */
3080        if (buff[0]=='#') continue;
3081        if (buff[0]=='\n') continue;
3082        if (buff[0]=='\0') continue;
3083       
3084        /* strip the \n */
3085        buff[strlen(buff)-1]='\0';
3086       
3087        /* ingore from # on */
3088        tmp=strchr(buff, '#');
3089        if (tmp) tmp[0]='\0';
3090       
3091        /* ingore from SPC */
3092        tmp=strchr(buff, ' ');
3093        if (tmp) tmp[0]='\0';
3094       
3095        /* stick on the local realm. */
3096        if (!strchr(buff, '@')) {
3097          strcat(buff, "@");
3098          strcat(buff, ZGetRealm());
3099        }
3100       
3101        ret=ZLocateUser(buff, &numlocs, ZAUTH);
3102        if (ret!=ZERR_NONE) {
3103          owl_function_error("Error getting location for %s", buff);
3104          continue;
3105        }
3106       
3107        numlocs=200;
3108        ret=ZGetLocations(location, &numlocs);
3109        if (ret==0) {
3110          for (i=0; i<numlocs; i++) {
3111            line=malloc(strlen(location[i].host)+strlen(location[i].time)+strlen(location[i].tty)+100);
3112            tmp=short_zuser(buff);
3113            sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
3114                    tmp,
3115                    location[i].host,
3116                    location[i].tty,
3117                    location[i].time);
3118            owl_fmtext_append_normal(&fm, line);
3119            owl_free(tmp);
3120          }
3121          if (numlocs>=200) {
3122            owl_fmtext_append_normal(&fm, "  Too many locations found for this user, truncating.\n");
3123          }
3124        }
3125      }
3126      fclose(f);
3127    }
3128    owl_free(ourfile);
3129  }
3130#endif
3131 
3132  owl_function_popless_fmtext(&fm);
3133  owl_fmtext_free(&fm);
3134}
3135
3136/* Dump messages in the current view to the file 'filename'. */
3137void owl_function_dump(char *filename) 
3138{
3139  int i, j, count;
3140  owl_message *m;
3141  owl_view *v;
3142  FILE *file;
3143
3144  /* struct stat sbuf; */
3145
3146  v=owl_global_get_current_view(&g);
3147
3148  /* in the future make it ask yes/no */
3149  /*
3150  ret=stat(filename, &sbuf);
3151  if (!ret) {
3152    ret=owl_function_askyesno("File exists, continue? [Y/n]");
3153    if (!ret) return;
3154  }
3155  */
3156
3157  file=fopen(filename, "w");
3158  if (!file) {
3159    owl_function_error("Error opening file");
3160    return;
3161  }
3162
3163  count=0;
3164  j=owl_view_get_size(v);
3165  for (i=0; i<j; i++) {
3166    m=owl_view_get_element(v, i);
3167    fputs(owl_message_get_text(m), file);
3168  }
3169  fclose(file);
3170  owl_function_makemsg("Messages dumped to %s", filename);
3171}
3172
3173void owl_function_do_newmsgproc(void)
3174{
3175  if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) {
3176    /* if there's a process out there, we need to check on it */
3177    if (owl_global_get_newmsgproc_pid(&g)) {
3178      owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g));
3179      owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG));
3180      waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG);
3181      if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) {
3182        /* it exited */
3183        owl_global_set_newmsgproc_pid(&g, 0);
3184        owl_function_debugmsg("newmsgproc exited");
3185      } else {
3186        owl_function_debugmsg("newmsgproc did not exit");
3187      }
3188    }
3189   
3190    /* if it exited, fork & exec a new one */
3191    if (owl_global_get_newmsgproc_pid(&g)==0) {
3192      int i, myargc;
3193      i=fork();
3194      if (i) {
3195        /* parent set the child's pid */
3196        owl_global_set_newmsgproc_pid(&g, i);
3197        owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
3198      } else {
3199        /* child exec's the program */
3200        char **parsed;
3201        parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
3202        if (myargc < 0) {
3203          owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g));
3204        }
3205        if (myargc <= 0) {
3206          _exit(127);
3207        }
3208        parsed=realloc(parsed, sizeof(*parsed) * (myargc+1));
3209        parsed[myargc] = NULL;
3210       
3211        owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc);
3212       
3213        execvp(parsed[0], parsed);
3214       
3215       
3216        /* was there an error exec'ing? */
3217        owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s", 
3218                              owl_global_get_newmsgproc(&g), parsed[0], strerror(errno));
3219        _exit(127);
3220      }
3221    }
3222  }
3223}
3224
3225/* print the xterm escape sequence to raise the window */
3226void owl_function_xterm_raise(void)
3227{
3228  printf("\033[5t");
3229}
3230
3231/* print the xterm escape sequence to deiconify the window */
3232void owl_function_xterm_deiconify(void)
3233{
3234  printf("\033[1t");
3235}
3236
3237/* Add the specified command to the startup file.  Eventually this
3238 * should be clever, and rewriting settings that will obviosly
3239 * override earlier settings with 'set' 'bindkey' and 'alias'
3240 * commands.  For now though we just remove any line that would
3241 * duplicate this one and then append this line to the end of
3242 * startupfile.
3243 */
3244void owl_function_addstartup(char *buff)
3245{
3246  FILE *file;
3247  char *filename;
3248
3249  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3250  file=fopen(filename, "a");
3251  if (!file) {
3252    owl_function_error("Error opening startupfile for new command");
3253    owl_free(filename);
3254    return;
3255  }
3256
3257  /* delete earlier copies */
3258  owl_util_file_deleteline(filename, buff, 1);
3259  owl_free(filename);
3260
3261  /* add this line */
3262  fprintf(file, "%s\n", buff);
3263
3264  fclose(file);
3265}
3266
3267/* Remove the specified command from the startup file. */
3268void owl_function_delstartup(char *buff)
3269{
3270  char *filename;
3271  filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3272  owl_util_file_deleteline(filename, buff, 1);
3273  owl_free(filename);
3274}
3275
3276/* Execute owl commands from the given filename.  If the filename
3277 * is NULL, use the default owl startup commands file.
3278 */
3279void owl_function_source(char *filename)
3280{
3281  FILE *file;
3282  char buff[LINE];
3283
3284  if (!filename) {
3285    filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
3286    file=fopen(filename, "r");
3287    owl_free(filename);
3288  } else {
3289    file=fopen(filename, "r");
3290  }
3291  if (!file) {
3292    /* just fail silently if it doesn't exist */
3293    return;
3294  }
3295  while (fgets(buff, LINE, file)!=NULL) {
3296    buff[strlen(buff)-1]='\0';
3297    owl_function_command(buff);
3298  }
3299  fclose(file);
3300}
3301
3302void owl_function_change_style(owl_view *v, char *stylename)
3303{
3304  owl_style *s;
3305
3306  s=owl_global_get_style_by_name(&g, stylename);
3307  if (!s) {
3308    owl_function_error("No style named %s", stylename);
3309    return;
3310  }
3311  owl_view_set_style(v, s);
3312  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
3313  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
3314  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
3315}
3316
3317void owl_function_toggleoneline()
3318{
3319  owl_view *v;
3320  owl_style *s;
3321
3322  v=owl_global_get_current_view(&g);
3323  s=owl_view_get_style(v);
3324
3325  if (!owl_style_matches_name(s, "oneline")) {
3326    owl_function_change_style(v, "oneline");
3327  } else {
3328    owl_function_change_style(v, owl_global_get_default_style(&g));
3329  }
3330
3331  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
3332  owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
3333  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
3334}
3335
3336void owl_function_error(char *fmt, ...)
3337{
3338  va_list ap;
3339  char buff[2048], buff2[2048];
3340  char *date;
3341  time_t now;
3342
3343  now=time(NULL);
3344  date=owl_strdup(ctime(&now));
3345  date[strlen(date)-1]='\0';
3346
3347  va_start(ap, fmt);
3348
3349  vsnprintf(buff, 2048, fmt, ap);
3350  sprintf(buff2, "%s %s", date, buff);
3351  owl_function_debugmsg("ERROR: %s", buff);
3352  if (owl_global_get_curs_msgwin(&g)) {
3353    werase(owl_global_get_curs_msgwin(&g));
3354    waddstr(owl_global_get_curs_msgwin(&g), buff); 
3355    wnoutrefresh(owl_global_get_curs_msgwin(&g));
3356    owl_global_set_needrefresh(&g);
3357  }
3358  owl_errqueue_append_err(owl_global_get_errqueue(&g), buff2);
3359  va_end(ap);
3360  owl_free(date);
3361}
3362
3363void owl_function_showerrs()
3364{
3365  owl_fmtext fm;
3366
3367  owl_fmtext_init_null(&fm);
3368  owl_fmtext_append_normal(&fm, "Errors:\n\n");
3369  owl_errqueue_to_fmtext(owl_global_get_errqueue(&g), &fm);
3370  owl_function_popless_fmtext(&fm);
3371}
3372
3373void owl_function_makemsg(char *fmt, ...)
3374{
3375  va_list ap;
3376  char buff[2048];
3377
3378  if (!owl_global_get_curs_msgwin(&g)) return;
3379
3380  va_start(ap, fmt);
3381  werase(owl_global_get_curs_msgwin(&g));
3382 
3383  vsnprintf(buff, 2048, fmt, ap);
3384  owl_function_debugmsg("makemsg: %s", buff);
3385  waddstr(owl_global_get_curs_msgwin(&g), buff); 
3386  wnoutrefresh(owl_global_get_curs_msgwin(&g));
3387  owl_global_set_needrefresh(&g);
3388  va_end(ap);
3389}
Note: See TracBrowser for help on using the repository browser.