source: functions.c @ d54838d

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