[5ca5f8e] | 1 | /* Copyright (c) 2004 James Kretchmar. All rights reserved. |
---|
[7d4fbcd] | 2 | * |
---|
[5ca5f8e] | 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 | * |
---|
| 26 | * |
---|
| 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. |
---|
[7d4fbcd] | 38 | */ |
---|
| 39 | |
---|
| 40 | #include <stdio.h> |
---|
| 41 | #include <unistd.h> |
---|
| 42 | #include <stdlib.h> |
---|
| 43 | #include <string.h> |
---|
| 44 | #include <signal.h> |
---|
[5145235] | 45 | #include <time.h> |
---|
[7d4fbcd] | 46 | #include <sys/param.h> |
---|
[700c712] | 47 | #include <sys/types.h> |
---|
[9c7a701] | 48 | #include <sys/time.h> |
---|
[8232149] | 49 | #include <termios.h> |
---|
[38cf544c] | 50 | #include <sys/stat.h> |
---|
[34509d5] | 51 | #include <locale.h> |
---|
[7d4fbcd] | 52 | #include "owl.h" |
---|
| 53 | |
---|
[2a2bb60] | 54 | #if OWL_STDERR_REDIR |
---|
[e8b95f8] | 55 | #ifdef HAVE_SYS_IOCTL_H |
---|
[2a2bb60] | 56 | #include <sys/ioctl.h> |
---|
[e8b95f8] | 57 | #endif |
---|
| 58 | #ifdef HAVE_SYS_FILIO_H |
---|
| 59 | #include <sys/filio.h> |
---|
| 60 | #endif |
---|
[2a2bb60] | 61 | int stderr_replace(void); |
---|
| 62 | #endif |
---|
| 63 | |
---|
[9c7a701] | 64 | #define STDIN 0 |
---|
| 65 | |
---|
[1aee7d9] | 66 | static const char fileIdent[] = "$Id$"; |
---|
| 67 | |
---|
[b2b0773] | 68 | owl_global g; |
---|
| 69 | |
---|
[de22c3d] | 70 | int main(int argc, char **argv, char **env) |
---|
| 71 | { |
---|
[7d4fbcd] | 72 | WINDOW *recwin, *sepwin, *typwin, *msgwin; |
---|
| 73 | owl_editwin *tw; |
---|
| 74 | owl_popwin *pw; |
---|
[47519e1b] | 75 | int ret, initialsubs, debug, argcsave, followlast; |
---|
[13a3c1db] | 76 | int newmsgs, nexttimediff; |
---|
[7d4fbcd] | 77 | struct sigaction sigact; |
---|
[2fa15f0] | 78 | char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE]; |
---|
[b363d83] | 79 | char *confdir; |
---|
[7d4fbcd] | 80 | owl_filter *f; |
---|
[bd3f232] | 81 | owl_style *s; |
---|
[a15a84f] | 82 | time_t nexttime, now; |
---|
| 83 | struct tm *today; |
---|
[38cf544c] | 84 | char *dir; |
---|
[8232149] | 85 | struct termios tio; |
---|
[13a3c1db] | 86 | owl_message *m; |
---|
[2a2bb60] | 87 | #if OWL_STDERR_REDIR |
---|
| 88 | int newstderr; |
---|
| 89 | #endif |
---|
[c60ade2] | 90 | |
---|
| 91 | if (!GLIB_CHECK_VERSION (2, 12, 0)) |
---|
| 92 | g_error ("GLib version 2.12.0 or above is needed."); |
---|
[7d4fbcd] | 93 | |
---|
| 94 | argcsave=argc; |
---|
| 95 | argvsave=argv; |
---|
| 96 | configfile=NULL; |
---|
[b363d83] | 97 | confdir = NULL; |
---|
[7d4fbcd] | 98 | tty=NULL; |
---|
| 99 | debug=0; |
---|
[bd3f232] | 100 | initialsubs=1; |
---|
[34509d5] | 101 | |
---|
| 102 | setlocale(LC_ALL, ""); |
---|
| 103 | |
---|
[7d4fbcd] | 104 | if (argc>0) { |
---|
| 105 | argv++; |
---|
| 106 | argc--; |
---|
| 107 | } |
---|
| 108 | while (argc>0) { |
---|
| 109 | if (!strcmp(argv[0], "-n")) { |
---|
| 110 | initialsubs=0; |
---|
| 111 | argv++; |
---|
| 112 | argc--; |
---|
| 113 | } else if (!strcmp(argv[0], "-c")) { |
---|
| 114 | if (argc<2) { |
---|
[b363d83] | 115 | fprintf(stderr, "Too few arguments to -c\n"); |
---|
| 116 | usage(); |
---|
| 117 | exit(1); |
---|
[7d4fbcd] | 118 | } |
---|
| 119 | configfile=argv[1]; |
---|
| 120 | argv+=2; |
---|
| 121 | argc-=2; |
---|
| 122 | } else if (!strcmp(argv[0], "-t")) { |
---|
| 123 | if (argc<2) { |
---|
[b363d83] | 124 | fprintf(stderr, "Too few arguments to -t\n"); |
---|
| 125 | usage(); |
---|
| 126 | exit(1); |
---|
[7d4fbcd] | 127 | } |
---|
| 128 | tty=argv[1]; |
---|
| 129 | argv+=2; |
---|
| 130 | argc-=2; |
---|
[b363d83] | 131 | } else if (!strcmp(argv[0], "-s")){ |
---|
| 132 | if (argc<2) { |
---|
| 133 | fprintf(stderr, "Too few arguments to -s\n"); |
---|
| 134 | usage(); |
---|
| 135 | exit(1); |
---|
| 136 | } |
---|
| 137 | confdir = argv[1]; |
---|
| 138 | argv+=2; |
---|
| 139 | argc-=2; |
---|
[7d4fbcd] | 140 | } else if (!strcmp(argv[0], "-d")) { |
---|
| 141 | debug=1; |
---|
| 142 | argv++; |
---|
| 143 | argc--; |
---|
[a68f05d] | 144 | } else if (!strcmp(argv[0], "-D")) { |
---|
| 145 | debug=1; |
---|
| 146 | unlink(OWL_DEBUG_FILE); |
---|
| 147 | argv++; |
---|
| 148 | argc--; |
---|
[7d4fbcd] | 149 | } else if (!strcmp(argv[0], "-v")) { |
---|
[78667f3] | 150 | printf("This is barnowl version %s\n", OWL_VERSION_STRING); |
---|
[7d4fbcd] | 151 | exit(0); |
---|
| 152 | } else { |
---|
| 153 | fprintf(stderr, "Uknown argument\n"); |
---|
| 154 | usage(); |
---|
| 155 | exit(1); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
[176d3443] | 159 | owl_function_debugmsg("startup: Finished parsing arguments"); |
---|
| 160 | |
---|
[7d4fbcd] | 161 | /* signal handler */ |
---|
[c9e72d1] | 162 | /*sigact.sa_handler=sig_handler;*/ |
---|
| 163 | sigact.sa_sigaction=sig_handler; |
---|
[7d4fbcd] | 164 | sigemptyset(&sigact.sa_mask); |
---|
[c9e72d1] | 165 | sigact.sa_flags=SA_SIGINFO; |
---|
[7d4fbcd] | 166 | sigaction(SIGWINCH, &sigact, NULL); |
---|
| 167 | sigaction(SIGALRM, &sigact, NULL); |
---|
[c9e72d1] | 168 | sigaction(SIGPIPE, &sigact, NULL); |
---|
[fe1f605] | 169 | sigaction(SIGTERM, &sigact, NULL); |
---|
| 170 | sigaction(SIGHUP, &sigact, NULL); |
---|
[7d4fbcd] | 171 | |
---|
[8232149] | 172 | /* save initial terminal settings */ |
---|
| 173 | tcgetattr(0, owl_global_get_startup_tio(&g)); |
---|
| 174 | |
---|
| 175 | /* turn ISTRIP off */ |
---|
| 176 | tcgetattr(0, &tio); |
---|
| 177 | tio.c_iflag &= ~ISTRIP; |
---|
| 178 | tcsetattr(0, TCSAFLUSH, &tio); |
---|
| 179 | |
---|
[7d4fbcd] | 180 | /* screen init */ |
---|
[b20de4f] | 181 | if (!getenv("TERMINFO")) { |
---|
[18e28a4] | 182 | owl_function_debugmsg("startup: Not setting TERMINFO"); |
---|
[b20de4f] | 183 | } else { |
---|
| 184 | owl_function_debugmsg("startup: leaving TERMINFO as %s from envrionment", getenv("TERMINFO")); |
---|
| 185 | } |
---|
[7d4fbcd] | 186 | initscr(); |
---|
| 187 | start_color(); |
---|
[ac70242] | 188 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
[7d4fbcd] | 189 | use_default_colors(); |
---|
[ac70242] | 190 | #endif |
---|
[7d4fbcd] | 191 | raw(); |
---|
| 192 | noecho(); |
---|
| 193 | |
---|
| 194 | /* define simple color pairs */ |
---|
| 195 | if (has_colors() && COLOR_PAIRS>=8) { |
---|
[8fa9562] | 196 | int bg = COLOR_BLACK; |
---|
| 197 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
| 198 | bg = -1; |
---|
| 199 | #endif |
---|
| 200 | init_pair(OWL_COLOR_BLACK, COLOR_BLACK, bg); |
---|
| 201 | init_pair(OWL_COLOR_RED, COLOR_RED, bg); |
---|
| 202 | init_pair(OWL_COLOR_GREEN, COLOR_GREEN, bg); |
---|
| 203 | init_pair(OWL_COLOR_YELLOW, COLOR_YELLOW, bg); |
---|
| 204 | init_pair(OWL_COLOR_BLUE, COLOR_BLUE, bg); |
---|
| 205 | init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, bg); |
---|
| 206 | init_pair(OWL_COLOR_CYAN, COLOR_CYAN, bg); |
---|
| 207 | init_pair(OWL_COLOR_WHITE, COLOR_WHITE, bg); |
---|
[7d4fbcd] | 208 | } |
---|
[38cf544c] | 209 | |
---|
[bd3f232] | 210 | /* owl global init */ |
---|
[7d4fbcd] | 211 | owl_global_init(&g); |
---|
[b363d83] | 212 | if (debug) owl_global_set_debug_on(&g); |
---|
| 213 | if (confdir) owl_global_set_confdir(&g, confdir); |
---|
[b20de4f] | 214 | owl_function_debugmsg("startup: first available debugging message"); |
---|
[7d4fbcd] | 215 | owl_global_set_startupargs(&g, argcsave, argvsave); |
---|
[09489b89] | 216 | owl_global_set_haveaim(&g); |
---|
[2a2bb60] | 217 | |
---|
[9c7a701] | 218 | /* prepare stdin dispatch */ |
---|
| 219 | { |
---|
| 220 | owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); |
---|
| 221 | d->fd = STDIN; |
---|
| 222 | d->cfunc = &owl_process_input; |
---|
| 223 | d->pfunc = NULL; |
---|
| 224 | owl_select_add_dispatch(d); |
---|
| 225 | } |
---|
| 226 | |
---|
[596c22df] | 227 | #ifdef HAVE_LIBZEPHYR |
---|
| 228 | /* zephyr init */ |
---|
| 229 | ret=owl_zephyr_initialize(); |
---|
[9c7a701] | 230 | if (!ret) { |
---|
| 231 | owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); |
---|
| 232 | d->fd = ZGetFD(); |
---|
| 233 | d->cfunc = &owl_zephyr_process_events; |
---|
| 234 | d->pfunc = NULL; |
---|
| 235 | owl_select_add_dispatch(d); |
---|
| 236 | owl_global_set_havezephyr(&g); |
---|
| 237 | } |
---|
| 238 | |
---|
[596c22df] | 239 | #endif |
---|
| 240 | |
---|
[2a2bb60] | 241 | #if OWL_STDERR_REDIR |
---|
[a0a5179] | 242 | /* Do this only after we've started curses up... */ |
---|
| 243 | owl_function_debugmsg("startup: doing stderr redirection"); |
---|
[2a2bb60] | 244 | newstderr = stderr_replace(); |
---|
[afbf668] | 245 | owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ, |
---|
| 246 | stderr_redirect_handler, NULL); |
---|
[2a2bb60] | 247 | #endif |
---|
| 248 | |
---|
[38cf544c] | 249 | /* create the owl directory, in case it does not exist */ |
---|
[a0a5179] | 250 | owl_function_debugmsg("startup: creating owl directory, if not present"); |
---|
[b363d83] | 251 | dir=owl_global_get_confdir(&g); |
---|
[38cf544c] | 252 | mkdir(dir, S_IRWXU); |
---|
[5145235] | 253 | |
---|
[ced25d1] | 254 | /* set the tty, either from the command line, or by figuring it out */ |
---|
[a0a5179] | 255 | owl_function_debugmsg("startup: setting tty name"); |
---|
[61e79a9] | 256 | if (tty) { |
---|
| 257 | owl_global_set_tty(&g, tty); |
---|
| 258 | } else { |
---|
| 259 | owl_global_set_tty(&g, owl_util_get_default_tty()); |
---|
| 260 | } |
---|
[7d4fbcd] | 261 | |
---|
[b6c067a] | 262 | /* Initialize perl */ |
---|
| 263 | owl_function_debugmsg("startup: processing config file"); |
---|
| 264 | owl_context_set_readconfig(owl_global_get_context(&g)); |
---|
| 265 | perlerr=owl_perlconfig_initperl(configfile); |
---|
| 266 | if (perlerr) { |
---|
| 267 | endwin(); |
---|
| 268 | owl_function_error("Internal perl error: %s\n", perlerr); |
---|
| 269 | fprintf(stderr, "Internal perl error: %s\n", perlerr); |
---|
| 270 | fflush(stderr); |
---|
| 271 | printf("Internal perl error: %s\n", perlerr); |
---|
| 272 | fflush(stdout); |
---|
| 273 | exit(1); |
---|
| 274 | } |
---|
| 275 | |
---|
[7d4fbcd] | 276 | /* setup the default filters */ |
---|
[3abf28b] | 277 | /* the personal filter will need to change again when AIM chat's are |
---|
| 278 | * included. Also, there should be an %aimme% */ |
---|
[a0a5179] | 279 | owl_function_debugmsg("startup: creating default filters"); |
---|
[bd3f232] | 280 | f=owl_malloc(sizeof(owl_filter)); |
---|
[095e717] | 281 | owl_filter_init_fromstring(f, "personal", "isprivate ^true$ and ( not type ^zephyr$" |
---|
| 282 | " or ( class ^message and" |
---|
| 283 | " ( instance ^personal$ or instance ^urgent$ ) ) )"); |
---|
[7d4fbcd] | 284 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 285 | |
---|
[bd3f232] | 286 | f=owl_malloc(sizeof(owl_filter)); |
---|
[fa86732] | 287 | owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) "); |
---|
| 288 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 289 | |
---|
| 290 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 291 | owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )"); |
---|
[7d4fbcd] | 292 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 293 | |
---|
[bd3f232] | 294 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 295 | owl_filter_init_fromstring(f, "ping", "opcode ^ping$"); |
---|
| 296 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 297 | |
---|
[bd3f232] | 298 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 299 | owl_filter_init_fromstring(f, "auto", "opcode ^auto$"); |
---|
| 300 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 301 | |
---|
[bd3f232] | 302 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 303 | owl_filter_init_fromstring(f, "login", "not login ^none$"); |
---|
[0236842] | 304 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 305 | |
---|
[bd3f232] | 306 | f=owl_malloc(sizeof(owl_filter)); |
---|
[7d4fbcd] | 307 | owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$"); |
---|
| 308 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 309 | |
---|
[bd3f232] | 310 | f=owl_malloc(sizeof(owl_filter)); |
---|
[5a6e6b9] | 311 | owl_filter_init_fromstring(f, "out", "direction ^out$"); |
---|
| 312 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 313 | |
---|
[bd3f232] | 314 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 315 | owl_filter_init_fromstring(f, "aim", "type ^aim$"); |
---|
| 316 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 317 | |
---|
[bd3f232] | 318 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 319 | owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$"); |
---|
| 320 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 321 | |
---|
[bd3f232] | 322 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 323 | owl_filter_init_fromstring(f, "none", "false"); |
---|
| 324 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 325 | |
---|
[bd3f232] | 326 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 327 | owl_filter_init_fromstring(f, "all", "true"); |
---|
[7d4fbcd] | 328 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 329 | |
---|
| 330 | /* set the current view */ |
---|
[a0a5179] | 331 | owl_function_debugmsg("startup: setting the current view"); |
---|
[c3ab155] | 332 | owl_view_create(owl_global_get_current_view(&g), "main", f, owl_global_get_style_by_name(&g, "default")); |
---|
[7d4fbcd] | 333 | |
---|
[96f8e5b] | 334 | /* AIM init */ |
---|
[a0a5179] | 335 | owl_function_debugmsg("startup: doing AIM initialization"); |
---|
[96f8e5b] | 336 | owl_aim_init(); |
---|
| 337 | |
---|
[ced25d1] | 338 | /* execute the startup function in the configfile */ |
---|
[a0a5179] | 339 | owl_function_debugmsg("startup: executing perl startup, if applicable"); |
---|
[0337203] | 340 | perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); |
---|
[7d4fbcd] | 341 | if (perlout) owl_free(perlout); |
---|
[212764e] | 342 | |
---|
[7d4fbcd] | 343 | /* hold on to the window names for convenience */ |
---|
| 344 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 345 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 346 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 347 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 348 | tw=owl_global_get_typwin(&g); |
---|
| 349 | |
---|
[252a5c2] | 350 | /* welcome message */ |
---|
[a0a5179] | 351 | owl_function_debugmsg("startup: creating splash message"); |
---|
[52f3507] | 352 | strcpy(startupmsg, "-----------------------------------------------------------------------\n"); |
---|
[c2c5c77] | 353 | sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING); |
---|
[252a5c2] | 354 | strcat(startupmsg, buff); |
---|
[52f3507] | 355 | strcat(startupmsg, " \n"); |
---|
[c2c5c77] | 356 | strcat(startupmsg, "This is a development build of barnowl. If you are using this \n"); |
---|
| 357 | strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu \n"); |
---|
[52f3507] | 358 | strcat(startupmsg, " ^ ^ \n"); |
---|
[e132a2d] | 359 | strcat(startupmsg, " OvO \n"); |
---|
[2058d7a] | 360 | strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu ( ) \n"); |
---|
[52f3507] | 361 | strcat(startupmsg, "-----------------------------------------------------------------m-m---\n"); |
---|
[252a5c2] | 362 | owl_function_adminmsg("", startupmsg); |
---|
| 363 | sepbar(NULL); |
---|
| 364 | |
---|
[687c674] | 365 | /* process the startup file */ |
---|
| 366 | owl_function_debugmsg("startup: processing startup file"); |
---|
| 367 | owl_function_source(NULL); |
---|
| 368 | |
---|
[7d4fbcd] | 369 | wrefresh(sepwin); |
---|
| 370 | |
---|
| 371 | /* load zephyr subs */ |
---|
[bd3f232] | 372 | if (initialsubs) { |
---|
[4357be8] | 373 | int ret2; |
---|
[a0a5179] | 374 | owl_function_debugmsg("startup: loading initial zephyr subs"); |
---|
[4357be8] | 375 | |
---|
| 376 | /* load default subscriptions */ |
---|
| 377 | ret=owl_zephyr_loaddefaultsubs(); |
---|
[252a5c2] | 378 | |
---|
[4357be8] | 379 | /* load subscriptions from subs file */ |
---|
[95474d7] | 380 | ret2=owl_zephyr_loadsubs(NULL, 0); |
---|
[4357be8] | 381 | |
---|
| 382 | if (ret || ret2) { |
---|
| 383 | owl_function_adminmsg("", "Error loading zephyr subscriptions"); |
---|
| 384 | } else if (ret2!=-1) { |
---|
[bd3f232] | 385 | owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES); |
---|
| 386 | } |
---|
[7d4fbcd] | 387 | |
---|
[bd3f232] | 388 | /* load login subscriptions */ |
---|
| 389 | if (owl_global_is_loginsubs(&g)) { |
---|
[a0a5179] | 390 | owl_function_debugmsg("startup: loading login subs"); |
---|
[bd3f232] | 391 | owl_function_loadloginsubs(NULL); |
---|
| 392 | } |
---|
[7d4fbcd] | 393 | } |
---|
| 394 | |
---|
[5a95b69] | 395 | /* First buddy check to sync the list without notifications */ |
---|
| 396 | owl_function_debugmsg("startup: doing initial zephyr buddy check"); |
---|
[4357be8] | 397 | /* owl_function_zephyr_buddy_check(0); */ |
---|
[5a95b69] | 398 | |
---|
[f933403] | 399 | /* set the startup and default style, based on userclue and presence of a |
---|
| 400 | * formatting function */ |
---|
[a0a5179] | 401 | owl_function_debugmsg("startup: setting startup and default style"); |
---|
[27c3a93] | 402 | if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) { |
---|
| 403 | /* the style was set by the user: leave it alone */ |
---|
[f933403] | 404 | } else { |
---|
[52f8dd6] | 405 | owl_global_set_default_style(&g, "default"); |
---|
[f933403] | 406 | } |
---|
| 407 | |
---|
[7d4fbcd] | 408 | /* zlog in if we need to */ |
---|
| 409 | if (owl_global_is_startuplogin(&g)) { |
---|
[a0a5179] | 410 | owl_function_debugmsg("startup: doing zlog in"); |
---|
[31e48a3] | 411 | owl_zephyr_zlog_in(); |
---|
[7d4fbcd] | 412 | } |
---|
| 413 | |
---|
[39dc159] | 414 | owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g)); |
---|
[72c210f] | 415 | s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)); |
---|
| 416 | if(s) |
---|
| 417 | owl_view_set_style(owl_global_get_current_view(&g), s); |
---|
| 418 | else |
---|
| 419 | owl_function_error("No such style: %s", owl_global_get_default_style(&g)); |
---|
[a0a5179] | 420 | |
---|
| 421 | owl_function_debugmsg("startup: setting context interactive"); |
---|
[7d4fbcd] | 422 | owl_context_set_interactive(owl_global_get_context(&g)); |
---|
| 423 | |
---|
[a15a84f] | 424 | nexttimediff=10; |
---|
[4b464a4] | 425 | nexttime=time(NULL); |
---|
| 426 | |
---|
[c0c4449c] | 427 | #ifdef HAVE_LIBZEPHYR |
---|
| 428 | /* Check for any zephyrs that have come in while we've done init. */ |
---|
| 429 | owl_zephyr_process_events(); |
---|
| 430 | #endif |
---|
| 431 | |
---|
[a0a5179] | 432 | owl_function_debugmsg("startup: entering main loop"); |
---|
[7d4fbcd] | 433 | /* main loop */ |
---|
| 434 | while (1) { |
---|
| 435 | |
---|
| 436 | /* if a resize has been scheduled, deal with it */ |
---|
| 437 | owl_global_resize(&g, 0, 0); |
---|
| 438 | |
---|
| 439 | /* these are here in case a resize changes the windows */ |
---|
| 440 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 441 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 442 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 443 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 444 | |
---|
| 445 | followlast=owl_global_should_followlast(&g); |
---|
[5789230] | 446 | |
---|
[8203afd] | 447 | owl_perlconfig_mainloop(); |
---|
[bc220b2] | 448 | |
---|
[4b464a4] | 449 | /* little hack */ |
---|
[a15a84f] | 450 | now=time(NULL); |
---|
| 451 | today=localtime(&now); |
---|
| 452 | if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) { |
---|
[4b464a4] | 453 | if (time(NULL)>nexttime) { |
---|
| 454 | if (nexttimediff==1) { |
---|
[a15a84f] | 455 | nexttimediff=10; |
---|
[4b464a4] | 456 | } else { |
---|
| 457 | nexttimediff=1; |
---|
| 458 | } |
---|
| 459 | nexttime+=nexttimediff; |
---|
| 460 | owl_hack_animate(); |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | |
---|
[aac889a] | 464 | /* Grab incoming messages. */ |
---|
[d09e5a1] | 465 | newmsgs=0; |
---|
[13a3c1db] | 466 | while(owl_global_messagequeue_pending(&g)) { |
---|
[5a95b69] | 467 | |
---|
[13a3c1db] | 468 | m = owl_global_messagequeue_popmsg(&g); |
---|
[7d4fbcd] | 469 | |
---|
[13a3c1db] | 470 | if(owl_process_message(m)) |
---|
| 471 | newmsgs = 1; |
---|
[7d4fbcd] | 472 | } |
---|
| 473 | |
---|
[5a95b69] | 474 | /* is it time to check zbuddies? */ |
---|
| 475 | if (owl_global_is_pseudologins(&g)) { |
---|
| 476 | if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) { |
---|
| 477 | owl_function_debugmsg("Doing zephyr buddy check"); |
---|
| 478 | owl_function_zephyr_buddy_check(1); |
---|
| 479 | owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g)); |
---|
| 480 | } |
---|
| 481 | } |
---|
| 482 | |
---|
[afbf668] | 483 | /* dispatch any muxevents */ |
---|
| 484 | owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0); |
---|
| 485 | |
---|
[7d4fbcd] | 486 | /* follow the last message if we're supposed to */ |
---|
[d09e5a1] | 487 | if (newmsgs && followlast) { |
---|
[7d4fbcd] | 488 | owl_function_lastmsg_noredisplay(); |
---|
| 489 | } |
---|
[700c712] | 490 | |
---|
[ced25d1] | 491 | /* do the newmsgproc thing */ |
---|
[d09e5a1] | 492 | if (newmsgs) { |
---|
[8f44c6b] | 493 | owl_function_do_newmsgproc(); |
---|
[700c712] | 494 | } |
---|
[7d4fbcd] | 495 | |
---|
| 496 | /* redisplay if necessary */ |
---|
[d09e5a1] | 497 | /* this should be optimized to not run if the new messages won't be displayed */ |
---|
| 498 | if (newmsgs) { |
---|
[7d4fbcd] | 499 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 500 | sepbar(NULL); |
---|
| 501 | if (owl_popwin_is_active(owl_global_get_popwin(&g))) { |
---|
| 502 | owl_popwin_refresh(owl_global_get_popwin(&g)); |
---|
| 503 | /* TODO: this is a broken kludge */ |
---|
| 504 | if (owl_global_get_viewwin(&g)) { |
---|
| 505 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | owl_global_set_needrefresh(&g); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | /* if a popwin just came up, refresh it */ |
---|
| 512 | pw=owl_global_get_popwin(&g); |
---|
| 513 | if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) { |
---|
| 514 | owl_popwin_refresh(pw); |
---|
| 515 | owl_popwin_no_needs_first_refresh(pw); |
---|
| 516 | owl_global_set_needrefresh(&g); |
---|
| 517 | /* TODO: this is a broken kludge */ |
---|
| 518 | if (owl_global_get_viewwin(&g)) { |
---|
| 519 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | /* update the terminal if we need to */ |
---|
| 524 | if (owl_global_is_needrefresh(&g)) { |
---|
| 525 | /* leave the cursor in the appropriate window */ |
---|
| 526 | if (owl_global_is_typwin_active(&g)) { |
---|
| 527 | owl_function_set_cursor(typwin); |
---|
| 528 | } else { |
---|
| 529 | owl_function_set_cursor(sepwin); |
---|
| 530 | } |
---|
| 531 | doupdate(); |
---|
| 532 | owl_global_set_noneedrefresh(&g); |
---|
| 533 | } |
---|
| 534 | |
---|
[9c7a701] | 535 | /* select on FDs we know about. */ |
---|
| 536 | owl_select(); |
---|
[2a2bb60] | 537 | |
---|
[c9e72d1] | 538 | /* Log any error signals */ |
---|
| 539 | { |
---|
| 540 | siginfo_t si; |
---|
| 541 | int signum; |
---|
| 542 | if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) { |
---|
[81634b6] | 543 | owl_function_error("Got unexpected signal: %d %s (code: %d band: %d errno: %d)", |
---|
[afbf668] | 544 | signum, signum==SIGPIPE?"SIGPIPE":"SIG????", |
---|
[81634b6] | 545 | si.si_code, si.si_band, si.si_errno); |
---|
[c9e72d1] | 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
[7d4fbcd] | 549 | } |
---|
| 550 | } |
---|
| 551 | |
---|
[13a3c1db] | 552 | /* |
---|
| 553 | * Process a new message passed to us on the message queue from some |
---|
| 554 | * protocol. This includes adding it to the message list, updating the |
---|
| 555 | * view and scrolling if appropriate, logging it, and so on. |
---|
| 556 | * |
---|
| 557 | * Either a pointer is kept to the message internally, or it is freed |
---|
| 558 | * if unneeded. The caller no longer ``owns'' the message's memory. |
---|
| 559 | * |
---|
| 560 | * Returns 1 if the message was added to the message list, and 0 if it |
---|
| 561 | * was ignored due to user settings or otherwise. |
---|
| 562 | */ |
---|
| 563 | int owl_process_message(owl_message *m) { |
---|
| 564 | owl_filter *f; |
---|
| 565 | /* if this message it on the puntlist, nuke it and continue */ |
---|
| 566 | if (owl_global_message_is_puntable(&g, m)) { |
---|
| 567 | owl_message_free(m); |
---|
| 568 | return 0; |
---|
| 569 | } |
---|
| 570 | |
---|
| 571 | /* login or logout that should be ignored? */ |
---|
| 572 | if (owl_global_is_ignorelogins(&g) |
---|
| 573 | && owl_message_is_loginout(m)) { |
---|
| 574 | owl_message_free(m); |
---|
| 575 | return 0; |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | if (!owl_global_is_displayoutgoing(&g) |
---|
| 579 | && owl_message_is_direction_out(m)) { |
---|
| 580 | owl_message_free(m); |
---|
| 581 | return 0; |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | /* add it to the global list */ |
---|
| 585 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
| 586 | /* add it to any necessary views; right now there's only the current view */ |
---|
| 587 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
| 588 | |
---|
| 589 | if(owl_message_is_direction_in(m)) { |
---|
| 590 | /* let perl know about it*/ |
---|
[b67ab6b] | 591 | owl_perlconfig_getmsg(m, NULL); |
---|
[13a3c1db] | 592 | |
---|
| 593 | /* do we need to autoreply? */ |
---|
| 594 | if (owl_global_is_zaway(&g) && !owl_message_get_attribute_value(m, "isauto")) { |
---|
| 595 | if (owl_message_is_type_zephyr(m)) { |
---|
| 596 | owl_zephyr_zaway(m); |
---|
| 597 | } else if (owl_message_is_type_aim(m)) { |
---|
| 598 | if (owl_message_is_private(m)) { |
---|
| 599 | owl_function_send_aimawymsg(owl_message_get_sender(m), owl_global_get_zaway_msg(&g)); |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | /* ring the bell if it's a personal */ |
---|
| 605 | if (!strcmp(owl_global_get_personalbell(&g), "on")) { |
---|
| 606 | if (!owl_message_is_loginout(m) && |
---|
| 607 | !owl_message_is_mail(m) && |
---|
| 608 | owl_message_is_personal(m)) { |
---|
| 609 | owl_function_beep(); |
---|
| 610 | } |
---|
| 611 | } else if (!strcmp(owl_global_get_personalbell(&g), "off")) { |
---|
| 612 | /* do nothing */ |
---|
| 613 | } else { |
---|
| 614 | f=owl_global_get_filter(&g, owl_global_get_personalbell(&g)); |
---|
| 615 | if (f && owl_filter_message_match(f, m)) { |
---|
| 616 | owl_function_beep(); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | /* if it matches the alert filter, do the alert action */ |
---|
| 621 | f=owl_global_get_filter(&g, owl_global_get_alert_filter(&g)); |
---|
| 622 | if (f && owl_filter_message_match(f, m)) { |
---|
| 623 | owl_function_command(owl_global_get_alert_action(&g)); |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | /* if it's a zephyr login or logout, update the zbuddylist */ |
---|
| 627 | if (owl_message_is_type_zephyr(m) && owl_message_is_loginout(m)) { |
---|
| 628 | if (owl_message_is_login(m)) { |
---|
| 629 | owl_zbuddylist_adduser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m)); |
---|
| 630 | } else if (owl_message_is_logout(m)) { |
---|
| 631 | owl_zbuddylist_deluser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m)); |
---|
| 632 | } else { |
---|
| 633 | owl_function_error("Internal error: received login notice that is neither login nor logout"); |
---|
| 634 | } |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | /* check for burning ears message */ |
---|
| 638 | /* this is an unsupported feature */ |
---|
| 639 | if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) { |
---|
| 640 | char *buff; |
---|
| 641 | buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m)); |
---|
| 642 | owl_function_adminmsg(buff, ""); |
---|
| 643 | owl_free(buff); |
---|
| 644 | owl_function_beep(); |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | /* log the message if we need to */ |
---|
| 649 | owl_log_message(m); |
---|
| 650 | |
---|
| 651 | return 1; |
---|
| 652 | } |
---|
| 653 | |
---|
[9c7a701] | 654 | void owl_process_aim() |
---|
| 655 | { |
---|
| 656 | if (owl_global_is_doaimevents(&g)) { |
---|
| 657 | owl_aim_process_events(); |
---|
| 658 | |
---|
| 659 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 660 | if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) { |
---|
| 661 | /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */ |
---|
| 662 | owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g)); |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | void owl_process_input() |
---|
| 669 | { |
---|
[5f3168a] | 670 | int ret; |
---|
| 671 | owl_input j; |
---|
[9c7a701] | 672 | owl_popwin *pw; |
---|
| 673 | owl_editwin *tw; |
---|
[5f3168a] | 674 | WINDOW *typwin; |
---|
[9c7a701] | 675 | |
---|
[5f3168a] | 676 | typwin = owl_global_get_curs_typwin(&g); |
---|
[4cc0ee0b] | 677 | while (1) { |
---|
[07bfbc2] | 678 | j.ch = wgetch(typwin); |
---|
| 679 | if (j.ch == ERR) return; |
---|
| 680 | |
---|
[4cc0ee0b] | 681 | owl_global_set_lastinputtime(&g, time(NULL)); |
---|
| 682 | pw=owl_global_get_popwin(&g); |
---|
| 683 | tw=owl_global_get_typwin(&g); |
---|
[9c7a701] | 684 | |
---|
[07bfbc2] | 685 | j.uch = '\0'; |
---|
| 686 | if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) { |
---|
| 687 | /* This is a curses control character. */ |
---|
[5f3168a] | 688 | } |
---|
[07bfbc2] | 689 | else if (j.ch > 0x7f && j.ch < 0xfe) { |
---|
| 690 | /* Pull in a full utf-8 character. */ |
---|
| 691 | int bytes, i; |
---|
| 692 | char utf8buf[7]; |
---|
| 693 | memset(utf8buf, '\0', 7); |
---|
| 694 | |
---|
| 695 | utf8buf[0] = j.ch; |
---|
| 696 | |
---|
| 697 | if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2; |
---|
| 698 | else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3; |
---|
| 699 | else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4; |
---|
| 700 | else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5; |
---|
| 701 | else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6; |
---|
| 702 | else bytes = 1; |
---|
| 703 | |
---|
| 704 | for (i = 1; i < bytes; i++) { |
---|
| 705 | int tmp = wgetch(typwin); |
---|
| 706 | /* If what we got was not a byte, or not a continuation byte */ |
---|
| 707 | if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) { |
---|
| 708 | /* ill-formed UTF-8 code unit subsequence, put back the |
---|
| 709 | char we just got. */ |
---|
| 710 | ungetch(tmp); |
---|
| 711 | j.ch = ERR; |
---|
| 712 | break; |
---|
| 713 | } |
---|
| 714 | utf8buf[i] = tmp; |
---|
[5f3168a] | 715 | } |
---|
[07bfbc2] | 716 | |
---|
| 717 | if (j.ch != ERR) { |
---|
| 718 | if (g_utf8_validate(utf8buf, -1, NULL)) { |
---|
| 719 | j.uch = g_utf8_get_char(utf8buf); |
---|
| 720 | } |
---|
| 721 | else { |
---|
| 722 | j.ch = ERR; |
---|
| 723 | } |
---|
[5f3168a] | 724 | } |
---|
| 725 | } |
---|
[07bfbc2] | 726 | else if (j.ch <= 0x7f) { |
---|
| 727 | j.uch = j.ch; |
---|
| 728 | } |
---|
[4cc0ee0b] | 729 | |
---|
[07bfbc2] | 730 | owl_global_set_lastinputtime(&g, time(NULL)); |
---|
[4cc0ee0b] | 731 | /* find and activate the current keymap. |
---|
| 732 | * TODO: this should really get fixed by activating |
---|
| 733 | * keymaps as we switch between windows... |
---|
| 734 | */ |
---|
| 735 | if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) { |
---|
| 736 | owl_context_set_popless(owl_global_get_context(&g), |
---|
| 737 | owl_global_get_viewwin(&g)); |
---|
| 738 | owl_function_activate_keymap("popless"); |
---|
| 739 | } else if (owl_global_is_typwin_active(&g) |
---|
[07bfbc2] | 740 | && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) { |
---|
[4cc0ee0b] | 741 | /* |
---|
| 742 | owl_context_set_editline(owl_global_get_context(&g), tw); |
---|
| 743 | owl_function_activate_keymap("editline"); |
---|
| 744 | */ |
---|
| 745 | } else if (owl_global_is_typwin_active(&g) |
---|
[07bfbc2] | 746 | && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) { |
---|
[4cc0ee0b] | 747 | owl_context_set_editmulti(owl_global_get_context(&g), tw); |
---|
| 748 | owl_function_activate_keymap("editmulti"); |
---|
| 749 | } else { |
---|
| 750 | owl_context_set_recv(owl_global_get_context(&g)); |
---|
| 751 | owl_function_activate_keymap("recv"); |
---|
| 752 | } |
---|
| 753 | /* now actually handle the keypress */ |
---|
| 754 | ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); |
---|
[07bfbc2] | 755 | if (ret!=0 && ret!=1) { |
---|
[4cc0ee0b] | 756 | owl_function_makemsg("Unable to handle keypress"); |
---|
| 757 | } |
---|
[9c7a701] | 758 | } |
---|
| 759 | } |
---|
| 760 | |
---|
[de22c3d] | 761 | void sig_handler(int sig, siginfo_t *si, void *data) |
---|
| 762 | { |
---|
[7d4fbcd] | 763 | if (sig==SIGWINCH) { |
---|
[bd3f232] | 764 | /* we can't inturrupt a malloc here, so it just sets a flag |
---|
| 765 | * schedulding a resize for later |
---|
| 766 | */ |
---|
[7d4fbcd] | 767 | owl_function_resize(); |
---|
[afbf668] | 768 | } else if (sig==SIGPIPE || sig==SIGCHLD) { |
---|
[c9e72d1] | 769 | /* Set a flag and some info that we got the sigpipe |
---|
| 770 | * so we can record that we got it and why... */ |
---|
| 771 | owl_global_set_errsignal(&g, sig, si); |
---|
[fe1f605] | 772 | } else if (sig==SIGTERM || sig==SIGHUP) { |
---|
| 773 | owl_function_quit(); |
---|
[7d4fbcd] | 774 | } |
---|
| 775 | } |
---|
| 776 | |
---|
[de22c3d] | 777 | void usage() |
---|
| 778 | { |
---|
[78667f3] | 779 | fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING); |
---|
| 780 | fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n"); |
---|
[e7cc1c3] | 781 | fprintf(stderr, " -n don't load zephyr subscriptions\n"); |
---|
| 782 | fprintf(stderr, " -d enable debugging\n"); |
---|
[a68f05d] | 783 | fprintf(stderr, " -D enable debugging and delete previous debug file\n"); |
---|
[78667f3] | 784 | fprintf(stderr, " -v print the Barnowl version number and exit\n"); |
---|
[e7cc1c3] | 785 | fprintf(stderr, " -h print this help message\n"); |
---|
| 786 | fprintf(stderr, " -c specify an alternate config file\n"); |
---|
[b363d83] | 787 | fprintf(stderr, " -s specify an alternate config dir (default ~/.owl)\n"); |
---|
[e7cc1c3] | 788 | fprintf(stderr, " -t set the tty name\n"); |
---|
[7d4fbcd] | 789 | } |
---|
[2a2bb60] | 790 | |
---|
| 791 | #if OWL_STDERR_REDIR |
---|
| 792 | |
---|
| 793 | /* Replaces stderr with a pipe so that we can read from it. |
---|
| 794 | * Returns the fd of the pipe from which stderr can be read. */ |
---|
[de22c3d] | 795 | int stderr_replace(void) |
---|
| 796 | { |
---|
[2a2bb60] | 797 | int pipefds[2]; |
---|
| 798 | if (0 != pipe(pipefds)) { |
---|
| 799 | perror("pipe"); |
---|
| 800 | owl_function_debugmsg("stderr_replace: pipe FAILED\n"); |
---|
| 801 | return -1; |
---|
| 802 | } |
---|
| 803 | owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]); |
---|
| 804 | if (-1 == dup2(pipefds[1], 2 /*stderr*/)) { |
---|
| 805 | owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno)); |
---|
| 806 | perror("dup2"); |
---|
| 807 | return -1; |
---|
| 808 | } |
---|
| 809 | return pipefds[0]; |
---|
| 810 | } |
---|
| 811 | |
---|
[afbf668] | 812 | /* Sends stderr (read from rfd) messages to the error console */ |
---|
| 813 | void stderr_redirect_handler(int handle, int rfd, int eventmask, void *data) |
---|
[de22c3d] | 814 | { |
---|
[2a2bb60] | 815 | int navail, bread; |
---|
| 816 | char *buf; |
---|
| 817 | /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/ |
---|
| 818 | if (rfd<0) return; |
---|
| 819 | if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) { |
---|
| 820 | return; |
---|
| 821 | } |
---|
| 822 | /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/ |
---|
| 823 | if (navail<=0) return; |
---|
| 824 | if (navail>256) { navail = 256; } |
---|
| 825 | buf = owl_malloc(navail+1); |
---|
| 826 | bread = read(rfd, buf, navail); |
---|
| 827 | if (buf[navail-1] != '\0') { |
---|
| 828 | buf[navail] = '\0'; |
---|
| 829 | } |
---|
| 830 | owl_function_error("Err: %s", buf); |
---|
| 831 | owl_free(buf); |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | #endif /* OWL_STDERR_REDIR */ |
---|