source: global.c @ 67103d4

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