home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / imap / src / osdep / tops-20 / env_t20.c < prev    next >
C/C++ Source or Header  |  1998-09-28  |  7KB  |  231 lines

  1. /*
  2.  * Program:    Environment routines -- TOPS-20 version
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    1 August 1988
  10.  * Last Edited:    28 September 1998
  11.  *
  12.  * Copyright 1998 by Mark Crispin
  13.  *
  14.  *  Permission to use, copy, modify, and distribute this software and its
  15.  * documentation for any purpose and without fee is hereby granted, provided
  16.  * that the above copyright notices appear in all copies and that both the
  17.  * above copyright notices and this permission notice appear in supporting
  18.  * documentation, and that the name of Mark Crispin not be used in advertising
  19.  * or publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  This software is made available "as is", and
  21.  * MARK CRISPIN DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  22.  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL
  24.  * MARK CRISPIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  25.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  26.  * WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT
  27.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  28.  * THIS SOFTWARE.
  29.  *
  30.  */
  31.  
  32.  
  33. /* Dedication:
  34.  * This file is dedicated with affection to the TOPS-20 operating system, which
  35.  * set standards for user and programmer friendliness that have still not been
  36.  * equaled by more `modern' operating systems.
  37.  * Wasureru mon ka!!!!
  38.  */
  39.  
  40. /* c-client environment parameters */
  41.  
  42. static char *myUserName = NIL;    /* user name */
  43. static char *myHomeDir = NIL;    /* home directory name */
  44. static char *myLocalHost = NIL;    /* local host name */
  45. static char *myNewsrc = NIL;    /* newsrc file name */
  46.  
  47.  
  48. /* Environment manipulate parameters
  49.  * Accepts: function code
  50.  *        function-dependent value
  51.  * Returns: function-dependent return value
  52.  */
  53.  
  54. void *env_parameters (long function,void *value)
  55. {
  56.   switch ((int) function) {
  57.   case SET_USERNAME:
  58.     if (myUserName) fs_give ((void **) &myUserName);
  59.     myUserName = cpystr ((char *) value);
  60.     break;
  61.   case GET_USERNAME:
  62.     value = (void *) myUserName;
  63.     break;
  64.   case SET_HOMEDIR:
  65.     if (myHomeDir) fs_give ((void **) &myHomeDir);
  66.     myHomeDir = cpystr ((char *) value);
  67.     break;
  68.   case GET_HOMEDIR:
  69.     value = (void *) myHomeDir;
  70.     break;
  71.   case SET_LOCALHOST:
  72.     if (myLocalHost) fs_give ((void **) &myLocalHost);
  73.     myLocalHost = cpystr ((char *) value);
  74.     break;
  75.   case GET_LOCALHOST:
  76.     value = (void *) myLocalHost;
  77.     break;
  78.   case SET_NEWSRC:
  79.     if (myNewsrc) fs_give ((void **) &myNewsrc);
  80.     myNewsrc = cpystr ((char *) value);
  81.     break;
  82.   case GET_NEWSRC:
  83.     value = (void *) myNewsrc;
  84.     break;
  85.   default:
  86.     value = NIL;        /* error case */
  87.     break;
  88.   }
  89.   return value;
  90. }
  91.  
  92. /* Write current time in RFC 822 format
  93.  * Accepts: destination string
  94.  */
  95.  
  96. void rfc822_date (char *date)
  97. {
  98.   int zone;
  99.   char *zonename;
  100.   struct tm *t;
  101.   struct timeval tv;
  102.   struct timezone tz;
  103.   gettimeofday (&tv,&tz);    /* get time and timezone poop */
  104.   t = localtime (&tv.tv_sec);    /* convert to individual items */
  105.   zone = -tz.tz_minuteswest;    /* TOPS-20 doesn't have tm_gmtoff or tm_zone */
  106.   zonename = timezone (tz.tz_minuteswest,t->tm_isdst);
  107.                 /* and output it */
  108.   sprintf (date,"%s, %d %s %d %02d:%02d:%02d %+03d%02d (%s)",
  109.        days[t->tm_wday],t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  110.        t->tm_hour,t->tm_min,t->tm_sec,
  111.        (t->tm_isdst ? 1 : 0) + zone/60,abs (zone) % 60,zonename);
  112. }
  113.  
  114.  
  115. /* Write current time in internal format
  116.  * Accepts: destination string
  117.  */
  118.  
  119. void internal_date (char *date)
  120. {
  121.   int zone;
  122.   struct tm *t;
  123.   struct timeval tv;
  124.   struct timezone tz;
  125.   gettimeofday (&tv,&tz);    /* get time and timezone poop */
  126.   t = localtime (&tv.tv_sec);    /* convert to individual items */
  127.   zone = -tz.tz_minuteswest;    /* TOPS-20 doesn't have tm_gmtoff or tm_zone */
  128.                 /* and output it */
  129.   sprintf (date,"%2d-%s-%d %02d:%02d:%02d %+03d%02d",
  130.        t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  131.        t->tm_hour,t->tm_min,t->tm_sec,
  132.        (t->tm_isdst ? 1 : 0) + zone/60,abs (zone) % 60);
  133. }
  134.  
  135. /* Return my user name
  136.  * Accepts: pointer to optional flags
  137.  * Returns: my user name
  138.  */
  139.  
  140. char *myusername_full (unsigned long *flags)
  141. {
  142.   if (!myUserName) {        /* get user name if don't have it yet */
  143.     char tmp[MAILTMPLEN];
  144.     int argblk[5],i;
  145.     jsys (GJINF,argblk);    /* get job poop */
  146.     if (!(i = argblk[1])) {    /* remember user number */
  147.       if (flags) *flags = MU_NOTLOGGEDIN;
  148.       return "SYSTEM";        /* not logged in */
  149.     }
  150.     argblk[1] = (int) (tmp-1);    /* destination */
  151.     argblk[2] = i;        /* user number */
  152.     jsys (DIRST,argblk);    /* get user name string */
  153.     myUserName = cpystr (tmp);    /* copy user name */
  154.     argblk[1] = 0;        /* no flags */
  155.     argblk[2] = i;        /* user number */
  156.     argblk[3] = 0;        /* no stepping */
  157.     jsys (RCDIR,argblk);    /* get home directory */
  158.     argblk[1] = (int) (tmp-1);    /* destination */
  159.     argblk[2] = argblk[3];    /* home directory number */
  160.     jsys (DIRST,argblk);    /* get home directory string */
  161.     myHomeDir = cpystr (tmp);    /* copy home directory */
  162.     if (!myNewsrc) {        /* set news file name if not defined */
  163.       sprintf (tmp,"%sNEWSRC",myhomedir ());
  164.       myNewsrc = cpystr (tmp);
  165.     }
  166.     if (flags) *flags = MU_LOGGEDIN;
  167.   }
  168.   return myUserName;
  169. }
  170.  
  171. /* Return my local host name
  172.  * Returns: my local host name
  173.  */
  174.  
  175. char *mylocalhost ()
  176. {
  177.   if (!myLocalHost) {        /* initialize if first time */
  178.     char tmp[MAILTMPLEN];
  179.     int argblk[5];
  180.     argblk[1] = _GTHNS;        /* convert number to string */
  181.     argblk[2] = (int) (tmp-1);
  182.     argblk[3] = -1;        /* want local host */
  183.     if (!jsys (GTHST,argblk)) strcpy (tmp,"LOCAL");
  184.     myLocalHost = cpystr (tmp);
  185.   }
  186.   return myLocalHost;
  187. }
  188.  
  189.  
  190. /* Return my home directory name
  191.  * Returns: my home directory name
  192.  */
  193.  
  194. char *myhomedir ()
  195. {
  196.   if (!myHomeDir) myusername ();/* initialize if first time */
  197.   return myHomeDir ? myHomeDir : "";
  198. }
  199.  
  200.  
  201. /* Determine default prototype stream to user
  202.  * Accepts: type (NIL for create, T for append)
  203.  * Returns: default prototype stream
  204.  */
  205.  
  206. MAILSTREAM *default_proto (long type)
  207. {
  208.   return NIL;            /* no default prototype */
  209. }
  210.  
  211. /* Emulator for BSD syslog() routine
  212.  * Accepts: priority
  213.  *        message
  214.  *        parameters
  215.  */
  216.  
  217. void syslog (int priority,const char *message,...)
  218. {
  219. }
  220.  
  221.  
  222. /* Emulator for BSD openlog() routine
  223.  * Accepts: identity
  224.  *        options
  225.  *        facility
  226.  */
  227.  
  228. void openlog (const char *ident,int logopt,int facility)
  229. {
  230. }
  231.