[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> |
---|
[7d4fbcd] | 51 | #include "owl.h" |
---|
| 52 | |
---|
[2a2bb60] | 53 | #if OWL_STDERR_REDIR |
---|
[e8b95f8] | 54 | #ifdef HAVE_SYS_IOCTL_H |
---|
[2a2bb60] | 55 | #include <sys/ioctl.h> |
---|
[e8b95f8] | 56 | #endif |
---|
| 57 | #ifdef HAVE_SYS_FILIO_H |
---|
| 58 | #include <sys/filio.h> |
---|
| 59 | #endif |
---|
[2a2bb60] | 60 | int stderr_replace(void); |
---|
| 61 | #endif |
---|
| 62 | |
---|
[1aee7d9] | 63 | static const char fileIdent[] = "$Id$"; |
---|
| 64 | |
---|
[b2b0773] | 65 | owl_global g; |
---|
| 66 | |
---|
[de22c3d] | 67 | int main(int argc, char **argv, char **env) |
---|
| 68 | { |
---|
[7d4fbcd] | 69 | WINDOW *recwin, *sepwin, *typwin, *msgwin; |
---|
| 70 | owl_editwin *tw; |
---|
| 71 | owl_popwin *pw; |
---|
[9c7a701] | 72 | int ret, initialsubs, debug, argcsave, followlast; |
---|
[13a3c1db] | 73 | int newmsgs, nexttimediff; |
---|
[7d4fbcd] | 74 | struct sigaction sigact; |
---|
[2fa15f0] | 75 | char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE]; |
---|
[b363d83] | 76 | char *confdir; |
---|
[7d4fbcd] | 77 | owl_filter *f; |
---|
[bd3f232] | 78 | owl_style *s; |
---|
[a15a84f] | 79 | time_t nexttime, now; |
---|
| 80 | struct tm *today; |
---|
[38cf544c] | 81 | char *dir; |
---|
[8232149] | 82 | struct termios tio; |
---|
[13a3c1db] | 83 | owl_message *m; |
---|
[2a2bb60] | 84 | #if OWL_STDERR_REDIR |
---|
| 85 | int newstderr; |
---|
| 86 | #endif |
---|
[7d4fbcd] | 87 | |
---|
| 88 | argcsave=argc; |
---|
| 89 | argvsave=argv; |
---|
| 90 | configfile=NULL; |
---|
[b363d83] | 91 | confdir = NULL; |
---|
[7d4fbcd] | 92 | tty=NULL; |
---|
| 93 | debug=0; |
---|
[bd3f232] | 94 | initialsubs=1; |
---|
[7d4fbcd] | 95 | if (argc>0) { |
---|
| 96 | argv++; |
---|
| 97 | argc--; |
---|
| 98 | } |
---|
| 99 | while (argc>0) { |
---|
| 100 | if (!strcmp(argv[0], "-n")) { |
---|
| 101 | initialsubs=0; |
---|
| 102 | argv++; |
---|
| 103 | argc--; |
---|
| 104 | } else if (!strcmp(argv[0], "-c")) { |
---|
| 105 | if (argc<2) { |
---|
[b363d83] | 106 | fprintf(stderr, "Too few arguments to -c\n"); |
---|
| 107 | usage(); |
---|
| 108 | exit(1); |
---|
[7d4fbcd] | 109 | } |
---|
| 110 | configfile=argv[1]; |
---|
| 111 | argv+=2; |
---|
| 112 | argc-=2; |
---|
| 113 | } else if (!strcmp(argv[0], "-t")) { |
---|
| 114 | if (argc<2) { |
---|
[b363d83] | 115 | fprintf(stderr, "Too few arguments to -t\n"); |
---|
| 116 | usage(); |
---|
| 117 | exit(1); |
---|
[7d4fbcd] | 118 | } |
---|
| 119 | tty=argv[1]; |
---|
| 120 | argv+=2; |
---|
| 121 | argc-=2; |
---|
[b363d83] | 122 | } else if (!strcmp(argv[0], "-s")){ |
---|
| 123 | if (argc<2) { |
---|
| 124 | fprintf(stderr, "Too few arguments to -s\n"); |
---|
| 125 | usage(); |
---|
| 126 | exit(1); |
---|
| 127 | } |
---|
| 128 | confdir = argv[1]; |
---|
| 129 | argv+=2; |
---|
| 130 | argc-=2; |
---|
[7d4fbcd] | 131 | } else if (!strcmp(argv[0], "-d")) { |
---|
| 132 | debug=1; |
---|
| 133 | argv++; |
---|
| 134 | argc--; |
---|
[a68f05d] | 135 | } else if (!strcmp(argv[0], "-D")) { |
---|
| 136 | debug=1; |
---|
| 137 | unlink(OWL_DEBUG_FILE); |
---|
| 138 | argv++; |
---|
| 139 | argc--; |
---|
[7d4fbcd] | 140 | } else if (!strcmp(argv[0], "-v")) { |
---|
[78667f3] | 141 | printf("This is barnowl version %s\n", OWL_VERSION_STRING); |
---|
[7d4fbcd] | 142 | exit(0); |
---|
| 143 | } else { |
---|
| 144 | fprintf(stderr, "Uknown argument\n"); |
---|
| 145 | usage(); |
---|
| 146 | exit(1); |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | |
---|
[176d3443] | 150 | owl_function_debugmsg("startup: Finished parsing arguments"); |
---|
| 151 | |
---|
[7d4fbcd] | 152 | /* signal handler */ |
---|
[c9e72d1] | 153 | /*sigact.sa_handler=sig_handler;*/ |
---|
| 154 | sigact.sa_sigaction=sig_handler; |
---|
[7d4fbcd] | 155 | sigemptyset(&sigact.sa_mask); |
---|
[c9e72d1] | 156 | sigact.sa_flags=SA_SIGINFO; |
---|
[7d4fbcd] | 157 | sigaction(SIGWINCH, &sigact, NULL); |
---|
| 158 | sigaction(SIGALRM, &sigact, NULL); |
---|
[c9e72d1] | 159 | sigaction(SIGPIPE, &sigact, NULL); |
---|
[fe1f605] | 160 | sigaction(SIGTERM, &sigact, NULL); |
---|
| 161 | sigaction(SIGHUP, &sigact, NULL); |
---|
[7d4fbcd] | 162 | |
---|
[8232149] | 163 | /* save initial terminal settings */ |
---|
| 164 | tcgetattr(0, owl_global_get_startup_tio(&g)); |
---|
| 165 | |
---|
| 166 | /* turn ISTRIP off */ |
---|
| 167 | tcgetattr(0, &tio); |
---|
| 168 | tio.c_iflag &= ~ISTRIP; |
---|
| 169 | tcsetattr(0, TCSAFLUSH, &tio); |
---|
| 170 | |
---|
[7d4fbcd] | 171 | /* screen init */ |
---|
[b20de4f] | 172 | if (!getenv("TERMINFO")) { |
---|
[18e28a4] | 173 | owl_function_debugmsg("startup: Not setting TERMINFO"); |
---|
[b20de4f] | 174 | } else { |
---|
| 175 | owl_function_debugmsg("startup: leaving TERMINFO as %s from envrionment", getenv("TERMINFO")); |
---|
| 176 | } |
---|
[7d4fbcd] | 177 | initscr(); |
---|
| 178 | start_color(); |
---|
[ac70242] | 179 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
[7d4fbcd] | 180 | use_default_colors(); |
---|
[ac70242] | 181 | #endif |
---|
[7d4fbcd] | 182 | raw(); |
---|
| 183 | noecho(); |
---|
| 184 | |
---|
| 185 | /* define simple color pairs */ |
---|
| 186 | if (has_colors() && COLOR_PAIRS>=8) { |
---|
[8fa9562] | 187 | int bg = COLOR_BLACK; |
---|
| 188 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
| 189 | bg = -1; |
---|
| 190 | #endif |
---|
| 191 | init_pair(OWL_COLOR_BLACK, COLOR_BLACK, bg); |
---|
| 192 | init_pair(OWL_COLOR_RED, COLOR_RED, bg); |
---|
| 193 | init_pair(OWL_COLOR_GREEN, COLOR_GREEN, bg); |
---|
| 194 | init_pair(OWL_COLOR_YELLOW, COLOR_YELLOW, bg); |
---|
| 195 | init_pair(OWL_COLOR_BLUE, COLOR_BLUE, bg); |
---|
| 196 | init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, bg); |
---|
| 197 | init_pair(OWL_COLOR_CYAN, COLOR_CYAN, bg); |
---|
| 198 | init_pair(OWL_COLOR_WHITE, COLOR_WHITE, bg); |
---|
[7d4fbcd] | 199 | } |
---|
[38cf544c] | 200 | |
---|
[bd3f232] | 201 | /* owl global init */ |
---|
[7d4fbcd] | 202 | owl_global_init(&g); |
---|
[b363d83] | 203 | if (debug) owl_global_set_debug_on(&g); |
---|
| 204 | if (confdir) owl_global_set_confdir(&g, confdir); |
---|
[b20de4f] | 205 | owl_function_debugmsg("startup: first available debugging message"); |
---|
[7d4fbcd] | 206 | owl_global_set_startupargs(&g, argcsave, argvsave); |
---|
[09489b89] | 207 | owl_global_set_haveaim(&g); |
---|
[2a2bb60] | 208 | |
---|
[9c7a701] | 209 | /* prepare stdin dispatch */ |
---|
| 210 | { |
---|
| 211 | owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); |
---|
[4cc0ee0b] | 212 | d->fd = fileno(stdin); |
---|
[9c7a701] | 213 | d->cfunc = &owl_process_input; |
---|
| 214 | d->pfunc = NULL; |
---|
| 215 | owl_select_add_dispatch(d); |
---|
| 216 | } |
---|
| 217 | |
---|
[596c22df] | 218 | #ifdef HAVE_LIBZEPHYR |
---|
| 219 | /* zephyr init */ |
---|
| 220 | ret=owl_zephyr_initialize(); |
---|
[9c7a701] | 221 | if (!ret) { |
---|
| 222 | owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); |
---|
| 223 | d->fd = ZGetFD(); |
---|
| 224 | d->cfunc = &owl_zephyr_process_events; |
---|
| 225 | d->pfunc = NULL; |
---|
| 226 | owl_select_add_dispatch(d); |
---|
| 227 | owl_global_set_havezephyr(&g); |
---|
| 228 | } |
---|
| 229 | |
---|
[596c22df] | 230 | #endif |
---|
| 231 | |
---|
[2a2bb60] | 232 | #if OWL_STDERR_REDIR |
---|
[a0a5179] | 233 | /* Do this only after we've started curses up... */ |
---|
| 234 | owl_function_debugmsg("startup: doing stderr redirection"); |
---|
[2a2bb60] | 235 | newstderr = stderr_replace(); |
---|
[afbf668] | 236 | owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ, |
---|
| 237 | stderr_redirect_handler, NULL); |
---|
[2a2bb60] | 238 | #endif |
---|
| 239 | |
---|
[38cf544c] | 240 | /* create the owl directory, in case it does not exist */ |
---|
[a0a5179] | 241 | owl_function_debugmsg("startup: creating owl directory, if not present"); |
---|
[b363d83] | 242 | dir=owl_global_get_confdir(&g); |
---|
[38cf544c] | 243 | mkdir(dir, S_IRWXU); |
---|
[5145235] | 244 | |
---|
[ced25d1] | 245 | /* set the tty, either from the command line, or by figuring it out */ |
---|
[a0a5179] | 246 | owl_function_debugmsg("startup: setting tty name"); |
---|
[61e79a9] | 247 | if (tty) { |
---|
| 248 | owl_global_set_tty(&g, tty); |
---|
| 249 | } else { |
---|
| 250 | owl_global_set_tty(&g, owl_util_get_default_tty()); |
---|
| 251 | } |
---|
[7d4fbcd] | 252 | |
---|
[b6c067a] | 253 | /* Initialize perl */ |
---|
| 254 | owl_function_debugmsg("startup: processing config file"); |
---|
| 255 | owl_context_set_readconfig(owl_global_get_context(&g)); |
---|
| 256 | perlerr=owl_perlconfig_initperl(configfile); |
---|
| 257 | if (perlerr) { |
---|
| 258 | endwin(); |
---|
| 259 | owl_function_error("Internal perl error: %s\n", perlerr); |
---|
| 260 | fprintf(stderr, "Internal perl error: %s\n", perlerr); |
---|
| 261 | fflush(stderr); |
---|
| 262 | printf("Internal perl error: %s\n", perlerr); |
---|
| 263 | fflush(stdout); |
---|
| 264 | exit(1); |
---|
| 265 | } |
---|
| 266 | |
---|
[7d4fbcd] | 267 | /* setup the default filters */ |
---|
[3abf28b] | 268 | /* the personal filter will need to change again when AIM chat's are |
---|
| 269 | * included. Also, there should be an %aimme% */ |
---|
[a0a5179] | 270 | owl_function_debugmsg("startup: creating default filters"); |
---|
[bd3f232] | 271 | f=owl_malloc(sizeof(owl_filter)); |
---|
[095e717] | 272 | owl_filter_init_fromstring(f, "personal", "isprivate ^true$ and ( not type ^zephyr$" |
---|
| 273 | " or ( class ^message and" |
---|
| 274 | " ( instance ^personal$ or instance ^urgent$ ) ) )"); |
---|
[7d4fbcd] | 275 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 276 | |
---|
[bd3f232] | 277 | f=owl_malloc(sizeof(owl_filter)); |
---|
[fa86732] | 278 | owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) "); |
---|
| 279 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 280 | |
---|
| 281 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 282 | owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )"); |
---|
[7d4fbcd] | 283 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 284 | |
---|
[bd3f232] | 285 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 286 | owl_filter_init_fromstring(f, "ping", "opcode ^ping$"); |
---|
| 287 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 288 | |
---|
[bd3f232] | 289 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 290 | owl_filter_init_fromstring(f, "auto", "opcode ^auto$"); |
---|
| 291 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 292 | |
---|
[bd3f232] | 293 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 294 | owl_filter_init_fromstring(f, "login", "not login ^none$"); |
---|
[0236842] | 295 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 296 | |
---|
[bd3f232] | 297 | f=owl_malloc(sizeof(owl_filter)); |
---|
[7d4fbcd] | 298 | owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$"); |
---|
| 299 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 300 | |
---|
[bd3f232] | 301 | f=owl_malloc(sizeof(owl_filter)); |
---|
[5a6e6b9] | 302 | owl_filter_init_fromstring(f, "out", "direction ^out$"); |
---|
| 303 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 304 | |
---|
[bd3f232] | 305 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 306 | owl_filter_init_fromstring(f, "aim", "type ^aim$"); |
---|
| 307 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 308 | |
---|
[bd3f232] | 309 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 310 | owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$"); |
---|
| 311 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 312 | |
---|
[bd3f232] | 313 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 314 | owl_filter_init_fromstring(f, "none", "false"); |
---|
| 315 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 316 | |
---|
[bd3f232] | 317 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 318 | owl_filter_init_fromstring(f, "all", "true"); |
---|
[7d4fbcd] | 319 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 320 | |
---|
| 321 | /* set the current view */ |
---|
[a0a5179] | 322 | owl_function_debugmsg("startup: setting the current view"); |
---|
[c3ab155] | 323 | owl_view_create(owl_global_get_current_view(&g), "main", f, owl_global_get_style_by_name(&g, "default")); |
---|
[7d4fbcd] | 324 | |
---|
[96f8e5b] | 325 | /* AIM init */ |
---|
[a0a5179] | 326 | owl_function_debugmsg("startup: doing AIM initialization"); |
---|
[96f8e5b] | 327 | owl_aim_init(); |
---|
| 328 | |
---|
[ced25d1] | 329 | /* execute the startup function in the configfile */ |
---|
[a0a5179] | 330 | owl_function_debugmsg("startup: executing perl startup, if applicable"); |
---|
[0337203] | 331 | perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); |
---|
[7d4fbcd] | 332 | if (perlout) owl_free(perlout); |
---|
[212764e] | 333 | |
---|
[7d4fbcd] | 334 | /* hold on to the window names for convenience */ |
---|
| 335 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 336 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 337 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 338 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 339 | tw=owl_global_get_typwin(&g); |
---|
| 340 | |
---|
[252a5c2] | 341 | /* welcome message */ |
---|
[a0a5179] | 342 | owl_function_debugmsg("startup: creating splash message"); |
---|
[52f3507] | 343 | strcpy(startupmsg, "-----------------------------------------------------------------------\n"); |
---|
[c2c5c77] | 344 | sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING); |
---|
[252a5c2] | 345 | strcat(startupmsg, buff); |
---|
[52f3507] | 346 | strcat(startupmsg, " \n"); |
---|
[c2c5c77] | 347 | strcat(startupmsg, "This is a development build of barnowl. If you are using this \n"); |
---|
| 348 | strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu \n"); |
---|
[52f3507] | 349 | strcat(startupmsg, " ^ ^ \n"); |
---|
[e132a2d] | 350 | strcat(startupmsg, " OvO \n"); |
---|
[2058d7a] | 351 | strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu ( ) \n"); |
---|
[52f3507] | 352 | strcat(startupmsg, "-----------------------------------------------------------------m-m---\n"); |
---|
[252a5c2] | 353 | owl_function_adminmsg("", startupmsg); |
---|
| 354 | sepbar(NULL); |
---|
| 355 | |
---|
[687c674] | 356 | /* process the startup file */ |
---|
| 357 | owl_function_debugmsg("startup: processing startup file"); |
---|
| 358 | owl_function_source(NULL); |
---|
| 359 | |
---|
[7d4fbcd] | 360 | wrefresh(sepwin); |
---|
| 361 | |
---|
| 362 | /* load zephyr subs */ |
---|
[bd3f232] | 363 | if (initialsubs) { |
---|
[4357be8] | 364 | int ret2; |
---|
[a0a5179] | 365 | owl_function_debugmsg("startup: loading initial zephyr subs"); |
---|
[4357be8] | 366 | |
---|
| 367 | /* load default subscriptions */ |
---|
| 368 | ret=owl_zephyr_loaddefaultsubs(); |
---|
[252a5c2] | 369 | |
---|
[4357be8] | 370 | /* load subscriptions from subs file */ |
---|
[95474d7] | 371 | ret2=owl_zephyr_loadsubs(NULL, 0); |
---|
[4357be8] | 372 | |
---|
| 373 | if (ret || ret2) { |
---|
| 374 | owl_function_adminmsg("", "Error loading zephyr subscriptions"); |
---|
| 375 | } else if (ret2!=-1) { |
---|
[bd3f232] | 376 | owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES); |
---|
| 377 | } |
---|
[7d4fbcd] | 378 | |
---|
[bd3f232] | 379 | /* load login subscriptions */ |
---|
| 380 | if (owl_global_is_loginsubs(&g)) { |
---|
[a0a5179] | 381 | owl_function_debugmsg("startup: loading login subs"); |
---|
[bd3f232] | 382 | owl_function_loadloginsubs(NULL); |
---|
| 383 | } |
---|
[7d4fbcd] | 384 | } |
---|
| 385 | |
---|
[5a95b69] | 386 | /* First buddy check to sync the list without notifications */ |
---|
| 387 | owl_function_debugmsg("startup: doing initial zephyr buddy check"); |
---|
[4357be8] | 388 | /* owl_function_zephyr_buddy_check(0); */ |
---|
[5a95b69] | 389 | |
---|
[f933403] | 390 | /* set the startup and default style, based on userclue and presence of a |
---|
| 391 | * formatting function */ |
---|
[a0a5179] | 392 | owl_function_debugmsg("startup: setting startup and default style"); |
---|
[27c3a93] | 393 | if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) { |
---|
| 394 | /* the style was set by the user: leave it alone */ |
---|
| 395 | } else if (owl_global_is_config_format(&g)) { |
---|
[f933403] | 396 | owl_global_set_default_style(&g, "perl"); |
---|
| 397 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 398 | owl_global_set_default_style(&g, "default"); |
---|
| 399 | } else { |
---|
| 400 | owl_global_set_default_style(&g, "basic"); |
---|
| 401 | } |
---|
| 402 | |
---|
[7d4fbcd] | 403 | /* zlog in if we need to */ |
---|
| 404 | if (owl_global_is_startuplogin(&g)) { |
---|
[a0a5179] | 405 | owl_function_debugmsg("startup: doing zlog in"); |
---|
[31e48a3] | 406 | owl_zephyr_zlog_in(); |
---|
[7d4fbcd] | 407 | } |
---|
| 408 | |
---|
[39dc159] | 409 | owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g)); |
---|
[72c210f] | 410 | s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)); |
---|
| 411 | if(s) |
---|
| 412 | owl_view_set_style(owl_global_get_current_view(&g), s); |
---|
| 413 | else |
---|
| 414 | owl_function_error("No such style: %s", owl_global_get_default_style(&g)); |
---|
[a0a5179] | 415 | |
---|
| 416 | owl_function_debugmsg("startup: setting context interactive"); |
---|
[7d4fbcd] | 417 | owl_context_set_interactive(owl_global_get_context(&g)); |
---|
| 418 | |
---|
[a15a84f] | 419 | nexttimediff=10; |
---|
[4b464a4] | 420 | nexttime=time(NULL); |
---|
| 421 | |
---|
[c0c4449c] | 422 | #ifdef HAVE_LIBZEPHYR |
---|
| 423 | /* Check for any zephyrs that have come in while we've done init. */ |
---|
| 424 | owl_zephyr_process_events(); |
---|
| 425 | #endif |
---|
| 426 | |
---|
[a0a5179] | 427 | owl_function_debugmsg("startup: entering main loop"); |
---|
[7d4fbcd] | 428 | /* main loop */ |
---|
| 429 | while (1) { |
---|
| 430 | |
---|
| 431 | /* if a resize has been scheduled, deal with it */ |
---|
| 432 | owl_global_resize(&g, 0, 0); |
---|
| 433 | |
---|
| 434 | /* these are here in case a resize changes the windows */ |
---|
| 435 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 436 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 437 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 438 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 439 | |
---|
| 440 | followlast=owl_global_should_followlast(&g); |
---|
[5789230] | 441 | |
---|
[8203afd] | 442 | owl_perlconfig_mainloop(); |
---|
[bc220b2] | 443 | |
---|
[4b464a4] | 444 | /* little hack */ |
---|
[a15a84f] | 445 | now=time(NULL); |
---|
| 446 | today=localtime(&now); |
---|
| 447 | if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) { |
---|
[4b464a4] | 448 | if (time(NULL)>nexttime) { |
---|
| 449 | if (nexttimediff==1) { |
---|
[a15a84f] | 450 | nexttimediff=10; |
---|
[4b464a4] | 451 | } else { |
---|
| 452 | nexttimediff=1; |
---|
| 453 | } |
---|
| 454 | nexttime+=nexttimediff; |
---|
| 455 | owl_hack_animate(); |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | |
---|
[aac889a] | 459 | /* Grab incoming messages. */ |
---|
[d09e5a1] | 460 | newmsgs=0; |
---|
[13a3c1db] | 461 | while(owl_global_messagequeue_pending(&g)) { |
---|
[5a95b69] | 462 | |
---|
[13a3c1db] | 463 | m = owl_global_messagequeue_popmsg(&g); |
---|
[7d4fbcd] | 464 | |
---|
[13a3c1db] | 465 | if(owl_process_message(m)) |
---|
| 466 | newmsgs = 1; |
---|
[7d4fbcd] | 467 | } |
---|
| 468 | |
---|
[5a95b69] | 469 | /* is it time to check zbuddies? */ |
---|
| 470 | if (owl_global_is_pseudologins(&g)) { |
---|
| 471 | if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) { |
---|
| 472 | owl_function_debugmsg("Doing zephyr buddy check"); |
---|
| 473 | owl_function_zephyr_buddy_check(1); |
---|
| 474 | owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g)); |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
[afbf668] | 478 | /* dispatch any muxevents */ |
---|
| 479 | owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0); |
---|
| 480 | |
---|
[7d4fbcd] | 481 | /* follow the last message if we're supposed to */ |
---|
[d09e5a1] | 482 | if (newmsgs && followlast) { |
---|
[7d4fbcd] | 483 | owl_function_lastmsg_noredisplay(); |
---|
| 484 | } |
---|
[700c712] | 485 | |
---|
[ced25d1] | 486 | /* do the newmsgproc thing */ |
---|
[d09e5a1] | 487 | if (newmsgs) { |
---|
[8f44c6b] | 488 | owl_function_do_newmsgproc(); |
---|
[700c712] | 489 | } |
---|
[7d4fbcd] | 490 | |
---|
| 491 | /* redisplay if necessary */ |
---|
[d09e5a1] | 492 | /* this should be optimized to not run if the new messages won't be displayed */ |
---|
| 493 | if (newmsgs) { |
---|
[7d4fbcd] | 494 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 495 | sepbar(NULL); |
---|
| 496 | if (owl_popwin_is_active(owl_global_get_popwin(&g))) { |
---|
| 497 | owl_popwin_refresh(owl_global_get_popwin(&g)); |
---|
| 498 | /* TODO: this is a broken kludge */ |
---|
| 499 | if (owl_global_get_viewwin(&g)) { |
---|
| 500 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | owl_global_set_needrefresh(&g); |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | /* if a popwin just came up, refresh it */ |
---|
| 507 | pw=owl_global_get_popwin(&g); |
---|
| 508 | if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) { |
---|
| 509 | owl_popwin_refresh(pw); |
---|
| 510 | owl_popwin_no_needs_first_refresh(pw); |
---|
| 511 | owl_global_set_needrefresh(&g); |
---|
| 512 | /* TODO: this is a broken kludge */ |
---|
| 513 | if (owl_global_get_viewwin(&g)) { |
---|
| 514 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | /* update the terminal if we need to */ |
---|
| 519 | if (owl_global_is_needrefresh(&g)) { |
---|
| 520 | /* leave the cursor in the appropriate window */ |
---|
| 521 | if (owl_global_is_typwin_active(&g)) { |
---|
| 522 | owl_function_set_cursor(typwin); |
---|
| 523 | } else { |
---|
| 524 | owl_function_set_cursor(sepwin); |
---|
| 525 | } |
---|
[4cc0ee0b] | 526 | owl_function_debugmsg("owl.c -- doupdate()"); |
---|
[7d4fbcd] | 527 | doupdate(); |
---|
| 528 | owl_global_set_noneedrefresh(&g); |
---|
| 529 | } |
---|
| 530 | |
---|
[bd3f232] | 531 | /* Handle all keypresses. If no key has been pressed, sleep for a |
---|
| 532 | * little bit, but otherwise do not. This lets input be grabbed |
---|
| 533 | * as quickly as possbile */ |
---|
[9c7a701] | 534 | |
---|
| 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 | { |
---|
| 670 | int ret, j; |
---|
| 671 | owl_popwin *pw; |
---|
| 672 | owl_editwin *tw; |
---|
| 673 | |
---|
[4cc0ee0b] | 674 | while (1) { |
---|
| 675 | j = wgetch(owl_global_get_curs_typwin(&g)); |
---|
| 676 | if (j == ERR) return; |
---|
[9c7a701] | 677 | |
---|
[4cc0ee0b] | 678 | owl_global_set_lastinputtime(&g, time(NULL)); |
---|
| 679 | pw=owl_global_get_popwin(&g); |
---|
| 680 | tw=owl_global_get_typwin(&g); |
---|
| 681 | |
---|
| 682 | /* find and activate the current keymap. |
---|
| 683 | * TODO: this should really get fixed by activating |
---|
| 684 | * keymaps as we switch between windows... |
---|
| 685 | */ |
---|
| 686 | if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) { |
---|
| 687 | owl_context_set_popless(owl_global_get_context(&g), |
---|
| 688 | owl_global_get_viewwin(&g)); |
---|
| 689 | owl_function_activate_keymap("popless"); |
---|
| 690 | } else if (owl_global_is_typwin_active(&g) |
---|
| 691 | && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_ONELINE) { |
---|
| 692 | /* |
---|
| 693 | owl_context_set_editline(owl_global_get_context(&g), tw); |
---|
| 694 | owl_function_activate_keymap("editline"); |
---|
| 695 | */ |
---|
| 696 | } else if (owl_global_is_typwin_active(&g) |
---|
| 697 | && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_MULTILINE) { |
---|
| 698 | owl_context_set_editmulti(owl_global_get_context(&g), tw); |
---|
| 699 | owl_function_activate_keymap("editmulti"); |
---|
| 700 | } else { |
---|
| 701 | owl_context_set_recv(owl_global_get_context(&g)); |
---|
| 702 | owl_function_activate_keymap("recv"); |
---|
| 703 | } |
---|
| 704 | /* now actually handle the keypress */ |
---|
| 705 | ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); |
---|
| 706 | if (ret != 0 && ret != 1) { |
---|
| 707 | owl_function_makemsg("Unable to handle keypress"); |
---|
| 708 | } |
---|
[9c7a701] | 709 | } |
---|
| 710 | } |
---|
| 711 | |
---|
[de22c3d] | 712 | void sig_handler(int sig, siginfo_t *si, void *data) |
---|
| 713 | { |
---|
[7d4fbcd] | 714 | if (sig==SIGWINCH) { |
---|
[bd3f232] | 715 | /* we can't inturrupt a malloc here, so it just sets a flag |
---|
| 716 | * schedulding a resize for later |
---|
| 717 | */ |
---|
[7d4fbcd] | 718 | owl_function_resize(); |
---|
[afbf668] | 719 | } else if (sig==SIGPIPE || sig==SIGCHLD) { |
---|
[c9e72d1] | 720 | /* Set a flag and some info that we got the sigpipe |
---|
| 721 | * so we can record that we got it and why... */ |
---|
| 722 | owl_global_set_errsignal(&g, sig, si); |
---|
[fe1f605] | 723 | } else if (sig==SIGTERM || sig==SIGHUP) { |
---|
| 724 | owl_function_quit(); |
---|
[7d4fbcd] | 725 | } |
---|
| 726 | } |
---|
| 727 | |
---|
[de22c3d] | 728 | void usage() |
---|
| 729 | { |
---|
[78667f3] | 730 | fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING); |
---|
| 731 | fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n"); |
---|
[e7cc1c3] | 732 | fprintf(stderr, " -n don't load zephyr subscriptions\n"); |
---|
| 733 | fprintf(stderr, " -d enable debugging\n"); |
---|
[a68f05d] | 734 | fprintf(stderr, " -D enable debugging and delete previous debug file\n"); |
---|
[78667f3] | 735 | fprintf(stderr, " -v print the Barnowl version number and exit\n"); |
---|
[e7cc1c3] | 736 | fprintf(stderr, " -h print this help message\n"); |
---|
| 737 | fprintf(stderr, " -c specify an alternate config file\n"); |
---|
[b363d83] | 738 | fprintf(stderr, " -s specify an alternate config dir (default ~/.owl)\n"); |
---|
[e7cc1c3] | 739 | fprintf(stderr, " -t set the tty name\n"); |
---|
[7d4fbcd] | 740 | } |
---|
[2a2bb60] | 741 | |
---|
| 742 | #if OWL_STDERR_REDIR |
---|
| 743 | |
---|
| 744 | /* Replaces stderr with a pipe so that we can read from it. |
---|
| 745 | * Returns the fd of the pipe from which stderr can be read. */ |
---|
[de22c3d] | 746 | int stderr_replace(void) |
---|
| 747 | { |
---|
[2a2bb60] | 748 | int pipefds[2]; |
---|
| 749 | if (0 != pipe(pipefds)) { |
---|
| 750 | perror("pipe"); |
---|
| 751 | owl_function_debugmsg("stderr_replace: pipe FAILED\n"); |
---|
| 752 | return -1; |
---|
| 753 | } |
---|
| 754 | owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]); |
---|
| 755 | if (-1 == dup2(pipefds[1], 2 /*stderr*/)) { |
---|
| 756 | owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno)); |
---|
| 757 | perror("dup2"); |
---|
| 758 | return -1; |
---|
| 759 | } |
---|
| 760 | return pipefds[0]; |
---|
| 761 | } |
---|
| 762 | |
---|
[afbf668] | 763 | /* Sends stderr (read from rfd) messages to the error console */ |
---|
| 764 | void stderr_redirect_handler(int handle, int rfd, int eventmask, void *data) |
---|
[de22c3d] | 765 | { |
---|
[2a2bb60] | 766 | int navail, bread; |
---|
| 767 | char *buf; |
---|
| 768 | /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/ |
---|
| 769 | if (rfd<0) return; |
---|
| 770 | if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) { |
---|
| 771 | return; |
---|
| 772 | } |
---|
| 773 | /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/ |
---|
| 774 | if (navail<=0) return; |
---|
| 775 | if (navail>256) { navail = 256; } |
---|
| 776 | buf = owl_malloc(navail+1); |
---|
| 777 | bread = read(rfd, buf, navail); |
---|
| 778 | if (buf[navail-1] != '\0') { |
---|
| 779 | buf[navail] = '\0'; |
---|
| 780 | } |
---|
| 781 | owl_function_error("Err: %s", buf); |
---|
| 782 | owl_free(buf); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | #endif /* OWL_STDERR_REDIR */ |
---|