imapext-2007

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

UW-IMAP'd extensions by yuuji