source: global.c @ 99cc3dc

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 99cc3dc was 40bda84, checked in by Nelson Elhage <nelhage@mit.edu>, 14 years ago
Catch ^Z and display a message instead of suspending.
  • Property mode set to 100644
File size: 20.9 KB
RevLine 
[7d4fbcd]1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <termios.h>
7#include <sys/ioctl.h>
8#include <time.h>
9#include "owl.h"
10
11#ifndef MAXHOSTNAMELEN
12#define MAXHOSTNAMELEN 256
13#endif
14
15void owl_global_init(owl_global *g) {
16  struct hostent *hent;
17  char hostname[MAXHOSTNAMELEN];
[ad15610]18  char *cd;
[7d4fbcd]19
[8262340]20  g->malloced=0;
21  g->freed=0;
22
[7d4fbcd]23  gethostname(hostname, MAXHOSTNAMELEN);
24  hent=gethostbyname(hostname);
25  if (!hent) {
[a8938c7]26    g->thishost=owl_strdup("localhost");
[7d4fbcd]27  } else {
[a8938c7]28    g->thishost=owl_strdup(hent->h_name);
[7d4fbcd]29  }
30
31  owl_context_init(&g->ctx);
32  owl_context_set_startup(&g->ctx);
33  g->curmsg=0;
34  g->topmsg=0;
[bd783db]35  g->markedmsgid=-1;
[7d4fbcd]36  g->needrefresh=1;
[a8938c7]37  g->startupargs=NULL;
[7d4fbcd]38
39  owl_variable_dict_setup(&(g->vars));
40
41  g->lines=LINES;
42  g->cols=COLS;
43
44  g->rightshift=0;
45
[a556caa]46  g->tw = owl_editwin_allocate();
47  owl_editwin_init(g->tw, NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
[7d4fbcd]48
49  owl_keyhandler_init(&g->kh);
50  owl_keys_setup_keymaps(&g->kh);
51
52  owl_list_create(&(g->filterlist));
53  owl_list_create(&(g->puntlist));
[d09e5a1]54  owl_list_create(&(g->messagequeue));
[f1e629d]55  owl_dict_create(&(g->styledict));
[7d4fbcd]56  g->curmsg_vert_offset=0;
57  g->resizepending=0;
58  g->typwinactive=0;
59  g->direction=OWL_DIRECTION_DOWNWARDS;
60  g->zaway=0;
61  if (has_colors()) {
62    g->hascolors=1;
63  }
64  g->colorpairs=COLOR_PAIRS;
[8fa9562]65  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]66  g->debug=OWL_DEBUG;
[41c9a96]67  owl_regex_init(&g->search_re);
[7d4fbcd]68  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]69  g->lastinputtime=g->starttime;
[700c712]70  g->newmsgproc_pid=0;
[61e79a9]71 
[7d4fbcd]72  owl_global_set_config_format(g, 0);
73  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
74  owl_global_set_no_have_config(g);
[10b866d]75  owl_history_init(&(g->msghist));
76  owl_history_init(&(g->cmdhist));
[5a9f6fe]77  owl_history_set_norepeats(&(g->cmdhist));
[7d4fbcd]78  g->nextmsgid=0;
79
80  _owl_global_setup_windows(g);
81
82  /* Fill in some variables which don't have constant defaults */
83  /* TODO: come back later and check passwd file first */
[a8938c7]84  g->homedir=owl_strdup(getenv("HOME"));
[7d4fbcd]85
[b363d83]86  g->confdir = NULL;
87  g->startupfile = NULL;
[ad15610]88  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
[b363d83]89  owl_global_set_confdir(g, cd);
90  owl_free(cd);
91
[7d4fbcd]92  owl_messagelist_create(&(g->msglist));
93  owl_mainwin_init(&(g->mw));
94  owl_popwin_init(&(g->pw));
[d09e5a1]95
96  g->aim_screenname=NULL;
[81655f8]97  g->aim_screenname_for_filters=NULL;
[d09e5a1]98  g->aim_loggedin=0;
[aa5f725]99  owl_buddylist_init(&(g->buddylist));
[b7bb454]100
[09489b89]101  g->havezephyr=0;
102  g->haveaim=0;
[b7bb454]103  g->ignoreaimlogin=0;
[a352335c]104  owl_global_set_no_doaimevents(g);
[ec6ff52]105
106  owl_errqueue_init(&(g->errqueue));
[c9e72d1]107  g->got_err_signal=0;
[5a95b69]108
109  owl_zbuddylist_create(&(g->zbuddies));
[8e401cae]110
111  owl_obarray_init(&(g->obarray));
[a387d12e]112
113  owl_message_init_fmtext_cache();
[9c7a701]114  owl_list_create(&(g->dispatchlist));
[58d1f8a]115  g->timerlist = NULL;
[adee9cc]116  g->interrupted = FALSE;
[40bda84]117  g->got_sigtstp = FALSE;
[7d4fbcd]118}
119
[eb6cedc]120/* Called once perl has been initialized */
121void owl_global_complete_setup(owl_global *g)
122{
123  owl_cmddict_setup(&(g->cmds));
124}
125
[7d4fbcd]126void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]127  int cols, typwin_lines;
[7d4fbcd]128
129  cols=g->cols;
[ecd5dc5]130  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]131
132  /* set the new window sizes */
133  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]134  if (g->recwinlines<0) {
135    /* gotta deal with this */
136    g->recwinlines=0;
[ecd5dc5]137  }
[7d4fbcd]138
[176d3443]139  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
140
[7d4fbcd]141  /* create the new windows */
142  g->recwin=newwin(g->recwinlines, cols, 0, 0);
[ecd5dc5]143  if (g->recwin==NULL) {
[2b237308]144    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n");
[ecd5dc5]145    endwin();
146    exit(50);
147  }
148     
[7d4fbcd]149  g->sepwin=newwin(1, cols, g->recwinlines, 0);
150  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
151  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
152
[a556caa]153  owl_editwin_set_curswin(g->tw, g->typwin, typwin_lines, g->cols);
[7d4fbcd]154
155  idlok(g->typwin, FALSE);
156  idlok(g->recwin, FALSE);
157  idlok(g->sepwin, FALSE);
158  idlok(g->msgwin, FALSE);
159
160  nodelay(g->typwin, 1);
161  keypad(g->typwin, TRUE);
162  wmove(g->typwin, 0, 0);
163
164  meta(g->typwin, TRUE);
165}
166
167owl_context *owl_global_get_context(owl_global *g) {
168  return(&g->ctx);
169}
170                         
[8742840]171int owl_global_get_lines(const owl_global *g) {
[7d4fbcd]172  return(g->lines);
173}
174
[8742840]175int owl_global_get_cols(const owl_global *g) {
[7d4fbcd]176  return(g->cols);
177}
178
[8742840]179int owl_global_get_recwin_lines(const owl_global *g) {
[7d4fbcd]180  return(g->recwinlines);
181}
182
183/* curmsg */
184
[8742840]185int owl_global_get_curmsg(const owl_global *g) {
[7d4fbcd]186  return(g->curmsg);
187}
188
189void owl_global_set_curmsg(owl_global *g, int i) {
190  g->curmsg=i;
191  /* we will reset the vertical offset from here */
192  /* we might want to move this out to the functions later */
193  owl_global_set_curmsg_vert_offset(g, 0);
194}
195
196/* topmsg */
197
[8742840]198int owl_global_get_topmsg(const owl_global *g) {
[7d4fbcd]199  return(g->topmsg);
200}
201
202void owl_global_set_topmsg(owl_global *g, int i) {
203  g->topmsg=i;
204}
205
[70110286]206/* markedmsgid */
207
[8742840]208int owl_global_get_markedmsgid(const owl_global *g) {
[70110286]209  return(g->markedmsgid);
210}
211
212void owl_global_set_markedmsgid(owl_global *g, int i) {
213  g->markedmsgid=i;
214  /* i; index of message in the current view.
[c08c70a]215  const owl_message *m;
[70110286]216  owl_view *v;
217
218  v = owl_global_get_current_view(&g);
219  m = owl_view_get_element(v, i);
220  g->markedmsgid = m ? owl_message_get_id(m) : 0;
221  */
222}
223
[7d4fbcd]224/* windows */
225
226owl_mainwin *owl_global_get_mainwin(owl_global *g) {
227  return(&(g->mw));
228}
229
230owl_popwin *owl_global_get_popwin(owl_global *g) {
231  return(&(g->pw));
232}
233
234/* msglist */
235
236owl_messagelist *owl_global_get_msglist(owl_global *g) {
237  return(&(g->msglist));
238}
239
240/* keyhandler */
241
242owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
243  return(&(g->kh));
244}
245
246/* curses windows */
247
[8742840]248WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
[7d4fbcd]249  return(g->recwin);
250}
251
[8742840]252WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
[7d4fbcd]253  return(g->sepwin);
254}
255
[8742840]256WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
[7d4fbcd]257  return(g->msgwin);
258}
259
[8742840]260WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
[7d4fbcd]261  return(g->typwin);
262}
263
264/* typwin */
265
[8742840]266owl_editwin *owl_global_get_typwin(const owl_global *g) {
[a556caa]267  return(g->tw);
[7d4fbcd]268}
269
270/* buffercommand */
271
[e19eb97]272void owl_global_set_buffercommand(owl_global *g, const char *command) {
[1b6b2f3]273  owl_editwin_set_command(owl_global_get_typwin(g), command);
[7d4fbcd]274}
275
[8742840]276const char *owl_global_get_buffercommand(const owl_global *g) {
[1b6b2f3]277  return owl_editwin_get_command(owl_global_get_typwin(g));
[7d4fbcd]278}
279
[1b6b2f3]280void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
281  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
[4211f50b]282}
283
[8742840]284void (*owl_global_get_buffercallback(const owl_global *g))(owl_editwin*) {
[1b6b2f3]285  return owl_editwin_get_callback(owl_global_get_typwin(g));
[4211f50b]286}
287
[7d4fbcd]288/* refresh */
289
[8742840]290int owl_global_is_needrefresh(const owl_global *g) {
[7d4fbcd]291  if (g->needrefresh==1) return(1);
292  return(0);
293}
294
295void owl_global_set_needrefresh(owl_global *g) {
296  g->needrefresh=1;
297}
298
299void owl_global_set_noneedrefresh(owl_global *g) {
300  g->needrefresh=0;
301}
302
303/* variable dictionary */
304
305owl_vardict *owl_global_get_vardict(owl_global *g) {
306  return &(g->vars);
307}
308
309/* command dictionary */
310
311owl_cmddict *owl_global_get_cmddict(owl_global *g) {
312  return &(g->cmds);
313}
314
315/* rightshift */
316
317void owl_global_set_rightshift(owl_global *g, int i) {
318  g->rightshift=i;
319}
320
[8742840]321int owl_global_get_rightshift(const owl_global *g) {
[7d4fbcd]322  return(g->rightshift);
323}
324
325/* typwin */
326
[8742840]327int owl_global_is_typwin_active(const owl_global *g) {
[7d4fbcd]328  if (g->typwinactive==1) return(1);
329  return(0);
330}
331
332void owl_global_set_typwin_active(owl_global *g) {
[da466e0]333  int d = owl_global_get_typewindelta(g);
334  if (d > 0)
335      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
336
[7d4fbcd]337  g->typwinactive=1;
338}
339
340void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]341  int d = owl_global_get_typewindelta(g);
342  if (d > 0)
343      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
344
[7d4fbcd]345  g->typwinactive=0;
346}
347
348/* resize */
349
350void owl_global_set_resize_pending(owl_global *g) {
351  g->resizepending=1;
352}
353
[8742840]354const char *owl_global_get_homedir(const owl_global *g) {
[a8938c7]355  if (g->homedir) return(g->homedir);
356  return("/");
[7d4fbcd]357}
358
[8742840]359const char *owl_global_get_confdir(const owl_global *g) {
[b363d83]360  if (g->confdir) return(g->confdir);
361  return("/");
362}
363
364/*
365 * Setting this also sets startupfile to confdir/startup
366 */
[e19eb97]367void owl_global_set_confdir(owl_global *g, const char *cd) {
[27f6487]368  owl_free(g->confdir);
[b363d83]369  g->confdir = owl_strdup(cd);
[27f6487]370  owl_free(g->startupfile);
[b363d83]371  g->startupfile = owl_sprintf("%s/startup", cd);
372}
373
[8742840]374const char *owl_global_get_startupfile(const owl_global *g) {
[b363d83]375  if(g->startupfile) return(g->startupfile);
376  return("/");
377}
378
[8742840]379int owl_global_get_direction(const owl_global *g) {
[7d4fbcd]380  return(g->direction);
381}
382
383void owl_global_set_direction_downwards(owl_global *g) {
384  g->direction=OWL_DIRECTION_DOWNWARDS;
385}
386
387void owl_global_set_direction_upwards(owl_global *g) {
388  g->direction=OWL_DIRECTION_UPWARDS;
389}
390
391/* perl stuff */
392
393void owl_global_set_perlinterp(owl_global *g, void *p) {
394  g->perl=p;
395}
396
[8742840]397void *owl_global_get_perlinterp(const owl_global *g) {
[7d4fbcd]398  return(g->perl);
399}
400
[8742840]401int owl_global_is_config_format(const owl_global *g) {
[7d4fbcd]402  if (g->config_format) return(1);
403  return(0);
404}
405
406void owl_global_set_config_format(owl_global *g, int state) {
407  if (state==1) {
408    g->config_format=1;
409  } else {
410    g->config_format=0;
411  }
412}
413
414void owl_global_set_have_config(owl_global *g) {
415  g->haveconfig=1;
416}
417
418void owl_global_set_no_have_config(owl_global *g) {
419  g->haveconfig=0;
420}
421
422int owl_global_have_config(owl_global *g) {
423  if (g->haveconfig) return(1);
424  return(0);
425}
426
427void owl_global_resize(owl_global *g, int x, int y) {
428  /* resize the screen.  If x or y is 0 use the terminal size */
429  struct winsize size;
430   
431  if (!g->resizepending) return;
432
433  /* delete the current windows */
434  delwin(g->recwin);
435  delwin(g->sepwin);
436  delwin(g->msgwin);
437  delwin(g->typwin);
438  if (!isendwin()) {
439    endwin();
440  }
441
442  refresh();
443
444  /* get the new size */
445  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
446  if (x==0) {
[054894e]447    if (size.ws_row) {
448      g->lines=size.ws_row;
449    } else {
450      g->lines=LINES;
451    } 
[7d4fbcd]452  } else {
[054894e]453      g->lines=x;
[7d4fbcd]454  }
455
456  if (y==0) {
[054894e]457    if (size.ws_col) {
458      g->cols=size.ws_col;
459    } else {
460      g->cols=COLS;
461    } 
[7d4fbcd]462  } else {
463    g->cols=y;
464  }
465
[1bdffcb]466#ifdef HAVE_RESIZETERM
[74037d9]467  resizeterm(size.ws_row, size.ws_col);
[1bdffcb]468#endif
[7d4fbcd]469
470  /* re-initialize the windows */
471  _owl_global_setup_windows(g);
472
[f1e629d]473  /* in case any styles rely on the current width */
474  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
475
[c0f9e30]476  /* recalculate the topmsg to make sure the current message is on
477   * screen */
478  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
479
[7d4fbcd]480  /* refresh stuff */
481  g->needrefresh=1;
482  owl_mainwin_redisplay(&(g->mw));
483  sepbar(NULL);
[a556caa]484  owl_editwin_redisplay(g->tw, 0);
[8240bce]485  owl_function_full_redisplay();
[7d4fbcd]486
487  /* TODO: this should handle other forms of popwins */
488  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
489      && owl_global_get_viewwin(g)) {
490    owl_popwin_refresh(owl_global_get_popwin(g));
491    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
492  }
493
[ecd5dc5]494  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
[7d4fbcd]495  owl_function_makemsg("");
496  g->resizepending=0;
497}
498
499/* debug */
500
[8742840]501int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]502  if (g->debug) return(1);
503  return(0);
504}
505
506/* starttime */
507
[8742840]508time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]509  return(g->starttime);
510}
511
[8742840]512time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]513  return(time(NULL)-g->starttime);
514}
515
[8742840]516time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]517  return(g->lastinputtime);
518}
519
[eebef19]520void owl_global_set_lastinputtime(owl_global *g, time_t time) {
521  g->lastinputtime = time;
[7f792c1]522}
523
[8742840]524time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]525  return(time(NULL)-g->lastinputtime);
526}
527
[8742840]528void owl_global_get_runtime_string(const owl_global *g, char *buff) {
[7d4fbcd]529  time_t diff;
530
531  diff=time(NULL)-owl_global_get_starttime(g);
532
533  /* print something nicer later */   
534  sprintf(buff, "%i seconds", (int) diff);
535}
536
[8742840]537const char *owl_global_get_hostname(const owl_global *g) {
[a8938c7]538  if (g->thishost) return(g->thishost);
539  return("");
[61e79a9]540}
541
[7d4fbcd]542/* userclue */
543
544void owl_global_set_userclue(owl_global *g, int clue) {
545  g->userclue=clue;
546}
547
548void owl_global_add_userclue(owl_global *g, int clue) {
549  g->userclue|=clue;
550}
551
[8742840]552int owl_global_get_userclue(const owl_global *g) {
[7d4fbcd]553  return(g->userclue);
554}
555
[8742840]556int owl_global_is_userclue(const owl_global *g, int clue) {
[7d4fbcd]557  if (g->userclue & clue) return(1);
558  return(0);
559}
560
561/* viewwin */
562
563owl_viewwin *owl_global_get_viewwin(owl_global *g) {
564  return(&(g->vw));
565}
566
567
568/* vert offset */
569
[8742840]570int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]571  return(g->curmsg_vert_offset);
572}
573
574void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
575  g->curmsg_vert_offset=i;
576}
577
578/* startup args */
579
[e19eb97]580void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
[a8938c7]581  int i, len;
582
583  if (g->startupargs) owl_free(g->startupargs);
584 
585  len=0;
586  for (i=0; i<argc; i++) {
[591e6aa7]587    len+=strlen(argv[i])+5;
[a8938c7]588  }
[34509d5]589  g->startupargs=owl_malloc(len+5);
[7d4fbcd]590
591  strcpy(g->startupargs, "");
592  for (i=0; i<argc; i++) {
[b9cb41b]593    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]594  }
595  g->startupargs[strlen(g->startupargs)-1]='\0';
596}
597
[8742840]598const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]599  if (g->startupargs) return(g->startupargs);
600  return("");
[7d4fbcd]601}
602
603/* history */
604
[10b866d]605owl_history *owl_global_get_msg_history(owl_global *g) {
606  return(&(g->msghist));
607}
608
609owl_history *owl_global_get_cmd_history(owl_global *g) {
610  return(&(g->cmdhist));
[7d4fbcd]611}
612
613/* filterlist */
614
615owl_list *owl_global_get_filterlist(owl_global *g) {
616  return(&(g->filterlist));
617}
618
[8742840]619owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[7d4fbcd]620  int i, j;
621  owl_filter *f;
622
623  j=owl_list_get_size(&(g->filterlist));
624  for (i=0; i<j; i++) {
625    f=owl_list_get_element(&(g->filterlist), i);
626    if (!strcmp(name, owl_filter_get_name(f))) {
627      return(f);
628    }
629  }
630  return(NULL);
631}
632
633void owl_global_add_filter(owl_global *g, owl_filter *f) {
634  owl_list_append_element(&(g->filterlist), f);
635}
636
[e19eb97]637void owl_global_remove_filter(owl_global *g, const char *name) {
[7d4fbcd]638  int i, j;
639  owl_filter *f;
640
641  j=owl_list_get_size(&(g->filterlist));
642  for (i=0; i<j; i++) {
643    f=owl_list_get_element(&(g->filterlist), i);
644    if (!strcmp(name, owl_filter_get_name(f))) {
645      owl_filter_free(f);
646      owl_list_remove_element(&(g->filterlist), i);
647      break;
648    }
649  }
650}
651
652/* nextmsgid */
653
654int owl_global_get_nextmsgid(owl_global *g) {
655  return(g->nextmsgid++);
656}
657
658/* current view */
659
660owl_view *owl_global_get_current_view(owl_global *g) {
661  return(&(g->current_view));
662}
663
664/* has colors */
665
[8742840]666int owl_global_get_hascolors(const owl_global *g) {
[7d4fbcd]667  if (g->hascolors) return(1);
668  return(0);
669}
670
671/* color pairs */
672
[8742840]673int owl_global_get_colorpairs(const owl_global *g) {
[7d4fbcd]674  return(g->colorpairs);
675}
676
[8fa9562]677owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
678  return(&(g->cpmgr));
679}
680
[7d4fbcd]681/* puntlist */
682
683owl_list *owl_global_get_puntlist(owl_global *g) {
684  return(&(g->puntlist));
685}
686
[c08c70a]687int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[77bced3]688  const owl_list *pl;
[7d4fbcd]689  int i, j;
690
691  pl=owl_global_get_puntlist(g);
692  j=owl_list_get_size(pl);
693  for (i=0; i<j; i++) {
694    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
695  }
696  return(0);
697}
698
699int owl_global_should_followlast(owl_global *g) {
[9e5c9f3]700  const owl_view *v;
[7d4fbcd]701 
702  if (!owl_global_is__followlast(g)) return(0);
703 
704  v=owl_global_get_current_view(g);
705 
706  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
707  return(0);
708}
[1fd0b25]709
[8742840]710int owl_global_is_search_active(const owl_global *g) {
[41c9a96]711  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]712  return(0);
713}
714
[89b2daf]715void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
[41c9a96]716  if (owl_regex_is_set(&g->search_re)) {
717    owl_regex_free(&g->search_re);
718    owl_regex_init(&g->search_re);
719  }
720  if (re != NULL)
721    owl_regex_copy(re, &g->search_re);
[1fd0b25]722}
723
[8742840]724const owl_regex *owl_global_get_search_re(const owl_global *g) {
[41c9a96]725  return &g->search_re;
[1fd0b25]726}
[700c712]727
[0e5afa2]728void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
[700c712]729  g->newmsgproc_pid=i;
730}
731
[0e5afa2]732pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
[700c712]733  return(g->newmsgproc_pid);
734}
735
[d09e5a1]736/* AIM stuff */
737
[8742840]738int owl_global_is_aimloggedin(const owl_global *g)
[6a415e9]739{
[d09e5a1]740  if (g->aim_loggedin) return(1);
741  return(0);
742}
743
[8742840]744const char *owl_global_get_aim_screenname(const owl_global *g)
[6a415e9]745{
[a352335c]746  if (owl_global_is_aimloggedin(g)) {
747    return (g->aim_screenname);
748  }
749  return("");
[d09e5a1]750}
751
[8742840]752const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
[81655f8]753{
754  if (owl_global_is_aimloggedin(g)) {
755    return (g->aim_screenname_for_filters);
756  }
757  return("");
758}
759
[e19eb97]760void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
[6a415e9]761{
[65b2173]762  char *sn_escaped;
[e19eb97]763  const char *quote;
[d09e5a1]764  g->aim_loggedin=1;
765  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]766  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]767  g->aim_screenname=owl_strdup(screenname);
[81655f8]768  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
769  quote = owl_getquoting(sn_escaped);
[9f4e3f8]770  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]771  owl_free(sn_escaped);
[d09e5a1]772}
773
[6a415e9]774void owl_global_set_aimnologgedin(owl_global *g)
775{
[d09e5a1]776  g->aim_loggedin=0;
777}
778
[8742840]779int owl_global_is_doaimevents(const owl_global *g)
[a352335c]780{
781  if (g->aim_doprocessing) return(1);
782  return(0);
783}
784
785void owl_global_set_doaimevents(owl_global *g)
786{
787  g->aim_doprocessing=1;
788}
789
790void owl_global_set_no_doaimevents(owl_global *g)
791{
792  g->aim_doprocessing=0;
793}
794
[6a415e9]795aim_session_t *owl_global_get_aimsess(owl_global *g)
796{
[d09e5a1]797  return(&(g->aimsess));
798}
799
[c15bbfb]800aim_conn_t *owl_global_get_bosconn(owl_global *g)
801{
802  return(&(g->bosconn));
803}
804
805void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]806{
[c15bbfb]807  g->bosconn=*conn;
[d09e5a1]808}
809
810/* message queue */
811
[6a415e9]812void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
813{
[d09e5a1]814  owl_list_append_element(&(g->messagequeue), m);
815}
816
817/* pop off the first message and return it.  Return NULL if the queue
818 * is empty.  The caller should free the message after using it, if
819 * necessary.
820 */
[13a3c1db]821owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]822{
[d09e5a1]823  owl_message *out;
824
825  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
826  out=owl_list_get_element(&(g->messagequeue), 0);
827  owl_list_remove_element(&(g->messagequeue), 0);
828  return(out);
829}
830
[6a415e9]831int owl_global_messagequeue_pending(owl_global *g)
832{
[d09e5a1]833  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
834  return(1);
835}
[aa5f725]836
[6a415e9]837owl_buddylist *owl_global_get_buddylist(owl_global *g)
838{
[aa5f725]839  return(&(g->buddylist));
840}
841 
[bd3f232]842/* style */
843
844/* Return the style with name 'name'.  If it does not exist return
845 * NULL */
[8742840]846const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]847{
[f1e629d]848  return owl_dict_find_element(&(g->styledict), name);
849}
850
851/* creates a list and fills it in with keys.  duplicates the keys,
852 * so they will need to be freed by the caller. */
[8742840]853int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]854  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]855}
856
[cf83b7a]857void owl_global_add_style(owl_global *g, owl_style *s)
858{
[f1fc47f]859  /*
860   * If we're redefining the current style, make sure to update
861   * pointers to it.
862   */
863  if(g->current_view.style
864     && !strcmp(owl_style_get_name(g->current_view.style),
865                owl_style_get_name(s)))
866    g->current_view.style = s;
867  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
868                          s, (void(*)(void*))owl_style_free);
[bd3f232]869}
[cf83b7a]870
[09489b89]871void owl_global_set_haveaim(owl_global *g)
872{
873  g->haveaim=1;
874}
875
[8742840]876int owl_global_is_haveaim(const owl_global *g)
[09489b89]877{
878  if (g->haveaim) return(1);
879  return(0);
880}
881
[b7bb454]882void owl_global_set_ignore_aimlogin(owl_global *g)
883{
884    g->ignoreaimlogin = 1;
885}
886
887void owl_global_unset_ignore_aimlogin(owl_global *g)
888{
889    g->ignoreaimlogin = 0;
890}
891
[8742840]892int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]893{
894    return g->ignoreaimlogin;
895}
896
[09489b89]897void owl_global_set_havezephyr(owl_global *g)
898{
899  g->havezephyr=1;
900}
901
[8742840]902int owl_global_is_havezephyr(const owl_global *g)
[09489b89]903{
904  if (g->havezephyr) return(1);
905  return(0);
906}
[de03334]907
[ec6ff52]908owl_errqueue *owl_global_get_errqueue(owl_global *g)
909{
910  return(&(g->errqueue));
911}
[c9e72d1]912
913void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
914{
915  g->got_err_signal = signum;
916  if (siginfo) {
917    g->err_signal_info = *siginfo;
918  } else {
919    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
920  }
921}
922
923int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
924{
925  int signum;
926  if (siginfo && g->got_err_signal) {
927    *siginfo = g->err_signal_info;
928  } 
929  signum = g->got_err_signal;
930  g->got_err_signal = 0;
931  return signum;
932}
933
[5a95b69]934
935owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
936{
937  return(&(g->zbuddies));
938}
[8232149]939
940struct termios *owl_global_get_startup_tio(owl_global *g)
941{
942  return(&(g->startup_tio));
943}
[8e401cae]944
[e19eb97]945const char * owl_global_intern(owl_global *g, const char * string)
[8e401cae]946{
947  return owl_obarray_insert(&(g->obarray), string);
948}
[9c7a701]949
950owl_list *owl_global_get_dispatchlist(owl_global *g)
951{
952  return &(g->dispatchlist);
953}
[b7bb454]954
[58d1f8a]955GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]956{
[58d1f8a]957  return &(g->timerlist);
[b7bb454]958}
[adee9cc]959
[8742840]960int owl_global_is_interrupted(const owl_global *g) {
[0cb6c26]961  return g->interrupted;
[adee9cc]962}
963
964void owl_global_set_interrupted(owl_global *g) {
965  g->interrupted = 1;
966}
967
968void owl_global_unset_interrupted(owl_global *g) {
969  g->interrupted = 0;
970}
[40bda84]971
972int owl_global_is_sigstp(const owl_global *g) {
973  return g->got_sigtstp;
974}
975
976void owl_global_set_got_sigstp(owl_global *g) {
977  g->got_sigtstp = 1;
978}
979
980void owl_global_unset_got_sigstp(owl_global *g) {
981  g->got_sigtstp = 0;
982}
Note: See TracBrowser for help on using the repository browser.