source: global.c @ 4f2166b

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