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