Changeset bd3f232


Ignore:
Timestamp:
Jun 10, 2003, 3:14:59 PM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
f14a7ee
Parents:
6e05655
Message:
Styles implemented
It's still a little buggy ... if a format_msg(); is used in perl admin
  messages (or maybe just the first admin message) are not formatted.
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r6e05655 rbd3f232  
    11$Id$
    22
     32.0.4-pre-1
     4        Make command line option -n actualy work
     5
     6        'set style' now works.  Possbile values at the moment are
     7           'default' 'basic' or 'perl', but the last only if a
     8           format_msg() function is found in .owlconf
     9       
    3102.0.3
    411        Don't ring the terminal bell on mail messages.
  • Makefile.in

    r6a415e9 rbd3f232  
    2323     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
    2424     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    25      aim.c buddylist.c timer.c
     25     aim.c buddylist.c timer.c style.c stylefunc.c
    2626OWL_SRC = owl.c
    2727TESTER_SRC = tester.c
  • buddylist.c

    rb2b0773 rbd3f232  
    11#include "owl.h"
     2
     3static const char fileIdent[] = "$Id$";
    24
    35void owl_buddylist_init(owl_buddylist *b)
  • fmtext.c

    r6bf73ce rbd3f232  
    468468  for (i=0; i<lines; i++) {
    469469    offset=ptr1-in->textbuff;
    470     ptr2=strchr(ptr1, '\n'); /* this is a valgrind suspicious line */
     470    ptr2=strchr(ptr1, '\n');
    471471    if (!ptr2) {
    472472      _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1);
     
    578578  }
    579579  dst->textlen=src->textlen;
    580   dst->textbuff=owl_malloc(mallocsize); /* valgrind suspcious line */
     580  dst->textbuff=owl_malloc(mallocsize);
    581581  dst->fmbuff=owl_malloc(mallocsize);
    582582  dst->colorbuff=owl_malloc(mallocsize);
  • global.c

    r6a415e9 rbd3f232  
    5252  owl_list_create(&(g->puntlist));
    5353  owl_list_create(&(g->messagequeue));
     54  owl_list_create(&(g->stylelist));
    5455  g->curmsg_vert_offset=0;
    5556  g->resizepending=0;
     
    728729}
    729730 
     731/* style */
     732
     733/* Return the style with name 'name'.  If it does not exist return
     734 * NULL */
     735owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
     736{
     737  int i, j;
     738  owl_style *s;
     739 
     740  j=owl_list_get_size(&(g->stylelist));
     741  for (i=0; i<j; i++) {
     742    s=owl_list_get_element(&(g->stylelist), i);
     743    if (owl_style_matches_name(s, name)) {
     744      return(s);
     745    }
     746  }
     747  return(NULL);
     748}
     749
     750owl_style *owl_global_get_current_style(owl_global *g) {
     751  return(owl_global_get_style_by_name(g, owl_global_get_style(g)));
     752}
     753
     754void owl_global_add_style(owl_global *g, owl_style *s) {
     755  owl_list_append_element(&(g->stylelist), s);
     756}
  • message.c

    rd559df9 rbd3f232  
    2424  strcpy(m->hostname, "");
    2525  m->zwriteline=strdup("");
     26  m->invalid_format=1;
    2627
    2728  owl_list_create(&(m->attributes));
     
    3132  m->time=owl_strdup(ctime(&t));
    3233  m->time[strlen(m->time)-1]='\0';
     34  owl_fmtext_init_null(&(m->fmtext));
    3335}
    3436
     
    98100}
    99101
     102void owl_message_invalidate_format(owl_message *m)
     103{
     104  m->invalid_format=1;
     105}
     106
    100107owl_fmtext *owl_message_get_fmtext(owl_message *m)
    101108{
     109  owl_style *s;
     110
     111  /* if the format is invalid, regenerate the text based on the
     112   * current style
     113   */
     114  if (m->invalid_format) {
     115    owl_fmtext_free(&(m->fmtext));
     116    owl_fmtext_init_null(&(m->fmtext));
     117    s=owl_global_get_current_style(&g);
     118    owl_style_get_formattext(s, &(m->fmtext), m);
     119    m->invalid_format=0;
     120  }
    102121  return(&(m->fmtext));
    103122}
     
    371390{
    372391  if (m == NULL) return(0);
     392  (void) owl_message_get_fmtext(m);
    373393  return(owl_fmtext_num_lines(&(m->fmtext)));
    374394}
     
    417437{
    418438  owl_fmtext a, b;
     439
     440  /* this will ensure that our cached copy is up to date */
     441  (void) owl_message_get_fmtext(m);
    419442
    420443  owl_fmtext_init_null(&a);
     
    538561  return(m->id);
    539562}
    540                                        
     563
     564/* return 1 if the message contains "string", 0 otherwise.  This is
     565 * case insensitive because the functions it uses are
     566 */
    541567int owl_message_search(owl_message *m, char *string)
    542568{
    543   /* return 1 if the message contains "string", 0 otherwise.  This is
    544    * case insensitive because the functions it uses are */
    545 
     569
     570  (void) owl_message_get_fmtext(m); /* is this necessary? */
     571 
    546572  return (owl_fmtext_search(&(m->fmtext), string));
    547573}
    548574
    549 void owl_message_create(owl_message *m, char *header, char *text)
    550 {
    551   char *indent;
    552 
    553   owl_message_init(m);
    554   owl_message_set_body(m, text);
    555 
    556   indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
    557   owl_text_indent(indent, text, OWL_MSGTAB);
    558   owl_fmtext_init_null(&(m->fmtext));
    559   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    560   owl_fmtext_append_ztext(&(m->fmtext), header);
    561   owl_fmtext_append_normal(&(m->fmtext), "\n");
    562   owl_fmtext_append_ztext(&(m->fmtext), indent);
    563   if (text[strlen(text)-1]!='\n') {
    564     owl_fmtext_append_normal(&(m->fmtext), "\n");
    565   }
    566 
    567   owl_free(indent);
    568 }
    569575
    570576/* if loginout == -1 it's a logout message
     
    596602    owl_message_set_islogin(m);
    597603  }
    598 
    599   /* create the formatted message */
    600   if (owl_global_is_config_format(&g)) {
    601     _owl_message_make_text_from_config(m);
    602   } else {
    603     _owl_message_make_text_from_aim(m);
    604   }
    605 }
    606 
    607 void _owl_message_make_text_from_aim(owl_message *m)
    608 {
    609   char *indent;
    610 
    611   if (owl_message_is_loginout(m)) {
    612     owl_fmtext_init_null(&(m->fmtext));
    613     owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    614     if (owl_message_is_login(m)) {
    615       owl_fmtext_append_bold(&(m->fmtext), "AIM LOGIN");
    616     } else {
    617       owl_fmtext_append_bold(&(m->fmtext), "AIM LOGOUT");
    618     }
    619     owl_fmtext_append_normal(&(m->fmtext), " for ");
    620     owl_fmtext_append_normal(&(m->fmtext), owl_message_get_sender(m));
    621     owl_fmtext_append_normal(&(m->fmtext), "\n");
    622   } else if (owl_message_is_direction_in(m)) {
    623     indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
    624     owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
    625     owl_fmtext_init_null(&(m->fmtext));
    626     owl_fmtext_append_bold(&(m->fmtext), OWL_TABSTR);
    627     owl_fmtext_append_bold(&(m->fmtext), "AIM from ");
    628     owl_fmtext_append_bold(&(m->fmtext), owl_message_get_sender(m));
    629     owl_fmtext_append_bold(&(m->fmtext), "\n");
    630     owl_fmtext_append_bold(&(m->fmtext), indent);
    631     if (indent[strlen(indent)-1]!='\n') {
    632       owl_fmtext_append_normal(&(m->fmtext), "\n");
    633     }
    634     owl_free(indent);
    635   } else if (owl_message_is_direction_out(m)) {
    636     indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
    637     owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
    638     owl_fmtext_init_null(&(m->fmtext));
    639     owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    640     owl_fmtext_append_normal(&(m->fmtext), "AIM sent to ");
    641     owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m));
    642     owl_fmtext_append_normal(&(m->fmtext), "\n");
    643     owl_fmtext_append_ztext(&(m->fmtext), indent);
    644     if (indent[strlen(indent)-1]!='\n') {
    645       owl_fmtext_append_normal(&(m->fmtext), "\n");
    646     }
    647     owl_free(indent);
    648   }
    649604}
    650605
    651606void owl_message_create_admin(owl_message *m, char *header, char *text)
    652607{
    653   char *indent;
    654 
    655608  owl_message_init(m);
    656609  owl_message_set_type_admin(m);
    657 
    658610  owl_message_set_body(m, text);
    659 
    660   /* do something to make it clear the notice shouldn't be used for now */
    661 
    662   indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
    663   owl_text_indent(indent, text, OWL_MSGTAB);
    664   owl_fmtext_init_null(&(m->fmtext));
    665   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    666   owl_fmtext_append_bold(&(m->fmtext), "OWL ADMIN ");
    667   owl_fmtext_append_ztext(&(m->fmtext), header);
    668   owl_fmtext_append_normal(&(m->fmtext), "\n");
    669   owl_fmtext_append_ztext(&(m->fmtext), indent);
    670   if (text[strlen(text)-1]!='\n') {
    671     owl_fmtext_append_normal(&(m->fmtext), "\n");
    672   }
    673 
    674   owl_free(indent);
     611  owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */
    675612}
    676613
     
    770707  m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec));
    771708  m->time[strlen(m->time)-1]='\0';
    772 
    773   /* create the formatted message */
    774   if (owl_global_is_config_format(&g)) {
    775     _owl_message_make_text_from_config(m);
    776   } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
    777     _owl_message_make_text_from_notice_standard(m);
    778   } else {
    779     _owl_message_make_text_from_notice_simple(m);
    780   }
    781 
    782709}
    783710
     
    812739  }
    813740
    814   /* create the formatted message */
    815   if (owl_global_is_config_format(&g)) {
    816     _owl_message_make_text_from_config(m);
    817   } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
    818     _owl_message_make_text_from_zwriteline_standard(m);
    819   } else {
    820     _owl_message_make_text_from_zwriteline_simple(m);
    821   }
    822 
    823741  owl_zwrite_free(&z);
    824742}
    825743
    826 void _owl_message_make_text_from_config(owl_message *m)
    827 {
    828   char *body, *indent;
    829 
    830   owl_fmtext_init_null(&(m->fmtext));
    831 
    832   /* get body from the config */
    833   body=owl_config_getmsg(m, 1);
    834  
    835   /* indent */
    836   indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10);
    837   owl_text_indent(indent, body, OWL_TAB);
    838 
    839   /* fmtext_append.  This needs to change */
    840   owl_fmtext_append_ztext(&(m->fmtext), indent);
    841 
    842   owl_free(indent);
    843   owl_free(body);
    844 }
    845 
    846 void _owl_message_make_text_from_zwriteline_standard(owl_message *m)
    847 {
    848   char *indent, *text, *zsigbuff, *foo;
    849 
    850   text=owl_message_get_body(m);
    851 
    852   indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
    853   owl_text_indent(indent, text, OWL_MSGTAB);
    854   owl_fmtext_init_null(&(m->fmtext));
    855   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    856   owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to ");
    857   foo=short_zuser(owl_message_get_recipient(m));
    858   owl_fmtext_append_normal(&(m->fmtext), foo);
    859   owl_free(foo);
    860   owl_fmtext_append_normal(&(m->fmtext), "  (Zsig: ");
    861 
    862   zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
    863   owl_message_pretty_zsig(m, zsigbuff);
    864   owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    865   owl_free(zsigbuff);
    866  
    867   owl_fmtext_append_normal(&(m->fmtext), ")");
    868   owl_fmtext_append_normal(&(m->fmtext), "\n");
    869   owl_fmtext_append_ztext(&(m->fmtext), indent);
    870   if (text[strlen(text)-1]!='\n') {
    871     owl_fmtext_append_normal(&(m->fmtext), "\n");
    872   }
    873 
    874   owl_free(indent);
    875 }
    876 
    877 void _owl_message_make_text_from_zwriteline_simple(owl_message *m)
    878 {
    879   char *indent, *text, *zsigbuff, *foo;
    880 
    881   text=owl_message_get_body(m);
    882 
    883   indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
    884   owl_text_indent(indent, text, OWL_MSGTAB);
    885   owl_fmtext_init_null(&(m->fmtext));
    886   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    887   owl_fmtext_append_normal(&(m->fmtext), "To: ");
    888   foo=short_zuser(owl_message_get_recipient(m));
    889   owl_fmtext_append_normal(&(m->fmtext), foo);
    890   owl_free(foo);
    891   owl_fmtext_append_normal(&(m->fmtext), "  (Zsig: ");
    892 
    893   zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
    894   owl_message_pretty_zsig(m, zsigbuff);
    895   owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    896   owl_free(zsigbuff);
    897  
    898   owl_fmtext_append_normal(&(m->fmtext), ")");
    899   owl_fmtext_append_normal(&(m->fmtext), "\n");
    900   owl_fmtext_append_ztext(&(m->fmtext), indent);
    901   if (text[strlen(text)-1]!='\n') {
    902     owl_fmtext_append_normal(&(m->fmtext), "\n");
    903   }
    904 
    905   owl_free(indent);
    906 }
    907 
    908 void _owl_message_make_text_from_notice_standard(owl_message *m)
    909 {
    910   char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    911   ZNotice_t *n;
    912 
    913   n=&(m->notice);
    914  
    915   /* get the body */
    916   body=owl_malloc(strlen(owl_message_get_body(m))+30);
    917   strcpy(body, owl_message_get_body(m));
    918 
    919   /* add a newline if we need to */
    920   if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
    921     strcat(body, "\n");
    922   }
    923 
    924   /* do the indenting into indent */
    925   indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
    926   owl_text_indent(indent, body, OWL_MSGTAB);
    927 
    928   /* edit the from addr for printing */
    929   strcpy(frombuff, owl_message_get_sender(m));
    930   ptr=strchr(frombuff, '@');
    931   if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
    932     *ptr='\0';
    933   }
    934 
    935   /* set the message for printing */
    936   owl_fmtext_init_null(&(m->fmtext));
    937   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    938 
    939   if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) {
    940     owl_fmtext_append_bold(&(m->fmtext), "PING");
    941     owl_fmtext_append_normal(&(m->fmtext), " from ");
    942     owl_fmtext_append_bold(&(m->fmtext), frombuff);
    943     owl_fmtext_append_normal(&(m->fmtext), "\n");
    944   } else if (!strcasecmp(n->z_class, "login")) {
    945     char *ptr, host[LINE], tty[LINE];
    946     int len;
    947 
    948     ptr=owl_zephyr_get_field(n, 1, &len);
    949     strncpy(host, ptr, len);
    950     host[len]='\0';
    951     ptr=owl_zephyr_get_field(n, 3, &len);
    952     strncpy(tty, ptr, len);
    953     tty[len]='\0';
    954    
    955     if (!strcasecmp(n->z_opcode, "user_login")) {
    956       owl_fmtext_append_bold(&(m->fmtext), "LOGIN");
    957     } else if (!strcasecmp(n->z_opcode, "user_logout")) {
    958       owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");
    959     }
    960     owl_fmtext_append_normal(&(m->fmtext), " for ");
    961     ptr=short_zuser(n->z_class_inst);
    962     owl_fmtext_append_bold(&(m->fmtext), ptr);
    963     owl_free(ptr);
    964     owl_fmtext_append_normal(&(m->fmtext), " at ");
    965     owl_fmtext_append_normal(&(m->fmtext), host);
    966     owl_fmtext_append_normal(&(m->fmtext), " ");
    967     owl_fmtext_append_normal(&(m->fmtext), tty);
    968     owl_fmtext_append_normal(&(m->fmtext), "\n");
    969   } else {
    970     owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));
    971     owl_fmtext_append_normal(&(m->fmtext), " / ");
    972     owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));
    973     owl_fmtext_append_normal(&(m->fmtext), " / ");
    974     owl_fmtext_append_bold(&(m->fmtext), frombuff);
    975     if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
    976       owl_fmtext_append_normal(&(m->fmtext), " {");
    977       owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));
    978       owl_fmtext_append_normal(&(m->fmtext), "} ");
    979     }
    980     if (n->z_opcode[0]!='\0') {
    981       owl_fmtext_append_normal(&(m->fmtext), " [");
    982       owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m));
    983       owl_fmtext_append_normal(&(m->fmtext), "] ");
    984     }
    985 
    986     /* stick on the zsig */
    987     zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
    988     owl_message_pretty_zsig(m, zsigbuff);
    989     owl_fmtext_append_normal(&(m->fmtext), "    (");
    990     owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    991     owl_fmtext_append_normal(&(m->fmtext), ")");
    992     owl_fmtext_append_normal(&(m->fmtext), "\n");
    993     owl_free(zsigbuff);
    994 
    995     /* then the indented message */
    996     owl_fmtext_append_ztext(&(m->fmtext), indent);
    997 
    998     /* make private messages bold for smaat users */
    999     if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
    1000       if (owl_message_is_personal(m)) {
    1001         owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
    1002       }
    1003     }
    1004   }
    1005 
    1006   owl_free(body);
    1007   owl_free(indent);
    1008 }
    1009 
    1010 void _owl_message_make_text_from_notice_simple(owl_message *m)
    1011 {
    1012   char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    1013   ZNotice_t *n;
    1014 
    1015   n=&(m->notice);
    1016 
    1017   /* get the body */
    1018   body=owl_strdup(owl_message_get_body(m));
    1019   body=realloc(body, strlen(body)+30);
    1020 
    1021   /* add a newline if we need to */
    1022   if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
    1023     strcat(body, "\n");
    1024   }
    1025 
    1026   /* do the indenting into indent */
    1027   indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
    1028   owl_text_indent(indent, body, OWL_MSGTAB);
    1029 
    1030   /* edit the from addr for printing */
    1031   strcpy(frombuff, owl_message_get_sender(m));
    1032   ptr=strchr(frombuff, '@');
    1033   if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
    1034     *ptr='\0';
    1035   }
    1036 
    1037   /* set the message for printing */
    1038   owl_fmtext_init_null(&(m->fmtext));
    1039   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    1040 
    1041   if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
    1042     owl_fmtext_append_bold(&(m->fmtext), "PING");
    1043     owl_fmtext_append_normal(&(m->fmtext), " from ");
    1044     owl_fmtext_append_bold(&(m->fmtext), frombuff);
    1045     owl_fmtext_append_normal(&(m->fmtext), "\n");
    1046   } else if (!strcasecmp(owl_message_get_class(m), "login")) {
    1047     char *ptr, host[LINE], tty[LINE];
    1048     int len;
    1049 
    1050     ptr=owl_zephyr_get_field(n, 1, &len);
    1051     strncpy(host, ptr, len);
    1052     host[len]='\0';
    1053     ptr=owl_zephyr_get_field(n, 3, &len);
    1054     strncpy(tty, ptr, len);
    1055     tty[len]='\0';
    1056    
    1057     if (!strcasecmp(owl_message_get_opcode(m), "user_login")) {
    1058       owl_fmtext_append_bold(&(m->fmtext), "LOGIN");
    1059     } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) {
    1060       owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");
    1061     }
    1062     owl_fmtext_append_normal(&(m->fmtext), " for ");
    1063     ptr=short_zuser(owl_message_get_instance(m));
    1064     owl_fmtext_append_bold(&(m->fmtext), ptr);
    1065     owl_free(ptr);
    1066     owl_fmtext_append_normal(&(m->fmtext), " at ");
    1067     owl_fmtext_append_normal(&(m->fmtext), host);
    1068     owl_fmtext_append_normal(&(m->fmtext), " ");
    1069     owl_fmtext_append_normal(&(m->fmtext), tty);
    1070     owl_fmtext_append_normal(&(m->fmtext), "\n");
    1071   } else {
    1072     owl_fmtext_append_normal(&(m->fmtext), "From: ");
    1073     if (strcasecmp(owl_message_get_class(m), "message")) {
    1074       owl_fmtext_append_normal(&(m->fmtext), "Class ");
    1075       owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));
    1076       owl_fmtext_append_normal(&(m->fmtext), " / Instance ");
    1077       owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));
    1078       owl_fmtext_append_normal(&(m->fmtext), " / ");
    1079     }
    1080     owl_fmtext_append_normal(&(m->fmtext), frombuff);
    1081     if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
    1082       owl_fmtext_append_normal(&(m->fmtext), " {");
    1083       owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));
    1084       owl_fmtext_append_normal(&(m->fmtext), "} ");
    1085     }
    1086 
    1087     /* stick on the zsig */
    1088     zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
    1089     owl_message_pretty_zsig(m, zsigbuff);
    1090     owl_fmtext_append_normal(&(m->fmtext), "    (");
    1091     owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
    1092     owl_fmtext_append_normal(&(m->fmtext), ")");
    1093     owl_fmtext_append_normal(&(m->fmtext), "\n");
    1094     owl_free(zsigbuff);
    1095 
    1096     /* then the indented message */
    1097     owl_fmtext_append_ztext(&(m->fmtext), indent);
    1098 
    1099     /* make personal messages bold for smaat users */
    1100     if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
    1101       if (owl_message_is_personal(m)) {
    1102         owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
    1103       }
    1104     }
    1105   }
    1106 
    1107   owl_free(body);
    1108   owl_free(indent);
    1109 }
    1110744
    1111745void owl_message_pretty_zsig(owl_message *m, char *buff)
  • messagelist.c

    r1aee7d9 rbd3f232  
    55static const char fileIdent[] = "$Id$";
    66
    7 int owl_messagelist_create(owl_messagelist *ml) {
     7int owl_messagelist_create(owl_messagelist *ml)
     8{
    89  owl_list_create(&(ml->list));
    910  return(0);
    1011}
    1112
    12 int owl_messagelist_get_size(owl_messagelist *ml) {
     13int owl_messagelist_get_size(owl_messagelist *ml)
     14{
    1315  return(owl_list_get_size(&(ml->list)));
    1416}
    1517
    16 void *owl_messagelist_get_element(owl_messagelist *ml, int n) {
     18void *owl_messagelist_get_element(owl_messagelist *ml, int n)
     19{
    1720  return(owl_list_get_element(&(ml->list), n));
    1821}
    1922
    20 owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int id) {
     23owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int id)
     24{
    2125  /* return the message with id == 'id'.  If it doesn't exist return NULL. */
    2226  /* we could make this much more efficient at some point */
     
    3640}
    3741
    38 int owl_messagelist_append_element(owl_messagelist *ml, void *element) {
     42int owl_messagelist_append_element(owl_messagelist *ml, void *element)
     43{
    3944  return(owl_list_append_element(&(ml->list), element));
    4045}
    4146
    4247/* do we really still want this? */
    43 int owl_messagelist_delete_element(owl_messagelist *ml, int n) {
     48int owl_messagelist_delete_element(owl_messagelist *ml, int n)
     49{
    4450  /* mark a message as deleted */
    4551  owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
     
    4753}
    4854
    49 int owl_messagelist_undelete_element(owl_messagelist *ml, int n) {
     55int owl_messagelist_undelete_element(owl_messagelist *ml, int n)
     56{
    5057  /* mark a message as deleted */
    5158  owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
     
    5360}
    5461
    55 int owl_messagelist_expunge(owl_messagelist *ml) {
     62int owl_messagelist_expunge(owl_messagelist *ml)
     63{
    5664  /* expunge deleted messages */
    5765  int i, j;
     
    7987  return(0);
    8088}
     89
     90void owl_messagelist_invalidate_formats(owl_messagelist *ml)
     91{
     92  int i, j;
     93  owl_message *m;
     94
     95  j=owl_list_get_size(&(ml->list));
     96  for (i=0; i<j; i++) {
     97    m=owl_list_get_element(&(ml->list), i);
     98    owl_message_invalidate_format(m);
     99  }
     100}
  • owl.c

    r6bf73ce rbd3f232  
    3737  char *configfile, *tty, *perlout, **argvsave, buff[LINE], startupmsg[LINE];
    3838  owl_filter *f;
     39  owl_style *s;
    3940  time_t nexttime, now;
    4041  struct tm *today;
     
    4647  tty=NULL;
    4748  debug=0;
     49  initialsubs=1;
    4850  if (argc>0) {
    4951    argv++;
     
    128130
    129131   
    130   /* owl init */
     132  /* owl global init */
    131133  owl_global_init(&g);
    132134  if (debug) owl_global_set_debug_on(&g);
     
    145147  }
    146148
     149  /* setup the built-in styles */
     150  s=owl_malloc(sizeof(owl_style));
     151  owl_style_create_internal(s, "default", &owl_stylefunc_default);
     152  owl_global_add_style(&g, s);
     153
     154  s=owl_malloc(sizeof(owl_style));
     155  owl_style_create_internal(s, "basic", &owl_stylefunc_basic);
     156  owl_global_add_style(&g, s);
     157
    147158  /* setup the default filters */
    148159  /* the personal filter will need to change again when AIM chat's are
    149160   *  included.  Also, there should be an %aimme% */
    150   f=malloc(sizeof(owl_filter));
     161  f=owl_malloc(sizeof(owl_filter));
    151162  owl_filter_init_fromstring(f, "personal", "( type ^zephyr$ "
    152163                             "and class ^message$ and instance ^personal$ "
     
    155166  owl_list_append_element(owl_global_get_filterlist(&g), f);
    156167
    157   f=malloc(sizeof(owl_filter));
     168  f=owl_malloc(sizeof(owl_filter));
    158169  owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or class ^login$");
    159170  owl_list_append_element(owl_global_get_filterlist(&g), f);
    160171
    161   f=malloc(sizeof(owl_filter));
     172  f=owl_malloc(sizeof(owl_filter));
    162173  owl_filter_init_fromstring(f, "ping", "opcode ^ping$");
    163174  owl_list_append_element(owl_global_get_filterlist(&g), f);
    164175
    165   f=malloc(sizeof(owl_filter));
     176  f=owl_malloc(sizeof(owl_filter));
    166177  owl_filter_init_fromstring(f, "auto", "opcode ^auto$");
    167178  owl_list_append_element(owl_global_get_filterlist(&g), f);
    168179
    169   f=malloc(sizeof(owl_filter));
     180  f=owl_malloc(sizeof(owl_filter));
    170181  owl_filter_init_fromstring(f, "login", "class ^login$");
    171182  owl_list_append_element(owl_global_get_filterlist(&g), f);
    172183
    173   f=malloc(sizeof(owl_filter));
     184  f=owl_malloc(sizeof(owl_filter));
    174185  owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$");
    175186  owl_list_append_element(owl_global_get_filterlist(&g), f);
    176187
    177   f=malloc(sizeof(owl_filter));
     188  f=owl_malloc(sizeof(owl_filter));
    178189  owl_filter_init_fromstring(f, "out", "direction ^out$");
    179190  owl_list_append_element(owl_global_get_filterlist(&g), f);
    180191
    181   f=malloc(sizeof(owl_filter));
     192  f=owl_malloc(sizeof(owl_filter));
    182193  owl_filter_init_fromstring(f, "aim", "type ^aim$");
    183194  owl_list_append_element(owl_global_get_filterlist(&g), f);
    184195
    185   f=malloc(sizeof(owl_filter));
     196  f=owl_malloc(sizeof(owl_filter));
    186197  owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$");
    187198  owl_list_append_element(owl_global_get_filterlist(&g), f);
    188199
    189   f=malloc(sizeof(owl_filter));
     200  f=owl_malloc(sizeof(owl_filter));
    190201  owl_filter_init_fromstring(f, "none", "false");
    191202  owl_list_append_element(owl_global_get_filterlist(&g), f);
    192203
    193   f=malloc(sizeof(owl_filter));
     204  f=owl_malloc(sizeof(owl_filter));
    194205  owl_filter_init_fromstring(f, "all", "true");
    195206  owl_list_append_element(owl_global_get_filterlist(&g), f);
     
    211222    printf("\nError parsing configfile\n");
    212223    exit(1);
     224  }
     225
     226  /* if the config defaults a formatting function, add 'perl' as a style */
     227  if (owl_global_is_config_format(&g)) {
     228    owl_function_debugmsg("Found perl formatting");
     229    s=owl_malloc(sizeof(owl_style));
     230    owl_style_create_perl(s, "perl", "owl::format_msg");
     231    owl_global_add_style(&g, s);
    213232  }
    214233
     
    228247
    229248  /* load zephyr subs */
    230   ret=owl_zephyr_loadsubs(NULL);
    231   if (ret!=-1) {
    232     owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES);
    233   }
    234 
    235   /* load login subs */
    236   if (owl_global_is_loginsubs(&g)) {
    237     owl_function_loadloginsubs(NULL);
     249  if (initialsubs) {
     250    /* load normal subscriptions */
     251    ret=owl_zephyr_loadsubs(NULL);
     252    if (ret!=-1) {
     253      owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES);
     254    }
     255
     256    /* load login subscriptions */
     257    if (owl_global_is_loginsubs(&g)) {
     258      owl_function_loadloginsubs(NULL);
     259    }
    238260  }
    239261
     
    241263  if (owl_global_is_startuplogin(&g)) {
    242264    owl_zephyr_zlog_in();
     265  }
     266
     267  /* set the default style, based on userclue and presence of a
     268   *  formatting function */
     269  if (owl_global_is_config_format(&g)) {
     270    owl_global_set_style(&g, "perl");
     271  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
     272    owl_global_set_style(&g, "default");
     273  } else {
     274    owl_global_set_style(&g, "basic");
    243275  }
    244276
     
    275307
    276308    followlast=owl_global_should_followlast(&g);
    277 
    278309   
    279310    /* If we're logged into AIM, do AIM stuff */
     
    306337      owl_message *m;
    307338      owl_filter *f;
    308 
     339     
     340      /* grab the new message, stick it in 'm' */
    309341      if (ZPending()) {
    310342        /* grab a zephyr notice, but if we've done 20 without stopping,
     
    332364      }
    333365     
    334       /* if it's on the puntlist then, nuke it and continue */
     366      /* if this message it on the puntlist, nuke it and continue */
    335367      if (owl_global_message_is_puntable(&g, m)) {
    336368        owl_message_free(m);
     
    343375
    344376      /* let the config know the new message has been received */
    345       owl_config_getmsg(m, 0);
     377      owl_config_getmsg(m, "owl::receive_msg();");
    346378
    347379      /* add it to any necessary views; right now there's only the current view */
     
    432464    }
    433465
    434     /* Handle all keypresses.
    435      * If no key has been pressed sleep for a little bit, but
    436      * otherwise do not, this lets input be grabbed as quickly
    437      * as possbile */
     466    /* Handle all keypresses.  If no key has been pressed, sleep for a
     467     * little bit, but otherwise do not.  This lets input be grabbed
     468     * as quickly as possbile */
    438469    j=wgetch(typwin);
    439470    if (j==ERR) {
     
    471502void sig_handler(int sig) {
    472503  if (sig==SIGWINCH) {
    473     /* we can't inturrupt a malloc here, so it just sets a flag */
     504    /* we can't inturrupt a malloc here, so it just sets a flag
     505     * schedulding a resize for later
     506     */
    474507    owl_function_resize();
    475508  }
  • owl.h

    r6e05655 rbd3f232  
    1414static const char owl_h_fileIdent[] = "$Id$";
    1515
    16 #define OWL_VERSION         2.0.3
    17 #define OWL_VERSION_STRING "2.0.3"
     16#define OWL_VERSION         2.0.4-pre-1
     17#define OWL_VERSION_STRING "2.0.4-pre-1"
    1818
    1919#define OWL_DEBUG 0
    2020#define OWL_DEBUG_FILE "/var/tmp/owldebug"
    2121
    22 #define OWL_CONFIG_DIR "/.owl"           /* this is relative to the user's home directory */
     22#define OWL_CONFIG_DIR "/.owl"             /* this is relative to the user's home directory */
    2323#define OWL_STARTUP_FILE "/.owl/startup"   /* this is relative to the user's home directory */
    2424
     
    6464#define OWL_SCROLLMODE_PAGED       4
    6565#define OWL_SCROLLMODE_PAGEDCENTER 5
     66
     67#define OWL_STYLE_TYPE_INTERNAL  0
     68#define OWL_STYLE_TYPE_PERL      1
    6669
    6770#define OWL_TAB               3  /* This *HAS* to be the size of TABSTR below */
     
    245248  int direction;
    246249  ZNotice_t notice;
    247   owl_fmtext fmtext;
     250  owl_fmtext fmtext;              /* this is now only a CACHED copy */
     251  int invalid_format;             /* indicates whether fmtext needs to be regenerated */
    248252  int delete;
    249253  char hostname[MAXHOSTNAMELEN+1];
     
    252256  char *zwriteline;
    253257} owl_message;
     258
     259typedef struct _owl_style {
     260  char *name;
     261  int type;
     262  char *perlfuncname;
     263  void (*formatfunc) (owl_fmtext *fm, owl_message *m);
     264} owl_style;
    254265
    255266typedef struct _owl_mainwin {
     
    415426  owl_timer aim_noop_timer;
    416427  owl_timer aim_ignorelogin_timer;
    417   int aim_loggedin;
    418   char *aim_screenname;
    419   owl_buddylist buddylist;
    420   owl_list messagequeue; /* for queueing up aim and other messages */
     428  int aim_loggedin;         /* true if currently logged into AIM */
     429  char *aim_screenname;     /* currently logged in AIM screen name */
     430  owl_buddylist buddylist;  /* list of logged in AIM buddies */
     431  owl_list messagequeue;    /* for queueing up aim and other messages */
     432  owl_list stylelist;       /* global list of available styles */
    421433} owl_global;
    422434
  • readconfig.c

    rd559df9 rbd3f232  
    131131}
    132132
    133 char *owl_config_getmsg(owl_message *m, int mode) {
    134   /* if mode==1 we are doing message formatting.  The returned
    135    * formatted message needs to be freed by the caller.
    136    *
    137    * if mode==0 we are just doing the message-has-been-received
    138    * thing.
    139   */
    140 
     133char *owl_config_getmsg(owl_message *m, char *funcname) {
    141134  int i, j, len;
    142135  char *ptr, *ptr2;
     136  char runstr[LINE];
    143137
    144138  if (!owl_global_have_config(&g)) return("");
     
    236230
    237231  /* run the procedure corresponding to the mode */
    238   if (mode==1) {
    239     return(owl_config_execute("owl::format_msg();"));
    240   } else {
    241     ptr=owl_config_execute("owl::receive_msg();");
    242     if (ptr) owl_free(ptr);
    243     return(NULL);
    244   }
    245 }
    246 
     232  sprintf(runstr, "%s();", funcname);
     233  return(owl_config_execute(runstr));
     234}
     235
  • variable.c

    r6a415e9 rbd3f232  
    198198  OWLVAR_STRING_FULL( "tty" /* %OwlVarStub */, "", "tty name for zephyr location", "",
    199199                      NULL, owl_variable_tty_set, NULL),
    200  
     200
     201  OWLVAR_STRING_FULL( "style" /* %OwlVarStub */, "default", "name of the current formatting style", "",
     202                      NULL, owl_variable_style_set, NULL),
     203
    201204  OWLVAR_INT(    "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70,
    202205                 "maximum number of columns for M-q to fill text to",
     
    347350  ZInitLocationInfo(owl_global_get_hostname(&g), newval);
    348351  return(owl_variable_string_set_default(v, newval));
     352}
     353
     354int owl_variable_style_set(owl_variable *v, void *newval) {
     355  /* Invalidate all message formats first */
     356  int ret;
     357  owl_style *s;
     358
     359  s=owl_global_get_style_by_name(&g, newval);
     360  if (!s) {
     361    /* this message won't get seen, we'll need to deal with that later */
     362    owl_function_makemsg("No style named '%s' exists.", newval);
     363    return(0);
     364  }
     365 
     366  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
     367  ret=owl_variable_string_set_default(v, newval);
     368  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     369  return(ret);
    349370}
    350371
Note: See TracChangeset for help on using the changeset viewer.