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