source: functions.c @ b6a7367

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