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 / mac / env_mac.c < prev    next >
C/C++ Source or Header  |  1998-09-28  |  7KB  |  244 lines

  1. /*
  2.  * Program:    Mac environment routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    26 January 1992
  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 notice appears 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. static char *myHomeDir = NIL;    /* home directory name */
  34. static char *myLocalHost = NIL;    /* local host name */
  35. static char *myNewsrc = NIL;    /* newsrc file name */
  36.  
  37. /* Environment manipulate parameters
  38.  * Accepts: function code
  39.  *        function-dependent value
  40.  * Returns: function-dependent return value
  41.  */
  42.  
  43. void *env_parameters (long function,void *value)
  44. {
  45.   char tmp[MAILTMPLEN];
  46.   switch ((int) function) {
  47.   case SET_HOMEDIR:
  48.     if (myHomeDir) fs_give ((void **) &myHomeDir);
  49.     myHomeDir = cpystr ((char *) value);
  50.     break;
  51.   case GET_HOMEDIR:
  52.     if (!myHomeDir) {        /* set home directory if not defined */
  53.       myHomeDir = cpystr ("");
  54.     }
  55.     value = (void *) myHomeDir;
  56.     break;
  57.   case SET_LOCALHOST:
  58.     myLocalHost = cpystr ((char *) value);
  59.     break;
  60.   case GET_LOCALHOST:
  61.     value = (void *) myLocalHost ? myLocalHost : "random-mac";
  62.     break;
  63.   case SET_NEWSRC:
  64.     if (myNewsrc) fs_give ((void **) &myNewsrc);
  65.     myNewsrc = cpystr ((char *) value);
  66.     break;
  67.   case GET_NEWSRC:
  68.     if (!myNewsrc) {        /* set news file name if not defined */
  69.       sprintf (tmp,"%s:News State",myhomedir ());
  70.       myNewsrc = cpystr (tmp);
  71.     }
  72.     value = (void *) myNewsrc;
  73.     break;
  74.   default:
  75.     value = NIL;        /* error case */
  76.     break;
  77.   }
  78.   return value;
  79. }
  80.  
  81. /* Write current time
  82.  * Accepts: destination string
  83.  *        format of date and time
  84.  *
  85.  * This depends upon the ReadLocation() call in System 7 and the
  86.  * user properly setting his location/timezone in the Map control
  87.  * panel.
  88.  * Nothing is done about the gmtFlags.dlsDelta byte yet, since I
  89.  * don't know how it's supposed to work.
  90.  */
  91.  
  92. static void do_date (char *date,char *fmt)
  93. {
  94.   long tz,tzm;
  95.   time_t ti = time (0);
  96.   struct tm *t = localtime (&ti);
  97.   MachineLocation loc;
  98.   ReadLocation (&loc);        /* get location/timezone poop */
  99.                 /* get sign-extended time zone */
  100.   tz = (loc.gmtFlags.gmtDelta & 0x00ffffff) |
  101.     ((loc.gmtFlags.gmtDelta & 0x00800000) ? 0xff000000 : 0);
  102.   tz /= 60;            /* get timezone in minutes */
  103.   tzm = tz % 60;        /* get minutes from the hour */
  104.                 /* output time */
  105.   strftime (date,MAILTMPLEN,fmt,t);
  106.                 /* now output time zone */
  107.   sprintf (date += strlen (date),"%+03ld%02ld",tz/60,tzm >= 0 ? tzm : -tzm);
  108. }
  109.  
  110.  
  111. /* Write current time in RFC 822 format
  112.  * Accepts: destination string
  113.  */
  114.  
  115. void rfc822_date (char *date)
  116. {
  117.   do_date (date,"%a, %d %b %Y %H:%M:%S ");
  118. }
  119.  
  120.  
  121. /* Write current time in internal format
  122.  * Accepts: destination string
  123.  */
  124.  
  125. void internal_date (char *date)
  126. {
  127.   do_date (date,"%2d-%b-%Y %H:%M:%S ");
  128. }
  129.  
  130. /* Return my local host name
  131.  * Returns: my local host name
  132.  */
  133.  
  134. char *mylocalhost (void)
  135. {
  136.   return (char *) mail_parameters (NIL,GET_LOCALHOST,NIL);
  137. }
  138.  
  139.  
  140. /* Return my home directory name
  141.  * Returns: my home directory name
  142.  */
  143.  
  144. char *myhomedir ()
  145. {
  146.   return (char *) mail_parameters (NIL,GET_HOMEDIR,NIL);
  147. }
  148.  
  149.  
  150. /* Determine default prototype stream to user
  151.  * Accepts: type (NIL for create, T for append)
  152.  * Returns: default prototype stream
  153.  */
  154.  
  155. MAILSTREAM *default_proto (long type)
  156. {
  157.   extern MAILSTREAM dummyproto;
  158.   return &dummyproto;        /* return default driver's prototype */
  159. }
  160.  
  161. /* Block until event satisfied
  162.  * Called as: while (wait_condition && wait ());
  163.  * Returns T if OK, NIL if user wants to abort
  164.  *
  165.  * Allows user to run a desk accessory, select a different window, or go
  166.  * to another application while waiting for the event to finish.  COMMAND/.
  167.  * will abort the wait.
  168.  * Assumes the Apple menu has the apple character as its first character,
  169.  * and that the main program has disabled all other menus.
  170.  */
  171.  
  172. long wait ()
  173. {
  174.   EventRecord event;
  175.   WindowPtr window;
  176.   MenuInfo **m;
  177.   long r;
  178.   Str255 tmp;
  179.                 /* wait for an event */
  180.   WaitNextEvent (everyEvent,&event,(long) 6,NIL);
  181.   switch (event.what) {        /* got one -- what is it? */
  182.   case mouseDown:        /* mouse clicked */
  183.     switch (FindWindow (event.where,&window)) {
  184.     case inMenuBar:        /* menu bar item? */
  185.                 /* yes, interesting event? */    
  186.       if (r = MenuSelect (event.where)) {
  187.                 /* round-about test for Apple menu */
  188.       if ((*(m = GetMHandle (HiWord (r))))->menuData[1] == appleMark) {
  189.                 /* get desk accessory name */ 
  190.       GetItem (m,LoWord (r),tmp);
  191.       OpenDeskAcc (tmp);    /* fire it up */
  192.       SetPort (window);    /* put us back at our window */
  193.     }
  194.     else SysBeep (60);    /* the fool forgot to disable it! */
  195.       }
  196.       HiliteMenu (0);        /* unhighlight it */
  197.       break;
  198.     case inContent:        /* some window was selected */
  199.       if (window != FrontWindow ()) SelectWindow (window);
  200.       break;
  201.     default:            /* ignore all others */
  202.       break;
  203.     }
  204.     break;
  205.   case keyDown:            /* key hit - if COMMAND/. then punt */
  206.     if ((event.modifiers & cmdKey) && (event.message & charCodeMask) == '.')
  207.       return NIL;
  208.     break;
  209.   default:            /* ignore all others */
  210.     break;
  211.   }
  212.   return T;            /* try wait test again */
  213. }
  214.  
  215. /* Return random number
  216.  */
  217.  
  218. long random ()
  219. {
  220.   return (long) rand () << 16 + rand ();
  221. }
  222.  
  223.  
  224. /* Emulator for BSD syslog() routine
  225.  * Accepts: priority
  226.  *        message
  227.  *        parameters
  228.  */
  229.  
  230. void syslog (int priority,const char *message,...)
  231. {
  232. }
  233.  
  234.  
  235. /* Emulator for BSD openlog() routine
  236.  * Accepts: identity
  237.  *        options
  238.  *        facility
  239.  */
  240.  
  241. void openlog (const char *ident,int logopt,int facility)
  242. {
  243. }
  244.