source: global.c @ 8262340

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8262340 was 8262340, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Added ZResetAuthentication in a number of places to fix problems with stale tickets Added some hooks for malloc debugging
  • Property mode set to 100644
File size: 12.6 KB
Line 
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
11static const char fileIdent[] = "$Id$";
12
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];
20
21  g->malloced=0;
22  g->freed=0;
23
24  gethostname(hostname, MAXHOSTNAMELEN);
25  hent=gethostbyname(hostname);
26  if (!hent) {
27    strcpy(g->thishost, "localhost");
28  } else {
29    strcpy(g->thishost, hent->h_name);
30  }
31
32  owl_context_init(&g->ctx);
33  owl_context_set_startup(&g->ctx);
34  g->curmsg=0;
35  g->topmsg=0;
36  g->needrefresh=1;
37
38  owl_variable_dict_setup(&(g->vars));
39  owl_cmddict_setup(&(g->cmds));
40
41  g->lines=LINES;
42  g->cols=COLS;
43
44  g->rightshift=0;
45
46  owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
47
48  owl_keyhandler_init(&g->kh);
49  owl_keys_setup_keymaps(&g->kh);
50
51  owl_list_create(&(g->filterlist));
52  owl_list_create(&(g->puntlist));
53  g->curmsg_vert_offset=0;
54  g->resizepending=0;
55  g->typwinactive=0;
56  g->direction=OWL_DIRECTION_DOWNWARDS;
57  g->zaway=0;
58  if (has_colors()) {
59    g->hascolors=1;
60  }
61  g->colorpairs=COLOR_PAIRS;
62  g->debug=OWL_DEBUG;
63  g->searchactive=0;
64  g->searchstring=NULL;
65  g->starttime=time(NULL); /* assumes we call init only a start time */
66  strcpy(g->buffercommand, "");
67  g->newmsgproc_pid=0;
68 
69  owl_global_set_config_format(g, 0);
70  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
71  owl_global_set_no_have_config(g);
72  owl_history_init(&(g->msghist));
73  owl_history_init(&(g->cmdhist));
74  g->nextmsgid=0;
75
76  owl_filterelement_create_true(&(g->fe_true));
77  owl_filterelement_create_false(&(g->fe_false));
78  owl_filterelement_create_null(&(g->fe_null));
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 */
84  strcpy(g->homedir, getenv("HOME"));
85
86  owl_messagelist_create(&(g->msglist));
87  owl_mainwin_init(&(g->mw));
88  owl_popwin_init(&(g->pw));
89}
90
91void _owl_global_setup_windows(owl_global *g) {
92  int lines, cols, typwin_lines;
93
94  lines=g->lines;
95  cols=g->cols;
96  typwin_lines = owl_global_get_typwin_lines(g);
97
98  /* set the new window sizes */
99  g->recwinlines=g->lines-(typwin_lines+2);
100
101  /* create the new windows */
102  g->recwin=newwin(g->recwinlines, cols, 0, 0);
103  g->sepwin=newwin(1, cols, g->recwinlines, 0);
104  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
105  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
106
107  owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols);
108
109  idlok(g->typwin, FALSE);
110  idlok(g->recwin, FALSE);
111  idlok(g->sepwin, FALSE);
112  idlok(g->msgwin, FALSE);
113
114  nodelay(g->typwin, 1);
115  keypad(g->typwin, TRUE);
116  wmove(g->typwin, 0, 0);
117
118  meta(g->typwin, TRUE);
119}
120
121owl_context *owl_global_get_context(owl_global *g) {
122  return(&g->ctx);
123}
124                         
125int owl_global_get_lines(owl_global *g) {
126  return(g->lines);
127}
128
129int owl_global_get_cols(owl_global *g) {
130  return(g->cols);
131}
132
133int owl_global_get_recwin_lines(owl_global *g) {
134  return(g->recwinlines);
135}
136
137/* curmsg */
138
139int owl_global_get_curmsg(owl_global *g) {
140  return(g->curmsg);
141}
142
143void owl_global_set_curmsg(owl_global *g, int i) {
144  g->curmsg=i;
145  /* we will reset the vertical offset from here */
146  /* we might want to move this out to the functions later */
147  owl_global_set_curmsg_vert_offset(g, 0);
148}
149
150/* topmsg */
151
152int owl_global_get_topmsg(owl_global *g) {
153  return(g->topmsg);
154}
155
156void owl_global_set_topmsg(owl_global *g, int i) {
157  g->topmsg=i;
158}
159
160/* windows */
161
162owl_mainwin *owl_global_get_mainwin(owl_global *g) {
163  return(&(g->mw));
164}
165
166owl_popwin *owl_global_get_popwin(owl_global *g) {
167  return(&(g->pw));
168}
169
170/* msglist */
171
172owl_messagelist *owl_global_get_msglist(owl_global *g) {
173  return(&(g->msglist));
174}
175
176/* keyhandler */
177
178owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
179  return(&(g->kh));
180}
181
182/* curses windows */
183
184WINDOW *owl_global_get_curs_recwin(owl_global *g) {
185  return(g->recwin);
186}
187
188WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
189  return(g->sepwin);
190}
191
192WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
193  return(g->msgwin);
194}
195
196WINDOW *owl_global_get_curs_typwin(owl_global *g) {
197  return(g->typwin);
198}
199
200/* typwin */
201
202owl_editwin *owl_global_get_typwin(owl_global *g) {
203  return(&(g->tw));
204}
205
206/* buffercommand */
207
208void owl_global_set_buffercommand(owl_global *g, char *command) {
209  strcpy(g->buffercommand, command);
210}
211
212char *owl_global_get_buffercommand(owl_global *g) {
213  return(g->buffercommand);
214}
215
216/* refresh */
217
218int owl_global_is_needrefresh(owl_global *g) {
219  if (g->needrefresh==1) return(1);
220  return(0);
221}
222
223void owl_global_set_needrefresh(owl_global *g) {
224  g->needrefresh=1;
225}
226
227void owl_global_set_noneedrefresh(owl_global *g) {
228  g->needrefresh=0;
229}
230
231/* variable dictionary */
232
233owl_vardict *owl_global_get_vardict(owl_global *g) {
234  return &(g->vars);
235}
236
237/* command dictionary */
238
239owl_cmddict *owl_global_get_cmddict(owl_global *g) {
240  return &(g->cmds);
241}
242
243/* rightshift */
244
245void owl_global_set_rightshift(owl_global *g, int i) {
246  g->rightshift=i;
247}
248
249int owl_global_get_rightshift(owl_global *g) {
250  return(g->rightshift);
251}
252
253/* typwin */
254
255int owl_global_is_typwin_active(owl_global *g) {
256  if (g->typwinactive==1) return(1);
257  return(0);
258}
259
260void owl_global_set_typwin_active(owl_global *g) {
261  g->typwinactive=1;
262}
263
264void owl_global_set_typwin_inactive(owl_global *g) {
265  g->typwinactive=0;
266}
267
268/* resize */
269
270void owl_global_set_resize_pending(owl_global *g) {
271  g->resizepending=1;
272}
273
274char *owl_global_get_homedir(owl_global *g) {
275  return(g->homedir);
276}
277
278int owl_global_get_direction(owl_global *g) {
279  return(g->direction);
280}
281
282void owl_global_set_direction_downwards(owl_global *g) {
283  g->direction=OWL_DIRECTION_DOWNWARDS;
284}
285
286void owl_global_set_direction_upwards(owl_global *g) {
287  g->direction=OWL_DIRECTION_UPWARDS;
288}
289
290/* perl stuff */
291
292void owl_global_set_perlinterp(owl_global *g, void *p) {
293  g->perl=p;
294}
295
296void *owl_global_get_perlinterp(owl_global *g) {
297  return(g->perl);
298}
299
300int owl_global_is_config_format(owl_global *g) {
301  if (g->config_format) return(1);
302  return(0);
303}
304
305void owl_global_set_config_format(owl_global *g, int state) {
306  if (state==1) {
307    g->config_format=1;
308  } else {
309    g->config_format=0;
310  }
311}
312
313void owl_global_set_have_config(owl_global *g) {
314  g->haveconfig=1;
315}
316
317void owl_global_set_no_have_config(owl_global *g) {
318  g->haveconfig=0;
319}
320
321int owl_global_have_config(owl_global *g) {
322  if (g->haveconfig) return(1);
323  return(0);
324}
325
326void owl_global_resize(owl_global *g, int x, int y) {
327  /* resize the screen.  If x or y is 0 use the terminal size */
328  struct winsize size;
329   
330  if (!g->resizepending) return;
331
332  /* delete the current windows */
333  delwin(g->recwin);
334  delwin(g->sepwin);
335  delwin(g->msgwin);
336  delwin(g->typwin);
337  if (!isendwin()) {
338    endwin();
339  }
340
341  refresh();
342
343  /* get the new size */
344  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
345  if (x==0) {
346    g->lines=size.ws_row;
347  } else {
348    g->lines=x;
349  }
350
351  if (y==0) {
352    g->cols=size.ws_col;
353  } else {
354    g->cols=y;
355  }
356
357  /* resizeterm(size.ws_row, size.ws_col); */
358
359  /* re-initialize the windows */
360  _owl_global_setup_windows(g);
361
362  /* refresh stuff */
363  g->needrefresh=1;
364  owl_mainwin_redisplay(&(g->mw));
365  sepbar(NULL);
366
367  if (owl_global_is_typwin_active(g)) {
368    owl_editwin_redisplay(&(g->tw), 0);
369  }     
370  /* TODO: this should handle other forms of popwins */
371  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
372      && owl_global_get_viewwin(g)) {
373    owl_popwin_refresh(owl_global_get_popwin(g));
374    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
375  }
376
377  /*
378  char buff[1024];
379  sprintf(buff, "New size is %i lines, %i cols.\n", size.ws_row, size.ws_col);
380  owl_function_makemsg(buff);
381  */
382  owl_function_makemsg("");
383
384  g->resizepending=0;
385}
386
387/* debug */
388
389int owl_global_is_debug_fast(owl_global *g) {
390  if (g->debug) return(1);
391  return(0);
392}
393
394/* starttime */
395
396time_t owl_global_get_starttime(owl_global *g) {
397  return(g->starttime);
398}
399
400time_t owl_global_get_runtime(owl_global *g) {
401  return(time(NULL)-g->starttime);
402}
403
404void owl_global_get_runtime_string(owl_global *g, char *buff) {
405  time_t diff;
406
407  diff=time(NULL)-owl_global_get_starttime(g);
408
409  /* print something nicer later */   
410  sprintf(buff, "%i seconds", (int) diff);
411}
412
413char *owl_global_get_hostname(owl_global *g) {
414  return(g->thishost);
415}
416
417/* userclue */
418
419void owl_global_set_userclue(owl_global *g, int clue) {
420  g->userclue=clue;
421}
422
423void owl_global_add_userclue(owl_global *g, int clue) {
424  g->userclue|=clue;
425}
426
427int owl_global_get_userclue(owl_global *g) {
428  return(g->userclue);
429}
430
431int owl_global_is_userclue(owl_global *g, int clue) {
432  if (g->userclue & clue) return(1);
433  return(0);
434}
435
436/* viewwin */
437
438owl_viewwin *owl_global_get_viewwin(owl_global *g) {
439  return(&(g->vw));
440}
441
442
443/* vert offset */
444
445int owl_global_get_curmsg_vert_offset(owl_global *g) {
446  return(g->curmsg_vert_offset);
447}
448
449void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
450  g->curmsg_vert_offset=i;
451}
452
453/* startup args */
454
455void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
456  int i;
457
458  strcpy(g->startupargs, "");
459  for (i=0; i<argc; i++) {
460    sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
461  }
462  g->startupargs[strlen(g->startupargs)-1]='\0';
463}
464
465char *owl_global_get_startupargs(owl_global *g) {
466  return(g->startupargs);
467}
468
469/* history */
470
471owl_history *owl_global_get_msg_history(owl_global *g) {
472  return(&(g->msghist));
473}
474
475owl_history *owl_global_get_cmd_history(owl_global *g) {
476  return(&(g->cmdhist));
477}
478
479/* filterlist */
480
481owl_list *owl_global_get_filterlist(owl_global *g) {
482  return(&(g->filterlist));
483}
484
485owl_filter *owl_global_get_filter(owl_global *g, char *name) {
486  int i, j;
487  owl_filter *f;
488
489  j=owl_list_get_size(&(g->filterlist));
490  for (i=0; i<j; i++) {
491    f=owl_list_get_element(&(g->filterlist), i);
492    if (!strcmp(name, owl_filter_get_name(f))) {
493      return(f);
494    }
495  }
496  return(NULL);
497}
498
499void owl_global_add_filter(owl_global *g, owl_filter *f) {
500  owl_list_append_element(&(g->filterlist), f);
501}
502
503void owl_global_remove_filter(owl_global *g, char *name) {
504  int i, j;
505  owl_filter *f;
506
507  j=owl_list_get_size(&(g->filterlist));
508  for (i=0; i<j; i++) {
509    f=owl_list_get_element(&(g->filterlist), i);
510    if (!strcmp(name, owl_filter_get_name(f))) {
511      owl_filter_free(f);
512      owl_list_remove_element(&(g->filterlist), i);
513      break;
514    }
515  }
516}
517
518/* nextmsgid */
519
520int owl_global_get_nextmsgid(owl_global *g) {
521  return(g->nextmsgid++);
522}
523
524/* current view */
525
526owl_view *owl_global_get_current_view(owl_global *g) {
527  return(&(g->current_view));
528}
529
530owl_filterelement *owl_global_get_filterelement_true(owl_global *g) {
531  return(&(g->fe_true));
532}
533
534owl_filterelement *owl_global_get_filterelement_false(owl_global *g) {
535  return(&(g->fe_false));
536}
537
538owl_filterelement *owl_global_get_filterelement_null(owl_global *g) {
539  return(&(g->fe_null));
540}
541
542/* has colors */
543
544int owl_global_get_hascolors(owl_global *g) {
545  if (g->hascolors) return(1);
546  return(0);
547}
548
549/* color pairs */
550
551int owl_global_get_colorpairs(owl_global *g) {
552  return(g->colorpairs);
553}
554
555/* puntlist */
556
557owl_list *owl_global_get_puntlist(owl_global *g) {
558  return(&(g->puntlist));
559}
560
561int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
562  owl_list *pl;
563  int i, j;
564
565  pl=owl_global_get_puntlist(g);
566  j=owl_list_get_size(pl);
567  for (i=0; i<j; i++) {
568    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
569  }
570  return(0);
571}
572
573int owl_global_should_followlast(owl_global *g) {
574  owl_view *v;
575 
576  if (!owl_global_is__followlast(g)) return(0);
577 
578  v=owl_global_get_current_view(g);
579 
580  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
581  return(0);
582}
583
584int owl_global_is_search_active(owl_global *g) {
585  if (g->searchactive) return(1);
586  return(0);
587}
588
589void owl_global_set_search_active(owl_global *g, char *string) {
590  g->searchactive=1;
591  if (g->searchstring != NULL) owl_free(g->searchstring);
592  g->searchstring=owl_strdup(string);
593}
594
595void owl_global_set_search_inactive(owl_global *g) {
596  g->searchactive=0;
597}
598
599char *owl_global_get_search_string(owl_global *g) {
600  if (g->searchstring==NULL) return("");
601  return(g->searchstring);
602}
603
604void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
605  g->newmsgproc_pid=i;
606}
607
608int owl_global_get_newmsgproc_pid(owl_global *g) {
609  return(g->newmsgproc_pid);
610}
611
612void owl_global_add_to_malloced(owl_global *g, int i) {
613  g->malloced+=i;
614}
615
616void owl_global_add_to_freed(owl_global *g, int i) {
617  g->freed+=1;
618}
619
620int owl_global_get_malloced(owl_global *g) {
621  return(g->malloced);
622}
623
624int owl_global_get_freed(owl_global *g) {
625  return(g->freed);
626}
627
628int owl_global_get_meminuse(owl_global *g) {
629  return(g->malloced-g->freed);
630}
Note: See TracBrowser for help on using the repository browser.