- Timestamp:
- Mar 28, 2009, 5:00:34 PM (16 years ago)
- Branches:
- owl
- Children:
- 4de643d
- Parents:
- 5189631
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.c
r176d3443 rdab82f29 1 /* Copyright (c) 2004 James Kretchmar. All rights reserved.1 /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar 2 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * * Redistributions in any form must be accompanied by information on 16 * how to obtain complete source code for the Owl software and any 17 * accompanying software that uses the Owl software. The source code 18 * must either be included in the distribution or be available for no 19 * more than the cost of distribution plus a nominal fee, and must be 20 * freely redistributable under reasonable conditions. For an 21 * executable file, complete source code means the source code for 22 * all modules it contains. It does not include source code for 23 * modules or files that typically accompany the major components of 24 * the operating system on which the executable file runs. 25 * 3 * This file is part of Owl. 4 * 5 * Owl is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * Owl is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Owl. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * --------------------------------------------------------------- 26 19 * 27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 30 * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 34 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 36 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 37 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 * As of Owl version 2.1.12 there are patches contributed by 21 * developers of the the branched BarnOwl project, Copyright (c) 22 * 2006-2008 The BarnOwl Developers. All rights reserved. 38 23 */ 39 24 … … 60 45 #endif 61 46 47 #define STDIN 0 48 62 49 static const char fileIdent[] = "$Id$"; 63 50 … … 69 56 owl_editwin *tw; 70 57 owl_popwin *pw; 71 int j,ret, initialsubs, debug, argcsave, followlast;72 int newmsgs, zpendcount,nexttimediff;58 int ret, initialsubs, debug, argcsave, followlast; 59 int newmsgs, nexttimediff; 73 60 struct sigaction sigact; 74 61 char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE]; … … 79 66 char *dir; 80 67 struct termios tio; 81 #ifdef HAVE_LIBZEPHYR82 ZNotice_t notice;83 #endif84 68 #if OWL_STDERR_REDIR 85 69 int newstderr; … … 200 184 owl_function_debugmsg("startup: first available debugging message"); 201 185 owl_global_set_startupargs(&g, argcsave, argvsave); 186 owl_global_set_haveaim(&g); 187 188 /* prepare stdin dispatch */ 189 { 190 owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); 191 owl_function_debugmsg("startup: creating input selector"); 192 d->fd = STDIN; 193 d->cfunc = &owl_process_input; 194 d->destroy = NULL; 195 owl_select_add_dispatch(d); 196 } 197 202 198 #ifdef HAVE_LIBZEPHYR 203 199 owl_global_set_havezephyr(&g); 200 if (!ret) { 201 owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); 202 owl_function_debugmsg("startup: creating zephyr selector"); 203 d->fd = ZGetFD(); 204 d->cfunc = &owl_zephyr_process_events; 205 d->destroy = NULL; 206 owl_select_add_dispatch(d); 207 owl_global_set_havezephyr(&g); 208 } 204 209 #endif 205 owl_global_set_haveaim(&g);206 210 207 211 #if OWL_STDERR_REDIR 208 212 /* Do this only after we've started curses up... */ 209 owl_function_debugmsg("startup: doing stderr redirection"); 210 newstderr = stderr_replace(); 211 owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ, 212 stderr_redirect_handler, NULL); 213 { 214 owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); 215 owl_function_debugmsg("startup: doing stderr redirection"); 216 d->fd = stderr_replace(); 217 d->cfunc = stderr_redirect_handler; 218 d->destroy = NULL; 219 owl_function_debugmsg("testing: 1"); 220 owl_select_add_dispatch(d); 221 owl_function_debugmsg("testing: 2"); 222 } 223 213 224 #endif 214 225 … … 463 474 /* Grab incoming messages. */ 464 475 newmsgs=0; 465 zpendcount=0; 466 while(owl_zephyr_zpending() || owl_global_messagequeue_pending(&g)) { 467 #ifdef HAVE_LIBZEPHYR 468 struct sockaddr_in from; 469 #endif 476 while(owl_global_messagequeue_pending(&g)) { 470 477 owl_message *m=NULL; 471 478 owl_filter *f; 472 479 473 /* grab the new message, stick it in 'm' */ 474 if (owl_zephyr_zpending()) { 475 #ifdef HAVE_LIBZEPHYR 476 /* grab a zephyr notice, but if we've done 20 without stopping, 477 take a break to process keystrokes etc. */ 478 if (zpendcount>20) break; 479 ZReceiveNotice(¬ice, &from); 480 zpendcount++; 481 482 /* is this an ack from a zephyr we sent? */ 483 if (owl_zephyr_notice_is_ack(¬ice)) { 484 owl_zephyr_handle_ack(¬ice); 485 continue; 486 } 487 488 /* if it's a ping and we're not viewing pings then skip it */ 489 if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) { 490 continue; 491 } 492 493 /* create the new message */ 494 m=owl_malloc(sizeof(owl_message)); 495 owl_message_create_from_znotice(m, ¬ice); 496 #endif 497 } else if (owl_global_messagequeue_pending(&g)) { 498 /* pick up the non-zephyr message in the message queue */ 499 m=owl_global_messageuque_popmsg(&g); 500 } else { 501 /* Not supposed to happen, but we seem to get here on resizes */ 502 owl_function_debugmsg("Bottomed out looking for zephyr"); 503 } 504 505 /* If we didn't pick up a message for some reason, don't go on */ 506 if (m==NULL) { 507 owl_function_debugmsg("m is null in main loop"); 508 continue; 509 } 480 m=owl_global_messageuque_popmsg(&g); 510 481 511 482 /* if this message it on the puntlist, nuke it and continue */ … … 599 570 } 600 571 601 /* dispatch any muxevents */602 owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0);603 604 572 /* follow the last message if we're supposed to */ 605 573 if (newmsgs && followlast) { … … 651 619 } 652 620 653 /* Handle all keypresses. If no key has been pressed, sleep for a 654 * little bit, but otherwise do not. This lets input be grabbed 655 * as quickly as possbile */ 656 j=wgetch(typwin); 657 if (j==ERR) { 658 usleep(10); 659 } else { 660 /* find and activate the current keymap. 661 * TODO: this should really get fixed by activating 662 * keymaps as we switch between windows... 663 */ 664 if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) { 665 owl_context_set_popless(owl_global_get_context(&g), 666 owl_global_get_viewwin(&g)); 667 owl_function_activate_keymap("popless"); 668 } else if (owl_global_is_typwin_active(&g) 669 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) { 670 /* 671 owl_context_set_editline(owl_global_get_context(&g), tw); 672 owl_function_activate_keymap("editline"); 673 */ 674 } else if (owl_global_is_typwin_active(&g) 675 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) { 676 owl_context_set_editmulti(owl_global_get_context(&g), tw); 677 owl_function_activate_keymap("editmulti"); 678 } else { 679 owl_context_set_recv(owl_global_get_context(&g)); 680 owl_function_activate_keymap("recv"); 681 } 682 /* now actually handle the keypress */ 683 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 684 if (ret!=0 && ret!=1) { 685 owl_function_makemsg("Unable to handle keypress"); 686 } 687 } 621 /* select on FDs we know about. */ 622 owl_select(); 688 623 689 624 /* Log any error signals */ … … 698 633 } 699 634 635 } 636 } 637 638 void owl_process_input(owl_dispatch *d) 639 { 640 int ret, j; 641 owl_popwin *pw; 642 owl_editwin *tw; 643 WINDOW *typwin; 644 645 typwin = owl_global_get_curs_typwin(&g); 646 while (1) { 647 j=wgetch(typwin); 648 if (j==ERR) return; 649 650 pw=owl_global_get_popwin(&g); 651 tw=owl_global_get_typwin(&g); 652 653 /* find and activate the current keymap. 654 * TODO: this should really get fixed by activating 655 * keymaps as we switch between windows... 656 */ 657 if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) { 658 owl_context_set_popless(owl_global_get_context(&g), 659 owl_global_get_viewwin(&g)); 660 owl_function_activate_keymap("popless"); 661 } else if (owl_global_is_typwin_active(&g) 662 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) { 663 /* 664 owl_context_set_editline(owl_global_get_context(&g), tw); 665 owl_function_activate_keymap("editline"); 666 */ 667 } else if (owl_global_is_typwin_active(&g) 668 && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) { 669 owl_context_set_editmulti(owl_global_get_context(&g), tw); 670 owl_function_activate_keymap("editmulti"); 671 } else { 672 owl_context_set_recv(owl_global_get_context(&g)); 673 owl_function_activate_keymap("recv"); 674 } 675 /* now actually handle the keypress */ 676 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 677 if (ret!=0 && ret!=1) { 678 owl_function_makemsg("Unable to handle keypress"); 679 } 700 680 } 701 681 } … … 743 723 return -1; 744 724 } 745 owl_function_debugmsg("stderr_replace: pipe: %d,%d \n", pipefds[0], pipefds[1]);725 owl_function_debugmsg("stderr_replace: pipe: %d,%d", pipefds[0], pipefds[1]); 746 726 if (-1 == dup2(pipefds[1], 2 /*stderr*/)) { 747 owl_function_debugmsg("stderr_replace: dup2 FAILED (%s) \n", strerror(errno));727 owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)", strerror(errno)); 748 728 perror("dup2"); 749 729 return -1;
Note: See TracChangeset
for help on using the changeset viewer.