1 /* ========================================================================
2  * Copyright 1988-2006 University of Washington
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *
11  * ========================================================================
12  */
13 
14 /*
15  * Program:	VMS environment routines
16  *
17  * Author:	Mark Crispin
18  *		Networks and Distributed Computing
19  *		Computing & Communications
20  *		University of Washington
21  *		Administration Building, AG-44
22  *		Seattle, WA  98195
23  *		Internet: MRC@CAC.Washington.EDU
24  *
25  * Date:	2 August 1994
26  * Last Edited:	30 August 2006
27  */
28 
29 
30 static char *myUserName = NIL;	/* user name */
31 static char *myLocalHost = NIL;	/* local host name */
32 static char *myHomeDir = NIL;	/* home directory name */
33 static char *myNewsrc = NIL;	/* newsrc file name */
34 
35 #include "pmatch.c"		/* include wildcard pattern matcher */
36 
37 /* Environment manipulate parameters
38  * Accepts: function code
39  *	    function-dependent value
40  * Returns: function-dependent return value
41  */
42 
env_parameters(long function,void * value)43 void *env_parameters (long function,void *value)
44 {
45   void *ret = NIL;
46   switch ((int) function) {
47   case SET_USERNAME:
48     myUserName = cpystr ((char *) value);
49   case GET_USERNAME:
50     ret = (void *) myUserName;
51     break;
52   case SET_HOMEDIR:
53     myHomeDir = cpystr ((char *) value);
54   case GET_HOMEDIR:
55     ret = (void *) myHomeDir;
56     break;
57   case SET_LOCALHOST:
58     myLocalHost = cpystr ((char *) value);
59   case GET_LOCALHOST:
60     ret = (void *) myLocalHost;
61     break;
62   case SET_NEWSRC:
63     if (myNewsrc) fs_give ((void **) &myNewsrc);
64     myNewsrc = cpystr ((char *) value);
65   case GET_NEWSRC:
66     if (!myNewsrc) {		/* set news file name if not defined */
67       char tmp[MAILTMPLEN];
68       sprintf (tmp,"%s:.newsrc",myhomedir ());
69       myNewsrc = cpystr (tmp);
70     }
71     ret = (void *) myNewsrc;
72     break;
73   }
74   return ret;
75 }
76 
77 /* Write current time
78  * Accepts: destination string
79  *	    optional format of day-of-week prefix
80  *	    format of date and time
81  */
82 
do_date(char * date,char * prefix,char * fmt)83 static void do_date (char *date,char *prefix,char *fmt)
84 {
85   time_t tn = time (0);
86   struct tm *t = localtime (&tn);
87   int zone = LOCALTIMEZONE + (t->tm_isdst ? 60 : 0);
88   if (prefix) {			/* want day of week? */
89     sprintf (date,prefix,days[t->tm_wday]);
90     date += strlen (date);	/* make next sprintf append */
91   }
92 				/* output the date */
93   sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900,
94 	   t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60);
95 }
96 
97 
98 /* Write current time in RFC 822 format
99  * Accepts: destination string
100  */
101 
rfc822_date(char * date)102 void rfc822_date (char *date)
103 {
104   do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d");
105 }
106 
107 
108 /* Write current time in internal format
109  * Accepts: destination string
110  */
111 
internal_date(char * date)112 void internal_date (char *date)
113 {
114   do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d");
115 }
116 
117 /* Return my user name
118  * Returns: my user name
119  */
120 
myusername()121 char *myusername ()
122 {
123   struct stat sbuf;
124   char tmp[MAILTMPLEN];
125 
126   if (!myUserName) {		/* get user name if don't have it yet */
127     myUserName = cpystr (cuserid (NIL));
128     myHomeDir = cpystr ("SYS$LOGIN");
129   }
130   return myUserName;
131 }
132 
133 
134 /* Return my home directory name
135  * Returns: my home directory name
136  */
137 
myhomedir()138 char *myhomedir ()
139 {
140   if (!myHomeDir) myusername ();/* initialize if first time */
141   return myHomeDir;
142 }
143 
144 
145 /* Determine default prototype stream to user
146  * Accepts: type (NIL for create, T for append)
147  * Returns: default prototype stream
148  */
149 
default_proto(long type)150 MAILSTREAM *default_proto (long type)
151 {
152   return NIL;			/* no default prototype */
153 }
154 
155 /* Emulator for BSD syslog() routine
156  * Accepts: priority
157  *	    message
158  *	    parameters
159  */
160 
syslog(int priority,const char * message,...)161 void syslog (int priority,const char *message,...)
162 {
163 }
164 
165 
166 /* Emulator for BSD openlog() routine
167  * Accepts: identity
168  *	    options
169  *	    facility
170  */
171 
openlog(const char * ident,int logopt,int facility)172 void openlog (const char *ident,int logopt,int facility)
173 {
174 }
175