source: global.c @ 6201646

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 6201646 was 93ee554, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 17 years ago
Merged revisions 734-776 via svnmerge from file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk ........ r738 | nelhage | 2007-07-07 17:42:45 -0400 (Sat, 07 Jul 2007) | 3 lines Make the built-in regression tests output TAP and add a perl wrapper to call it. ........ r739 | nelhage | 2007-07-07 17:43:22 -0400 (Sat, 07 Jul 2007) | 2 lines Forgot these in the last commit; Make all the tests output TAP ........ r740 | nelhage | 2007-07-07 19:46:16 -0400 (Sat, 07 Jul 2007) | 2 lines Clean up an unused var warning. ........ r741 | nelhage | 2007-07-08 15:37:43 -0400 (Sun, 08 Jul 2007) | 2 lines Adding a -s switch to change the location of the config dir (~/.owl) ........ r742 | nelhage | 2007-07-08 15:39:57 -0400 (Sun, 08 Jul 2007) | 2 lines I don't understand why this didn't commit last time. I blame psvn. ........ r743 | nelhage | 2007-07-11 22:37:16 -0400 (Wed, 11 Jul 2007) | 3 lines Don't allow you to go off the end of an empty message list. [fixes: #9] ........ r744 | nelhage | 2007-07-30 18:47:39 -0400 (Mon, 30 Jul 2007) | 2 lines Fix sending to -c message -i personal ........ r745 | chmrr | 2007-07-30 20:21:18 -0400 (Mon, 30 Jul 2007) | 3 lines r20981@zoq-fot-pik: chmrr | 2007-07-30 20:20:44 -0400 * message length 0 means no fields ........ r746 | nelhage | 2007-07-30 20:25:59 -0400 (Mon, 30 Jul 2007) | 4 lines * zero-len message means no fields * Actually use owl_zephyr_get_zsig to get the zsig, which handles 0- and 1- field zephyrs correctly. ........ r747 | nelhage | 2007-07-30 20:29:36 -0400 (Mon, 30 Jul 2007) | 2 lines Making that last patch actually compile. Bad me. ........ r748 | nelhage | 2007-08-01 01:42:53 -0400 (Wed, 01 Aug 2007) | 3 lines owl_message_get_text needs to make sure there's text to return before returning it. fixes: #15 ........ r749 | nelhage | 2007-08-01 01:52:08 -0400 (Wed, 01 Aug 2007) | 5 lines zephyr smartnarrow now uses the ``personal'' filter to decide whether to narrow to user or not, and the zephyr-user filter now checks for `filter personal' instead of <message,personal,*>. closes #2 ........ r750 | nelhage | 2007-08-01 02:27:30 -0400 (Wed, 01 Aug 2007) | 5 lines Changing the default personal filter to <message,personal,*> for zephyr. refs 2 ........ r751 | nelhage | 2007-08-01 22:58:31 -0400 (Wed, 01 Aug 2007) | 2 lines Display opcodes with the default style ........ r752 | nelhage | 2007-08-08 18:01:51 -0400 (Wed, 08 Aug 2007) | 2 lines Applying ctl's variable shuffling patch for better ANSI C-ness. closes #18 ........ r753 | nelhage | 2007-08-11 01:04:07 -0400 (Sat, 11 Aug 2007) | 3 lines Implement :punt and :unpunt to punt arbitrary filters, rather than just z-triplets. closes #6 ........ r754 | nelhage | 2007-08-11 01:18:37 -0400 (Sat, 11 Aug 2007) | 2 lines Show non-personal pings like stock owl does. closes #12 ........ r756 | asedeno | 2007-08-17 12:48:37 -0400 (Fri, 17 Aug 2007) | 8 lines Apply patch from: http://rt.cpan.org/Public/Bug/Display.html?id=17484 Fixing problems with jabber servers keeping the same stream id when negotiating TLS. Thanks to ghudson for tracking this down. ........ r757 | nelhage | 2007-08-17 17:26:44 -0400 (Fri, 17 Aug 2007) | 4 lines When we're narrowing to an instance, properly include un-instances. This fixes narrowing to any instance that starts with ``un-'' ........ r758 | nelhage | 2007-08-27 19:17:20 -0400 (Mon, 27 Aug 2007) | 2 lines Don't read before the start of the string for an instance ........ r759 | nelhage | 2007-09-07 00:13:45 -0400 (Fri, 07 Sep 2007) | 3 lines Adding an explicit -f - to the tar commands for FreeBSD compatibility (reported by ecprice) ........ r760 | ecprice | 2007-09-08 17:33:34 -0400 (Sat, 08 Sep 2007) | 3 lines Fixes for FreeBSD. ........ r761 | nelhage | 2007-09-10 20:00:45 -0400 (Mon, 10 Sep 2007) | 3 lines Use "" instead of `undef' as a default for messages with no reply command to hopefully squelch perl warnings. ........ r762 | nelhage | 2007-09-12 21:37:41 -0400 (Wed, 12 Sep 2007) | 2 lines Do ~-expansion in :loadsubs. closes #26 ........ r763 | nelhage | 2007-09-12 21:54:51 -0400 (Wed, 12 Sep 2007) | 2 lines Validate JIDs passed to jmuc join. closes #25 ........ r764 | nelhage | 2007-09-12 22:46:17 -0400 (Wed, 12 Sep 2007) | 2 lines Show full JIDs for users in non-anonymous JIDs in :jmuc presence. closes #24 ........ r766 | nelhage | 2007-10-02 00:38:49 -0400 (Tue, 02 Oct 2007) | 3 lines Don't crash if we hit `i' on iso-8859-*. This is not the right solution, but at least it doesn't SEGV. ........ r767 | asedeno | 2007-10-10 15:21:13 -0400 (Wed, 10 Oct 2007) | 1 line Fixing a typo pointed out by kchen. ........ r768 | matt | 2007-10-14 17:16:35 -0400 (Sun, 14 Oct 2007) | 1 line added -m flag to aimwrite ........ r769 | austein | 2007-10-14 18:16:44 -0400 (Sun, 14 Oct 2007) | 1 line aimwrite -m displays according to displayoutgoing ........ r770 | asedeno | 2007-12-06 14:38:05 -0500 (Thu, 06 Dec 2007) | 3 lines Making usleep call more reasonable. Responsiveness seems okay on linerva, no-knife, and darkmatter, and reported good on zephyr. ........ r771 | nelhage | 2007-12-10 21:34:46 -0500 (Mon, 10 Dec 2007) | 2 lines Add zip as build-depends ........ r772 | nelhage | 2007-12-10 21:36:25 -0500 (Mon, 10 Dec 2007) | 2 lines We're not ktools ........ r773 | nelhage | 2007-12-23 11:32:02 -0500 (Sun, 23 Dec 2007) | 2 lines bind END in popless windows. closes #41 ........ r774 | chmrr | 2007-12-23 15:16:26 -0500 (Sun, 23 Dec 2007) | 3 lines r1805@utwig: chmrr | 2007-12-23 15:15:33 -0500 * Allow C-r on outgoing messages (useful for CCs) ........ r775 | chmrr | 2007-12-23 15:16:29 -0500 (Sun, 23 Dec 2007) | 3 lines r1806@utwig: chmrr | 2007-12-23 15:15:50 -0500 * Identify ourselves as barnowl in a couple more places ........
  • Property mode set to 100644
File size: 19.3 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
[1aee7d9]11static const char fileIdent[] = "$Id$";
12
[7d4fbcd]13#ifndef MAXHOSTNAMELEN
14#define MAXHOSTNAMELEN 256
15#endif
16
17void owl_global_init(owl_global *g) {
18  struct hostent *hent;
19  char hostname[MAXHOSTNAMELEN];
[ad15610]20  char *cd;
[7d4fbcd]21
[8262340]22  g->malloced=0;
23  g->freed=0;
24
[7d4fbcd]25  gethostname(hostname, MAXHOSTNAMELEN);
26  hent=gethostbyname(hostname);
27  if (!hent) {
[a8938c7]28    g->thishost=owl_strdup("localhost");
[7d4fbcd]29  } else {
[a8938c7]30    g->thishost=owl_strdup(hent->h_name);
[7d4fbcd]31  }
32
33  owl_context_init(&g->ctx);
34  owl_context_set_startup(&g->ctx);
35  g->curmsg=0;
36  g->topmsg=0;
37  g->needrefresh=1;
[a8938c7]38  g->startupargs=NULL;
[7d4fbcd]39
40  owl_variable_dict_setup(&(g->vars));
41  owl_cmddict_setup(&(g->cmds));
42
43  g->lines=LINES;
44  g->cols=COLS;
45
46  g->rightshift=0;
47
[10b866d]48  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
[7d4fbcd]49
50  owl_keyhandler_init(&g->kh);
51  owl_keys_setup_keymaps(&g->kh);
52
[afbf668]53  owl_list_create(&(g->muxevents));
[7d4fbcd]54  owl_list_create(&(g->filterlist));
55  owl_list_create(&(g->puntlist));
[d09e5a1]56  owl_list_create(&(g->messagequeue));
[f1e629d]57  owl_dict_create(&(g->styledict));
[7d4fbcd]58  g->curmsg_vert_offset=0;
59  g->resizepending=0;
60  g->typwinactive=0;
61  g->direction=OWL_DIRECTION_DOWNWARDS;
62  g->zaway=0;
63  if (has_colors()) {
64    g->hascolors=1;
65  }
66  g->colorpairs=COLOR_PAIRS;
[8fa9562]67  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]68  g->debug=OWL_DEBUG;
[1fd0b25]69  g->searchactive=0;
70  g->searchstring=NULL;
[7d4fbcd]71  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]72  g->lastinputtime=g->starttime;
[700c712]73  g->newmsgproc_pid=0;
[61e79a9]74 
[7d4fbcd]75  owl_global_set_config_format(g, 0);
76  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
77  owl_global_set_no_have_config(g);
[10b866d]78  owl_history_init(&(g->msghist));
79  owl_history_init(&(g->cmdhist));
[5a9f6fe]80  owl_history_set_norepeats(&(g->cmdhist));
[7d4fbcd]81  g->nextmsgid=0;
82
83  _owl_global_setup_windows(g);
84
85  /* Fill in some variables which don't have constant defaults */
86  /* TODO: come back later and check passwd file first */
[a8938c7]87  g->homedir=owl_strdup(getenv("HOME"));
[7d4fbcd]88
[b363d83]89  g->confdir = NULL;
90  g->startupfile = NULL;
[ad15610]91  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
[b363d83]92  owl_global_set_confdir(g, cd);
93  owl_free(cd);
94
[7d4fbcd]95  owl_messagelist_create(&(g->msglist));
96  owl_mainwin_init(&(g->mw));
97  owl_popwin_init(&(g->pw));
[d09e5a1]98
99  g->aim_screenname=NULL;
100  g->aim_loggedin=0;
[6a415e9]101  owl_timer_create_countdown(&(g->aim_noop_timer), 30);
102  owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
[de03334]103  owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
[aa5f725]104  owl_buddylist_init(&(g->buddylist));
[2404c3a]105   
[09489b89]106  g->havezephyr=0;
107  g->haveaim=0;
[a352335c]108  owl_global_set_no_doaimevents(g);
[ec6ff52]109
110  owl_errqueue_init(&(g->errqueue));
[c9e72d1]111  g->got_err_signal=0;
[5a95b69]112
113  owl_zbuddylist_create(&(g->zbuddies));
114  owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
[8e401cae]115
116  owl_obarray_init(&(g->obarray));
[a387d12e]117
118  owl_message_init_fmtext_cache();
[7d4fbcd]119}
120
121void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]122  int cols, typwin_lines;
[7d4fbcd]123
124  cols=g->cols;
[ecd5dc5]125  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]126
127  /* set the new window sizes */
128  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]129  if (g->recwinlines<0) {
130    /* gotta deal with this */
131    g->recwinlines=0;
[ecd5dc5]132  }
[7d4fbcd]133
[176d3443]134  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
135
[7d4fbcd]136  /* create the new windows */
137  g->recwin=newwin(g->recwinlines, cols, 0, 0);
[ecd5dc5]138  if (g->recwin==NULL) {
[176d3443]139    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
[ecd5dc5]140    endwin();
141    exit(50);
142  }
143     
[7d4fbcd]144  g->sepwin=newwin(1, cols, g->recwinlines, 0);
145  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
146  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
147
148  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
149
150  idlok(g->typwin, FALSE);
151  idlok(g->recwin, FALSE);
152  idlok(g->sepwin, FALSE);
153  idlok(g->msgwin, FALSE);
154
155  nodelay(g->typwin, 1);
156  keypad(g->typwin, TRUE);
157  wmove(g->typwin, 0, 0);
158
159  meta(g->typwin, TRUE);
160}
161
162owl_context *owl_global_get_context(owl_global *g) {
163  return(&g->ctx);
164}
165                         
166int owl_global_get_lines(owl_global *g) {
167  return(g->lines);
168}
169
170int owl_global_get_cols(owl_global *g) {
171  return(g->cols);
172}
173
174int owl_global_get_recwin_lines(owl_global *g) {
175  return(g->recwinlines);
176}
177
178/* curmsg */
179
180int owl_global_get_curmsg(owl_global *g) {
181  return(g->curmsg);
182}
183
184void owl_global_set_curmsg(owl_global *g, int i) {
185  g->curmsg=i;
186  /* we will reset the vertical offset from here */
187  /* we might want to move this out to the functions later */
188  owl_global_set_curmsg_vert_offset(g, 0);
189}
190
191/* topmsg */
192
193int owl_global_get_topmsg(owl_global *g) {
194  return(g->topmsg);
195}
196
197void owl_global_set_topmsg(owl_global *g, int i) {
198  g->topmsg=i;
199}
200
201/* windows */
202
203owl_mainwin *owl_global_get_mainwin(owl_global *g) {
204  return(&(g->mw));
205}
206
207owl_popwin *owl_global_get_popwin(owl_global *g) {
208  return(&(g->pw));
209}
210
211/* msglist */
212
213owl_messagelist *owl_global_get_msglist(owl_global *g) {
214  return(&(g->msglist));
215}
216
217/* keyhandler */
218
219owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
220  return(&(g->kh));
221}
222
223/* curses windows */
224
225WINDOW *owl_global_get_curs_recwin(owl_global *g) {
226  return(g->recwin);
227}
228
229WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
230  return(g->sepwin);
231}
232
233WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
234  return(g->msgwin);
235}
236
237WINDOW *owl_global_get_curs_typwin(owl_global *g) {
238  return(g->typwin);
239}
240
241/* typwin */
242
243owl_editwin *owl_global_get_typwin(owl_global *g) {
244  return(&(g->tw));
245}
246
247/* buffercommand */
248
249void owl_global_set_buffercommand(owl_global *g, char *command) {
[1b6b2f3]250  owl_editwin_set_command(owl_global_get_typwin(g), command);
[7d4fbcd]251}
252
253char *owl_global_get_buffercommand(owl_global *g) {
[1b6b2f3]254  return owl_editwin_get_command(owl_global_get_typwin(g));
[7d4fbcd]255}
256
[1b6b2f3]257void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
258  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
[4211f50b]259}
260
[1b6b2f3]261void (*owl_global_get_buffercallback(owl_global *g))(owl_editwin*) {
262  return owl_editwin_get_callback(owl_global_get_typwin(g));
[4211f50b]263}
264
[7d4fbcd]265/* refresh */
266
267int owl_global_is_needrefresh(owl_global *g) {
268  if (g->needrefresh==1) return(1);
269  return(0);
270}
271
272void owl_global_set_needrefresh(owl_global *g) {
273  g->needrefresh=1;
274}
275
276void owl_global_set_noneedrefresh(owl_global *g) {
277  g->needrefresh=0;
278}
279
280/* variable dictionary */
281
282owl_vardict *owl_global_get_vardict(owl_global *g) {
283  return &(g->vars);
284}
285
286/* command dictionary */
287
288owl_cmddict *owl_global_get_cmddict(owl_global *g) {
289  return &(g->cmds);
290}
291
292/* rightshift */
293
294void owl_global_set_rightshift(owl_global *g, int i) {
295  g->rightshift=i;
296}
297
298int owl_global_get_rightshift(owl_global *g) {
299  return(g->rightshift);
300}
301
302/* typwin */
303
304int owl_global_is_typwin_active(owl_global *g) {
305  if (g->typwinactive==1) return(1);
306  return(0);
307}
308
309void owl_global_set_typwin_active(owl_global *g) {
310  g->typwinactive=1;
311}
312
313void owl_global_set_typwin_inactive(owl_global *g) {
314  g->typwinactive=0;
315}
316
317/* resize */
318
319void owl_global_set_resize_pending(owl_global *g) {
320  g->resizepending=1;
321}
322
323char *owl_global_get_homedir(owl_global *g) {
[a8938c7]324  if (g->homedir) return(g->homedir);
325  return("/");
[7d4fbcd]326}
327
[b363d83]328char *owl_global_get_confdir(owl_global *g) {
329  if (g->confdir) return(g->confdir);
330  return("/");
331}
332
333/*
334 * Setting this also sets startupfile to confdir/startup
335 */
336void owl_global_set_confdir(owl_global *g, char *cd) {
337  free(g->confdir);
338  g->confdir = owl_strdup(cd);
339  free(g->startupfile);
340  g->startupfile = owl_sprintf("%s/startup", cd);
341}
342
343char *owl_global_get_startupfile(owl_global *g) {
344  if(g->startupfile) return(g->startupfile);
345  return("/");
346}
347
[7d4fbcd]348int owl_global_get_direction(owl_global *g) {
349  return(g->direction);
350}
351
352void owl_global_set_direction_downwards(owl_global *g) {
353  g->direction=OWL_DIRECTION_DOWNWARDS;
354}
355
356void owl_global_set_direction_upwards(owl_global *g) {
357  g->direction=OWL_DIRECTION_UPWARDS;
358}
359
360/* perl stuff */
361
362void owl_global_set_perlinterp(owl_global *g, void *p) {
363  g->perl=p;
364}
365
366void *owl_global_get_perlinterp(owl_global *g) {
367  return(g->perl);
368}
369
370int owl_global_is_config_format(owl_global *g) {
371  if (g->config_format) return(1);
372  return(0);
373}
374
375void owl_global_set_config_format(owl_global *g, int state) {
376  if (state==1) {
377    g->config_format=1;
378  } else {
379    g->config_format=0;
380  }
381}
382
383void owl_global_set_have_config(owl_global *g) {
384  g->haveconfig=1;
385}
386
387void owl_global_set_no_have_config(owl_global *g) {
388  g->haveconfig=0;
389}
390
391int owl_global_have_config(owl_global *g) {
392  if (g->haveconfig) return(1);
393  return(0);
394}
395
396void owl_global_resize(owl_global *g, int x, int y) {
397  /* resize the screen.  If x or y is 0 use the terminal size */
398  struct winsize size;
399   
400  if (!g->resizepending) return;
401
402  /* delete the current windows */
403  delwin(g->recwin);
404  delwin(g->sepwin);
405  delwin(g->msgwin);
406  delwin(g->typwin);
407  if (!isendwin()) {
408    endwin();
409  }
410
411  refresh();
412
413  /* get the new size */
414  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
415  if (x==0) {
416    g->lines=size.ws_row;
417  } else {
418    g->lines=x;
419  }
420
421  if (y==0) {
422    g->cols=size.ws_col;
423  } else {
424    g->cols=y;
425  }
426
[1bdffcb]427#ifdef HAVE_RESIZETERM
[74037d9]428  resizeterm(size.ws_row, size.ws_col);
[1bdffcb]429#endif
[7d4fbcd]430
431  /* re-initialize the windows */
432  _owl_global_setup_windows(g);
433
[f1e629d]434  /* in case any styles rely on the current width */
435  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
436
[7d4fbcd]437  /* refresh stuff */
438  g->needrefresh=1;
439  owl_mainwin_redisplay(&(g->mw));
440  sepbar(NULL);
441
442  if (owl_global_is_typwin_active(g)) {
443    owl_editwin_redisplay(&(g->tw), 0);
444  }     
445  /* TODO: this should handle other forms of popwins */
446  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
447      && owl_global_get_viewwin(g)) {
448    owl_popwin_refresh(owl_global_get_popwin(g));
449    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
450  }
451
[ecd5dc5]452  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
[7d4fbcd]453  owl_function_makemsg("");
454  g->resizepending=0;
455}
456
457/* debug */
458
459int owl_global_is_debug_fast(owl_global *g) {
460  if (g->debug) return(1);
461  return(0);
462}
463
464/* starttime */
465
466time_t owl_global_get_starttime(owl_global *g) {
467  return(g->starttime);
468}
469
470time_t owl_global_get_runtime(owl_global *g) {
471  return(time(NULL)-g->starttime);
472}
473
[7f792c1]474time_t owl_global_get_lastinputtime(owl_global *g) {
475  return(g->lastinputtime);
476}
477
478void owl_global_update_lastinputtime(owl_global *g) {
479  g->lastinputtime = time(NULL);
480}
481
482time_t owl_global_get_idletime(owl_global *g) {
483  return(time(NULL)-g->lastinputtime);
484}
485
[7d4fbcd]486void owl_global_get_runtime_string(owl_global *g, char *buff) {
487  time_t diff;
488
489  diff=time(NULL)-owl_global_get_starttime(g);
490
491  /* print something nicer later */   
492  sprintf(buff, "%i seconds", (int) diff);
493}
494
[61e79a9]495char *owl_global_get_hostname(owl_global *g) {
[a8938c7]496  if (g->thishost) return(g->thishost);
497  return("");
[61e79a9]498}
499
[7d4fbcd]500/* userclue */
501
502void owl_global_set_userclue(owl_global *g, int clue) {
503  g->userclue=clue;
504}
505
506void owl_global_add_userclue(owl_global *g, int clue) {
507  g->userclue|=clue;
508}
509
510int owl_global_get_userclue(owl_global *g) {
511  return(g->userclue);
512}
513
514int owl_global_is_userclue(owl_global *g, int clue) {
515  if (g->userclue & clue) return(1);
516  return(0);
517}
518
519/* viewwin */
520
521owl_viewwin *owl_global_get_viewwin(owl_global *g) {
522  return(&(g->vw));
523}
524
525
526/* vert offset */
527
528int owl_global_get_curmsg_vert_offset(owl_global *g) {
529  return(g->curmsg_vert_offset);
530}
531
532void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
533  g->curmsg_vert_offset=i;
534}
535
536/* startup args */
537
538void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
[a8938c7]539  int i, len;
540
541  if (g->startupargs) owl_free(g->startupargs);
542 
543  len=0;
544  for (i=0; i<argc; i++) {
[591e6aa7]545    len+=strlen(argv[i])+5;
[a8938c7]546  }
[34509d5]547  g->startupargs=owl_malloc(len+5);
[7d4fbcd]548
549  strcpy(g->startupargs, "");
550  for (i=0; i<argc; i++) {
551    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
552  }
553  g->startupargs[strlen(g->startupargs)-1]='\0';
554}
555
556char *owl_global_get_startupargs(owl_global *g) {
[a8938c7]557  if (g->startupargs) return(g->startupargs);
558  return("");
[7d4fbcd]559}
560
561/* history */
562
[10b866d]563owl_history *owl_global_get_msg_history(owl_global *g) {
564  return(&(g->msghist));
565}
566
567owl_history *owl_global_get_cmd_history(owl_global *g) {
568  return(&(g->cmdhist));
[7d4fbcd]569}
570
[afbf668]571/* muxevents */
572
573owl_muxevents *owl_global_get_muxevents(owl_global *g) {
574  return(&(g->muxevents));
575}
576
[7d4fbcd]577/* filterlist */
578
579owl_list *owl_global_get_filterlist(owl_global *g) {
580  return(&(g->filterlist));
581}
582
583owl_filter *owl_global_get_filter(owl_global *g, char *name) {
584  int i, j;
585  owl_filter *f;
586
587  j=owl_list_get_size(&(g->filterlist));
588  for (i=0; i<j; i++) {
589    f=owl_list_get_element(&(g->filterlist), i);
590    if (!strcmp(name, owl_filter_get_name(f))) {
591      return(f);
592    }
593  }
594  return(NULL);
595}
596
597void owl_global_add_filter(owl_global *g, owl_filter *f) {
598  owl_list_append_element(&(g->filterlist), f);
599}
600
601void owl_global_remove_filter(owl_global *g, char *name) {
602  int i, j;
603  owl_filter *f;
604
605  j=owl_list_get_size(&(g->filterlist));
606  for (i=0; i<j; i++) {
607    f=owl_list_get_element(&(g->filterlist), i);
608    if (!strcmp(name, owl_filter_get_name(f))) {
609      owl_filter_free(f);
610      owl_list_remove_element(&(g->filterlist), i);
611      break;
612    }
613  }
614}
615
616/* nextmsgid */
617
618int owl_global_get_nextmsgid(owl_global *g) {
619  return(g->nextmsgid++);
620}
621
622/* current view */
623
624owl_view *owl_global_get_current_view(owl_global *g) {
625  return(&(g->current_view));
626}
627
628/* has colors */
629
630int owl_global_get_hascolors(owl_global *g) {
631  if (g->hascolors) return(1);
632  return(0);
633}
634
635/* color pairs */
636
637int owl_global_get_colorpairs(owl_global *g) {
638  return(g->colorpairs);
639}
640
[8fa9562]641owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
642  return(&(g->cpmgr));
643}
644
[7d4fbcd]645/* puntlist */
646
647owl_list *owl_global_get_puntlist(owl_global *g) {
648  return(&(g->puntlist));
649}
650
651int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
652  owl_list *pl;
653  int i, j;
654
655  pl=owl_global_get_puntlist(g);
656  j=owl_list_get_size(pl);
657  for (i=0; i<j; i++) {
658    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
659  }
660  return(0);
661}
662
663int owl_global_should_followlast(owl_global *g) {
664  owl_view *v;
665 
666  if (!owl_global_is__followlast(g)) return(0);
667 
668  v=owl_global_get_current_view(g);
669 
670  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
671  return(0);
672}
[1fd0b25]673
674int owl_global_is_search_active(owl_global *g) {
675  if (g->searchactive) return(1);
676  return(0);
677}
678
679void owl_global_set_search_active(owl_global *g, char *string) {
680  g->searchactive=1;
681  if (g->searchstring != NULL) owl_free(g->searchstring);
682  g->searchstring=owl_strdup(string);
683}
684
685void owl_global_set_search_inactive(owl_global *g) {
686  g->searchactive=0;
687}
688
689char *owl_global_get_search_string(owl_global *g) {
690  if (g->searchstring==NULL) return("");
691  return(g->searchstring);
692}
[700c712]693
694void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
695  g->newmsgproc_pid=i;
696}
697
698int owl_global_get_newmsgproc_pid(owl_global *g) {
699  return(g->newmsgproc_pid);
700}
701
[8262340]702void owl_global_add_to_malloced(owl_global *g, int i) {
703  g->malloced+=i;
704}
705
706void owl_global_add_to_freed(owl_global *g, int i) {
707  g->freed+=1;
708}
709
710int owl_global_get_malloced(owl_global *g) {
711  return(g->malloced);
712}
713
714int owl_global_get_freed(owl_global *g) {
715  return(g->freed);
716}
717
718int owl_global_get_meminuse(owl_global *g) {
719  return(g->malloced-g->freed);
720}
[d09e5a1]721
722/* AIM stuff */
723
[6a415e9]724int owl_global_is_aimloggedin(owl_global *g)
725{
[d09e5a1]726  if (g->aim_loggedin) return(1);
727  return(0);
728}
729
[6a415e9]730char *owl_global_get_aim_screenname(owl_global *g)
731{
[a352335c]732  if (owl_global_is_aimloggedin(g)) {
733    return (g->aim_screenname);
734  }
735  return("");
[d09e5a1]736}
737
[6a415e9]738void owl_global_set_aimloggedin(owl_global *g, char *screenname)
739{
[d09e5a1]740  g->aim_loggedin=1;
741  if (g->aim_screenname) owl_free(g->aim_screenname);
742  g->aim_screenname=owl_strdup(screenname);
743}
744
[6a415e9]745void owl_global_set_aimnologgedin(owl_global *g)
746{
[d09e5a1]747  g->aim_loggedin=0;
748}
749
[a352335c]750int owl_global_is_doaimevents(owl_global *g)
751{
752  if (g->aim_doprocessing) return(1);
753  return(0);
754}
755
756void owl_global_set_doaimevents(owl_global *g)
757{
758  g->aim_doprocessing=1;
759}
760
761void owl_global_set_no_doaimevents(owl_global *g)
762{
763  g->aim_doprocessing=0;
764}
765
[6a415e9]766aim_session_t *owl_global_get_aimsess(owl_global *g)
767{
[d09e5a1]768  return(&(g->aimsess));
769}
770
[c15bbfb]771aim_conn_t *owl_global_get_bosconn(owl_global *g)
772{
773  return(&(g->bosconn));
774}
775
776void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]777{
[c15bbfb]778  g->bosconn=*conn;
[d09e5a1]779}
780
[6a415e9]781int owl_global_is_aimnop_time(owl_global *g)
782{
783  if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
[d09e5a1]784  return(0);
785}
786
[6a415e9]787void owl_global_aimnop_sent(owl_global *g)
788{
789  owl_timer_reset(&(g->aim_noop_timer));
790}
[d09e5a1]791
[6a415e9]792owl_timer *owl_global_get_aim_login_timer(owl_global *g)
793{
794  return(&(g->aim_ignorelogin_timer));
[d09e5a1]795}
796
797/* message queue */
798
[6a415e9]799void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
800{
[d09e5a1]801  owl_list_append_element(&(g->messagequeue), m);
802}
803
804/* pop off the first message and return it.  Return NULL if the queue
805 * is empty.  The caller should free the message after using it, if
806 * necessary.
807 */
[13a3c1db]808owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]809{
[d09e5a1]810  owl_message *out;
811
812  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
813  out=owl_list_get_element(&(g->messagequeue), 0);
814  owl_list_remove_element(&(g->messagequeue), 0);
815  return(out);
816}
817
[6a415e9]818int owl_global_messagequeue_pending(owl_global *g)
819{
[d09e5a1]820  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
821  return(1);
822}
[aa5f725]823
[6a415e9]824owl_buddylist *owl_global_get_buddylist(owl_global *g)
825{
[aa5f725]826  return(&(g->buddylist));
827}
828 
[bd3f232]829/* style */
830
831/* Return the style with name 'name'.  If it does not exist return
832 * NULL */
833owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
834{
[f1e629d]835  return owl_dict_find_element(&(g->styledict), name);
836}
837
838/* creates a list and fills it in with keys.  duplicates the keys,
839 * so they will need to be freed by the caller. */
840int owl_global_get_style_names(owl_global *g, owl_list *l) {
841  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]842}
843
[cf83b7a]844void owl_global_add_style(owl_global *g, owl_style *s)
845{
[f1fc47f]846  /*
847   * If we're redefining the current style, make sure to update
848   * pointers to it.
849   */
850  if(g->current_view.style
851     && !strcmp(owl_style_get_name(g->current_view.style),
852                owl_style_get_name(s)))
853    g->current_view.style = s;
854  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
855                          s, (void(*)(void*))owl_style_free);
[bd3f232]856}
[cf83b7a]857
[09489b89]858void owl_global_set_haveaim(owl_global *g)
859{
860  g->haveaim=1;
861}
862
863int owl_global_is_haveaim(owl_global *g)
864{
865  if (g->haveaim) return(1);
866  return(0);
867}
868
869void owl_global_set_havezephyr(owl_global *g)
870{
871  g->havezephyr=1;
872}
873
874int owl_global_is_havezephyr(owl_global *g)
875{
876  if (g->havezephyr) return(1);
877  return(0);
878}
[de03334]879
880owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
881{
882  return(&(g->aim_buddyinfo_timer));
883}
[ec6ff52]884
885owl_errqueue *owl_global_get_errqueue(owl_global *g)
886{
887  return(&(g->errqueue));
888}
[c9e72d1]889
890void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
891{
892  g->got_err_signal = signum;
893  if (siginfo) {
894    g->err_signal_info = *siginfo;
895  } else {
896    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
897  }
898}
899
900int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
901{
902  int signum;
903  if (siginfo && g->got_err_signal) {
904    *siginfo = g->err_signal_info;
905  } 
906  signum = g->got_err_signal;
907  g->got_err_signal = 0;
908  return signum;
909}
910
[5a95b69]911owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
912{
913  return(&(g->zephyr_buddycheck_timer));
914}
915
916owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
917{
918  return(&(g->zbuddies));
919}
[8232149]920
921struct termios *owl_global_get_startup_tio(owl_global *g)
922{
923  return(&(g->startup_tio));
924}
[8e401cae]925
926char * owl_global_intern(owl_global *g, char * string)
927{
928  return owl_obarray_insert(&(g->obarray), string);
929}
Note: See TracBrowser for help on using the repository browser.