summaryrefslogtreecommitdiff
path: root/imap/src/osdep/tops-20/env_t20.c
blob: 38403454445ed95651857716a87f8c3eef1f1b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* ========================================================================
 * Copyright 1988-2006 University of Washington
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 
 * ========================================================================
 */

/*
 * Program:	Environment routines -- TOPS-20 version
 *
 * Author:	Mark Crispin
 *		Networks and Distributed Computing
 *		Computing & Communications
 *		University of Washington
 *		Administration Building, AG-44
 *		Seattle, WA  98195
 *		Internet: MRC@CAC.Washington.EDU
 *
 * Date:	1 August 1988
 * Last Edited:	30 August 2006
 */


/* Dedication:
 * This file is dedicated with affection to the TOPS-20 operating system, which
 * set standards for user and programmer friendliness that have still not been
 * equaled by more `modern' operating systems.
 * Wasureru mon ka!!!!
 */

/* c-client environment parameters */

static char *myUserName = NIL;	/* user name */
static char *myHomeDir = NIL;	/* home directory name */
static char *myLocalHost = NIL;	/* local host name */
static char *myNewsrc = NIL;	/* newsrc file name */
static short no822tztext = NIL;	/* disable RFC [2]822 timezone text */


#include "pmatch.c"		/* include wildcard pattern matcher */

/* Environment manipulate parameters
 * Accepts: function code
 *	    function-dependent value
 * Returns: function-dependent return value
 */

void *env_parameters (long function,void *value)
{
  void *ret = NIL;
  switch ((int) function) {
  case SET_USERNAME:
    if (myUserName) fs_give ((void **) &myUserName);
    myUserName = cpystr ((char *) value);
  case GET_USERNAME:
    ret = (void *) myUserName;
    break;
  case SET_HOMEDIR:
    if (myHomeDir) fs_give ((void **) &myHomeDir);
    myHomeDir = cpystr ((char *) value);
  case GET_HOMEDIR:
    ret = (void *) myHomeDir;
    break;
  case SET_LOCALHOST:
    if (myLocalHost) fs_give ((void **) &myLocalHost);
    myLocalHost = cpystr ((char *) value);
  case GET_LOCALHOST:
    ret = (void *) myLocalHost;
    break;
  case SET_NEWSRC:
    if (myNewsrc) fs_give ((void **) &myNewsrc);
    myNewsrc = cpystr ((char *) value);
  case GET_NEWSRC:
    ret = (void *) myNewsrc;
    break;
  case SET_DISABLE822TZTEXT:
    no822tztext = value ? T : NIL;
  case GET_DISABLE822TZTEXT:
    ret = (void *) (no822tztext ? VOIDT : NIL);
    break;
  }
  return ret;
}

/* Write current time in RFC 822 format
 * Accepts: destination string
 */

void rfc822_date (char *date)
{
  char *s;
  int argblk[4];
  argblk[1] = (int) (date-1);
  argblk[2] = -1;		/* time now */
  argblk[3] = OT_822;		/* want RFC [2]822 format */
  jsys (ODTIM,argblk);
				/* suppress time zone text if desired */
  if (no822tztext && (s = strstr (date," ("))) *s = NIL;
}


/* Write current time in internal format
 * Accepts: destination string
 */

void internal_date (char *date)
{
  int argblk[5];
  argblk[1] = (int) (date-1);
  argblk[2] = -1;		/* time now */
  argblk[3] = OT_4YR;		/* output in 4-digit year format */
  jsys (ODTIM,argblk);
  argblk[2] = ' ';		/* delimit with space */
  jsys (BOUT,argblk);
  argblk[2] = -1;		/* time now */
  argblk[4] = 0;		/* no flags */
  jsys (ODCNV,argblk);		/* get time zone */
  argblk[2] = ((argblk[4] & 077000000) >> 18) * -100;
				/* add an hour if summer time */
  if (argblk[4] & IC_ADS) argblk[2] += 100;
  argblk[3] = 0340005000012;
  jsys (NOUT,argblk);
}

/* Return my user name
 * Accepts: pointer to optional flags
 * Returns: my user name
 */

char *myusername_full (unsigned long *flags)
{
  if (!myUserName) {		/* get user name if don't have it yet */
    char tmp[MAILTMPLEN];
    int argblk[5],i;
    jsys (GJINF,argblk);	/* get job poop */
    if (!(i = argblk[1])) {	/* remember user number */
      if (flags) *flags = MU_NOTLOGGEDIN;
      return "SYSTEM";		/* not logged in */
    }
    argblk[1] = (int) (tmp-1);	/* destination */
    argblk[2] = i;		/* user number */
    jsys (DIRST,argblk);	/* get user name string */
    myUserName = cpystr (tmp);	/* copy user name */
    argblk[1] = 0;		/* no flags */
    argblk[2] = i;		/* user number */
    argblk[3] = 0;		/* no stepping */
    jsys (RCDIR,argblk);	/* get home directory */
    argblk[1] = (int) (tmp-1);	/* destination */
    argblk[2] = argblk[3];	/* home directory number */
    jsys (DIRST,argblk);	/* get home directory string */
    myHomeDir = cpystr (tmp);	/* copy home directory */
    if (!myNewsrc) {		/* set news file name if not defined */
      sprintf (tmp,"%sNEWSRC",myhomedir ());
      myNewsrc = cpystr (tmp);
    }
    if (flags) *flags = MU_LOGGEDIN;
  }
  return myUserName;
}

/* Return my local host name
 * Returns: my local host name
 */

char *mylocalhost ()
{
  if (!myLocalHost) {		/* initialize if first time */
    char tmp[MAILTMPLEN];
    int argblk[5];
    argblk[1] = _GTHNS;		/* convert number to string */
    argblk[2] = (int) (tmp-1);
    argblk[3] = -1;		/* want local host */
    if (!jsys (GTHST,argblk)) strcpy (tmp,"LOCAL");
    myLocalHost = cpystr (tmp);
  }
  return myLocalHost;
}


/* Return my home directory name
 * Returns: my home directory name
 */

char *myhomedir ()
{
  if (!myHomeDir) myusername ();/* initialize if first time */
  return myHomeDir ? myHomeDir : "";
}


/* Determine default prototype stream to user
 * Accepts: type (NIL for create, T for append)
 * Returns: default prototype stream
 */

MAILSTREAM *default_proto (long type)
{
  return NIL;			/* no default prototype */
}

/* Emulator for BSD syslog() routine
 * Accepts: priority
 *	    message
 *	    parameters
 */

void syslog (int priority,const char *message,...)
{
}


/* Emulator for BSD openlog() routine
 * Accepts: identity
 *	    options
 *	    facility
 */

void openlog (const char *ident,int logopt,int facility)
{
}