[5789230] | 1 | /* |
---|
[7d4fbcd] | 2 | * Copyright 2001 Massachusetts Institute of Technology |
---|
| 3 | * |
---|
| 4 | * Permission to use, copy, modify, and distribute this software and |
---|
| 5 | * its documentation for any purpose and without fee is hereby |
---|
| 6 | * granted, provided that the above copyright notice and this |
---|
| 7 | * permission notice appear in all copies and in supporting |
---|
| 8 | * documentation. No representation is made about the suitability of |
---|
| 9 | * this software for any purpose. It is provided "as is" without |
---|
| 10 | * express or implied warranty. |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #include <stdio.h> |
---|
| 14 | #include <unistd.h> |
---|
| 15 | #include <stdlib.h> |
---|
| 16 | #include <string.h> |
---|
| 17 | #include <com_err.h> |
---|
| 18 | #include <signal.h> |
---|
[5145235] | 19 | #include <time.h> |
---|
[7d4fbcd] | 20 | #include <sys/param.h> |
---|
[700c712] | 21 | #include <sys/types.h> |
---|
[38cf544c] | 22 | #include <sys/stat.h> |
---|
[7d4fbcd] | 23 | #include "owl.h" |
---|
| 24 | |
---|
[1aee7d9] | 25 | static const char fileIdent[] = "$Id$"; |
---|
| 26 | |
---|
[b2b0773] | 27 | owl_global g; |
---|
| 28 | |
---|
[7d4fbcd] | 29 | int main(int argc, char **argv, char **env) { |
---|
| 30 | WINDOW *recwin, *sepwin, *typwin, *msgwin; |
---|
| 31 | owl_editwin *tw; |
---|
| 32 | owl_popwin *pw; |
---|
[ced25d1] | 33 | int j, ret, initialsubs, debug, argcsave, followlast; |
---|
[d09e5a1] | 34 | int newmsgs, zpendcount, nexttimediff; |
---|
[7d4fbcd] | 35 | struct sigaction sigact; |
---|
[b45293f] | 36 | char *configfile, *tty, *perlout, **argvsave, buff[LINE], startupmsg[LINE]; |
---|
[7d4fbcd] | 37 | owl_filter *f; |
---|
[bd3f232] | 38 | owl_style *s; |
---|
[a15a84f] | 39 | time_t nexttime, now; |
---|
| 40 | struct tm *today; |
---|
[38cf544c] | 41 | char *dir; |
---|
[09489b89] | 42 | #ifdef HAVE_LIBZEPHYR |
---|
[be0a79f] | 43 | ZNotice_t notice; |
---|
[09489b89] | 44 | #endif |
---|
[7d4fbcd] | 45 | |
---|
| 46 | argcsave=argc; |
---|
| 47 | argvsave=argv; |
---|
| 48 | configfile=NULL; |
---|
| 49 | tty=NULL; |
---|
| 50 | debug=0; |
---|
[bd3f232] | 51 | initialsubs=1; |
---|
[7d4fbcd] | 52 | if (argc>0) { |
---|
| 53 | argv++; |
---|
| 54 | argc--; |
---|
| 55 | } |
---|
| 56 | while (argc>0) { |
---|
| 57 | if (!strcmp(argv[0], "-n")) { |
---|
| 58 | initialsubs=0; |
---|
| 59 | argv++; |
---|
| 60 | argc--; |
---|
| 61 | } else if (!strcmp(argv[0], "-c")) { |
---|
| 62 | if (argc<2) { |
---|
| 63 | fprintf(stderr, "Too few arguments to -c\n"); |
---|
| 64 | usage(); |
---|
| 65 | exit(1); |
---|
| 66 | } |
---|
| 67 | configfile=argv[1]; |
---|
| 68 | argv+=2; |
---|
| 69 | argc-=2; |
---|
| 70 | } else if (!strcmp(argv[0], "-t")) { |
---|
| 71 | if (argc<2) { |
---|
| 72 | fprintf(stderr, "Too few arguments to -t\n"); |
---|
| 73 | usage(); |
---|
| 74 | exit(1); |
---|
| 75 | } |
---|
| 76 | tty=argv[1]; |
---|
| 77 | argv+=2; |
---|
| 78 | argc-=2; |
---|
| 79 | } else if (!strcmp(argv[0], "-d")) { |
---|
| 80 | debug=1; |
---|
| 81 | argv++; |
---|
| 82 | argc--; |
---|
| 83 | } else if (!strcmp(argv[0], "-v")) { |
---|
| 84 | printf("This is owl version %s\n", OWL_VERSION_STRING); |
---|
| 85 | exit(0); |
---|
| 86 | } else { |
---|
| 87 | fprintf(stderr, "Uknown argument\n"); |
---|
| 88 | usage(); |
---|
| 89 | exit(1); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
[be0a79f] | 93 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 94 | /* zephyr init */ |
---|
[be0a79f] | 95 | ret=owl_zephyr_initialize(); |
---|
| 96 | if (ret) { |
---|
[7d4fbcd] | 97 | exit(1); |
---|
| 98 | } |
---|
[be0a79f] | 99 | #endif |
---|
| 100 | |
---|
[7d4fbcd] | 101 | /* signal handler */ |
---|
| 102 | sigact.sa_handler=sig_handler; |
---|
| 103 | sigemptyset(&sigact.sa_mask); |
---|
| 104 | sigact.sa_flags=0; |
---|
| 105 | sigaction(SIGWINCH, &sigact, NULL); |
---|
| 106 | sigaction(SIGALRM, &sigact, NULL); |
---|
| 107 | |
---|
| 108 | /* screen init */ |
---|
| 109 | sprintf(buff, "TERMINFO=%s", TERMINFO); |
---|
| 110 | putenv(buff); |
---|
| 111 | initscr(); |
---|
| 112 | start_color(); |
---|
[ac70242] | 113 | #ifdef HAVE_USE_DEFAULT_COLORS |
---|
[7d4fbcd] | 114 | use_default_colors(); |
---|
[ac70242] | 115 | #endif |
---|
[7d4fbcd] | 116 | raw(); |
---|
| 117 | noecho(); |
---|
| 118 | |
---|
| 119 | /* define simple color pairs */ |
---|
| 120 | if (has_colors() && COLOR_PAIRS>=8) { |
---|
| 121 | init_pair(OWL_COLOR_BLACK, COLOR_BLACK, -1); |
---|
| 122 | init_pair(OWL_COLOR_RED, COLOR_RED, -1); |
---|
| 123 | init_pair(OWL_COLOR_GREEN, COLOR_GREEN, -1); |
---|
| 124 | init_pair(OWL_COLOR_YELLOW, COLOR_YELLOW, -1); |
---|
| 125 | init_pair(OWL_COLOR_BLUE, COLOR_BLUE, -1); |
---|
| 126 | init_pair(OWL_COLOR_MAGENTA, COLOR_MAGENTA, -1); |
---|
| 127 | init_pair(OWL_COLOR_CYAN, COLOR_CYAN, -1); |
---|
| 128 | init_pair(OWL_COLOR_WHITE, COLOR_WHITE, -1); |
---|
| 129 | } |
---|
[38cf544c] | 130 | |
---|
[7d4fbcd] | 131 | |
---|
[bd3f232] | 132 | /* owl global init */ |
---|
[7d4fbcd] | 133 | owl_global_init(&g); |
---|
| 134 | if (debug) owl_global_set_debug_on(&g); |
---|
| 135 | owl_global_set_startupargs(&g, argcsave, argvsave); |
---|
[09489b89] | 136 | #ifdef HAVE_LIBZEPHYR |
---|
| 137 | owl_global_set_havezephyr(&g); |
---|
| 138 | #endif |
---|
| 139 | owl_global_set_haveaim(&g); |
---|
| 140 | |
---|
[38cf544c] | 141 | /* create the owl directory, in case it does not exist */ |
---|
| 142 | dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR); |
---|
| 143 | mkdir(dir, S_IRWXU); |
---|
| 144 | owl_free(dir); |
---|
[5145235] | 145 | |
---|
[ced25d1] | 146 | /* set the tty, either from the command line, or by figuring it out */ |
---|
[61e79a9] | 147 | if (tty) { |
---|
| 148 | owl_global_set_tty(&g, tty); |
---|
| 149 | } else { |
---|
| 150 | owl_global_set_tty(&g, owl_util_get_default_tty()); |
---|
| 151 | } |
---|
[7d4fbcd] | 152 | |
---|
[bd3f232] | 153 | /* setup the built-in styles */ |
---|
| 154 | s=owl_malloc(sizeof(owl_style)); |
---|
| 155 | owl_style_create_internal(s, "default", &owl_stylefunc_default); |
---|
| 156 | owl_global_add_style(&g, s); |
---|
| 157 | |
---|
| 158 | s=owl_malloc(sizeof(owl_style)); |
---|
| 159 | owl_style_create_internal(s, "basic", &owl_stylefunc_basic); |
---|
| 160 | owl_global_add_style(&g, s); |
---|
| 161 | |
---|
[8b32593] | 162 | s=owl_malloc(sizeof(owl_style)); |
---|
| 163 | owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline); |
---|
| 164 | owl_global_add_style(&g, s); |
---|
| 165 | |
---|
[7d4fbcd] | 166 | /* setup the default filters */ |
---|
[3abf28b] | 167 | /* the personal filter will need to change again when AIM chat's are |
---|
| 168 | * included. Also, there should be an %aimme% */ |
---|
[bd3f232] | 169 | f=owl_malloc(sizeof(owl_filter)); |
---|
[3abf28b] | 170 | owl_filter_init_fromstring(f, "personal", "( type ^zephyr$ " |
---|
| 171 | "and class ^message$ and instance ^personal$ " |
---|
| 172 | "and ( recipient ^%me%$ or sender ^%me%$ ) ) " |
---|
[3723f31] | 173 | "or ( type ^aim$ and login ^none$ )"); |
---|
[7d4fbcd] | 174 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 175 | |
---|
[bd3f232] | 176 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 177 | owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )"); |
---|
[7d4fbcd] | 178 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 179 | |
---|
[bd3f232] | 180 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 181 | owl_filter_init_fromstring(f, "ping", "opcode ^ping$"); |
---|
| 182 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 183 | |
---|
[bd3f232] | 184 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0236842] | 185 | owl_filter_init_fromstring(f, "auto", "opcode ^auto$"); |
---|
| 186 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 187 | |
---|
[bd3f232] | 188 | f=owl_malloc(sizeof(owl_filter)); |
---|
[0c502e9] | 189 | owl_filter_init_fromstring(f, "login", "not login ^none$"); |
---|
[0236842] | 190 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 191 | |
---|
[bd3f232] | 192 | f=owl_malloc(sizeof(owl_filter)); |
---|
[7d4fbcd] | 193 | owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$"); |
---|
| 194 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 195 | |
---|
[bd3f232] | 196 | f=owl_malloc(sizeof(owl_filter)); |
---|
[5a6e6b9] | 197 | owl_filter_init_fromstring(f, "out", "direction ^out$"); |
---|
| 198 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 199 | |
---|
[bd3f232] | 200 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 201 | owl_filter_init_fromstring(f, "aim", "type ^aim$"); |
---|
| 202 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 203 | |
---|
[bd3f232] | 204 | f=owl_malloc(sizeof(owl_filter)); |
---|
[31e48a3] | 205 | owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$"); |
---|
| 206 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 207 | |
---|
[bd3f232] | 208 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 209 | owl_filter_init_fromstring(f, "none", "false"); |
---|
| 210 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 211 | |
---|
[bd3f232] | 212 | f=owl_malloc(sizeof(owl_filter)); |
---|
[89426ab] | 213 | owl_filter_init_fromstring(f, "all", "true"); |
---|
[7d4fbcd] | 214 | owl_list_append_element(owl_global_get_filterlist(&g), f); |
---|
| 215 | |
---|
| 216 | /* set the current view */ |
---|
[c3ab155] | 217 | owl_view_create(owl_global_get_current_view(&g), "main", f, owl_global_get_style_by_name(&g, "default")); |
---|
[7d4fbcd] | 218 | |
---|
[96f8e5b] | 219 | /* AIM init */ |
---|
| 220 | owl_aim_init(); |
---|
| 221 | |
---|
[38cf544c] | 222 | /* process the startup file */ |
---|
| 223 | owl_function_execstartup(); |
---|
| 224 | |
---|
[7d4fbcd] | 225 | /* read the config file */ |
---|
[38cf544c] | 226 | owl_context_set_readconfig(owl_global_get_context(&g)); |
---|
[7d4fbcd] | 227 | ret=owl_readconfig(configfile); |
---|
| 228 | if (ret) { |
---|
| 229 | endwin(); |
---|
| 230 | printf("\nError parsing configfile\n"); |
---|
| 231 | exit(1); |
---|
| 232 | } |
---|
[ced25d1] | 233 | |
---|
[e075479] | 234 | /* if the config defines a formatting function, add 'perl' as a style */ |
---|
[bd3f232] | 235 | if (owl_global_is_config_format(&g)) { |
---|
| 236 | owl_function_debugmsg("Found perl formatting"); |
---|
| 237 | s=owl_malloc(sizeof(owl_style)); |
---|
| 238 | owl_style_create_perl(s, "perl", "owl::format_msg"); |
---|
| 239 | owl_global_add_style(&g, s); |
---|
[e075479] | 240 | owl_global_set_default_style(&g, "perl"); |
---|
[bd3f232] | 241 | } |
---|
| 242 | |
---|
[ced25d1] | 243 | /* execute the startup function in the configfile */ |
---|
[7d4fbcd] | 244 | perlout = owl_config_execute("owl::startup();"); |
---|
| 245 | if (perlout) owl_free(perlout); |
---|
| 246 | owl_function_debugmsg("-- Owl Startup --"); |
---|
| 247 | |
---|
| 248 | /* hold on to the window names for convenience */ |
---|
| 249 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 250 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 251 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 252 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 253 | tw=owl_global_get_typwin(&g); |
---|
| 254 | |
---|
| 255 | wrefresh(sepwin); |
---|
| 256 | |
---|
| 257 | /* load zephyr subs */ |
---|
[bd3f232] | 258 | if (initialsubs) { |
---|
| 259 | /* load normal subscriptions */ |
---|
| 260 | ret=owl_zephyr_loadsubs(NULL); |
---|
| 261 | if (ret!=-1) { |
---|
| 262 | owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES); |
---|
| 263 | } |
---|
[7d4fbcd] | 264 | |
---|
[bd3f232] | 265 | /* load login subscriptions */ |
---|
| 266 | if (owl_global_is_loginsubs(&g)) { |
---|
| 267 | owl_function_loadloginsubs(NULL); |
---|
| 268 | } |
---|
[7d4fbcd] | 269 | } |
---|
| 270 | |
---|
| 271 | /* zlog in if we need to */ |
---|
| 272 | if (owl_global_is_startuplogin(&g)) { |
---|
[31e48a3] | 273 | owl_zephyr_zlog_in(); |
---|
[7d4fbcd] | 274 | } |
---|
| 275 | |
---|
[e075479] | 276 | /* set the startup and default style, based on userclue and presence of a |
---|
| 277 | * formatting function */ |
---|
[bd3f232] | 278 | if (owl_global_is_config_format(&g)) { |
---|
[ef56a67] | 279 | owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "perl")); |
---|
[e075479] | 280 | owl_global_set_default_style(&g, "perl"); |
---|
[bd3f232] | 281 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
[ef56a67] | 282 | owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "default")); |
---|
[e075479] | 283 | owl_global_set_default_style(&g, "default"); |
---|
[bd3f232] | 284 | } else { |
---|
[ef56a67] | 285 | owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "basic")); |
---|
[e075479] | 286 | owl_global_set_default_style(&g, "basic"); |
---|
[bd3f232] | 287 | } |
---|
| 288 | |
---|
[7d4fbcd] | 289 | /* welcome message */ |
---|
| 290 | strcpy(startupmsg, "-------------------------------------------------------------------------\n"); |
---|
[22fcd366] | 291 | sprintf(buff, "Welcome to Owl version %s. Press 'h' for on line help. \n", OWL_VERSION_STRING); |
---|
[7d4fbcd] | 292 | strcat(startupmsg, buff); |
---|
[601a9e0] | 293 | strcat(startupmsg, " \n"); |
---|
[ce7db4d] | 294 | strcat(startupmsg, "If you would like to receive release announcements about owl you can join \n"); |
---|
[601a9e0] | 295 | strcat(startupmsg, "the owl-users@mit.edu mailing list. MIT users can add themselves, \n"); |
---|
| 296 | strcat(startupmsg, "otherwise send a request to owner-owl-users@mit.edu. ^ ^ \n"); |
---|
| 297 | strcat(startupmsg, " OvO \n"); |
---|
| 298 | strcat(startupmsg, "Please report any bugs or suggestions to bug-owl@mit.edu ( ) \n"); |
---|
| 299 | strcat(startupmsg, "-------------------------------------------------------------------m-m---\n"); |
---|
[7d4fbcd] | 300 | owl_function_adminmsg("", startupmsg); |
---|
| 301 | sepbar(NULL); |
---|
| 302 | |
---|
| 303 | owl_context_set_interactive(owl_global_get_context(&g)); |
---|
| 304 | |
---|
[a15a84f] | 305 | nexttimediff=10; |
---|
[4b464a4] | 306 | nexttime=time(NULL); |
---|
| 307 | |
---|
[7d4fbcd] | 308 | /* main loop */ |
---|
| 309 | while (1) { |
---|
| 310 | |
---|
| 311 | /* if a resize has been scheduled, deal with it */ |
---|
| 312 | owl_global_resize(&g, 0, 0); |
---|
| 313 | |
---|
| 314 | /* these are here in case a resize changes the windows */ |
---|
| 315 | msgwin=owl_global_get_curs_msgwin(&g); |
---|
| 316 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 317 | sepwin=owl_global_get_curs_sepwin(&g); |
---|
| 318 | typwin=owl_global_get_curs_typwin(&g); |
---|
| 319 | |
---|
| 320 | followlast=owl_global_should_followlast(&g); |
---|
[5789230] | 321 | |
---|
| 322 | /* If we're logged into AIM, do AIM stuff */ |
---|
| 323 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 324 | owl_function_debugmsg("Doing aim processing"); |
---|
| 325 | owl_aim_process_events(); |
---|
| 326 | } |
---|
| 327 | |
---|
[4b464a4] | 328 | /* little hack */ |
---|
[a15a84f] | 329 | now=time(NULL); |
---|
| 330 | today=localtime(&now); |
---|
| 331 | if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) { |
---|
[4b464a4] | 332 | if (time(NULL)>nexttime) { |
---|
| 333 | if (nexttimediff==1) { |
---|
[a15a84f] | 334 | nexttimediff=10; |
---|
[4b464a4] | 335 | } else { |
---|
| 336 | nexttimediff=1; |
---|
| 337 | } |
---|
| 338 | nexttime+=nexttimediff; |
---|
| 339 | owl_hack_animate(); |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | |
---|
[aac889a] | 343 | /* Grab incoming messages. */ |
---|
[d09e5a1] | 344 | newmsgs=0; |
---|
[ced25d1] | 345 | zpendcount=0; |
---|
[be0a79f] | 346 | while(owl_zephyr_zpending() || owl_global_messagequeue_pending(&g)) { |
---|
[09489b89] | 347 | #ifdef HAVE_LIBZEPHYR |
---|
[7d4fbcd] | 348 | struct sockaddr_in from; |
---|
[09489b89] | 349 | #endif |
---|
[7d4fbcd] | 350 | owl_message *m; |
---|
[ecd5dc5] | 351 | owl_filter *f; |
---|
[09489b89] | 352 | |
---|
[bd3f232] | 353 | /* grab the new message, stick it in 'm' */ |
---|
[be0a79f] | 354 | if (owl_zephyr_zpending()) { |
---|
[09489b89] | 355 | #ifdef HAVE_LIBZEPHYR |
---|
[d09e5a1] | 356 | /* grab a zephyr notice, but if we've done 20 without stopping, |
---|
| 357 | take a break to process keystrokes etc. */ |
---|
| 358 | if (zpendcount>20) break; |
---|
| 359 | ZReceiveNotice(¬ice, &from); |
---|
| 360 | zpendcount++; |
---|
| 361 | |
---|
| 362 | /* is this an ack from a zephyr we sent? */ |
---|
| 363 | if (owl_zephyr_notice_is_ack(¬ice)) { |
---|
| 364 | owl_zephyr_handle_ack(¬ice); |
---|
| 365 | continue; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | /* if it's a ping and we're not viewing pings then skip it */ |
---|
| 369 | if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) { |
---|
| 370 | continue; |
---|
| 371 | } |
---|
[7d4fbcd] | 372 | |
---|
[d09e5a1] | 373 | /* create the new message */ |
---|
| 374 | m=owl_malloc(sizeof(owl_message)); |
---|
| 375 | owl_message_create_from_znotice(m, ¬ice); |
---|
[09489b89] | 376 | #endif |
---|
[d09e5a1] | 377 | } else if (owl_global_messagequeue_pending(&g)) { |
---|
| 378 | m=owl_global_messageuque_popmsg(&g); |
---|
[7d4fbcd] | 379 | } |
---|
| 380 | |
---|
[bd3f232] | 381 | /* if this message it on the puntlist, nuke it and continue */ |
---|
[7d4fbcd] | 382 | if (owl_global_message_is_puntable(&g, m)) { |
---|
| 383 | owl_message_free(m); |
---|
| 384 | continue; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | /* otherwise add it to the global list */ |
---|
| 388 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
[d09e5a1] | 389 | newmsgs=1; |
---|
[7d4fbcd] | 390 | |
---|
| 391 | /* let the config know the new message has been received */ |
---|
[bd3f232] | 392 | owl_config_getmsg(m, "owl::receive_msg();"); |
---|
[7d4fbcd] | 393 | |
---|
| 394 | /* add it to any necessary views; right now there's only the current view */ |
---|
| 395 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
| 396 | |
---|
| 397 | /* do we need to autoreply? */ |
---|
[aac889a] | 398 | if (owl_message_is_type_zephyr(m) && owl_global_is_zaway(&g)) { |
---|
[7d4fbcd] | 399 | owl_zephyr_zaway(m); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | /* ring the bell if it's a personal */ |
---|
[3abf28b] | 403 | if (owl_global_is_personalbell(&g) && |
---|
[5789230] | 404 | !owl_message_is_loginout(m) && |
---|
[dafd919] | 405 | !owl_message_is_mail(m) && |
---|
[5789230] | 406 | owl_message_is_private(m)) { |
---|
[7d4fbcd] | 407 | owl_function_beep(); |
---|
| 408 | } |
---|
| 409 | |
---|
[ecd5dc5] | 410 | /* if it matches the alert filter, do the alert action */ |
---|
| 411 | f=owl_global_get_filter(&g, owl_global_get_alert_filter(&g)); |
---|
| 412 | if (f && owl_filter_message_match(f, m)) { |
---|
| 413 | owl_function_command(owl_global_get_alert_action(&g)); |
---|
| 414 | } |
---|
| 415 | |
---|
[7d4fbcd] | 416 | /* check for burning ears message */ |
---|
| 417 | /* this is an unsupported feature */ |
---|
| 418 | if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) { |
---|
[1c6c4d3] | 419 | char *buff; |
---|
| 420 | buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m)); |
---|
[7d4fbcd] | 421 | owl_function_adminmsg(buff, ""); |
---|
[1c6c4d3] | 422 | owl_free(buff); |
---|
[7d4fbcd] | 423 | owl_function_beep(); |
---|
| 424 | } |
---|
| 425 | |
---|
[d09e5a1] | 426 | /* log the message if we need to */ |
---|
[7d4fbcd] | 427 | if (owl_global_is_logging(&g) || owl_global_is_classlogging(&g)) { |
---|
| 428 | owl_log_incoming(m); |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | /* follow the last message if we're supposed to */ |
---|
[d09e5a1] | 433 | if (newmsgs && followlast) { |
---|
[7d4fbcd] | 434 | owl_function_lastmsg_noredisplay(); |
---|
| 435 | } |
---|
[700c712] | 436 | |
---|
[ced25d1] | 437 | /* do the newmsgproc thing */ |
---|
[d09e5a1] | 438 | if (newmsgs) { |
---|
[8f44c6b] | 439 | owl_function_do_newmsgproc(); |
---|
[700c712] | 440 | } |
---|
[7d4fbcd] | 441 | |
---|
| 442 | /* redisplay if necessary */ |
---|
[d09e5a1] | 443 | /* this should be optimized to not run if the new messages won't be displayed */ |
---|
| 444 | if (newmsgs) { |
---|
[7d4fbcd] | 445 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 446 | sepbar(NULL); |
---|
| 447 | if (owl_popwin_is_active(owl_global_get_popwin(&g))) { |
---|
| 448 | owl_popwin_refresh(owl_global_get_popwin(&g)); |
---|
| 449 | /* TODO: this is a broken kludge */ |
---|
| 450 | if (owl_global_get_viewwin(&g)) { |
---|
| 451 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | owl_global_set_needrefresh(&g); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | /* if a popwin just came up, refresh it */ |
---|
| 458 | pw=owl_global_get_popwin(&g); |
---|
| 459 | if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) { |
---|
| 460 | owl_popwin_refresh(pw); |
---|
| 461 | owl_popwin_no_needs_first_refresh(pw); |
---|
| 462 | owl_global_set_needrefresh(&g); |
---|
| 463 | /* TODO: this is a broken kludge */ |
---|
| 464 | if (owl_global_get_viewwin(&g)) { |
---|
| 465 | owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | /* update the terminal if we need to */ |
---|
| 470 | if (owl_global_is_needrefresh(&g)) { |
---|
| 471 | /* leave the cursor in the appropriate window */ |
---|
| 472 | if (owl_global_is_typwin_active(&g)) { |
---|
| 473 | owl_function_set_cursor(typwin); |
---|
| 474 | } else { |
---|
| 475 | owl_function_set_cursor(sepwin); |
---|
| 476 | } |
---|
| 477 | doupdate(); |
---|
| 478 | owl_global_set_noneedrefresh(&g); |
---|
| 479 | } |
---|
| 480 | |
---|
[bd3f232] | 481 | /* Handle all keypresses. If no key has been pressed, sleep for a |
---|
| 482 | * little bit, but otherwise do not. This lets input be grabbed |
---|
| 483 | * as quickly as possbile */ |
---|
[7d4fbcd] | 484 | j=wgetch(typwin); |
---|
| 485 | if (j==ERR) { |
---|
| 486 | usleep(10); |
---|
| 487 | continue; |
---|
| 488 | } |
---|
| 489 | /* find and activate the current keymap. |
---|
| 490 | * TODO: this should really get fixed by activating |
---|
| 491 | * keymaps as we switch between windows... |
---|
| 492 | */ |
---|
| 493 | if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) { |
---|
| 494 | owl_context_set_popless(owl_global_get_context(&g), |
---|
| 495 | owl_global_get_viewwin(&g)); |
---|
| 496 | owl_function_activate_keymap("popless"); |
---|
| 497 | } else if (owl_global_is_typwin_active(&g) |
---|
| 498 | && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) { |
---|
[cf83b7a] | 499 | /* |
---|
[7d4fbcd] | 500 | owl_context_set_editline(owl_global_get_context(&g), tw); |
---|
| 501 | owl_function_activate_keymap("editline"); |
---|
[cf83b7a] | 502 | */ |
---|
[7d4fbcd] | 503 | } else if (owl_global_is_typwin_active(&g) |
---|
| 504 | && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) { |
---|
| 505 | owl_context_set_editmulti(owl_global_get_context(&g), tw); |
---|
| 506 | owl_function_activate_keymap("editmulti"); |
---|
| 507 | } else { |
---|
| 508 | owl_context_set_recv(owl_global_get_context(&g)); |
---|
| 509 | owl_function_activate_keymap("recv"); |
---|
| 510 | } |
---|
| 511 | /* now actually handle the keypress */ |
---|
| 512 | ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); |
---|
| 513 | if (ret!=0 && ret!=1) { |
---|
| 514 | owl_function_makemsg("Unable to handle keypress"); |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | void sig_handler(int sig) { |
---|
| 520 | if (sig==SIGWINCH) { |
---|
[bd3f232] | 521 | /* we can't inturrupt a malloc here, so it just sets a flag |
---|
| 522 | * schedulding a resize for later |
---|
| 523 | */ |
---|
[7d4fbcd] | 524 | owl_function_resize(); |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | void usage() { |
---|
[e7cc1c3] | 529 | fprintf(stderr, "Owl version %s\n", OWL_VERSION_STRING); |
---|
| 530 | fprintf(stderr, "Usage: owl [-n] [-d] [-v] [-h] [-c <configfile>] [-t <ttyname>]\n"); |
---|
| 531 | fprintf(stderr, " -n don't load zephyr subscriptions\n"); |
---|
| 532 | fprintf(stderr, " -d enable debugging\n"); |
---|
| 533 | fprintf(stderr, " -v print the Owl version number and exit\n"); |
---|
| 534 | fprintf(stderr, " -h print this help message\n"); |
---|
| 535 | fprintf(stderr, " -c specify an alternate config file\n"); |
---|
| 536 | fprintf(stderr, " -t set the tty name\n"); |
---|
| 537 | |
---|
[7d4fbcd] | 538 | } |
---|