imapext-2007

annotate src/osdep/mac/env_mac.c @ 0:ada5e610ab86

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

UW-IMAP'd extensions by yuuji