Changeset f1e629d for style.c


Ignore:
Timestamp:
Jul 6, 2003, 6:42:06 PM (18 years ago)
Author:
Erik Nygren <nygren@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:
5d9c664
Parents:
675ce49
Message:
	New API for perl message formatting functions.
	        Legacy variables are still supported for owl::format_msg
		and owl::receive_msg, but these functions are now also
		passed an owl::Message object which contains methods
		for accessing the contents of the message.  See perlwrap.pm
		(and docs TBD) for the available methods.
		*** WARNING:  The exact API for owl::Message has
		*** not yet stabilized.
	Added "style" command for creating new styles.
	        Usage:  style <name> perl <function_name>
	Added support for "show styles".  Changed global style table
	        from list to dictionary.
	Changed AIM password prompt from "Password:" to "AIM Password:".
	Messages are reformatted after a window resize to allow styles
	        to take into account the width of the window.
	When perl throws an error, the message is put in the msgwin
	        if possible.
	Added perl functions for:
	        owl::getcurmsg() -- returns an owl::Message object for
		                    the active message
		                    in the current view.
	        owl::getnumcols() -- returns the column width of the window
		owl::zephyr_getrealm() -- returns the zephyr realm
	        owl::zephyr_getsender() -- returns the zephyr sender
	Made owl::COMMAND("foo"); be syntactic sugar for
	        owl::command("COMMAND foo");
		*** Is this a good or bad idea?
		*** This feature may be taken out before release.
	Added perlwrap.pm to contain perl code to be compiled into
	        the binary.  This is transformed into perlwrap.c by
		encapsulate.pl.
	Renamed readconfig.c to perlconfig.c and changed variables accordingly.
	Minor bugfixes in cmd.c and commands.c
File:
1 edited

Legend:

Unmodified
Added
Removed
  • style.c

    ref56a67 rf1e629d  
    33static const char fileIdent[] = "$Id$";
    44
    5 void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m))
     5void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)
    66{
    77  s->type=OWL_STYLE_TYPE_INTERNAL;
    88  s->name=owl_strdup(name);
     9  if (description) {
     10    s->description=owl_strdup(description);
     11  } else {
     12    s->description=owl_sprintf("Owl internal style %s", name);
     13  }
    914  s->perlfuncname=NULL;
    1015  s->formatfunc=formatfunc;
    1116}
    1217
    13 void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname)
     18void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description)
    1419{
    1520  s->type=OWL_STYLE_TYPE_PERL;
    1621  s->name=owl_strdup(name);
    1722  s->perlfuncname=owl_strdup(perlfuncname);
     23  if (description) {
     24    s->description=owl_strdup(description);
     25  } else {
     26    s->description=owl_sprintf("User-defined perl style that calls %s",
     27                               perlfuncname);
     28  }
    1829  s->formatfunc=NULL;
    1930}
     
    3041}
    3142
     43char *owl_style_get_description(owl_style *s)
     44{
     45  return(s->description);
     46}
     47
    3248/* Use style 's' to format message 'm' into fmtext 'fm'.
    3349 * 'fm' should already be be initialzed
     
    4157
    4258    /* run the perl function */
    43     body=owl_config_getmsg(m, s->perlfuncname);
     59    body=owl_perlconfig_getmsg(m, 1, s->perlfuncname);
    4460   
    4561    /* indent */
     
    5571}
    5672
     73int owl_style_validate(owl_style *s) {
     74  if (!s) {
     75    return -1;
     76  } else if (s->type==OWL_STYLE_TYPE_INTERNAL) {
     77    return 0;
     78  } else if (s->type==OWL_STYLE_TYPE_PERL
     79             && s->perlfuncname
     80             && owl_perlconfig_is_function(s->perlfuncname)) {
     81    return 0;
     82  } else {
     83    return -1;
     84  }
     85}
     86
    5787void owl_style_free(owl_style *s)
    5888{
    5989  if (s->name) owl_free(s->name);
     90  if (s->description) owl_free(s->description);
    6091  if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) {
    6192    owl_free(s->perlfuncname);
Note: See TracChangeset for help on using the changeset viewer.