source: functions.c @ f562355

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