[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> |
---|
[8232149] | 48 | #include <termios.h> |
---|
[38cf544c] | 49 | #include <sys/stat.h> |
---|
[7d4fbcd] | 50 | #include "owl.h" |
---|
| 51 | |
---|
[2a2bb60] | 52 | #if OWL_STDERR_REDIR |
---|
[e8b95f8] | 53 | #ifdef HAVE_SYS_IOCTL_H |
---|
[2a2bb60] | 54 | #include <sys/ioctl.h> |
---|
[e8b95f8] | 55 | #endif |
---|
| 56 | #ifdef HAVE_SYS_FILIO_H |
---|
| 57 | #include <sys/filio.h> |
---|
| 58 | #endif |
---|
[2a2bb60] | 59 | int stderr_replace(void); |
---|
| 60 | #endif |
---|
| 61 | |
---|
[1aee7d9] | 62 | static const char fileIdent[] = "$Id$"; |
---|
| 63 | |
---|
[b2b0773] | 64 | owl_global g; |
---|
| 65 | |
---|
[de22c3d] | 66 | int main(int argc, char **argv, char **env) |
---|
| 67 | { |
---|
[7d4fbcd] | 68 | WINDOW *recwin, *sepwin, *typwin, *msgwin; |
---|
| 69 | owl_editwin *tw; |
---|
| 70 | owl_popwin *pw; |
---|
[ced25d1] | 71 | int j, ret, initialsubs, debug, argcsave, followlast; |
---|
[d09e5a1] | 72 | int newmsgs, zpendcount, nexttimediff; |
---|
[7d4fbcd] | 73 | struct sigaction sigact; |
---|
[2fa15f0] | 74 | char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE]; |
---|
[7d4fbcd] | 75 | owl_filter *f; |
---|
[bd3f232] | 76 | owl_style *s; |
---|
[a15a84f] | 77 | time_t nexttime, now; |
---|
| 78 | struct tm *today; |
---|
[38cf544c] | 79 | char *dir; |
---|
[8232149] | 80 | struct termios tio; |
---|
[09489b89] | 81 | #ifdef HAVE_LIBZEPHYR |
---|
[be0a79f] | 82 | ZNotice_t notice; |
---|
[09489b89] | 83 | #endif |
---|
[2a2bb60] | 84 | #if OWL_STDERR_REDIR |
---|
| 85 | int newstderr; |
---|
| 86 | #endif |
---|
[7d4fbcd] | 87 | |
---|
| 88 | argcsave=argc; |
---|
| 89 | argvsave=argv; |
---|
| 90 | configfile=NULL; |
---|
| 91 | tty=NULL; |
---|
| 92 | debug=0; |
---|
[bd3f232] | 93 | initialsubs=1; |
---|
[7d4fbcd] | 94 | if (argc>0) { |
---|
| 95 | argv++; |
---|
| 96 | argc--; |
---|
| 97 | } |
---|
| 98 | while (argc>0) { |
---|
| 99 | if (!strcmp(argv[0], "-n")) { |
---|
| 100 | initialsubs=0; |
---|
| 101 | argv++; |
---|
| 102 | argc--; |
---|
| 103 | } else if (!strcmp(argv[0], "-c")) { |
---|
| 104 | if (argc<2) { |
---|
| 105 | fprintf(stderr, "Too few arguments to -c\n"); |
---|
| 106 | usage(); |
---|
| 107 | exit(1); |
---|
| 108 | } |
---|
| 109 | configfile=argv[1]; |
---|
| 110 | argv+=2; |
---|
| 111 | argc-=2; |
---|
| 112 | } else if (!strcmp(argv[0], "-t")) { |
---|
| 113 | if (argc<2) { |
---|
| 114 | fprintf(stderr, "Too few arguments to -t\n"); |
---|
| 115 | usage(); |
---|
| 116 | exit(1); |
---|
| 117 | } |
---|
| 118 | tty=argv[1]; |
---|
| 119 | argv+=2; |
---|
| 120 | argc-=2; |
---|
| 121 | } else if (!strcmp(argv[0], "-d")) { |
---|
| 122 | debug=1; |
---|
| 123 | argv++; |
---|
| 124 | argc--; |
---|
[a68f05d] | 125 | } else if (!strcmp(argv[0], "-D")) { |
---|
| 126 | debug=1; |
---|
| 127 | unlink(OWL_DEBUG_FILE); |
---|
| 128 | argv++; |
---|
| 129 | argc--; |
---|
[7d4fbcd] | 130 | } else if (!strcmp(argv[0], "-v")) { |
---|
| 131 | printf("This is owl version %s\n", OWL_VERSION_STRING); |
---|
| 132 | exit(0); |
---|
| 133 | } else { |
---|
| 134 | fprintf(stderr, "Uknown argument\n"); |
---|
| 135 | usage(); |
---|
| 136 | exit(1); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
[176d3443] | 140 | owl_function_debugmsg("startup: Finished parsing arguments"); |
---|
| 141 | |
---|
[7d4fbcd] | 142 | /* signal handler */ |
---|
[c9e72d1] | 143 | /*sigact.sa_handler=sig_handler;*/ |
---|
| 144 | sigact.sa_sigaction=sig_handler; |
---|
[7d4fbcd] | 145 | sigemptyset(&sigact.sa_mask); |
---|
[c9e72d1] | 146 | sigact.sa_flags=SA_SIGINFO; |
---|
[7d4fbcd] | 147 | sigaction(SIGWINCH, &sigact, NULL); |
---|
| 148 | sigaction(SIGALRM, &sigact, NULL); |
---|
[c9e72d1] | 149 | sigaction(SIGPIPE, &sigact, NULL); |
---|
[fe1f605] | 150 | sigaction(SIGTERM, &sigact, NULL); |
---|
| 151 | sigaction(SIGHUP, &sigact, NULL); |
---|
[7d4fbcd] | 152 | |
---|
[8232149] | 153 | /* save initial terminal settings */ |
---|
| 154 | tcgetattr(0, owl_global_get_startup_tio(&g)); |
---|
| 155 | |
---|
| 156 | /* turn ISTRIP off */ |
---|
| 157 | tcgetattr(0, &tio); |
---|
| 158 | tio.c_iflag &= ~ISTRIP; |
---|
| 159 | tcsetattr(0, TCSAFLUSH, &tio); |
---|
| 160 | |
---|
[7d4fbcd] | 161 | /* screen init */ |
---|
[b20de4f] | 162 | if (!getenv("TERMINFO")) { |
---|
| 163 | sprintf(buff, "TERMINFO=%s", TERMINFO); |
---|
| 164 | putenv(buff); |
---|
| 165 | owl_function_debugmsg("startup: setting TERMINFO to %s", TERMINFO); |
---|
| 166 | } else { |
---|
| 167 | owl_function_debugmsg("startup: leaving TERMINFO as %s from envrionment", getenv("TERMINFO")); |
---|
| 168 | } |
---|
[7d4fbcd] | 169 | initscr(); |
---|
| 170 | start_color(); |
---|
[ac70242] | 171 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
[7d4fbcd] | 172 | use_default_colors(); |
---|
[ac70242] | 173 | #endif |
---|
[7d4fbcd] | 174 | raw(); |
---|
| 175 | noecho(); |
---|
| 176 | |
---|
| 177 | /* define simple color pairs */ |
---|
| 178 | if (has_colors() && COLOR_PAIRS>=8) { |
---|
[8fa9562] | 179 | int bg = COLOR_BLACK; |
---|
| 180 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
| 181 | bg = -1; |
---|
| 182 | #endif |
---|
| 183 | init_pair(OWL_COLOR_BLACK, COLOR_BLACK, bg); |
---|
| 184 | init_pair(OWL_COLOR_RED, COLOR_RED, bg); |
---|
| 185 | init_pair(OWL_COLOR_GREEN, COLOR_GREEN, bg); |
---|
| 186 | init_pair(OWL_COLOR_YELLOW, COLOR_YELLOW, bg); |
---|
| 187 | init_pair(OWL_COLOR_BLUE, COLOR_BLUE, bg); |
---|
| 188 | init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, bg); |
---|
| 189 | init_pair(OWL_COLOR_CYAN, COLOR_CYAN, bg); |
---|
| 190 | init_pair(OWL_COLOR_WHITE, COLOR_WHITE, bg); |
---|
[7d4fbcd] | 191 | } |
---|
[38cf544c] | 192 | |
---|
[bd3f232] | 193 | /* owl global init */ |
---|
[7d4fbcd] | 194 | owl_global_init(&g); |
---|
[cb769bb] | 195 | if (debug) owl_global_set_debug_on(&g); |
---|
[b20de4f] | 196 | owl_function_debugmsg("startup: first available debugging message"); |
---|
[7d4fbcd] | 197 | owl_global_set_startupargs(&g, argcsave, argvsave); |
---|
[09489b89] | 198 | owl_global_set_haveaim(&g); |
---|
[2a2bb60] | 199 | |
---|
[596c22df] | 200 | #ifdef HAVE_LIBZEPHYR |
---|
| 201 | /* zephyr init */ |
---|
| 202 | ret=owl_zephyr_initialize(); |
---|
| 203 | if (!ret) |
---|
| 204 | owl_global_set_havezephyr(&g); |
---|
| 205 | #endif |
---|
| 206 | |
---|
[2a2bb60] | 207 | #if OWL_STDERR_REDIR |
---|
[a0a5179] | 208 | /* Do this only after we've started curses up... */ |
---|
| 209 | owl_function_debugmsg("startup: doing stderr redirection"); |
---|
[2a2bb60] | 210 | newstderr = stderr_replace(); |
---|
[afbf668] | 211 | owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ, |
---|
| 212 | stderr_redirect_handler, NULL); |
---|
[2a2bb60] | 213 | #endif |
---|
| 214 | |
---|
[38cf544c] | 215 | /* create the owl directory, in case it does not exist */ |
---|
[a0a5179] | 216 | owl_function_debugmsg("startup: creating owl directory, if not present"); |
---|
[38cf544c] | 217 | dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR); |
---|
| 218 | mkdir(dir, S_IRWXU); |
---|
| 219 | owl_free(dir); |
---|
[5145235] | 220 | |
---|
[ced25d1] | 221 | /* set the tty, either from the command line, or by figuring it out */ |
---|
[a0a5179] | 222 | owl_function_debugmsg("startup: setting tty name"); |
---|
[61e79a9] | 223 | if (tty) { |
---|
| 224 | owl_global_set_tty(&g, tty); |
---|
| 225 | } else { |
---|
| 226 | owl_global_set_tty(&g, owl_util_get_default_tty()); |
---|
| 227 | } |
---|
[7d4fbcd] | 228 | |
---|
[b6c067a] | 229 | /* Initialize perl */ |
---|
| 230 | owl_function_debugmsg("startup: processing config file"); |
---|
| 231 | owl_context_set_readconfig(owl_global_get_context(&g)); |
---|
| 232 | perlerr=owl_perlconfig_initperl(configfile); |
---|
| 233 | if (perlerr) { |
---|
| 234 | endwin(); |
---|
| 235 | owl_function_error("Internal perl error: %s\n", perlerr); |
---|
| 236 | fprintf(stderr, "Internal perl error: %s\n", perlerr); |
---|
| 237 | fflush(stderr); |
---|
| 238 | printf("Internal perl error: %s\n", perlerr); |
---|
| 239 | fflush(stdout); |
---|
| 240 | exit(1); |
---|
| 241 | } |
---|
| 242 | |
---|
[bd3f232] | 243 | /* setup the built-in styles */ |
---|
[a0a5179] | 244 | owl_function_debugmsg("startup: creating built-in styles"); |
---|
[bd3f232] | 245 | |
---|
| 246 | s=owl_malloc(sizeof(owl_style)); |
---|
[176d3443] | 247 | owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting."); |
---|
[bd3f232] | 248 | owl_global_add_style(&g, s); |
---|
[ec6ff52] | 249 | #if 0 |
---|
| 250 | s=owl_malloc(sizeof(owl_style)); |
---|
[176d3443] | 251 | owl_style_create_internal(s, "vt", &owl_stylefunc_vt, "VT message formatting."); |
---|
[ec6ff52] | 252 | owl_global_add_style(&g, s); |
---|
| 253 | #endif |
---|
[8b32593] | 254 | s=owl_malloc(sizeof(owl_style)); |
---|
[176d3443] | 255 | owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline, "Formats for one-line-per-message"); |
---|
[8b32593] | 256 | owl_global_add_style(&g, s); |
---|
| 257 | |
---|
[7d4fbcd] | 258 | /* setup the default filters */ |
---|
[3abf28b] | 259 | /* the personal filter will need to change again when AIM chat's are |
---|
| 260 | * included. Also, there should be an %aimme% */ |
---|
[a0a5179] | 261 | owl_function_debugmsg("startup: creating default filters"); |
---|
[bd3f232] | 262 | f=owl_malloc(sizeof(owl_filter)); |
---|
[312675c] | 263 | owl_filter_init_fromstring(f, "personal", "isprivate ^true$"); |
---|
[7d4fbcd] | 264 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 265 | |
---|
[bd3f232] | 266 | f=owl_malloc(sizeof(owl_filter)); |
---|
[fa86732] | 267 | owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) "); |
---|
| 268 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 269 | |
---|
| 270 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 271 | owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )"); |
---|
[7d4fbcd] | 272 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 273 | |
---|
[bd3f232] | 274 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 275 | owl_filter_init_fromstring(f, "ping", "opcode ^ping$"); |
---|
| 276 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 277 | |
---|
[bd3f232] | 278 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 279 | owl_filter_init_fromstring(f, "auto", "opcode ^auto$"); |
---|
| 280 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 281 | |
---|
[bd3f232] | 282 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 283 | owl_filter_init_fromstring(f, "login", "not login ^none$"); |
---|
[0236842] | 284 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 285 | |
---|
[bd3f232] | 286 | f=owl_malloc(sizeof(owl_filter)); |
---|
[7d4fbcd] | 287 | owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$"); |
---|
| 288 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 289 | |
---|
[bd3f232] | 290 | f=owl_malloc(sizeof(owl_filter)); |
---|
[5a6e6b9] | 291 | owl_filter_init_fromstring(f, "out", "direction ^out$"); |
---|
| 292 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 293 | |
---|
[bd3f232] | 294 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 295 | owl_filter_init_fromstring(f, "aim", "type ^aim$"); |
---|
| 296 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 297 | |
---|
[bd3f232] | 298 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 299 | owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$"); |
---|
| 300 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 301 | |
---|
[bd3f232] | 302 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 303 | owl_filter_init_fromstring(f, "none", "false"); |
---|
| 304 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 305 | |
---|
[bd3f232] | 306 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 307 | owl_filter_init_fromstring(f, "all", "true"); |
---|
[7d4fbcd] | 308 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 309 | |
---|
| 310 | /* set the current view */ |
---|
[a0a5179] | 311 | owl_function_debugmsg("startup: setting the current view"); |
---|
[c3ab155] | 312 | owl_view_create(owl_global_get_current_view(&g), "main", f, owl_global_get_style_by_name(&g, "default")); |
---|
[7d4fbcd] | 313 | |
---|
[96f8e5b] | 314 | /* AIM init */ |
---|
[a0a5179] | 315 | owl_function_debugmsg("startup: doing AIM initialization"); |
---|
[96f8e5b] | 316 | owl_aim_init(); |
---|
| 317 | |
---|
[ced25d1] | 318 | /* execute the startup function in the configfile */ |
---|
[a0a5179] | 319 | owl_function_debugmsg("startup: executing perl startup, if applicable"); |
---|
[0337203] | 320 | perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); |
---|
[7d4fbcd] | 321 | if (perlout) owl_free(perlout); |
---|
[212764e] | 322 | |
---|
[7d4fbcd] | 323 | /* hold on to the window names for convenience */ |
---|
| 324 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 325 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 326 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 327 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 328 | tw=owl_global_get_typwin(&g); |
---|
| 329 | |
---|
[252a5c2] | 330 | /* welcome message */ |
---|
[a0a5179] | 331 | owl_function_debugmsg("startup: creating splash message"); |
---|
[52f3507] | 332 | strcpy(startupmsg, "-----------------------------------------------------------------------\n"); |
---|
[c2c5c77] | 333 | sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING); |
---|
[252a5c2] | 334 | strcat(startupmsg, buff); |
---|
[52f3507] | 335 | strcat(startupmsg, " \n"); |
---|
[c2c5c77] | 336 | strcat(startupmsg, "This is a development build of barnowl. If you are using this \n"); |
---|
| 337 | strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu \n"); |
---|
[52f3507] | 338 | strcat(startupmsg, " ^ ^ \n"); |
---|
[e132a2d] | 339 | strcat(startupmsg, " OvO \n"); |
---|
[2058d7a] | 340 | strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu ( ) \n"); |
---|
[52f3507] | 341 | strcat(startupmsg, "-----------------------------------------------------------------m-m---\n"); |
---|
[252a5c2] | 342 | owl_function_adminmsg("", startupmsg); |
---|
| 343 | sepbar(NULL); |
---|
| 344 | |
---|
[687c674] | 345 | /* process the startup file */ |
---|
| 346 | owl_function_debugmsg("startup: processing startup file"); |
---|
| 347 | owl_function_source(NULL); |
---|
| 348 | |
---|
[7d4fbcd] | 349 | wrefresh(sepwin); |
---|
| 350 | |
---|
| 351 | /* load zephyr subs */ |
---|
[bd3f232] | 352 | if (initialsubs) { |
---|
[4357be8] | 353 | int ret2; |
---|
[a0a5179] | 354 | owl_function_debugmsg("startup: loading initial zephyr subs"); |
---|
[4357be8] | 355 | |
---|
| 356 | /* load default subscriptions */ |
---|
| 357 | ret=owl_zephyr_loaddefaultsubs(); |
---|
[252a5c2] | 358 | |
---|
[4357be8] | 359 | /* load subscriptions from subs file */ |
---|
[95474d7] | 360 | ret2=owl_zephyr_loadsubs(NULL, 0); |
---|
[4357be8] | 361 | |
---|
| 362 | if (ret || ret2) { |
---|
| 363 | owl_function_adminmsg("", "Error loading zephyr subscriptions"); |
---|
| 364 | } else if (ret2!=-1) { |
---|
[bd3f232] | 365 | owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES); |
---|
| 366 | } |
---|
[7d4fbcd] | 367 | |
---|
[bd3f232] | 368 | /* load login subscriptions */ |
---|
| 369 | if (owl_global_is_loginsubs(&g)) { |
---|
[a0a5179] | 370 | owl_function_debugmsg("startup: loading login subs"); |
---|
[bd3f232] | 371 | owl_function_loadloginsubs(NULL); |
---|
| 372 | } |
---|
[7d4fbcd] | 373 | } |
---|
| 374 | |
---|
[5a95b69] | 375 | /* First buddy check to sync the list without notifications */ |
---|
| 376 | owl_function_debugmsg("startup: doing initial zephyr buddy check"); |
---|
[4357be8] | 377 | /* owl_function_zephyr_buddy_check(0); */ |
---|
[5a95b69] | 378 | |
---|
[f933403] | 379 | /* set the startup and default style, based on userclue and presence of a |
---|
| 380 | * formatting function */ |
---|
[a0a5179] | 381 | owl_function_debugmsg("startup: setting startup and default style"); |
---|
[27c3a93] | 382 | if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) { |
---|
| 383 | /* the style was set by the user: leave it alone */ |
---|
| 384 | } else if (owl_global_is_config_format(&g)) { |
---|
[f933403] | 385 | owl_global_set_default_style(&g, "perl"); |
---|
| 386 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 387 | owl_global_set_default_style(&g, "default"); |
---|
| 388 | } else { |
---|
| 389 | owl_global_set_default_style(&g, "basic"); |
---|
| 390 | } |
---|
| 391 | |
---|
[7d4fbcd] | 392 | /* zlog in if we need to */ |
---|
| 393 | if (owl_global_is_startuplogin(&g)) { |
---|
[a0a5179] | 394 | owl_function_debugmsg("startup: doing zlog in"); |
---|
[31e48a3] | 395 | owl_zephyr_zlog_in(); |
---|
[7d4fbcd] | 396 | } |
---|
| 397 | |
---|
[39dc159] | 398 | owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g)); |
---|
[72c210f] | 399 | s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)); |
---|
| 400 | if(s) |
---|
| 401 | owl_view_set_style(owl_global_get_current_view(&g), s); |
---|
| 402 | else |
---|
| 403 | owl_function_error("No such style: %s", owl_global_get_default_style(&g)); |
---|
[a0a5179] | 404 | |
---|
| 405 | owl_function_debugmsg("startup: setting context interactive"); |
---|
[7d4fbcd] | 406 | owl_context_set_interactive(owl_global_get_context(&g)); |
---|
| 407 | |
---|
[a15a84f] | 408 | nexttimediff=10; |
---|
[4b464a4] | 409 | nexttime=time(NULL); |
---|
| 410 | |
---|
[a0a5179] | 411 | owl_function_debugmsg("startup: entering main loop"); |
---|
[7d4fbcd] | 412 | /* main loop */ |
---|
| 413 | while (1) { |
---|
| 414 | |
---|
| 415 | /* if a resize has been scheduled, deal with it */ |
---|
| 416 | owl_global_resize(&g, 0, 0); |
---|
| 417 | |
---|
| 418 | /* these are here in case a resize changes the windows */ |
---|
| 419 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 420 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 421 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 422 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 423 | |
---|
| 424 | followlast=owl_global_should_followlast(&g); |
---|
[5789230] | 425 | |
---|
[a352335c] | 426 | /* Do AIM stuff */ |
---|
| 427 | if (owl_global_is_doaimevents(&g)) { |
---|
[5789230] | 428 | owl_aim_process_events(); |
---|
[de03334] | 429 | |
---|
[a352335c] | 430 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 431 | if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) { |
---|
[f4d0975] | 432 | /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */ |
---|
[a352335c] | 433 | owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g)); |
---|
| 434 | } |
---|
[de03334] | 435 | } |
---|
[5789230] | 436 | } |
---|
| 437 | |
---|
[8203afd] | 438 | owl_perlconfig_mainloop(); |
---|
[bc220b2] | 439 | |
---|
[4b464a4] | 440 | /* little hack */ |
---|
[a15a84f] | 441 | now=time(NULL); |
---|
| 442 | today=localtime(&now); |
---|
| 443 | if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) { |
---|
[4b464a4] | 444 | if (time(NULL)>nexttime) { |
---|
| 445 | if (nexttimediff==1) { |
---|
[a15a84f] | 446 | nexttimediff=10; |
---|
[4b464a4] | 447 | } else { |
---|
| 448 | nexttimediff=1; |
---|
| 449 | } |
---|
| 450 | nexttime+=nexttimediff; |
---|
| 451 | owl_hack_animate(); |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | |
---|
[aac889a] | 455 | /* Grab incoming messages. */ |
---|
[d09e5a1] | 456 | newmsgs=0; |
---|
[ced25d1] | 457 | zpendcount=0; |
---|
[be0a79f] | 458 | while(owl_zephyr_zpending() || owl_global_messagequeue_pending(&g)) { |
---|
[09489b89] | 459 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 460 | struct sockaddr_in from; |
---|
[09489b89] | 461 | #endif |
---|
[e6449bc] | 462 | owl_message *m=NULL; |
---|
[ecd5dc5] | 463 | owl_filter *f; |
---|
[09489b89] | 464 | |
---|
[bd3f232] | 465 | /* grab the new message, stick it in 'm' */ |
---|
[be0a79f] | 466 | if (owl_zephyr_zpending()) { |
---|
[09489b89] | 467 | #ifdef HAVE_LIBZEPHYR |
---|
[d09e5a1] | 468 | /* grab a zephyr notice, but if we've done 20 without stopping, |
---|
| 469 | take a break to process keystrokes etc. */ |
---|
| 470 | if (zpendcount>20) break; |
---|
| 471 | ZReceiveNotice(¬ice, &from); |
---|
| 472 | zpendcount++; |
---|
| 473 | |
---|
| 474 | /* is this an ack from a zephyr we sent? */ |
---|
| 475 | if (owl_zephyr_notice_is_ack(¬ice)) { |
---|
| 476 | owl_zephyr_handle_ack(¬ice); |
---|
| 477 | continue; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | /* if it's a ping and we're not viewing pings then skip it */ |
---|
| 481 | if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) { |
---|
| 482 | continue; |
---|
| 483 | } |
---|
[7d4fbcd] | 484 | |
---|
[d09e5a1] | 485 | /* create the new message */ |
---|
| 486 | m=owl_malloc(sizeof(owl_message)); |
---|
| 487 | owl_message_create_from_znotice(m, ¬ice); |
---|
[09489b89] | 488 | #endif |
---|
[d09e5a1] | 489 | } else if (owl_global_messagequeue_pending(&g)) { |
---|
[74037d9] | 490 | /* pick up the non-zephyr message in the message queue */ |
---|
[d09e5a1] | 491 | m=owl_global_messageuque_popmsg(&g); |
---|
[74037d9] | 492 | } else { |
---|
| 493 | /* Not supposed to happen, but we seem to get here on resizes */ |
---|
| 494 | owl_function_debugmsg("Bottomed out looking for zephyr"); |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | /* If we didn't pick up a message for some reason, don't go on */ |
---|
| 498 | if (m==NULL) { |
---|
| 499 | owl_function_debugmsg("m is null in main loop"); |
---|
| 500 | continue; |
---|
[7d4fbcd] | 501 | } |
---|
| 502 | |
---|
[bd3f232] | 503 | /* if this message it on the puntlist, nuke it and continue */ |
---|
[7d4fbcd] | 504 | if (owl_global_message_is_puntable(&g, m)) { |
---|
| 505 | owl_message_free(m); |
---|
| 506 | continue; |
---|
| 507 | } |
---|
| 508 | |
---|
[280ddc6] | 509 | /* login or logout that should be ignored? */ |
---|
| 510 | if (owl_global_is_ignorelogins(&g) && owl_message_is_loginout(m)) { |
---|
| 511 | owl_message_free(m); |
---|
| 512 | continue; |
---|
| 513 | } |
---|
| 514 | |
---|
[7d4fbcd] | 515 | /* otherwise add it to the global list */ |
---|
| 516 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
[d09e5a1] | 517 | newmsgs=1; |
---|
[7d4fbcd] | 518 | |
---|
| 519 | /* let the config know the new message has been received */ |
---|
[f1e629d] | 520 | owl_perlconfig_getmsg(m, 0, NULL); |
---|
[7d4fbcd] | 521 | |
---|
| 522 | /* add it to any necessary views; right now there's only the current view */ |
---|
| 523 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
| 524 | |
---|
| 525 | /* do we need to autoreply? */ |
---|
[9854278] | 526 | if (owl_global_is_zaway(&g) && !owl_message_get_attribute_value(m, "isauto")) { |
---|
[1077753b] | 527 | if (owl_message_is_type_zephyr(m)) { |
---|
| 528 | owl_zephyr_zaway(m); |
---|
| 529 | } else if (owl_message_is_type_aim(m)) { |
---|
[e9f239b] | 530 | if (owl_message_is_private(m)) { |
---|
| 531 | owl_function_send_aimawymsg(owl_message_get_sender(m), owl_global_get_zaway_msg(&g)); |
---|
| 532 | } |
---|
[1077753b] | 533 | } |
---|
[7d4fbcd] | 534 | } |
---|
| 535 | |
---|
| 536 | /* ring the bell if it's a personal */ |
---|
[5d365f6] | 537 | if (!strcmp(owl_global_get_personalbell(&g), "on")) { |
---|
| 538 | if (!owl_message_is_loginout(m) && |
---|
| 539 | !owl_message_is_mail(m) && |
---|
[f178fb5] | 540 | owl_message_is_personal(m)) { |
---|
[5d365f6] | 541 | owl_function_beep(); |
---|
| 542 | } |
---|
| 543 | } else if (!strcmp(owl_global_get_personalbell(&g), "off")) { |
---|
| 544 | /* do nothing */ |
---|
| 545 | } else { |
---|
| 546 | f=owl_global_get_filter(&g, owl_global_get_personalbell(&g)); |
---|
| 547 | if (f && owl_filter_message_match(f, m)) { |
---|
| 548 | owl_function_beep(); |
---|
| 549 | } |
---|
[7d4fbcd] | 550 | } |
---|
| 551 | |
---|
[5d365f6] | 552 | |
---|
[ecd5dc5] | 553 | /* if it matches the alert filter, do the alert action */ |
---|
| 554 | f=owl_global_get_filter(&g, owl_global_get_alert_filter(&g)); |
---|
| 555 | if (f && owl_filter_message_match(f, m)) { |
---|
| 556 | owl_function_command(owl_global_get_alert_action(&g)); |
---|
| 557 | } |
---|
| 558 | |
---|
[5a95b69] | 559 | /* if it's a zephyr login or logout, update the zbuddylist */ |
---|
| 560 | if (owl_message_is_type_zephyr(m) && owl_message_is_loginout(m)) { |
---|
| 561 | if (owl_message_is_login(m)) { |
---|
| 562 | owl_zbuddylist_adduser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m)); |
---|
| 563 | } else if (owl_message_is_logout(m)) { |
---|
| 564 | owl_zbuddylist_deluser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m)); |
---|
| 565 | } else { |
---|
| 566 | owl_function_error("Internal error: received login notice that is neither login nor logout"); |
---|
| 567 | } |
---|
| 568 | } |
---|
| 569 | |
---|
[7d4fbcd] | 570 | /* check for burning ears message */ |
---|
| 571 | /* this is an unsupported feature */ |
---|
| 572 | if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) { |
---|
[1c6c4d3] | 573 | char *buff; |
---|
| 574 | buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m)); |
---|
[7d4fbcd] | 575 | owl_function_adminmsg(buff, ""); |
---|
[1c6c4d3] | 576 | owl_free(buff); |
---|
[7d4fbcd] | 577 | owl_function_beep(); |
---|
| 578 | } |
---|
| 579 | |
---|
[d09e5a1] | 580 | /* log the message if we need to */ |
---|
[15b34fd] | 581 | owl_log_message(m); |
---|
[7d4fbcd] | 582 | } |
---|
| 583 | |
---|
[5a95b69] | 584 | /* is it time to check zbuddies? */ |
---|
| 585 | if (owl_global_is_pseudologins(&g)) { |
---|
| 586 | if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) { |
---|
| 587 | owl_function_debugmsg("Doing zephyr buddy check"); |
---|
| 588 | owl_function_zephyr_buddy_check(1); |
---|
| 589 | owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g)); |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | |
---|
[afbf668] | 593 | /* dispatch any muxevents */ |
---|
| 594 | owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0); |
---|
| 595 | |
---|
[7d4fbcd] | 596 | /* follow the last message if we're supposed to */ |
---|
[d09e5a1] | 597 | if (newmsgs && followlast) { |
---|
[7d4fbcd] | 598 | owl_function_lastmsg_noredisplay(); |
---|
| 599 | } |
---|
[700c712] | 600 | |
---|
[ced25d1] | 601 | /* do the newmsgproc thing */ |
---|
[d09e5a1] | 602 | if (newmsgs) { |
---|
[8f44c6b] | 603 | owl_function_do_newmsgproc(); |
---|
[700c712] | 604 | } |
---|
[7d4fbcd] | 605 | |
---|
| 606 | /* redisplay if necessary */ |
---|
[d09e5a1] | 607 | /* this should be optimized to not run if the new messages won't be displayed */ |
---|
| 608 | if (newmsgs) { |
---|
[7d4fbcd] | 609 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 610 | sepbar(NULL); |
---|
| 611 | if (owl_popwin_is_active(owl_global_get_popwin(&g))) { |
---|
| 612 | owl_popwin_refresh(owl_global_get_popwin(&g)); |
---|
| 613 | /* TODO: this is a broken kludge */ |
---|
| 614 | if (owl_global_get_viewwin(&g)) { |
---|
| 615 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 616 | } |
---|
| 617 | } |
---|
| 618 | owl_global_set_needrefresh(&g); |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | /* if a popwin just came up, refresh it */ |
---|
| 622 | pw=owl_global_get_popwin(&g); |
---|
| 623 | if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) { |
---|
| 624 | owl_popwin_refresh(pw); |
---|
| 625 | owl_popwin_no_needs_first_refresh(pw); |
---|
| 626 | owl_global_set_needrefresh(&g); |
---|
| 627 | /* TODO: this is a broken kludge */ |
---|
| 628 | if (owl_global_get_viewwin(&g)) { |
---|
| 629 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | /* update the terminal if we need to */ |
---|
| 634 | if (owl_global_is_needrefresh(&g)) { |
---|
| 635 | /* leave the cursor in the appropriate window */ |
---|
| 636 | if (owl_global_is_typwin_active(&g)) { |
---|
| 637 | owl_function_set_cursor(typwin); |
---|
| 638 | } else { |
---|
| 639 | owl_function_set_cursor(sepwin); |
---|
| 640 | } |
---|
| 641 | doupdate(); |
---|
| 642 | owl_global_set_noneedrefresh(&g); |
---|
| 643 | } |
---|
| 644 | |
---|
[bd3f232] | 645 | /* Handle all keypresses. If no key has been pressed, sleep for a |
---|
| 646 | * little bit, but otherwise do not. This lets input be grabbed |
---|
| 647 | * as quickly as possbile */ |
---|
[7d4fbcd] | 648 | j=wgetch(typwin); |
---|
| 649 | if (j==ERR) { |
---|
| 650 | usleep(10); |
---|
| 651 | } else { |
---|
[7f792c1] | 652 | owl_global_update_lastinputtime(&g); |
---|
[1fd4cd3e] | 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 | } |
---|
[7d4fbcd] | 680 | } |
---|
[2a2bb60] | 681 | |
---|
[c9e72d1] | 682 | /* Log any error signals */ |
---|
| 683 | { |
---|
| 684 | siginfo_t si; |
---|
| 685 | int signum; |
---|
| 686 | if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) { |
---|
[81634b6] | 687 | owl_function_error("Got unexpected signal: %d %s (code: %d band: %d errno: %d)", |
---|
[afbf668] | 688 | signum, signum==SIGPIPE?"SIGPIPE":"SIG????", |
---|
[81634b6] | 689 | si.si_code, si.si_band, si.si_errno); |
---|
[c9e72d1] | 690 | } |
---|
| 691 | } |
---|
| 692 | |
---|
[7d4fbcd] | 693 | } |
---|
| 694 | } |
---|
| 695 | |
---|
[de22c3d] | 696 | void sig_handler(int sig, siginfo_t *si, void *data) |
---|
| 697 | { |
---|
[7d4fbcd] | 698 | if (sig==SIGWINCH) { |
---|
[bd3f232] | 699 | /* we can't inturrupt a malloc here, so it just sets a flag |
---|
| 700 | * schedulding a resize for later |
---|
| 701 | */ |
---|
[7d4fbcd] | 702 | owl_function_resize(); |
---|
[afbf668] | 703 | } else if (sig==SIGPIPE || sig==SIGCHLD) { |
---|
[c9e72d1] | 704 | /* Set a flag and some info that we got the sigpipe |
---|
| 705 | * so we can record that we got it and why... */ |
---|
| 706 | owl_global_set_errsignal(&g, sig, si); |
---|
[fe1f605] | 707 | } else if (sig==SIGTERM || sig==SIGHUP) { |
---|
| 708 | owl_function_quit(); |
---|
[7d4fbcd] | 709 | } |
---|
[c9e72d1] | 710 | |
---|
[7d4fbcd] | 711 | } |
---|
| 712 | |
---|
[de22c3d] | 713 | void usage() |
---|
| 714 | { |
---|
[e7cc1c3] | 715 | fprintf(stderr, "Owl version %s\n", OWL_VERSION_STRING); |
---|
[a68f05d] | 716 | fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-t <ttyname>]\n"); |
---|
[e7cc1c3] | 717 | fprintf(stderr, " -n don't load zephyr subscriptions\n"); |
---|
| 718 | fprintf(stderr, " -d enable debugging\n"); |
---|
[a68f05d] | 719 | fprintf(stderr, " -D enable debugging and delete previous debug file\n"); |
---|
[e7cc1c3] | 720 | fprintf(stderr, " -v print the Owl version number and exit\n"); |
---|
| 721 | fprintf(stderr, " -h print this help message\n"); |
---|
| 722 | fprintf(stderr, " -c specify an alternate config file\n"); |
---|
| 723 | fprintf(stderr, " -t set the tty name\n"); |
---|
[7d4fbcd] | 724 | } |
---|
[2a2bb60] | 725 | |
---|
| 726 | #if OWL_STDERR_REDIR |
---|
| 727 | |
---|
| 728 | /* Replaces stderr with a pipe so that we can read from it. |
---|
| 729 | * Returns the fd of the pipe from which stderr can be read. */ |
---|
[de22c3d] | 730 | int stderr_replace(void) |
---|
| 731 | { |
---|
[2a2bb60] | 732 | int pipefds[2]; |
---|
| 733 | if (0 != pipe(pipefds)) { |
---|
| 734 | perror("pipe"); |
---|
| 735 | owl_function_debugmsg("stderr_replace: pipe FAILED\n"); |
---|
| 736 | return -1; |
---|
| 737 | } |
---|
| 738 | owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]); |
---|
| 739 | if (-1 == dup2(pipefds[1], 2 /*stderr*/)) { |
---|
| 740 | owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno)); |
---|
| 741 | perror("dup2"); |
---|
| 742 | return -1; |
---|
| 743 | } |
---|
| 744 | return pipefds[0]; |
---|
| 745 | } |
---|
| 746 | |
---|
[afbf668] | 747 | /* Sends stderr (read from rfd) messages to the error console */ |
---|
| 748 | void stderr_redirect_handler(int handle, int rfd, int eventmask, void *data) |
---|
[de22c3d] | 749 | { |
---|
[2a2bb60] | 750 | int navail, bread; |
---|
| 751 | char *buf; |
---|
| 752 | /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/ |
---|
| 753 | if (rfd<0) return; |
---|
| 754 | if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) { |
---|
| 755 | return; |
---|
| 756 | } |
---|
| 757 | /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/ |
---|
| 758 | if (navail<=0) return; |
---|
| 759 | if (navail>256) { navail = 256; } |
---|
| 760 | buf = owl_malloc(navail+1); |
---|
| 761 | bread = read(rfd, buf, navail); |
---|
| 762 | if (buf[navail-1] != '\0') { |
---|
| 763 | buf[navail] = '\0'; |
---|
| 764 | } |
---|
| 765 | owl_function_error("Err: %s", buf); |
---|
| 766 | owl_free(buf); |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | #endif /* OWL_STDERR_REDIR */ |
---|