Add two new format functions: %(myhost) and %(myname).
authorKen Hornstein <kenh@pobox.com>
Wed, 15 Feb 2012 01:24:43 +0000 (20:24 -0500)
committerKen Hornstein <kenh@pobox.com>
Wed, 15 Feb 2012 01:24:43 +0000 (20:24 -0500)
man/mh-format.man
sbr/fmt_compile.c

index c50e02f..aa1c630 100644 (file)
@@ -252,7 +252,9 @@ strlen              integer length of \fIstr\fR
 width          integer output buffer size in bytes
 charleft               integer bytes left in output buffer
 timenow                integer seconds since the UNIX epoch
 width          integer output buffer size in bytes
 charleft               integer bytes left in output buffer
 timenow                integer seconds since the UNIX epoch
-me             string  the user's mailbox
+me             string  the user's mailbox (username)
+myhost         string  the user's local hostname
+myname         string  the user's name
 eq     literal boolean \fInum\fR == \fIarg\fR
 ne     literal boolean \fInum\fR != \fIarg\fR
 gt     literal boolean \fInum\fR > \fIarg\fR
 eq     literal boolean \fInum\fR == \fIarg\fR
 ne     literal boolean \fInum\fR != \fIarg\fR
 gt     literal boolean \fInum\fR > \fIarg\fR
@@ -302,6 +304,19 @@ putaddr    literal         print \fIstr\fR address list with
 .fi
 .RE
 .PP
 .fi
 .RE
 .PP
+The (\fIme\fR\^) function returns the username of the current user.  The
+(\fImyhost\fR\^) function returns the
+.B localname
+entry in
+.IR mts.conf ,
+or the local hostname if
+.B localname
+is not configured.  The (\fImyname\fR\^) function will return the value of
+the
+.B SIGNATURE
+environment variable if set, otherwise will return the passwd GECOS field for
+the current user.
+.PP
 The following functions require a date component as an argument:
 .PP
 .RS 5
 The following functions require a date component as an argument:
 .PP
 .RS 5
index b4e8bcb..239243f 100644 (file)
@@ -44,6 +44,7 @@
 #include <h/tws.h>
 #include <h/fmt_scan.h>
 #include <h/fmt_compile.h>
 #include <h/tws.h>
 #include <h/fmt_scan.h>
 #include <h/fmt_compile.h>
+#include <h/mts.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -75,6 +76,8 @@ extern struct mailname fmt_mnull;
 #define        TF_NOW     6        /* special - get current unix time    */
 #define        TF_EXPR_SV 7        /* like expr but save current str reg */
 #define        TF_NOP     8        /* like expr but no result            */
 #define        TF_NOW     6        /* special - get current unix time    */
 #define        TF_EXPR_SV 7        /* like expr but save current str reg */
 #define        TF_NOP     8        /* like expr but no result            */
+#define TF_MYNAME  9        /* special - get current name of user */
+#define TF_MYHOST  10       /* special - get "local" hostname     */
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
 
 /* ftable->flags */
 /* NB that TFL_PUTS is also used to decide whether the test
@@ -153,6 +156,8 @@ static struct ftable functable[] = {
      { "dat",        TF_NUM,   FT_LV_DAT,      0,              TFL_PUTN },
      { "strlen",     TF_NONE,  FT_LV_STRLEN,   0,              TFL_PUTN },
      { "me",         TF_MYBOX, FT_LS_LIT,      0,              TFL_PUTS },
      { "dat",        TF_NUM,   FT_LV_DAT,      0,              TFL_PUTN },
      { "strlen",     TF_NONE,  FT_LV_STRLEN,   0,              TFL_PUTN },
      { "me",         TF_MYBOX, FT_LS_LIT,      0,              TFL_PUTS },
+     { "myname",     TF_MYNAME,        FT_LS_LIT,      0,              TFL_PUTS },
+     { "myhost",     TF_MYHOST,        FT_LS_LIT,      0,              TFL_PUTS },
      { "plus",       TF_NUM,   FT_LV_PLUS_L,   0,              TFL_PUTN },
      { "minus",      TF_NUM,   FT_LV_MINUS_L,  0,              TFL_PUTN },
      { "divide",     TF_NUM,   FT_LV_DIVIDE_L, 0,              TFL_PUTN },
      { "plus",       TF_NUM,   FT_LV_PLUS_L,   0,              TFL_PUTN },
      { "minus",      TF_NUM,   FT_LV_MINUS_L,  0,              TFL_PUTN },
      { "divide",     TF_NUM,   FT_LV_DIVIDE_L, 0,              TFL_PUTN },
@@ -245,11 +250,6 @@ static unsigned char *usr_fstring; /* for CERROR */
 #define CERROR(str) compile_error (str, cp)
 
 /*
 #define CERROR(str) compile_error (str, cp)
 
 /*
- * external prototypes
- */
-extern char *getusername(void);
-
-/*
  * static prototypes
  */
 static struct ftable *lookup(char *);
  * static prototypes
  */
 static struct ftable *lookup(char *);
@@ -593,6 +593,14 @@ do_func(char *sp)
        LS(t->f_type, getusername());
        break;
 
        LS(t->f_type, getusername());
        break;
 
+    case TF_MYNAME:
+       LS(t->f_type, getfullname());
+       break;
+
+    case TF_MYHOST:
+       LS(t->f_type, LocalName(0));
+       break;
+
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;
     case TF_NOW:
        LV(t->f_type, time((time_t *) 0));
        break;