source: stylefunc.c @ 9c4ec91

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 9c4ec91 was 9c4ec91, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
In 'oneline' style don't bold outgoing AIM messages
  • Property mode set to 100644
File size: 16.6 KB
RevLine 
[bd3f232]1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
[5639bf2]5/* In all of these functions, 'fm' is expected to already be
6 * initialized.
7 */
8   
[bd3f232]9void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
10{
11  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
12  ZNotice_t *n;
13
14  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
15    n=owl_message_get_notice(m);
16
17    /* get the body */
18    body=owl_strdup(owl_message_get_body(m));
19    body=realloc(body, strlen(body)+30);
20
21    /* add a newline if we need to */
22    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
23      strcat(body, "\n");
24    }
25   
26    /* do the indenting into indent */
27    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
28    owl_text_indent(indent, body, OWL_MSGTAB);
29   
30    /* edit the from addr for printing */
31    strcpy(frombuff, owl_message_get_sender(m));
32    ptr=strchr(frombuff, '@');
33    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
34      *ptr='\0';
35    }
36   
37    /* set the message for printing */
38    owl_fmtext_append_normal(fm, OWL_TABSTR);
39   
[8b32593]40    if (owl_message_is_ping(m)) {
[bd3f232]41      owl_fmtext_append_bold(fm, "PING");
42      owl_fmtext_append_normal(fm, " from ");
43      owl_fmtext_append_bold(fm, frombuff);
44      owl_fmtext_append_normal(fm, "\n");
[8b32593]45    } else if (owl_message_is_loginout(m)) {
[bd3f232]46      char *ptr, host[LINE], tty[LINE];
47      int len;
48     
49      ptr=owl_zephyr_get_field(n, 1, &len);
50      strncpy(host, ptr, len);
51      host[len]='\0';
52      ptr=owl_zephyr_get_field(n, 3, &len);
53      strncpy(tty, ptr, len);
54      tty[len]='\0';
[8b32593]55
56      if (owl_message_is_login(m)) {
[bd3f232]57        owl_fmtext_append_bold(fm, "LOGIN");
[8b32593]58      } else if (owl_message_is_logout(m)) {
[bd3f232]59        owl_fmtext_append_bold(fm, "LOGOUT");
60      }
61      owl_fmtext_append_normal(fm, " for ");
62      ptr=short_zuser(owl_message_get_instance(m));
63      owl_fmtext_append_bold(fm, ptr);
64      owl_free(ptr);
65      owl_fmtext_append_normal(fm, " at ");
66      owl_fmtext_append_normal(fm, host);
67      owl_fmtext_append_normal(fm, " ");
68      owl_fmtext_append_normal(fm, tty);
69      owl_fmtext_append_normal(fm, "\n");
70    } else {
71      owl_fmtext_append_normal(fm, "From: ");
72      if (strcasecmp(owl_message_get_class(m), "message")) {
73        owl_fmtext_append_normal(fm, "Class ");
74        owl_fmtext_append_normal(fm, owl_message_get_class(m));
75        owl_fmtext_append_normal(fm, " / Instance ");
76        owl_fmtext_append_normal(fm, owl_message_get_instance(m));
77        owl_fmtext_append_normal(fm, " / ");
78      }
79      owl_fmtext_append_normal(fm, frombuff);
80      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
81        owl_fmtext_append_normal(fm, " {");
82        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
83        owl_fmtext_append_normal(fm, "} ");
84      }
85     
86      /* stick on the zsig */
87      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
88      owl_message_pretty_zsig(m, zsigbuff);
89      owl_fmtext_append_normal(fm, "    (");
90      owl_fmtext_append_ztext(fm, zsigbuff);
91      owl_fmtext_append_normal(fm, ")");
92      owl_fmtext_append_normal(fm, "\n");
93      owl_free(zsigbuff);
94     
95      /* then the indented message */
96      owl_fmtext_append_ztext(fm, indent);
97     
98      /* make personal messages bold for smaat users */
99      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
100        if (owl_message_is_personal(m)) {
101          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
102        }
103      }
104    }
105   
106    owl_free(body);
107    owl_free(indent);
108  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
109    char *indent, *text, *zsigbuff, *foo;
110     
111    text=owl_message_get_body(m);
112   
113    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
114    owl_text_indent(indent, text, OWL_MSGTAB);
115    owl_fmtext_append_normal(fm, OWL_TABSTR);
116    owl_fmtext_append_normal(fm, "To: ");
117    foo=short_zuser(owl_message_get_recipient(m));
118    owl_fmtext_append_normal(fm, foo);
119    owl_free(foo);
120    owl_fmtext_append_normal(fm, "  (Zsig: ");
121   
122    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
123    owl_message_pretty_zsig(m, zsigbuff);
124    owl_fmtext_append_ztext(fm, zsigbuff);
125    owl_free(zsigbuff);
126   
127    owl_fmtext_append_normal(fm, ")");
128    owl_fmtext_append_normal(fm, "\n");
129    owl_fmtext_append_ztext(fm, indent);
130    if (text[strlen(text)-1]!='\n') {
131      owl_fmtext_append_normal(fm, "\n");
132    }
133   
134    owl_free(indent);
135  } else if (owl_message_is_type_aim(m)) {
136    char *indent;
137   
138    if (owl_message_is_loginout(m)) {
139      owl_fmtext_append_normal(fm, OWL_TABSTR);
140      if (owl_message_is_login(m)) {
141        owl_fmtext_append_bold(fm, "AIM LOGIN");
142      } else {
143        owl_fmtext_append_bold(fm, "AIM LOGOUT");
144      }
145      owl_fmtext_append_normal(fm, " for ");
146      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
147      owl_fmtext_append_normal(fm, "\n");
148    } else if (owl_message_is_direction_in(m)) {
149      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
150      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
151      owl_fmtext_append_bold(fm, OWL_TABSTR);
152      owl_fmtext_append_bold(fm, "AIM from ");
153      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
154      owl_fmtext_append_bold(fm, "\n");
155      owl_fmtext_append_bold(fm, indent);
156      if (indent[strlen(indent)-1]!='\n') {
157        owl_fmtext_append_normal(fm, "\n");
158      }
159      owl_free(indent);
160    } else if (owl_message_is_direction_out(m)) {
161      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
162      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
163      owl_fmtext_append_normal(fm, OWL_TABSTR);
164      owl_fmtext_append_normal(fm, "AIM sent to ");
165      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
166      owl_fmtext_append_normal(fm, "\n");
167      owl_fmtext_append_ztext(fm, indent);
168      if (indent[strlen(indent)-1]!='\n') {
169        owl_fmtext_append_normal(fm, "\n");
170      }
171      owl_free(indent);
172    }
173  } else if (owl_message_is_type_admin(m)) {
174    char *text, *header, *indent;
175   
176    text=owl_message_get_body(m);
177    header=owl_message_get_attribute_value(m, "adminheader");
178   
179    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
180    owl_text_indent(indent, text, OWL_MSGTAB);
181    owl_fmtext_append_normal(fm, OWL_TABSTR);
182    owl_fmtext_append_bold(fm, "OWL ADMIN ");
183    owl_fmtext_append_ztext(fm, header);
184    owl_fmtext_append_normal(fm, "\n");
185    owl_fmtext_append_ztext(fm, indent);
186    if (text[strlen(text)-1]!='\n') {
187      owl_fmtext_append_normal(fm, "\n");
188    }
189   
190    owl_free(indent);
191  }
192}
193
194void owl_stylefunc_default(owl_fmtext *fm, owl_message *m)
195{
196  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
197  ZNotice_t *n;
198
199  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
200    n=owl_message_get_notice(m);
201 
202    /* get the body */
203    body=owl_malloc(strlen(owl_message_get_body(m))+30);
204    strcpy(body, owl_message_get_body(m));
205   
206    /* add a newline if we need to */
207    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
208      strcat(body, "\n");
209    }
210   
211    /* do the indenting into indent */
212    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
213    owl_text_indent(indent, body, OWL_MSGTAB);
214   
215    /* edit the from addr for printing */
216    strcpy(frombuff, owl_message_get_sender(m));
217    ptr=strchr(frombuff, '@');
218    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
219      *ptr='\0';
220    }
221   
222    /* set the message for printing */
223    owl_fmtext_append_normal(fm, OWL_TABSTR);
224   
[8b32593]225    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
[bd3f232]226      owl_fmtext_append_bold(fm, "PING");
227      owl_fmtext_append_normal(fm, " from ");
228      owl_fmtext_append_bold(fm, frombuff);
229      owl_fmtext_append_normal(fm, "\n");
[8b32593]230    } else if (owl_message_is_loginout(m)) {
[bd3f232]231      char *ptr, host[LINE], tty[LINE];
232      int len;
233     
234      ptr=owl_zephyr_get_field(n, 1, &len);
235      strncpy(host, ptr, len);
236      host[len]='\0';
237      ptr=owl_zephyr_get_field(n, 3, &len);
238      strncpy(tty, ptr, len);
239      tty[len]='\0';
240     
[8b32593]241      if (owl_message_is_login(m)) {
[bd3f232]242        owl_fmtext_append_bold(fm, "LOGIN");
[8b32593]243      } else if (owl_message_is_logout(m)) {
[bd3f232]244        owl_fmtext_append_bold(fm, "LOGOUT");
245      }
246      owl_fmtext_append_normal(fm, " for ");
247      ptr=short_zuser(n->z_class_inst);
248      owl_fmtext_append_bold(fm, ptr);
249      owl_free(ptr);
250      owl_fmtext_append_normal(fm, " at ");
251      owl_fmtext_append_normal(fm, host);
252      owl_fmtext_append_normal(fm, " ");
253      owl_fmtext_append_normal(fm, tty);
254      owl_fmtext_append_normal(fm, "\n");
255    } else {
256      owl_fmtext_append_normal(fm, owl_message_get_class(m));
257      owl_fmtext_append_normal(fm, " / ");
258      owl_fmtext_append_normal(fm, owl_message_get_instance(m));
259      owl_fmtext_append_normal(fm, " / ");
260      owl_fmtext_append_bold(fm, frombuff);
261      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
262        owl_fmtext_append_normal(fm, " {");
263        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
264        owl_fmtext_append_normal(fm, "} ");
265      }
266      if (n->z_opcode[0]!='\0') {
267        owl_fmtext_append_normal(fm, " [");
268        owl_fmtext_append_normal(fm, owl_message_get_opcode(m));
269        owl_fmtext_append_normal(fm, "] ");
270      }
271     
272      /* stick on the zsig */
273      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
274      owl_message_pretty_zsig(m, zsigbuff);
275      owl_fmtext_append_normal(fm, "    (");
276      owl_fmtext_append_ztext(fm, zsigbuff);
277      owl_fmtext_append_normal(fm, ")");
278      owl_fmtext_append_normal(fm, "\n");
279      owl_free(zsigbuff);
280     
281      /* then the indented message */
282      owl_fmtext_append_ztext(fm, indent);
283     
284      /* make private messages bold for smaat users */
285      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
286        if (owl_message_is_personal(m)) {
287          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
288        }
289      }
290    }
291   
292    owl_free(body);
293    owl_free(indent);
294  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
295    char *indent, *text, *zsigbuff, *foo;
296   
297    text=owl_message_get_body(m);
298   
299    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
300    owl_text_indent(indent, text, OWL_MSGTAB);
301    owl_fmtext_append_normal(fm, OWL_TABSTR);
302    owl_fmtext_append_normal(fm, "Zephyr sent to ");
303    foo=short_zuser(owl_message_get_recipient(m));
304    owl_fmtext_append_normal(fm, foo);
305    owl_free(foo);
306    owl_fmtext_append_normal(fm, "  (Zsig: ");
307   
308    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
309    owl_message_pretty_zsig(m, zsigbuff);
310    owl_fmtext_append_ztext(fm, zsigbuff);
311    owl_free(zsigbuff);
312   
313    owl_fmtext_append_normal(fm, ")");
314    owl_fmtext_append_normal(fm, "\n");
315    owl_fmtext_append_ztext(fm, indent);
316    if (text[strlen(text)-1]!='\n') {
317      owl_fmtext_append_normal(fm, "\n");
318    }
319   
320    owl_free(indent);
321  } else if (owl_message_is_type_aim(m)) {
322    char *indent;
323   
324    if (owl_message_is_loginout(m)) {
325      owl_fmtext_append_normal(fm, OWL_TABSTR);
326      if (owl_message_is_login(m)) {
327        owl_fmtext_append_bold(fm, "AIM LOGIN");
328      } else {
329        owl_fmtext_append_bold(fm, "AIM LOGOUT");
330      }
331      owl_fmtext_append_normal(fm, " for ");
332      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
333      owl_fmtext_append_normal(fm, "\n");
334    } else if (owl_message_is_direction_in(m)) {
335      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
336      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
337      owl_fmtext_append_bold(fm, OWL_TABSTR);
338      owl_fmtext_append_bold(fm, "AIM from ");
339      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
340      owl_fmtext_append_bold(fm, "\n");
341      owl_fmtext_append_bold(fm, indent);
342      if (indent[strlen(indent)-1]!='\n') {
343        owl_fmtext_append_normal(fm, "\n");
344      }
345      owl_free(indent);
346    } else if (owl_message_is_direction_out(m)) {
347      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
348      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
349      owl_fmtext_append_normal(fm, OWL_TABSTR);
350      owl_fmtext_append_normal(fm, "AIM sent to ");
351      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
352      owl_fmtext_append_normal(fm, "\n");
353      owl_fmtext_append_ztext(fm, indent);
354      if (indent[strlen(indent)-1]!='\n') {
355        owl_fmtext_append_normal(fm, "\n");
356      }
357      owl_free(indent);
358    }
359  } else if (owl_message_is_type_admin(m)) {
360    char *text, *header, *indent;
361   
362    text=owl_message_get_body(m);
363    header=owl_message_get_attribute_value(m, "adminheader");
364   
365    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
366    owl_text_indent(indent, text, OWL_MSGTAB);
367    owl_fmtext_append_normal(fm, OWL_TABSTR);
368    owl_fmtext_append_bold(fm, "OWL ADMIN ");
369    owl_fmtext_append_ztext(fm, header);
370    owl_fmtext_append_normal(fm, "\n");
371    owl_fmtext_append_ztext(fm, indent);
372    if (text[strlen(text)-1]!='\n') {
373      owl_fmtext_append_normal(fm, "\n");
374    }
375   
376    owl_free(indent);
377  }
378}
[8b32593]379
380void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
381{
382  char *tmp;
[5ea6fea]383  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
384  char *sender, *recip;
[8b32593]385
[5ea6fea]386  sender=short_zuser(owl_message_get_sender(m));
387  recip=short_zuser(owl_message_get_recipient(m));
388 
[8b32593]389  if (owl_message_is_type_zephyr(m)) {
390    owl_fmtext_append_spaces(fm, OWL_TAB);
391    if (owl_message_is_login(m)) {
[5ea6fea]392      tmp=owl_sprintf(baseformat, "<", "LOGIN", "", sender);
[8b32593]393      owl_fmtext_append_normal(fm, tmp);
394      owl_fmtext_append_normal(fm, "\n");
[5ea6fea]395      owl_free(tmp);
[8b32593]396    } else if (owl_message_is_logout(m)) {
[5ea6fea]397      tmp=owl_sprintf(baseformat, "<", "LOGOUT", "", sender);
[8b32593]398      owl_fmtext_append_normal(fm, tmp);
399      owl_fmtext_append_normal(fm, "\n");
[5ea6fea]400      owl_free(tmp);
[8b32593]401    } else if (owl_message_is_ping(m)) {
[5ea6fea]402      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
[8b32593]403      owl_fmtext_append_normal(fm, tmp);
404      owl_fmtext_append_normal(fm, "\n");
[5ea6fea]405      owl_free(tmp);
[8b32593]406    } else {
407      if (owl_message_is_direction_in(m)) {
[5ea6fea]408        tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
[8b32593]409      } else if (owl_message_is_direction_out(m)) {
[5ea6fea]410        tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
[8b32593]411      } else {
[5ea6fea]412        tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
[8b32593]413      }
414      owl_fmtext_append_normal(fm, tmp);
415      if (tmp) owl_free(tmp);
416     
417      tmp=owl_strdup(owl_message_get_body(m));
418      owl_util_tr(tmp, '\n', ' ');
[65e3901]419      owl_fmtext_append_ztext(fm, tmp);
[8b32593]420      owl_fmtext_append_normal(fm, "\n");
421      if (tmp) owl_free(tmp);
422    }
423     
424    /* make personal messages bold for smaat users */
[c3ab155]425    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
426        owl_message_is_personal(m) &&
427        owl_message_is_direction_in(m)) {
[8b32593]428      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
429    }
[5ea6fea]430
431    owl_free(sender);
432    owl_free(recip);
[8b32593]433   
434  } else if (owl_message_is_type_aim(m)) {
435    owl_fmtext_append_spaces(fm, OWL_TAB);
436    if (owl_message_is_login(m)) {
[5ea6fea]437      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
[8b32593]438      owl_fmtext_append_normal(fm, tmp);
439      owl_fmtext_append_normal(fm, "\n");
440      if (tmp) owl_free(tmp);
441    } else if (owl_message_is_logout(m)) {
[5ea6fea]442      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
[8b32593]443      owl_fmtext_append_normal(fm, tmp);
444      owl_fmtext_append_normal(fm, "\n");
445      if (tmp) owl_free(tmp);
446    } else {
447      if (owl_message_is_direction_in(m)) {
[5ea6fea]448        tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
[8b32593]449        owl_fmtext_append_normal(fm, tmp);
450        if (tmp) owl_free(tmp);
451      } else if (owl_message_is_direction_out(m)) {
[5ea6fea]452        tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
[8b32593]453        owl_fmtext_append_normal(fm, tmp);
454        if (tmp) owl_free(tmp);
455      }
456     
457      tmp=owl_strdup(owl_message_get_body(m));
458      owl_util_tr(tmp, '\n', ' ');
459      owl_fmtext_append_normal(fm, tmp);
460      owl_fmtext_append_normal(fm, "\n");
461      if (tmp) owl_free(tmp);
462
[0c502e9]463      /* make personal messages bold for smaat users */
[9c4ec91]464      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
[0c502e9]465        owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
466      }
[8b32593]467    }
468  } else if (owl_message_is_type_admin(m)) {
469    owl_fmtext_append_spaces(fm, OWL_TAB);
470    owl_fmtext_append_normal(fm, "< ADMIN                                        ");
471   
472    tmp=owl_strdup(owl_message_get_body(m));
473    owl_util_tr(tmp, '\n', ' ');
474    owl_fmtext_append_normal(fm, tmp);
475    owl_fmtext_append_normal(fm, "\n");
476    if (tmp) owl_free(tmp);
477  }
478
479}
Note: See TracBrowser for help on using the repository browser.